def test_get_valid_vms_from_retrieve_result(self): ops = vmops.VMwareVMOps(mock.Mock(), mock.Mock(), mock.Mock()) fake_objects = vmwareapi_fake.FakeRetrieveResult() fake_objects.add_object(vmwareapi_fake.VirtualMachine()) fake_objects.add_object(vmwareapi_fake.VirtualMachine()) fake_objects.add_object(vmwareapi_fake.VirtualMachine()) vms = ops._get_valid_vms_from_retrieve_result(fake_objects) self.assertEqual(3, len(vms))
def test_get_valid_vms_from_retrieve_result_with_invalid(self): ops = vmops.VMwareVMOps(mock.Mock(), mock.Mock(), mock.Mock()) fake_objects = vmwareapi_fake.FakeRetrieveResult() fake_objects.add_object(vmwareapi_fake.VirtualMachine()) invalid_vm1 = vmwareapi_fake.VirtualMachine() invalid_vm1.set('runtime.connectionState', 'orphaned') invalid_vm2 = vmwareapi_fake.VirtualMachine() invalid_vm2.set('runtime.connectionState', 'inaccessible') fake_objects.add_object(invalid_vm1) fake_objects.add_object(invalid_vm2) vms = ops._get_valid_vms_from_retrieve_result(fake_objects) self.assertEqual(1, len(vms))
def test_get_host_name_for_vm(self, _get_ref_from_uuid): fake_host = fake.HostSystem() fake_host_id = fake_host.obj.value fake_vm = fake.VirtualMachine(name='vm-123', runtime_host=fake_host.obj) fake_objects = fake.FakeRetrieveResult() fake_objects.add_object(fake_vm) vm_ref = vm_util.get_vm_ref_from_name( fake.FakeObjectRetrievalSession(fake_objects), 'vm-123') self.assertIsNotNone(vm_ref) host_id = vm_util.get_host_id_from_vm_ref( fake.FakeObjectRetrievalSession(fake_objects), vm_ref) self.assertEqual(fake_host_id, host_id)
def _create_fake_vm_objects(self): fake_objects = fake.FakeRetrieveResult() fake_objects.add_object(fake.VirtualMachine()) return fake_objects