From 00bd9230de372cd7b28e6f7ceb1aa168bb68b61f Mon Sep 17 00:00:00 2001 From: Tom Barron Date: Wed, 13 Mar 2019 09:31:40 -0400 Subject: [PATCH] Port dummy driver manage/unmanage changes to stable Branchless manila-tempest-plugin had changes for the manage share server feature that required changes in the dummy driver for its manage and unmanage routines. Here we test porting the dummy driver changes for the manage and unmanage share and snapshot methods, omitting the manage and unmanage methods for share servers since these are not supported in the stable branches. Note that backporting such changes to a stable branch for a regular driver would likely be unacceptable given stable policy but the dummy driver is test-only code that never runs outside of tests. Change-Id: Ib9e5dd3ad6b745ea1dfe442d9357a70ca4c148ec (cherry picked from commit 6b25b0a4075550163554895b5a1e275675ef9f21) --- manila/tests/share/drivers/dummy.py | 47 +++++++++++++++++++++++++++-- 1 file changed, 44 insertions(+), 3 deletions(-) diff --git a/manila/tests/share/drivers/dummy.py b/manila/tests/share/drivers/dummy.py index ec6c27c0a4..6f3216294e 100644 --- a/manila/tests/share/drivers/dummy.py +++ b/manila/tests/share/drivers/dummy.py @@ -303,21 +303,62 @@ class DummyDriver(driver.ShareDriver): @slow_me_down def manage_existing(self, share, driver_options): """Brings an existing share under Manila management.""" - return {"size": 1, "export_locations": self._create_share(share)} + new_export = share['export_location'] + old_share_id = self._get_share_id_from_export(new_export) + old_export = self.private_storage.get( + old_share_id, key='export_location') + if old_export.split(":/")[-1] == new_export.split(":/")[-1]: + result = {"size": 1, "export_locations": self._create_share(share)} + self.private_storage.delete(old_share_id) + return result + else: + msg = ("Invalid export specified, existing share %s" + " could not be found" % old_share_id) + raise exception.ShareBackendException(msg=msg) + + def _get_share_id_from_export(self, export_location): + values = export_location.split('share_') + if len(values) > 1: + return values[1][37:].replace("_", "-") + else: + return export_location @slow_me_down def unmanage(self, share): """Removes the specified share from Manila management.""" + self.private_storage.update( + share['id'], {'export_location': share['export_location']}) @slow_me_down def manage_existing_snapshot(self, snapshot, driver_options): """Brings an existing snapshot under Manila management.""" - self._create_snapshot(snapshot) - return {"size": 1, "provider_location": snapshot["provider_location"]} + old_snap_id = self._get_snap_id_from_provider_location( + snapshot['provider_location']) + old_provider_location = self.private_storage.get( + old_snap_id, key='provider_location') + if old_provider_location == snapshot['provider_location']: + self._create_snapshot(snapshot) + self.private_storage.delete(old_snap_id) + return {"size": 1, + "provider_location": snapshot["provider_location"]} + else: + msg = ("Invalid provider location specified, existing snapshot %s" + " could not be found" % old_snap_id) + raise exception.ShareBackendException(msg=msg) + + def _get_snap_id_from_provider_location(self, provider_location): + values = provider_location.split('snapshot_') + if len(values) > 1: + return values[1][37:].replace("_", "-") + else: + return provider_location @slow_me_down def unmanage_snapshot(self, snapshot): """Removes the specified snapshot from Manila management.""" + self.private_storage.update( + snapshot['id'], + {'provider_location': snapshot['provider_location']}) @slow_me_down def revert_to_snapshot(self, context, snapshot, share_access_rules,