def test_delete_port_pair(self):
        project_id = TEST_TENANT_ID
        q_ctx = FakeNeutronContext()
        t_ctx = context.get_db_context()
        self._basic_pod_setup()
        fake_plugin = FakeSfcPlugin()

        ingress = uuidutils.generate_uuid()
        egress = uuidutils.generate_uuid()
        t_pp1_id, _ = self._prepare_port_pair_test(project_id, t_ctx, 'pod_1',
                                                   0, ingress, egress, True)
        fake_plugin.delete_port_pair(q_ctx, t_pp1_id)
        ppg_mappings = db_api.get_bottom_mappings_by_top_id(
            t_ctx, t_pp1_id, constants.RT_PORT_PAIR_GROUP)
        self.assertEqual(len(TOP_PORTPAIRS), 0)
        self.assertEqual(len(BOTTOM1_PORTPAIRS), 0)
        self.assertEqual(len(ppg_mappings), 0)

        t_pp2_id, _ = self._prepare_port_pair_test(project_id, t_ctx, 'pod_1',
                                                   0, ingress, egress, True)
        BOTTOM1_PORTPAIRS.pop()
        fake_plugin.delete_port_pair(q_ctx, t_pp2_id)
        ppg_mappings = db_api.get_bottom_mappings_by_top_id(
            t_ctx, t_pp2_id, constants.RT_PORT_PAIR_GROUP)
        self.assertEqual(len(TOP_PORTPAIRS), 0)
        self.assertEqual(len(ppg_mappings), 0)
    def test_delete_port_pair(self):
        project_id = TEST_TENANT_ID
        q_ctx = FakeNeutronContext()
        t_ctx = context.get_db_context()
        self._basic_pod_setup()
        fake_plugin = FakeSfcPlugin()

        ingress = uuidutils.generate_uuid()
        egress = uuidutils.generate_uuid()
        t_pp1_id, _ = self._prepare_port_pair_test(
            project_id, t_ctx, 'pod_1', 0, ingress, egress, True)
        fake_plugin.delete_port_pair(q_ctx, t_pp1_id)
        ppg_mappings = db_api.get_bottom_mappings_by_top_id(
            t_ctx, t_pp1_id, constants.RT_PORT_PAIR_GROUP)
        self.assertEqual(len(TOP_PORTPAIRS), 0)
        self.assertEqual(len(BOTTOM1_PORTPAIRS), 0)
        self.assertEqual(len(ppg_mappings), 0)

        t_pp2_id, _ = self._prepare_port_pair_test(
            project_id, t_ctx, 'pod_1', 0, ingress, egress, True)
        BOTTOM1_PORTPAIRS.pop()
        fake_plugin.delete_port_pair(q_ctx, t_pp2_id)
        ppg_mappings = db_api.get_bottom_mappings_by_top_id(
            t_ctx, t_pp2_id, constants.RT_PORT_PAIR_GROUP)
        self.assertEqual(len(TOP_PORTPAIRS), 0)
        self.assertEqual(len(ppg_mappings), 0)
    def test_delete_flow_classifier(self):
        project_id = TEST_TENANT_ID
        q_ctx = FakeNeutronContext()
        t_ctx = context.get_db_context()
        self._basic_pod_setup()
        fake_plugin = FakeFcPlugin()

        src_port_id = uuidutils.generate_uuid()

        t_fc_id1, _ = self._prepare_flow_classifier_test(
            project_id, t_ctx, 'pod_1', 0, src_port_id, True)
        fake_plugin.delete_flow_classifier(q_ctx, t_fc_id1)
        ppg_mappings = db_api.get_bottom_mappings_by_top_id(
            t_ctx, t_fc_id1, constants.RT_FLOW_CLASSIFIER)
        self.assertEqual(len(TOP_FLOWCLASSIFIERS), 0)
        self.assertEqual(len(BOTTOM1_FLOWCLASSIFIERS), 0)
        self.assertEqual(len(ppg_mappings), 0)

        t_fc_id2, _ = self._prepare_flow_classifier_test(
            project_id, t_ctx, 'pod_1', 0, src_port_id, True)
        BOTTOM1_FLOWCLASSIFIERS.pop()
        fake_plugin.delete_flow_classifier(q_ctx, t_fc_id2)
        ppg_mappings = db_api.get_bottom_mappings_by_top_id(
            t_ctx, t_fc_id2, constants.RT_FLOW_CLASSIFIER)
        self.assertEqual(len(TOP_FLOWCLASSIFIERS), 0)
        self.assertEqual(len(ppg_mappings), 0)
    def test_delete_flow_classifier(self):
        project_id = TEST_TENANT_ID
        q_ctx = FakeNeutronContext()
        t_ctx = context.get_db_context()
        self._basic_pod_setup()
        fake_plugin = FakeFcPlugin()

        src_port_id = uuidutils.generate_uuid()

        t_fc_id1, _ = self._prepare_flow_classifier_test(
            project_id, t_ctx, 'pod_1', 0, src_port_id, True)
        fake_plugin.delete_flow_classifier(q_ctx, t_fc_id1)
        ppg_mappings = db_api.get_bottom_mappings_by_top_id(
            t_ctx, t_fc_id1, constants.RT_FLOW_CLASSIFIER)
        self.assertEqual(len(TOP_FLOWCLASSIFIERS), 0)
        self.assertEqual(len(BOTTOM1_FLOWCLASSIFIERS), 0)
        self.assertEqual(len(ppg_mappings), 0)

        t_fc_id2, _ = self._prepare_flow_classifier_test(
            project_id, t_ctx, 'pod_1', 0, src_port_id, True)
        BOTTOM1_FLOWCLASSIFIERS.pop()
        fake_plugin.delete_flow_classifier(q_ctx, t_fc_id2)
        ppg_mappings = db_api.get_bottom_mappings_by_top_id(
            t_ctx, t_fc_id2, constants.RT_FLOW_CLASSIFIER)
        self.assertEqual(len(TOP_FLOWCLASSIFIERS), 0)
        self.assertEqual(len(ppg_mappings), 0)
    def test_delete_port_chain(self):
        project_id = TEST_TENANT_ID
        q_ctx = FakeNeutronContext()
        t_ctx = context.get_db_context()
        self._basic_pod_setup()
        fake_plugin = FakeSfcPlugin()
        ids = {'t_ppg_id': [uuidutils.generate_uuid()],
               'b_ppg_id': [uuidutils.generate_uuid()],
               't_fc_id': [uuidutils.generate_uuid()],
               'b_fc_id': [uuidutils.generate_uuid()]}
        t_pc_id1, _ = self._prepare_port_chain_test(
            project_id, t_ctx, 'pod_1', 0, True, ids)

        fake_plugin.delete_port_chain(q_ctx, t_pc_id1)
        pc_mappings = db_api.get_bottom_mappings_by_top_id(
            t_ctx, t_pc_id1, constants.RT_PORT_CHAIN)
        self.assertEqual(len(TOP_PORTCHAINS), 0)
        self.assertEqual(len(BOTTOM1_PORTCHAINS), 0)
        self.assertEqual(len(pc_mappings), 0)

        t_pc_id2, _ = self._prepare_port_chain_test(
            project_id, t_ctx, 'pod_1', 0, True, ids)
        BOTTOM1_PORTCHAINS.pop()
        fake_plugin.delete_port_chain(q_ctx, t_pc_id2)
        pc_mappings = db_api.get_bottom_mappings_by_top_id(
            t_ctx, t_pc_id2, constants.RT_PORT_CHAIN)
        self.assertEqual(len(TOP_PORTCHAINS), 0)
        self.assertEqual(len(pc_mappings), 0)
    def test_delete_port_pair_group(self):
        project_id = TEST_TENANT_ID
        q_ctx = FakeNeutronContext()
        t_ctx = context.get_db_context()
        self._basic_pod_setup()
        fake_plugin = FakeSfcPlugin()

        t_pp_id = uuidutils.generate_uuid()
        b_pp_id = uuidutils.generate_uuid()

        t_ppg_id1, _ = self._prepare_port_pair_group_test(
            project_id, t_ctx, 'pod_1', 0, [t_pp_id], True, [b_pp_id])
        fake_plugin.delete_port_pair_group(q_ctx, t_ppg_id1)
        ppg_mappings = db_api.get_bottom_mappings_by_top_id(
            t_ctx, t_ppg_id1, constants.RT_PORT_PAIR_GROUP)
        self.assertEqual(len(TOP_PORTPAIRGROUPS), 0)
        self.assertEqual(len(BOTTOM1_PORTPAIRGROUPS), 0)
        self.assertEqual(len(ppg_mappings), 0)

        t_ppg_id2, _ = self._prepare_port_pair_group_test(
            project_id, t_ctx, 'pod_1', 0, [t_pp_id], True, [b_pp_id])
        BOTTOM1_PORTPAIRGROUPS.pop()
        fake_plugin.delete_port_pair_group(q_ctx, t_ppg_id2)
        ppg_mappings = db_api.get_bottom_mappings_by_top_id(
            t_ctx, t_ppg_id2, constants.RT_PORT_PAIR_GROUP)
        self.assertEqual(len(TOP_PORTPAIRGROUPS), 0)
        self.assertEqual(len(ppg_mappings), 0)
    def test_update_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)
        update_body = {
            'trunk': {
                'name': 'new_name',
                'description': 'updated',
                'admin_state_up': False
            }
        }
        updated_top_trunk = fake_plugin.update_trunk(q_ctx, t_trunk['id'],
                                                     update_body)
        self.assertEqual(updated_top_trunk['name'], 'new_name')
        self.assertEqual(updated_top_trunk['description'], 'updated')
        self.assertFalse(updated_top_trunk['admin_state_up'])

        updated_btm_trunk = fake_plugin.get_trunk(q_ctx, t_trunk['id'])
        self.assertEqual(updated_btm_trunk['name'], 'new_name')
        self.assertEqual(updated_btm_trunk['description'], 'updated')
        self.assertFalse(updated_btm_trunk['admin_state_up'])
    def test_delete_port_chain(self):
        project_id = TEST_TENANT_ID
        q_ctx = FakeNeutronContext()
        t_ctx = context.get_db_context()
        self._basic_pod_setup()
        fake_plugin = FakeSfcPlugin()
        ids = {
            't_ppg_id': [uuidutils.generate_uuid()],
            'b_ppg_id': [uuidutils.generate_uuid()],
            't_fc_id': [uuidutils.generate_uuid()],
            'b_fc_id': [uuidutils.generate_uuid()]
        }
        t_pc_id1, _ = self._prepare_port_chain_test(project_id, t_ctx, 'pod_1',
                                                    0, True, ids)

        fake_plugin.delete_port_chain(q_ctx, t_pc_id1)
        pc_mappings = db_api.get_bottom_mappings_by_top_id(
            t_ctx, t_pc_id1, constants.RT_PORT_CHAIN)
        self.assertEqual(len(TOP_PORTCHAINS), 0)
        self.assertEqual(len(BOTTOM1_PORTCHAINS), 0)
        self.assertEqual(len(pc_mappings), 0)

        t_pc_id2, _ = self._prepare_port_chain_test(project_id, t_ctx, 'pod_1',
                                                    0, True, ids)
        BOTTOM1_PORTCHAINS.pop()
        fake_plugin.delete_port_chain(q_ctx, t_pc_id2)
        pc_mappings = db_api.get_bottom_mappings_by_top_id(
            t_ctx, t_pc_id2, constants.RT_PORT_CHAIN)
        self.assertEqual(len(TOP_PORTCHAINS), 0)
        self.assertEqual(len(pc_mappings), 0)
    def test_delete_port_pair_group(self):
        project_id = TEST_TENANT_ID
        q_ctx = FakeNeutronContext()
        t_ctx = context.get_db_context()
        self._basic_pod_setup()
        fake_plugin = FakeSfcPlugin()

        t_pp_id = uuidutils.generate_uuid()
        b_pp_id = uuidutils.generate_uuid()

        t_ppg_id1, _ = self._prepare_port_pair_group_test(
            project_id, t_ctx, 'pod_1', 0, [t_pp_id], True, [b_pp_id])
        fake_plugin.delete_port_pair_group(q_ctx, t_ppg_id1)
        ppg_mappings = db_api.get_bottom_mappings_by_top_id(
            t_ctx, t_ppg_id1, constants.RT_PORT_PAIR_GROUP)
        self.assertEqual(len(TOP_PORTPAIRGROUPS), 0)
        self.assertEqual(len(BOTTOM1_PORTPAIRGROUPS), 0)
        self.assertEqual(len(ppg_mappings), 0)

        t_ppg_id2, _ = self._prepare_port_pair_group_test(
            project_id, t_ctx, 'pod_1', 0, [t_pp_id], True, [b_pp_id])
        BOTTOM1_PORTPAIRGROUPS.pop()
        fake_plugin.delete_port_pair_group(q_ctx, t_ppg_id2)
        ppg_mappings = db_api.get_bottom_mappings_by_top_id(
            t_ctx, t_ppg_id2, constants.RT_PORT_PAIR_GROUP)
        self.assertEqual(len(TOP_PORTPAIRGROUPS), 0)
        self.assertEqual(len(ppg_mappings), 0)
예제 #10
0
 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)
     port = fake_plugin._get_port(context, port_id)
     self.assertIsNotNone(port)
예제 #11
0
 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)
     port = fake_plugin._get_port(context, port_id)
     self.assertIsNotNone(port)
    def test_get_trunks_pagination(self):
        project_id = TEST_TENANT_ID
        q_ctx = FakeNeutronContext()
        t_ctx = context.get_db_context()
        self._basic_pod_setup()
        fake_plugin = FakePlugin()

        t_trunk1, _ = self._prepare_trunk_test(
            project_id, t_ctx, 'pod_1', 1, True,
            '101779d0-e30e-495a-ba71-6265a1669701',
            '1b1779d0-e30e-495a-ba71-6265a1669701')
        t_trunk2, _ = self._prepare_trunk_test(
            project_id, t_ctx, 'pod_1', 2, True,
            '201779d0-e30e-495a-ba71-6265a1669701',
            '2b1779d0-e30e-495a-ba71-6265a1669701')
        t_trunk3, _ = self._prepare_trunk_test(
            project_id, t_ctx, 'pod_2', 3, True,
            '301779d0-e30e-495a-ba71-6265a1669701',
            '3b1779d0-e30e-495a-ba71-6265a1669701')
        t_trunk4, _ = self._prepare_trunk_test(
            project_id, t_ctx, 'pod_2', 4, True,
            '401779d0-e30e-495a-ba71-6265a1669701',
            '4b1779d0-e30e-495a-ba71-6265a1669701')
        t_trunk5, _ = self._prepare_trunk_test(
            project_id, t_ctx, 'pod_2', 5, False,
            '501779d0-e30e-495a-ba71-6265a1669701')
        t_trunk6, _ = self._prepare_trunk_test(
            project_id, t_ctx, 'pod_2', 6, False,
            '601779d0-e30e-495a-ba71-6265a1669701')
        t_trunk7, _ = self._prepare_trunk_test(
            project_id, t_ctx, 'pod_2', 7, False,
            '601779d0-e30e-495a-ba71-6265a1669701')

        # limit no marker
        res = fake_plugin.get_trunks(q_ctx, limit=3)
        res_trunk_ids = [trunk['id'] for trunk in res]
        except_trunk_ids = [t_trunk1['id'], t_trunk2['id'], t_trunk3['id']]
        self.assertEqual(res_trunk_ids, except_trunk_ids)

        # limit and top pod's marker
        res = fake_plugin.get_trunks(q_ctx, limit=3, marker=t_trunk5['id'])
        res_trunk_ids = [trunk['id'] for trunk in res]
        except_trunk_ids = [t_trunk6['id'], t_trunk7['id']]
        self.assertEqual(res_trunk_ids, except_trunk_ids)

        # limit and bottom pod's marker
        res = fake_plugin.get_trunks(q_ctx, limit=6, marker=t_trunk1['id'])
        res_trunk_ids = [trunk['id'] for trunk in res]
        except_trunk_ids = [t_trunk2['id'], t_trunk3['id'], t_trunk4['id'],
                            t_trunk5['id'], t_trunk6['id'], t_trunk7['id']]
        self.assertEqual(res_trunk_ids, except_trunk_ids)

        # limit and bottom pod's marker and filters
        res = fake_plugin.get_trunks(q_ctx, limit=6, marker=t_trunk1['id'],
                                     filters={'status': ['UP']})
        res_trunk_ids = [trunk['id'] for trunk in res]
        except_trunk_ids = [t_trunk2['id'], t_trunk3['id'], t_trunk4['id']]
        self.assertEqual(res_trunk_ids, except_trunk_ids)
    def test_get_trunks_pagination(self):
        project_id = TEST_TENANT_ID
        q_ctx = FakeNeutronContext()
        t_ctx = context.get_db_context()
        self._basic_pod_setup()
        fake_plugin = FakePlugin()

        t_trunk1, _ = self._prepare_trunk_test(
            project_id, t_ctx, 'pod_1', 1, True,
            '101779d0-e30e-495a-ba71-6265a1669701',
            '1b1779d0-e30e-495a-ba71-6265a1669701')
        t_trunk2, _ = self._prepare_trunk_test(
            project_id, t_ctx, 'pod_1', 2, True,
            '201779d0-e30e-495a-ba71-6265a1669701',
            '2b1779d0-e30e-495a-ba71-6265a1669701')
        t_trunk3, _ = self._prepare_trunk_test(
            project_id, t_ctx, 'pod_2', 3, True,
            '301779d0-e30e-495a-ba71-6265a1669701',
            '3b1779d0-e30e-495a-ba71-6265a1669701')
        t_trunk4, _ = self._prepare_trunk_test(
            project_id, t_ctx, 'pod_2', 4, True,
            '401779d0-e30e-495a-ba71-6265a1669701',
            '4b1779d0-e30e-495a-ba71-6265a1669701')
        t_trunk5, _ = self._prepare_trunk_test(
            project_id, t_ctx, 'pod_2', 5, False,
            '501779d0-e30e-495a-ba71-6265a1669701')
        t_trunk6, _ = self._prepare_trunk_test(
            project_id, t_ctx, 'pod_2', 6, False,
            '601779d0-e30e-495a-ba71-6265a1669701')
        t_trunk7, _ = self._prepare_trunk_test(
            project_id, t_ctx, 'pod_2', 7, False,
            '601779d0-e30e-495a-ba71-6265a1669701')

        # limit no marker
        res = fake_plugin.get_trunks(q_ctx, limit=3)
        res_trunk_ids = [trunk['id'] for trunk in res]
        except_trunk_ids = [t_trunk1['id'], t_trunk2['id'], t_trunk3['id']]
        self.assertEqual(res_trunk_ids, except_trunk_ids)

        # limit and top pod's marker
        res = fake_plugin.get_trunks(q_ctx, limit=3, marker=t_trunk5['id'])
        res_trunk_ids = [trunk['id'] for trunk in res]
        except_trunk_ids = [t_trunk6['id'], t_trunk7['id']]
        self.assertEqual(res_trunk_ids, except_trunk_ids)

        # limit and bottom pod's marker
        res = fake_plugin.get_trunks(q_ctx, limit=6, marker=t_trunk1['id'])
        res_trunk_ids = [trunk['id'] for trunk in res]
        except_trunk_ids = [t_trunk2['id'], t_trunk3['id'], t_trunk4['id'],
                            t_trunk5['id'], t_trunk6['id'], t_trunk7['id']]
        self.assertEqual(res_trunk_ids, except_trunk_ids)

        # limit and bottom pod's marker and filters
        res = fake_plugin.get_trunks(q_ctx, limit=6, marker=t_trunk1['id'],
                                     filters={'status': ['UP']})
        res_trunk_ids = [trunk['id'] for trunk in res]
        except_trunk_ids = [t_trunk2['id'], t_trunk3['id'], t_trunk4['id']]
        self.assertEqual(res_trunk_ids, except_trunk_ids)
예제 #14
0
 def get_endpoint_by_host(self, host):
     LOG.debug("get_endpoint_by_host() called for host %s", host)
     host_endpoint = {'ip_address': None}
     context = t_context.get_db_context()
     agents = db_api.get_agent_by_host_type(context, host,
                                            q_lib_constants.AGENT_TYPE_OVS)
     if agents:
         host_endpoint['ip_address'] = agents['tunnel_ip']
     return host_endpoint
예제 #15
0
 def get_endpoint_by_host(self, host):
     LOG.debug("get_endpoint_by_host() called for host %s", host)
     host_endpoint = {'ip_address': None}
     context = t_context.get_db_context()
     agents = db_api.get_agent_by_host_type(
         context, host, q_lib_constants.AGENT_TYPE_OVS)
     if agents:
         host_endpoint['ip_address'] = agents['tunnel_ip']
     return host_endpoint
예제 #16
0
    def __init__(self):
        self._sites = {}
        self.compute_host_manager = ComputeHostManager(self)

        sites = models.list_sites(t_context.get_db_context(), [])
        for site in sites:
            # skip top site
            if not site['az_id']:
                continue
            self.create_site(t_context.get_admin_context(), site['site_name'])
예제 #17
0
    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)
    def test_get_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)
        res = fake_plugin.get_trunk(q_ctx, t_trunk['id'])
        t_trunk['status'] = b_trunk['status']
        t_trunk['sub_ports'][0].pop('trunk_id')
        six.assertCountEqual(self, t_trunk, res)
    def test_get_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)
        res = fake_plugin.get_trunk(q_ctx, t_trunk['id'])
        t_trunk['status'] = b_trunk['status']
        t_trunk['sub_ports'][0].pop('trunk_id')
        six.assertCountEqual(self, t_trunk, res)
    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 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 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)
    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)
    def test_get_trunks(self):
        project_id = TEST_TENANT_ID
        q_ctx = FakeNeutronContext()
        t_ctx = context.get_db_context()
        self._basic_pod_setup()
        fake_plugin = FakePlugin()

        t_trunk1, _ = self._prepare_trunk_test(project_id, t_ctx, 'pod_1', 1,
                                               True)
        t_trunk2, _ = self._prepare_trunk_test(project_id, t_ctx, 'pod_1', 2,
                                               True)
        t_trunk3, _ = self._prepare_trunk_test(project_id, t_ctx, 'pod_2', 3,
                                               True)
        t_trunk4, _ = self._prepare_trunk_test(project_id, t_ctx, 'pod_2', 4,
                                               True)
        t_trunk5, _ = self._prepare_trunk_test(project_id, t_ctx, 'pod_1', 5,
                                               False)
        t_trunk6, _ = self._prepare_trunk_test(project_id, t_ctx, 'pod_1', 6,
                                               False)
        res = fake_plugin.get_trunks(q_ctx)
        self.assertEqual(len(res), 6)

        res = fake_plugin.get_trunks(q_ctx,
                                     filters={'id': [t_trunk1['id']]},
                                     limit=3)

        t_trunk1['status'] = 'UP'
        res[0]['sub_ports'][0]['trunk_id'] = t_trunk1['id']
        six.assertCountEqual(self, [t_trunk1], res)

        res = fake_plugin.get_trunks(q_ctx, filters={'id': [t_trunk5['id']]})
        t_trunk5['sub_ports'][0].pop('trunk_id')
        six.assertCountEqual(self, [t_trunk5], res)

        trunks = fake_plugin.get_trunks(q_ctx,
                                        filters={
                                            'status': ['UP'],
                                            'description': ['created']
                                        })
        self.assertEqual(len(trunks), 4)
    def test_get_trunks(self):
        project_id = TEST_TENANT_ID
        q_ctx = FakeNeutronContext()
        t_ctx = context.get_db_context()
        self._basic_pod_setup()
        fake_plugin = FakePlugin()

        t_trunk1, _ = self._prepare_trunk_test(project_id, t_ctx,
                                               'pod_1', 1, True)
        t_trunk2, _ = self._prepare_trunk_test(project_id, t_ctx,
                                               'pod_1', 2, True)
        t_trunk3, _ = self._prepare_trunk_test(project_id, t_ctx,
                                               'pod_2', 3, True)
        t_trunk4, _ = self._prepare_trunk_test(project_id, t_ctx,
                                               'pod_2', 4, True)
        t_trunk5, _ = self._prepare_trunk_test(project_id, t_ctx,
                                               'pod_1', 5, False)
        t_trunk6, _ = self._prepare_trunk_test(project_id, t_ctx,
                                               'pod_1', 6, False)
        res = fake_plugin.get_trunks(q_ctx)
        self.assertEqual(len(res), 6)

        res = fake_plugin.get_trunks(
            q_ctx, filters={'id': [t_trunk1['id']]}, limit=3)

        t_trunk1['status'] = 'UP'
        res[0]['sub_ports'][0]['trunk_id'] = t_trunk1['id']
        six.assertCountEqual(self, [t_trunk1], res)

        res = fake_plugin.get_trunks(q_ctx, filters={'id': [t_trunk5['id']]})
        t_trunk5['sub_ports'][0].pop('trunk_id')
        six.assertCountEqual(self, [t_trunk5], res)

        trunks = fake_plugin.get_trunks(q_ctx,
                                        filters={'status': ['UP'],
                                                 'description': ['created']})
        self.assertEqual(len(trunks), 4)
    def test_update_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)
        update_body = {'trunk': {
            'name': 'new_name',
            'description': 'updated',
            'admin_state_up': False}
        }
        updated_top_trunk = fake_plugin.update_trunk(q_ctx, t_trunk['id'],
                                                     update_body)
        self.assertEqual(updated_top_trunk['name'], 'new_name')
        self.assertEqual(updated_top_trunk['description'], 'updated')
        self.assertFalse(updated_top_trunk['admin_state_up'])

        updated_btm_trunk = fake_plugin.get_trunk(q_ctx, t_trunk['id'])
        self.assertEqual(updated_btm_trunk['name'], 'new_name')
        self.assertEqual(updated_btm_trunk['description'], 'updated')
        self.assertFalse(updated_btm_trunk['admin_state_up'])
예제 #27
0
def fake_get_context_from_neutron_context(q_context):
    ctx = context.get_db_context()
    ctx.project_id = q_context.project_id
    return ctx
예제 #28
0
    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, t_ctx, 'pod_1',
                                              t_net_id)
        ingress1 = self._prepare_port_test(project_id, t_ctx, 'pod_1',
                                           t_net_id)
        egress1 = self._prepare_port_test(project_id, t_ctx, 'pod_1', t_net_id)
        t_pp1_id, b_pp1_id = self._prepare_port_pair_test(
            project_id, t_ctx, 'pod_1', 0, ingress1, egress1, True)
        t_ppg1_id, b_ppg1_id = self._prepare_port_pair_group_test(
            project_id, t_ctx, 'pod_1', 0, [t_pp1_id], True, [b_pp1_id])
        ppg_mapping = {t_pp1_id: t_ppg1_id}
        self._update_port_pair_test(ppg_mapping, TOP_PORTPAIRS)
        t_fc1_id, b_fc1_id = self._prepare_flow_classifier_test(
            project_id, t_ctx, 'pod_1', 0, src_port_id, True)

        ids = {
            't_ppg_id': [t_ppg1_id],
            'b_ppg_id': [b_ppg1_id],
            't_fc_id': [t_fc1_id],
            'b_fc_id': [b_fc1_id]
        }

        t_pc1_id, b_pc1_id = self._prepare_port_chain_test(
            project_id, t_ctx, 'pod_1', 0, True, ids)
        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, [])
        t_fc2_id, b_fc2_id = self._prepare_flow_classifier_test(
            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 fake_get_context_from_neutron_context(q_context):
    ctx = context.get_db_context()
    return ctx
예제 #30
0
    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)
예제 #31
0
    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,
                                              t_ctx, 'pod_1', t_net_id)
        ingress1 = self._prepare_port_test(project_id, t_ctx,
                                           'pod_1', t_net_id)
        egress1 = self._prepare_port_test(project_id, t_ctx, 'pod_1', t_net_id)
        t_pp1_id, b_pp1_id = self._prepare_port_pair_test(
            project_id, t_ctx, 'pod_1', 0, ingress1, egress1, True)
        t_ppg1_id, b_ppg1_id = self._prepare_port_pair_group_test(
            project_id, t_ctx, 'pod_1', 0,
            [t_pp1_id], True, [b_pp1_id])
        ppg_mapping = {t_pp1_id: t_ppg1_id}
        self._update_port_pair_test(ppg_mapping, TOP_PORTPAIRS)
        t_fc1_id, b_fc1_id = self._prepare_flow_classifier_test(
            project_id, t_ctx, 'pod_1', 0, src_port_id, True)

        ids = {'t_ppg_id': [t_ppg1_id],
               'b_ppg_id': [b_ppg1_id],
               't_fc_id': [t_fc1_id],
               'b_fc_id': [b_fc1_id]}

        t_pc1_id, b_pc1_id = self._prepare_port_chain_test(
            project_id, t_ctx, 'pod_1', 0, True, ids)
        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, [])
        t_fc2_id, b_fc2_id = self._prepare_flow_classifier_test(
            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])
예제 #32
0
    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)

        # create a segment
        # with it's name matches 'newl3-regionname-detailname'
        segment3_id = uuidutils.generate_uuid()
        segment3_name = t_constant.PREFIX_OF_SEGMENT_NAME + 'pod_1'\
            + t_constant.PREFIX_OF_SEGMENT_NAME_DIVISION + 'segment2'
        segment3 = {'segment': {
            'id': segment3_id,
            'name': segment3_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, segment3)

        res = fake_plugin.get_segment(neutron_context, segment2_id)
        self.assertEqual(res['name'], segment2_name)
        res = fake_plugin.get_segment(neutron_context, segment3_id)
        self.assertEqual(res['name'], segment3_name)
        net_filter = {'name': [segment2_name]}
        b_net = fake_plugin.central_plugin.get_networks(
            neutron_context, net_filter)
        self.assertFalse(b_net)
        net_filter = {'name': [segment3_name]}
        b_net = fake_plugin.central_plugin.get_networks(
            neutron_context, net_filter)
        self.assertEqual(b_net[0]['name'], segment3_name)

        # delete a segment
        # it's name matches 'newl3-regionname-detailname'
        fake_plugin.delete_segment(neutron_context, segment3_id)
        self.assertRaises(sg_excp.SegmentNotFound,
                          fake_plugin.get_segment,
                          neutron_context, segment3_id)
        net_filter = {'name': [segment3_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)
예제 #33
0
def fake_get_context_from_neutron_context(q_context):
    ctx = context.get_db_context()
    ctx.project_id = q_context.project_id
    return ctx
    def test_action_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)

        add_subport_id1 = self._prepare_port_test(project_id,
                                                  t_ctx,
                                                  'pod_1',
                                                  1,
                                                  create_bottom=False)
        add_subport_id2 = self._prepare_port_test(project_id,
                                                  t_ctx,
                                                  'pod_1',
                                                  2,
                                                  create_bottom=False)
        add_subport_id3 = self._prepare_port_test(project_id,
                                                  t_ctx,
                                                  'pod_1',
                                                  3,
                                                  create_bottom=False)
        add_subport_id4 = self._prepare_port_test(project_id,
                                                  t_ctx,
                                                  'pod_1',
                                                  4,
                                                  create_bottom=False)
        add_subport_id5 = self._prepare_port_test(project_id,
                                                  t_ctx,
                                                  'pod_1',
                                                  5,
                                                  create_bottom=False)
        add_subport_id6 = self._prepare_port_test(project_id,
                                                  t_ctx,
                                                  'pod_1',
                                                  6,
                                                  create_bottom=True)
        add_subport_id7 = self._prepare_port_test(project_id,
                                                  t_ctx,
                                                  'pod_1',
                                                  7,
                                                  create_bottom=True)
        add_subport_id8 = self._prepare_port_test(project_id,
                                                  t_ctx,
                                                  'pod_1',
                                                  8,
                                                  create_bottom=False)
        add_subport_id9 = self._prepare_port_test(project_id,
                                                  t_ctx,
                                                  'pod_1',
                                                  9,
                                                  create_bottom=False)

        # Avoid warning: assigned to but never used
        ids = [
            add_subport_id1, add_subport_id2, add_subport_id3, add_subport_id4,
            add_subport_id5, add_subport_id6, add_subport_id7, add_subport_id8,
            add_subport_id9
        ]
        ids.sort()

        remove_subports = {
            'segmentation_type': 'vlan',
            'port_id': uuidutils.generate_uuid(),
            'segmentation_id': 165
        }
        b_trunk['sub_ports'].append(remove_subports)

        add_subports = []
        for _id in xrange(1, 10):
            port_id = eval("add_subport_id%d" % _id)
            subport = {
                'segmentation_type': 'vlan',
                'port_id': port_id,
                '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)
def fake_get_context_from_neutron_context(q_context):
    ctx = context.get_db_context()
    return ctx
    def test_action_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)

        add_subport_id1 = self._prepare_port_test(project_id, t_ctx, 'pod_1',
                                                  1, create_bottom=False)
        add_subport_id2 = self._prepare_port_test(project_id, t_ctx, 'pod_1',
                                                  2, create_bottom=False)
        add_subport_id3 = self._prepare_port_test(project_id, t_ctx, 'pod_1',
                                                  3, create_bottom=False)
        add_subport_id4 = self._prepare_port_test(project_id, t_ctx, 'pod_1',
                                                  4, create_bottom=False)
        add_subport_id5 = self._prepare_port_test(project_id, t_ctx, 'pod_1',
                                                  5, create_bottom=False)
        add_subport_id6 = self._prepare_port_test(project_id, t_ctx, 'pod_1',
                                                  6, create_bottom=True)
        add_subport_id7 = self._prepare_port_test(project_id, t_ctx, 'pod_1',
                                                  7, create_bottom=True)
        add_subport_id8 = self._prepare_port_test(project_id, t_ctx, 'pod_1',
                                                  8, create_bottom=False)
        add_subport_id9 = self._prepare_port_test(project_id, t_ctx, 'pod_1',
                                                  9, create_bottom=False)

        # Avoid warning: assigned to but never used
        ids = [add_subport_id1, add_subport_id2, add_subport_id3,
               add_subport_id4, add_subport_id5, add_subport_id6,
               add_subport_id7, add_subport_id8, add_subport_id9]
        ids.sort()

        remove_subports = {'segmentation_type': 'vlan',
                           'port_id': uuidutils.generate_uuid(),
                           'segmentation_id': 165}
        b_trunk['sub_ports'].append(remove_subports)

        add_subports = []
        for _id in xrange(1, 10):
            port_id = eval("add_subport_id%d" % _id)
            subport = {
                'segmentation_type': 'vlan',
                'port_id': port_id,
                '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)
예제 #37
0
    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)