def test_create_port_exc(self): vm_id = fake_vmware_api.Constants.VM_UUID vlan = model.Vlan(vlan_ids=["1001"]) network_config = model.NetworkConfig(vlan) network = model.Network(name="net-1234", network_type=p_const.TYPE_VLAN, config=network_config) net_id = "net" port = model.Port(name=None, mac_address=None, ipaddresses=None, vm_id=vm_id) virtual_nic = model.VirtualNic(mac_address=None, port_uuid=None, vm_id=vm_id, vm_name=None, nic_type=None, pg_id=None) with mock.patch.object(self.vc_driver, "is_valid_switch", return_value=None): exc = self.assertRaises(error.VcenterConfigurationError, self.vc_driver.create_port, network, net_id, port, virtual_nic) self.assertIn("Invalid Switch", str(exc))
def test_create_port_invalid_cluster(self): vm_id = fake_vmware_api.Constants.VM_UUID vlan = model.Vlan(vlan_ids=["1001"]) network_config = model.NetworkConfig(vlan) network = model.Network(name="net-1234", network_type=p_const.TYPE_VLAN, config=network_config) net_id = "net" port = model.Port(name=None, mac_address=None, ipaddresses=None, vm_id=vm_id) virtual_nic = model.VirtualNic(mac_address=None, port_uuid=None, vm_id=vm_id, vm_name=None, nic_type=None, pg_id=None) cluster_mor = fake_vmware_api.DataObject() cluster_mor.value = "invalid_id" cache.VCCache.add_cluster_mor_for_vm(vm_id, cluster_mor) exc = self.assertRaises(error.VcenterConfigurationError, self.vc_driver.create_port, network, net_id, port, virtual_nic) self.assertIn("Cluster for VM %s could not be determined" % vm_id, str(exc))
def test_post_create_port_nic_devices_none(self): try: vm_id = fake_vmware_api.Constants.VM_UUID network_uuid = fake_vmware_api.Constants.PORTGROUP_NAME port = model.Port(name=None, mac_address=None, ipaddresses=None, vm_id=vm_id, port_status=constants.PORT_STATUS_UP, network_uuid=network_uuid) updateSet = fake_vmware_api.DataObject() updateSet.version = 1 filterSet = [] updateSet.filterSet = filterSet propFilterUpdate = fake_vmware_api.DataObject() filterSet.append(propFilterUpdate) objectSet = [] propFilterUpdate.objectSet = objectSet objectUpdate = fake_vmware_api.DataObject() objectSet.append(objectUpdate) with mock.patch.object(vim_util, "wait_for_updates_ex", return_value=updateSet): self.vc_driver.post_create_port(port) except Exception: self.assertFalse(fake_vmware_api. is_task_done("ReconfigureDVPort_Task"))
def test_model_port(self): key = "1-2-3" name = "net1" mac_address = "ABC-DEFG-HIJK" ipaddresses = ["100.100.10.1"] vswitch_uuid = "uuid1" network_uuid = "uuid2" vm_id = "uuid3" port_config = None port_status = None port = model.Port(name, mac_address, ipaddresses, vswitch_uuid, vm_id, network_uuid, port_config, port_status, key) self.assertFalse(port.uuid is None, "Port uuid is none") self.assertEqual(port.key, key, "Port key does not match") self.assertEqual(port.name, name, "Port name does not match") self.assertEqual(len(port.ipaddresses), 1) self.assertEqual(port.ipaddresses[0], ipaddresses[0]) self.assertEqual(port.mac_address, mac_address, "Port mac_address does not match") self.assertEqual(port.vswitch_uuid, vswitch_uuid, "Port vswitch_uuid does not match") self.assertEqual(port.vm_id, vm_id, "Port vm_id does not match") self.assertEqual(port.network_uuid, network_uuid, "Port network_uuid does not match")
def test_model_network(self): key = "1-2-3" name = "net1" network_type = constants.NETWORK_VLAN vs_name = "dvs1" port_name = "port1" vlanIds = [1001] operation_mode = "mode1" vlan_type = "Native" vlan = model.Vlan(vlanIds, operation_mode, vlan_type) config = model.NetworkConfig(vlan) vs = model.VirtualSwitch(vs_name) port = model.Port(port_name, None, None, None, None) network = model.Network(name, network_type, config, [vs], [port], key) self.assertFalse(network.uuid is None, "Network uuid is none") self.assertEqual(network.key, key, "Network key does not match") self.assertEqual(network.name, name, "Network name does not match") self.assertEqual(network.network_type, network_type, "Network network_type does not match") self.assertTrue(network.config is not None) self.assertTrue(network.config.vlan is not None) self.assertEqual(network.config.vlan.operation_mode, operation_mode) self.assertEqual(network.config.vlan.vlan_type, vlan_type) self.assertEqual(len(network.config.vlan.vlanIds), 1) self.assertEqual(network.config.vlan.vlanIds[0], vlanIds[0]) self.assertEqual(len(network.vswitches), 1) self.assertEqual(network.vswitches[0].name, vs_name) self.assertEqual(len(network.ports), 1) self.assertEqual(network.ports[0].name, port_name)
def test_post_create_port_vm_deleted(self): vm_id = fake_vmware_api.Constants.VM_UUID network_uuid = fake_vmware_api.Constants.PORTGROUP_NAME port = model.Port(name=None, mac_address=None, ipaddresses=None, vm_id=vm_id, port_status=constants.PORT_STATUS_UP, network_uuid=network_uuid) updateSet = fake_vmware_api.DataObject() updateSet.version = 1 filterSet = [] updateSet.filterSet = filterSet propFilterUpdate = fake_vmware_api.DataObject() filterSet.append(propFilterUpdate) objectSet = [] propFilterUpdate.objectSet = objectSet objectUpdate = fake_vmware_api.DataObject() objectUpdate.kind = "leave" objectSet.append(objectUpdate) with mock.patch.object(vim_util, "wait_for_updates_ex", return_value=updateSet) as wait_update: self.vc_driver.post_create_port(port) self.assertTrue(wait_update.called)
def test_post_create_port(self): vm_id = fake_vmware_api.Constants.VM_UUID network_uuid = fake_vmware_api.Constants.PORTGROUP_NAME port = model.Port(name=None, mac_address=None, ipaddresses=None, vm_id=vm_id, port_status=constants.PORT_STATUS_UP, network_uuid=network_uuid) self.vc_driver.post_create_port(port) self.assertTrue(fake_vmware_api.is_task_done("ReconfigureDVPort_Task"))
def test_post_create_port_excp1(self): vm_id = fake_vmware_api.Constants.VM_UUID network_uuid = fake_vmware_api.Constants.PORTGROUP_NAME port = model.Port(name=None, mac_address=None, ipaddresses=None, vm_id=vm_id, port_status=constants.PORT_STATUS_UP, network_uuid=network_uuid) with mock.patch.object(network_util, "get_portgroup_mor_by_name", return_value=None): self.assertRaises(error_util.RunTimeError, self.vc_driver.post_create_port, port) self.assertFalse(fake_vmware_api.is_task_done( "ReconfigureDVPort_Task"))
def test_update_port_up(self): port_id = "PORT-1234-5678" vm_id = fake_vmware_api.Constants.VM_UUID mac_address = fake_vmware_api.Constants.VM_MAC vlan = model.Vlan(vlan_ids=["1001"]) network_config = model.NetworkConfig(vlan) network = model.Network(name="net-1234", network_type=p_const.TYPE_VLAN, config=network_config) port = model.Port(uuid=port_id, name=None, mac_address=mac_address, ipaddresses=None, vm_id=vm_id, port_status=constants.PORT_STATUS_UP) self.vc_driver.update_port(network, port, None) self.assertTrue(fake_vmware_api.is_task_done("ReconfigureDVPort_Task"))
def test_post_create_port_excp3(self): vm_id = fake_vmware_api.Constants.VM_UUID network_uuid = fake_vmware_api.Constants.PORTGROUP_NAME port = model.Port(name=None, mac_address=None, ipaddresses=None, vm_id=vm_id, port_status=constants.PORT_STATUS_UP, network_uuid=network_uuid) with mock.patch.object(dvs_driver.DvsNetworkDriver, "_register_vm_for_updates", side_effect=error_util.RunTimeError( "Exception in registering vm for updates")): self.assertRaises(error_util.RunTimeError, self.vc_driver.post_create_port, port) self.assertFalse( fake_vmware_api.is_task_done("ReconfigureDVPort_Task"))
def test_update_port_invalid_status(self): port_id = "PORT-1234-5678" vm_id = fake_vmware_api.Constants.VM_UUID mac_address = fake_vmware_api.Constants.VM_MAC vlan = model.Vlan(vlan_ids=["1001"]) network_config = model.NetworkConfig(vlan) network = model.Network(name="net-1234", network_type=p_const.TYPE_VLAN, config=network_config) port = model.Port(uuid=port_id, name=None, mac_address=mac_address, ipaddresses=None, vm_id=vm_id, port_status="Invalid") self.assertRaises(error.OVSvAppNeutronAgentError, self.vc_driver.update_port, network, port, None)
def test_create_port(self): vm_id = fake_vmware_api.Constants.VM_UUID vlan = model.Vlan(vlanIds=["1001"]) network_config = model.NetworkConfig(vlan) network = model.Network(name="net-1234", network_type=constants.NETWORK_VLAN, config=network_config) port = model.Port(name=None, mac_address=None, ipaddresses=None, vm_id=vm_id) virtual_nic = model.VirtualNic(mac_address=None, port_uuid=None, vm_id=vm_id, vm_name=None, nic_type=None) with mock.patch.object(model, "VirtualSwitch") as vswitch: self.vc_driver.create_port(network, port, virtual_nic) self.assertTrue(vswitch.called)
def test_post_create_port_excp2(self): vm_id = fake_vmware_api.Constants.VM_UUID network_uuid = fake_vmware_api.Constants.PORTGROUP_NAME port = model.Port(name=None, mac_address=None, ipaddresses=None, vm_id=vm_id, port_status=constants.PORT_STATUS_UP, network_uuid=network_uuid) with mock.patch.object(dvs_driver.DvsNetworkDriver, "_find_cluster_switch_for_vm", return_value=[None, None, "test_vds"]), \ mock.patch.object(network_util, "get_portgroup_mor_by_name", return_value="pg_mor"), \ mock.patch.object(resource_util, "get_vm_mor_for_uuid", return_value=None): self.assertRaises(error_util.RunTimeError, self.vc_driver.post_create_port, port) self.assertFalse( fake_vmware_api.is_task_done("ReconfigureDVPort_Task"))