TVD servives: Handle the case where plugin is disabled
Make sure the TVD plugin and services drivers will not crash in case one of the core plugins is disabled. Also generelize the code used by the different drivers to select their plugin Change-Id: I85dc35b9f516e0df9c9d5e19f90284b4942558e5
This commit is contained in:
parent
2c21c61709
commit
8a4485398c
@ -575,8 +575,8 @@ class NsxTVDPlugin(addr_pair_db.AllowedAddressPairsMixin,
|
||||
mappings = nsx_db.get_project_plugin_mappings(context.session)
|
||||
return [self._get_project_plugin_dict(data) for data in mappings]
|
||||
|
||||
def _get_plugin_from_project(self, context, project_id):
|
||||
"""Get the correct plugin for this project.
|
||||
def get_plugin_type_from_project(self, context, project_id):
|
||||
"""Get the correct plugin type for this project.
|
||||
|
||||
Look for the project in the DB.
|
||||
If not there - add an entry with the default plugin
|
||||
@ -597,4 +597,13 @@ class NsxTVDPlugin(addr_pair_db.AllowedAddressPairsMixin,
|
||||
raise nsx_exc.NsxPluginException(err_msg=msg)
|
||||
|
||||
LOG.debug("Using %s plugin for project %s", plugin_type, project_id)
|
||||
return plugin_type
|
||||
|
||||
def _get_plugin_from_project(self, context, project_id):
|
||||
"""Get the correct plugin for this project.
|
||||
|
||||
Look for the project in the DB.
|
||||
If not there - add an entry with the default plugin
|
||||
"""
|
||||
plugin_type = self.get_plugin_type_from_project(context, project_id)
|
||||
return self.plugins[plugin_type]
|
||||
|
@ -15,6 +15,9 @@
|
||||
|
||||
from oslo_config import cfg
|
||||
|
||||
from neutron_lib import context as n_context
|
||||
from neutron_lib.plugins import directory
|
||||
|
||||
|
||||
def is_tvd_core_plugin():
|
||||
core_plugin = cfg.CONF.core_plugin
|
||||
@ -22,3 +25,14 @@ def is_tvd_core_plugin():
|
||||
core_plugin.endswith('vmware_nsxtvd')):
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
def get_tvd_plugin_type_for_project(project_id, context=None):
|
||||
"""Get the plugin type used by a project
|
||||
|
||||
Raise an exception if not found or the plugin is not in use
|
||||
"""
|
||||
if not context:
|
||||
context = n_context.get_admin_context()
|
||||
core_plugin = directory.get_plugin()
|
||||
return core_plugin.get_plugin_type_from_project(context, project_id)
|
||||
|
@ -27,7 +27,6 @@ from oslo_log import log as logging
|
||||
|
||||
from vmware_nsx.common import locking
|
||||
from vmware_nsx.common import nsxv_constants
|
||||
from vmware_nsx.db import db as nsx_db
|
||||
from vmware_nsx.db import nsxv_db
|
||||
from vmware_nsx.extensions import edge_service_gateway_bgp_peer as ext_esg
|
||||
from vmware_nsx.extensions import projectpluginmap
|
||||
@ -97,22 +96,8 @@ class NSXBgpPlugin(service_base.ServicePluginBase, bgp_db.BgpDbMixin):
|
||||
# Check if the current project id has a matching driver
|
||||
# Currently only NSX-V is supported
|
||||
if self._core_plugin.is_tvd_plugin():
|
||||
mapping = nsx_db.get_project_plugin_mapping(
|
||||
context.session, project)
|
||||
if mapping:
|
||||
plugin_type = mapping['plugin']
|
||||
else:
|
||||
msg = (_("Couldn't find the plugin project %s is "
|
||||
"using") % project)
|
||||
raise n_exc.InvalidInput(error_message=msg)
|
||||
|
||||
# make sure the core plugin is supported
|
||||
if not self._core_plugin.get_plugin_by_type(plugin_type):
|
||||
msg = (_("Plugin %(plugin)s for project %(project)s is not "
|
||||
"supported by the core plugin") % {
|
||||
'project': project,
|
||||
'plugin': plugin_type})
|
||||
raise n_exc.InvalidInput(error_message=msg)
|
||||
plugin_type = self._core_plugin.get_plugin_type_from_project(
|
||||
context, project)
|
||||
else:
|
||||
plugin_type = self._core_plugin.plugin_type()
|
||||
|
||||
|
@ -17,11 +17,10 @@ from oslo_log import helpers as log_helpers
|
||||
from oslo_log import log as logging
|
||||
|
||||
from neutron_fwaas.services.firewall.drivers import fwaas_base
|
||||
from neutron_lib import context as n_context
|
||||
from neutron_lib.exceptions import firewall_v1 as exceptions
|
||||
|
||||
from vmware_nsx.db import db as nsx_db
|
||||
from vmware_nsx.extensions import projectpluginmap
|
||||
from vmware_nsx.plugins.nsx import utils as tvd_utils
|
||||
from vmware_nsx.services.fwaas.nsx_v import edge_fwaas_driver as v_driver
|
||||
from vmware_nsx.services.fwaas.nsx_v3 import edge_fwaas_driver_v1 as t_driver
|
||||
|
||||
@ -41,10 +40,20 @@ class EdgeFwaasTVDriverV1(fwaas_base.FwaasDriverBase):
|
||||
|
||||
# supported drivers:
|
||||
self.drivers = {}
|
||||
self.drivers[projectpluginmap.NsxPlugins.NSX_T] = (
|
||||
t_driver.EdgeFwaasV3DriverV1())
|
||||
self.drivers[projectpluginmap.NsxPlugins.NSX_V] = (
|
||||
v_driver.EdgeFwaasDriver())
|
||||
try:
|
||||
self.drivers[projectpluginmap.NsxPlugins.NSX_T] = (
|
||||
t_driver.EdgeFwaasV3DriverV1())
|
||||
except Exception:
|
||||
LOG.warning("EdgeFwaasTVDriverV1 failed to initialize the NSX-T "
|
||||
"driver")
|
||||
self.drivers[projectpluginmap.NsxPlugins.NSX_T] = None
|
||||
try:
|
||||
self.drivers[projectpluginmap.NsxPlugins.NSX_V] = (
|
||||
v_driver.EdgeFwaasDriver())
|
||||
except Exception:
|
||||
LOG.warning("EdgeFwaasTVDriverV1 failed to initialize the NSX-V "
|
||||
"driver")
|
||||
self.drivers[projectpluginmap.NsxPlugins.NSX_V] = None
|
||||
|
||||
def get_T_driver(self):
|
||||
return self.drivers[projectpluginmap.NsxPlugins.NSX_T]
|
||||
@ -53,17 +62,8 @@ class EdgeFwaasTVDriverV1(fwaas_base.FwaasDriverBase):
|
||||
return self.drivers[projectpluginmap.NsxPlugins.NSX_V]
|
||||
|
||||
def _get_driver_for_project(self, project):
|
||||
context = n_context.get_admin_context()
|
||||
mapping = nsx_db.get_project_plugin_mapping(
|
||||
context.session, project)
|
||||
if mapping:
|
||||
plugin_type = mapping['plugin']
|
||||
else:
|
||||
LOG.error("Didn't find the plugin project %s is using", project)
|
||||
raise exceptions.FirewallInternalDriverError(
|
||||
driver=self.driver_name)
|
||||
|
||||
if plugin_type not in self.drivers:
|
||||
plugin_type = tvd_utils.get_tvd_plugin_type_for_project(project)
|
||||
if not self.drivers.get(plugin_type):
|
||||
LOG.error("Project %(project)s with plugin %(plugin)s has no "
|
||||
"support for FWaaS V1", {'project': project,
|
||||
'plugin': plugin_type})
|
||||
|
@ -17,11 +17,10 @@ from oslo_log import helpers as log_helpers
|
||||
from oslo_log import log as logging
|
||||
|
||||
from neutron_fwaas.services.firewall.drivers import fwaas_base_v2
|
||||
from neutron_lib import context as n_context
|
||||
from neutron_lib.exceptions import firewall_v2 as exceptions
|
||||
|
||||
from vmware_nsx.db import db as nsx_db
|
||||
from vmware_nsx.extensions import projectpluginmap
|
||||
from vmware_nsx.plugins.nsx import utils as tvd_utils
|
||||
from vmware_nsx.services.fwaas.nsx_v3 import edge_fwaas_driver_v2 as t_driver
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
@ -40,24 +39,20 @@ class EdgeFwaasTVDriverV2(fwaas_base_v2.FwaasDriverBase):
|
||||
|
||||
# supported drivers (Only NSX-T):
|
||||
self.drivers = {}
|
||||
self.drivers[projectpluginmap.NsxPlugins.NSX_T] = (
|
||||
t_driver.EdgeFwaasV3DriverV2())
|
||||
try:
|
||||
self.drivers[projectpluginmap.NsxPlugins.NSX_T] = (
|
||||
t_driver.EdgeFwaasV3DriverV2())
|
||||
except Exception:
|
||||
LOG.warning("EdgeFwaasTVDriverV2 failed to initialize the NSX-T "
|
||||
"driver")
|
||||
self.drivers[projectpluginmap.NsxPlugins.NSX_T] = None
|
||||
|
||||
def get_T_driver(self):
|
||||
return self.drivers[projectpluginmap.NsxPlugins.NSX_T]
|
||||
|
||||
def _get_driver_for_project(self, project):
|
||||
context = n_context.get_admin_context()
|
||||
mapping = nsx_db.get_project_plugin_mapping(
|
||||
context.session, project)
|
||||
if mapping:
|
||||
plugin_type = mapping['plugin']
|
||||
else:
|
||||
LOG.error("Didn't find the plugin project %s is using", project)
|
||||
raise exceptions.FirewallInternalDriverError(
|
||||
driver=self.driver_name)
|
||||
|
||||
if plugin_type not in self.drivers:
|
||||
plugin_type = tvd_utils.get_tvd_plugin_type_for_project(project)
|
||||
if not self.drivers.get(plugin_type):
|
||||
LOG.error("Project %(project)s with plugin %(plugin)s has no "
|
||||
"support for FWaaS V2", {'project': project,
|
||||
'plugin': plugin_type})
|
||||
|
@ -52,6 +52,9 @@ class CommonEdgeFwaasV3Driver(fwaas_base.FwaasDriverBase):
|
||||
if self._core_plugin.is_tvd_plugin():
|
||||
self._core_plugin = self._core_plugin.get_plugin_by_type(
|
||||
projectpluginmap.NsxPlugins.NSX_T)
|
||||
if not self._core_plugin:
|
||||
# The nsx-t plugin was not initialized
|
||||
return
|
||||
# make sure plugin init was completed
|
||||
if not self._core_plugin.init_is_complete:
|
||||
self._core_plugin.init_complete(None, None, {})
|
||||
@ -70,7 +73,8 @@ class CommonEdgeFwaasV3Driver(fwaas_base.FwaasDriverBase):
|
||||
return self.nsxlib.logical_router
|
||||
|
||||
def check_backend_version(self, resource, event, trigger, **kwargs):
|
||||
if not self.nsxlib.feature_supported(consts.FEATURE_ROUTER_FIREWALL):
|
||||
if (self.core_plugin and
|
||||
not self.nsxlib.feature_supported(consts.FEATURE_ROUTER_FIREWALL)):
|
||||
# router firewall is not supported
|
||||
LOG.warning("FWaaS is not supported by the NSX backend (version "
|
||||
"%s): Router firewall is not supported",
|
||||
|
Loading…
Reference in New Issue
Block a user