From 33212a66eb8ce0a99681132f3395a9d32c14b9f5 Mon Sep 17 00:00:00 2001 From: Rodolfo Alonso Hernandez Date: Wed, 3 Apr 2019 09:27:29 +0100 Subject: [PATCH] Implement providernet._raise_if_updates_provider_attributes internally Function [1] is a private function in Neutron and should not be imported in other projects. Also this function is removed in [2], while implementing the related bug. Related-Bug: #1806052 [1] https://github.com/openstack/neutron/blob/stable/stein/neutron/extensions/providernet.py#L24 [2] https://review.openstack.org/#/c/633165/ Change-Id: Ic6260fbe944062c8db7c888b77c3725b2f44c68c --- vmware_nsx/common/utils.py | 15 +++++++++++++++ vmware_nsx/plugins/dvs/plugin.py | 3 +-- vmware_nsx/plugins/nsx_mh/plugin.py | 3 +-- vmware_nsx/plugins/nsx_p/plugin.py | 3 +-- vmware_nsx/plugins/nsx_v/plugin.py | 3 +-- vmware_nsx/plugins/nsx_v3/plugin.py | 3 +-- 6 files changed, 20 insertions(+), 10 deletions(-) diff --git a/vmware_nsx/common/utils.py b/vmware_nsx/common/utils.py index 3bdadbfe31..5b5c69b271 100644 --- a/vmware_nsx/common/utils.py +++ b/vmware_nsx/common/utils.py @@ -26,9 +26,12 @@ import six import tenacity from tenacity import _utils as tenacity_utils +from neutron._i18n import _ from neutron import version as n_version +from neutron_lib.api.definitions import provider_net from neutron_lib.api import validators from neutron_lib import constants +from neutron_lib import exceptions as n_exc from oslo_context import context as common_context from oslo_log import log @@ -295,3 +298,15 @@ def spawn_n(func, *args, **kwargs): func(*args, **kwargs) eventlet.spawn_n(context_wrapper, *args, **kwargs) + + +def raise_if_updates_provider_attributes(attrs): + """Raise exception if provider attributes are present. + + This method is used for plugins that do not support updating provider + network attributes. + """ + if any(validators.is_attr_set(attrs.get(a)) + for a in provider_net.ATTRIBUTES): + msg = _("Plugin does not support updating provider attributes") + raise n_exc.InvalidInput(error_message=msg) diff --git a/vmware_nsx/plugins/dvs/plugin.py b/vmware_nsx/plugins/dvs/plugin.py index cb3eb8ab14..6ceb2b1958 100644 --- a/vmware_nsx/plugins/dvs/plugin.py +++ b/vmware_nsx/plugins/dvs/plugin.py @@ -47,7 +47,6 @@ from neutron.db import portbindings_db from neutron.db import portsecurity_db from neutron.db import securitygroups_db from neutron.db import vlantransparent_db as vlan_ext_db -from neutron.extensions import providernet from neutron.extensions import securitygroup as ext_sg from neutron.quota import resource_registry @@ -377,7 +376,7 @@ class NsxDvsV2(addr_pair_db.AllowedAddressPairsMixin, def update_network(self, context, id, network): net_attrs = network['network'] - providernet._raise_if_updates_provider_attributes(net_attrs) + c_utils.raise_if_updates_provider_attributes(net_attrs) with db_api.CONTEXT_WRITER.using(context): net_res = super(NsxDvsV2, self).update_network(context, id, diff --git a/vmware_nsx/plugins/nsx_mh/plugin.py b/vmware_nsx/plugins/nsx_mh/plugin.py index c4d2c1afe8..c75548b6cf 100644 --- a/vmware_nsx/plugins/nsx_mh/plugin.py +++ b/vmware_nsx/plugins/nsx_mh/plugin.py @@ -69,7 +69,6 @@ from neutron.db import models_v2 from neutron.db import portbindings_db from neutron.db import portsecurity_db from neutron.db import securitygroups_db -from neutron.extensions import providernet from neutron.extensions import securitygroup as ext_sg from neutron.quota import resource_registry @@ -1070,7 +1069,7 @@ class NsxPluginV2(addr_pair_db.AllowedAddressPairsMixin, fields) for network in networks]) def update_network(self, context, id, network): - providernet._raise_if_updates_provider_attributes(network['network']) + c_utils.raise_if_updates_provider_attributes(network['network']) if network["network"].get("admin_state_up") is False: raise NotImplementedError(_("admin_state_up=False networks " "are not supported.")) diff --git a/vmware_nsx/plugins/nsx_p/plugin.py b/vmware_nsx/plugins/nsx_p/plugin.py index 06d3fc1a3f..165c4b1657 100644 --- a/vmware_nsx/plugins/nsx_p/plugin.py +++ b/vmware_nsx/plugins/nsx_p/plugin.py @@ -26,7 +26,6 @@ from neutron.db import l3_db from neutron.db.models import l3 as l3_db_models from neutron.db.models import securitygroup as securitygroup_model # noqa from neutron.db import models_v2 -from neutron.extensions import providernet from neutron.extensions import securitygroup as ext_sg from neutron.quota import resource_registry from neutron_lib.api.definitions import address_scope @@ -675,7 +674,7 @@ class NsxPolicyPlugin(nsx_plugin_common.NsxPluginV3Base): self._assert_on_resource_admin_state_down(net_data) # Neutron does not support changing provider network values - providernet._raise_if_updates_provider_attributes(net_data) + utils.raise_if_updates_provider_attributes(net_data) extern_net = self._network_is_external(context, network_id) is_nsx_net = self._network_is_nsx_net(context, network_id) diff --git a/vmware_nsx/plugins/nsx_v/plugin.py b/vmware_nsx/plugins/nsx_v/plugin.py index 9a284a26f4..a910b49667 100644 --- a/vmware_nsx/plugins/nsx_v/plugin.py +++ b/vmware_nsx/plugins/nsx_v/plugin.py @@ -91,7 +91,6 @@ from neutron.db import models_v2 from neutron.db import portsecurity_db from neutron.db import securitygroups_db from neutron.db import vlantransparent_db -from neutron.extensions import providernet from neutron.extensions import securitygroup as ext_sg from neutron.quota import resource_registry from neutron.services.flavors import flavors_plugin @@ -1676,7 +1675,7 @@ class NsxVPluginV2(addr_pair_db.AllowedAddressPairsMixin, not validators.is_attr_set( attrs.get(pnet.SEGMENTATION_ID))): return - providernet._raise_if_updates_provider_attributes(attrs) + c_utils.raise_if_updates_provider_attributes(attrs) def _update_vlan_network_dvs_ids(self, context, network, new_physical_network, az_dvs): diff --git a/vmware_nsx/plugins/nsx_v3/plugin.py b/vmware_nsx/plugins/nsx_v3/plugin.py index b076cd1419..5169893200 100644 --- a/vmware_nsx/plugins/nsx_v3/plugin.py +++ b/vmware_nsx/plugins/nsx_v3/plugin.py @@ -58,7 +58,6 @@ from neutron.db import l3_db from neutron.db.models import l3 as l3_db_models from neutron.db.models import securitygroup as securitygroup_model # noqa from neutron.db import models_v2 -from neutron.extensions import providernet from neutron.extensions import securitygroup as ext_sg from neutron.quota import resource_registry @@ -1075,7 +1074,7 @@ class NsxV3Plugin(nsx_plugin_common.NsxPluginV3Base, original_net = super(NsxV3Plugin, self).get_network(context, id) net_data = network['network'] # Neutron does not support changing provider network values - providernet._raise_if_updates_provider_attributes(net_data) + utils.raise_if_updates_provider_attributes(net_data) extern_net = self._network_is_external(context, id) is_nsx_net = self._network_is_nsx_net(context, id) is_ens_net = self._is_ens_tz_net(context, id)