Beispiel #1
0
 def test_ds(self):
     ds = datastore.Datastore("fake_ref", "ds_name", 2 * units.Gi,
                              1 * units.Gi)
     self.assertEqual('ds_name', ds.name)
     self.assertEqual('fake_ref', ds.ref)
     self.assertEqual(2 * units.Gi, ds.capacity)
     self.assertEqual(1 * units.Gi, ds.freespace)
Beispiel #2
0
 def test_build_url(self):
     ds = datastore.Datastore("fake_ref", "ds_name")
     path = 'images/ubuntu.vmdk'
     self.assertRaises(ValueError, ds.build_url, 'https', '10.0.0.2', path)
     ds.datacenter = mock.Mock()
     ds.datacenter.name = "dc_path"
     ds_url = ds.build_url('https', '10.0.0.2', path)
     self.assertEqual(ds_url.datastore_name, "ds_name")
     self.assertEqual(ds_url.datacenter_path, "dc_path")
     self.assertEqual(ds_url.path, path)
Beispiel #3
0
 def test_get_summary(self):
     ds_ref = vim_util.get_moref('ds-0', 'Datastore')
     ds = datastore.Datastore(ds_ref, 'ds-name')
     summary = mock.sentinel.summary
     session = mock.Mock()
     session.invoke_api = mock.Mock()
     session.invoke_api.return_value = summary
     ret = ds.get_summary(session)
     self.assertEqual(summary, ret)
     session.invoke_api.assert_called_once_with(new_vim_util,
                                                'get_object_property',
                                                session.vim, ds.ref,
                                                'summary')
Beispiel #4
0
    def test_get_connected_hosts(self):
        session = mock.Mock()
        ds_ref = vim_util.get_moref('ds-0', 'Datastore')
        ds = datastore.Datastore(ds_ref, 'ds-name')
        ds.get_summary = mock.Mock()
        ds.get_summary.return_value.accessible = False
        self.assertEqual([], ds.get_connected_hosts(session))
        ds.get_summary.return_value.accessible = True
        m1 = HostMount("m1", MountInfo('readWrite', True, True))
        m2 = HostMount("m2", MountInfo('read', True, True))
        m3 = HostMount("m3", MountInfo('readWrite', False, True))
        m4 = HostMount("m4", MountInfo('readWrite', True, False))
        ds.get_summary.assert_called_once_with(session)

        class Prop(object):
            DatastoreHostMount = [m1, m2, m3, m4]

        session.invoke_api = mock.Mock()
        session.invoke_api.return_value = Prop()
        hosts = ds.get_connected_hosts(session)
        self.assertEqual(1, len(hosts))
        self.assertEqual("m1", hosts.pop())
Beispiel #5
0
 def test_build_path(self):
     ds = datastore.Datastore("fake_ref", "ds_name")
     ds_path = ds.build_path("some_dir", "foo.vmdk")
     self.assertEqual('[ds_name] some_dir/foo.vmdk', str(ds_path))
Beispiel #6
0
 def test_ds_no_capacity_no_freespace(self):
     ds = datastore.Datastore("fake_ref", "ds_name")
     self.assertIsNone(ds.capacity)
     self.assertIsNone(ds.freespace)