示例#1
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"))
     result = ds_util.get_datastore(
         fake.FakeObjectRetrievalSession(fake_objects), None, None,
         datastore_valid_regex)
     self.assertEqual("openstack-ds0", result.name)
示例#2
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"))
     result = ds_util.get_datastore(
         fake.FakeObjectRetrievalSession(fake_objects), None, None,
         datastore_valid_regex)
     self.assertNotEqual("openstack-ds1", result.name)
示例#3
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))
     result = ds_util.get_datastore(
         fake.FakeObjectRetrievalSession(fake0, fake1), None, None, regex)
     self.assertEqual("ds2", result.name)
示例#4
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)
示例#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_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)
示例#7
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)
示例#8
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"))
        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)
示例#9
0
    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))
示例#10
0
    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)
示例#11
0
    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))
示例#12
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:
         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)
示例#13
0
    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)

        with self._mock_get_datastore_calls(fake_objects):
            self.assertRaises(exception.DatastoreNotFound,
                              ds_util.get_datastore, self.session,
                              'fake-cluster')
示例#14
0
    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)

        with self._mock_get_datastore_calls(fake_objects):
            self.assertRaises(exception.DatastoreNotFound,
                              ds_util.get_datastore, self.session,
                              'fake-cluster')
示例#15
0
    def test_get_cdrom_attach_config_spec(self):

        result = vm_util.get_cdrom_attach_config_spec(fake.FakeFactory(),
                                             fake.Datastore(),
                                             "/tmp/foo.iso",
                                             200, 0)
        expected = """{
    'deviceChange': [
        {
            'device': {
                'connectable': {
                    'allowGuestControl': False,
                    'startConnected': True,
                    'connected': True,
                    'obj_name': 'ns0: VirtualDeviceConnectInfo'
                },
                'backing': {
                    'datastore': {
                        "summary.maintenanceMode": "normal",
                        "summary.type": "VMFS",
                        "summary.accessible":true,
                        "summary.name": "fake-ds",
                        "summary.capacity": 1099511627776,
                        "summary.freeSpace": 536870912000,
                        "browser": ""
                    },
                    'fileName': '/tmp/foo.iso',
                    'obj_name': 'ns0: VirtualCdromIsoBackingInfo'
                },
                'controllerKey': 200,
                'unitNumber': 0,
                'key': -1,
                'obj_name': 'ns0: VirtualCdrom'
            },
            'operation': 'add',
            'obj_name': 'ns0: VirtualDeviceConfigSpec'
        }
    ],
    'obj_name': 'ns0: VirtualMachineConfigSpec'
}
"""

        expected = re.sub(r'\s+', '', expected)
        result = re.sub(r'\s+', '', repr(result))
        self.assertEqual(expected, result)