def test_manage_existing_snapshot(self, get_existing_snapshot, rename_snapshot): volume = fake_volume(self.ctxt) existing_snapshot = fake_snapshot(self.ctxt) existing_snapshot.volume = volume manage_snapshot_spec = {'id': fake.SNAPSHOT2_ID} manage_snapshot = fake_snapshot(self.ctxt, **manage_snapshot_spec) manage_snapshot.volume = volume existing_name = existing_snapshot['name'] manage_name = manage_snapshot['name'] volume_name = volume['name'] volume_size = volume['size'] existing_path = self.drv._get_snapshot_path(existing_snapshot) get_existing_snapshot.return_value = { 'name': existing_name, 'path': existing_path, 'volume_name': volume_name, 'volume_size': volume_size } rename_snapshot.return_value = {} payload = {'source-name': existing_name} self.assertIsNone( self.drv.manage_existing_snapshot(manage_snapshot, payload) ) get_existing_snapshot.assert_called_with(manage_snapshot, payload) payload = {'newName': manage_name} rename_snapshot.assert_called_with(existing_path, payload)
def test_create_cgsnapshot(self, create_snapshot, rename_snapshot, delete_snapshot): cgsnapshot = fake_cgsnapshot(self.ctxt) volume = fake_volume(self.ctxt) snapshot = fake_snapshot(self.ctxt) snapshot.volume = volume snapshots = [snapshot] cgsnapshot_name = ( self.cfg.nexenta_group_snapshot_template % cgsnapshot['id']) cgsnapshot_path = '%s@%s' % (self.drv.root_path, cgsnapshot_name) snapshot_path = '%s/%s@%s' % (self.drv.root_path, snapshot['volume_name'], cgsnapshot_name) create_snapshot.return_value = {} rename_snapshot.return_value = {} delete_snapshot.return_value = {} result = self.drv.create_cgsnapshot(self.ctxt, cgsnapshot, snapshots) create_payload = {'path': cgsnapshot_path, 'recursive': True} create_snapshot.assert_called_with(create_payload) rename_payload = {'newName': snapshot['name']} rename_snapshot.assert_called_with(snapshot_path, rename_payload) delete_payload = {'defer': True, 'recursive': True} delete_snapshot.assert_called_with(cgsnapshot_path, delete_payload) expected = ({}, []) self.assertEqual(expected, result)
def test_create_volume_from_snapshot(self, clone_snapshot, unmount_filesystem, mount_filesystem, extend_volume): volume = fake_volume(self.ctxt) snapshot = fake_snapshot(self.ctxt) snapshot.volume = volume clone_size = 10 clone_spec = { 'id': fake.VOLUME2_ID, 'size': clone_size } clone = fake_volume(self.ctxt, **clone_spec) snapshot_path = self.drv._get_snapshot_path(snapshot) clone_path = self.drv._get_volume_path(clone) clone_snapshot.return_value = {} unmount_filesystem.return_value = {} mount_filesystem.return_value = {} extend_volume.return_value = None self.assertIsNone( self.drv.create_volume_from_snapshot(clone, snapshot) ) clone_payload = {'targetPath': clone_path} clone_snapshot.assert_called_with(snapshot_path, clone_payload) unmount_filesystem.assert_called_with(clone_path) mount_filesystem.assert_called_with(clone_path) extend_volume.assert_called_with(clone, clone_size)
def test__check_already_managed_snapshot(self): volume = fake_volume(self.ctxt) snapshot = fake_snapshot(self.ctxt) snapshot.volume = volume result = self.drv._check_already_managed_snapshot(snapshot) expected = False self.assertEqual(expected, result)
def test__get_existing_snapshot(self, list_snapshots): volume = fake_volume(self.ctxt) snapshot = fake_snapshot(self.ctxt) snapshot.volume = volume name = snapshot['name'] path = self.drv._get_snapshot_path(snapshot) parent = self.drv._get_volume_path(volume) list_snapshots.return_value = [{ 'name': name, 'path': path }] payload = {'source-name': name} result = self.drv._get_existing_snapshot(snapshot, payload) payload = { 'parent': parent, 'fields': 'name,path', 'recursive': False, 'name': name } list_snapshots.assert_called_with(payload) expected = { 'name': name, 'path': path, 'volume_name': volume['name'], 'volume_size': volume['size'] } self.assertEqual(expected, result)
def test_delete_snapshot(self, delete_snapshot): volume = fake_volume(self.ctxt) snapshot = fake_snapshot(self.ctxt) snapshot.volume = volume delete_snapshot.return_value = {} self.assertIsNone(self.drv.delete_snapshot(snapshot)) path = self.drv._get_snapshot_path(snapshot) payload = {'defer': True} delete_snapshot.assert_called_with(path, payload)
def test_create_snapshot(self, create_snapshot): volume = fake_volume(self.ctxt) snapshot = fake_snapshot(self.ctxt) snapshot.volume = volume create_snapshot.return_value = {} self.assertIsNone(self.drv.create_snapshot(snapshot)) path = self.drv._get_snapshot_path(snapshot) payload = {'path': path} create_snapshot.assert_called_with(payload)
def test__get_snapshot_path(self): volume = fake_volume(self.ctxt) snapshot = fake_snapshot(self.ctxt) snapshot.volume = volume result = self.drv._get_snapshot_path(snapshot) expected = '%s/%s@%s' % (self.drv.root_path, snapshot['volume_name'], snapshot['name']) self.assertEqual(expected, result)
def test_revert_to_snapshot(self, rollback_volume): volume = fake_volume(self.ctxt) snapshot = fake_snapshot(self.ctxt) snapshot.volume = volume rollback_volume.return_value = {} self.assertIsNone( self.drv.revert_to_snapshot(self.ctxt, volume, snapshot)) path = self.drv._get_volume_path(volume) payload = {'snapshot': snapshot['name']} rollback_volume.assert_called_with(path, payload)
def test_revert_to_snapshot(self, rollback_volume): volume = fake_volume(self.ctxt) snapshot = fake_snapshot(self.ctxt) snapshot.volume = volume rollback_volume.return_value = {} self.assertIsNone( self.drv.revert_to_snapshot(self.ctxt, volume, snapshot) ) path = self.drv._get_volume_path(volume) payload = {'snapshot': snapshot['name']} rollback_volume.assert_called_with(path, payload)
def test_delete_cgsnapshot(self, delete_snapshot): cgsnapshot = fake_cgsnapshot(self.ctxt) volume = fake_volume(self.ctxt) snapshot = fake_snapshot(self.ctxt) snapshot.volume = volume snapshots = [snapshot] delete_snapshot.return_value = {} result = self.drv.delete_cgsnapshot(self.ctxt, cgsnapshot, snapshots) delete_snapshot.assert_called_with(snapshot) expected = ({}, []) self.assertEqual(expected, result)
def test_delete_cgsnapshot(self, delete_snapshot): cgsnapshot = fake_cgsnapshot(self.ctxt) snapshot = fake_snapshot(self.ctxt) volume = fake_volume(self.ctxt) snapshot.volume = volume snapshots = [snapshot] delete_snapshot.return_value = {} result = self.drv.delete_cgsnapshot(self.ctxt, cgsnapshot, snapshots) delete_snapshot.assert_called_with(snapshot) expected = ({}, []) self.assertEqual(expected, result)
def test_create_consistencygroup_from_src_snapshots(self, create_volume): cgroup = fake_cgroup(self.ctxt) cgsnapshot = fake_cgsnapshot(self.ctxt) volume = fake_volume(self.ctxt) snapshot = fake_snapshot(self.ctxt) snapshot.volume = volume snapshots = [snapshot] clone_spec = {'id': fake.VOLUME2_ID} clone = fake_volume(self.ctxt, **clone_spec) clones = [clone] create_volume.return_value = {} result = self.drv.create_consistencygroup_from_src( self.ctxt, cgroup, clones, cgsnapshot, snapshots, None, None) create_volume.assert_called_with(clone, snapshot) expected = ({}, []) self.assertEqual(expected, result)
def test_create_consistencygroup_from_src_snapshots(self, create_volume): cgroup = fake_cgroup(self.ctxt) cgsnapshot = fake_cgsnapshot(self.ctxt) volume = fake_volume(self.ctxt) snapshot = fake_snapshot(self.ctxt) snapshot.volume = volume snapshots = [snapshot] clone_spec = {'id': fake.VOLUME2_ID} clone = fake_volume(self.ctxt, **clone_spec) clones = [clone] create_volume.return_value = {} result = self.drv.create_consistencygroup_from_src(self.ctxt, cgroup, clones, cgsnapshot, snapshots, None, None) create_volume.assert_called_with(clone, snapshot) expected = ({}, []) self.assertEqual(expected, result)
def test_manage_existing_snapshot_get_size(self, get_snapshot): volume = fake_volume(self.ctxt) snapshot = fake_snapshot(self.ctxt) snapshot.volume = volume snapshot_name = snapshot['name'] volume_name = volume['name'] volume_size = volume['size'] snapshot_path = self.drv._get_snapshot_path(snapshot) get_snapshot.return_value = { 'name': snapshot_name, 'path': snapshot_path, 'volume_name': volume_name, 'volume_size': volume_size } payload = {'source-name': snapshot_name} result = self.drv.manage_existing_snapshot_get_size(volume, payload) expected = volume['size'] self.assertEqual(expected, result)
def test_get_manageable_snapshots(self, list_snapshots, list_volumes): volume = fake_volume(self.ctxt) volumes = [volume] snapshot = fake_snapshot(self.ctxt) snapshot.volume = volume snapshots = [snapshot] guid = 12345 name = snapshot['name'] path = self.drv._get_snapshot_path(snapshot) parent = self.drv._get_volume_path(volume) list_snapshots.return_value = [{ 'name': name, 'path': path, 'guid': guid, 'parent': parent, 'hprService': '', 'snaplistId': '' }] list_volumes.return_value = volumes result = self.drv.get_manageable_snapshots(snapshots, None, 1, 0, 'size', 'asc') payload = { 'parent': self.drv.root_path, 'fields': 'name,guid,path,parent,hprService,snaplistId', 'recursive': True } list_snapshots.assert_called_with(payload) expected = [{ 'cinder_id': snapshot['id'], 'extra_info': None, 'reason_not_safe': 'Snapshot already managed', 'source_reference': { 'name': volume['name'] }, 'reference': { 'source-guid': guid, 'source-name': snapshot['name'] }, 'safe_to_manage': False, 'size': volume['size'] }] self.assertEqual(expected, result)
def test_unmanage_snapshot(self): volume = fake_volume(self.ctxt) snapshot = fake_snapshot(self.ctxt) snapshot.volume = volume self.assertIsNone(self.drv.unmanage_snapshot(snapshot))