diff --git a/requirements.txt b/requirements.txt index 2c6b4bd..0e493c5 100644 --- a/requirements.txt +++ b/requirements.txt @@ -15,7 +15,7 @@ python-glanceclient>=0.15.0 python-neutronclient<3,>=2.3.6 python-novaclient>=2.18.1 python-openstackclient>=0.4.1 -python-keystoneclient>=1.7.2 +python-keystoneclient>=3.10.0 scp>=0.8.0 tabulate>=0.7.3 diff --git a/vmtp/credentials.py b/vmtp/credentials.py index dcd4484..dfe26b7 100644 --- a/vmtp/credentials.py +++ b/vmtp/credentials.py @@ -15,6 +15,9 @@ # Module for credentials in Openstack import getpass +from keystoneauth1.identity import v2 +from keystoneauth1.identity import v3 +from keystoneauth1 import session import os import re @@ -35,6 +38,27 @@ class Credentials(object): dct['tenant_name'] = self.rc_tenant_name return dct + def get_session(self): + dct = { + 'username': self.rc_username, + 'password': self.rc_password, + 'auth_url': self.rc_auth_url + } + + if self.rc_identity_api_version == 3: + dct.update({ + 'project_name': self.rc_project_name, + 'project_domain_name': self.rc_project_domain_name, + 'user_domain_name': self.rc_user_domain_name + }) + auth = v3.Password(**dct) + else: + dct.update({ + 'tenant_name': self.rc_tenant_name + }) + auth = v2.Password(**dct) + return session.Session(auth=auth, verify=self.rc_cacert) + # # Read a openrc file and take care of the password # The 2 args are passed from the command line and can be None @@ -44,7 +68,7 @@ class Credentials(object): self.rc_username = None self.rc_tenant_name = None self.rc_auth_url = None - self.rc_cacert = False + self.rc_cacert = None self.rc_region_name = None self.rc_project_name = None self.rc_project_domain_name = None @@ -75,7 +99,7 @@ class Credentials(object): self.rc_identity_api_version = int(value) # now match against wanted variable names - if name == 'USERNAME': + elif name == 'USERNAME': self.rc_username = value elif name == 'AUTH_URL': self.rc_auth_url = value @@ -87,12 +111,12 @@ class Credentials(object): self.rc_region_name = value elif name == "PASSWORD" and not pwd: pwd = value + elif name == "USER_DOMAIN_NAME": + self.rc_user_domain_name = value elif name == "PROJECT_NAME": self.rc_project_name = value elif name == "PROJECT_DOMAIN_NAME": self.rc_project_domain_name = value - elif name == "USER_DOMAIN_NAME": - self.rc_user_domain_name = value else: LOG.error('Error: rc file does not exist %s' % (openrc_file)) success = False diff --git a/vmtp/vmtp.py b/vmtp/vmtp.py index 4f881e4..935aae5 100755 --- a/vmtp/vmtp.py +++ b/vmtp/vmtp.py @@ -32,10 +32,7 @@ from config import config_loads import credentials from glanceclient import client as glanceclient import iperf_tool -from keystoneclient.auth.identity import v2 as keystone_v2 -from keystoneclient.auth.identity import v3 as keystone_v3 from keystoneclient import client as keystoneclient -from keystoneclient import session from log import CONLOG from log import FILELOG from log import LOG @@ -199,12 +196,7 @@ class VmtpTest(object): # If we need to reuse existing vms just return without setup if not self.config.reuse_existing_vm: - creds = self.cred.get_credentials() - if self.cred.rc_identity_api_version == 3: - auth = keystone_v3.Password(**creds) - else: - auth = keystone_v2.Password(**creds) - sess = session.Session(auth=auth, verify=self.cred.rc_cacert) + sess = self.cred.get_session() # Create the nova and neutron instances nova_client = novaclient.Client('2', session=sess)