3 # Copyright 2016 RIFT.IO Inc
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
9 # http://www.apache.org/licenses/LICENSE-2.0
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.
24 import rift
.auto
.session
29 gi
.require_version('RwCloudYang', '1.0')
31 from gi
.repository
import RwCloudYang
33 @pytest.fixture(scope
='session')
34 def cloud_name_prefix():
35 '''fixture which returns the prefix used in cloud account names'''
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
)
43 @pytest.fixture(scope
='session')
44 def sdn_account_name():
45 '''fixture which returns the name used to identify the sdn account'''
48 @pytest.fixture(scope
='session')
49 def sdn_account_type():
50 '''fixture which returns the account type used by the sdn account'''
53 @pytest.fixture(scope
='session')
55 '''Fixture containing the module which defines cloud account
57 module to be used when configuring a cloud account
61 @pytest.fixture(scope
='session')
63 '''Fixture containing the xpath that should be used to configure a cloud account
65 xpath to be used when configure a cloud account
67 return '/cloud/account'
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
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
82 A list of CloudAccounts
85 for idx
, cloud_tenant
in enumerate(cloud_tenants
):
86 cloud_account_name
= "{prefix}-{idx}".format(prefix
=cloud_name_prefix
, idx
=idx
)
88 if cloud_type
== 'lxc':
90 cloud_module
.CloudAccount
.from_dict({
91 "name": cloud_account_name
,
92 "account_type": "cloudsim_proxy"})
94 elif cloud_type
== 'openstack':
96 auth_url
= 'http://{cloud_host}:5000/v3/'.format(cloud_host
=cloud_host
)
97 mgmt_network
= os
.getenv('MGMT_NETWORK', 'private')
99 cloud_module
.CloudAccount
.from_dict({
100 'name': cloud_account_name
,
101 'account_type': 'openstack',
106 'auth_url': auth_url
,
107 'tenant': cloud_tenant
,
108 'mgmt_network': mgmt_network
}})
110 elif cloud_type
== 'mock':
112 cloud_module
.CloudAccount
.from_dict({
113 "name": cloud_account_name
,
114 "account_type": "mock"})
120 @pytest.fixture(scope
='session', autouse
=True)
121 def cloud_account(cloud_accounts
):
122 '''fixture which returns an instance of CloudAccount
125 cloud_accounts - fixture: list of generated cloud accounts
128 An instance of CloudAccount
130 return cloud_accounts
[0]