fix and reverse unit tests about network_segment_ranges
some unit tests can not been passed as stein version neutron refreshed. this patch is to fixed some problems about the loading network_segment_ranges db error and reverse other related unit tests. Change-Id: I55448c9313e890d36e58e25077e4e00945f96ca9 signed-off-by: zhangchi <zhangchi@szzt.com.cn> co-Authored-By: tangzhuo <ztang@hnu.edu.cn>
This commit is contained in:
parent
196826a8fb
commit
1a3a6bb9bb
File diff suppressed because it is too large
Load Diff
|
@ -692,9 +692,119 @@ class PluginTest(unittest.TestCase):
|
|||
def test_get_port(self):
|
||||
self._basic_pod_setup()
|
||||
project_id = TEST_TENANT_ID
|
||||
fake_plugin = FakeSfcPlugin()
|
||||
t_ctx = context.get_db_context()
|
||||
port_id = self._prepare_port_test(project_id, t_ctx, 'pod_1', None)
|
||||
self.assertIsNotNone(port_id)
|
||||
port = fake_plugin._get_port(context, port_id)
|
||||
self.assertIsNotNone(port)
|
||||
|
||||
@patch.object(db_base_plugin_v2.NeutronDbPluginV2, 'get_port',
|
||||
new=FakeCorePlugin.get_port)
|
||||
@patch.object(sfc_db.SfcDbPlugin, 'get_port_pairs',
|
||||
new=FakeSfcPlugin.get_port_pairs)
|
||||
@patch.object(context, 'get_context_from_neutron_context',
|
||||
new=fake_get_context_from_neutron_context)
|
||||
def test_create_port_chain(self):
|
||||
project_id = TEST_TENANT_ID
|
||||
q_ctx = FakeNeutronContext()
|
||||
t_ctx = context.get_db_context()
|
||||
self._basic_pod_setup()
|
||||
fake_plugin = FakeSfcPlugin()
|
||||
|
||||
t_net_id = self._prepare_net_test(project_id, t_ctx, 'pod_1')
|
||||
ingress = self._prepare_port_test(project_id, t_ctx, 'pod_1', t_net_id)
|
||||
egress = self._prepare_port_test(project_id, t_ctx, 'pod_1', t_net_id)
|
||||
src_port_id = self._prepare_port_test(project_id,
|
||||
t_ctx, 'pod_1', t_net_id)
|
||||
t_pp1_id, _ = self._prepare_port_pair_test(
|
||||
project_id, t_ctx, 'pod_1', 0, ingress, egress, False)
|
||||
t_ppg1_id, _ = self._prepare_port_pair_group_test(
|
||||
project_id, t_ctx, 'pod_1', 0, [t_pp1_id], False, None)
|
||||
ppg1_mapping = {t_pp1_id: t_ppg1_id}
|
||||
self._update_port_pair_test(ppg1_mapping, TOP_PORTPAIRS)
|
||||
t_fc1_id, _ = self._prepare_flow_classifier_test(
|
||||
project_id, t_ctx, 'pod_1', 0, src_port_id, False)
|
||||
body = {"port_chain": {
|
||||
"tenant_id": project_id,
|
||||
"name": "pc1",
|
||||
"chain_parameters": {
|
||||
"symmetric": False, "correlation": "mpls"},
|
||||
"port_pair_groups": [t_ppg1_id],
|
||||
"flow_classifiers": [t_fc1_id],
|
||||
"project_id": project_id,
|
||||
"chain_id": 1,
|
||||
"description": ""}}
|
||||
t_pc1 = fake_plugin.create_port_chain(q_ctx, body)
|
||||
pp1_mappings = db_api.get_bottom_mappings_by_top_id(
|
||||
t_ctx, t_pp1_id, constants.RT_PORT_PAIR)
|
||||
ppg1_mappings = db_api.get_bottom_mappings_by_top_id(
|
||||
t_ctx, t_ppg1_id, constants.RT_PORT_PAIR_GROUP)
|
||||
fc1_mappings = db_api.get_bottom_mappings_by_top_id(
|
||||
t_ctx, t_fc1_id, constants.RT_FLOW_CLASSIFIER)
|
||||
pc1_mappings = db_api.get_bottom_mappings_by_top_id(
|
||||
t_ctx, t_pc1['id'], constants.RT_PORT_CHAIN)
|
||||
btm1_pp_ids = [btm_pp['id'] for btm_pp in BOTTOM1_PORTPAIRS]
|
||||
btm1_ppg_ids = [btm_ppg['id'] for btm_ppg in BOTTOM1_PORTPAIRGROUPS]
|
||||
btm1_fc_ids = [btm_fc['id'] for btm_fc in BOTTOM1_FLOWCLASSIFIERS]
|
||||
btm1_pc_ids = [btm_pc['id'] for btm_pc in BOTTOM1_PORTCHAINS]
|
||||
b_pp1_id = pp1_mappings[0][1]
|
||||
b_ppg1_id = ppg1_mappings[0][1]
|
||||
b_fc1_id = fc1_mappings[0][1]
|
||||
b_pc1_id = pc1_mappings[0][1]
|
||||
self.assertEqual([b_pp1_id], btm1_pp_ids)
|
||||
self.assertEqual([b_ppg1_id], btm1_ppg_ids)
|
||||
self.assertEqual([b_fc1_id], btm1_fc_ids)
|
||||
self.assertEqual([b_pc1_id], btm1_pc_ids)
|
||||
|
||||
# make conflict
|
||||
TOP_PORTCHAINS.pop()
|
||||
TOP_FLOWCLASSIFIERS.pop()
|
||||
TOP_PORTPAIRGROUPS.pop()
|
||||
TOP_PORTPAIRS.pop()
|
||||
b_ppg1_mapping = {b_pp1_id: b_ppg1_id}
|
||||
self._update_port_pair_test(b_ppg1_mapping, BOTTOM1_PORTPAIRS)
|
||||
db_api.create_recycle_resource(
|
||||
t_ctx, t_ppg1_id, constants.RT_PORT_PAIR_GROUP, q_ctx.project_id)
|
||||
|
||||
t_pp2_id, _ = self._prepare_port_pair_test(
|
||||
project_id, t_ctx, 'pod_1', 0, ingress, egress, False)
|
||||
t_ppg2_id, _ = self._prepare_port_pair_group_test(
|
||||
project_id, t_ctx, 'pod_1', 0, [t_pp2_id], False, None)
|
||||
ppg2_mapping = {t_pp2_id: t_ppg2_id}
|
||||
self._update_port_pair_test(ppg2_mapping, TOP_PORTPAIRS)
|
||||
t_fc2_id, _ = self._prepare_flow_classifier_test(
|
||||
project_id, t_ctx, 'pod_1', 0, src_port_id, False)
|
||||
body2 = {"port_chain": {
|
||||
"tenant_id": project_id,
|
||||
"name": "pc1",
|
||||
"chain_parameters": {
|
||||
"symmetric": False, "correlation": "mpls"},
|
||||
"port_pair_groups": [t_ppg2_id],
|
||||
"flow_classifiers": [t_fc2_id],
|
||||
"project_id": project_id,
|
||||
"chain_id": 1,
|
||||
"description": ""}}
|
||||
t_pc2 = fake_plugin.create_port_chain(q_ctx, body2)
|
||||
pp2_mappings = db_api.get_bottom_mappings_by_top_id(
|
||||
t_ctx, t_pp2_id, constants.RT_PORT_PAIR)
|
||||
ppg2_mappings = db_api.get_bottom_mappings_by_top_id(
|
||||
t_ctx, t_ppg2_id, constants.RT_PORT_PAIR_GROUP)
|
||||
fc2_mappings = db_api.get_bottom_mappings_by_top_id(
|
||||
t_ctx, t_fc2_id, constants.RT_FLOW_CLASSIFIER)
|
||||
pc2_mappings = db_api.get_bottom_mappings_by_top_id(
|
||||
t_ctx, t_pc2['id'], constants.RT_PORT_CHAIN)
|
||||
btm1_pp_ids = [btm_pp['id'] for btm_pp in BOTTOM1_PORTPAIRS]
|
||||
btm1_ppg_ids = [btm_ppg['id'] for btm_ppg in BOTTOM1_PORTPAIRGROUPS]
|
||||
btm1_fc_ids = [btm_fc['id'] for btm_fc in BOTTOM1_FLOWCLASSIFIERS]
|
||||
btm1_pc_ids = [btm_pc['id'] for btm_pc in BOTTOM1_PORTCHAINS]
|
||||
b_pp2_id = pp2_mappings[0][1]
|
||||
b_ppg2_id = ppg2_mappings[0][1]
|
||||
b_fc2_id = fc2_mappings[0][1]
|
||||
b_pc2_id = pc2_mappings[0][1]
|
||||
self.assertEqual([b_pp2_id], btm1_pp_ids)
|
||||
self.assertEqual([b_ppg2_id], btm1_ppg_ids)
|
||||
self.assertEqual([b_fc2_id], btm1_fc_ids)
|
||||
self.assertEqual([b_pc2_id], btm1_pc_ids)
|
||||
|
||||
@patch.object(context, 'get_context_from_neutron_context',
|
||||
new=fake_get_context_from_neutron_context)
|
||||
|
@ -837,8 +947,11 @@ class PluginTest(unittest.TestCase):
|
|||
new=fake_get_context_from_neutron_context)
|
||||
def test_update_service_function_chain(self):
|
||||
project_id = TEST_TENANT_ID
|
||||
q_ctx = FakeNeutronContext()
|
||||
t_ctx = context.get_db_context()
|
||||
self._basic_pod_setup()
|
||||
fake_sfc_plugin = FakeSfcPlugin()
|
||||
fake_fc_plugin = FakeFcPlugin()
|
||||
|
||||
t_net_id = self._prepare_net_test(project_id, t_ctx, 'pod_1')
|
||||
src_port_id = self._prepare_port_test(project_id,
|
||||
|
@ -866,14 +979,50 @@ class PluginTest(unittest.TestCase):
|
|||
self._prepare_chain_group_assoc_test(t_pc1_id, t_ppg1_id)
|
||||
self._prepare_chain_classifier_assoc_test(t_pc1_id, t_fc1_id)
|
||||
|
||||
pp_body = {'port_pair': {
|
||||
'name': 'new_name',
|
||||
'description': 'new_pp_description'}}
|
||||
fake_sfc_plugin.update_port_pair(q_ctx, t_pp1_id, pp_body)
|
||||
self.assertEqual(TOP_PORTPAIRS[0]['description'], 'new_pp_description')
|
||||
self.assertEqual(TOP_PORTPAIRS[0]['name'], 'new_name')
|
||||
self.assertEqual(BOTTOM1_PORTPAIRS[0]['description'],
|
||||
'new_pp_description')
|
||||
self.assertEqual(BOTTOM1_PORTPAIRS[0]['name'], 'new_name')
|
||||
|
||||
fc_body = {'flow_classifier': {
|
||||
'name': 'new_name',
|
||||
'description': 'new_fc_description'}}
|
||||
fake_fc_plugin.update_flow_classifier(q_ctx, t_fc1_id, fc_body)
|
||||
self.assertEqual(TOP_FLOWCLASSIFIERS[0]['name'], 'new_name')
|
||||
self.assertEqual(TOP_FLOWCLASSIFIERS[0]['description'],
|
||||
'new_fc_description')
|
||||
self.assertEqual(BOTTOM1_FLOWCLASSIFIERS[0]['name'], 'new_name')
|
||||
self.assertEqual(BOTTOM1_FLOWCLASSIFIERS[0]['description'],
|
||||
'new_fc_description')
|
||||
|
||||
ingress2 = self._prepare_port_test(project_id, t_ctx,
|
||||
'pod_1', t_net_id)
|
||||
egress2 = self._prepare_port_test(project_id, t_ctx, 'pod_1', t_net_id)
|
||||
t_pp2_id, b_pp2_id = self._prepare_port_pair_test(
|
||||
project_id, t_ctx, 'pod_1', 0, ingress2, egress2, True)
|
||||
ppg_body = {'port_pair_group': {
|
||||
'name': 'new_name',
|
||||
'description': 'new_ppg_description',
|
||||
'port_pairs': [t_pp1_id, t_pp2_id]}}
|
||||
ppg_mapping = {t_pp2_id: t_ppg1_id}
|
||||
self._update_port_pair_test(ppg_mapping, TOP_PORTPAIRS)
|
||||
|
||||
fake_sfc_plugin.update_port_pair_group(q_ctx, t_ppg1_id, ppg_body)
|
||||
self.assertEqual(TOP_PORTPAIRGROUPS[0]['name'], 'new_name')
|
||||
self.assertEqual(TOP_PORTPAIRGROUPS[0]['description'],
|
||||
'new_ppg_description')
|
||||
self.assertEqual(TOP_PORTPAIRGROUPS[0]['port_pairs'],
|
||||
[t_pp1_id, t_pp2_id])
|
||||
self.assertEqual(BOTTOM1_PORTPAIRGROUPS[0]['name'], 'new_name')
|
||||
self.assertEqual(BOTTOM1_PORTPAIRGROUPS[0]['description'],
|
||||
'new_ppg_description')
|
||||
self.assertEqual(BOTTOM1_PORTPAIRGROUPS[0]['port_pairs'],
|
||||
[b_pp1_id, b_pp2_id])
|
||||
t_ppg2_id, b_ppg2_id = self._prepare_port_pair_group_test(
|
||||
project_id, t_ctx, 'pod_1', 0,
|
||||
[], True, [])
|
||||
|
@ -881,6 +1030,27 @@ class PluginTest(unittest.TestCase):
|
|||
project_id, t_ctx, 'pod_1', 0, src_port_id, True)
|
||||
self._prepare_chain_group_assoc_test(t_pc1_id, t_ppg2_id)
|
||||
self._prepare_chain_classifier_assoc_test(t_pc1_id, t_fc2_id)
|
||||
pc_body = {'port_chain': {
|
||||
'name': 'new_name',
|
||||
'description': 'new_pc_description',
|
||||
'port_pair_groups': [t_ppg1_id, t_ppg2_id],
|
||||
'flow_classifiers': [t_fc1_id, t_fc2_id]}}
|
||||
|
||||
fake_sfc_plugin.update_port_chain(q_ctx, t_pc1_id, pc_body)
|
||||
self.assertEqual(TOP_PORTCHAINS[0]['name'], 'new_name')
|
||||
self.assertEqual(TOP_PORTCHAINS[0]['description'],
|
||||
'new_pc_description')
|
||||
self.assertEqual(TOP_PORTCHAINS[0]['port_pair_groups'],
|
||||
[t_ppg1_id, t_ppg2_id])
|
||||
self.assertEqual(TOP_PORTCHAINS[0]['flow_classifiers'],
|
||||
[t_fc1_id, t_fc2_id])
|
||||
self.assertEqual(BOTTOM1_PORTCHAINS[0]['name'], 'new_name')
|
||||
self.assertEqual(BOTTOM1_PORTCHAINS[0]['description'],
|
||||
'new_pc_description')
|
||||
self.assertEqual(BOTTOM1_PORTCHAINS[0]['port_pair_groups'],
|
||||
[b_ppg1_id, b_ppg2_id])
|
||||
self.assertEqual(BOTTOM1_PORTCHAINS[0]['flow_classifiers'],
|
||||
[b_fc1_id, b_fc2_id])
|
||||
|
||||
def tearDown(self):
|
||||
core.ModelBase.metadata.drop_all(core.get_engine())
|
||||
|
|
|
@ -541,6 +541,28 @@ class PluginTest(unittest.TestCase):
|
|||
self.assertEqual(updated_btm_trunk['description'], 'updated')
|
||||
self.assertFalse(updated_btm_trunk['admin_state_up'])
|
||||
|
||||
@patch.object(context, 'get_context_from_neutron_context',
|
||||
new=fake_get_context_from_neutron_context)
|
||||
def test_delete_trunk(self):
|
||||
project_id = TEST_TENANT_ID
|
||||
q_ctx = FakeNeutronContext()
|
||||
t_ctx = context.get_db_context()
|
||||
self._basic_pod_setup()
|
||||
fake_plugin = FakePlugin()
|
||||
|
||||
t_trunk, b_trunk = self._prepare_trunk_test(project_id, t_ctx,
|
||||
'pod_1', 1, True)
|
||||
|
||||
fake_plugin.delete_trunk(q_ctx, t_trunk['id'])
|
||||
self.assertEqual(len(TOP_TRUNKS), 0)
|
||||
self.assertEqual(len(BOTTOM1_TRUNKS), 0)
|
||||
route_filters = [{'key': 'top_id',
|
||||
'comparator': 'eq',
|
||||
'value': t_trunk['id']}]
|
||||
routes = core.query_resource(t_ctx, models.ResourceRouting,
|
||||
route_filters, [])
|
||||
self.assertEqual(len(routes), 0)
|
||||
|
||||
@patch.object(db_base_plugin_v2.NeutronDbPluginV2, 'get_ports',
|
||||
new=FakeCorePlugin.get_ports)
|
||||
@patch.object(db_base_plugin_v2.NeutronDbPluginV2, 'update_port',
|
||||
|
@ -550,7 +572,9 @@ class PluginTest(unittest.TestCase):
|
|||
def test_action_subports(self):
|
||||
project_id = TEST_TENANT_ID
|
||||
t_ctx = context.get_db_context()
|
||||
q_ctx = FakeNeutronContext()
|
||||
self._basic_pod_setup()
|
||||
fake_plugin = FakePlugin()
|
||||
|
||||
t_trunk, b_trunk = self._prepare_trunk_test(project_id, t_ctx,
|
||||
'pod_1', 1, True)
|
||||
|
@ -594,6 +618,65 @@ class PluginTest(unittest.TestCase):
|
|||
'segmentation_id': _id}
|
||||
add_subports.append(subport)
|
||||
|
||||
fake_plugin.add_subports(q_ctx, t_trunk['id'],
|
||||
{'sub_ports': add_subports})
|
||||
|
||||
top_subports = TOP_TRUNKS[0]['sub_ports']
|
||||
btm_subports = BOTTOM1_TRUNKS[0]['sub_ports']
|
||||
|
||||
except_btm_subports = []
|
||||
for subport in b_trunk['sub_ports']:
|
||||
if subport['segmentation_id'] == 164:
|
||||
except_btm_subports.extend([subport])
|
||||
for subport in add_subports:
|
||||
subport['trunk_id'] = b_trunk['id']
|
||||
except_btm_subports.extend(add_subports)
|
||||
six.assertCountEqual(self, btm_subports, except_btm_subports)
|
||||
|
||||
except_top_subports = []
|
||||
for subport in t_trunk['sub_ports']:
|
||||
if subport['segmentation_id'] == 164:
|
||||
except_top_subports.extend([subport])
|
||||
for subport in add_subports:
|
||||
subport['trunk_id'] = t_trunk['id']
|
||||
except_top_subports.extend(add_subports)
|
||||
except_btm_subports.extend(add_subports)
|
||||
six.assertCountEqual(self, top_subports, except_top_subports)
|
||||
|
||||
self.assertEqual(len(BOTTOM1_PORTS), 10)
|
||||
map_filters = [{'key': 'resource_type',
|
||||
'comparator': 'eq',
|
||||
'value': constants.RT_PORT},
|
||||
{'key': 'project_id',
|
||||
'comparator': 'eq',
|
||||
'value': project_id}]
|
||||
|
||||
port_mappings = db_api.list_resource_routings(t_ctx, map_filters)
|
||||
self.assertEqual(len(port_mappings), 10)
|
||||
|
||||
@patch.object(db_base_plugin_v2.NeutronDbPluginV2, 'update_port',
|
||||
new=FakeCorePlugin.update_port)
|
||||
@patch.object(context, 'get_context_from_neutron_context',
|
||||
new=fake_get_context_from_neutron_context)
|
||||
def test_remove_subports(self):
|
||||
project_id = TEST_TENANT_ID
|
||||
q_ctx = FakeNeutronContext()
|
||||
t_ctx = context.get_db_context()
|
||||
self._basic_pod_setup()
|
||||
fake_plugin = FakePlugin()
|
||||
|
||||
t_trunk, b_trunk = self._prepare_trunk_test(project_id, t_ctx,
|
||||
'pod_1', 1, True)
|
||||
subport_id = t_trunk['sub_ports'][0]['port_id']
|
||||
|
||||
remove_subport = {'sub_ports': [{'port_id': subport_id}]}
|
||||
fake_plugin.remove_subports(q_ctx, t_trunk['id'], remove_subport)
|
||||
|
||||
top_subports = TOP_TRUNKS[0]['sub_ports']
|
||||
btm_subports = BOTTOM1_TRUNKS[0]['sub_ports']
|
||||
self.assertEqual(len(top_subports), 0)
|
||||
self.assertEqual(len(btm_subports), 0)
|
||||
|
||||
def tearDown(self):
|
||||
core.ModelBase.metadata.drop_all(core.get_engine())
|
||||
test_utils.get_resource_store().clean()
|
||||
|
|
|
@ -22,6 +22,7 @@ import unittest
|
|||
from oslo_config import cfg
|
||||
from oslo_utils import uuidutils
|
||||
|
||||
import neutron.conf.common as q_config
|
||||
from neutron.services.trunk import exceptions as t_exc
|
||||
from neutron_lib.api.definitions import portbindings
|
||||
import neutron_lib.constants as q_constants
|
||||
|
@ -264,6 +265,7 @@ class FakePlugin(plugin.TricirclePlugin):
|
|||
|
||||
class PluginTest(unittest.TestCase):
|
||||
def setUp(self):
|
||||
cfg.CONF.register_opts(q_config.core_opts)
|
||||
self.tenant_id = uuidutils.generate_uuid()
|
||||
self.plugin = FakePlugin()
|
||||
self.context = FakeContext()
|
||||
|
@ -580,6 +582,16 @@ class PluginTest(unittest.TestCase):
|
|||
# "agent" extension and body contains tunnel ip
|
||||
mock_agent.assert_has_calls([mock.call(self.context, agent_state)])
|
||||
|
||||
@patch.object(FakePlugin, '_ensure_trunk', new=mock.Mock)
|
||||
@patch.object(t_context, 'get_context_from_neutron_context', new=mock.Mock)
|
||||
def test_get_port(self):
|
||||
t_net, t_subnet, t_port, _ = self._prepare_resource()
|
||||
|
||||
t_vm_port = self._prepare_vm_port(t_net, t_subnet, 1)
|
||||
t_port = self.plugin.get_port(self.context, t_vm_port['id'])
|
||||
b_port = get_resource('port', False, t_port['id'])
|
||||
self.assertDictEqual(t_port, b_port)
|
||||
|
||||
@patch.object(t_context, 'get_context_from_neutron_context', new=mock.Mock)
|
||||
@patch.object(plugin.TricirclePlugin, '_handle_security_group',
|
||||
new=mock.Mock)
|
||||
|
@ -624,6 +636,154 @@ class PluginTest(unittest.TestCase):
|
|||
b_port.pop('project_id')
|
||||
self.assertDictEqual(t_ports[i], b_port)
|
||||
|
||||
@patch.object(t_context, 'get_context_from_neutron_context')
|
||||
@patch.object(FakeNeutronHandle, 'handle_update')
|
||||
def test_update_port(self, mock_update, mock_context):
|
||||
t_net, t_subnet, _, _ = self._prepare_resource()
|
||||
b_net = self.plugin.get_network(self.context, t_net['id'])
|
||||
cfg.CONF.set_override('region_name', 'Pod1', 'nova')
|
||||
mock_context.return_value = self.context
|
||||
port_id = 'fake_port_id'
|
||||
host_id = 'fake_host'
|
||||
fake_port = {
|
||||
'id': port_id,
|
||||
'network_id': b_net['id'],
|
||||
'binding:vif_type': 'fake_vif_type',
|
||||
'binding:host_id': host_id,
|
||||
portbindings.VIF_DETAILS: {},
|
||||
portbindings.VNIC_TYPE: 'normal'
|
||||
}
|
||||
fake_agent = {
|
||||
'agent_type': 'Open vSwitch agent',
|
||||
'host': host_id,
|
||||
'configurations': {
|
||||
'tunneling_ip': '192.168.1.101'}}
|
||||
create_resource('port', False, fake_port)
|
||||
create_resource('agent', False, fake_agent)
|
||||
update_body = {'port': {'device_owner': 'compute:None',
|
||||
'binding:host_id': host_id}}
|
||||
|
||||
self.plugin.update_port(self.context, port_id, update_body)
|
||||
# network is not vxlan type
|
||||
mock_update.assert_called_with(
|
||||
self.context, 'port', port_id,
|
||||
{'port': {'binding:profile': {'region': 'Pod1',
|
||||
'device': 'compute:None',
|
||||
'binding:vif_type': 'fake_vif_type',
|
||||
'binding:host_id': host_id,
|
||||
portbindings.VIF_DETAILS: {},
|
||||
portbindings.VNIC_TYPE: 'normal'}}})
|
||||
|
||||
# update network type from vlan to vxlan
|
||||
update_resource('network', False, b_net['id'],
|
||||
{'provider:network_type': 'vxlan'})
|
||||
|
||||
self.plugin.update_port(self.context, port_id, update_body)
|
||||
# port vif type is not recognized
|
||||
mock_update.assert_called_with(
|
||||
self.context, 'port', port_id,
|
||||
{'port': {'binding:profile': {'region': 'Pod1',
|
||||
'device': 'compute:None',
|
||||
'binding:vif_type': 'fake_vif_type',
|
||||
'binding:host_id': host_id,
|
||||
portbindings.VIF_DETAILS: {},
|
||||
portbindings.VNIC_TYPE: 'normal'}}})
|
||||
|
||||
# update network type from fake_vif_type to ovs
|
||||
update_resource('port', False, port_id,
|
||||
{'binding:vif_type': 'ovs'})
|
||||
|
||||
self.plugin.update_port(self.context, port_id,
|
||||
{'port': {'device_owner': 'compute:None',
|
||||
'binding:host_id': 'fake_another_host'}})
|
||||
# agent in the specific host is not found
|
||||
mock_update.assert_called_with(
|
||||
self.context, 'port', port_id,
|
||||
{'port': {'binding:profile': {'region': 'Pod1',
|
||||
'device': 'compute:None',
|
||||
'binding:vif_type': 'ovs',
|
||||
'binding:host_id':
|
||||
'fake_another_host',
|
||||
portbindings.VIF_DETAILS: {},
|
||||
portbindings.VNIC_TYPE: 'normal'}}})
|
||||
|
||||
self.plugin.update_port(self.context, port_id, update_body)
|
||||
# default p2p mode, update with agent host tunnel ip
|
||||
mock_update.assert_called_with(
|
||||
self.context, 'port', port_id,
|
||||
{'port': {'binding:profile': {'region': 'Pod1',
|
||||
'tunnel_ip': '192.168.1.101',
|
||||
'type': 'Open vSwitch agent',
|
||||
'host': host_id,
|
||||
'device': 'compute:None',
|
||||
'binding:vif_type': 'ovs',
|
||||
'binding:host_id': host_id,
|
||||
portbindings.VIF_DETAILS: {},
|
||||
portbindings.VNIC_TYPE: 'normal'}}})
|
||||
|
||||
cfg.CONF.set_override('cross_pod_vxlan_mode', 'l2gw', 'client')
|
||||
cfg.CONF.set_override('l2gw_tunnel_ip', '192.168.1.105', 'tricircle')
|
||||
update_body = {'port': {'device_owner': 'compute:None',
|
||||
'binding:host_id': host_id}}
|
||||
self.plugin.update_port(self.context, port_id, update_body)
|
||||
# l2gw mode, update with configured l2 gateway tunnel ip
|
||||
mock_update.assert_called_with(
|
||||
self.context, 'port', port_id,
|
||||
{'port': {'binding:profile': {'region': 'Pod1',
|
||||
'tunnel_ip': '192.168.1.105',
|
||||
'type': 'Open vSwitch agent',
|
||||
'host': 'fake_host',
|
||||
'device': 'compute:None',
|
||||
'binding:vif_type': 'ovs',
|
||||
'binding:host_id': host_id,
|
||||
portbindings.VIF_DETAILS: {},
|
||||
portbindings.VNIC_TYPE: 'normal'}}})
|
||||
|
||||
cfg.CONF.set_override('l2gw_tunnel_ip', None, 'tricircle')
|
||||
cfg.CONF.set_override('cross_pod_vxlan_mode', 'l2gw', 'client')
|
||||
self.plugin.update_port(self.context, port_id, update_body)
|
||||
# l2gw mode, but l2 gateway tunnel ip is not configured
|
||||
mock_update.assert_called_with(
|
||||
self.context, 'port', port_id,
|
||||
{'port': {'binding:profile': {'region': 'Pod1',
|
||||
'device': 'compute:None',
|
||||
'binding:vif_type': 'ovs',
|
||||
'binding:host_id': host_id,
|
||||
portbindings.VIF_DETAILS: {},
|
||||
portbindings.VNIC_TYPE: 'normal'}}})
|
||||
|
||||
cfg.CONF.set_override('cross_pod_vxlan_mode', 'noop', 'client')
|
||||
self.plugin.update_port(self.context, port_id, update_body)
|
||||
# noop mode
|
||||
mock_update.assert_called_with(
|
||||
self.context, 'port', port_id,
|
||||
{'port': {'binding:profile': {'region': 'Pod1',
|
||||
'device': 'compute:None',
|
||||
'binding:vif_type': 'ovs',
|
||||
'binding:host_id': host_id,
|
||||
portbindings.VIF_DETAILS: {},
|
||||
portbindings.VNIC_TYPE: 'normal'}}})
|
||||
|
||||
FakeCorePlugin.supported_extension_aliases = []
|
||||
self.plugin.update_port(self.context, port_id, update_body)
|
||||
# core plugin doesn't support "agent" extension
|
||||
mock_update.assert_called_with(
|
||||
self.context, 'port', port_id,
|
||||
{'port': {'binding:profile': {'region': 'Pod1',
|
||||
'device': 'compute:None',
|
||||
'binding:vif_type': 'ovs',
|
||||
'binding:host_id': host_id,
|
||||
portbindings.VIF_DETAILS: {},
|
||||
portbindings.VNIC_TYPE: 'normal'}}})
|
||||
FakeCorePlugin.supported_extension_aliases = ['agent']
|
||||
|
||||
self.plugin.update_port(self.context, port_id,
|
||||
{'port': {portbindings.PROFILE: {
|
||||
constants.PROFILE_FORCE_UP: True}}})
|
||||
b_port = get_resource('port', False, port_id)
|
||||
# port status is update to active
|
||||
self.assertEqual(q_constants.PORT_STATUS_ACTIVE, b_port['status'])
|
||||
|
||||
@patch.object(t_context, 'get_context_from_neutron_context')
|
||||
def test_update_subnet(self, mock_context):
|
||||
_, t_subnet, t_port, _ = self._prepare_resource(enable_dhcp=False)
|
||||
|
@ -639,4 +799,5 @@ class PluginTest(unittest.TestCase):
|
|||
self.assertEqual(b_port['device_owner'], 'network:dhcp')
|
||||
|
||||
def tearDown(self):
|
||||
cfg.CONF.unregister_opts(q_config.core_opts)
|
||||
test_utils.get_resource_store().clean()
|
||||
|
|
|
@ -12,14 +12,20 @@
|
|||
# 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 mock import patch
|
||||
import unittest
|
||||
|
||||
from neutron_lib.api.definitions import provider_net
|
||||
from neutron_lib.plugins import constants as plugin_constants
|
||||
from neutron_lib.plugins import directory
|
||||
|
||||
import neutron.conf.common as q_config
|
||||
from neutron.extensions import segment as extension
|
||||
from neutron.plugins.ml2 import managers as n_managers
|
||||
from neutron.services.segments import exceptions as sg_excp
|
||||
from oslo_config import cfg
|
||||
from oslo_serialization import jsonutils
|
||||
from oslo_utils import uuidutils
|
||||
|
||||
from tricircle.common import context
|
||||
import tricircle.db.api as db_api
|
||||
|
@ -28,10 +34,8 @@ from tricircle.db import models
|
|||
import tricircle.network.central_plugin as plugin
|
||||
from tricircle.network import helper
|
||||
from tricircle.network.segment_plugin import TricircleSegmentPlugin
|
||||
from tricircle.tests.unit.network.test_central_plugin \
|
||||
import FakeClient as CentralFakeClient
|
||||
from tricircle.tests.unit.network.test_central_plugin \
|
||||
import FakePlugin as CentralFakePlugin
|
||||
from tricircle.tests.unit.network.test_central_plugin import FakeClient as CFC
|
||||
from tricircle.tests.unit.network.test_central_plugin import FakePlugin as CFP
|
||||
|
||||
import tricircle.tests.unit.utils as test_utils
|
||||
|
||||
|
@ -49,7 +53,7 @@ FakeNeutronContext = test_utils.FakeNeutronContext
|
|||
TEST_TENANT_ID = test_utils.TEST_TENANT_ID
|
||||
|
||||
|
||||
class FakeClient(CentralFakeClient):
|
||||
class FakeClient(CFC):
|
||||
def __init__(self, region_name=None):
|
||||
super(FakeClient, self).__init__(region_name)
|
||||
|
||||
|
@ -83,7 +87,7 @@ class FakePlugin(TricircleSegmentPlugin):
|
|||
self.extension_manager = FakeExtensionManager()
|
||||
self.extension_manager.initialize()
|
||||
self.helper = FakeHelper(self)
|
||||
self.central_plugin = CentralFakePlugin()
|
||||
self.central_plugin = CFP()
|
||||
|
||||
def _get_client(self, region_name):
|
||||
return FakeClient(region_name)
|
||||
|
@ -102,10 +106,6 @@ class FakePlugin(TricircleSegmentPlugin):
|
|||
return network
|
||||
|
||||
|
||||
def fake_get_plugin(alias=plugin_constants.CORE):
|
||||
return CentralFakePlugin()
|
||||
|
||||
|
||||
def fake_get_client(region_name):
|
||||
return FakeClient(region_name)
|
||||
|
||||
|
@ -139,7 +139,7 @@ class PluginTest(unittest.TestCase):
|
|||
cfg.CONF.set_override('enable_l3_route_network', True,
|
||||
group='tricircle')
|
||||
plugin_path = \
|
||||
'tricircle.tests.unit.network.test_central_plugin.FakePlugin'
|
||||
'tricircle.tests.unit.network.test_segment_plugin.FakePlugin'
|
||||
cfg.CONF.set_override('core_plugin', plugin_path)
|
||||
cfg.CONF.set_override('enable_api_gateway', True)
|
||||
self.context = context.Context()
|
||||
|
@ -159,10 +159,7 @@ class PluginTest(unittest.TestCase):
|
|||
group='tricircle')
|
||||
|
||||
def fake_get_plugin(alias=plugin_constants.CORE):
|
||||
if alias == 'trunk':
|
||||
return FakeTrunkPlugin()
|
||||
return CentralFakePlugin()
|
||||
from neutron_lib.plugins import directory
|
||||
return None
|
||||
directory.get_plugin = fake_get_plugin
|
||||
|
||||
global segments_plugin
|
||||
|
@ -194,6 +191,112 @@ class PluginTest(unittest.TestCase):
|
|||
core.create_resource(self.context, models.ResourceRouting, route1)
|
||||
core.create_resource(self.context, models.ResourceRouting, route2)
|
||||
|
||||
@patch.object(context, 'get_context_from_neutron_context')
|
||||
@patch.object(TricircleSegmentPlugin, '_get_client',
|
||||
new=fake_get_client)
|
||||
@patch.object(plugin.TricirclePlugin, '_get_client',
|
||||
new=fake_get_client)
|
||||
def test_create_segment(self, mock_context):
|
||||
self._basic_pod_route_setup()
|
||||
fake_plugin = FakePlugin()
|
||||
neutron_context = FakeNeutronContext()
|
||||
tricircle_context = context.get_db_context()
|
||||
mock_context.return_value = tricircle_context
|
||||
|
||||
# create a routed network
|
||||
top_net_id = uuidutils.generate_uuid()
|
||||
network = {'network': {
|
||||
'id': top_net_id, 'name': 'multisegment1',
|
||||
'tenant_id': TEST_TENANT_ID,
|
||||
'admin_state_up': True, 'shared': False,
|
||||
'availability_zone_hints': [],
|
||||
provider_net.PHYSICAL_NETWORK: 'bridge',
|
||||
provider_net.NETWORK_TYPE: 'vlan',
|
||||
provider_net.SEGMENTATION_ID: '2016'}}
|
||||
fake_plugin.central_plugin.create_network(neutron_context, network)
|
||||
net_filter = {'name': ['multisegment1']}
|
||||
top_net = fake_plugin.central_plugin.get_networks(
|
||||
neutron_context, net_filter)
|
||||
self.assertEqual(top_net[0]['id'], top_net_id)
|
||||
|
||||
res = fake_plugin.get_segments(neutron_context)
|
||||
self.assertEqual(len(res), 1)
|
||||
|
||||
# creat segment's name normally
|
||||
segment2_id = uuidutils.generate_uuid()
|
||||
segment2_name = 'test-segment2'
|
||||
segment2 = {'segment': {
|
||||
'id': segment2_id,
|
||||
'name': segment2_name,
|
||||
'network_id': top_net_id,
|
||||
extension.PHYSICAL_NETWORK: 'bridge2',
|
||||
extension.NETWORK_TYPE: 'flat',
|
||||
extension.SEGMENTATION_ID: '2016',
|
||||
'tenant_id': TEST_TENANT_ID,
|
||||
'description': None
|
||||
}}
|
||||
fake_plugin.create_segment(neutron_context, segment2)
|
||||
res = fake_plugin.get_segment(neutron_context, segment2_id)
|
||||
self.assertEqual(res['name'], segment2_name)
|
||||
net_filter = {'name': [segment2_name]}
|
||||
b_net = fake_plugin.central_plugin.get_networks(
|
||||
neutron_context, net_filter)
|
||||
self.assertFalse(b_net)
|
||||
|
||||
@patch.object(context, 'get_context_from_neutron_context')
|
||||
@patch.object(TricircleSegmentPlugin, '_get_client',
|
||||
new=fake_get_client)
|
||||
@patch.object(plugin.TricirclePlugin, '_get_client',
|
||||
new=fake_get_client)
|
||||
@patch.object(plugin.TricirclePlugin, 'delete_network',
|
||||
new=fake_delete_network)
|
||||
def test_delete_segment(self, mock_context):
|
||||
self._basic_pod_route_setup()
|
||||
fake_plugin = FakePlugin()
|
||||
neutron_context = FakeNeutronContext()
|
||||
tricircle_context = context.get_db_context()
|
||||
mock_context.return_value = tricircle_context
|
||||
|
||||
# create a routed network
|
||||
top_net_id = uuidutils.generate_uuid()
|
||||
network = {'network': {
|
||||
'id': top_net_id, 'name': 'multisegment1',
|
||||
'tenant_id': TEST_TENANT_ID,
|
||||
'admin_state_up': True, 'shared': False,
|
||||
'availability_zone_hints': [],
|
||||
provider_net.PHYSICAL_NETWORK: 'bridge',
|
||||
provider_net.NETWORK_TYPE: 'vlan',
|
||||
provider_net.SEGMENTATION_ID: '2016'}}
|
||||
fake_plugin.central_plugin.create_network(neutron_context, network)
|
||||
|
||||
# create a normal segment
|
||||
segment2_id = uuidutils.generate_uuid()
|
||||
segment2_name = 'test-segment3'
|
||||
segment2 = {'segment': {
|
||||
'id': segment2_id,
|
||||
'name': segment2_name,
|
||||
'network_id': top_net_id,
|
||||
extension.PHYSICAL_NETWORK: 'bridge2',
|
||||
extension.NETWORK_TYPE: 'flat',
|
||||
extension.SEGMENTATION_ID: '2016',
|
||||
'tenant_id': TEST_TENANT_ID,
|
||||
'description': None
|
||||
}}
|
||||
fake_plugin.create_segment(neutron_context, segment2)
|
||||
|
||||
res = fake_plugin.get_segment(neutron_context, segment2_id)
|
||||
self.assertEqual(res['name'], segment2_name)
|
||||
net_filter = {'name': [segment2_name]}
|
||||
b_net = fake_plugin.central_plugin.get_networks(
|
||||
neutron_context, net_filter)
|
||||
self.assertFalse(b_net)
|
||||
|
||||
# delete a normal segment
|
||||
fake_plugin.delete_segment(neutron_context, segment2_id)
|
||||
self.assertRaises(sg_excp.SegmentNotFound,
|
||||
fake_plugin.get_segment,
|
||||
neutron_context, segment2_id)
|
||||
|
||||
def tearDown(self):
|
||||
core.ModelBase.metadata.drop_all(core.get_engine())
|
||||
test_utils.get_resource_store().clean()
|
||||
|
|
Loading…
Reference in New Issue