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
This commit is contained in:
Pratik Shah 2017-06-29 15:55:27 +05:30
parent d86cd042c3
commit 874e3058de
2 changed files with 28 additions and 6 deletions

View File

@ -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:

View File

@ -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')