From ee1b5e2b756f49a384d348555e9611526c0c1217 Mon Sep 17 00:00:00 2001 From: Helen Walsh Date: Fri, 5 Mar 2021 12:56:28 +0000 Subject: [PATCH] PowerMax Driver - Fix for legacy PowerMax OS around generations In the previous version of PowerMax OS generations of snapVx were used instead of unique snap ids which were just introduced. A generation can be returned as a 0 integer which equates to False in python. The fix is to convert the int to a string if it is returned from REST as an int. Closes-Bug: #1938572 Change-Id: I5b660776190f3026296d6d3237bd3b0d609f769f --- .../dell_emc/powermax/test_powermax_rest.py | 22 +++++++++++++++++++ .../volume/drivers/dell_emc/powermax/rest.py | 2 +- .../volume/drivers/dell_emc/powermax/utils.py | 9 ++++++++ ...egacy_generation_fix-09e437f955cd9d70.yaml | 8 +++++++ 4 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 releasenotes/notes/powermax_legacy_generation_fix-09e437f955cd9d70.yaml diff --git a/cinder/tests/unit/volume/drivers/dell_emc/powermax/test_powermax_rest.py b/cinder/tests/unit/volume/drivers/dell_emc/powermax/test_powermax_rest.py index 0b35fb16d09..477c8699739 100644 --- a/cinder/tests/unit/volume/drivers/dell_emc/powermax/test_powermax_rest.py +++ b/cinder/tests/unit/volume/drivers/dell_emc/powermax/test_powermax_rest.py @@ -2431,3 +2431,25 @@ class PowerMaxRestTest(test.TestCase): exception.VolumeBackendAPIException, self.rest.get_ip_interface_physical_port, array_id, virtual_port, ip_address) + + @mock.patch.object(rest.PowerMaxRest, 'get_volume_snaps', + return_value=[{'snap_name': 'snap_name', + 'snap_id': tpd.PowerMaxData.snap_id}]) + def test_get_snap_id(self, mock_snaps): + snap_id = self.rest.get_snap_id( + self.data.array, self.data.device_id, + self.data.test_snapshot_snap_name) + self.assertEqual(self.data.snap_id, snap_id) + + @mock.patch.object(rest.PowerMaxRest, 'get_volume_snaps', + side_effect=[[{'snap_name': 'generation_int', + 'generation': 0}], + [{'snap_name': 'generation_string', + 'generation': '0'}]]) + def test_get_snap_id_legacy_generation(self, mock_snaps): + self.rest.is_snap_id = False + for x in range(0, 2): + snap_id = self.rest.get_snap_id( + self.data.array, self.data.device_id, + self.data.test_snapshot_snap_name) + self.assertEqual('0', snap_id) diff --git a/cinder/volume/drivers/dell_emc/powermax/rest.py b/cinder/volume/drivers/dell_emc/powermax/rest.py index 6027da44586..e63de0d2118 100644 --- a/cinder/volume/drivers/dell_emc/powermax/rest.py +++ b/cinder/volume/drivers/dell_emc/powermax/rest.py @@ -3397,7 +3397,7 @@ class PowerMaxRest(object): message=exception_message) else: return snapshots[0].get('snap_id') if self.is_snap_id else ( - snapshots[0].get('generation')) + self.utils.convert_to_string(snapshots[0].get('generation'))) def get_major_minor_ucode(self, array): """Get the major and minor parts of the ucode diff --git a/cinder/volume/drivers/dell_emc/powermax/utils.py b/cinder/volume/drivers/dell_emc/powermax/utils.py index aeed7b9d332..b0a7323d43f 100644 --- a/cinder/volume/drivers/dell_emc/powermax/utils.py +++ b/cinder/volume/drivers/dell_emc/powermax/utils.py @@ -2086,3 +2086,12 @@ class PowerMaxUtils(object): service_level = str() return array_id, srp, service_level, workload + + @staticmethod + def convert_to_string(in_value): + """Convert to string if value is an int + + :param in_value: the input (most likely a str or int) + :returns: str + """ + return in_value if isinstance(in_value, str) else str(in_value) diff --git a/releasenotes/notes/powermax_legacy_generation_fix-09e437f955cd9d70.yaml b/releasenotes/notes/powermax_legacy_generation_fix-09e437f955cd9d70.yaml new file mode 100644 index 00000000000..0254089e145 --- /dev/null +++ b/releasenotes/notes/powermax_legacy_generation_fix-09e437f955cd9d70.yaml @@ -0,0 +1,8 @@ +--- +fixes: + - | + PowerMax driver `bug #1938572 + `_ : + Legacy PowerMax OS fix to convert an int to a string if the generation + of snapVX is returned as an int from REST so that a 0 does not equate + to False in python.