From f78174aa3cb0f88c995b2b1f61d10a0761b7bfe7 Mon Sep 17 00:00:00 2001 From: Salvatore Orlando Date: Wed, 1 May 2013 12:32:17 +0200 Subject: [PATCH] Avoid initialization of policy engine before extensions are loaded Bug 1174877 For a particular NVP extension, a database entry was being populated in the plugin's __init__ method. The entry was added with an admin context. Grabbing the context caused the policy engine to load before all the extension were loaded, so rule on extended attribute were not being parsed correctly. This cause checks on external networks to fail always. Change-Id: Icbc759773acab2a7687883d8d2844272c8ea55a3 --- quantum/plugins/nicira/QuantumPlugin.py | 37 +++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/quantum/plugins/nicira/QuantumPlugin.py b/quantum/plugins/nicira/QuantumPlugin.py index dd44db286..f56e4e8fd 100644 --- a/quantum/plugins/nicira/QuantumPlugin.py +++ b/quantum/plugins/nicira/QuantumPlugin.py @@ -188,9 +188,13 @@ class NvpPluginV2(db_base_plugin_v2.QuantumDbPluginV2, self.setup_rpc() self.network_scheduler = importutils.import_object( cfg.CONF.network_scheduler_driver) - self._ensure_default_network_gateway() + # Set this flag to false as the default gateway has not + # been yet updated from the config file + self._is_default_net_gw_in_sync = False def _ensure_default_network_gateway(self): + if self._is_default_net_gw_in_sync: + return # Add the gw in the db as default, and unset any previous default def_l2_gw_uuid = self.cluster.default_l2_gw_service_uuid try: @@ -212,8 +216,9 @@ class NvpPluginV2(db_base_plugin_v2.QuantumDbPluginV2, ctx, {gw_res_name: def_gw_data}) # In any case set is as default self._set_default_network_gateway(ctx, def_network_gw['id']) + # Ensure this method is executed only once + self._is_default_net_gw_in_sync = True except Exception: - # This is fatal - abort startup LOG.exception(_("Unable to process default l2 gw service:%s"), def_l2_gw_uuid) raise @@ -1859,6 +1864,8 @@ class NvpPluginV2(db_base_plugin_v2.QuantumDbPluginV2, Create the gateway service on NVP platform and corresponding data structures in Quantum datase. """ + # Ensure the default gateway in the config file is in sync with the db + self._ensure_default_network_gateway() # Need to re-do authZ checks here in order to avoid creation on NVP gw_data = network_gateway[networkgw.RESOURCE_NAME.replace('-', '_')] tenant_id = self._get_tenant_id_for_create(context, gw_data) @@ -1886,6 +1893,8 @@ class NvpPluginV2(db_base_plugin_v2.QuantumDbPluginV2, Remove the gateway service from NVP platform and corresponding data structures in Quantum datase. """ + # Ensure the default gateway in the config file is in sync with the db + self._ensure_default_network_gateway() with context.session.begin(subtransactions=True): try: super(NvpPluginV2, self).delete_network_gateway(context, id) @@ -1902,6 +1911,8 @@ class NvpPluginV2(db_base_plugin_v2.QuantumDbPluginV2, return net_gateway def get_network_gateway(self, context, id, fields=None): + # Ensure the default gateway in the config file is in sync with the db + self._ensure_default_network_gateway() # Ensure the tenant_id attribute is populated on the returned gateway #return self._ensure_tenant_on_net_gateway( # context, super(NvpPluginV2, self).get_network_gateway( @@ -1910,6 +1921,8 @@ class NvpPluginV2(db_base_plugin_v2.QuantumDbPluginV2, id, fields) def get_network_gateways(self, context, filters=None, fields=None): + # Ensure the default gateway in the config file is in sync with the db + self._ensure_default_network_gateway() # Ensure the tenant_id attribute is populated on returned gateways net_gateways = super(NvpPluginV2, self).get_network_gateways(context, @@ -1917,6 +1930,26 @@ class NvpPluginV2(db_base_plugin_v2.QuantumDbPluginV2, fields) return net_gateways + def update_network_gateway(self, context, id, network_gateway): + # Ensure the default gateway in the config file is in sync with the db + self._ensure_default_network_gateway() + return super(NvpPluginV2, self).update_network_gateway( + context, id, network_gateway) + + def connect_network(self, context, network_gateway_id, + network_mapping_info): + # Ensure the default gateway in the config file is in sync with the db + self._ensure_default_network_gateway() + return super(NvpPluginV2, self).connect_network( + context, network_gateway_id, network_mapping_info) + + def disconnect_network(self, context, network_gateway_id, + network_mapping_info): + # Ensure the default gateway in the config file is in sync with the db + self._ensure_default_network_gateway() + return super(NvpPluginV2, self).disconnect_network( + context, network_gateway_id, network_mapping_info) + def get_plugin_version(self): return PLUGIN_VERSION -- 2.45.2