1 # Copyright (C) 2022 Wind River Systems, Inc.
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
7 # http://www.apache.org/licenses/LICENSE-2.0
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.
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
26 def real_stx_aio_client():
27 os_client_args = config.get_stx_access_info()
28 config_client = get_stx_client(**os_client_args)
33 def real_stx_dc_client():
34 os_client_args = config.get_dc_access_info()
35 config_client = get_dc_client(**os_client_args)
38 # pytestmark = pytest.mark.usefixtures("mappers")
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
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
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
67 host2 = stxClientImp.getPserver(host1.id)
69 assert host1.id == host2.id
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
79 k8s2 = stxClientImp.getK8sDetail(k8s1.name)
81 assert k8s1.name == k8s2.name
82 assert k8s1.id == k8s2.id
86 k8s4 = stxClientImp.getK8sDetail(k8s3.name)
88 assert k8s3.name == k8s4.name
89 assert k8s3.id == k8s4.id
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
100 labellist = stxClientImp.getLabelList(hostid=hostlist[0].id)
101 assert len(labellist) > 0
102 label1 = labellist[0]
103 assert label1.id == "test"
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
112 cpulist = stxClientImp.getCpuList(hostid=hostlist[0].id)
113 assert len(cpulist) > 0
115 cpu2 = stxClientImp.getCpu(cpu1.id)
117 assert cpu1.id == cpu2.id
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
126 memlist = stxClientImp.getMemList(hostid=hostlist[0].id)
127 assert len(memlist) > 0
129 mem2 = stxClientImp.getMem(mem1.id)
131 assert mem1.id == mem2.id
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
140 ethlist = stxClientImp.getEthernetList(hostid=hostlist[0].id)
141 assert len(ethlist) > 0
143 eth2 = stxClientImp.getEthernet(eth1.id)
145 assert eth1.id == eth2.id
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
154 iflist = stxClientImp.getIfList(hostid=hostlist[0].id)
155 assert len(iflist) > 0
157 if2 = stxClientImp.getIf(if1.id)
159 assert if1.id == if2.id
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
168 iflist = stxClientImp.getIfList(hostid=hostlist[0].id)
169 assert len(iflist) > 0
171 portlist = stxClientImp.getPortList(interfaceid=iflist[0].id)
172 assert len(portlist) > 0
174 port2 = stxClientImp.getPort(port1.id)
175 assert port1 != port2
176 assert port1.id == port2.id
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
185 devicelist = stxClientImp.getDeviceList(hostid=hostlist[0].id)
186 assert len(devicelist) > 0
188 dev2 = stxClientImp.getDevice(dev1.id)
190 assert dev1.id == dev2.id
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
200 res2 = stxClientImp.getResourcePoolDetail(res1.id)
202 assert res1.name == res2.name
203 assert res1.id == res2.id
207 res4 = stxClientImp.getResourcePoolDetail(res3.id)
209 assert res3.name == res4.name
210 assert res3.id == res4.id