Fix INF-359 and INF-352 about the alarm event record
[pti/o2.git] / tests / integration-ocloud / test_clientdriver_stx_fault.py
1 # Copyright (C) 2022 Wind River Systems, Inc.
2 #
3 #  Licensed under the Apache License, Version 2.0 (the "License");
4 #  you may not use this file except in compliance with the License.
5 #  You may obtain a copy of the License at
6 #
7 #      http://www.apache.org/licenses/LICENSE-2.0
8 #
9 #  Unless required by applicable law or agreed to in writing, software
10 #  distributed under the License is distributed on an "AS IS" BASIS,
11 #  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 #  See the License for the specific language governing permissions and
13 #  limitations under the License.
14
15 # import sys
16 # import logging
17 import pytest
18
19 from o2common.config import config
20 from o2ims.adapter.clients.fault_client import StxFaultClientImp
21 # from o2ims.adapter.clients.ocloud_client import StxClientImp
22 from cgtsclient.client import get_client as get_stx_client
23 from dcmanagerclient.api.client import client as get_dc_client
24 from fmclient.client import get_client as get_fm_client
25
26
27 @pytest.fixture
28 def real_stx_aio_client():
29     os_client_args = config.get_stx_access_info()
30     config_client = get_stx_client(**os_client_args)
31     yield config_client
32
33
34 @pytest.fixture
35 def real_stx_dc_client():
36     os_client_args = config.get_dc_access_info()
37     config_client = get_dc_client(**os_client_args)
38     yield config_client
39
40
41 @pytest.fixture
42 def real_stx_fm_client():
43     os_client_args = config.get_fm_access_info()
44     config_client = get_fm_client(1, **os_client_args)
45     yield config_client
46
47 # pytestmark = pytest.mark.usefixtures("mappers")
48
49
50 def test_get_alarmlist(real_stx_fm_client):
51     fmClientImp = StxFaultClientImp(real_stx_fm_client)
52     assert fmClientImp is not None
53     alarms = fmClientImp.getAlarmList()
54     assert alarms is not None
55     assert len(alarms) > 0
56
57
58 def test_get_alarminfo(real_stx_fm_client):
59     fmClientImp = StxFaultClientImp(real_stx_fm_client)
60     assert fmClientImp is not None
61     alarms = fmClientImp.getAlarmList()
62     assert alarms is not None
63     assert len(alarms) > 0
64     alarm1 = alarms[0]
65     alarm2 = fmClientImp.getAlarmInfo(alarm1.id)
66     assert alarm1 != alarm2
67     assert alarm1.id == alarm2.id
68     # fmClientImp.getAlarmInfo('f87478e9-4cec-44dc-8f13-9304445d4070')
69     # assert fmClientImp is None
70
71
72 def test_get_eventlist(real_stx_fm_client):
73     fmClientImp = StxFaultClientImp(real_stx_fm_client)
74     assert fmClientImp is not None
75     events = fmClientImp.getEventList()
76     assert events is not None
77     assert len(events) > 0
78
79
80 def test_get_eventinfo(real_stx_fm_client):
81     fmClientImp = StxFaultClientImp(real_stx_fm_client)
82     assert fmClientImp is not None
83     events = fmClientImp.getEventList()
84     assert events is not None
85     assert len(events) > 0
86     event1 = events[0]
87     event2 = fmClientImp.getEventInfo(event1.id)
88     assert event1 != event2
89     assert event1.id == event2.id
90
91
92 def test_get_subcloud_alarmlist(real_stx_fm_client, real_stx_dc_client):
93     fmClientImp = StxFaultClientImp(
94         real_stx_fm_client, dc_client=real_stx_dc_client)
95     assert fmClientImp is not None
96     subclouds = fmClientImp.getSubcloudList()
97     stxclient, _ = fmClientImp.getSubcloudFaultClient(subclouds[0].subcloud_id)
98     res_pool_id = stxclient.isystem.list()[0].uuid
99
100     fmClientImp.setFaultClient(res_pool_id)
101     alarms = fmClientImp.getAlarmList()
102     assert alarms is not None
103     assert len(alarms) > 0