TVD project plugin mappings validations
Only admin user will be able to create a mapping, and the project id should have the uuid format Change-Id: Ia87b8fd024d0b9c6fe2d3317134f54526b328b11
This commit is contained in:
parent
1c0b3c2b8a
commit
13232a5145
@ -107,6 +107,14 @@ class ProjectPluginAlreadyExists(nexception.Conflict):
|
|||||||
"%(project_id)s.")
|
"%(project_id)s.")
|
||||||
|
|
||||||
|
|
||||||
|
class ProjectPluginAdminOnly(nexception.NotAuthorized):
|
||||||
|
message = _("Project Plugin map can be added only by an admin user.")
|
||||||
|
|
||||||
|
|
||||||
|
class ProjectPluginIllegalId(nexception.Conflict):
|
||||||
|
message = _("Project ID %(project_id)s is illegal.")
|
||||||
|
|
||||||
|
|
||||||
class ProjectPluginMapPluginBase(object):
|
class ProjectPluginMapPluginBase(object):
|
||||||
|
|
||||||
@abc.abstractmethod
|
@abc.abstractmethod
|
||||||
|
@ -25,6 +25,7 @@ from neutron_lib.plugins import directory
|
|||||||
from oslo_config import cfg
|
from oslo_config import cfg
|
||||||
from oslo_log import log as logging
|
from oslo_log import log as logging
|
||||||
from oslo_utils import excutils
|
from oslo_utils import excutils
|
||||||
|
from oslo_utils import uuidutils
|
||||||
|
|
||||||
from neutron.db import _resource_extend as resource_extend
|
from neutron.db import _resource_extend as resource_extend
|
||||||
from neutron.db import _utils as db_utils
|
from neutron.db import _utils as db_utils
|
||||||
@ -708,13 +709,27 @@ class NsxTVDPlugin(agentschedulers_db.AZDhcpAgentSchedulerDbMixin,
|
|||||||
'plugin': data['plugin'],
|
'plugin': data['plugin'],
|
||||||
'tenant_id': data['project']}
|
'tenant_id': data['project']}
|
||||||
|
|
||||||
def create_project_plugin_map(self, context, project_plugin_map):
|
def create_project_plugin_map(self, context, project_plugin_map,
|
||||||
# TODO(asarfaty): Validate project id exists
|
internal=False):
|
||||||
data = project_plugin_map['project_plugin_map']
|
data = project_plugin_map['project_plugin_map']
|
||||||
|
|
||||||
|
# validations:
|
||||||
|
# 1. validate it doesn't already exist
|
||||||
if nsx_db.get_project_plugin_mapping(
|
if nsx_db.get_project_plugin_mapping(
|
||||||
context.session, data['project']):
|
context.session, data['project']):
|
||||||
raise projectpluginmap.ProjectPluginAlreadyExists(
|
raise projectpluginmap.ProjectPluginAlreadyExists(
|
||||||
project_id=data['project'])
|
project_id=data['project'])
|
||||||
|
if not internal:
|
||||||
|
# 2. only admin user is allowed
|
||||||
|
if not context.is_admin:
|
||||||
|
raise projectpluginmap.ProjectPluginAdminOnly()
|
||||||
|
# 3. Validate the project id
|
||||||
|
# TODO(asarfaty): Validate project id exists in keystone
|
||||||
|
if not uuidutils.is_uuid_like(data['project']):
|
||||||
|
raise projectpluginmap.ProjectPluginIllegalId(
|
||||||
|
project_id=data['project'])
|
||||||
|
|
||||||
|
# Add the entry to the DB and return it
|
||||||
LOG.info("Adding mapping between project %(project)s and plugin "
|
LOG.info("Adding mapping between project %(project)s and plugin "
|
||||||
"%(plugin)s", {'project': data['project'],
|
"%(plugin)s", {'project': data['project'],
|
||||||
'plugin': data['plugin']})
|
'plugin': data['plugin']})
|
||||||
@ -756,11 +771,11 @@ class NsxTVDPlugin(agentschedulers_db.AZDhcpAgentSchedulerDbMixin,
|
|||||||
else:
|
else:
|
||||||
# add a new entry with the default plugin
|
# add a new entry with the default plugin
|
||||||
try:
|
try:
|
||||||
# TODO(asarfaty) we get timeout here when called under
|
self.create_project_plugin_map(
|
||||||
# _ext_extend_network_dict of the first create_network
|
context,
|
||||||
self.create_project_plugin_map(context,
|
|
||||||
{'project_plugin_map': {'plugin': plugin_type,
|
{'project_plugin_map': {'plugin': plugin_type,
|
||||||
'project': project_id}})
|
'project': project_id}},
|
||||||
|
internal=True)
|
||||||
except projectpluginmap.ProjectPluginAlreadyExists:
|
except projectpluginmap.ProjectPluginAlreadyExists:
|
||||||
# Maybe added by another thread
|
# Maybe added by another thread
|
||||||
pass
|
pass
|
||||||
|
@ -128,7 +128,8 @@ class NsxVMetadataProxyHandler(object):
|
|||||||
context,
|
context,
|
||||||
{'project_plugin_map':
|
{'project_plugin_map':
|
||||||
{'plugin': projectpluginmap.NsxPlugins.NSX_V,
|
{'plugin': projectpluginmap.NsxPlugins.NSX_V,
|
||||||
'project': nsxv_constants.INTERNAL_TENANT_ID}})
|
'project': nsxv_constants.INTERNAL_TENANT_ID}},
|
||||||
|
internal=True)
|
||||||
except projectpluginmap.ProjectPluginAlreadyExists:
|
except projectpluginmap.ProjectPluginAlreadyExists:
|
||||||
pass
|
pass
|
||||||
self.internal_net, self.internal_subnet = (
|
self.internal_net, self.internal_subnet = (
|
||||||
|
@ -47,7 +47,7 @@ class NsxTVDPluginTestCase(v_tests.NsxVPluginV2TestCase,
|
|||||||
super(NsxTVDPluginTestCase, self).setUp(
|
super(NsxTVDPluginTestCase, self).setUp(
|
||||||
plugin=plugin,
|
plugin=plugin,
|
||||||
ext_mgr=ext_mgr)
|
ext_mgr=ext_mgr)
|
||||||
|
self._project_id = _uuid()
|
||||||
self.core_plugin = directory.get_plugin()
|
self.core_plugin = directory.get_plugin()
|
||||||
|
|
||||||
# create a context with this tenant
|
# create a context with this tenant
|
||||||
@ -62,7 +62,7 @@ class NsxTVDPluginTestCase(v_tests.NsxVPluginV2TestCase,
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def project_id(self):
|
def project_id(self):
|
||||||
pass
|
return self._project_id
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def plugin_type(self):
|
def plugin_type(self):
|
||||||
@ -186,9 +186,6 @@ class NsxTVDPluginTestCase(v_tests.NsxVPluginV2TestCase,
|
|||||||
|
|
||||||
class TestPluginWithDefaultPlugin(NsxTVDPluginTestCase):
|
class TestPluginWithDefaultPlugin(NsxTVDPluginTestCase):
|
||||||
"""Test TVD plugin with the NSX-T (default) sub plugin"""
|
"""Test TVD plugin with the NSX-T (default) sub plugin"""
|
||||||
@property
|
|
||||||
def project_id(self):
|
|
||||||
return 'project_t'
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def plugin_type(self):
|
def plugin_type(self):
|
||||||
@ -372,10 +369,6 @@ class TestPluginWithDefaultPlugin(NsxTVDPluginTestCase):
|
|||||||
class TestPluginWithNsxv(TestPluginWithDefaultPlugin):
|
class TestPluginWithNsxv(TestPluginWithDefaultPlugin):
|
||||||
"""Test TVD plugin with the NSX-V sub plugin"""
|
"""Test TVD plugin with the NSX-V sub plugin"""
|
||||||
|
|
||||||
@property
|
|
||||||
def project_id(self):
|
|
||||||
return 'project_v'
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def plugin_type(self):
|
def plugin_type(self):
|
||||||
return 'nsx-v'
|
return 'nsx-v'
|
||||||
@ -398,10 +391,6 @@ class TestPluginWithNsxv(TestPluginWithDefaultPlugin):
|
|||||||
class TestPluginWithDvs(TestPluginWithDefaultPlugin):
|
class TestPluginWithDvs(TestPluginWithDefaultPlugin):
|
||||||
"""Test TVD plugin with the DVS sub plugin"""
|
"""Test TVD plugin with the DVS sub plugin"""
|
||||||
|
|
||||||
@property
|
|
||||||
def project_id(self):
|
|
||||||
return 'project_dvs'
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def plugin_type(self):
|
def plugin_type(self):
|
||||||
return 'dvs'
|
return 'dvs'
|
||||||
|
Loading…
x
Reference in New Issue
Block a user