From 6dfb80d0196b8609a166535a66d15bd1d7ed01f0 Mon Sep 17 00:00:00 2001 From: Alexey Stepanov Date: Fri, 2 Sep 2016 12:20:17 +0300 Subject: [PATCH] Initialize NailgunClient with session only 1. Initialize NailgunClient with session only - old way was deprecated > 1 month ago 2. get_releases_details -> get_release (was method duplicate) This changes is required for the future refactoring (move to core) Change-Id: Ia01a453f7f8233d4d39152bf56714157e3d74475 Blueprint: fuel-qa-join-helpers (cherry picked from commit 132455b) --- fuelweb_test/models/fuel_web_client.py | 22 +++++++++++-- fuelweb_test/models/nailgun_client.py | 44 ++++++-------------------- 2 files changed, 28 insertions(+), 38 deletions(-) diff --git a/fuelweb_test/models/fuel_web_client.py b/fuelweb_test/models/fuel_web_client.py index 2937c5e47..7fb4e7918 100644 --- a/fuelweb_test/models/fuel_web_client.py +++ b/fuelweb_test/models/fuel_web_client.py @@ -34,6 +34,8 @@ except ImportError: DevopsObjNotFound = Node.DoesNotExist # pylint: enable=no-member from keystoneauth1 import exceptions +from keystoneauth1.identity import V2Password +from keystoneauth1.session import Session as KeystoneSession import netaddr from proboscis.asserts import assert_equal from proboscis.asserts import assert_false @@ -75,6 +77,7 @@ from fuelweb_test.settings import DEPLOYMENT_MODE_HA from fuelweb_test.settings import DISABLE_SSL from fuelweb_test.settings import DNS_SUFFIX from fuelweb_test.settings import iface_alias +from fuelweb_test.settings import KEYSTONE_CREDS from fuelweb_test.settings import KVM_USE from fuelweb_test.settings import MULTIPLE_NETWORKS from fuelweb_test.settings import NOVA_QUOTAS_ENABLED @@ -106,9 +109,22 @@ class FuelWebClient29(object): def __init__(self, environment): self.ssh_manager = SSHManager() self.admin_node_ip = self.ssh_manager.admin_ip - self.client = NailgunClient(self.ssh_manager.admin_ip) self._environment = environment + + keystone_url = "http://{0}:5000/v2.0".format(self.admin_node_ip) + + auth = V2Password( + auth_url=keystone_url, + username=KEYSTONE_CREDS['username'], + password=KEYSTONE_CREDS['password'], + tenant_name=KEYSTONE_CREDS['tenant_name']) + # TODO: in v3 project_name + + self._session = KeystoneSession(auth=auth, verify=False) + + self.client = NailgunClient(session=self._session) self.security = SecurityChecks(self.client, self._environment) + super(FuelWebClient29, self).__init__() @property @@ -295,7 +311,7 @@ class FuelWebClient29(object): logger.info('Assert role %s is available in release %s', role_name, release_name) release_id = self.assert_release_state(release_name) - release_data = self.client.get_releases_details(release_id=release_id) + release_data = self.client.get_release(release_id=release_id) assert_equal( True, role_name in release_data['roles'], message='There is no {0} role in release id {1}'.format( @@ -2361,7 +2377,7 @@ class FuelWebClient29(object): @logwrap def get_next_deployable_release_id(self, release_id): releases = self.client.get_releases() - release_details = self.client.get_releases_details(release_id) + release_details = self.client.get_release(release_id) for release in releases: if (release["id"] > release_id and diff --git a/fuelweb_test/models/nailgun_client.py b/fuelweb_test/models/nailgun_client.py index c6c304dc7..a85087b1f 100644 --- a/fuelweb_test/models/nailgun_client.py +++ b/fuelweb_test/models/nailgun_client.py @@ -14,49 +14,21 @@ from warnings import warn -from keystoneauth1.identity import V2Password -from keystoneauth1.session import Session as KeystoneSession - from core.helpers.log_helpers import logwrap from fuelweb_test import logger -from fuelweb_test.settings import FORCE_HTTPS_MASTER_NODE -from fuelweb_test.settings import KEYSTONE_CREDS + from fuelweb_test.settings import OPENSTACK_RELEASE class NailgunClient(object): """NailgunClient""" # TODO documentation - def __init__(self, admin_node_ip=None, session=None, **kwargs): - if session: - logger.info( - 'Initialization of NailgunClient using shared session \n' - '(auth_url={})'.format(session.auth.auth_url)) - self.session = session - else: - warn( - 'Initialization of NailgunClient by IP is deprecated, ' - 'please use keystonesession1.session.Session', - DeprecationWarning) - - if FORCE_HTTPS_MASTER_NODE: - url = "https://{0}:8443".format(admin_node_ip) - else: - url = "http://{0}:8000".format(admin_node_ip) - logger.info('Initiate Nailgun client with url %s', url) - keystone_url = "http://{0}:5000/v2.0".format(admin_node_ip) - - creds = dict(KEYSTONE_CREDS, **kwargs) - - auth = V2Password( - auth_url=keystone_url, - username=creds['username'], - password=creds['password'], - tenant_name=creds['tenant_name']) - # TODO: in v3 project_name - - self.session = KeystoneSession(auth=auth, verify=False) + def __init__(self, session): + logger.info( + 'Initialization of NailgunClient using shared session \n' + '(auth_url={})'.format(session.auth.auth_url)) + self.session = session def __repr__(self): klass, obj_id = type(self), hex(id(self)) @@ -229,7 +201,9 @@ class NailgunClient(object): @logwrap def get_releases_details(self, release_id): - warn('get_releases_details is deprecated in favor of get_release') + msg = 'get_releases_details is deprecated in favor of get_release' + warn(msg, DeprecationWarning) + logger.warning(msg) return self._get(url="/releases/{}".format(release_id)).json() @logwrap