From b336b8cc035890e13b2a0f9fd44b841e5afa460f Mon Sep 17 00:00:00 2001 From: Gary Kotton Date: Wed, 24 Jan 2018 03:35:18 -0800 Subject: [PATCH] NSX|TV: validate plugin is available When admin creates plugin mapping validate that it is available. Change-Id: If41dc891e8f9a484b85d00d9fff2f7fa3a6f376c --- vmware_nsx/extensions/projectpluginmap.py | 4 ++++ vmware_nsx/plugins/nsx/plugin.py | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/vmware_nsx/extensions/projectpluginmap.py b/vmware_nsx/extensions/projectpluginmap.py index 4d23f779de..efd43e43c8 100644 --- a/vmware_nsx/extensions/projectpluginmap.py +++ b/vmware_nsx/extensions/projectpluginmap.py @@ -115,6 +115,10 @@ class ProjectPluginIllegalId(nexception.Conflict): message = _("Project ID %(project_id)s is illegal.") +class ProjectPluginNotAvailable(nexception.NotAuthorized): + message = _("Plugin %(plugin)s is not available.") + + class ProjectPluginMapPluginBase(object): @abc.abstractmethod diff --git a/vmware_nsx/plugins/nsx/plugin.py b/vmware_nsx/plugins/nsx/plugin.py index dab61be5c5..cf3a01cfcb 100644 --- a/vmware_nsx/plugins/nsx/plugin.py +++ b/vmware_nsx/plugins/nsx/plugin.py @@ -756,6 +756,10 @@ class NsxTVDPlugin(agentschedulers_db.AZDhcpAgentSchedulerDbMixin, if not uuidutils.is_uuid_like(data['project']): raise projectpluginmap.ProjectPluginIllegalId( project_id=data['project']) + # 4. Check that plugin is available + if data['plugin'] not in self.plugins: + raise projectpluginmap.ProjectPluginNotAvailable( + plugin=data['plugin']) # Add the entry to the DB and return it LOG.info("Adding mapping between project %(project)s and plugin "