80d739f6b2099070ad9bc69c020b3d04154b99b2
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
26 import rift
.rwcal
.openstack
30 gi
.require_version('RwCloudYang', '1.0')
32 from gi
.repository
import RwCloudYang
34 @pytest.fixture(scope
='session')
35 def cloud_name_prefix():
36 '''fixture which returns the prefix used in cloud account names'''
39 @pytest.fixture(scope
='session')
40 def cloud_account_name(cloud_name_prefix
):
41 '''fixture which returns the name used to identify the cloud account'''
42 return '{prefix}-0'.format(prefix
=cloud_name_prefix
)
44 @pytest.fixture(scope
='session')
45 def sdn_account_name():
46 '''fixture which returns the name used to identify the sdn account'''
49 @pytest.fixture(scope
='session')
50 def sdn_account_type():
51 '''fixture which returns the account type used by the sdn account'''
54 @pytest.fixture(scope
='session')
56 '''Fixture containing the module which defines cloud account
58 module to be used when configuring a cloud account
62 @pytest.fixture(scope
='session')
64 '''Fixture containing the xpath that should be used to configure a cloud account
66 xpath to be used when configure a cloud account
68 return '/cloud/account'
70 @pytest.fixture(scope
='session')
71 def cloud_accounts(cloud_module
, cloud_name_prefix
, cloud_host
, cloud_user
, cloud_tenants
, cloud_type
):
72 '''fixture which returns a list of CloudAccounts. One per tenant provided
75 cloud_module - fixture: module defining cloud account
76 cloud_name_prefix - fixture: name prefix used for cloud account
77 cloud_host - fixture: cloud host address
78 cloud_user - fixture: cloud account user key
79 cloud_tenants - fixture: list of tenants to create cloud accounts on
80 cloud_type - fixture: cloud account type
83 A list of CloudAccounts
86 for idx
, cloud_tenant
in enumerate(cloud_tenants
):
87 cloud_account_name
= "{prefix}-{idx}".format(prefix
=cloud_name_prefix
, idx
=idx
)
89 if cloud_type
== 'lxc':
91 cloud_module
.CloudAccount
.from_dict({
92 "name": cloud_account_name
,
93 "account_type": "cloudsim_proxy"})
95 elif cloud_type
== 'openstack':
97 auth_url
= 'http://{cloud_host}:5000/v3/'.format(cloud_host
=cloud_host
)
98 mgmt_network
= os
.getenv('MGMT_NETWORK', 'private')
100 cloud_module
.CloudAccount
.from_dict({
101 'name': cloud_account_name
,
102 'account_type': 'openstack',
107 'auth_url': auth_url
,
108 'tenant': cloud_tenant
,
109 'mgmt_network': mgmt_network
}})
111 elif cloud_type
== 'mock':
113 cloud_module
.CloudAccount
.from_dict({
114 "name": cloud_account_name
,
115 "account_type": "mock"})
121 @pytest.fixture(scope
='session', autouse
=True)
122 def cloud_account(cloud_accounts
):
123 '''fixture which returns an instance of CloudAccount
126 cloud_accounts - fixture: list of generated cloud accounts
129 An instance of CloudAccount
131 return cloud_accounts
[0]
133 @pytest.fixture(scope
='class')
134 def openstack_client(cloud_host
, cloud_user
, cloud_tenant
):
135 """Fixture which returns a session to openstack host.
138 Session to an openstack host.
140 password
= 'mypasswd'
141 auth_url
= 'http://{cloud_host}:5000/v3/'.format(cloud_host
=cloud_host
)
142 mgmt_network
= os
.getenv('MGMT_NETWORK', 'private')
143 return rift
.rwcal
.openstack
.OpenstackDriver(**{'username': cloud_user
,
144 'password': password
,
145 'auth_url': auth_url
,
146 'project' : cloud_tenant
,
147 'mgmt_network': mgmt_network
,
148 'cert_validate': False,
149 'user_domain': 'Default',
150 'project_domain':'Default',
151 'region': 'RegionOne'})