Merge "Updated to use keystoneauth1"

This commit is contained in:
Jenkins 2017-08-19 07:03:33 +00:00 committed by Gerrit Code Review
commit dd33f6a1df
3 changed files with 30 additions and 14 deletions

View File

@ -15,7 +15,7 @@ python-glanceclient>=0.15.0
python-neutronclient>=3.0.0 python-neutronclient>=3.0.0
python-novaclient>=2.18.1 python-novaclient>=2.18.1
python-openstackclient>=0.4.1 python-openstackclient>=0.4.1
python-keystoneclient>=1.7.2 python-keystoneclient>=3.10.0
scp>=0.8.0 scp>=0.8.0
tabulate>=0.7.3 tabulate>=0.7.3

View File

@ -15,6 +15,9 @@
# Module for credentials in Openstack # Module for credentials in Openstack
import getpass import getpass
from keystoneauth1.identity import v2
from keystoneauth1.identity import v3
from keystoneauth1 import session
import os import os
import re import re
@ -35,6 +38,27 @@ class Credentials(object):
dct['tenant_name'] = self.rc_tenant_name dct['tenant_name'] = self.rc_tenant_name
return dct 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 # Read a openrc file and take care of the password
# The 2 args are passed from the command line and can be None # 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_username = None
self.rc_tenant_name = None self.rc_tenant_name = None
self.rc_auth_url = None self.rc_auth_url = None
self.rc_cacert = False self.rc_cacert = None
self.rc_region_name = None self.rc_region_name = None
self.rc_project_name = None self.rc_project_name = None
self.rc_project_domain_name = None self.rc_project_domain_name = None
@ -75,7 +99,7 @@ class Credentials(object):
self.rc_identity_api_version = int(value) self.rc_identity_api_version = int(value)
# now match against wanted variable names # now match against wanted variable names
if name == 'USERNAME': elif name == 'USERNAME':
self.rc_username = value self.rc_username = value
elif name == 'AUTH_URL': elif name == 'AUTH_URL':
self.rc_auth_url = value self.rc_auth_url = value
@ -87,12 +111,12 @@ class Credentials(object):
self.rc_region_name = value self.rc_region_name = value
elif name == "PASSWORD" and not pwd: elif name == "PASSWORD" and not pwd:
pwd = value pwd = value
elif name == "USER_DOMAIN_NAME":
self.rc_user_domain_name = value
elif name == "PROJECT_NAME": elif name == "PROJECT_NAME":
self.rc_project_name = value self.rc_project_name = value
elif name == "PROJECT_DOMAIN_NAME": elif name == "PROJECT_DOMAIN_NAME":
self.rc_project_domain_name = value self.rc_project_domain_name = value
elif name == "USER_DOMAIN_NAME":
self.rc_user_domain_name = value
else: else:
LOG.error('Error: rc file does not exist %s' % (openrc_file)) LOG.error('Error: rc file does not exist %s' % (openrc_file))
success = False success = False

View File

@ -32,10 +32,7 @@ from config import config_loads
import credentials import credentials
from glanceclient.v2 import client as glanceclient from glanceclient.v2 import client as glanceclient
import iperf_tool 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 client as keystoneclient
from keystoneclient import session
from log import CONLOG from log import CONLOG
from log import FILELOG from log import FILELOG
from log import LOG from log import LOG
@ -203,12 +200,7 @@ class VmtpTest(object):
# If we need to reuse existing vms just return without setup # If we need to reuse existing vms just return without setup
if not self.config.reuse_existing_vm: if not self.config.reuse_existing_vm:
creds = self.cred.get_credentials() sess = self.cred.get_session()
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)
# Create the nova and neutron instances # Create the nova and neutron instances
nova_client = novaclient.Client('2', session=sess) nova_client = novaclient.Client('2', session=sess)