Skip to content

Commit

Permalink
Use keystoneclient v3 intead of v2.0
Browse files Browse the repository at this point in the history
Change-Id: I88d39369894d5cc578fc81abf5dd6ce24381a4d3
Fix-Bug: #PROD-26297(PROD:26297)
  • Loading branch information
Hanna Arhipova committed Jan 15, 2019
1 parent a97f4c4 commit 44caf35
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 27 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# cvp-spt
Environment variables
--
* Set *keystone_api_version* to required keystone API version (like keystone_api_version=v2.0)
Or it will be set to 'v3' otherwise
* Set *keystone_api_version* to required keystone API version (like keystone_api_version=2)
Or it will be set to '3' otherwise
23 changes: 14 additions & 9 deletions cvp_spt/fixtures/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,25 @@
def local_salt_client():
return utils.init_salt_client()


# TODO: fix
# should not be executed on any test run
nodes = utils.get_pairs()
hw_nodes = utils.get_hw_pairs()


@pytest.fixture(scope='session', params=nodes.values(), ids=nodes.keys())
def pair(request):
return request.param


@pytest.fixture(scope='session', params=hw_nodes.values(), ids=hw_nodes.keys())
def hw_pair(request):
return request.param


@pytest.fixture(scope='session')
def openstack_clients(local_salt_client):
keystone_api_version = utils.get_configuration().get("keystone_api_version")
nodes_info = local_salt_client.cmd(
'keystone:server', 'pillar.get',
['keystone:server'],
Expand All @@ -32,9 +35,8 @@ def openstack_clients(local_salt_client):
pytest.skip("No keystone server found")
return False
keystone = nodes_info[nodes_info.keys()[0]]
url = 'http://{ip}:{port}/{api_version}'.format(ip=keystone['bind']['private_address'],
port=keystone['bind']['private_port'],
api_version="v3" if (keystone_api_version is None) else keystone_api_version)
url = 'http://{ip}:{port}/'.format(ip=keystone['bind']['public_address'],
port=keystone['bind']['public_port'])
return os_client.OfficialClientManager(
username=keystone['admin_name'],
password=keystone['admin_password'],
Expand All @@ -44,18 +46,21 @@ def openstack_clients(local_salt_client):
domain='Default',
)


@pytest.fixture(scope='session')
def os_resources(openstack_clients):
os_actions = os_client.OSCliActions(openstack_clients)
os_resource = {}
config = utils.get_configuration()
image_name = config.get('image_name') or ['Ubuntu']
os_resource['image_id'] = str([image.id for image in openstack_clients.image.images.list(filters={'name': image_name})][0])

if not os_resource['image_id']:
print "No image ID. Exiting"
os_images_list = [image.id for image in openstack_clients.image.images.list(filters={'name': image_name})]
if os_images_list.__len__() == 0:
print "No images with name {}. This name can be redefined with 'image_name' env var ".format(image_name)
exit()

os_resource['image_id'] = str(os_images_list[0])

os_resource['flavor_id'] = [flavor.id for flavor in openstack_clients.compute.flavors.list() if flavor.name == 'spt-test']
if not os_resource['flavor_id']:
os_resource['flavor_id'] = os_actions.create_flavor('spt-test', 1536, 1, 3).id
Expand All @@ -77,14 +82,14 @@ def os_resources(openstack_clients):
openstack_clients.network.add_interface_router(os_resource['router']['id'], {'subnet_id': os_resource['subnet1']})
openstack_clients.network.add_interface_router(os_resource['router']['id'], {'subnet_id': os_resource['subnet2']['id']})
yield os_resource
#time.sleep(5)
# time.sleep(5)
openstack_clients.network.remove_interface_router(os_resource['router']['id'], {'subnet_id': os_resource['subnet1']})
openstack_clients.network.remove_interface_router(os_resource['router']['id'], {'subnet_id': os_resource['subnet2']['id']})
openstack_clients.network.remove_gateway_router(os_resource['router']['id'])
time.sleep(5)
openstack_clients.network.delete_router(os_resource['router']['id'])
time.sleep(5)
#openstack_clients.network.delete_subnet(subnet1['id'])
# openstack_clients.network.delete_subnet(subnet1['id'])
openstack_clients.network.delete_network(os_resource['net1']['id'])
openstack_clients.network.delete_network(os_resource['net2']['id'])

Expand Down
6 changes: 4 additions & 2 deletions cvp_spt/tests/test_glance.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@

@pytest.fixture
def create_image():
line = 'dd if=/dev/zero of=/tmp/image_mk_framework.dd ' \
'bs=1M count=9000'
line = 'echo "Executing dd on $(hostname -f)"; ' \
'dd if=/dev/zero of=/tmp/image_mk_framework.dd bs=1M count=9000 ;' \
'echo "Free space :" ; ' \
'df -H / '

subprocess.call(line.split())
yield
Expand Down
2 changes: 1 addition & 1 deletion cvp_spt/tests/test_vm2vm.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
def test_vm2vm (openstack_clients, pair, os_resources, record_property):
os_actions = os_client.OSCliActions(openstack_clients)
config = utils.get_configuration()
timeout = int(config.get('nova_timeout') or 30)
timeout = int(config.get('nova_timeout', 30))
try:
zone1 = [service.zone for service in openstack_clients.compute.services.list() if service.host == pair[0]]
zone2 = [service.zone for service in openstack_clients.compute.services.list() if service.host == pair[1]]
Expand Down
37 changes: 24 additions & 13 deletions cvp_spt/utils/os_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from glanceclient import client as glance_client
from keystoneauth1 import identity as keystone_identity
from keystoneauth1 import session as keystone_session
from keystoneclient import client as keystone_client
from keystoneclient.v3 import client as keystone_client
from neutronclient.v2_0 import client as neutron_client
from novaclient import client as novaclient

Expand All @@ -18,7 +18,7 @@ class OfficialClientManager(object):

CINDERCLIENT_VERSION = 3
GLANCECLIENT_VERSION = 2
KEYSTONECLIENT_VERSION = 2, 0
KEYSTONECLIENT_VERSION = 3
NEUTRONCLIENT_VERSION = 2
NOVACLIENT_VERSION = 2
INTERFACE = 'admin'
Expand Down Expand Up @@ -72,16 +72,21 @@ def _get_auth_session(cls, username=None, password=None,
auth_url = auth_url.replace("http", "https")

if cls.KEYSTONECLIENT_VERSION == (2, 0):
#auth_url = "{}{}".format(auth_url, "v2.0/")
# auth_url = "{}{}".format(auth_url, "v2.0/")
auth = keystone_identity.v2.Password(
username=username, password=password, auth_url=auth_url,
username=username,
password=password,
auth_url=auth_url,
tenant_name=tenant_name)
else:
auth_url = "{}{}".format(auth_url, "v3/")
auth_url = "{}{}".format(auth_url, "/v3")
auth = keystone_identity.v3.Password(
auth_url=auth_url, user_domain_name=domain,
username=username, password=password,
project_domain_name=domain, project_name=tenant_name)
auth_url=auth_url,
user_domain_name=domain,
username=username,
password=password,
project_domain_name=domain,
project_name=tenant_name)

auth_session = keystone_session.Session(auth=auth, verify=cert)
# auth_session.get_auth_headers()
Expand All @@ -92,10 +97,14 @@ def get_auth_client(cls, username=None, password=None,
tenant_name=None, auth_url=None, cert=None,
domain='Default', **kwargs):
session = cls._get_auth_session(
username=username, password=password, tenant_name=tenant_name,
auth_url=auth_url, cert=cert, domain=domain)
keystone = keystone_client.Client(
cls.KEYSTONECLIENT_VERSION, session=session, **kwargs)
username=username,
password=password,
tenant_name=tenant_name,
auth_url=auth_url,
cert=cert,
domain=domain)
keystone = keystone_client.Client(version=cls.KEYSTONECLIENT_VERSION,
session=session, **kwargs)
keystone.management_url = auth_url
return keystone

Expand Down Expand Up @@ -196,12 +205,14 @@ def image(self):
)
return self._image


class OSCliActions(object):
def __init__(self, os_clients):
self.os_clients = os_clients

def get_admin_tenant(self):
return self.os_clients.auth.tenants.find(name="admin")
# TODO Keystone v3 doesnt have tenants attribute
return self.os_clients.auth.projects.find(name="admin")

# TODO: refactor
def get_cirros_image(self):
Expand Down

0 comments on commit 44caf35

Please sign in to comment.