def test_get_datastore_inaccessible_ds(self): data_store = fake.Datastore() data_store.set("summary.accessible", False) fake_objects = fake.FakeRetrieveResult() fake_objects.add_object(data_store) self.assertRaises(exception.DatastoreNotFound, ds_util.get_datastore, fake.FakeObjectRetrievalSession(fake_objects))
def test_get_datastore(self): fake_objects = fake.FakeRetrieveResult() fake_objects.add_object(fake.Datastore()) result = ds_util.get_datastore( fake.FakeObjectRetrievalSession(fake_objects)) self.assertEqual("fake-ds", result.name) self.assertEqual(units.Ti, result.capacity) self.assertEqual(500 * units.Gi, result.freespace)
def test_get_datastore_ds_in_maintenance(self): data_store = fake.Datastore() data_store.set("summary.maintenanceMode", "inMaintenance") fake_objects = fake.FakeRetrieveResult() fake_objects.add_object(data_store) self.assertRaises(exception.DatastoreNotFound, ds_util.get_datastore, fake.FakeObjectRetrievalSession(fake_objects))
def test_get_datastore_with_list(self): # Test with a regex containing whitelist of datastores datastore_valid_regex = re.compile("(openstack-ds0|openstack-ds2)") fake_objects = fake.FakeRetrieveResult() fake_objects.add_object(fake.Datastore("openstack-ds0")) fake_objects.add_object(fake.Datastore("openstack-ds1")) fake_objects.add_object(fake.Datastore("openstack-ds2")) result = ds_util.get_datastore( fake.FakeObjectRetrievalSession(fake_objects), None, None, datastore_valid_regex) self.assertNotEqual("openstack-ds1", result.name)
def test_get_datastore_with_regex(self): # Test with a regex that matches with a datastore datastore_valid_regex = re.compile("^openstack.*\d$") fake_objects = fake.FakeRetrieveResult() fake_objects.add_object(fake.Datastore("openstack-ds0")) fake_objects.add_object(fake.Datastore("fake-ds0")) fake_objects.add_object(fake.Datastore("fake-ds1")) result = ds_util.get_datastore( fake.FakeObjectRetrievalSession(fake_objects), None, None, datastore_valid_regex) self.assertEqual("openstack-ds0", result.name)
def test_get_datastore_with_token(self): regex = re.compile("^ds.*\d$") fake0 = fake.FakeRetrieveResult() fake0.add_object(fake.Datastore("ds0", 10 * units.Gi, 5 * units.Gi)) fake0.add_object(fake.Datastore("foo", 10 * units.Gi, 9 * units.Gi)) setattr(fake0, 'token', 'token-0') fake1 = fake.FakeRetrieveResult() fake1.add_object(fake.Datastore("ds2", 10 * units.Gi, 8 * units.Gi)) fake1.add_object(fake.Datastore("ds3", 10 * units.Gi, 1 * units.Gi)) result = ds_util.get_datastore( fake.FakeObjectRetrievalSession(fake0, fake1), None, None, regex) self.assertEqual("ds2", result.name)
def test_get_values(self): objects = self._create_fake_vm_objects() lst_properties = [ 'runtime.powerState', 'summary.guest.toolsStatus', 'summary.guest.toolsRunningStatus' ] query = vm_util.get_values_from_object_properties( fake.FakeObjectRetrievalSession(objects), objects, lst_properties) self.assertEqual('poweredOn', query['runtime.powerState']) self.assertEqual('guestToolsRunning', query['summary.guest.toolsRunningStatus']) self.assertEqual('toolsOk', query['summary.guest.toolsStatus'])
def test_get_datastore(self): fake_objects = fake.FakeRetrieveResult() fake_objects.add_object(fake.Datastore()) fake_objects.add_object( fake.Datastore("fake-ds-2", 2048, 1000, False, "normal")) fake_objects.add_object( fake.Datastore("fake-ds-3", 4096, 2000, True, "inMaintenance")) result = ds_util.get_datastore( fake.FakeObjectRetrievalSession(fake_objects)) self.assertEqual("fake-ds", result.name) self.assertEqual(units.Ti, result.capacity) self.assertEqual(500 * units.Gi, result.freespace)
def test_get_host_ref_from_id(self): fake_host_name = "ha-host" fake_host_sys = fake.HostSystem(fake_host_name) fake_host_id = fake_host_sys.obj.value fake_objects = fake.FakeRetrieveResult() fake_objects.add_object(fake_host_sys) ref = vm_util.get_host_ref_from_id( fake.FakeObjectRetrievalSession(fake_objects), fake_host_id, ['name']) self.assertIsInstance(ref, fake.HostSystem) self.assertEqual(fake_host_id, ref.obj.value) host_name = vm_util.get_host_name_from_host_ref(ref) self.assertEqual(fake_host_name, host_name)
def test_get_datastore_with_regex_error(self): # Test with a regex that has no match # Checks if code raises DatastoreNotFound with a specific message datastore_invalid_regex = re.compile("unknown-ds") exp_message = (_("Datastore regex %s did not match any datastores") % datastore_invalid_regex.pattern) fake_objects = fake.FakeRetrieveResult() fake_objects.add_object(fake.Datastore("fake-ds0")) fake_objects.add_object(fake.Datastore("fake-ds1")) # assertRaisesRegExp would have been a good choice instead of # try/catch block, but it's available only from Py 2.7. try: ds_util.get_datastore( fake.FakeObjectRetrievalSession(fake_objects), None, None, datastore_invalid_regex) except exception.DatastoreNotFound as e: self.assertEqual(exp_message, e.args[0]) else: self.fail("DatastoreNotFound Exception was not raised with " "message: %s" % exp_message)
def test_get_datastore_no_host_in_cluster(self): self.assertRaises(exception.DatastoreNotFound, ds_util.get_datastore, fake.FakeObjectRetrievalSession(""), 'fake_cluster')
def test_get_datastore_without_datastore(self): self.assertRaises(exception.DatastoreNotFound, ds_util.get_datastore, fake.FakeObjectRetrievalSession(None), cluster="fake-cluster")
def test_get_all_cluster_refs_by_name_missing(self): fake_objects = fake.FakeRetrieveResult() fake_objects.add_object(partialObject(path='cluster')) refs = vm_util.get_all_cluster_refs_by_name( fake.FakeObjectRetrievalSession(fake_objects), ['cluster']) self.assertTrue(not refs)
def test_get_all_cluster_refs_by_name_exists(self): fake_objects = fake.FakeRetrieveResult() fake_objects.add_object(fake.ClusterComputeResource(name='cluster')) refs = vm_util.get_all_cluster_refs_by_name( fake.FakeObjectRetrievalSession(fake_objects), ['cluster']) self.assertEqual(1, len(refs))
def test_get_all_cluster_refs_by_name_none(self): fake_objects = fake.FakeRetrieveResult() refs = vm_util.get_all_cluster_refs_by_name( fake.FakeObjectRetrievalSession(fake_objects), ['fake_cluster']) self.assertTrue(not refs)
def test_get_host_ref_no_hosts_in_cluster(self): self.assertRaises(exception.NoValidHost, vm_util.get_host_ref, fake.FakeObjectRetrievalSession(""), 'fake_cluster')