[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
This commit is contained in:
zhiyuan_cai 2018-01-21 17:10:43 +08:00
parent 284a228f83
commit 1cb38b8397
4 changed files with 51 additions and 43 deletions

View File

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

View File

@ -65,12 +65,7 @@ from tricircle.db import core
from tricircle.db import models from tricircle.db import models
import tricircle.network.central_plugin as plugin import tricircle.network.central_plugin as plugin
from tricircle.network import central_qos_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 helper
from tricircle.network import managers
from tricircle.network import qos_driver from tricircle.network import qos_driver
from tricircle.tests.unit.network import test_qos from tricircle.tests.unit.network import test_qos
from tricircle.tests.unit.network import test_security_groups 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}) 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): class FakeHelper(helper.NetworkHelper):
def _get_client(self, region_name=None): def _get_client(self, region_name=None):
return FakeClient(region_name) return FakeClient(region_name)
@ -757,34 +747,6 @@ class FakeHelper(helper.NetworkHelper):
t_ctx, q_ctx, _type, _id) 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): class FakeExtensionManager(n_managers.ExtensionManager):
def __init__(self): def __init__(self):
super(FakeExtensionManager, self).__init__() super(FakeExtensionManager, self).__init__()
@ -821,7 +783,7 @@ class FakePlugin(plugin.TricirclePlugin,
self.set_ipam_backend() self.set_ipam_backend()
self.helper = FakeHelper(self) self.helper = FakeHelper(self)
self.xjob_handler = FakeRPCAPI(self) self.xjob_handler = FakeRPCAPI(self)
self.type_manager = FakeTypeManager() self.type_manager = test_utils.FakeTypeManager()
self.extension_manager = FakeExtensionManager() self.extension_manager = FakeExtensionManager()
self.extension_manager.initialize() self.extension_manager.initialize()
self.driver_manager = FakeQosServiceDriverManager() self.driver_manager = FakeQosServiceDriverManager()
@ -858,6 +820,10 @@ class FakePlugin(plugin.TricirclePlugin,
subnet = ori_subnet._as_dict() subnet = ori_subnet._as_dict()
else: else:
subnet = ori_subnet 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: if type(subnet.get('gateway_ip')) == netaddr.ip.IPAddress:
subnet['gateway_ip'] = str(subnet['gateway_ip']) subnet['gateway_ip'] = str(subnet['gateway_ip'])
if 'project_id' in subnet: if 'project_id' in subnet:

View File

@ -215,7 +215,7 @@ def fake_get_min_search_step(self):
class FakeCorePlugin(central_plugin.TricirclePlugin): class FakeCorePlugin(central_plugin.TricirclePlugin):
def __init__(self): def __init__(self):
pass self.type_manager = test_utils.FakeTypeManager()
def get_port(self, context, port_id): def get_port(self, context, port_id):
return {portbindings.HOST_ID: None, return {portbindings.HOST_ID: None,
@ -242,6 +242,10 @@ class PluginTest(unittest.TestCase):
core.initialize() core.initialize()
core.ModelBase.metadata.create_all(core.get_engine()) core.ModelBase.metadata.create_all(core.get_engine())
self.context = context.Context() 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 xmanager.IN_TEST = True
def fake_get_plugin(alias='core'): def fake_get_plugin(alias='core'):

View File

@ -27,6 +27,11 @@ import neutron_lib.context as q_context
import neutron_lib.objects.exceptions as q_obj_exceptions import neutron_lib.objects.exceptions as q_obj_exceptions
from tricircle.common import constants 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): class ResourceStore(object):
@ -622,3 +627,36 @@ class FakeClient(object):
updated = True updated = True
res.update(body[_type]) res.update(body[_type])
return updated 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