Correct '/v3' suffix to auth_url

Implementing a utility function to check auth_url which is defined in
the keystone_authtoken section of /etc/tacker/tacker.conf. So that,
'/v3' suffix will be added (if it is missed) to match with keystoneclient
v3.

Changes:
- Create a validate_keystone_auth_url function in tacker.nfvo.nfvo_plugin
- Check auth_url in get_auth_dict in nfvo_plugin

Co-Authored-By: Cong Phuoc Hoang <hoangphuocbk2.07@gmail.com>

Change-Id: I30abaff188bd1d352750cb327a624c1e8ced884f
This commit is contained in:
Trinh Nguyen 2018-08-10 02:30:32 +09:00 committed by Cong Phuoc Hoang
parent 4a77473dcd
commit 2ea5461907
3 changed files with 29 additions and 13 deletions

View File

@ -21,6 +21,7 @@
import logging as std_logging
import os
import random
import re
import signal
import socket
import string
@ -224,3 +225,10 @@ def generate_resource_name(resource, prefix='tmpl'):
string.ascii_lowercase + string.digits)
for _ in range(16)) \
+ '-' + resource
def get_auth_url_v3(auth_url):
if re.match('.+v3/?$', auth_url) is not None:
return auth_url
else:
return '{0}/v3'.format(auth_url)

View File

@ -37,6 +37,7 @@ from tacker.mistral import mistral_client
from tacker.nfvo.drivers.vim import abstract_vim_driver
from tacker.nfvo.drivers.vnffg import abstract_vnffg_driver
from tacker.nfvo.drivers.workflow import workflow_generator
from tacker.nfvo.nfvo_plugin import NfvoPlugin
from tacker.plugins.common import constants
from tacker.vnfm import keystone
@ -120,8 +121,9 @@ class OpenStack_Driver(abstract_vim_driver.VimAbstractDriver,
verify = 'True' == vim_obj['auth_cred'].get('cert_verify', 'True') \
or False
auth_url = vim_obj['auth_url']
keystone_version = self._validate_auth_url(auth_url=auth_url,
verify=verify)
keystone_version = NfvoPlugin.validate_keystone_auth_url(
auth_url=auth_url,
verify=verify)
auth_cred = self._get_auth_creds(keystone_version, vim_obj)
return self._initialize_keystone(keystone_version, auth_cred)
@ -154,14 +156,6 @@ class OpenStack_Driver(abstract_vim_driver.VimAbstractDriver,
return auth_plugin
def _validate_auth_url(self, auth_url, verify):
try:
keystone_version = self.keystone.get_version(auth_url, verify)
except Exception as e:
LOG.error('VIM Auth URL invalid')
raise nfvo.VimConnectionException(message=str(e))
return keystone_version
def _initialize_keystone(self, version, auth):
ks_client = self.keystone.initialize_client(version=version, **auth)
return ks_client
@ -339,8 +333,9 @@ class OpenStack_Driver(abstract_vim_driver.VimAbstractDriver,
"""
verify = 'True' == vim_obj.get('cert_verify', 'True') or False
auth_url = vim_obj['auth_url']
keystone_version = self._validate_auth_url(auth_url=auth_url,
verify=verify)
keystone_version = NfvoPlugin.validate_keystone_auth_url(
auth_url=auth_url,
verify=verify)
auth_cred = self._get_auth_creds(keystone_version, vim_obj)
auth_plugin = self._get_auth_plugin(keystone_version, **auth_cred)
sess = session.Session(auth=auth_plugin)

View File

@ -43,6 +43,7 @@ from tacker.keymgr import API as KEYMGR_API
from tacker import manager
from tacker.nfvo.workflows.vim_monitor import vim_monitor_utils
from tacker.plugins.common import constants
from tacker.vnfm import keystone
from tacker.vnfm import vim_client
from tacker.tosca import utils as toscautils
@ -87,10 +88,22 @@ class NfvoPlugin(nfvo_db_plugin.NfvoPluginDb, vnffg_db.VnffgPluginDbMixin,
cfg.CONF.nfvo_vim.vim_drivers)
self.vim_client = vim_client.VimClient()
@staticmethod
def validate_keystone_auth_url(auth_url, verify):
keystone_obj = keystone.Keystone()
auth_url = utils.get_auth_url_v3(auth_url)
try:
return keystone_obj.get_version(auth_url, verify)
except Exception as e:
LOG.error('Keystone Auth URL invalid')
raise nfvo.VimConnectionException(message=str(e))
def get_auth_dict(self, context):
auth = CONF.keystone_authtoken
auth_url = utils.get_auth_url_v3(auth.auth_url)
self.validate_keystone_auth_url(auth_url, 'True')
return {
'auth_url': auth.auth_url + '/v3',
'auth_url': auth_url,
'token': context.auth_token,
'project_domain_name': auth.project_domain_name or context.domain,
'project_name': context.tenant_name