| Jeremy Mordkoff | 6f07e6f | 2016-09-07 18:56:51 -0400 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
| 2 | """ |
| Jeremy Mordkoff | 4870d0e | 2017-09-30 20:28:33 -0400 | [diff] [blame^] | 3 | # |
| Jeremy Mordkoff | 6f07e6f | 2016-09-07 18:56:51 -0400 | [diff] [blame] | 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 | |
| Jeremy Mordkoff | 4870d0e | 2017-09-30 20:28:33 -0400 | [diff] [blame^] | 25 | import gi |
| Jeremy Mordkoff | 6f07e6f | 2016-09-07 18:56:51 -0400 | [diff] [blame] | 26 | import pytest |
| 27 | |
| Chamarty | 4bd9025 | 2017-04-03 17:26:43 -0400 | [diff] [blame] | 28 | gi.require_version('RwsdnalYang', '1.0') |
| Jeremy Mordkoff | 6f07e6f | 2016-09-07 18:56:51 -0400 | [diff] [blame] | 29 | |
| Chamarty | 4bd9025 | 2017-04-03 17:26:43 -0400 | [diff] [blame] | 30 | from gi.repository import RwsdnalYang |
| Jeremy Mordkoff | 4870d0e | 2017-09-30 20:28:33 -0400 | [diff] [blame^] | 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 |
| Jeremy Mordkoff | 6f07e6f | 2016-09-07 18:56:51 -0400 | [diff] [blame] | 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 | ''' |
| Chamarty | 4bd9025 | 2017-04-03 17:26:43 -0400 | [diff] [blame] | 47 | proxy = mgmt_session.proxy(RwsdnalYang) |
| Jeremy Mordkoff | 4870d0e | 2017-09-30 20:28:33 -0400 | [diff] [blame^] | 48 | sdn_account = RwsdnalYang.YangData_RwProject_Project_SdnAccounts_SdnAccountList( |
| Jeremy Mordkoff | 6f07e6f | 2016-09-07 18:56:51 -0400 | [diff] [blame] | 49 | name=sdn_account_name, |
| 50 | account_type=sdn_account_type) |
| Jeremy Mordkoff | 4870d0e | 2017-09-30 20:28:33 -0400 | [diff] [blame^] | 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) |
| Jeremy Mordkoff | 6f07e6f | 2016-09-07 18:56:51 -0400 | [diff] [blame] | 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 | ''' |
| Chamarty | 4bd9025 | 2017-04-03 17:26:43 -0400 | [diff] [blame] | 90 | proxy = mgmt_session.proxy(RwsdnalYang) |
| Jeremy Mordkoff | 4870d0e | 2017-09-30 20:28:33 -0400 | [diff] [blame^] | 91 | xpath = "/rw-project:project[rw-project:name='default']/sdn-accounts/sdn-account-list[name=%s]" % quoted_key(sdn_account_name) |
| Jeremy Mordkoff | 6f07e6f | 2016-09-07 18:56:51 -0400 | [diff] [blame] | 92 | sdn_account = proxy.get_config(xpath) |
| 93 | assert sdn_account.account_type == sdn_account_type |
| 94 | |
| Jeremy Mordkoff | 4870d0e | 2017-09-30 20:28:33 -0400 | [diff] [blame^] | 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 | |
| Jeremy Mordkoff | 6f07e6f | 2016-09-07 18:56:51 -0400 | [diff] [blame] | 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''' |
| Chamarty | 4bd9025 | 2017-04-03 17:26:43 -0400 | [diff] [blame] | 114 | proxy = mgmt_session.proxy(RwsdnalYang) |
| Jeremy Mordkoff | 4870d0e | 2017-09-30 20:28:33 -0400 | [diff] [blame^] | 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)) |
| Jeremy Mordkoff | 6f07e6f | 2016-09-07 18:56:51 -0400 | [diff] [blame] | 122 | proxy.delete_config(xpath) |
| 123 | |
| 124 | |
| 125 | @pytest.mark.setup('launchpad') |
| Jeremy Mordkoff | 4870d0e | 2017-09-30 20:28:33 -0400 | [diff] [blame^] | 126 | @pytest.mark.depends('sdn') |
| Jeremy Mordkoff | 6f07e6f | 2016-09-07 18:56:51 -0400 | [diff] [blame] | 127 | @pytest.mark.usefixtures('cloud_account') |
| 128 | @pytest.mark.incremental |
| 129 | class TestLaunchpadSetup: |
| Jeremy Mordkoff | 4870d0e | 2017-09-30 20:28:33 -0400 | [diff] [blame^] | 130 | def test_create_cloud_accounts(self, mgmt_session, cloud_module, cloud_xpath, cloud_accounts, l2_port_chaining, openstack_sdn_account_name): |
| Jeremy Mordkoff | 6f07e6f | 2016-09-07 18:56:51 -0400 | [diff] [blame] | 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: |
| Jeremy Mordkoff | 4870d0e | 2017-09-30 20:28:33 -0400 | [diff] [blame^] | 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)) |
| Jeremy Mordkoff | 6f07e6f | 2016-09-07 18:56:51 -0400 | [diff] [blame] | 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 | |
| Jeremy Mordkoff | 6f07e6f | 2016-09-07 18:56:51 -0400 | [diff] [blame] | 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( |
| Jeremy Mordkoff | 4870d0e | 2017-09-30 20:28:33 -0400 | [diff] [blame^] | 155 | '{}[name={}]/connection-status/status'.format(cloud_xpath, quoted_key(cloud_account.name)), |
| Jeremy Mordkoff | 6f07e6f | 2016-09-07 18:56:51 -0400 | [diff] [blame] | 156 | 'success', |
| 157 | timeout=30, |
| 158 | fail_on=['failure']) |
| 159 | |
| Jeremy Mordkoff | 4870d0e | 2017-09-30 20:28:33 -0400 | [diff] [blame^] | 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']) |
| Jeremy Mordkoff | 6f07e6f | 2016-09-07 18:56:51 -0400 | [diff] [blame] | 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: |
| Jeremy Mordkoff | 4870d0e | 2017-09-30 20:28:33 -0400 | [diff] [blame^] | 184 | xpath = "{}[name={}]".format(cloud_xpath, quoted_key(cloud_account.name)) |
| Jeremy Mordkoff | 6f07e6f | 2016-09-07 18:56:51 -0400 | [diff] [blame] | 185 | proxy.delete_config(xpath) |
| Jeremy Mordkoff | 4870d0e | 2017-09-30 20:28:33 -0400 | [diff] [blame^] | 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))) |