trunk: Remove ovs constants from trunk utils module

Trunk utils should be driver agnostic.

Change-Id: Iec646b3b11b03687013db5af6afda3a21c03acb6
Closes-Bug: 1622632
This commit is contained in:
Jakub Libosvar 2016-09-12 16:37:37 +02:00 committed by Armando Migliaccio
parent 7adfe5668d
commit 68d13b92a5
8 changed files with 33 additions and 17 deletions
neutron
services/trunk
tests
functional/services/trunk
drivers/openvswitch/agent
test_plugin.py
unit/services/trunk/drivers/openvswitch

@ -35,8 +35,8 @@ from neutron.services.trunk import constants
from neutron.services.trunk.drivers.openvswitch.agent \
import trunk_manager as tman
from neutron.services.trunk.drivers.openvswitch import constants as t_const
from neutron.services.trunk.drivers.openvswitch import utils
from neutron.services.trunk.rpc import agent
from neutron.services.trunk import utils as trunk_utils
LOG = logging.getLogger(__name__)
@ -178,7 +178,7 @@ class OVSDBHandler(object):
def manages_this_trunk(self, trunk_id):
"""True if this OVSDB handler manages trunk based on given ID."""
bridge_name = trunk_utils.gen_trunk_br_name(trunk_id)
bridge_name = utils.gen_trunk_br_name(trunk_id)
return ovs_lib.BaseOVS().bridge_exists(bridge_name)
def wire_subports_for_trunk(self, context, trunk_id, subports,
@ -308,7 +308,7 @@ class OVSDBHandler(object):
# name, trunk id and subport ids so we can easily remove the trunk
# bridge and service ports once this port is removed
trunk_bridge = trunk_bridge or ovs_lib.OVSBridge(
trunk_utils.gen_trunk_br_name(trunk_id))
utils.gen_trunk_br_name(trunk_id))
port = port or self._get_parent_port(trunk_bridge)
port['external_ids']['bridge_name'] = trunk_bridge.br_name

@ -19,7 +19,7 @@ from oslo_log import log as logging
from neutron._i18n import _
from neutron.agent.common import ovs_lib
from neutron.services.trunk.drivers.openvswitch.agent import exceptions as exc
from neutron.services.trunk import utils
from neutron.services.trunk.drivers.openvswitch import utils
LOG = logging.getLogger(__name__)

@ -22,7 +22,7 @@ from neutron.plugins.ml2.drivers.openvswitch.agent.common import (
constants as agent_consts)
from neutron.services.trunk import constants as trunk_consts
from neutron.services.trunk.drivers import base
from neutron.services.trunk import utils
from neutron.services.trunk.drivers.openvswitch import utils
LOG = logging.getLogger(__name__)

@ -0,0 +1,21 @@
# (c) Copyright 2016 Hewlett Packard Enterprise Development LP
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
from neutron_lib import constants
from neutron.services.trunk.drivers.openvswitch import constants as ovs_const
def gen_trunk_br_name(trunk_id):
return ((ovs_const.TRUNK_BR_PREFIX + trunk_id)
[:constants.DEVICE_NAME_MAX_LEN - 1])

@ -12,16 +12,8 @@
# License for the specific language governing permissions and limitations
# under the License.
from neutron_lib import constants
from neutron.common import utils
from neutron import manager
from neutron.services.trunk.drivers.openvswitch import constants as ovs_const
def gen_trunk_br_name(trunk_id):
return ((ovs_const.TRUNK_BR_PREFIX + trunk_id)
[:constants.DEVICE_NAME_MAX_LEN - 1])
def get_agent_types_by_host(context, host):

@ -21,7 +21,7 @@ import testtools
from neutron.common import utils as common_utils
from neutron.services.trunk.drivers.openvswitch.agent import trunk_manager
from neutron.services.trunk import utils
from neutron.services.trunk.drivers.openvswitch import utils
from neutron.tests.common import conn_testers
from neutron.tests.common import helpers
from neutron.tests.common import net_helpers

@ -13,8 +13,8 @@
# under the License.
from neutron.extensions import portbindings as pb
from neutron.services.trunk.drivers.openvswitch import utils
from neutron.services.trunk import plugin as trunk_plugin
from neutron.services.trunk import utils as trunk_utils
from neutron.tests.common import helpers
from neutron.tests.unit.plugins.ml2 import base as ml2_test_base
@ -38,7 +38,7 @@ class TestTrunkServicePlugin(ml2_test_base.ML2TestFramework):
bound_port = self.core_plugin.update_port(self.context,
trunk_port_id, port)
self.assertEqual(
trunk_utils.gen_trunk_br_name(trunk_res['id']),
utils.gen_trunk_br_name(trunk_res['id']),
bound_port[pb.VIF_DETAILS][pb.VIF_DETAILS_BRIDGE_NAME])
def test_ovs_bridge_name_not_set_when_not_trunk(self):

@ -23,6 +23,9 @@ from neutron.plugins.ml2.drivers.openvswitch.agent.common import (
from neutron.services.trunk.drivers.openvswitch import driver
from neutron.tests import base
GEN_TRUNK_BR_NAME_PATCH = (
'neutron.services.trunk.drivers.openvswitch.utils.gen_trunk_br_name')
class OVSDriverTestCase(base.BaseTestCase):
@ -51,7 +54,7 @@ class OVSDriverTestCase(base.BaseTestCase):
ovs_driver = driver.OVSDriver.create()
self.assertFalse(ovs_driver.is_loaded)
@mock.patch('neutron.services.trunk.utils.gen_trunk_br_name')
@mock.patch(GEN_TRUNK_BR_NAME_PATCH)
def test_vif_details_bridge_name_handler_registration(self,
mock_gen_br_name):
driver.register()