Ejemplo n.º 1
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)
Ejemplo n.º 2
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)
Ejemplo n.º 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))

        with self._mock_get_datastore_calls(fake0, fake1):
            result = ds_util.get_datastore(self.session, 'fake-cluster', regex)
        self.assertEqual("ds2", result.name)
Ejemplo n.º 4
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)
Ejemplo n.º 5
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')
Ejemplo n.º 6
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')
Ejemplo n.º 7
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)
Ejemplo n.º 8
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)
Ejemplo n.º 9
0
    def test_get_host_stats_vc(self):
        """Check retrieval of host stats from VC"""
        res_types = [
            resource_types.MEMORY, resource_types.CPU,
            resource_types.DISK_USED, resource_types.DISK_TOTAL
        ]

        respool = fake.ResourcePool()
        fake._create_object('ResourcePool', respool)
        datastore = fake.Datastore("ds-1", 1024, 500)
        fake._create_object('Datastore', datastore)
        host = fake.HostSystem()
        fake._create_object('HostSystem', host)
        cluster = fake.ClusterComputeResource()
        fake._create_object('ClusterComputeResource', cluster)
        cluster._add_host(host.obj)
        cluster._add_datastore(datastore.obj)

        fake_pools = fake.FakeRetrieveResult()
        fake_pools.add_object(respool)
        fake_hosts = fake.FakeRetrieveResult()
        fake_hosts.add_object(host)
        fake_ds = fake.FakeRetrieveResult()
        fake_ds.add_object(datastore)
        fake_cluster = fake.FakeRetrieveResult()
        fake_cluster.add_object(cluster)

        session = fake_session(fake_resource_pools=fake_pools,
                               fake_host_system=fake_hosts,
                               fake_datastore=fake_ds,
                               fake_cluster=fake_cluster)
        driver = fake_driver(session, cluster_ref=cluster.obj)
        pf9_stats = vm_utils_pf9.get_host_stats_vc(driver, res_types,
                                                   'test_cluster')
        self.assertEquals(10.0, pf9_stats['cpu_util_percent'])
        self.assertEquals(48.828125, pf9_stats['mem_util_percent'])
        self.assertEquals(1024.0, pf9_stats['disk_total_gb'])
        self.assertEquals(524.0, pf9_stats['disk_used_gb'])