update from RIFT as of 696b75d2fe9fb046261b08c616f1bcf6c0b54a9b second try
[osm/SO.git] / rwlaunchpad / ra / pytest / test_launchpad.py
1 #!/usr/bin/env python3
2 """
3 #
4 # 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
25 import gi
26 import pytest
27
28 gi.require_version('RwsdnalYang', '1.0')
29
30 from gi.repository import RwsdnalYang
31 from gi.repository import RwSdnYang
32 from gi.repository import RwRoAccountYang
33
34 gi.require_version('RwKeyspec', '1.0')
35 from gi.repository.RwKeyspec import quoted_key
36
37 @pytest.mark.setup('sdn')
38 @pytest.mark.feature('sdn')
39 @pytest.mark.incremental
40 class 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 '''
47 proxy = mgmt_session.proxy(RwsdnalYang)
48 sdn_account = RwsdnalYang.YangData_RwProject_Project_SdnAccounts_SdnAccountList(
49 name=sdn_account_name,
50 account_type=sdn_account_type)
51 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)
78 sdn_account = proxy.get(xpath)
79
80 @pytest.mark.depends('sdn')
81 @pytest.mark.feature('sdn')
82 @pytest.mark.incremental
83 class 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 '''
90 proxy = mgmt_session.proxy(RwsdnalYang)
91 xpath = "/rw-project:project[rw-project:name='default']/sdn-accounts/sdn-account-list[name=%s]" % quoted_key(sdn_account_name)
92 sdn_account = proxy.get_config(xpath)
93 assert sdn_account.account_type == sdn_account_type
94
95 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
108 @pytest.mark.teardown('sdn')
109 @pytest.mark.feature('sdn')
110 @pytest.mark.incremental
111 class TestSdnTeardown:
112 def test_delete_odl_sdn_account(self, mgmt_session, sdn_account_name):
113 '''Unconfigure sdn account'''
114 proxy = mgmt_session.proxy(RwsdnalYang)
115 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))
122 proxy.delete_config(xpath)
123
124
125 @pytest.mark.setup('launchpad')
126 @pytest.mark.depends('sdn')
127 @pytest.mark.usefixtures('cloud_account')
128 @pytest.mark.incremental
129 class TestLaunchpadSetup:
130 def test_create_cloud_accounts(self, mgmt_session, cloud_module, cloud_xpath, cloud_accounts, l2_port_chaining, openstack_sdn_account_name):
131 '''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:
138 if l2_port_chaining:
139 cloud_account.sdn_account = openstack_sdn_account_name
140 xpath = '{}[name={}]'.format(cloud_xpath, quoted_key(cloud_account.name))
141 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
146 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(
155 '{}[name={}]/connection-status/status'.format(cloud_xpath, quoted_key(cloud_account.name)),
156 'success',
157 timeout=30,
158 fail_on=['failure'])
159
160 @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'])
175
176 @pytest.mark.teardown('launchpad')
177 @pytest.mark.usefixtures('cloud_account')
178 @pytest.mark.incremental
179 class 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:
184 xpath = "{}[name={}]".format(cloud_xpath, quoted_key(cloud_account.name))
185 proxy.delete_config(xpath)
186
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)))