4 # Copyright 2017 RIFT.IO Inc
6 # Licensed under the Apache License, Version 2.0 (the "License");
7 # you may not use this file except in compliance with the License.
8 # You may obtain a copy of the License at
10 # http://www.apache.org/licenses/LICENSE-2.0
12 # Unless required by applicable law or agreed to in writing, software
13 # distributed under the License is distributed on an "AS IS" BASIS,
14 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 # See the License for the specific language governing permissions and
16 # limitations under the License.
26 import rift
.auto
.mano
as mano
28 from gi
.repository
import (
37 @pytest.fixture(scope
='session')
38 def ha_mgmt_sessions(sut_host_addrs
, session_type
):
39 """Fixture that returns mgmt sessions for active, standby LPs"""
41 for name
,addr
in sut_host_addrs
.items():
42 if session_type
== 'netconf':
43 mgmt_session
= rift
.auto
.session
.NetconfSession(host
=addr
)
44 elif session_type
== 'restconf':
45 mgmt_session
= rift
.auto
.session
.RestconfSession(host
=addr
)
48 sessions
['standby'] = mgmt_session
49 elif 'active' in name
:
50 sessions
['active'] = mgmt_session
51 mgmt_session
.connect()
52 rift
.vcs
.vcs
.wait_until_system_started(mgmt_session
)
56 @pytest.fixture(scope
='session')
57 def active_mgmt_session(ha_mgmt_sessions
):
58 """Fixture that returns mgmt sessions for active LP"""
59 return ha_mgmt_sessions
['active']
61 @pytest.fixture(scope
='session')
62 def standby_mgmt_session(ha_mgmt_sessions
):
63 """Fixture that returns mgmt sessions for standby LP"""
64 return ha_mgmt_sessions
['standby']
66 @pytest.fixture(scope
='session')
67 def active_confd_host(active_mgmt_session
):
68 """Fixture that returns mgmt sessions for active LP"""
69 return active_mgmt_session
.host
71 @pytest.fixture(scope
='session')
72 def standby_confd_host(standby_mgmt_session
):
73 """Fixture that returns mgmt sessions for standby LP"""
74 return standby_mgmt_session
.host
76 @pytest.fixture(scope
='session')
77 def revertive_pref_host(active_mgmt_session
):
78 """Fixture that returns mgmt sessions for active LP"""
79 return active_mgmt_session
.host
81 @pytest.fixture(scope
='session')
82 def active_site_name(active_mgmt_session
):
83 """Fixture that returns mgmt sessions for active LP"""
86 @pytest.fixture(scope
='session')
87 def standby_site_name(standby_mgmt_session
):
88 """Fixture that returns mgmt sessions for standby LP"""
91 @pytest.fixture(scope
='session', autouse
=True)
92 def redundancy_config_setup(logger
, active_confd_host
, standby_confd_host
, active_mgmt_session
):
93 """Fixture that prepares the rw-redundancy-config.xml file and copies it to RVR of active, standby systems;
94 starts the mock dns script in the revertive-preference host.
95 It assumes system-tests are running containers where launchpad runs in production mode"""
97 # Starts the mock dns script in revertive-preference host which is the active system.
98 ssh_mock_dns_cmd
= 'ssh -n -o BatchMode=yes -o StrictHostKeyChecking=no {revertive_pref_host} -- "python3 /usr/rift/usr/rift/systemtest/util/test_mock_dns.py --active-site site-a {active_host} --standby-site site-b {standby_host}"'.format(
99 revertive_pref_host
=active_confd_host
, active_host
=active_confd_host
, standby_host
=standby_confd_host
)
100 logger
.debug('Running mock dns script in host {host}; cmd: {ssh_cmd}'.format(host
=active_confd_host
,
101 ssh_cmd
=ssh_mock_dns_cmd
))
102 subprocess
.Popen(ssh_mock_dns_cmd
, shell
=True)
103 # Have to check if the script ran fine
105 # Prepares the rw-redundancy-config.xml file
106 redundancy_cfg_file_path
= os
.path
.join(os
.getenv('RIFT_INSTALL'),
107 'usr/rift/systemtest/config/rw-redundancy-config.xml')
108 with
open(redundancy_cfg_file_path
) as f
:
109 file_content
= f
.read()
111 with
open(redundancy_cfg_file_path
+'.auto', 'w') as f
:
112 new_content
= file_content
.replace('1.1.1.1', active_confd_host
).replace('2.2.2.2', standby_confd_host
)
113 logger
.debug('redundancy config file content: {}'.format(new_content
))
116 # Copies the redundancy config file to active, standby systems
117 for host_addr
in (active_confd_host
, standby_confd_host
):
118 scp_cmd
= 'scp -o StrictHostkeyChecking=no {file_path} {host}:/usr/rift/var/rift/rw-redundancy-config.xml'.format(
119 file_path
=redundancy_cfg_file_path
+'.auto', host
=host_addr
)
121 'Copying redundancy config xml to host {host}; scp cmd: {scp_cmd}'.format(host
=host_addr
, scp_cmd
=scp_cmd
))
122 assert os
.system(scp_cmd
) == 0
124 # Restart the launchpad service in active, standby systems
125 for host_addr
in (active_confd_host
, standby_confd_host
):
126 ssh_launchpad_restart_cmd
= 'ssh -n -o BatchMode=yes -o StrictHostKeyChecking=no {host} -- "sudo pkill rwmain"'.format(
128 logger
.debug('Restarting launchpad service in host {host}. cmd: {ssh_cmd}'.format(host
=host_addr
,
129 ssh_cmd
=ssh_launchpad_restart_cmd
))
130 assert os
.system(ssh_launchpad_restart_cmd
.format(host
=host_addr
)) == 0
133 active_mgmt_session
.connect()
134 rift
.vcs
.vcs
.wait_until_system_started(active_mgmt_session
)
135 mano
.verify_ha_redundancy_state(active_mgmt_session
)
137 @pytest.fixture(scope
='session')
138 def ha_lp_nodes(sut_host_addrs
, session_type
):
139 """Fixture that returns rift.auto.mano.LpNode objects for active, standby LPs"""
141 for name
,addr
in sut_host_addrs
.items():
142 lp_node
= mano
.LpNode(host
=addr
, session_type
=session_type
, connect
=False)
143 if 'standby' in name
:
144 lp_nodes
['standby'] = lp_node
145 elif 'active' in name
:
146 lp_nodes
['active'] = lp_node
150 @pytest.fixture(scope
='session')
151 def active_lp_node_obj(ha_lp_nodes
):
152 """Fixture that returns rift.auto.mano.LpNode object for active LP"""
153 return ha_lp_nodes
['active']
155 @pytest.fixture(scope
='session')
156 def standby_lp_node_obj(ha_lp_nodes
):
157 """Fixture that returns rift.auto.mano.LpNode object for standby LP"""
158 return ha_lp_nodes
['standby']
160 @pytest.fixture(scope
='session')
161 def rw_active_user_proxy(active_mgmt_session
):
162 return active_mgmt_session
.proxy(RwUserYang
)
164 @pytest.fixture(scope
='session')
165 def rw_active_project_proxy(active_mgmt_session
):
166 return active_mgmt_session
.proxy(RwProjectYang
)
168 @pytest.fixture(scope
='session')
169 def rw_active_rbac_int_proxy(active_mgmt_session
):
170 return active_mgmt_session
.proxy(RwRbacInternalYang
)
172 @pytest.fixture(scope
='session')
173 def rw_active_conman_proxy(active_mgmt_session
):
174 return active_mgmt_session
.proxy(RwConmanYang
)
176 @pytest.fixture(scope
='session')
177 def rbac_active_platform_proxy(active_mgmt_session
):
178 return active_mgmt_session
.proxy(RwRbacPlatformYang
)
180 @pytest.fixture(scope
='session')
181 def rw_active_cloud_pxy(active_mgmt_session
):
182 return active_mgmt_session
.proxy(RwCloudYang
)