def test_delete_vpg_no_id(vnc_api_client, vnc_lib): vnc_lib.virtual_port_group_delete.side_effect = vnc_api.NoIdError( "vpg-uuid") vnc_api_client.delete_vpg("vpg-uuid") vnc_lib.virtual_port_group_delete.assert_called_once_with(id="vpg-uuid")
def test_update_vpg(vnc_api_client, vnc_lib, vpg_1): vnc_lib.virtual_port_group_update.side_effect = vnc_api.NoIdError( "vpg-uuid") vpg_1 = mock.Mock() vnc_api_client.update_vpg(vpg_1) vnc_lib.virtual_port_group_update.assert_called_once_with(vpg_1)
def test_update_virtual_port_group_no_raise_on_noiderror(self, cfg): vpg = mock.Mock() self.vnc_api.virtual_port_group_update = mock.Mock( side_effect=vnc_api.NoIdError("id")) self.driver.update_virtual_port_group(vpg) self.vnc_api.virtual_port_group_update.assert_called_with(vpg)
def test_delete_vn_no_id(vnc_api_client, vnc_lib, vn, vmi_1): vnc_lib.virtual_network_read.return_value = vn vnc_lib.virtual_machine_interface_read.return_value = vmi_1 vnc_lib.virtual_network_delete.side_effect = vnc_api.NoIdError(vn.uuid) vnc_api_client.delete_vn(vn.uuid) vnc_lib.virtual_network_delete.assert_called_once_with(id=vn.uuid)
def test_delete_virtual_machine_interface_no_raise_on_noiderror(self, cfg): self.vnc_api.virtual_machine_interface_delete = mock.Mock( side_effect=vnc_api.NoIdError("id")) self.driver.delete_virtual_machine_interface(["name-1"]) self.vnc_api.virtual_machine_interface_delete.assert_called_with( fq_name=["name-1"])
def test_read_pi(vnc_api_client, vnc_lib): pi = mock.Mock() vnc_lib.physical_interface_read.side_effect = [ pi, vnc_api.NoIdError("pi-uuid"), ] assert vnc_api_client.read_pi("pi-uuid") == pi assert vnc_api_client.read_pi("pi-uuid") is None
def test_delete_vmi(vnc_api_client, vnc_lib): vnc_lib.virtual_machine_interface_delete.side_effect = vnc_api.NoIdError( "vmi-uuid") with mock.patch.object(vnc_api_client, "detach_vmi_from_vpg"): vnc_api_client.delete_vmi("vmi-uuid") vnc_lib.virtual_machine_interface_delete.assert_called_once_with( id="vmi-uuid")
def test_read_fabric_name_from_switch_return_none_when_no_pr(self, cfg): self.vnc_api.physical_router_read = mock.Mock( side_effect=vnc_api.NoIdError("id-1")) fabric_name = self.driver.read_fabric_name_from_switch("switch-1") self.vnc_api.physical_router_read.assert_called_with( fq_name=["default-global-system-config", "switch-1"], id=None) self.assertIsNone(fabric_name)
def test_get_objects_from_vnc_api_when_obj_not_exists( self, object_name, cfg): get_func = "get_%s" % object_name vnc_get_func_name = "%s_read" % object_name vnc_read = mock.Mock(side_effect=vnc_api.NoIdError("id")) self.vnc_api.configure_mock(**{vnc_get_func_name: vnc_read}) obj = getattr(self.driver, get_func)(uuid="uuid-1", fq_name=["name-1"]) self.assertIsNone(obj) vnc_read.assert_called_with(id="uuid-1", fq_name=["name-1"])
def test_read_all_prs(vnc_api_client, vnc_lib): pr = mock.Mock() pr_refs = { "physical-routers": [{"uuid": "pr-1-uuid"}, {"uuid": "pr-2-uuid"}] } vnc_lib.physical_routers_list.return_value = pr_refs vnc_lib.physical_router_read.side_effect = [ pr, vnc_api.NoIdError("pr-2-uuid"), ] prs = vnc_api_client.read_all_physical_routers() assert prs == [pr]
def test_read_nodes_by_host_names(vnc_api_client, vnc_lib): node_1 = vnc_api.Node(name="esxi-1") node_2 = vnc_api.Node(name="esxi-2") node_3 = vnc_api.Node(name="esxi-3") vnc_lib.nodes_list.return_value = { "nodes": [ {"uuid": "node-1-uuid"}, {"uuid": "node-2-uuid"}, {"uuid": "node-3-uuid"}, {"uuid": "node-4-uuid"}, ] } vnc_lib.node_read.side_effect = [ node_1, node_2, node_3, vnc_api.NoIdError("node-4-uuid"), ] result = vnc_api_client.get_nodes_by_host_names(["esxi-1", "esxi-2"]) assert len(result) == 2 assert node_1 in result assert node_2 in result
def test_get_project_no_id(vnc_api_client, vnc_lib): vnc_lib.project_read.side_effect = vnc_api.NoIdError("project-uuid") with pytest.raises(exceptions.VNCAdminProjectNotFound): vnc_api_client.get_project()