Esempio n. 1
0
    def test_same_network_not_attached_to_lr(self):
        project = self._vnc_lib.project_read(
            ['default-domain', 'default-project'])
        ipam = self._vnc_lib.network_ipam_read(
            ['default-domain', 'default-project', 'default-network-ipam'])

        # Create subnets
        ipam_sn_v4_vn = IpamSubnetType(subnet=SubnetType('11.1.1.0', 24))

        # Create VN my-vn
        vn = VirtualNetwork('%s-vn' % self.id(), project)
        vn.add_network_ipam(ipam, VnSubnetsType([ipam_sn_v4_vn]))
        self._vnc_lib.virtual_network_create(vn)
        net_obj = self._vnc_lib.virtual_network_read(id=vn.uuid)

        # Create v4 Ip object
        ip_obj = InstanceIp(name=str(uuid.uuid4()), instance_ip_family='v4')
        ip_obj.uuid = ip_obj.name

        # Create Port
        port_obj = self.create_port(project, net_obj)

        # Create Logical Router
        lr = LogicalRouter('router-test-v4-%s' % self.id(), project)
        lr.set_logical_router_type('snat-routing')
        self._vnc_lib.logical_router_create(lr)

        # Add Router Interface
        lr.add_virtual_machine_interface(port_obj)
        self._vnc_lib.logical_router_update(lr)

        # set router_external
        net_obj.set_router_external(True)
        self._vnc_lib.virtual_network_update(net_obj)

        with ExpectedException(BadRequest):
            lr.add_virtual_network(net_obj)
            self._vnc_lib.logical_router_update(lr)
        lr.del_virtual_network(net_obj)

        lr.del_virtual_machine_interface(port_obj)
        self._vnc_lib.logical_router_update(lr)
        lr.add_virtual_network(net_obj)
        self._vnc_lib.logical_router_update(lr)

        # Create Port
        port_obj = self.create_port(project, net_obj)
        with ExpectedException(BadRequest):
            lr.add_virtual_machine_interface(port_obj)
            self._vnc_lib.logical_router_update(lr)
        self._vnc_lib.logical_router_delete(id=lr.uuid)
    def test_vxlan_routing_for_internal_vn(self):
        project = self._vnc_lib.project_read(
            fq_name=['default-domain', 'default-project'])
        project.set_vxlan_routing(True)
        self._vnc_lib.project_update(project)

        # Create Logical Router
        lr = LogicalRouter('router-test-v4-%s' % self.id(), project)
        lr_uuid = self._vnc_lib.logical_router_create(lr)
        lr = self._vnc_lib.logical_router_read(id=lr_uuid)

        # Check to see whether internal VN for VxLAN Routing is created.
        int_vn_name = get_lr_internal_vn_name(lr_uuid)
        int_vn_fqname = ['default-domain', 'default-project', int_vn_name]
        try:
            self._vnc_lib.virtual_network_read(fq_name=int_vn_fqname)
        except NoIdError as e:
            # Invisible objects do not come up in read
            # calls but throws up a exception saying the
            # object is invisible but cannot be read, confirming
            # the presence of the object. Hack!
            if "This object is not visible" not in str(e):
                assert (False)

        # Check to see if we are not able to attach Ext Gateway when
        # VxLAN Routing is enabled.
        ext_vn = VirtualNetwork(name=self.id() + '_ext_lr')
        ext_vn_uuid = self._vnc_lib.virtual_network_create(ext_vn)
        ext_vn = self._vnc_lib.virtual_network_read(id=ext_vn_uuid)
        lr.add_virtual_network(ext_vn)
        try:
            self._vnc_lib.logical_router_update(lr)
            self.fail("API allow to add an external gateway to the logical "
                      "router while the VxLAN routing is enabled")
        except BadRequest:
            pass

        # Check to see if we are not able to disable VxLAN routing in the
        # project when there is one LR in the project.
        project.set_vxlan_routing(False)
        try:
            self._vnc_lib.project_update(project)
            self.fail("API allows to disable VxLAN routhing while there is a "
                      "logical router in the project")
        except BadRequest:
            pass

        # Check to see if deleting the VN deletes the internal VN
        # that was created.
        self._vnc_lib.logical_router_delete(id=lr_uuid)
        try:
            self._vnc_lib.virtual_network_read(fq_name=int_vn_fqname)
            self.fail("Logical router internal virtual network was not "
                      "removed")
        except NoIdError:
            pass

        # Check to see if we are able to disable VxLAN Routing
        # after LR is deleted in the project.
        project.set_vxlan_routing(False)
        self._vnc_lib.project_update(project)