def test_associating_bgpvpn(self):
        # Create one logical with one interface on a virtual network
        lr, vns, _, _ = self.create_logical_router('lr-%s' % self.id())
        # We attached only one virtual network to the logical router
        vn = vns[0]
        # Create two bgpvpn with route targets
        for idx in range(2):
            bgpvpn = Bgpvpn('bgpvpn%d-%s' % (idx, self.id()))
            bgpvpn.set_route_target_list(
                RouteTargetList(['target:%d:0' % idx]))
            bgpvpn.set_import_route_target_list(
                RouteTargetList(['target:%d:1' % idx]))
            bgpvpn.set_export_route_target_list(
                RouteTargetList(['target:%d:2' % idx]))
            self._vnc_lib.bgpvpn_create(bgpvpn)
            lr.add_bgpvpn(bgpvpn)
            self._vnc_lib.logical_router_update(lr)

        # Check bgpvpn's route targets are correctly associated to virtual
        # network's primary routing instances of network attached to the
        # logical routers.
        # Check imported and exported route targets
        self.check_rt_in_ri(self.get_ri_name(vn), 'target:0:0')
        self.check_rt_in_ri(self.get_ri_name(vn), 'target:1:0')

        # Check imported route targets
        self.check_rt_in_ri(self.get_ri_name(vn), 'target:0:1', exim='import')
        self.check_rt_in_ri(self.get_ri_name(vn), 'target:1:1', exim='import')

        # Check exported route targets
        self.check_rt_in_ri(self.get_ri_name(vn), 'target:0:2', exim='export')
        self.check_rt_in_ri(self.get_ri_name(vn), 'target:1:2', exim='export')
    def test_route_target_overlapping(self):
        rt_name = 'target:4:1'
        # Create one virtual network and set a route target in its route
        # target list
        vn = self.create_virtual_network('vn-%s' % self.id(), '10.0.0.0/24')
        vn.set_route_target_list(RouteTargetList([rt_name]))
        self._vnc_lib.virtual_network_update(vn)
        # Create one bgpvpn, set the same route target in its route target list
        # and associate it to the virtual network
        bgpvpn = Bgpvpn('bgpvpn-%s' % self.id())
        bgpvpn.set_route_target_list(RouteTargetList([rt_name]))
        bgpvpn_id = self._vnc_lib.bgpvpn_create(bgpvpn)
        bgpvpn = self._vnc_lib.bgpvpn_read(id=bgpvpn_id)
        vn.add_bgpvpn(bgpvpn)
        self._vnc_lib.virtual_network_update(vn)

        # Check the route target is set on the virtual network's routing
        # instance
        self.check_rt_in_ri(self.get_ri_name(vn), rt_name)

        # Remove the route target from the bgpvpn' route target list and check
        # the route target is still set on the virtual network's routing
        # instance
        bgpvpn.set_route_target_list(RouteTargetList())
        self._vnc_lib.bgpvpn_update(bgpvpn)
        sleep(1)
        self.check_rt_in_ri(self.get_ri_name(vn), rt_name)

        # Remove the route target from the virtual network's route target list
        # and check is no more associate to the routing instance
        vn.set_route_target_list(RouteTargetList())
        self._vnc_lib.virtual_network_update(vn)
        self.check_rt_in_ri(self.get_ri_name(vn), rt_name, is_present=False)
        self.check_rt_is_deleted(rt_name)
    def test_associating_bgpvpn(self):
        # Create one virtual network
        vn = self.create_virtual_network('vn-%s' % self.id(), '10.0.0.0/24')
        # Create two bgpvpn with route targets
        for idx in range(2):
            bgpvpn = Bgpvpn('bgpvpn%d-%s' % (idx, self.id()))
            bgpvpn.set_route_target_list(
                RouteTargetList(['target:%d:0' % idx]))
            bgpvpn.set_import_route_target_list(
                RouteTargetList(['target:%d:1' % idx]))
            bgpvpn.set_export_route_target_list(
                RouteTargetList(['target:%d:2' % idx]))
            self._vnc_lib.bgpvpn_create(bgpvpn)
            vn.add_bgpvpn(bgpvpn)
            self._vnc_lib.virtual_network_update(vn)

        # Check bgpvpn's route targets are correctly associated to virtual
        # network's primary routing instances.
        # Check imported and exported route targets
        self.check_rt_in_ri(self.get_ri_name(vn), 'target:0:0')
        self.check_rt_in_ri(self.get_ri_name(vn), 'target:0:0')

        # Check imported route targets
        self.check_rt_in_ri(self.get_ri_name(vn), 'target:0:1', exim='import')
        self.check_rt_in_ri(self.get_ri_name(vn), 'target:0:1', exim='import')

        # Check exported route targets
        self.check_rt_in_ri(self.get_ri_name(vn), 'target:0:2', exim='export')
        self.check_rt_in_ri(self.get_ri_name(vn), 'target:0:2', exim='export')
Exemple #4
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_configured_targets(self):
        # create  vn1
        vn1_name = self.id() + 'vn1'
        vn1_obj = self.create_virtual_network(vn1_name, '10.0.0.0/24')
        self.wait_to_get_object(RoutingInstanceST,
                                vn1_obj.get_fq_name_str() + ':' + vn1_name)

        rtgt_list = RouteTargetList(route_target=['target:1:1'])
        vn1_obj.set_route_target_list(rtgt_list)
        exp_rtgt_list = RouteTargetList(route_target=['target:2:1'])
        vn1_obj.set_export_route_target_list(exp_rtgt_list)
        imp_rtgt_list = RouteTargetList(route_target=['target:3:1'])
        vn1_obj.set_import_route_target_list(imp_rtgt_list)
        self._vnc_lib.virtual_network_update(vn1_obj)

        self.check_rt_in_ri(self.get_ri_name(vn1_obj), 'target:1:1', True)
        self.check_rt_in_ri(self.get_ri_name(vn1_obj), 'target:2:1', True,
                            'export')
        self.check_rt_in_ri(self.get_ri_name(vn1_obj), 'target:3:1', True,
                            'import')

        exp_rtgt_list.route_target.append('target:1:1')
        vn1_obj.set_export_route_target_list(exp_rtgt_list)
        self._vnc_lib.virtual_network_update(vn1_obj)
        self.check_rt_in_ri(self.get_ri_name(vn1_obj), 'target:1:1', True)
        self.check_rt_in_ri(self.get_ri_name(vn1_obj), 'target:2:1', True,
                            'export')

        imp_rtgt_list.route_target.append('target:1:1')
        vn1_obj.set_import_route_target_list(imp_rtgt_list)
        self._vnc_lib.virtual_network_update(vn1_obj)
        self.check_rt_in_ri(self.get_ri_name(vn1_obj), 'target:1:1', True)
        self.check_rt_in_ri(self.get_ri_name(vn1_obj), 'target:3:1', True,
                            'import')

        exp_rtgt_list = RouteTargetList(route_target=['target:2:1'])
        vn1_obj.set_export_route_target_list(exp_rtgt_list)
        imp_rtgt_list = RouteTargetList(route_target=['target:3:1'])
        vn1_obj.set_import_route_target_list(imp_rtgt_list)
        self._vnc_lib.virtual_network_update(vn1_obj)
        self.check_rt_in_ri(self.get_ri_name(vn1_obj), 'target:1:1', True)
        self.check_rt_in_ri(self.get_ri_name(vn1_obj), 'target:2:1', True,
                            'export')
        self.check_rt_in_ri(self.get_ri_name(vn1_obj), 'target:3:1', True,
                            'import')

        self._vnc_lib.virtual_network_delete(id=vn1_obj.uuid)
        self.check_ri_is_deleted(fq_name=vn1_obj.fq_name + [vn1_obj.name])
    def test_route_target_removed_when_resource_deleted(self):
        # Create two virtual networks
        vn1 = self.create_virtual_network('vn1-%s' % self.id(), '10.0.0.0/24')
        vn2 = self.create_virtual_network('vn2-%s' % self.id(), '10.0.1.0/24')
        # Create one bgpvpn with route target
        bgpvpn = Bgpvpn('bgpvpn-%s' % self.id())
        rt_name = 'target:200:1'
        bgpvpn.set_route_target_list(RouteTargetList([rt_name]))
        bgpvpn_id = self._vnc_lib.bgpvpn_create(bgpvpn)
        bgpvpn = self._vnc_lib.bgpvpn_read(id=bgpvpn_id)
        # Associate bgpvpn to networks
        for vn in [vn1, vn2]:
            vn.add_bgpvpn(bgpvpn)
            self._vnc_lib.virtual_network_update(vn)

        # Check route target is correctly removed when no more networks use
        # them.
        # Remove one of the associated virtual networks
        self._vnc_lib.virtual_network_delete(id=vn2.uuid)
        self.check_ri_is_deleted(self.get_ri_name(vn2))
        # Check the bgpvpn's route target is still referenced by
        # virtual network's primary routing instance which are still associated
        self.check_rt_in_ri(self.get_ri_name(vn1), rt_name)

        # Remove last associated virtual network
        self._vnc_lib.virtual_network_delete(id=vn1.uuid)
        self.check_ri_is_deleted(fq_name=self.get_ri_name(vn1))
        # Check the bgpvpn's route target was also deleted
        self.check_rt_is_deleted(rt_name)
    def test_create_vn_with_configured_rt_in_system_range(self):
        gsc = self.api.global_system_config_read(GlobalSystemConfig().fq_name)
        vn = VirtualNetwork('%s-vn' % self.id())
        rt_name = 'target:%d:%d' % (gsc.autonomous_system,
                                    BGP_RTGT_MIN_ID + 1000)
        vn.set_route_target_list(RouteTargetList([rt_name]))

        self.assertRaises(BadRequest, self.api.virtual_network_create, vn)
 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 #9
0
 def create(self):
     if not self.bgpvpn_id:
         project = self.vnc_lib_h.project_read(
             fq_name=['default-domain', self.project_name])
         bgpvpn = Bgpvpn(name=self.bgpvpn_name, parent_obj=project)
         bgpvpn.set_route_target_list(RouteTargetList(self.route_target))
         self.bgpvpn_id = self.vnc_lib_h.bgpvpn_create(bgpvpn)
         self.logger.info('created Bgpvpn %s' % self.bgpvpn_name)
         self.read()
 def add_route_target(self, router_asn, route_target_number):
     val = 'target:%s:%s' % (router_asn, route_target_number)
     tgts = self.vnc_obj.get_route_target_list()
     if tgts:
         if val not in tgts.get_route_target():
             tgts.add_route_target(val)
     else:
         tgts = RouteTargetList([val])
     self.vnc_obj.set_route_target_list(tgts)
     self.vnc_api.virtual_network_update(self.vnc_obj)
     self.update()
Exemple #11
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_route_target_overlapping(self):
        rt_name = 'target:4:1'
        # Create one logical router with one private virtual network and set a
        # route target in its configured route target list
        lr, vns, _, _ = self.create_logical_router('lr-%s' % self.id())
        # We attached only one virtual network to the logical router
        vn = vns[0]
        lr.set_configured_route_target_list(RouteTargetList([rt_name]))
        self._vnc_lib.logical_router_update(lr)
        # Create one bgpvpn, set the same route target in its route target list
        # and associate it to the logical router
        bgpvpn = Bgpvpn('bgpvpn-%s' % self.id())
        bgpvpn.set_route_target_list(RouteTargetList([rt_name]))
        bgpvpn_id = self._vnc_lib.bgpvpn_create(bgpvpn)
        bgpvpn = self._vnc_lib.bgpvpn_read(id=bgpvpn_id)
        lr.add_bgpvpn(bgpvpn)
        self._vnc_lib.logical_router_update(lr)

        # Check the route target is set on the virtual network's routing
        # instance
        self.check_rt_in_ri(self.get_ri_name(vn), rt_name)

        # Remove the route target from the bgpvpn' route target list and check
        # the route target is still set on the virtual network's routing
        # instance
        bgpvpn.set_route_target_list(RouteTargetList())
        self._vnc_lib.bgpvpn_update(bgpvpn)
        sleep(1)
        self.check_rt_in_ri(self.get_ri_name(vn), rt_name)

        # Remove the route target from the logical router's configured route
        # target list and check is no more associate to the routing instance
        lr.set_configured_route_target_list(RouteTargetList())
        self._vnc_lib.logical_router_update(lr)
        self.check_rt_in_ri(self.get_ri_name(vn), rt_name, is_present=False)
        self.check_rt_is_deleted(rt_name)
    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_route_target_removed_when_resource_deleted(self):
        # Create two logical router with one virtual network attached
        lr1, vns1, _, _ = self.create_logical_router('lr1-%s' % self.id())
        lr2, vns2, _, _ = self.create_logical_router('lr2-%s' % self.id())
        # We attached only one virtual network per logical routers
        vn1 = vns1[0]
        vn2 = vns2[0]
        # Create one bgpvpn with route target
        bgpvpn = Bgpvpn('bgpvpn-%s' % self.id())
        rt_name = 'target:300:1'
        bgpvpn.set_route_target_list(RouteTargetList([rt_name]))
        bgpvpn_id = self._vnc_lib.bgpvpn_create(bgpvpn)
        bgpvpn = self._vnc_lib.bgpvpn_read(id=bgpvpn_id)
        # Associate bgpvpn to routers
        for lr in [lr1, lr2]:
            lr.add_bgpvpn(bgpvpn)
            self._vnc_lib.logical_router_update(lr)

        # Check route target is correctly removed when no more routers use
        # them.
        # Remove one of the associated logical router but keep attached virtual
        # network and its primary routing instance used to applied bgpvpn's
        # route target
        self._vnc_lib.logical_router_delete(id=lr2.uuid)
        # Chech that routing instance still there but the bgpvpn route target
        # were not anymore referenced
        self.check_vn_ri_state(self.get_ri_name(vn2))
        self.check_rt_in_ri(self.get_ri_name(vn2), rt_name, is_present=False)
        # Check the bgpvpn's route target is still referenced by
        # virtual network's primary routing instance which are still associated
        # to the first logical router
        self.check_rt_in_ri(self.get_ri_name(vn1), rt_name)

        # Remove last associated logical router
        self._vnc_lib.logical_router_delete(id=lr1.uuid)
        # Chech the routing instance still there but the bgpvpn route target
        # were not anymore referenced
        self.check_vn_ri_state(self.get_ri_name(vn1))
        self.check_rt_in_ri(self.get_ri_name(vn1), rt_name, is_present=False)
        # Check the bgpvpn's route target was also deleted
        self.check_rt_is_deleted(rt_name)
Exemple #15
0
    def test_update_asn_if_any_rt_uses_4_byte(self):
        """
        Test scenario.

        1. Set enable_4byte_as to true
        2. Create RT with 4 bytes ASN
        3. Set enable_4byte_as to false
        4. Change global ASN to different 2 bytes numbers
        """
        gsc = self.api.global_system_config_read(GlobalSystemConfig().fq_name)

        # Set enable_4byte_as to True
        gsc.enable_4byte_as = True
        gsc.autonomous_system = self.ASN_4_BYTES
        self.api.global_system_config_update(gsc)

        # reread gsc
        gsc = self.api.global_system_config_read(GlobalSystemConfig().fq_name)
        self.assertEqual(gsc.enable_4byte_as, True)

        # create VN and RT with 4bytes ASN
        vn = VirtualNetwork('%s-vn' % self.id())
        rt_name = 'target:%d:%d' % (self.ASN_4_BYTES, 1000)
        vn.set_route_target_list(RouteTargetList([rt_name]))
        self.api.virtual_network_create(vn)

        # Set enable_4byte_as to false
        gsc.enable_4byte_as = False
        self.api.global_system_config_update(gsc)
        # Change global ASN to 2 bytes numbers (must be in separate step)
        gsc.autonomous_system = self.NEW_ASN
        self.api.global_system_config_update(gsc)

        # reread gsc to confirm change
        gsc = self.api.global_system_config_read(GlobalSystemConfig().fq_name)
        self.assertEqual(gsc.autonomous_system, self.NEW_ASN)

        # cleanup
        self.api.virtual_network_delete(id=vn.uuid)
        gsc.autonomous_system = self.DEFAULT_ASN
        self.api.global_system_config_update(gsc)
    def test_updating_bgpvpn(self):
        # Create one logical router with one private virtual network
        lr, vns, _, _ = self.create_logical_router('lr-%s' % self.id())
        # We attached only one virtual network to the logical router
        vn = vns[0]
        # Create one bgpvpn without any route target associated to the logical
        # router
        bgpvpn = Bgpvpn('bgpvpn-%s' % self.id())
        bgpvpn_id = self._vnc_lib.bgpvpn_create(bgpvpn)
        bgpvpn = self._vnc_lib.bgpvpn_read(id=bgpvpn_id)
        lr.add_bgpvpn(bgpvpn)
        self._vnc_lib.logical_router_update(lr)

        rt_name = 'target:3:1'

        # Check set/unset import and export route target
        bgpvpn.set_route_target_list(RouteTargetList([rt_name]))
        self._vnc_lib.bgpvpn_update(bgpvpn)
        self.check_rt_in_ri(self.get_ri_name(vn), rt_name)
        bgpvpn.set_route_target_list(RouteTargetList())
        self._vnc_lib.bgpvpn_update(bgpvpn)
        self.check_rt_in_ri(self.get_ri_name(vn), rt_name, is_present=False)
        self.check_rt_is_deleted(rt_name)

        # Check set/unset import route target
        bgpvpn.set_import_route_target_list(RouteTargetList([rt_name]))
        self._vnc_lib.bgpvpn_update(bgpvpn)
        self.check_rt_in_ri(self.get_ri_name(vn), rt_name, exim='import')
        bgpvpn.set_import_route_target_list(RouteTargetList())
        self._vnc_lib.bgpvpn_update(bgpvpn)
        self.check_rt_in_ri(self.get_ri_name(vn), rt_name, is_present=False)
        self.check_rt_is_deleted(rt_name)

        # Check set/unset export route target
        bgpvpn.set_export_route_target_list(RouteTargetList([rt_name]))
        self._vnc_lib.bgpvpn_update(bgpvpn)
        self.check_rt_in_ri(self.get_ri_name(vn), rt_name, exim='export')
        bgpvpn.set_export_route_target_list(RouteTargetList())
        self._vnc_lib.bgpvpn_update(bgpvpn)
        self.check_rt_in_ri(self.get_ri_name(vn), rt_name, is_present=False)
        self.check_rt_is_deleted(rt_name)
    def test_updating_bgpvpn(self):
        # Create one virtual network
        vn = self.create_virtual_network('vn-%s' % self.id(), '10.0.0.0/24')
        # Create one bgpvpn without any route target associated to the virtual
        # network
        bgpvpn = Bgpvpn('bgpvpn-%s' % self.id())
        bgpvpn_id = self._vnc_lib.bgpvpn_create(bgpvpn)
        bgpvpn = self._vnc_lib.bgpvpn_read(id=bgpvpn_id)
        vn.add_bgpvpn(bgpvpn)
        self._vnc_lib.virtual_network_update(vn)

        rt_name = 'target:3:1'

        # Check set/unset import and export route target
        bgpvpn.set_route_target_list(RouteTargetList([rt_name]))
        self._vnc_lib.bgpvpn_update(bgpvpn)
        self.check_rt_in_ri(self.get_ri_name(vn), rt_name)
        bgpvpn.set_route_target_list(RouteTargetList())
        self._vnc_lib.bgpvpn_update(bgpvpn)
        self.check_rt_in_ri(self.get_ri_name(vn), rt_name, is_present=False)
        self.check_rt_is_deleted(rt_name)

        # Check set/unset import route target
        bgpvpn.set_import_route_target_list(RouteTargetList([rt_name]))
        self._vnc_lib.bgpvpn_update(bgpvpn)
        self.check_rt_in_ri(self.get_ri_name(vn), rt_name, exim='import')
        bgpvpn.set_import_route_target_list(RouteTargetList())
        self._vnc_lib.bgpvpn_update(bgpvpn)
        self.check_rt_in_ri(self.get_ri_name(vn), rt_name, is_present=False)
        self.check_rt_is_deleted(rt_name)

        # Check set/unset export route target
        bgpvpn.set_export_route_target_list(RouteTargetList([rt_name]))
        self._vnc_lib.bgpvpn_update(bgpvpn)
        self.check_rt_in_ri(self.get_ri_name(vn), rt_name, exim='export')
        bgpvpn.set_export_route_target_list(RouteTargetList())
        self._vnc_lib.bgpvpn_update(bgpvpn)
        self.check_rt_in_ri(self.get_ri_name(vn), rt_name, is_present=False)
        self.check_rt_is_deleted(rt_name)
    def test_vxlan_routing(self):
        proj_obj = self._vnc_lib.project_read(
            fq_name=['default-domain', 'default-project'])
        # 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)

        # Enable vxlan_routing in the project
        # and verify RT not attached to LR
        proj_obj.set_vxlan_routing(True)
        self._vnc_lib.project_update(proj_obj)
        ri_name = self.get_ri_name(vn1_obj)
        ri_obj = self._vnc_lib.routing_instance_read(fq_name=ri_name)
        vn_rt_refs = set(
            [ref['to'][0] for ref in ri_obj.get_route_target_refs() or []])

        # create logical router with RT
        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)
        lr = self._vnc_lib.logical_router_read(fq_name=lr.get_fq_name())
        lr_target = self.check_lr_target(lr.get_fq_name())
        ri_obj = self._vnc_lib.routing_instance_read(fq_name=ri_name)
        vn_rt_refs_with_lr = set(
            [ref['to'][0] for ref in ri_obj.get_route_target_refs() or []])
        # ensure no RT from LR is attached to VN
        self.assertTrue(vn_rt_refs_with_lr == vn_rt_refs,
                        msg='RT attached to VN is different after LR creation')

        # configure a new route target after
        # LR is created
        rtgt_list.add_route_target('target:1:2')
        lr.set_configured_route_target_list(rtgt_list)
        self._vnc_lib.logical_router_update(lr)
        lr = self._vnc_lib.logical_router_read(fq_name=lr.get_fq_name())
        lr_target = self.check_lr_target(lr.get_fq_name())
        ri_obj = self._vnc_lib.routing_instance_read(fq_name=ri_name)
        vn_rt_refs_with_lr = set(
            [ref['to'][0] for ref in ri_obj.get_route_target_refs() or []])
        # ensure no RT from LR is attached to VN
        self.assertTrue(vn_rt_refs_with_lr == vn_rt_refs,
                        msg='RT attached to VN is different after LR creation')

        # check no service instance generated
        self.check_no_si_in_lr(lr.get_fq_name())

        # cleanup
        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)
    def test_vxlan_routing(self):
        proj_obj = self._vnc_lib.project_read(
                fq_name=['default-domain', 'default-project'])
        # 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)

        # Enable vxlan_routing in the project
        # and verify RT not attached to LR
        proj_obj.set_vxlan_routing(True)
        self._vnc_lib.project_update(proj_obj)
        ri_name = self.get_ri_name(vn1_obj)
        ri_obj = self._vnc_lib.routing_instance_read(fq_name=ri_name)
        vn_rt_refs = set([ref['to'][0]
            for ref in ri_obj.get_route_target_refs() or []])

        # create logical router with RT
        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)
        lr = self._vnc_lib.logical_router_read(fq_name=lr.get_fq_name())
        lr_target = self.check_lr_target(lr.get_fq_name())
        ri_obj = self._vnc_lib.routing_instance_read(fq_name=ri_name)
        vn_rt_refs_with_lr = set([ref['to'][0]
            for ref in ri_obj.get_route_target_refs() or []])
        # ensure no RT from LR is attached to VN
        self.assertTrue(vn_rt_refs_with_lr == vn_rt_refs,
                        msg='RT attached to VN is different after LR creation')

        # configure a new route target after
        # LR is created
        rtgt_list.add_route_target('target:1:2')
        lr.set_configured_route_target_list(rtgt_list)
        self._vnc_lib.logical_router_update(lr)
        lr = self._vnc_lib.logical_router_read(fq_name=lr.get_fq_name())
        lr_target = self.check_lr_target(lr.get_fq_name())
        ri_obj = self._vnc_lib.routing_instance_read(fq_name=ri_name)
        vn_rt_refs_with_lr = set([ref['to'][0]
            for ref in ri_obj.get_route_target_refs() or []])
        # ensure no RT from LR is attached to VN
        self.assertTrue(vn_rt_refs_with_lr == vn_rt_refs,
                        msg='RT attached to VN is different after LR creation')

        # check no service instance generated
        self.check_no_si_in_lr(lr.get_fq_name())

        # cleanup
        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)
    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])
Exemple #21
0
 def update_bgpvpn_mode(self, route_target=[]):
     self.bgpvpn_obj.set_route_target_list(RouteTargetList(route_target))
     self.vnc_lib.bgpvpn_update(bgpvpn)
Exemple #22
0
    def test_public_snat_routes(self):

        # create private vn
        vn_private_name = self.id() + 'vn1'
        vn_private = self.create_virtual_network(vn_private_name, "1.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(vn_private)
        self._vnc_lib.virtual_machine_interface_create(vmi)

        # create public vn
        vn_public_name = 'vn-public'
        vn_public = VirtualNetwork(vn_public_name)
        vn_public.set_router_external(True)
        ipam_obj = NetworkIpam('ipam')
        self._vnc_lib.network_ipam_create(ipam_obj)
        vn_public.add_network_ipam(
            ipam_obj,
            VnSubnetsType([IpamSubnetType(SubnetType("192.168.7.0", 24))]))
        self._vnc_lib.virtual_network_create(vn_public)

        # create logical router, set route targets,
        # add private network and extend lr to public network
        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)
        lr.add_virtual_network(vn_public)
        self._vnc_lib.logical_router_create(lr)

        @retries(5)
        def _match_route_table(rtgt_list, ri_name):
            lri = self._vnc_lib.routing_instance_read(fq_name_str=ri_name)
            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, "100.64.0.4")
            for rtgt in rtgt_list:
                self.assertIn(rtgt, route.route_target)

        @retries(5)
        def _wait_to_get_si():
            si_list = self._vnc_lib.service_instances_list()
            si = si_list.get("service-instances")[0]
            si = self._vnc_lib.service_instance_read(id=si.get("uuid"))
            return si

        @retries(5)
        def _wait_to_delete_si():
            si_list = self._vnc_lib.service_instances_list()
            try:
                si = si_list.get("service-instances")[0]
                si = self._vnc_lib.service_instance_read(id=si.get("uuid"))
                raise
            except Exception:
                pass

        @retries(5)
        def _wait_to_delete_ip(vn_fq_name):
            vn = self._vnc_lib.virtual_network_read(fq_name=vn_fq_name)
            ip_refs = vn.get_instance_ip_back_refs()
            if ip_refs:
                raise
            return

        # end

        si = _wait_to_get_si()
        si_props = si.get_service_instance_properties().get_interface_list()[1]
        ri_name = si_props.virtual_network + ":" + \
            si_props.virtual_network.split(':')[-1]
        lr_rtgt = self._vnc_lib.logical_router_read(
            id=lr.uuid).route_target_refs[0]['to'][0]
        _match_route_table(['target:1:1', lr_rtgt], ri_name)

        rtgt_list = RouteTargetList(route_target=['target:2:2'])
        lr.set_configured_route_target_list(rtgt_list)
        self._vnc_lib.logical_router_update(lr)
        _match_route_table(['target:2:2', lr_rtgt], ri_name)

        lr.del_virtual_network(vn_public)
        self._vnc_lib.logical_router_update(lr)
        _wait_to_delete_si()

        # cleanup
        self._vnc_lib.logical_router_delete(fq_name=lr.get_fq_name())
        self._vnc_lib.virtual_machine_interface_delete(
            fq_name=vmi.get_fq_name())
        _wait_to_delete_ip(vn_private.get_fq_name())
        self._vnc_lib.virtual_network_delete(fq_name=vn_private.get_fq_name())
        _wait_to_delete_ip(vn_public.get_fq_name())
        self._vnc_lib.virtual_network_delete(fq_name=vn_public.get_fq_name())
Exemple #23
0
 def update_rt(self, rt=[]):
     self.bgpvpn_obj.set_route_target_list(RouteTargetList(rt))
     self.vnc_lib_h.bgpvpn_update(self.bgpvpn_obj)
Exemple #24
0
    def test_logical_router_delete(self):
        # configure vxlan routing
        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)
        # 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)
        lr = self._vnc_lib.logical_router_read(id=lr.uuid)
        lr_target = self.check_lr_target(lr.get_fq_name())
        intvns = self.get_lr_internal_vn(lr.get_fq_name())

        # Deletion
        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)

        # internalVN should be restored when LR delete fails
        try:
            # override libs
            org_dbe_delete = self._server_info['api_server']._db_conn.dbe_delete
            def tmp_dbe_delete(obj_type, id, read_result):
                if obj_type == 'logical_router':
                    return False, (400, 'Fake LR delete failure')
                else:
                    return org_dbe_delete(obj_type, id, read_result)
            self._server_info['api_server']._db_conn.dbe_delete = tmp_dbe_delete

            try:
                self._vnc_lib.logical_router_delete(id=lr.uuid)
            except BadRequest as err:
                lr = self._vnc_lib.logical_router_read(id=lr.uuid)
                self.get_lr_internal_vn(lr.get_fq_name())
            else:
                raise Exception('UT: Fake LR delete didnt create BadRequest exception')
        finally:
            self._server_info['api_server']._db_conn.dbe_delete = org_dbe_delete

        # internalVN should be removed when LR is deleted successfully
        self._vnc_lib.logical_router_delete(id=lr.uuid)
        self.check_lr_is_deleted(uuid=lr.uuid)
        self.assertRaises(NoIdError, self._vnc_lib.virtual_network_read,
                          intvns[0]['uuid'])
        self.check_rt_is_deleted(name=lr_target)