vmware-nsx/vmware_nsx/plugins/nsx_v/managers.py
asarfaty 50afa71853 Fix broken Victoria branch
1.Upgrade pylint to 2.4.4, add exclusions to the tests, and
  fix some lint errors in the code

2. Fix user creation with GRANT in MySQL 8.0(Ubuntu Focal)
In Ubuntu Bionic (18.04) mysql 5.7 version used to create
the user implicitly when using using the GRANT.
Ubuntu Focal (20.04) has mysql 8.0 and with mysql 8.0 there
is no implicit user creation with GRANT. We need to
create the user first before using GRANT command.
See also commit I97b0dcbb88c6ef7c22e3c55970211bed792bbd0d

3. Remove fwaas from the zuul.yaml
4. Remove DB migration test which is failing ue to FWaaS migration
with py38
5. Fix cover tests python version in .tox
6. fix requirememnts

Change-Id: I22654a5d5ccaad3185ae3365a90afba1ce870695
2020-09-21 15:31:18 +02:00

94 lines
3.5 KiB
Python

# Copyright 2014 VMware, Inc.
# All Rights Reserved
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
from oslo_config import cfg
import stevedore
from oslo_log import log
from vmware_nsx._i18n import _
from vmware_nsx.common import exceptions as nsx_exc
LOG = log.getLogger(__name__)
ROUTER_TYPE_DRIVERS = ["distributed", "exclusive", "shared"]
class RouterTypeManager(stevedore.named.NamedExtensionManager):
"""Manage router segment types using drivers."""
def __init__(self, plugin):
# Mapping from type name to DriverManager
self.drivers = {}
LOG.info("Configured router type driver names: %s",
ROUTER_TYPE_DRIVERS)
super(RouterTypeManager, self).__init__(
'vmware_nsx.neutron.nsxv.router_type_drivers',
ROUTER_TYPE_DRIVERS,
invoke_on_load=True,
invoke_args=(plugin,))
LOG.info("Loaded type driver names: %s", self.names())
self._register_types()
self._check_tenant_router_types(cfg.CONF.nsxv.tenant_router_types)
def _register_types(self):
for ext in self:
router_type = ext.obj.get_type()
if router_type in self.drivers:
LOG.error("Type driver '%(new_driver)s' ignored because "
"type driver '%(old_driver)s' is already "
"registered for type '%(type)s'",
{'new_driver': ext.name,
'old_driver': self.drivers[router_type].name,
'type': router_type})
else:
self.drivers[router_type] = ext
LOG.info("Registered types: %s", self.drivers.keys())
def _check_tenant_router_types(self, types):
self.tenant_router_types = []
for router_type in types:
if router_type in self.drivers:
self.tenant_router_types.append(router_type)
else:
msg = _("No type driver for tenant router_type: %s. "
"Service terminated!") % router_type
LOG.error(msg)
raise SystemExit(msg)
LOG.info("Tenant router_types: %s", self.tenant_router_types)
def get_tenant_router_driver(self, context, router_type):
driver = self.drivers.get(router_type)
if driver:
return driver.obj
raise nsx_exc.NoRouterAvailable()
def decide_tenant_router_type(self, context, router_type=None):
if router_type is None:
for rt in self.tenant_router_types:
driver = self.drivers.get(rt)
if driver:
return rt
raise nsx_exc.NoRouterAvailable()
if context.is_admin:
driver = self.drivers.get(router_type)
if driver:
return router_type
elif router_type in self.tenant_router_types:
driver = self.drivers.get(router_type)
if driver:
return router_type
raise nsx_exc.NoRouterAvailable()