def test_virtual_port_group_delete(self): proj_obj = Project('%s-project' % (self.id())) self.api.project_create(proj_obj) vn = VirtualNetwork('vn-%s' % (self.id()), parent_obj=proj_obj) self.api.virtual_network_create(vn) vpg_name = "vpg-" + self.id() vpg_obj = VirtualPortGroup(vpg_name) self.api.virtual_port_group_create(vpg_obj) vmi_id_list = [] for i in range(self.VMI_NUM): vmi_obj = VirtualMachineInterface(self.id() + str(i), parent_obj=proj_obj) vmi_obj.set_virtual_network(vn) vmi_id_list.append( self.api.virtual_machine_interface_create(vmi_obj)) vpg_obj.add_virtual_machine_interface(vmi_obj) self.api.virtual_port_group_update(vpg_obj) self.api.ref_relax_for_delete(vpg_obj.uuid, vmi_id_list[i]) # Make sure when VPG doesn't get deleted, since associated VMIs # still refers it. with ExpectedException(BadRequest): self.api.virtual_port_group_delete(id=vpg_obj.uuid) # Cleanup for i in range(self.VMI_NUM): self.api.virtual_machine_interface_delete(id=vmi_id_list[i]) self.api.virtual_port_group_delete(id=vpg_obj.uuid)
def _create_vpg(self, name, fabric, pi_obj, vlan_id, vport_vmi, vmi_profile): vpg_obj = VirtualPortGroup(name, parent_obj=fabric) vpg_obj.name = name vpg_obj.set_display_name(name) uuid = self._vnc_lib.virtual_port_group_create(vpg_obj) vpg_obj_rd = self._vnc_lib.virtual_port_group_read(id=uuid) vpg_obj.add_physical_interface(pi_obj) vpg_obj.add_virtual_machine_interface(vport_vmi) self._vnc_lib.virtual_port_group_update(vpg_obj) # update vmi vmi_bindings = { "key_value_pair": [{ "key": "vpg", "value": name }, { "key": "vnic_type", "value": "baremetal" }, { "key": "vif_type", "value": "vrouter" }, { "key": "profile", "value": vmi_profile }, { "key": "tor_port_vlan_id", "value": str(vlan_id) }] } vport_vmi.set_virtual_machine_interface_bindings(vmi_bindings) vmi_properties = {"sub_interface_vlan_tag": str(vlan_id)} vport_vmi.set_virtual_machine_interface_properties(vmi_properties) self._vnc_lib.virtual_machine_interface_update(vport_vmi) return vpg_obj, vpg_obj_rd