blob: 2a275bcee292ac661e6486886c4659df1f85e115 [file] [log] [blame]
Jeremy Mordkoff6f07e6f2016-09-07 18:56:51 -04001#!/usr/bin/env python3
2"""
Jeremy Mordkoff4870d0e2017-09-30 20:28:33 -04003#
Jeremy Mordkoff6f07e6f2016-09-07 18:56:51 -04004# Copyright 2016 RIFT.IO Inc
5#
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
9#
10# http://www.apache.org/licenses/LICENSE-2.0
11#
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.
17#
18
19@file test_launchpad.py
20@author Paul Laidler (Paul.Laidler@riftio.com)
21@date 07/07/2016
22@brief System test of basic launchpad functionality
23"""
24
Jeremy Mordkoff4870d0e2017-09-30 20:28:33 -040025import gi
Jeremy Mordkoff6f07e6f2016-09-07 18:56:51 -040026import pytest
27
Chamarty4bd90252017-04-03 17:26:43 -040028gi.require_version('RwsdnalYang', '1.0')
Jeremy Mordkoff6f07e6f2016-09-07 18:56:51 -040029
Chamarty4bd90252017-04-03 17:26:43 -040030from gi.repository import RwsdnalYang
Jeremy Mordkoff4870d0e2017-09-30 20:28:33 -040031from gi.repository import RwSdnYang
32from gi.repository import RwRoAccountYang
33
34gi.require_version('RwKeyspec', '1.0')
35from gi.repository.RwKeyspec import quoted_key
Jeremy Mordkoff6f07e6f2016-09-07 18:56:51 -040036
37@pytest.mark.setup('sdn')
38@pytest.mark.feature('sdn')
39@pytest.mark.incremental
40class TestSdnSetup:
41 def test_create_odl_sdn_account(self, mgmt_session, sdn_account_name, sdn_account_type):
42 '''Configure sdn account
43
44 Asserts:
45 SDN name and accout type.
46 '''
Chamarty4bd90252017-04-03 17:26:43 -040047 proxy = mgmt_session.proxy(RwsdnalYang)
Jeremy Mordkoff4870d0e2017-09-30 20:28:33 -040048 sdn_account = RwsdnalYang.YangData_RwProject_Project_SdnAccounts_SdnAccountList(
Jeremy Mordkoff6f07e6f2016-09-07 18:56:51 -040049 name=sdn_account_name,
50 account_type=sdn_account_type)
Jeremy Mordkoff4870d0e2017-09-30 20:28:33 -040051 xpath = "/rw-project:project[rw-project:name='default']/sdn-accounts/sdn-account-list[name=%s]" % quoted_key(sdn_account_name)
52 proxy.replace_config(xpath, sdn_account)
53 sdn_account = proxy.get(xpath)
54
55 def test_create_openstack_sdn_account(self, mgmt_session, openstack_sdn_account_name, cloud_account):
56 '''Configure sdn account
57
58 Asserts:
59 SDN name and account type.
60 '''
61 proxy = mgmt_session.proxy(RwSdnYang)
62 sdn_account = RwSdnYang.YangData_RwProject_Project_Sdn_Account.from_dict({
63 'name': openstack_sdn_account_name,
64 'account_type': 'openstack',
65 'openstack': {
66 'admin': cloud_account.openstack.admin,
67 'key': cloud_account.openstack.key,
68 'secret': cloud_account.openstack.secret,
69 'auth_url': cloud_account.openstack.auth_url,
70 'tenant': cloud_account.openstack.tenant,
71 'project_domain': cloud_account.openstack.project_domain,
72 'user_domain': cloud_account.openstack.user_domain,
73 'region': cloud_account.openstack.region,
74 }})
75
76 xpath = "/rw-project:project[rw-project:name='default']/sdn/account[name={}]".format(quoted_key(openstack_sdn_account_name))
77 proxy.replace_config(xpath, sdn_account)
Jeremy Mordkoff6f07e6f2016-09-07 18:56:51 -040078 sdn_account = proxy.get(xpath)
79
80@pytest.mark.depends('sdn')
81@pytest.mark.feature('sdn')
82@pytest.mark.incremental
83class TestSdn:
84 def test_show_odl_sdn_account(self, mgmt_session, sdn_account_name, sdn_account_type):
85 '''Showing sdn account configuration
86
87 Asserts:
88 sdn_account.account_type is what was configured
89 '''
Chamarty4bd90252017-04-03 17:26:43 -040090 proxy = mgmt_session.proxy(RwsdnalYang)
Jeremy Mordkoff4870d0e2017-09-30 20:28:33 -040091 xpath = "/rw-project:project[rw-project:name='default']/sdn-accounts/sdn-account-list[name=%s]" % quoted_key(sdn_account_name)
Jeremy Mordkoff6f07e6f2016-09-07 18:56:51 -040092 sdn_account = proxy.get_config(xpath)
93 assert sdn_account.account_type == sdn_account_type
94
Jeremy Mordkoff4870d0e2017-09-30 20:28:33 -040095 def test_openstack_sdn_account_connection_status(self, mgmt_session, openstack_sdn_account_name):
96 '''Verify connection status on openstack sdn account
97
98 Asserts:
99 openstack sdn account is successfully connected
100 '''
101 proxy = mgmt_session.proxy(RwSdnYang)
102 proxy.wait_for(
103 '/rw-project:project[rw-project:name="default"]/sdn/account[name={}]/connection-status/status'.format(quoted_key(openstack_sdn_account_name)),
104 'success',
105 timeout=30,
106 fail_on=['failure'])
107
Jeremy Mordkoff6f07e6f2016-09-07 18:56:51 -0400108@pytest.mark.teardown('sdn')
109@pytest.mark.feature('sdn')
110@pytest.mark.incremental
111class TestSdnTeardown:
112 def test_delete_odl_sdn_account(self, mgmt_session, sdn_account_name):
113 '''Unconfigure sdn account'''
Chamarty4bd90252017-04-03 17:26:43 -0400114 proxy = mgmt_session.proxy(RwsdnalYang)
Jeremy Mordkoff4870d0e2017-09-30 20:28:33 -0400115 xpath = "/rw-project:project[rw-project:name='default']/sdn-accounts/sdn-account-list[name=%s]" % quoted_key(sdn_account_name)
116 proxy.delete_config(xpath)
117
118 def test_delete_openstack_sdn_account(self, mgmt_session, openstack_sdn_account_name):
119 '''Unconfigure sdn account'''
120 proxy = mgmt_session.proxy(RwSdnYang)
121 xpath = '/rw-project:project[rw-project:name="default"]/sdn/account[name={}]'.format(quoted_key(openstack_sdn_account_name))
Jeremy Mordkoff6f07e6f2016-09-07 18:56:51 -0400122 proxy.delete_config(xpath)
123
124
125@pytest.mark.setup('launchpad')
Jeremy Mordkoff4870d0e2017-09-30 20:28:33 -0400126@pytest.mark.depends('sdn')
Jeremy Mordkoff6f07e6f2016-09-07 18:56:51 -0400127@pytest.mark.usefixtures('cloud_account')
128@pytest.mark.incremental
129class TestLaunchpadSetup:
Jeremy Mordkoff4870d0e2017-09-30 20:28:33 -0400130 def test_create_cloud_accounts(self, mgmt_session, cloud_module, cloud_xpath, cloud_accounts, l2_port_chaining, openstack_sdn_account_name):
Jeremy Mordkoff6f07e6f2016-09-07 18:56:51 -0400131 '''Configure cloud accounts
132
133 Asserts:
134 Cloud name and cloud type details
135 '''
136 proxy = mgmt_session.proxy(cloud_module)
137 for cloud_account in cloud_accounts:
Jeremy Mordkoff4870d0e2017-09-30 20:28:33 -0400138 if l2_port_chaining:
139 cloud_account.sdn_account = openstack_sdn_account_name
140 xpath = '{}[name={}]'.format(cloud_xpath, quoted_key(cloud_account.name))
Jeremy Mordkoff6f07e6f2016-09-07 18:56:51 -0400141 proxy.replace_config(xpath, cloud_account)
142 response = proxy.get(xpath)
143 assert response.name == cloud_account.name
144 assert response.account_type == cloud_account.account_type
145
Jeremy Mordkoff6f07e6f2016-09-07 18:56:51 -0400146 def test_account_connection_status(self, mgmt_session, cloud_module, cloud_xpath, cloud_accounts):
147 '''Verify connection status on each cloud account
148
149 Asserts:
150 Cloud account is successfully connected
151 '''
152 proxy = mgmt_session.proxy(cloud_module)
153 for cloud_account in cloud_accounts:
154 proxy.wait_for(
Jeremy Mordkoff4870d0e2017-09-30 20:28:33 -0400155 '{}[name={}]/connection-status/status'.format(cloud_xpath, quoted_key(cloud_account.name)),
Jeremy Mordkoff6f07e6f2016-09-07 18:56:51 -0400156 'success',
157 timeout=30,
158 fail_on=['failure'])
159
Jeremy Mordkoff4870d0e2017-09-30 20:28:33 -0400160 @pytest.mark.feature('openmano')
161 def test_create_ro_accounts(self, mgmt_session, ro_accounts):
162 for name, ro_account in ro_accounts.items():
163 mgmt_session.proxy(RwRoAccountYang).create_config('/rw-project:project[rw-project:name="default"]/ro-account/account', ro_account)
164
165 @pytest.mark.feature('openmano')
166 def test_ro_account_connection_status(self, mgmt_session, ro_accounts):
167 for name, ro_account in ro_accounts.items():
168 mgmt_session.proxy(RwRoAccountYang).wait_for((
169 '/rw-project:project[rw-project:name="default"]'
170 '/ro-account-state/account[name={account_name}]/connection-status/status'
171 ).format(account_name=quoted_key(ro_account.name)),
172 'success',
173 timeout=30,
174 fail_on=['failure'])
Jeremy Mordkoff6f07e6f2016-09-07 18:56:51 -0400175
176@pytest.mark.teardown('launchpad')
177@pytest.mark.usefixtures('cloud_account')
178@pytest.mark.incremental
179class TestLaunchpadTeardown:
180 def test_delete_cloud_accounts(self, mgmt_session, cloud_module, cloud_xpath, cloud_accounts):
181 '''Unconfigure cloud_account'''
182 proxy = mgmt_session.proxy(cloud_module)
183 for cloud_account in cloud_accounts:
Jeremy Mordkoff4870d0e2017-09-30 20:28:33 -0400184 xpath = "{}[name={}]".format(cloud_xpath, quoted_key(cloud_account.name))
Jeremy Mordkoff6f07e6f2016-09-07 18:56:51 -0400185 proxy.delete_config(xpath)
Jeremy Mordkoff4870d0e2017-09-30 20:28:33 -0400186
187 @pytest.mark.feature('openmano')
188 def test_delete_ro_accounts(self, mgmt_session, ro_accounts):
189 for name, ro_account in ro_accounts.items():
190 xpath = "/rw-project:project[rw-project:name='default']/ro-account/account[name={}]"
191 mgmt_session.proxy(RwRoAccountYang).delete_config(xpath.format(quoted_key(name)))