Enhance: Enable O2 IMS for distributed cloud
[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
85 def test_get_cpu_list(real_stx_aio_client):
86     stxClientImp = StxClientImp(real_stx_aio_client)
87     assert stxClientImp is not None
88     hostlist = stxClientImp.getPserverList()
89     assert len(hostlist) > 0
90
91     cpulist = stxClientImp.getCpuList(hostid=hostlist[0].id)
92     assert len(cpulist) > 0
93     cpu1 = cpulist[0]
94     cpu2 = stxClientImp.getCpu(cpu1.id)
95     assert cpu1 != cpu2
96     assert cpu1.id == cpu2.id
97
98
99 def test_get_mem_list(real_stx_aio_client):
100     stxClientImp = StxClientImp(real_stx_aio_client)
101     assert stxClientImp is not None
102     hostlist = stxClientImp.getPserverList()
103     assert len(hostlist) > 0
104
105     memlist = stxClientImp.getMemList(hostid=hostlist[0].id)
106     assert len(memlist) > 0
107     mem1 = memlist[0]
108     mem2 = stxClientImp.getMem(mem1.id)
109     assert mem1 != mem2
110     assert mem1.id == mem2.id
111
112
113 def test_get_eth_list(real_stx_aio_client):
114     stxClientImp = StxClientImp(real_stx_aio_client)
115     assert stxClientImp is not None
116     hostlist = stxClientImp.getPserverList()
117     assert len(hostlist) > 0
118
119     ethlist = stxClientImp.getEthernetList(hostid=hostlist[0].id)
120     assert len(ethlist) > 0
121     eth1 = ethlist[0]
122     eth2 = stxClientImp.getEthernet(eth1.id)
123     assert eth1 != eth2
124     assert eth1.id == eth2.id
125
126
127 def test_get_if_list(real_stx_aio_client):
128     stxClientImp = StxClientImp(real_stx_aio_client)
129     assert stxClientImp is not None
130     hostlist = stxClientImp.getPserverList()
131     assert len(hostlist) > 0
132
133     iflist = stxClientImp.getIfList(hostid=hostlist[0].id)
134     assert len(iflist) > 0
135     if1 = iflist[0]
136     if2 = stxClientImp.getIf(if1.id)
137     assert if1 != if2
138     assert if1.id == if2.id
139
140
141 def test_get_if_port_list(real_stx_aio_client):
142     stxClientImp = StxClientImp(real_stx_aio_client)
143     assert stxClientImp is not None
144     hostlist = stxClientImp.getPserverList()
145     assert len(hostlist) > 0
146
147     iflist = stxClientImp.getIfList(hostid=hostlist[0].id)
148     assert len(iflist) > 0
149
150     portlist = stxClientImp.getPortList(interfaceid=iflist[0].id)
151     assert len(portlist) > 0
152     port1 = portlist[0]
153     port2 = stxClientImp.getPort(port1.id)
154     assert port1 != port2
155     assert port1.id == port2.id
156
157
158 def test_get_subcloud_list(real_stx_aio_client, real_stx_dc_client):
159     # dcClientImp = StxClientImp(real_stx_dc_client)
160     dcClientImp = StxClientImp(
161         stx_client=real_stx_aio_client, dc_client=real_stx_dc_client)
162     sa = dcClientImp.getSubcloudList()
163     assert len(sa) == 0