Пример #1
0
def _get_ds_capacity_and_freespace(session,
                                   cluster=None,
                                   datastore_regex=None):
    try:
        ds = ds_util.get_datastore(session, cluster, datastore_regex)
        return ds.capacity, ds.freespace
    except exception.DatastoreNotFound:
        return 0, 0
Пример #2
0
def _get_ds_capacity_and_freespace(session, cluster=None,
                                   datastore_regex=None):
    try:
        ds = ds_util.get_datastore(session, cluster,
                                   datastore_regex)
        return ds.capacity, ds.freespace
    except exception.DatastoreNotFound:
        return 0, 0
Пример #3
0
 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:
         with self._mock_get_datastore_calls(fake_objects):
             ds_util.get_datastore(self.session, 'fake-cluster',
                                   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)
Пример #4
0
 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:
         with self._mock_get_datastore_calls(fake_objects):
             ds_util.get_datastore(self.session, 'fake-cluster',
                                   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)
Пример #5
0
    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"))

        with self._mock_get_datastore_calls(fake_objects):
            result = ds_util.get_datastore(self.session, 'fake-cluster',
                                           datastore_valid_regex)
        self.assertNotEqual("openstack-ds1", result.name)
Пример #6
0
    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"))

        with self._mock_get_datastore_calls(fake_objects):
            result = ds_util.get_datastore(self.session, 'fake-cluster',
                                           datastore_valid_regex)
        self.assertEqual("openstack-ds0", result.name)
Пример #7
0
    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"))

        with self._mock_get_datastore_calls(fake_objects):
            result = ds_util.get_datastore(self.session, 'fake-cluster',
                                           datastore_valid_regex)
        self.assertNotEqual("openstack-ds1", result.name)
Пример #8
0
    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"))

        with self._mock_get_datastore_calls(fake_objects):
            result = ds_util.get_datastore(self.session, 'fake-cluster',
                                           datastore_valid_regex)
        self.assertEqual("openstack-ds0", result.name)
Пример #9
0
    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))

        with self._mock_get_datastore_calls(fake0, fake1):
            result = ds_util.get_datastore(self.session, 'fake-cluster', regex)
        self.assertEqual("ds2", result.name)
Пример #10
0
    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"))

        with self._mock_get_datastore_calls(fake_objects):
            result = ds_util.get_datastore(self.session, 'fake-cluster')
        self.assertEqual("fake-ds", result.name)
        self.assertEqual(units.Ti, result.capacity)
        self.assertEqual(500 * units.Gi, result.freespace)
Пример #11
0
    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))

        with self._mock_get_datastore_calls(fake0, fake1):
            result = ds_util.get_datastore(self.session, 'fake-cluster', regex)
        self.assertEqual("ds2", result.name)
Пример #12
0
    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"))

        with self._mock_get_datastore_calls(fake_objects):
            result = ds_util.get_datastore(self.session, 'fake-cluster')
        self.assertEqual("fake-ds", result.name)
        self.assertEqual(units.Ti, result.capacity)
        self.assertEqual(500 * units.Gi, result.freespace)