Exemple #1
0
 def test_vn_internal_lr(self):
     proj_obj = self._vnc_lib.project_read(
             fq_name=['default-domain', 'default-project'])
     proj_obj.set_vxlan_routing(True)
     self._vnc_lib.project_update(proj_obj)
     lr_name = self.id() + '_logicalrouter'
     lr = LogicalRouter(lr_name)
     rtgt_list = RouteTargetList(route_target=['target:3:1'])
     lr.set_configured_route_target_list(rtgt_list)
     self._vnc_lib.logical_router_create(lr)
     lr_read = self._vnc_lib.logical_router_read(fq_name=lr.get_fq_name())
     lr_target = self.check_lr_target(lr_read.get_fq_name())
     ivn_name = get_lr_internal_vn_name(lr_read.uuid)
     lr_ivn_read = self._vnc_lib.virtual_network_read(
                                fq_name=proj_obj.get_fq_name()+[ivn_name])
     ri_name = self.get_ri_name(lr_ivn_read)
     self.check_route_target_in_routing_instance(
                                     ri_name,rtgt_list.get_route_target())
     # change RT and see it is getting updated
     rtgt_list.delete_route_target('target:3:1')
     rtgt_list.add_route_target('target:4:1')
     lr.set_configured_route_target_list(rtgt_list)
     self._vnc_lib.logical_router_update(lr)
     self.check_route_target_in_routing_instance(
                                     ri_name,rtgt_list.get_route_target())
     # cleanup
     self._vnc_lib.logical_router_delete(id=lr.uuid)
     self.check_lr_is_deleted(uuid=lr.uuid)
     self.check_vn_is_deleted(uuid=lr_ivn_read.uuid)
 def test_vn_internal_lr(self):
     proj_obj = self._vnc_lib.project_read(
             fq_name=['default-domain', 'default-project'])
     proj_obj.set_vxlan_routing(True)
     self._vnc_lib.project_update(proj_obj)
     lr_name = self.id() + '_logicalrouter'
     lr = LogicalRouter(lr_name)
     rtgt_list = RouteTargetList(route_target=['target:3:1'])
     lr.set_configured_route_target_list(rtgt_list)
     self._vnc_lib.logical_router_create(lr)
     lr_read = self._vnc_lib.logical_router_read(fq_name=lr.get_fq_name())
     lr_target = self.check_lr_target(lr_read.get_fq_name())
     ivn_name = get_lr_internal_vn_name(lr_read.uuid)
     lr_ivn_read = self._vnc_lib.virtual_network_read(
                                fq_name=proj_obj.get_fq_name()+[ivn_name])
     ri_name = self.get_ri_name(lr_ivn_read)
     self.check_route_target_in_routing_instance(
                                     ri_name,rtgt_list.get_route_target())
     # change RT and see it is getting updated
     rtgt_list.delete_route_target('target:3:1')
     rtgt_list.add_route_target('target:4:1')
     lr.set_configured_route_target_list(rtgt_list)
     self._vnc_lib.logical_router_update(lr)
     self.check_route_target_in_routing_instance(
                                     ri_name,rtgt_list.get_route_target())
     # cleanup
     self._vnc_lib.logical_router_delete(id=lr.uuid)
     self.check_lr_is_deleted(uuid=lr.uuid)
     self.check_vn_is_deleted(uuid=lr_ivn_read.uuid)
Exemple #3
0
    def test_logical_router(self):
        # create  vn1
        vn1_name = self.id() + 'vn1'
        vn1_obj = self.create_virtual_network(vn1_name, '10.0.0.0/24')

        # create virtual machine interface
        vmi_name = self.id() + 'vmi1'
        vmi = VirtualMachineInterface(
            vmi_name,
            parent_type='project',
            fq_name=['default-domain', 'default-project', vmi_name])
        vmi.add_virtual_network(vn1_obj)
        self._vnc_lib.virtual_machine_interface_create(vmi)

        # create logical router
        lr_name = self.id() + 'lr1'
        lr = LogicalRouter(lr_name)
        rtgt_list = RouteTargetList(route_target=['target:1:1'])
        lr.set_configured_route_target_list(rtgt_list)
        lr.add_virtual_machine_interface(vmi)
        self._vnc_lib.logical_router_create(lr)

        ri_name = self.get_ri_name(vn1_obj)
        self.check_route_target_in_routing_instance(
            ri_name, rtgt_list.get_route_target())

        rtgt_list.add_route_target('target:1:2')
        lr.set_configured_route_target_list(rtgt_list)
        self._vnc_lib.logical_router_update(lr)
        self.check_route_target_in_routing_instance(
            ri_name, rtgt_list.get_route_target())

        rtgt_list.delete_route_target('target:1:1')
        lr.set_configured_route_target_list(rtgt_list)
        self._vnc_lib.logical_router_update(lr)
        self.check_route_target_in_routing_instance(
            ri_name, rtgt_list.get_route_target())

        lr.del_virtual_machine_interface(vmi)
        self._vnc_lib.logical_router_update(lr)
        self._vnc_lib.virtual_machine_interface_delete(id=vmi.uuid)
        self._vnc_lib.virtual_network_delete(id=vn1_obj.uuid)
        self.check_vn_is_deleted(uuid=vn1_obj.uuid)
        self._vnc_lib.logical_router_delete(id=lr.uuid)
        self.check_lr_is_deleted(uuid=lr.uuid)
        self.check_rt_is_deleted(name='target:64512:8000002')
    def test_logical_router(self):
        # create  vn1
        vn1_name = self.id() + 'vn1'
        vn1_obj = self.create_virtual_network(vn1_name, '10.0.0.0/24')

        # create virtual machine interface
        vmi_name = self.id() + 'vmi1'
        vmi = VirtualMachineInterface(vmi_name, parent_type='project', fq_name=['default-domain', 'default-project', vmi_name])
        vmi.add_virtual_network(vn1_obj)
        self._vnc_lib.virtual_machine_interface_create(vmi)

        # create logical router
        lr_name = self.id() + 'lr1'
        lr = LogicalRouter(lr_name)
        rtgt_list = RouteTargetList(route_target=['target:1:1'])
        lr.set_configured_route_target_list(rtgt_list)
        lr.add_virtual_machine_interface(vmi)
        self._vnc_lib.logical_router_create(lr)

        ri_name = self.get_ri_name(vn1_obj)
        self.check_route_target_in_routing_instance(ri_name,rtgt_list.get_route_target())

        rtgt_list.add_route_target('target:1:2')
        lr.set_configured_route_target_list(rtgt_list)
        self._vnc_lib.logical_router_update(lr)
        self.check_route_target_in_routing_instance(ri_name, rtgt_list.get_route_target())

        rtgt_list.delete_route_target('target:1:1')
        lr.set_configured_route_target_list(rtgt_list)
        self._vnc_lib.logical_router_update(lr)
        self.check_route_target_in_routing_instance(ri_name, rtgt_list.get_route_target())

        lr.del_virtual_machine_interface(vmi)
        self._vnc_lib.logical_router_update(lr)
        self._vnc_lib.virtual_machine_interface_delete(id=vmi.uuid)
        self._vnc_lib.virtual_network_delete(id=vn1_obj.uuid)
        self.check_vn_is_deleted(uuid=vn1_obj.uuid)
        self._vnc_lib.logical_router_delete(id=lr.uuid)
        self.check_lr_is_deleted(uuid=lr.uuid)
        self.check_rt_is_deleted(name='target:64512:8000002')
    def test_add_delete_route(self):
        lvn_name = self.id() + 'lvn'
        rvn_name = self.id() + 'rvn'
        lvn = self.create_virtual_network(lvn_name, "10.0.0.0/24")
        rvn = self.create_virtual_network(rvn_name, "20.0.0.0/24")

        service_name = self.id() + 's1'
        np = self.create_network_policy(lvn,
                                        rvn, [service_name],
                                        service_mode="in-network-nat")

        vn_name = self.id() + 'vn100'
        vn = self.create_virtual_network(vn_name, "1.0.0.0/24")
        rtgt_list = RouteTargetList(route_target=['target:1:1'])
        vn.set_route_target_list(rtgt_list)
        exp_rtgt_list = RouteTargetList(route_target=['target:2:1'])
        vn.set_export_route_target_list(exp_rtgt_list)
        imp_rtgt_list = RouteTargetList(route_target=['target:3:1'])
        vn.set_import_route_target_list(imp_rtgt_list)
        self._vnc_lib.virtual_network_update(vn)
        rt = RouteTable("rt1")
        self._vnc_lib.route_table_create(rt)
        vn.add_route_table(rt)
        self._vnc_lib.virtual_network_update(vn)
        routes = RouteTableType()
        route = RouteType(prefix="0.0.0.0/0",
                          next_hop="default-domain:default-project:" +
                          service_name)
        routes.add_route(route)
        rt.set_routes(routes)
        self._vnc_lib.route_table_update(rt)

        @retries(5)
        def _match_route_table(rtgt_list):
            lri = self._vnc_lib.routing_instance_read(
                fq_name=self.get_ri_name(lvn))
            sr = lri.get_static_route_entries()
            if sr is None:
                raise Exception("sr is None")
            route = sr.route[0]
            self.assertEqual(route.prefix, "0.0.0.0/0")
            self.assertEqual(route.next_hop, "10.0.0.252")
            for rtgt in rtgt_list:
                self.assertIn(rtgt, route.route_target)
            ri100 = self._vnc_lib.routing_instance_read(
                fq_name=self.get_ri_name(vn))
            rt100 = set(ref['to'][0] for ref in ri100.get_route_target_refs())
            lrt = set(ref['to'][0]
                      for ref in lri.get_route_target_refs() or [])
            if rt100 & lrt:
                return (rt100 & lrt)
            raise Exception("rt100 route-target ref not found")

        rt100 = _match_route_table(rtgt_list.get_route_target() +
                                   imp_rtgt_list.get_route_target())

        rtgt_list.add_route_target('target:1:2')
        vn.set_route_target_list(rtgt_list)
        exp_rtgt_list.add_route_target('target:2:2')
        vn.set_export_route_target_list(exp_rtgt_list)
        imp_rtgt_list.add_route_target('target:3:2')
        vn.set_import_route_target_list(imp_rtgt_list)
        self._vnc_lib.virtual_network_update(vn)
        _match_route_table(rtgt_list.get_route_target())

        rtgt_list.delete_route_target('target:1:1')
        vn.set_route_target_list(rtgt_list)
        exp_rtgt_list.delete_route_target('target:2:1')
        vn.set_export_route_target_list(exp_rtgt_list)
        imp_rtgt_list.delete_route_target('target:3:1')
        vn.set_import_route_target_list(imp_rtgt_list)
        self._vnc_lib.virtual_network_update(vn)
        _match_route_table(rtgt_list.get_route_target())

        routes.set_route([])
        rt.set_routes(routes)
        self._vnc_lib.route_table_update(rt)

        @retries(5)
        def _match_route_table_cleanup(rt100):
            lri = self._vnc_lib.routing_instance_read(
                fq_name=self.get_ri_name(lvn))
            sr = lri.get_static_route_entries()
            if sr and sr.route:
                raise Exception("sr has route")
            ri = self._vnc_lib.routing_instance_read(
                fq_name=self.get_ri_name(lvn))
            rt_refs = ri.get_route_target_refs()
            rt_set = set(ref['to'][0]
                         for ref in ri.get_route_target_refs() or [])
            if rt100 & rt_set:
                raise Exception("route-target ref still found: %s" %
                                (rt100 & rt_set))

        _match_route_table_cleanup(rt100)

        # add the route again, then delete the network without deleting the
        # link to route table
        route = RouteType(prefix="0.0.0.0/0",
                          next_hop="default-domain:default-project:" +
                          service_name)
        routes.add_route(route)
        rt.set_routes(routes)
        self._vnc_lib.route_table_update(rt)
        _match_route_table(rtgt_list.get_route_target())
        self._vnc_lib.virtual_network_delete(fq_name=vn.get_fq_name())
        _match_route_table_cleanup(rt100)

        self._vnc_lib.route_table_delete(fq_name=rt.get_fq_name())
        self.delete_network_policy(np, auto_policy=True)
        gevent.sleep(1)
        self._vnc_lib.virtual_network_delete(fq_name=lvn.get_fq_name())
        self._vnc_lib.virtual_network_delete(fq_name=rvn.get_fq_name())
        # check if vn is deleted
        self.check_vn_is_deleted(uuid=lvn.uuid)
        self.check_vn_is_deleted(uuid=rvn.uuid)
        self.check_vn_is_deleted(uuid=vn.uuid)
        self.check_ri_is_deleted(fq_name=lvn.fq_name + [lvn.name])
        self.check_ri_is_deleted(fq_name=rvn.fq_name + [rvn.name])
        self.check_ri_is_deleted(fq_name=vn.fq_name + [vn.name])