From 874e3058def2ec0303a4c2fda3773bc4954641d7 Mon Sep 17 00:00:00 2001 From: Pratik Shah Date: Thu, 29 Jun 2017 15:55:27 +0530 Subject: [PATCH] Added a fix for Neutron GCE to run on stable/newton and master branch Files modified: - neutron/neutron/plugins/ml2/drivers/gce/mech_gce.py - neutron/tests/plugins/ml2/drivers/gce/test_gce.py Change-Id: Ia91c77ede8acf9d90e98384cd5af5c027be4d685 --- .../plugins/ml2/drivers/gce/mech_gce.py | 26 +++++++++++++++---- .../tests/plugins/ml2/drivers/gce/test_gce.py | 8 +++++- 2 files changed, 28 insertions(+), 6 deletions(-) diff --git a/neutron/neutron/plugins/ml2/drivers/gce/mech_gce.py b/neutron/neutron/plugins/ml2/drivers/gce/mech_gce.py index 73fb595..5b79f28 100644 --- a/neutron/neutron/plugins/ml2/drivers/gce/mech_gce.py +++ b/neutron/neutron/plugins/ml2/drivers/gce/mech_gce.py @@ -25,8 +25,12 @@ from neutron.common import gceconf from neutron.common import gceutils from neutron.manager import NeutronManager from neutron.plugins.ml2 import driver_api as api -from neutron_lib import exceptions as e from neutron.extensions import securitygroup as sg +from neutron_lib import exceptions as e +try: + from neutron_lib.plugins import directory +except ImportError: + pass LOG = log.getLogger(__name__) @@ -216,7 +220,10 @@ class GceMechanismDriver(api.MechanismDriver): except gceutils.HttpError: return - core_plugin = NeutronManager.get_plugin() + try: + core_plugin = NeutronManager.get_plugin() + except AttributeError: + core_plugin = directory.get_plugin() rule = core_plugin.get_security_group_rule(context, rule_id) network_link = gce_firewall_info['network'] @@ -246,7 +253,10 @@ class GceMechanismDriver(api.MechanismDriver): pass def _create_secgrp_rules_if_needed(self, context, secgrp_ids): - core_plugin = NeutronManager.get_plugin() + try: + core_plugin = NeutronManager.get_plugin() + except AttributeError: + core_plugin = directory.get_plugin() secgrp_rules = [] for secgrp_id in secgrp_ids: secgrp = core_plugin.get_security_group(context._plugin_context, @@ -266,14 +276,20 @@ class GceMechanismDriver(api.MechanismDriver): network_link) def _update_secgrp(self, context, secgrp_id): - core_plugin = NeutronManager.get_plugin() + try: + core_plugin = NeutronManager.get_plugin() + except AttributeError: + core_plugin = directory.get_plugin() secgrp = core_plugin.get_security_group(context, secgrp_id) secgrp_rules = secgrp['security_group_rules'] for secgrp_rule in secgrp_rules: self._update_secgrp_rule(context, secgrp_rule['id']) def _delete_secgrp(self, context, secgrp_id): - core_plugin = NeutronManager.get_plugin() + try: + core_plugin = NeutronManager.get_plugin() + except AttributeError: + core_plugin = directory.get_plugin() secgrp = core_plugin.get_security_group(context, secgrp_id) secgrp_rules = secgrp['security_group_rules'] for secgrp_rule in secgrp_rules: diff --git a/neutron/tests/plugins/ml2/drivers/gce/test_gce.py b/neutron/tests/plugins/ml2/drivers/gce/test_gce.py index d629a76..a702736 100644 --- a/neutron/tests/plugins/ml2/drivers/gce/test_gce.py +++ b/neutron/tests/plugins/ml2/drivers/gce/test_gce.py @@ -18,6 +18,7 @@ import mock from neutron.tests import base from neutron.plugins.ml2.drivers.gce.mech_gce import GceMechanismDriver from neutron.plugins.ml2.drivers.gce.mech_gce import SecurityGroupInvalidDirection +from neutron.manager import NeutronManager from neutron.tests.common.gce import gce_mock from neutron.tests.common.gce.gce_mock import FakeNeutronManager from neutron.tests.unit.extensions import test_securitygroup as test_sg @@ -27,6 +28,11 @@ from neutron_lib import constants as const DATA_DIR = os.path.dirname(os.path.abspath("gce_mock.py")) + '/data' NETWORK_LINK = "projects/omni-163105/global/networks/net-03c4f178-670e-4805-a511-9470ca4a0b06" +if hasattr(NeutronManager, "get_plugin"): + neutron_get_plugin = 'neutron.manager.NeutronManager.get_plugin' +else: + neutron_get_plugin = 'neutron_lib.plugins.directory.get_plugin' + class GCENeutronTestCase(test_sg.SecurityGroupsTestCase, base.BaseTestCase): @mock.patch('neutron.common.gceutils.get_gce_service') @@ -144,7 +150,7 @@ class GCENeutronTestCase(test_sg.SecurityGroupsTestCase, base.BaseTestCase): self._driver.gce_project, gce_mock.fake_operation()) - @mock.patch('neutron.manager.NeutronManager.get_plugin') + @mock.patch(neutron_get_plugin) @mock.patch('neutron.common.gceutils.wait_for_operation') @mock.patch('neutron.common.gceutils.update_firewall_rule') @mock.patch('neutron.common.gceutils.get_firewall_rule')