Browse Source

[Urgent] fix unit test errors

This patch fixes two unit test errors. One is "ipv6_address_mode not
found", the other is "has no attribute type_manager". The first error
is addressed by the previous patch[1] but cannot be merged due to the
second error, so this patch address these two errors at the same time.

[1] https://review.openstack.org/#/c/532417/

Change-Id: Ibda5b5870fa8466b3f5a886ee0c16a2ec8c74abc
changes/89/536089/2
zhiyuan_cai 3 years ago
parent
commit
1cb38b8397
4 changed files with 51 additions and 43 deletions
  1. +3
    -3
      tricircle/network/central_trunk_plugin.py
  2. +5
    -39
      tricircle/tests/unit/network/test_central_plugin.py
  3. +5
    -1
      tricircle/tests/unit/network/test_central_trunk_plugin.py
  4. +38
    -0
      tricircle/tests/unit/utils.py

+ 3
- 3
tricircle/network/central_trunk_plugin.py View File

@ -307,10 +307,10 @@ class TricircleTrunkPlugin(plugin.TrunkPlugin):
def add_subports(self, context, trunk_id, subports):
t_ctx = t_context.get_context_from_neutron_context(context)
with context.session.begin():
res = super(TricircleTrunkPlugin, self).add_subports(
context, trunk_id, subports)
self.update_subports_device_id(context, subports, trunk_id,
t_constants.DEVICE_OWNER_SUBPORT)
res = super(TricircleTrunkPlugin, self).add_subports(
context, trunk_id, subports)
mappings = db_api.get_bottom_mappings_by_top_id(
t_ctx, trunk_id, t_constants.RT_TRUNK)
if mappings:
@ -323,9 +323,9 @@ class TricircleTrunkPlugin(plugin.TrunkPlugin):
def remove_subports(self, context, trunk_id, subports):
t_ctx = t_context.get_context_from_neutron_context(context)
with context.session.begin():
self.update_subports_device_id(context, subports, '', '')
res = super(TricircleTrunkPlugin, self).remove_subports(
context, trunk_id, subports)
self.update_subports_device_id(context, subports, '', '')
mappings = db_api.get_bottom_mappings_by_top_id(
t_ctx, trunk_id, t_constants.RT_TRUNK)
if mappings:


+ 5
- 39
tricircle/tests/unit/network/test_central_plugin.py View File

@ -65,12 +65,7 @@ from tricircle.db import core
from tricircle.db import models
import tricircle.network.central_plugin as plugin
from tricircle.network import central_qos_plugin
from tricircle.network.drivers import type_flat
from tricircle.network.drivers import type_local
from tricircle.network.drivers import type_vlan
from tricircle.network.drivers import type_vxlan
from tricircle.network import helper
from tricircle.network import managers
from tricircle.network import qos_driver
from tricircle.tests.unit.network import test_qos
from tricircle.tests.unit.network import test_security_groups
@ -734,11 +729,6 @@ class FakeRPCAPI(FakeBaseRPCAPI):
ctxt, payload={constants.JT_SHADOW_PORT_SETUP: combine_id})
class FakeExtension(object):
def __init__(self, ext_obj):
self.obj = ext_obj
class FakeHelper(helper.NetworkHelper):
def _get_client(self, region_name=None):
return FakeClient(region_name)
@ -757,34 +747,6 @@ class FakeHelper(helper.NetworkHelper):
t_ctx, q_ctx, _type, _id)
class FakeTypeManager(managers.TricircleTypeManager):
def _register_types(self):
local_driver = type_local.LocalTypeDriver()
self.drivers[constants.NT_LOCAL] = FakeExtension(local_driver)
vlan_driver = type_vlan.VLANTypeDriver()
self.drivers[constants.NT_VLAN] = FakeExtension(vlan_driver)
vxlan_driver = type_vxlan.VxLANTypeDriver()
self.drivers[constants.NT_VxLAN] = FakeExtension(vxlan_driver)
local_driver = type_flat.FlatTypeDriver()
self.drivers[constants.NT_FLAT] = FakeExtension(local_driver)
def extend_network_dict_provider(self, cxt, net):
target_net = None
for t_net in TOP_NETS:
if t_net['id'] == net['id']:
target_net = t_net
if not target_net:
return
for segment in TOP_SEGMENTS:
if target_net['id'] == segment['network_id']:
target_net['provider:network_type'] = segment['network_type']
target_net[
'provider:physical_network'] = segment['physical_network']
target_net[
'provider:segmentation_id'] = segment['segmentation_id']
break
class FakeExtensionManager(n_managers.ExtensionManager):
def __init__(self):
super(FakeExtensionManager, self).__init__()
@ -821,7 +783,7 @@ class FakePlugin(plugin.TricirclePlugin,
self.set_ipam_backend()
self.helper = FakeHelper(self)
self.xjob_handler = FakeRPCAPI(self)
self.type_manager = FakeTypeManager()
self.type_manager = test_utils.FakeTypeManager()
self.extension_manager = FakeExtensionManager()
self.extension_manager.initialize()
self.driver_manager = FakeQosServiceDriverManager()
@ -858,6 +820,10 @@ class FakePlugin(plugin.TricirclePlugin,
subnet = ori_subnet._as_dict()
else:
subnet = ori_subnet
if 'ipv6_ra_mode' not in subnet:
subnet['ipv6_ra_mode'] = None
if 'ipv6_address_mode' not in subnet:
subnet['ipv6_address_mode'] = None
if type(subnet.get('gateway_ip')) == netaddr.ip.IPAddress:
subnet['gateway_ip'] = str(subnet['gateway_ip'])
if 'project_id' in subnet:


+ 5
- 1
tricircle/tests/unit/network/test_central_trunk_plugin.py View File

@ -215,7 +215,7 @@ def fake_get_min_search_step(self):
class FakeCorePlugin(central_plugin.TricirclePlugin):
def __init__(self):
pass
self.type_manager = test_utils.FakeTypeManager()
def get_port(self, context, port_id):
return {portbindings.HOST_ID: None,
@ -242,6 +242,10 @@ class PluginTest(unittest.TestCase):
core.initialize()
core.ModelBase.metadata.create_all(core.get_engine())
self.context = context.Context()
cfg.CONF.set_override('tenant_network_types', ['local', 'vlan'],
group='tricircle')
cfg.CONF.set_override('bridge_network_type', 'vlan',
group='tricircle')
xmanager.IN_TEST = True
def fake_get_plugin(alias='core'):


+ 38
- 0
tricircle/tests/unit/utils.py View File

@ -27,6 +27,11 @@ import neutron_lib.context as q_context
import neutron_lib.objects.exceptions as q_obj_exceptions
from tricircle.common import constants
from tricircle.network.drivers import type_flat
from tricircle.network.drivers import type_local
from tricircle.network.drivers import type_vlan
from tricircle.network.drivers import type_vxlan
from tricircle.network import managers
class ResourceStore(object):
@ -622,3 +627,36 @@ class FakeClient(object):
updated = True
res.update(body[_type])
return updated
class FakeTypeManager(managers.TricircleTypeManager):
def _register_types(self):
local_driver = type_local.LocalTypeDriver()
self.drivers[constants.NT_LOCAL] = FakeExtension(local_driver)
vlan_driver = type_vlan.VLANTypeDriver()
self.drivers[constants.NT_VLAN] = FakeExtension(vlan_driver)
vxlan_driver = type_vxlan.VxLANTypeDriver()
self.drivers[constants.NT_VxLAN] = FakeExtension(vxlan_driver)
local_driver = type_flat.FlatTypeDriver()
self.drivers[constants.NT_FLAT] = FakeExtension(local_driver)
def extend_network_dict_provider(self, cxt, net):
target_net = None
for t_net in get_resource_store().TOP_NETWORKS:
if t_net['id'] == net['id']:
target_net = t_net
if not target_net:
return
for segment in get_resource_store().TOP_NETWORKSEGMENTS:
if target_net['id'] == segment['network_id']:
target_net['provider:network_type'] = segment['network_type']
target_net[
'provider:physical_network'] = segment['physical_network']
target_net[
'provider:segmentation_id'] = segment['segmentation_id']
break
class FakeExtension(object):
def __init__(self, ext_obj):
self.obj = ext_obj

Loading…
Cancel
Save