def test_create_session(self):
"""Test create_session."""
- m = mox.Mox()
+ m = self.mox
m.StubOutWithMock(api.VMwareAPISession, 'vim')
self._session.vim = self._vim
m.ReplayAll()
def test_do_setup(self):
"""Test do_setup."""
- m = mox.Mox()
+ m = self.mox
m.StubOutWithMock(self._driver.__class__, 'session')
self._driver.session = self._session
m.ReplayAll()
def test_success_wait_for_task(self):
"""Test successful wait_for_task."""
- m = mox.Mox()
+ m = self.mox
m.StubOutWithMock(api.VMwareAPISession, 'vim')
self._session.vim = self._vim
result = FakeMor('VirtualMachine', 'my_vm')
def test_failed_wait_for_task(self):
"""Test failed wait_for_task."""
- m = mox.Mox()
+ m = self.mox
m.StubOutWithMock(api.VMwareAPISession, 'vim')
self._session.vim = self._vim
failed_task_info = FakeTaskInfo('failed')
def test_get_backing(self):
"""Test get_backing."""
- m = mox.Mox()
+ m = self.mox
m.StubOutWithMock(api.VMwareAPISession, 'vim')
self._session.vim = self._vim
m.StubOutWithMock(self._session, 'invoke_api')
def test_delete_backing(self):
"""Test delete_backing."""
- m = mox.Mox()
+ m = self.mox
m.StubOutWithMock(api.VMwareAPISession, 'vim')
self._session.vim = self._vim
m.StubOutWithMock(self._session, 'invoke_api')
def test_delete_volume_without_backing(self):
"""Test delete_volume without backing."""
- m = mox.Mox()
+ m = self.mox
m.StubOutWithMock(self._driver.__class__, 'volumeops')
self._driver.volumeops = self._volumeops
m.StubOutWithMock(self._volumeops, 'get_backing')
def test_delete_volume_with_backing(self):
"""Test delete_volume with backing."""
- m = mox.Mox()
+ m = self.mox
m.StubOutWithMock(self._driver.__class__, 'volumeops')
self._driver.volumeops = self._volumeops
def test_get_host(self):
"""Test get_host."""
- m = mox.Mox()
+ m = self.mox
m.StubOutWithMock(api.VMwareAPISession, 'vim')
self._session.vim = self._vim
m.StubOutWithMock(self._session, 'invoke_api')
def test_get_hosts(self):
"""Test get_hosts."""
- m = mox.Mox()
+ m = self.mox
m.StubOutWithMock(api.VMwareAPISession, 'vim')
self._session.vim = self._vim
m.StubOutWithMock(self._session, 'invoke_api')
m.UnsetStubs()
m.VerifyAll()
+ def test_is_valid_with_accessible_attr(self):
+ """Test _is_valid with accessible attribute."""
+ m = self.mox
+ m.StubOutWithMock(api.VMwareAPISession, 'vim')
+ self._session.vim = self._vim
+ m.StubOutWithMock(self._session, 'invoke_api')
+ datastore = FakeMor('Datastore', 'my_ds')
+ mntInfo = FakeObject()
+ mntInfo.accessMode = "readWrite"
+ mntInfo.accessible = True
+ host = FakeMor('HostSystem', 'my_host')
+ host_mount = FakeObject()
+ host_mount.key = host
+ host_mount.mountInfo = mntInfo
+ host_mounts = FakeObject()
+ host_mounts.DatastoreHostMount = [host_mount]
+ self._session.invoke_api(vim_util, 'get_object_property',
+ self._vim, datastore,
+ 'host').AndReturn(host_mounts)
+
+ m.ReplayAll()
+ self.assertTrue(self._volumeops._is_valid(datastore, host))
+ m.UnsetStubs()
+ m.VerifyAll()
+
+ def test_is_valid_without_accessible_attr(self):
+ """Test _is_valid without accessible attribute."""
+ m = self.mox
+ m.StubOutWithMock(api.VMwareAPISession, 'vim')
+ self._session.vim = self._vim
+ m.StubOutWithMock(self._session, 'invoke_api')
+ datastore = FakeMor('Datastore', 'my_ds')
+ mntInfo = FakeObject()
+ mntInfo.accessMode = "readWrite"
+ host = FakeMor('HostSystem', 'my_host')
+ host_mount = FakeObject()
+ host_mount.key = host
+ host_mount.mountInfo = mntInfo
+ host_mounts = FakeObject()
+ host_mounts.DatastoreHostMount = [host_mount]
+ self._session.invoke_api(vim_util, 'get_object_property',
+ self._vim, datastore,
+ 'host').AndReturn(host_mounts)
+ m.StubOutWithMock(self._volumeops, 'get_summary')
+ summary = FakeObject()
+ summary.accessible = True
+ self._volumeops.get_summary(datastore).AndReturn(summary)
+
+ m.ReplayAll()
+ self.assertTrue(self._volumeops._is_valid(datastore, host))
+ m.UnsetStubs()
+ m.VerifyAll()
+
def test_get_dss_rp(self):
"""Test get_dss_rp."""
- m = mox.Mox()
+ m = self.mox
m.StubOutWithMock(api.VMwareAPISession, 'vim')
self._session.vim = self._vim
m.StubOutWithMock(self._session, 'invoke_api')
self.assertEqual(parent, child)
# Recursive
- m = mox.Mox()
+ m = self.mox
m.StubOutWithMock(api.VMwareAPISession, 'vim')
self._session.vim = self._vim
m.StubOutWithMock(self._session, 'invoke_api')
def test_get_dc(self):
"""Test get_dc."""
- m = mox.Mox()
+ m = self.mox
m.StubOutWithMock(self._volumeops, '_get_parent')
self._volumeops._get_parent(mox.IgnoreArg(), 'Datacenter')
def test_get_vmfolder(self):
"""Test get_vmfolder."""
- m = mox.Mox()
+ m = self.mox
m.StubOutWithMock(api.VMwareAPISession, 'vim')
self._session.vim = self._vim
m.StubOutWithMock(self._session, 'invoke_api')
def test_create_backing(self):
"""Test create_backing."""
- m = mox.Mox()
+ m = self.mox
m.StubOutWithMock(api.VMwareAPISession, 'vim')
self._session.vim = self._vim
m.StubOutWithMock(self._session, 'invoke_api')
def test_get_datastore(self):
"""Test get_datastore."""
- m = mox.Mox()
+ m = self.mox
m.StubOutWithMock(api.VMwareAPISession, 'vim')
self._session.vim = self._vim
m.StubOutWithMock(self._session, 'invoke_api')
def test_get_summary(self):
"""Test get_summary."""
- m = mox.Mox()
+ m = self.mox
m.StubOutWithMock(api.VMwareAPISession, 'vim')
self._session.vim = self._vim
m.StubOutWithMock(self._session, 'invoke_api')
def test_init_conn_with_instance_and_backing(self):
"""Test initialize_connection with instance and backing."""
- m = mox.Mox()
+ m = self.mox
m.StubOutWithMock(self._driver.__class__, 'volumeops')
self._driver.volumeops = self._volumeops
m.StubOutWithMock(self._volumeops, 'get_backing')
def test_get_volume_group_folder(self):
"""Test _get_volume_group_folder."""
- m = mox.Mox()
+ m = self.mox
m.StubOutWithMock(self._driver.__class__, 'volumeops')
self._driver.volumeops = self._volumeops
datacenter = FakeMor('Datacenter', 'my_dc')
def test_select_datastore_summary(self):
"""Test _select_datastore_summary."""
- m = mox.Mox()
+ m = self.mox
m.StubOutWithMock(self._driver.__class__, 'volumeops')
self._driver.volumeops = self._volumeops
datastore1 = FakeMor('Datastore', 'my_ds_1')
def test_get_folder_ds_summary(self):
"""Test _get_folder_ds_summary."""
- m = mox.Mox()
+ m = self.mox
m.StubOutWithMock(self._driver.__class__, 'volumeops')
self._driver.volumeops = self._volumeops
size = 1
def test_init_conn_with_instance_no_backing(self):
"""Test initialize_connection with instance and without backing."""
- m = mox.Mox()
+ m = self.mox
m.StubOutWithMock(self._driver.__class__, 'volumeops')
self._driver.volumeops = self._volumeops
m.StubOutWithMock(self._volumeops, 'get_backing')
def test_init_conn_without_instance(self):
"""Test initialize_connection without instance and a backing."""
- m = mox.Mox()
+ m = self.mox
m.StubOutWithMock(self._driver.__class__, 'volumeops')
self._driver.volumeops = self._volumeops
m.StubOutWithMock(self._volumeops, 'get_backing')
def test_create_snapshot_operation(self):
"""Test volumeops.create_snapshot."""
- m = mox.Mox()
+ m = self.mox
m.StubOutWithMock(api.VMwareAPISession, 'vim')
self._session.vim = self._vim
m.StubOutWithMock(self._session, 'invoke_api')
def test_create_snapshot_without_backing(self):
"""Test vmdk.create_snapshot without backing."""
- m = mox.Mox()
+ m = self.mox
m.StubOutWithMock(self._driver.__class__, 'volumeops')
self._driver.volumeops = self._volumeops
m.StubOutWithMock(self._volumeops, 'get_backing')
def test_create_snapshot_with_backing(self):
"""Test vmdk.create_snapshot with backing."""
- m = mox.Mox()
+ m = self.mox
m.StubOutWithMock(self._driver.__class__, 'volumeops')
self._driver.volumeops = self._volumeops
m.StubOutWithMock(self._volumeops, 'get_backing')
def test_get_snapshot(self):
"""Test get_snapshot."""
- m = mox.Mox()
+ m = self.mox
m.StubOutWithMock(api.VMwareAPISession, 'vim')
self._session.vim = self._vim
m.StubOutWithMock(self._session, 'invoke_api')
def test_delete_snapshot_not_present(self):
"""Test volumeops.delete_snapshot, when not present."""
- m = mox.Mox()
+ m = self.mox
m.StubOutWithMock(self._volumeops, 'get_snapshot')
name = 'snapshot_name'
backing = FakeMor('VirtualMachine', 'my_back')
def test_delete_snapshot_when_present(self):
"""Test volumeops.delete_snapshot, when it is present."""
- m = mox.Mox()
+ m = self.mox
m.StubOutWithMock(api.VMwareAPISession, 'vim')
self._session.vim = self._vim
m.StubOutWithMock(self._session, 'invoke_api')
def test_delete_snapshot_without_backing(self):
"""Test delete_snapshot without backing."""
- m = mox.Mox()
+ m = self.mox
m.StubOutWithMock(self._driver.__class__, 'volumeops')
self._driver.volumeops = self._volumeops
m.StubOutWithMock(self._volumeops, 'get_backing')
def test_delete_snapshot_with_backing(self):
"""Test delete_snapshot with backing."""
- m = mox.Mox()
+ m = self.mox
m.StubOutWithMock(self._driver.__class__, 'volumeops')
self._driver.volumeops = self._volumeops
m.StubOutWithMock(self._volumeops, 'get_backing')
def test_create_cloned_volume_without_backing(self):
"""Test create_cloned_volume without a backing."""
- m = mox.Mox()
+ m = self.mox
m.StubOutWithMock(self._driver.__class__, 'volumeops')
self._driver.volumeops = self._volumeops
m.StubOutWithMock(self._volumeops, 'get_backing')
def test_get_path_name(self):
"""Test get_path_name."""
- m = mox.Mox()
+ m = self.mox
m.StubOutWithMock(api.VMwareAPISession, 'vim')
self._session.vim = self._vim
m.StubOutWithMock(self._session, 'invoke_api')
m.VerifyAll()
def test_delete_file(self):
- """Test delete_file."""
- m = mox.Mox()
+ """Test _delete_file."""
+ m = self.mox
m.StubOutWithMock(api.VMwareAPISession, 'vim')
self._session.vim = self._vim
m.StubOutWithMock(self._session, 'invoke_api')
def test_copy_backing(self):
"""Test copy_backing."""
- m = mox.Mox()
+ m = self.mox
m.StubOutWithMock(api.VMwareAPISession, 'vim')
self._session.vim = self._vim
m.StubOutWithMock(self._session, 'invoke_api')
def test_register_backing(self):
"""Test register_backing."""
- m = mox.Mox()
+ m = self.mox
m.StubOutWithMock(api.VMwareAPISession, 'vim')
self._session.vim = self._vim
m.StubOutWithMock(self._session, 'invoke_api')
def test_clone_backing_by_copying(self):
"""Test _clone_backing_by_copying."""
- m = mox.Mox()
+ m = self.mox
m.StubOutWithMock(self._driver.__class__, 'volumeops')
self._driver.volumeops = self._volumeops
volume = FakeObject()
def test_create_cloned_volume_with_backing(self):
"""Test create_cloned_volume with a backing."""
- m = mox.Mox()
+ m = self.mox
m.StubOutWithMock(self._driver.__class__, 'volumeops')
self._driver.volumeops = self._volumeops
m.StubOutWithMock(self._volumeops, 'get_backing')
def test_create_volume_from_snapshot_without_backing(self):
"""Test create_volume_from_snapshot without a backing."""
- m = mox.Mox()
+ m = self.mox
m.StubOutWithMock(self._driver.__class__, 'volumeops')
self._driver.volumeops = self._volumeops
m.StubOutWithMock(self._volumeops, 'get_backing')
def test_create_volume_from_snap_without_backing_snap(self):
"""Test create_volume_from_snapshot without a backing snapshot."""
- m = mox.Mox()
+ m = self.mox
m.StubOutWithMock(self._driver.__class__, 'volumeops')
self._driver.volumeops = self._volumeops
backing = FakeMor('VirtualMachine', 'my_vm')
def test_revert_to_snapshot(self):
"""Test revert_to_snapshot."""
- m = mox.Mox()
+ m = self.mox
m.StubOutWithMock(api.VMwareAPISession, 'vim')
self._session.vim = self._vim
m.StubOutWithMock(self._session, 'invoke_api')
def test_create_volume_from_snapshot(self):
"""Test create_volume_from_snapshot."""
- m = mox.Mox()
+ m = self.mox
m.StubOutWithMock(self._driver.__class__, 'volumeops')
self._driver.volumeops = self._volumeops
backing = FakeMor('VirtualMachine', 'my_vm')
def test_get_entity_name(self):
"""Test volumeops get_entity_name."""
- m = mox.Mox()
+ m = self.mox
m.StubOutWithMock(api.VMwareAPISession, 'vim')
self._session.vim = self._vim
m.StubOutWithMock(self._session, 'invoke_api')
def test_get_vmdk_path(self):
"""Test volumeops get_vmdk_path."""
- m = mox.Mox()
+ m = self.mox
m.StubOutWithMock(api.VMwareAPISession, 'vim')
self._session.vim = self._vim
m.StubOutWithMock(self._session, 'invoke_api')
def test_copy_vmdk_file(self):
"""Test copy_vmdk_file."""
- m = mox.Mox()
+ m = self.mox
m.StubOutWithMock(api.VMwareAPISession, 'vim')
self._session.vim = self._vim
m.StubOutWithMock(self._session, 'invoke_api')
def test_delete_vmdk_file(self):
"""Test delete_vmdk_file."""
- m = mox.Mox()
+ m = self.mox
m.StubOutWithMock(api.VMwareAPISession, 'vim')
self._session.vim = self._vim
m.StubOutWithMock(self._session, 'invoke_api')
def test_copy_image_to_volume_non_vmdk(self):
"""Test copy_image_to_volume for a non-vmdk disk format."""
- m = mox.Mox()
+ m = self.mox
image_id = 'image-123456789'
image_meta = FakeObject()
image_meta['disk_format'] = 'novmdk'
def test_copy_image_to_volume_vmdk(self):
"""Test copy_image_to_volume with an acceptable vmdk disk format."""
- m = mox.Mox()
+ m = self.mox
m.StubOutWithMock(self._driver.__class__, 'session')
self._driver.session = self._session
m.StubOutWithMock(api.VMwareAPISession, 'vim')
def test_copy_volume_to_image_non_vmdk(self):
"""Test copy_volume_to_image for a non-vmdk disk format."""
- m = mox.Mox()
+ m = self.mox
image_meta = FakeObject()
image_meta['disk_format'] = 'novmdk'
volume = FakeObject()
def test_copy_volume_to_image_vmdk(self):
"""Test copy_volume_to_image for a valid vmdk disk format."""
- m = mox.Mox()
+ m = self.mox
m.StubOutWithMock(self._driver.__class__, 'session')
self._driver.session = self._session
m.StubOutWithMock(api.VMwareAPISession, 'vim')
def test_create_folder_not_present(self):
"""Test create_folder when not present."""
- m = mox.Mox()
+ m = self.mox
m.StubOutWithMock(api.VMwareAPISession, 'vim')
self._session.vim = self._vim
m.StubOutWithMock(self._session, 'invoke_api')
def test_create_folder_already_present(self):
"""Test create_folder when already present."""
- m = mox.Mox()
+ m = self.mox
m.StubOutWithMock(api.VMwareAPISession, 'vim')
self._session.vim = self._vim
m.StubOutWithMock(self._session, 'invoke_api')
def test_relocate_backing(self):
"""Test relocate_backing."""
- m = mox.Mox()
+ m = self.mox
m.StubOutWithMock(api.VMwareAPISession, 'vim')
self._session.vim = self._vim
m.StubOutWithMock(self._volumeops, '_get_relocate_spec')
def test_move_backing_to_folder(self):
"""Test move_backing_to_folder."""
- m = mox.Mox()
+ m = self.mox
m.StubOutWithMock(api.VMwareAPISession, 'vim')
self._session.vim = self._vim
m.StubOutWithMock(self._session, 'invoke_api')
def test_init_conn_with_instance_and_backing(self):
"""Test initialize_connection with instance and backing."""
- m = mox.Mox()
+ m = self.mox
m.StubOutWithMock(self._driver.__class__, 'volumeops')
self._driver.volumeops = self._volumeops
m.StubOutWithMock(self._volumeops, 'get_backing')
def test_get_volume_group_folder(self):
"""Test _get_volume_group_folder."""
- m = mox.Mox()
+ m = self.mox
m.StubOutWithMock(self._driver.__class__, 'volumeops')
self._driver.volumeops = self._volumeops
datacenter = FakeMor('Datacenter', 'my_dc')
def test_init_conn_with_instance_and_backing_and_relocation(self):
"""Test initialize_connection with backing being relocated."""
- m = mox.Mox()
+ m = self.mox
m.StubOutWithMock(self._driver.__class__, 'volumeops')
self._driver.volumeops = self._volumeops
m.StubOutWithMock(self._volumeops, 'get_backing')
def test_get_folder(self):
"""Test _get_folder."""
- m = mox.Mox()
+ m = self.mox
m.StubOutWithMock(self._volumeops, '_get_parent')
self._volumeops._get_parent(mox.IgnoreArg(), 'Folder')
def test_volumeops_clone_backing(self):
"""Test volumeops.clone_backing."""
- m = mox.Mox()
+ m = self.mox
m.StubOutWithMock(self._volumeops, '_get_parent')
backing = FakeMor('VirtualMachine', 'my_back')
folder = FakeMor('Folder', 'my_fol')
def test_clone_backing_linked(self):
"""Test _clone_backing with clone type - linked."""
- m = mox.Mox()
+ m = self.mox
m.StubOutWithMock(self._driver.__class__, 'volumeops')
self._driver.volumeops = self._volumeops
m.StubOutWithMock(self._volumeops, 'clone_backing')
def test_clone_backing_full(self):
"""Test _clone_backing with clone type - full."""
- m = mox.Mox()
+ m = self.mox
m.StubOutWithMock(self._driver.__class__, 'volumeops')
self._driver.volumeops = self._volumeops
m.StubOutWithMock(self._volumeops, 'get_host')
def test_create_volume_from_snapshot(self):
"""Test create_volume_from_snapshot."""
- m = mox.Mox()
+ m = self.mox
m.StubOutWithMock(self._driver.__class__, 'volumeops')
self._driver.volumeops = self._volumeops
m.StubOutWithMock(self._volumeops, 'get_backing')
def test_create_cloned_volume_with_backing(self):
"""Test create_cloned_volume with clone type - full."""
- m = mox.Mox()
+ m = self.mox
m.StubOutWithMock(self._driver.__class__, 'volumeops')
self._driver.volumeops = self._volumeops
m.StubOutWithMock(self._volumeops, 'get_backing')
def test_create_lined_cloned_volume_with_backing(self):
"""Test create_cloned_volume with clone type - linked."""
- m = mox.Mox()
+ m = self.mox
m.StubOutWithMock(self._driver.__class__, 'volumeops')
self._driver.volumeops = self._volumeops
m.StubOutWithMock(self._volumeops, 'get_backing')