| Jeremy Mordkoff | 6f07e6f | 2016-09-07 18:56:51 -0400 | [diff] [blame] | 1 | |
| 2 | # |
| 3 | # Copyright 2016 RIFT.IO Inc |
| 4 | # |
| 5 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | # you may not use this file except in compliance with the License. |
| 7 | # You may obtain a copy of the License at |
| 8 | # |
| 9 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | # |
| 11 | # Unless required by applicable law or agreed to in writing, software |
| 12 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | # See the License for the specific language governing permissions and |
| 15 | # limitations under the License. |
| 16 | # |
| 17 | |
| 18 | import pytest |
| 19 | import os |
| 20 | import subprocess |
| 21 | import sys |
| 22 | |
| 23 | import rift.auto.log |
| 24 | import rift.auto.session |
| 25 | import rift.vcs.vcs |
| 26 | import logging |
| 27 | |
| 28 | import gi |
| 29 | gi.require_version('RwCloudYang', '1.0') |
| 30 | |
| 31 | from gi.repository import RwCloudYang |
| 32 | |
| 33 | @pytest.fixture(scope='session') |
| 34 | def cloud_name_prefix(): |
| 35 | '''fixture which returns the prefix used in cloud account names''' |
| 36 | return 'cloud' |
| 37 | |
| 38 | @pytest.fixture(scope='session') |
| 39 | def cloud_account_name(cloud_name_prefix): |
| 40 | '''fixture which returns the name used to identify the cloud account''' |
| 41 | return '{prefix}-0'.format(prefix=cloud_name_prefix) |
| 42 | |
| 43 | @pytest.fixture(scope='session') |
| 44 | def sdn_account_name(): |
| 45 | '''fixture which returns the name used to identify the sdn account''' |
| 46 | return 'sdn-0' |
| 47 | |
| 48 | @pytest.fixture(scope='session') |
| 49 | def sdn_account_type(): |
| 50 | '''fixture which returns the account type used by the sdn account''' |
| 51 | return 'odl' |
| 52 | |
| 53 | @pytest.fixture(scope='session') |
| 54 | def cloud_module(): |
| 55 | '''Fixture containing the module which defines cloud account |
| 56 | Returns: |
| 57 | module to be used when configuring a cloud account |
| 58 | ''' |
| 59 | return RwCloudYang |
| 60 | |
| 61 | @pytest.fixture(scope='session') |
| 62 | def cloud_xpath(): |
| 63 | '''Fixture containing the xpath that should be used to configure a cloud account |
| 64 | Returns: |
| 65 | xpath to be used when configure a cloud account |
| 66 | ''' |
| 67 | return '/cloud/account' |
| 68 | |
| 69 | @pytest.fixture(scope='session') |
| 70 | def cloud_accounts(cloud_module, cloud_name_prefix, cloud_host, cloud_user, cloud_tenants, cloud_type): |
| 71 | '''fixture which returns a list of CloudAccounts. One per tenant provided |
| 72 | |
| 73 | Arguments: |
| 74 | cloud_module - fixture: module defining cloud account |
| 75 | cloud_name_prefix - fixture: name prefix used for cloud account |
| 76 | cloud_host - fixture: cloud host address |
| 77 | cloud_user - fixture: cloud account user key |
| 78 | cloud_tenants - fixture: list of tenants to create cloud accounts on |
| 79 | cloud_type - fixture: cloud account type |
| 80 | |
| 81 | Returns: |
| 82 | A list of CloudAccounts |
| 83 | ''' |
| 84 | accounts = [] |
| 85 | for idx, cloud_tenant in enumerate(cloud_tenants): |
| 86 | cloud_account_name = "{prefix}-{idx}".format(prefix=cloud_name_prefix, idx=idx) |
| 87 | |
| 88 | if cloud_type == 'lxc': |
| 89 | accounts.append( |
| 90 | cloud_module.CloudAccount.from_dict({ |
| 91 | "name": cloud_account_name, |
| 92 | "account_type": "cloudsim_proxy"}) |
| 93 | ) |
| 94 | elif cloud_type == 'openstack': |
| 95 | password = 'mypasswd' |
| 96 | auth_url = 'http://{cloud_host}:5000/v3/'.format(cloud_host=cloud_host) |
| 97 | mgmt_network = os.getenv('MGMT_NETWORK', 'private') |
| 98 | accounts.append( |
| 99 | cloud_module.CloudAccount.from_dict({ |
| 100 | 'name': cloud_account_name, |
| 101 | 'account_type': 'openstack', |
| 102 | 'openstack': { |
| 103 | 'admin': True, |
| 104 | 'key': cloud_user, |
| 105 | 'secret': password, |
| 106 | 'auth_url': auth_url, |
| 107 | 'tenant': cloud_tenant, |
| 108 | 'mgmt_network': mgmt_network}}) |
| 109 | ) |
| 110 | elif cloud_type == 'mock': |
| 111 | accounts.append( |
| 112 | cloud_module.CloudAccount.from_dict({ |
| 113 | "name": cloud_account_name, |
| 114 | "account_type": "mock"}) |
| 115 | ) |
| 116 | |
| 117 | return accounts |
| 118 | |
| 119 | |
| 120 | @pytest.fixture(scope='session', autouse=True) |
| 121 | def cloud_account(cloud_accounts): |
| 122 | '''fixture which returns an instance of CloudAccount |
| 123 | |
| 124 | Arguments: |
| 125 | cloud_accounts - fixture: list of generated cloud accounts |
| 126 | |
| 127 | Returns: |
| 128 | An instance of CloudAccount |
| 129 | ''' |
| 130 | return cloud_accounts[0] |
| 131 | |