Add capabilities of the DMS query
[pti/o2.git] / tests / integration-ocloud / test_clientdriver_stx.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.ocloud_client import StxClientImp
21 from cgtsclient.client import get_client as get_stx_client
22 from dcmanagerclient.api.client import client as get_dc_client
23
24
25 @pytest.fixture
26 def real_stx_aio_client():
27     os_client_args = config.get_stx_access_info()
28     config_client = get_stx_client(**os_client_args)
29     yield config_client
30
31
32 @pytest.fixture
33 def real_stx_dc_client():
34     os_client_args = config.get_dc_access_info()
35     config_client = get_dc_client(**os_client_args)
36     yield config_client
37
38 # pytestmark = pytest.mark.usefixtures("mappers")
39
40
41 def test_get_instanceinfo(real_stx_aio_client):
42     # logger = logging.getLogger(__name__)
43     stxclientimp = StxClientImp(real_stx_aio_client)
44     assert stxclientimp is not None
45     systeminfo = stxclientimp.getInstanceInfo()
46     assert systeminfo is not None
47     assert systeminfo.id is not None
48     assert systeminfo.name is not None
49     assert systeminfo.content is not None
50
51
52 def test_get_pserverlist(real_stx_aio_client):
53     stxClientImp = StxClientImp(real_stx_aio_client)
54     assert stxClientImp is not None
55     hosts = stxClientImp.getPserverList()
56     assert hosts is not None
57     assert len(hosts) > 0
58
59
60 def test_get_pserver(real_stx_aio_client):
61     stxClientImp = StxClientImp(real_stx_aio_client)
62     assert stxClientImp is not None
63     hosts = stxClientImp.getPserverList()
64     assert hosts is not None
65     assert len(hosts) > 0
66     host1 = hosts[0]
67     host2 = stxClientImp.getPserver(host1.id)
68     assert host1 != host2
69     assert host1.id == host2.id
70
71
72 def test_get_k8s_list(real_stx_aio_client):
73     stxClientImp = StxClientImp(real_stx_aio_client)
74     assert stxClientImp is not None
75     k8slist = stxClientImp.getK8sList()
76     assert k8slist is not None
77     assert len(k8slist) > 0
78     k8s1 = k8slist[0]
79     k8s2 = stxClientImp.getK8sDetail(k8s1.name)
80     assert k8s1 != k8s2
81     assert k8s1.name == k8s2.name
82     assert k8s1.id == k8s2.id
83
84     if len(k8slist) > 1:
85         k8s3 = k8slist[1]
86         k8s4 = stxClientImp.getK8sDetail(k8s3.name)
87         assert k8s3 != k8s4
88         assert k8s3.name == k8s4.name
89         assert k8s3.id == k8s4.id
90
91
92 def test_get_label_list(real_stx_aio_client):
93     stxClientImp = StxClientImp(real_stx_aio_client)
94     assert stxClientImp is not None
95     hostlist = stxClientImp.getPserverList()
96     assert len(hostlist) > 0
97
98     print(hostlist[0].id)
99
100     labellist = stxClientImp.getLabelList(hostid=hostlist[0].id)
101     assert len(labellist) > 0
102     label1 = labellist[0]
103     assert label1.id == "test"
104
105
106 def test_get_cpu_list(real_stx_aio_client):
107     stxClientImp = StxClientImp(real_stx_aio_client)
108     assert stxClientImp is not None
109     hostlist = stxClientImp.getPserverList()
110     assert len(hostlist) > 0
111
112     cpulist = stxClientImp.getCpuList(hostid=hostlist[0].id)
113     assert len(cpulist) > 0
114     cpu1 = cpulist[0]
115     cpu2 = stxClientImp.getCpu(cpu1.id)
116     assert cpu1 != cpu2
117     assert cpu1.id == cpu2.id
118
119
120 def test_get_mem_list(real_stx_aio_client):
121     stxClientImp = StxClientImp(real_stx_aio_client)
122     assert stxClientImp is not None
123     hostlist = stxClientImp.getPserverList()
124     assert len(hostlist) > 0
125
126     memlist = stxClientImp.getMemList(hostid=hostlist[0].id)
127     assert len(memlist) > 0
128     mem1 = memlist[0]
129     mem2 = stxClientImp.getMem(mem1.id)
130     assert mem1 != mem2
131     assert mem1.id == mem2.id
132
133
134 def test_get_eth_list(real_stx_aio_client):
135     stxClientImp = StxClientImp(real_stx_aio_client)
136     assert stxClientImp is not None
137     hostlist = stxClientImp.getPserverList()
138     assert len(hostlist) > 0
139
140     ethlist = stxClientImp.getEthernetList(hostid=hostlist[0].id)
141     assert len(ethlist) > 0
142     eth1 = ethlist[0]
143     eth2 = stxClientImp.getEthernet(eth1.id)
144     assert eth1 != eth2
145     assert eth1.id == eth2.id
146
147
148 def test_get_if_list(real_stx_aio_client):
149     stxClientImp = StxClientImp(real_stx_aio_client)
150     assert stxClientImp is not None
151     hostlist = stxClientImp.getPserverList()
152     assert len(hostlist) > 0
153
154     iflist = stxClientImp.getIfList(hostid=hostlist[0].id)
155     assert len(iflist) > 0
156     if1 = iflist[0]
157     if2 = stxClientImp.getIf(if1.id)
158     assert if1 != if2
159     assert if1.id == if2.id
160
161
162 def test_get_if_port_list(real_stx_aio_client):
163     stxClientImp = StxClientImp(real_stx_aio_client)
164     assert stxClientImp is not None
165     hostlist = stxClientImp.getPserverList()
166     assert len(hostlist) > 0
167
168     iflist = stxClientImp.getIfList(hostid=hostlist[0].id)
169     assert len(iflist) > 0
170
171     portlist = stxClientImp.getPortList(interfaceid=iflist[0].id)
172     assert len(portlist) > 0
173     port1 = portlist[0]
174     port2 = stxClientImp.getPort(port1.id)
175     assert port1 != port2
176     assert port1.id == port2.id
177
178
179 def test_get_device_list(real_stx_aio_client):
180     stxClientImp = StxClientImp(real_stx_aio_client)
181     assert stxClientImp is not None
182     hostlist = stxClientImp.getPserverList()
183     assert len(hostlist) > 0
184
185     devicelist = stxClientImp.getDeviceList(hostid=hostlist[0].id)
186     assert len(devicelist) > 0
187     dev1 = devicelist[0]
188     dev2 = stxClientImp.getDevice(dev1.id)
189     assert dev1 != dev2
190     assert dev1.id == dev2.id
191
192
193 def test_get_res_pool_list(real_stx_aio_client, real_stx_dc_client):
194     stxClientImp = StxClientImp(real_stx_aio_client, real_stx_dc_client)
195     assert stxClientImp is not None
196     reslist = stxClientImp.getResourcePoolList()
197     assert reslist is not None
198     assert len(reslist) > 0
199     res1 = reslist[0]
200     res2 = stxClientImp.getResourcePoolDetail(res1.id)
201     assert res1 != res2
202     assert res1.name == res2.name
203     assert res1.id == res2.id
204
205     if len(reslist) > 1:
206         res3 = reslist[1]
207         res4 = stxClientImp.getResourcePoolDetail(res3.id)
208         assert res3 != res4
209         assert res3.name == res4.name
210         assert res3.id == res4.id