LBaaS: Share base_mgr between nsxv and nsxv3

In vmware-nsx lbaas service folder, the base_mgr module can be
shared between nsxv and nsxv3. Thus move it under lbaas folder so
it can be use by nsxv3 as well. To have minimum impact on nsxv
side, rename base to LoadbalancerBaseManager and subclass
EdgeLoadbalancerBaseManager from it.

Also, this patch fixes a few pep8 error.

Change-Id: I994d39a5dbdb38e1b7805b2eec97e8ef7719f556
This commit is contained in:
Tong Liu 2017-05-20 01:03:52 +00:00 committed by Gary Kotton
parent 091cb5a148
commit 931c5a89f1
10 changed files with 49 additions and 41 deletions

View File

@ -227,6 +227,8 @@ class NsxVPluginV2(addr_pair_db.AllowedAddressPairsMixin,
# Create the client to interface with the NSX-v # Create the client to interface with the NSX-v
_nsx_v_callbacks = edge_utils.NsxVCallbacks(self) _nsx_v_callbacks = edge_utils.NsxVCallbacks(self)
self.nsx_v = vcns_driver.VcnsDriver(_nsx_v_callbacks) self.nsx_v = vcns_driver.VcnsDriver(_nsx_v_callbacks)
# Use the existing class instead of creating a new instance
self.lbv2_driver = self.nsx_v
# Ensure that edges do concurrency # Ensure that edges do concurrency
self._ensure_lock_operations() self._ensure_lock_operations()
# Configure aggregate publishing # Configure aggregate publishing

View File

@ -18,34 +18,40 @@ from neutron_lib.plugins import constants as plugin_const
from neutron_lib.plugins import directory from neutron_lib.plugins import directory
class EdgeLoadbalancerBaseManager(object): class LoadbalancerBaseManager(object):
_lbv2_driver = None _lbv2_driver = None
_core_plugin = None _core_plugin = None
def __init__(self, vcns_driver): def __init__(self):
super(EdgeLoadbalancerBaseManager, self).__init__() super(LoadbalancerBaseManager, self).__init__()
self.vcns_driver = vcns_driver
def _get_plugin(self, plugin_type): def _get_plugin(self, plugin_type):
return directory.get_plugin(plugin_type) return directory.get_plugin(plugin_type)
@property @property
def lbv2_driver(self): def lbv2_driver(self):
if not EdgeLoadbalancerBaseManager._lbv2_driver: if not LoadbalancerBaseManager._lbv2_driver:
plugin = self._get_plugin( plugin = self._get_plugin(
plugin_const.LOADBALANCERV2) plugin_const.LOADBALANCERV2)
EdgeLoadbalancerBaseManager._lbv2_driver = ( LoadbalancerBaseManager._lbv2_driver = (
plugin.drivers['vmwareedge']) plugin.drivers['vmwareedge'])
return EdgeLoadbalancerBaseManager._lbv2_driver return LoadbalancerBaseManager._lbv2_driver
@property @property
def core_plugin(self): def core_plugin(self):
if not EdgeLoadbalancerBaseManager._core_plugin: if not LoadbalancerBaseManager._core_plugin:
EdgeLoadbalancerBaseManager._core_plugin = ( LoadbalancerBaseManager._core_plugin = (
self._get_plugin(lib_const.CORE)) self._get_plugin(lib_const.CORE))
return EdgeLoadbalancerBaseManager._core_plugin return LoadbalancerBaseManager._core_plugin
class EdgeLoadbalancerBaseManager(LoadbalancerBaseManager):
def __init__(self, vcns_driver):
super(EdgeLoadbalancerBaseManager, self).__init__()
self.vcns_driver = vcns_driver
@property @property
def vcns(self): def vcns(self):

View File

@ -20,9 +20,9 @@ from oslo_utils import excutils
from vmware_nsx.common import locking from vmware_nsx.common import locking
from vmware_nsx.db import nsxv_db from vmware_nsx.db import nsxv_db
from vmware_nsx.plugins.nsx_v.vshield.common import exceptions as nsxv_exc from vmware_nsx.plugins.nsx_v.vshield.common import exceptions as nsxv_exc
from vmware_nsx.services.lbaas import base_mgr
from vmware_nsx.services.lbaas.nsx_v import lbaas_common as lb_common from vmware_nsx.services.lbaas.nsx_v import lbaas_common as lb_common
from vmware_nsx.services.lbaas.nsx_v import lbaas_const as lb_const from vmware_nsx.services.lbaas.nsx_v import lbaas_const as lb_const
from vmware_nsx.services.lbaas.nsx_v.v2 import base_mgr
LOG = logging.getLogger(__name__) LOG = logging.getLogger(__name__)
@ -130,7 +130,7 @@ class EdgeHealthMonitorManager(base_mgr.EdgeLoadbalancerBaseManager):
except nsxv_exc.VcnsApiException: except nsxv_exc.VcnsApiException:
with excutils.save_and_reraise_exception(): with excutils.save_and_reraise_exception():
self.lbv2_driver.health_monitor.failed_completion(context, self.lbv2_driver.health_monitor.failed_completion(context,
new_hm) new_hm)
LOG.error('Failed to update monitor on edge: %s', edge_id) LOG.error('Failed to update monitor on edge: %s', edge_id)
self.lbv2_driver.health_monitor.successful_completion(context, new_hm) self.lbv2_driver.health_monitor.successful_completion(context, new_hm)
@ -170,7 +170,7 @@ class EdgeHealthMonitorManager(base_mgr.EdgeLoadbalancerBaseManager):
except nsxv_exc.VcnsApiException: except nsxv_exc.VcnsApiException:
with excutils.save_and_reraise_exception(): with excutils.save_and_reraise_exception():
self.lbv2_driver.health_monitor.failed_completion(context, self.lbv2_driver.health_monitor.failed_completion(context,
hm) hm)
LOG.error('Failed to delete monitor on edge: %s', edge_id) LOG.error('Failed to delete monitor on edge: %s', edge_id)
nsxv_db.del_nsxv_lbaas_monitor_binding( nsxv_db.del_nsxv_lbaas_monitor_binding(

View File

@ -23,9 +23,9 @@ from neutron_lib import exceptions as n_exc
from vmware_nsx._i18n import _ from vmware_nsx._i18n import _
from vmware_nsx.common import locking from vmware_nsx.common import locking
from vmware_nsx.db import nsxv_db from vmware_nsx.db import nsxv_db
from vmware_nsx.services.lbaas import base_mgr
from vmware_nsx.services.lbaas.nsx_v import lbaas_common as lb_common from vmware_nsx.services.lbaas.nsx_v import lbaas_common as lb_common
from vmware_nsx.services.lbaas.nsx_v import lbaas_const as lb_const from vmware_nsx.services.lbaas.nsx_v import lbaas_const as lb_const
from vmware_nsx.services.lbaas.nsx_v.v2 import base_mgr
LOG = logging.getLogger(__name__) LOG = logging.getLogger(__name__)
@ -57,34 +57,34 @@ def policy_to_application_rule(policy):
# Example: acl <id> hdr_sub(cookie) SEEN=1 # Example: acl <id> hdr_sub(cookie) SEEN=1
hdr_type = 'hdr' + type_by_comp hdr_type = 'hdr' + type_by_comp
rule_line = ('acl %(rule_id)s %(hdr_type)s(cookie) ' rule_line = ('acl %(rule_id)s %(hdr_type)s(cookie) '
'%(key)s=%(val)s' % {'rule_id': rule.id, '%(key)s=%(val)s' % {'rule_id': rule.id,
'hdr_type': hdr_type, 'hdr_type': hdr_type,
'key': rule.key, 'key': rule.key,
'val': rule.value}) 'val': rule.value})
elif rule.type == lb_const.L7_RULE_TYPE_HEADER: elif rule.type == lb_const.L7_RULE_TYPE_HEADER:
# Example: acl <id> hdr(user-agent) -i test # Example: acl <id> hdr(user-agent) -i test
hdr_type = 'hdr' + type_by_comp hdr_type = 'hdr' + type_by_comp
rule_line = ('acl %(rule_id)s %(hdr_type)s(%(key)s) ' rule_line = ('acl %(rule_id)s %(hdr_type)s(%(key)s) '
'-i %(val)s' % {'rule_id': rule.id, '-i %(val)s' % {'rule_id': rule.id,
'hdr_type': hdr_type, 'hdr_type': hdr_type,
'key': rule.key, 'key': rule.key,
'val': rule.value}) 'val': rule.value})
elif rule.type == lb_const.L7_RULE_TYPE_HOST_NAME: elif rule.type == lb_const.L7_RULE_TYPE_HOST_NAME:
# Example: acl <id> hdr_beg(host) -i abcd # Example: acl <id> hdr_beg(host) -i abcd
hdr_type = 'hdr' + type_by_comp hdr_type = 'hdr' + type_by_comp
# -i for case insensitive host name # -i for case insensitive host name
rule_line = ('acl %(rule_id)s %(hdr_type)s(host) ' rule_line = ('acl %(rule_id)s %(hdr_type)s(host) '
'-i %(val)s' % {'rule_id': rule.id, '-i %(val)s' % {'rule_id': rule.id,
'hdr_type': hdr_type, 'hdr_type': hdr_type,
'val': rule.value}) 'val': rule.value})
elif rule.type == lb_const.L7_RULE_TYPE_PATH: elif rule.type == lb_const.L7_RULE_TYPE_PATH:
# Example: acl <id> path_beg -i /images # Example: acl <id> path_beg -i /images
# -i for case insensitive path # -i for case insensitive path
path_type = 'path' + type_by_comp path_type = 'path' + type_by_comp
rule_line = ('acl %(rule_id)s %(path_type)s ' rule_line = ('acl %(rule_id)s %(path_type)s '
'-i %(val)s' % {'rule_id': rule.id, '-i %(val)s' % {'rule_id': rule.id,
'path_type': path_type, 'path_type': path_type,
'val': rule.value}) 'val': rule.value})
elif rule.type == lb_const.L7_RULE_TYPE_FILE_TYPE: elif rule.type == lb_const.L7_RULE_TYPE_FILE_TYPE:
# Example: acl <id> path_sub -i .jpg # Example: acl <id> path_sub -i .jpg
# Regardless of the compare type, always check contained in path. # Regardless of the compare type, always check contained in path.
@ -93,8 +93,8 @@ def policy_to_application_rule(policy):
if not val.startswith('.'): if not val.startswith('.'):
val = '.' + val val = '.' + val
rule_line = ('acl %(rule_id)s path_sub ' rule_line = ('acl %(rule_id)s path_sub '
'-i %(val)s' % {'rule_id': rule.id, '-i %(val)s' % {'rule_id': rule.id,
'val': val}) 'val': val})
else: else:
msg = _('Unsupported L7rule type %s') % rule.type msg = _('Unsupported L7rule type %s') % rule.type
raise n_exc.BadRequest(resource='edge-lbaas', msg=msg) raise n_exc.BadRequest(resource='edge-lbaas', msg=msg)

View File

@ -18,7 +18,7 @@ from oslo_log import log as logging
from oslo_utils import excutils from oslo_utils import excutils
from vmware_nsx.common import locking from vmware_nsx.common import locking
from vmware_nsx.services.lbaas.nsx_v.v2 import base_mgr from vmware_nsx.services.lbaas import base_mgr
from vmware_nsx.services.lbaas.nsx_v.v2 import l7policy_mgr from vmware_nsx.services.lbaas.nsx_v.v2 import l7policy_mgr
LOG = logging.getLogger(__name__) LOG = logging.getLogger(__name__)

View File

@ -22,9 +22,9 @@ from vmware_nsx.common import exceptions as nsxv_exc
from vmware_nsx.common import locking from vmware_nsx.common import locking
from vmware_nsx.db import nsxv_db from vmware_nsx.db import nsxv_db
from vmware_nsx.plugins.nsx_v.vshield.common import exceptions as vcns_exc from vmware_nsx.plugins.nsx_v.vshield.common import exceptions as vcns_exc
from vmware_nsx.services.lbaas import base_mgr
from vmware_nsx.services.lbaas.nsx_v import lbaas_common as lb_common from vmware_nsx.services.lbaas.nsx_v import lbaas_common as lb_common
from vmware_nsx.services.lbaas.nsx_v import lbaas_const as lb_const from vmware_nsx.services.lbaas.nsx_v import lbaas_const as lb_const
from vmware_nsx.services.lbaas.nsx_v.v2 import base_mgr
LOG = logging.getLogger(__name__) LOG = logging.getLogger(__name__)
@ -38,8 +38,8 @@ def listener_to_edge_app_profile(listener, edge_cert_id):
'template': lb_const.PROTOCOL_MAP[listener.protocol], 'template': lb_const.PROTOCOL_MAP[listener.protocol],
} }
if (listener.protocol == lb_const.LB_PROTOCOL_HTTPS if (listener.protocol == lb_const.LB_PROTOCOL_HTTPS or
or listener.protocol == lb_const.LB_PROTOCOL_TERMINATED_HTTPS): listener.protocol == lb_const.LB_PROTOCOL_TERMINATED_HTTPS):
if edge_cert_id: if edge_cert_id:
edge_app_profile['clientSsl'] = { edge_app_profile['clientSsl'] = {
'caCertificate': [], 'caCertificate': [],
@ -262,7 +262,7 @@ class EdgeListenerManager(base_mgr.EdgeLoadbalancerBaseManager):
except vcns_exc.VcnsApiException: except vcns_exc.VcnsApiException:
with excutils.save_and_reraise_exception(): with excutils.save_and_reraise_exception():
self.lbv2_driver.listener.failed_completion(context, self.lbv2_driver.listener.failed_completion(context,
new_listener) new_listener)
LOG.error('Failed to update app profile on edge: %s', LOG.error('Failed to update app profile on edge: %s',
edge_id) edge_id)

View File

@ -25,8 +25,8 @@ from oslo_utils import excutils
from vmware_nsx._i18n import _ from vmware_nsx._i18n import _
from vmware_nsx.db import nsxv_db from vmware_nsx.db import nsxv_db
from vmware_nsx.plugins.nsx_v.vshield.common import exceptions as nsxv_exc from vmware_nsx.plugins.nsx_v.vshield.common import exceptions as nsxv_exc
from vmware_nsx.services.lbaas import base_mgr
from vmware_nsx.services.lbaas.nsx_v import lbaas_common as lb_common from vmware_nsx.services.lbaas.nsx_v import lbaas_common as lb_common
from vmware_nsx.services.lbaas.nsx_v.v2 import base_mgr
LOG = logging.getLogger(__name__) LOG = logging.getLogger(__name__)

View File

@ -20,8 +20,8 @@ from oslo_utils import excutils
from vmware_nsx.common import locking from vmware_nsx.common import locking
from vmware_nsx.db import nsxv_db from vmware_nsx.db import nsxv_db
from vmware_nsx.plugins.nsx_v.vshield.common import exceptions as nsxv_exc from vmware_nsx.plugins.nsx_v.vshield.common import exceptions as nsxv_exc
from vmware_nsx.services.lbaas import base_mgr
from vmware_nsx.services.lbaas.nsx_v import lbaas_common as lb_common from vmware_nsx.services.lbaas.nsx_v import lbaas_common as lb_common
from vmware_nsx.services.lbaas.nsx_v.v2 import base_mgr
LOG = logging.getLogger(__name__) LOG = logging.getLogger(__name__)

View File

@ -22,9 +22,9 @@ from neutron_lib import exceptions as n_exc
from vmware_nsx.common import locking from vmware_nsx.common import locking
from vmware_nsx.db import nsxv_db from vmware_nsx.db import nsxv_db
from vmware_nsx.plugins.nsx_v.vshield.common import exceptions as nsxv_exc from vmware_nsx.plugins.nsx_v.vshield.common import exceptions as nsxv_exc
from vmware_nsx.services.lbaas import base_mgr
from vmware_nsx.services.lbaas.nsx_v import lbaas_common as lb_common from vmware_nsx.services.lbaas.nsx_v import lbaas_common as lb_common
from vmware_nsx.services.lbaas.nsx_v import lbaas_const as lb_const from vmware_nsx.services.lbaas.nsx_v import lbaas_const as lb_const
from vmware_nsx.services.lbaas.nsx_v.v2 import base_mgr
from vmware_nsx.services.lbaas.nsx_v.v2 import listener_mgr from vmware_nsx.services.lbaas.nsx_v.v2 import listener_mgr
LOG = logging.getLogger(__name__) LOG = logging.getLogger(__name__)

View File

@ -21,8 +21,8 @@ from neutron_lib import context
from vmware_nsx.db import nsxv_db from vmware_nsx.db import nsxv_db
from vmware_nsx.plugins.nsx_v.vshield import vcns_driver from vmware_nsx.plugins.nsx_v.vshield import vcns_driver
from vmware_nsx.services.lbaas import base_mgr
from vmware_nsx.services.lbaas.nsx_v import lbaas_common as lb_common from vmware_nsx.services.lbaas.nsx_v import lbaas_common as lb_common
from vmware_nsx.services.lbaas.nsx_v.v2 import base_mgr
LB_VIP = '10.0.0.10' LB_VIP = '10.0.0.10'
@ -98,8 +98,8 @@ class BaseTestEdgeLbaasV2(base.BaseTestCase):
self.lbv2_driver = mock.Mock() self.lbv2_driver = mock.Mock()
self.core_plugin = mock.Mock() self.core_plugin = mock.Mock()
base_mgr.EdgeLoadbalancerBaseManager._lbv2_driver = self.lbv2_driver base_mgr.LoadbalancerBaseManager._lbv2_driver = self.lbv2_driver
base_mgr.EdgeLoadbalancerBaseManager._core_plugin = self.core_plugin base_mgr.LoadbalancerBaseManager._core_plugin = self.core_plugin
self._patch_lb_plugin(self.lbv2_driver, self._tested_entity) self._patch_lb_plugin(self.lbv2_driver, self._tested_entity)
self.lb = lb_models.LoadBalancer(LB_ID, LB_TENANT_ID, 'lb-name', '', self.lb = lb_models.LoadBalancer(LB_ID, LB_TENANT_ID, 'lb-name', '',