def test_vm_port_not_added_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 VM vm_inst_obj = VirtualMachine(str(uuid.uuid4())) vm_inst_obj.uuid = vm_inst_obj.name self._vnc_lib.virtual_machine_create(vm_inst_obj) id_perms = IdPermsType(enable=True) vm_port_obj = VirtualMachineInterface(str(uuid.uuid4()), vm_inst_obj, id_perms=id_perms) vm_port_obj.uuid = vm_port_obj.name vm_port_obj.set_virtual_network(vn) ip_obj.set_virtual_machine_interface(vm_port_obj) ip_obj.set_virtual_network(net_obj) self._vnc_lib.virtual_machine_interface_create(vm_port_obj) self._vnc_lib.instance_ip_create(ip_obj) # Create Logical Router lr = LogicalRouter('router-test-v4-%s' % self.id(), project) self._vnc_lib.logical_router_create(lr) # Add Router Interface lr.add_virtual_machine_interface(vm_port_obj) with ExpectedException(RefsExistError): self._vnc_lib.logical_router_update(lr) lr.del_virtual_machine_interface(vm_port_obj) # Create Port port_obj = self.create_port(project, net_obj) lr.add_virtual_machine_interface(port_obj) self._vnc_lib.logical_router_update(lr) with ExpectedException(BadRequest): port_obj.add_virtual_machine(vm_inst_obj) self._vnc_lib.virtual_machine_interface_update(port_obj) self._vnc_lib.logical_router_delete(id=lr.uuid)
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)