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.
25 import rift
.auto
.mano
as mano
26 import rift
.auto
.descriptor
27 from gi
.repository
.RwKeyspec
import quoted_key
29 from gi
.repository
import (
39 @pytest.mark
.setup('active_configuration')
40 @pytest.mark
.incremental
41 class TestActiveLpConfiguration(object):
42 """Setting up the configuration."""
44 def collect_active_lp_data(
45 self
, active_lp_node_obj
, active_confd_host
,
46 standby_confd_host
, logger
):
47 """Collect active lp data."""
48 mano
.verify_hagr_endpoints(active_confd_host
, standby_confd_host
)
49 active_lp_node_obj
.collect_data()
51 def wait_for_standby_to_comeup(
52 self
, standby_mgmt_session
, active_confd_host
, standby_confd_host
):
53 """Wait for the standby to come up.
55 Wait for endpoint 'ha/geographic/active' to return 200
57 mano
.wait_for_standby_to_become_active(standby_mgmt_session
)
58 # mano.verify_hagr_endpoints(
59 # active_host=standby_confd_host, standby_host=active_confd_host)
61 def collect_standby_lp_data(
62 self
, standby_lp_node_obj
, standby_mgmt_session
, cloud_account
,
63 fmt_cloud_xpath
, projects
, fmt_nsd_catalog_xpath
):
64 """Collect standby lp data."""
66 rw_new_active_cloud_pxy
= standby_mgmt_session
.proxy(RwCloudYang
)
67 nsd_pxy
= standby_mgmt_session
.proxy(RwProjectNsdYang
)
68 rwnsr_proxy
= standby_mgmt_session
.proxy(RwNsrYang
)
70 for project_name
in projects
:
71 rw_new_active_cloud_pxy
.wait_for(
72 fmt_cloud_xpath
.format(
73 project
=quoted_key(project_name
),
74 account_name
=quoted_key(cloud_account
.name
)) +
75 '/connection-status/status', 'success',
76 timeout
=60, fail_on
=['failure'])
78 # nsd_catalog = nsd_pxy.get_config(
79 # fmt_nsd_catalog_xpath.format(project=quoted_key(project_name)))
82 if pytest
.config
.getoption("--nsr-test"):
83 nsr_opdata
= rwnsr_proxy
.get(
84 '/rw-project:project[rw-project:name={project}]' +
85 '/ns-instance-opdata'.format(
86 project
=quoted_key(project_name
))
94 '/rw-project:project[rw-project:name={project}]' +
95 '/ns-instance-opdata/nsr[ns-instance-config-ref=' +
96 '{config_ref}]/config-status'.format(
97 project
=quoted_key(project_name
),
98 config_ref
=quoted_key(nsr
.ns_instance_config_ref
))
101 rwnsr_proxy
.wait_for(
102 xpath
, "configured", fail_on
=['failed'], timeout
=400)
104 standby_lp_node_obj
.collect_data()
106 def attempt_indirect_failover(
107 self
, revertive_pref_host
, active_confd_host
, standby_confd_host
,
108 active_site_name
, standby_site_name
, logger
):
109 """Try indirect failover."""
112 'Attempting first failover. Host {} will be new active'.format(
115 mano
.indirect_failover(
116 revertive_pref_host
, new_active_ip
=standby_confd_host
,
117 new_active_site
=standby_site_name
,
118 new_standby_ip
=active_confd_host
,
119 new_standby_site
=active_site_name
)
121 def match_active_standby(self
, active_lp_node_obj
, standby_lp_node_obj
):
122 """Compare active standby."""
123 active_lp_node_obj
.compare(standby_lp_node_obj
)
125 def test_create_project_users_cloud_acc(
126 self
, rbac_user_passwd
, user_domain
, rw_active_user_proxy
, logger
,
127 rw_active_project_proxy
, rw_active_rbac_int_proxy
, cloud_account
,
128 rw_active_conman_proxy
, rw_active_cloud_pxy
, user_roles
,
129 fmt_prefixed_cloud_xpath
, fmt_cloud_xpath
, descriptors
,
130 active_mgmt_session
, fmt_nsd_catalog_xpath
, active_lp_node_obj
,
131 standby_lp_node_obj
, active_confd_host
, standby_confd_host
,
132 revertive_pref_host
, active_site_name
, standby_site_name
,
133 standby_mgmt_session
):
134 """Create 3 of users, projects, cloud accounts, decriptors & nsrs."""
135 def failover_and_match():
136 """Try an indirect failover.
138 Match active and standby data
140 self
.collect_active_lp_data(
141 active_lp_node_obj
, active_confd_host
,
142 standby_confd_host
, logger
)
143 self
.attempt_indirect_failover(
144 revertive_pref_host
, active_confd_host
, standby_confd_host
,
145 active_site_name
, standby_site_name
, logger
)
146 self
.wait_for_standby_to_comeup(
147 standby_mgmt_session
, active_confd_host
, standby_confd_host
)
148 self
.collect_standby_lp_data(
149 standby_lp_node_obj
, standby_mgmt_session
, cloud_account
,
150 fmt_cloud_xpath
, projects
, fmt_nsd_catalog_xpath
)
151 self
.match_active_standby(active_lp_node_obj
, standby_lp_node_obj
)
153 def delete_data_set(idx
):
155 rift
.auto
.descriptor
.terminate_nsr(
156 rwvnfr_pxy
, rwnsr_pxy
, rwvlr_pxy
, logger
,
157 project
=projects
[idx
])
159 rift
.auto
.descriptor
.delete_descriptors(
160 active_mgmt_session
, project_name
)
162 rw_active_cloud_pxy
.delete_config(
163 fmt_prefixed_cloud_xpath
.format(
164 project
=quoted_key(projects
[idx
]),
165 account_name
=quoted_key(cloud_account
.name
)
168 response
= rw_active_cloud_pxy
.get(
169 fmt_cloud_xpath
.format(
170 project
=quoted_key(projects
[idx
]),
171 account_name
=quoted_key(cloud_account
.name
)
174 assert response
is None
176 mano
.delete_project(rw_active_conman_proxy
, projects
[idx
])
178 mano
.delete_user(rw_active_user_proxy
, users
[idx
], user_domain
)
182 user_name_pfx
= 'user_ha_'
184 for idx
in range(1, 4):
185 users
.append(user_name_pfx
+ str(idx
))
188 rw_active_user_proxy
, user_name_pfx
+ str(idx
),
189 rbac_user_passwd
, user_domain
)
191 # Create projects and assign roles to users
192 prj_name_pfx
= 'prj_ha_'
194 for idx
in range(1, 4):
195 project_name
= prj_name_pfx
+ str(idx
)
196 projects
.append(project_name
)
198 rw_active_conman_proxy
, project_name
)
200 for idx
in range(0, 3):
201 project_name
= projects
[idx
]
202 role
= random
.choice(user_roles
)
205 'Assinging role {} to user {} in project {}'.format(
206 role
, user
, project_name
))
208 mano
.assign_project_role_to_user(
209 rw_active_project_proxy
, role
, user
, project_name
,
210 user_domain
, rw_active_rbac_int_proxy
)
213 'Creating cloud account {} for project {}'.format(
214 cloud_account
.name
, project_name
))
216 xpath
= fmt_prefixed_cloud_xpath
.format(
217 project
=quoted_key(project_name
),
218 account_name
=quoted_key(cloud_account
.name
))
220 rw_active_cloud_pxy
.replace_config(xpath
, cloud_account
)
222 xpath_no_pfx
= fmt_cloud_xpath
.format(
223 project
=quoted_key(project_name
),
224 account_name
=quoted_key(cloud_account
.name
))
226 response
= rw_active_cloud_pxy
.get(xpath_no_pfx
)
227 assert response
.name
== cloud_account
.name
228 assert response
.account_type
== cloud_account
.account_type
230 rw_active_cloud_pxy
.wait_for(
231 fmt_cloud_xpath
.format(
232 project
=quoted_key(project_name
),
233 account_name
=quoted_key(cloud_account
.name
)) +
234 '/connection-status/status', 'success', timeout
=30,
237 # Uploads the descriptors
238 for descriptor
in descriptors
:
239 rift
.auto
.descriptor
.onboard(
240 active_mgmt_session
, descriptor
, project
=project_name
)
242 # Verify whether the descriptors uploaded successfully
244 'Onboarding descriptors for project {}'.format(project_name
))
246 nsd_pxy
= active_mgmt_session
.proxy(RwProjectNsdYang
)
247 rwnsr_pxy
= active_mgmt_session
.proxy(RwNsrYang
)
248 rwvnfr_pxy
= active_mgmt_session
.proxy(RwVnfrYang
)
249 rwvlr_pxy
= active_mgmt_session
.proxy(RwVlrYang
)
251 nsd_xpath
= fmt_nsd_catalog_xpath
.format(
252 project
=quoted_key(project_name
))
253 nsd_catalog
= nsd_pxy
.get_config(nsd_xpath
)
256 nsd_xpath
= fmt_nsd_catalog_xpath
.format(
257 project
=quoted_key(project_name
))
258 nsd_catalog
= nsd_pxy
.get_config(nsd_xpath
)
260 nsd
= nsd_catalog
.nsd
[0]
261 nsr
= rift
.auto
.descriptor
.create_nsr(
262 cloud_account
.name
, nsd
.name
, nsd
)
265 'Instantiating NS for project {}'.format(project_name
))
266 rift
.auto
.descriptor
.instantiate_nsr(
267 nsr
, rwnsr_pxy
, logger
, project
=project_name
)