diff --git a/vmware_nsx/common/utils.py b/vmware_nsx/common/utils.py index 92676f13b6..1b720aabd0 100644 --- a/vmware_nsx/common/utils.py +++ b/vmware_nsx/common/utils.py @@ -13,11 +13,12 @@ # License for the specific language governing permissions and limitations # under the License. +from distutils import version import functools import hashlib import eventlet -from neutron import version +from neutron import version as n_version from neutron_lib.api import validators from neutron_lib import exceptions from oslo_config import cfg @@ -33,9 +34,10 @@ LOG = log.getLogger(__name__) MAX_DISPLAY_NAME_LEN = 40 MAX_RESOURCE_TYPE_LEN = 20 MAX_TAG_LEN = 40 -NEUTRON_VERSION = version.version_info.release_string() +NEUTRON_VERSION = n_version.version_info.release_string() NSX_NEUTRON_PLUGIN = 'NSX Neutron plugin' OS_NEUTRON_ID_SCOPE = 'os-neutron-id' +NSXV3_VERSION_1_1_0 = '1.1.0' # Allowed network types for the NSX Plugin @@ -66,6 +68,11 @@ class NsxV3NetworkTypes: VXLAN = 'vxlan' +def is_nsx_version_1_1_0(nsx_version): + return (version.LooseVersion(nsx_version) >= + version.LooseVersion(NSXV3_VERSION_1_1_0)) + + def get_tags(**kwargs): tags = ([dict(tag=value, scope=key) for key, value in six.iteritems(kwargs)]) @@ -116,7 +123,7 @@ def build_v3_api_version_tag(): return [{'scope': OS_NEUTRON_ID_SCOPE, 'tag': NSX_NEUTRON_PLUGIN}, {'scope': "os-api-version", - 'tag': version.version_info.release_string()}] + 'tag': n_version.version_info.release_string()}] def _validate_resource_type_length(resource_type): @@ -151,7 +158,7 @@ def build_v3_tags_payload(resource, resource_type, project_name): {'scope': 'os-project-name', 'tag': project_name[:MAX_TAG_LEN]}, {'scope': 'os-api-version', - 'tag': version.version_info.release_string()[:MAX_TAG_LEN]}] + 'tag': n_version.version_info.release_string()[:MAX_TAG_LEN]}] def add_v3_tag(tags, resource_type, tag): diff --git a/vmware_nsx/plugins/nsx_v3/plugin.py b/vmware_nsx/plugins/nsx_v3/plugin.py index 7a036a94a4..7b40213d39 100644 --- a/vmware_nsx/plugins/nsx_v3/plugin.py +++ b/vmware_nsx/plugins/nsx_v3/plugin.py @@ -157,7 +157,8 @@ class NsxV3Plugin(agentschedulers_db.AZDhcpAgentSchedulerDbMixin, def __init__(self): super(NsxV3Plugin, self).__init__() LOG.info(_LI("Starting NsxV3Plugin")) - LOG.info(_LI("NSX Version: %s"), nsxlib.get_version()) + self._nsx_version = nsxlib.get_version() + LOG.info(_LI("NSX Version: %s"), self._nsx_version) self._api_cluster = nsx_cluster.NSXClusteredAPI() self._nsx_client = nsx_client.NSX3Client(self._api_cluster) nsx_client._set_default_api_cluster(self._api_cluster) @@ -205,17 +206,19 @@ class NsxV3Plugin(agentschedulers_db.AZDhcpAgentSchedulerDbMixin, "switching profile: %s") % NSX_V3_DHCP_PROFILE_NAME raise nsx_exc.NsxPluginException(msg) - LOG.debug("Initializing NSX v3 Mac Learning switching profile") self._mac_learning_profile = None - try: - self._mac_learning_profile = self._init_mac_learning_profile() - # Only expose the extension if it is supported - self.supported_extension_aliases.append('mac-learning') - except Exception as e: - LOG.warning(_LW("Unable to initialize NSX v3 MAC Learning " - "profile: %(name)s. Reason: %(reason)s"), - {'name': NSX_V3_MAC_LEARNING_PROFILE_NAME, - 'reason': e}) + if utils.is_nsx_version_1_1_0(self._nsx_version): + LOG.debug("Initializing NSX v3 Mac Learning switching profile") + try: + self._mac_learning_profile = self._init_mac_learning_profile() + # Only expose the extension if it is supported + self.supported_extension_aliases.append('mac-learning') + except Exception as e: + LOG.warning(_LW("Unable to initialize NSX v3 MAC Learning " + "profile: %(name)s. Reason: %(reason)s"), + {'name': NSX_V3_MAC_LEARNING_PROFILE_NAME, + 'reason': e}) + self._unsubscribe_callback_events() if cfg.CONF.api_replay_mode: self.supported_extension_aliases.append('api-replay') diff --git a/vmware_nsx/shell/admin/plugins/nsxv3/resources/dhcp_binding.py b/vmware_nsx/shell/admin/plugins/nsxv3/resources/dhcp_binding.py index b0498cb753..6e1ec09100 100644 --- a/vmware_nsx/shell/admin/plugins/nsxv3/resources/dhcp_binding.py +++ b/vmware_nsx/shell/admin/plugins/nsxv3/resources/dhcp_binding.py @@ -20,7 +20,9 @@ from oslo_config import cfg from vmware_nsx._i18n import _LI from vmware_nsx.common import nsx_constants +from vmware_nsx.common import utils as comm_utils from vmware_nsx.dhcp_meta import rpc as nsx_rpc +from vmware_nsx.nsxlib import v3 as nsxlib from vmware_nsx.nsxlib.v3 import client from vmware_nsx.nsxlib.v3 import cluster from vmware_nsx.nsxlib.v3 import native_dhcp @@ -50,6 +52,12 @@ def list_dhcp_bindings(resource, event, trigger, **kwargs): def nsx_update_dhcp_bindings(resource, event, trigger, **kwargs): """Resync DHCP bindings for NSXv3 CrossHairs.""" + nsx_version = nsxlib.get_version() + if not comm_utils.is_nsx_version_1_1_0(nsx_version): + LOG.info(_LI("This utility is not available for NSX version %s"), + nsx_version) + return + cluster_api = cluster.NSXClusteredAPI() nsx_client = client.NSX3Client(cluster_api) client._set_default_api_cluster(cluster_api) diff --git a/vmware_nsx/tests/unit/nsx_v3/test_plugin.py b/vmware_nsx/tests/unit/nsx_v3/test_plugin.py index dad0f4f228..dc5be09ba3 100644 --- a/vmware_nsx/tests/unit/nsx_v3/test_plugin.py +++ b/vmware_nsx/tests/unit/nsx_v3/test_plugin.py @@ -101,6 +101,12 @@ class NsxV3PluginTestCaseMixin(test_plugin.NeutronDbPluginV2TestCase, _patch_object(nsx_plugin, 'nsx_client', new=mock_client_module) _patch_object(nsx_plugin, 'nsx_cluster', new=mock_cluster_module) + # Mock the nsx v3 version + mock_nsxlib_get_version = mock.patch( + "vmware_nsx.nsxlib.v3.get_version", + return_value='1.1.0') + mock_nsxlib_get_version.start() + # populate pre-existing mock resources cluster_id = uuidutils.generate_uuid() self.mock_api.post(