Convert file endlines to Unix (LF)
[pti/o2.git] / tests / integration-ocloud / test_clientdriver_stx_sa.py
1 # Copyright (C) 2021 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_sa_client import StxSaClientImp
21 from cgtsclient.client import get_client
22
23
24 @pytest.fixture
25 def real_stx_aio_client():
26     os_client_args = config.get_stx_access_info()
27     config_client = get_client(**os_client_args)
28     yield config_client
29
30 # pytestmark = pytest.mark.usefixtures("mappers")
31
32
33 def test_get_instanceinfo(real_stx_aio_client):
34     # logger = logging.getLogger(__name__)
35     stxclientimp = StxSaClientImp(real_stx_aio_client)
36     assert stxclientimp is not None
37     systeminfo = stxclientimp.getInstanceInfo()
38     assert systeminfo is not None
39     assert systeminfo.id is not None
40     assert systeminfo.name is not None
41     assert systeminfo.content is not None
42
43
44 def test_get_pserverlist(real_stx_aio_client):
45     stxSaClientImp = StxSaClientImp(real_stx_aio_client)
46     assert stxSaClientImp is not None
47     hosts = stxSaClientImp.getPserverList()
48     assert hosts is not None
49     assert len(hosts) > 0
50
51
52 def test_get_pserver(real_stx_aio_client):
53     stxSaClientImp = StxSaClientImp(real_stx_aio_client)
54     assert stxSaClientImp is not None
55     hosts = stxSaClientImp.getPserverList()
56     assert hosts is not None
57     assert len(hosts) > 0
58     host1 = hosts[0]
59     host2 = stxSaClientImp.getPserver(host1.id)
60     assert host1 != host2
61     assert host1.id == host2.id
62
63
64 def test_get_k8s_list(real_stx_aio_client):
65     stxSaClientImp = StxSaClientImp(real_stx_aio_client)
66     assert stxSaClientImp is not None
67     k8slist = stxSaClientImp.getK8sList()
68     assert k8slist is not None
69     assert len(k8slist) > 0
70     k8s1 = k8slist[0]
71     k8s2 = stxSaClientImp.getK8sDetail(k8s1.name)
72     assert k8s1 != k8s2
73     assert k8s1.name == k8s2.name
74     assert k8s1.id == k8s2.id
75
76
77 def test_get_cpu_list(real_stx_aio_client):
78     stxSaClientImp = StxSaClientImp(real_stx_aio_client)
79     assert stxSaClientImp is not None
80     hostlist = stxSaClientImp.getPserverList()
81     assert len(hostlist) > 0
82
83     cpulist = stxSaClientImp.getCpuList(hostid=hostlist[0].id)
84     assert len(cpulist) > 0
85     cpu1 = cpulist[0]
86     cpu2 = stxSaClientImp.getCpu(cpu1.id)
87     assert cpu1 != cpu2
88     assert cpu1.id == cpu2.id
89
90
91 def test_get_mem_list(real_stx_aio_client):
92     stxSaClientImp = StxSaClientImp(real_stx_aio_client)
93     assert stxSaClientImp is not None
94     hostlist = stxSaClientImp.getPserverList()
95     assert len(hostlist) > 0
96
97     memlist = stxSaClientImp.getMemList(hostid=hostlist[0].id)
98     assert len(memlist) > 0
99     mem1 = memlist[0]
100     mem2 = stxSaClientImp.getMem(mem1.id)
101     assert mem1 != mem2
102     assert mem1.id == mem2.id
103
104
105 def test_get_eth_list(real_stx_aio_client):
106     stxSaClientImp = StxSaClientImp(real_stx_aio_client)
107     assert stxSaClientImp is not None
108     hostlist = stxSaClientImp.getPserverList()
109     assert len(hostlist) > 0
110
111     ethlist = stxSaClientImp.getEthernetList(hostid=hostlist[0].id)
112     assert len(ethlist) > 0
113     eth1 = ethlist[0]
114     eth2 = stxSaClientImp.getEthernet(eth1.id)
115     assert eth1 != eth2
116     assert eth1.id == eth2.id
117
118
119 def test_get_if_list(real_stx_aio_client):
120     stxSaClientImp = StxSaClientImp(real_stx_aio_client)
121     assert stxSaClientImp is not None
122     hostlist = stxSaClientImp.getPserverList()
123     assert len(hostlist) > 0
124
125     iflist = stxSaClientImp.getIfList(hostid=hostlist[0].id)
126     assert len(iflist) > 0
127     if1 = iflist[0]
128     if2 = stxSaClientImp.getIf(if1.id)
129     assert if1 != if2
130     assert if1.id == if2.id
131
132
133 def test_get_if_port_list(real_stx_aio_client):
134     stxSaClientImp = StxSaClientImp(real_stx_aio_client)
135     assert stxSaClientImp is not None
136     hostlist = stxSaClientImp.getPserverList()
137     assert len(hostlist) > 0
138
139     iflist = stxSaClientImp.getIfList(hostid=hostlist[0].id)
140     assert len(iflist) > 0
141
142     portlist = stxSaClientImp.getPortList(interfaceid=iflist[0].id)
143     assert len(portlist) > 0
144     port1 = portlist[0]
145     port2 = stxSaClientImp.getPort(port1.id)
146     assert port1 != port2
147     assert port1.id == port2.id