Better handle vim domain exception

Instead of handling each keystone parameter error in Tacker,
reuse keystone's BadRequest exception that already takes care of
parameter errors in user input not just for domains, but users,
projects and tenants.

Change-Id: I2a6aa6f7f9dec829bf1010d244d1aadf7942ec9d
This commit is contained in:
Sripriya 2016-08-04 16:14:22 -07:00
parent d3fecf7434
commit ea987efd12
4 changed files with 11 additions and 50 deletions

View File

@ -97,7 +97,7 @@ Execution of testcase:
.. code-block:: console
./tools/prepare_functional_test.sh
* From tacker directory, all function testcases can be executed using
following commands:

View File

@ -73,14 +73,6 @@ class VimDuplicateUrlException(exceptions.TackerException):
"duplicate VIM")
class VimProjectDomainNameMissingException(exceptions.TackerException):
message = _("'project_domain_name' is missing")
class VimUserDomainNameMissingException(exceptions.TackerException):
message = _("'user_domain_name' is missing")
RESOURCE_ATTRIBUTE_MAP = {
'vims': {

View File

@ -88,14 +88,8 @@ class OpenStack_Driver(abstract_vim_driver.VimAbstractDriver):
if keystone_version == 'v3':
auth_cred['project_id'] = vim_project.get('id')
auth_cred['project_name'] = vim_project.get('name')
if not vim_project.get('project_domain_name'):
LOG.error(_("'project_domain_name' is missing."))
raise nfvo.VimProjectDomainNameMissingException()
auth_cred['project_domain_name'] = vim_project.get(
'project_domain_name')
if not auth_cred.get('user_domain_name'):
LOG.error(_("'user_domain_name' is missing."))
raise nfvo.VimUserDomainNameMissingException()
else:
auth_cred['tenant_id'] = vim_project.get('id')
auth_cred['tenant_name'] = vim_project.get('name')
@ -140,8 +134,8 @@ class OpenStack_Driver(abstract_vim_driver.VimAbstractDriver):
"""
try:
regions_list = self._find_regions(ks_client)
except exceptions.Unauthorized as e:
LOG.warning(_("Authorization failed for user"))
except (exceptions.Unauthorized, exceptions.BadRequest) as e:
LOG.warn(_("Authorization failed for user"))
raise nfvo.VimUnauthorizedException(message=e.message)
vim_obj['placement_attr'] = {'regions': regions_list}
return vim_obj

View File

@ -15,7 +15,6 @@
from keystoneclient import exceptions
import mock
from mock import sentinel
from oslo_config import cfg
from tacker.extensions import nfvo
@ -122,8 +121,15 @@ class TestOpenstack_Driver(base.TestCase):
self.openstack_driver.deregister_vim(vim_id)
mock_os_remove.assert_called_once_with(file_path)
def test_register_vim_invalid_credentials(self):
def test_register_vim_invalid_auth(self):
attrs = {'regions.list.side_effect': exceptions.Unauthorized}
self._test_register_vim_auth(attrs)
def test_register_vim_missing_auth(self):
attrs = {'regions.list.side_effect': exceptions.BadRequest}
self._test_register_vim_auth(attrs)
def _test_register_vim_auth(self, attrs):
keystone_version = 'v3'
mock_ks_client = mock.Mock(version=keystone_version, **attrs)
self.keystone.get_version.return_value = keystone_version
@ -133,34 +139,3 @@ class TestOpenstack_Driver(base.TestCase):
mock_ks_client.regions.list.assert_called_once_with()
self.keystone.initialize_client.assert_called_once_with(
version=keystone_version, **self.auth_obj)
def test_auth_vim_missing_project_domain_name(self):
keystone_version = 'v3'
self.keystone.get_version.return_value = keystone_version
auth_cred = {'username': sentinel.usrname1,
'password': sentinel.password1,
'user_domain_name': sentinel.user_domain.name,
'user_id': sentinel.usrid1}
vim_obj = {'auth_url': "http://xxx",
'auth_cred': auth_cred,
'vim_project': {'id': sentinel.prj_id1,
'name': sentinel.prj_name1}}
self.assertRaises(nfvo.VimProjectDomainNameMissingException,
self.openstack_driver.authenticate_vim,
vim_obj)
def test_auth_vim_missing_user_domain_name(self):
keystone_version = 'v3'
self.keystone.get_version.return_value = keystone_version
auth_cred = {'username': sentinel.usrname1,
'password': sentinel.password1,
'user_id': sentinel.usrid1}
vim_obj = {'auth_url': "http://xxx",
'auth_cred': auth_cred,
'vim_project': {'id': sentinel.prj_id1,
'project_domain_name':
sentinel.prj_domain_name1,
'name': sentinel.prj_name1}}
self.assertRaises(nfvo.VimUserDomainNameMissingException,
self.openstack_driver.authenticate_vim,
vim_obj)