blob: 34a598e88bef8ffedfc0f9715f82809987900618 [file] [log] [blame]
Hanna Arhipova55cc1292019-01-08 14:22:18 +02001import pytest
Hanna Arhipova16e93fb2019-01-23 19:03:01 +02002import utils
Hanna Arhipova55cc1292019-01-08 14:22:18 +02003import random
4import time
Hanna Arhipova16e93fb2019-01-23 19:03:01 +02005from utils import os_client
Hanna Arhipova55cc1292019-01-08 14:22:18 +02006
7@pytest.fixture(scope='session')
8def local_salt_client():
9 return utils.init_salt_client()
10
11
12# TODO: fix
13# should not be executed on any test run
14nodes = utils.get_pairs()
15hw_nodes = utils.get_hw_pairs()
16
17
18@pytest.fixture(scope='session', params=nodes.values(), ids=nodes.keys())
19def pair(request):
20 return request.param
21
22
23@pytest.fixture(scope='session', params=hw_nodes.values(), ids=hw_nodes.keys())
24def hw_pair(request):
25 return request.param
26
27
28@pytest.fixture(scope='session')
29def openstack_clients(local_salt_client):
30 nodes_info = local_salt_client.cmd(
31 'keystone:server', 'pillar.get',
Oleksii Zhurbac8997a42019-06-03 13:24:53 -050032 ['keystone:client:os_client_config:cfgs:root:content:clouds:admin_identity'],
Hanna Arhipova55cc1292019-01-08 14:22:18 +020033 expr_form='pillar')
Oleksii Zhurbac8997a42019-06-03 13:24:53 -050034
Hanna Arhipova55cc1292019-01-08 14:22:18 +020035 if nodes_info.__len__() < 1:
36 pytest.skip("No keystone server found")
37 return False
38 keystone = nodes_info[nodes_info.keys()[0]]
Oleksii Zhurbac8997a42019-06-03 13:24:53 -050039 # TODO: region? OS_CACERT?
Hanna Arhipova55cc1292019-01-08 14:22:18 +020040 return os_client.OfficialClientManager(
Oleksii Zhurbac8997a42019-06-03 13:24:53 -050041 username=keystone['auth']['username'],
42 password=keystone['auth']['password'],
43 tenant_name=keystone['auth']['project_name'],
44 auth_url=keystone['auth']['auth_url'],
Hanna Arhipova55cc1292019-01-08 14:22:18 +020045 cert=False,
Oleksii Zhurbac8997a42019-06-03 13:24:53 -050046 # domain will be used as project_domain_name and user_domain_name
47 domain=keystone['auth']['project_domain_name'],
Hanna Arhipova55cc1292019-01-08 14:22:18 +020048 )
49
50
51@pytest.fixture(scope='session')
52def os_resources(openstack_clients):
53 os_actions = os_client.OSCliActions(openstack_clients)
54 os_resource = {}
55 config = utils.get_configuration()
56 image_name = config.get('image_name') or ['Ubuntu']
57
58 os_images_list = [image.id for image in openstack_clients.image.images.list(filters={'name': image_name})]
59 if os_images_list.__len__() == 0:
Hanna Arhipova04ac2002019-03-01 13:12:41 +020060 pytest.skip("No images with name {}. This name can be redefined with 'image_name' env var ".format(image_name))
Hanna Arhipova55cc1292019-01-08 14:22:18 +020061
62 os_resource['image_id'] = str(os_images_list[0])
63
64 os_resource['flavor_id'] = [flavor.id for flavor in openstack_clients.compute.flavors.list() if flavor.name == 'spt-test']
65 if not os_resource['flavor_id']:
66 os_resource['flavor_id'] = os_actions.create_flavor('spt-test', 1536, 1, 3).id
67 else:
68 os_resource['flavor_id'] = str(os_resource['flavor_id'][0])
69
70 os_resource['sec_group'] = os_actions.create_sec_group()
71 os_resource['keypair'] = openstack_clients.compute.keypairs.create('spt-test-{}'.format(random.randrange(100, 999)))
72 os_resource['net1'] = os_actions.create_network_resources()
73 os_resource['ext_net'] = os_actions.get_external_network()
74 adm_tenant = os_actions.get_admin_tenant()
75 os_resource['router'] = os_actions.create_router(os_resource['ext_net'], adm_tenant.id)
76 os_resource['net2'] = os_actions.create_network(adm_tenant.id)
Hanna Arhipovacbf1f3a2019-04-09 20:02:10 +030077 os_resource['subnet2'] = os_actions.create_subnet(os_resource['net2'], adm_tenant.id, '10.2.7.0/24')
Hanna Arhipova55cc1292019-01-08 14:22:18 +020078 for subnet in openstack_clients.network.list_subnets()['subnets']:
79 if subnet['network_id'] == os_resource['net1']['id']:
80 os_resource['subnet1'] = subnet['id']
81
82 openstack_clients.network.add_interface_router(os_resource['router']['id'], {'subnet_id': os_resource['subnet1']})
83 openstack_clients.network.add_interface_router(os_resource['router']['id'], {'subnet_id': os_resource['subnet2']['id']})
84 yield os_resource
85 # time.sleep(5)
86 openstack_clients.network.remove_interface_router(os_resource['router']['id'], {'subnet_id': os_resource['subnet1']})
87 openstack_clients.network.remove_interface_router(os_resource['router']['id'], {'subnet_id': os_resource['subnet2']['id']})
88 openstack_clients.network.remove_gateway_router(os_resource['router']['id'])
89 time.sleep(5)
90 openstack_clients.network.delete_router(os_resource['router']['id'])
91 time.sleep(5)
92 # openstack_clients.network.delete_subnet(subnet1['id'])
93 openstack_clients.network.delete_network(os_resource['net1']['id'])
94 openstack_clients.network.delete_network(os_resource['net2']['id'])
95
96 openstack_clients.compute.security_groups.delete(os_resource['sec_group'].id)
97 openstack_clients.compute.keypairs.delete(os_resource['keypair'].name)
98
99 openstack_clients.compute.flavors.delete(os_resource['flavor_id'])