From 15ee0a0642eef48d2cbac315404efab5c8a152f7 Mon Sep 17 00:00:00 2001 From: Tao He Date: Thu, 21 Aug 2025 14:58:07 +0000 Subject: [PATCH 1/2] Update device, device and node functions --- PyPowerFlex/objects/gen2/device.py | 38 +++--------------------- PyPowerFlex/objects/gen2/device_group.py | 11 ++----- PyPowerFlex/objects/gen2/storage_node.py | 28 +++++++++++++++++ tests/gen2/test_device.py | 22 -------------- tests/gen2/test_storage_node.py | 18 +++++++++++ 5 files changed, 52 insertions(+), 65 deletions(-) diff --git a/PyPowerFlex/objects/gen2/device.py b/PyPowerFlex/objects/gen2/device.py index aa133c4..ecea9e3 100644 --- a/PyPowerFlex/objects/gen2/device.py +++ b/PyPowerFlex/objects/gen2/device.py @@ -41,10 +41,10 @@ class Device(base_client.EntityRequest): def create(self, current_pathname, + media_type, device_group_id, node_id, force=None, - media_type=None, name=None): """Create PowerFlex device. @@ -58,8 +58,8 @@ def create(self, :rtype: dict """ - if not all([current_pathname, device_group_id, node_id]): - msg = 'current_pathname, device_group_id and node_id must be set.' + if not all([current_pathname, media_type, device_group_id, node_id]): + msg = 'current_pathname, media_type, device_group_id and node_id must be set.' raise exceptions.InvalidInput(msg) params = { @@ -98,37 +98,8 @@ def rename(self, device_id, name): return self._rename_entity(action, device_id, params) - def update_pathname(self, device_id, new_pathname): - """Update PowerFlex device pathname. - TODO TTHE make sure this API is valid after the latest dev build is ready - - :type device_id: str - :type new_pathname: str - :rtype: dict - """ - - action = 'updateDeviceOriginalPathname' - params = {"updateDeviceOriginalPathname": new_pathname} - r, response = self.send_post_request(self.base_action_url, - action=action, - entity=self.entity, - entity_id=device_id, - params=params) - if r.status_code != requests.codes.ok: - msg = ( - f"Failed to update pathname for PowerFlex {self.entity} " - f"with id {device_id}. " - f"Error: {response}" - ) - LOG.error(msg) - raise exceptions.PowerFlexClientException(msg) - - return self.get(entity_id=device_id) - def set_capacity_limit(self, device_id, capacity_limit_gb): """Update PowerFlex device capacity limit in GB. - TODO TTHE make sure this API is valid after the latest dev build is ready - :type device_id: str :type capacity_limit_gb: int :rtype: dict @@ -154,9 +125,8 @@ def set_capacity_limit(self, device_id, capacity_limit_gb): def clear_errors(self, device_id, force=None): """Clear PowerFlex device errors. - TODO TTHE make sure this field - `forceClear` is valid after the latest dev build is ready - :type device_id: str + :type force: bool :rtype: dict """ diff --git a/PyPowerFlex/objects/gen2/device_group.py b/PyPowerFlex/objects/gen2/device_group.py index 5eaab40..ca9b02d 100644 --- a/PyPowerFlex/objects/gen2/device_group.py +++ b/PyPowerFlex/objects/gen2/device_group.py @@ -69,19 +69,12 @@ def create(self, return self._create_entity(params) - def delete(self, device_group_id, force=None): + def delete(self, device_group_id): """Remove PowerFlex device group. - TODO TTHE make sure this `force` field is valid after the latest dev build is ready - :type device_group_id: str - :type force: bool :rtype: None """ - params = { - "force": force - } - - return self._delete_entity(device_group_id, params) + return self._delete_entity(device_group_id) def modify(self, device_group_id, diff --git a/PyPowerFlex/objects/gen2/storage_node.py b/PyPowerFlex/objects/gen2/storage_node.py index b4043e4..4b22fd7 100644 --- a/PyPowerFlex/objects/gen2/storage_node.py +++ b/PyPowerFlex/objects/gen2/storage_node.py @@ -190,3 +190,31 @@ def set_ip_role(self, node_id, ip, role): raise exceptions.PowerFlexClientException(msg) return self.get(entity_id=node_id) + + def update_original_pathnames(self, node_id, force=None): + """Update original pathnames for PowerFlex Storage Node. + + :type node_id: str + :type force: bool + :rtype: dict + """ + + action = 'updateNodeOriginalPathnames' + + params = {"forceFailedDevices": force} + + r, response = self.send_post_request(self.base_action_url, + action=action, + entity=self.entity, + entity_id=node_id, + params=params) + if r.status_code != requests.codes.ok: + msg = ( + f"Failed to update original pathnames for PowerFlex {self.entity} " + f"with id {node_id}. " + f"Error: {response}" + ) + LOG.error(msg) + raise exceptions.PowerFlexClientException(msg) + + return self.get(entity_id=node_id) \ No newline at end of file diff --git a/tests/gen2/test_device.py b/tests/gen2/test_device.py index 39bb0e7..448d301 100644 --- a/tests/gen2/test_device.py +++ b/tests/gen2/test_device.py @@ -54,9 +54,6 @@ def setUp(self): '/action/setDeviceCapacityLimit': {}, f'/instances/Device::{self.fake_device_id}' - '/action/updateDeviceOriginalPathname': - {}, - f'/instances/Device::{self.fake_device_id}' '/action/clearDeviceError': {}, f'/instances/Device::{self.fake_device_id}' @@ -152,25 +149,6 @@ def test_device_rename_bad_status(self): self.fake_device_id, name='new_name') - def test_device_update_pathname(self): - """ - Test device update_pathname. - """ - self.client.device.update_pathname( - self.fake_device_id, - new_pathname='/dev/sdb') - - def test_device_update_pathname_bad_status(self): - """ - Test device update_pathname with bad status. - """ - with self.http_response_mode(self.RESPONSE_MODE.BadStatus): - self.assertRaises( - exceptions.PowerFlexClientException, - self.client.device.update_pathname, - self.fake_device_id, - new_pathname='/dev/sdb') - def test_device_set_capacity_limit(self): """ Test device set_capacity_limit. diff --git a/tests/gen2/test_storage_node.py b/tests/gen2/test_storage_node.py index 9dfd636..711b6c9 100644 --- a/tests/gen2/test_storage_node.py +++ b/tests/gen2/test_storage_node.py @@ -56,6 +56,8 @@ def setUp(self): {}, f'/instances/Node::{self.fake_node_id}/action/modifyIpRole': {}, + f'/instances/Node::{self.fake_node_id}/action/updateNodeOriginalPathnames': + {}, }, self.RESPONSE_MODE.Invalid: { '/types/Node/instances': @@ -178,3 +180,19 @@ def test_storage_node_set_ip_role_bad_status(self): self.fake_node_id, ip='1.2.3.4', role=StorageNodeIpRoles.storage_and_app) + + def test_storage_node_update_original_pathnames(self): + """ + Test storage_node update_original_pathnames. + """ + self.client.storage_node.update_original_pathnames(self.fake_node_id) + + def test_storage_node_update_original_pathnames_bad_status(self): + """ + Test storage_node update_original_pathnames with a bad status. + """ + with self.http_response_mode(self.RESPONSE_MODE.BadStatus): + self.assertRaises( + exceptions.PowerFlexClientException, + self.client.storage_node.update_original_pathnames, + self.fake_node_id) From b8f6666d52eeff732bda2e9219eec2dd8ebdbbb4 Mon Sep 17 00:00:00 2001 From: Tao He Date: Fri, 29 Aug 2025 06:15:05 +0000 Subject: [PATCH 2/2] Fix lint issue --- PyPowerFlex/objects/gen2/storage_node.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PyPowerFlex/objects/gen2/storage_node.py b/PyPowerFlex/objects/gen2/storage_node.py index 4b22fd7..63b3dcb 100644 --- a/PyPowerFlex/objects/gen2/storage_node.py +++ b/PyPowerFlex/objects/gen2/storage_node.py @@ -217,4 +217,4 @@ def update_original_pathnames(self, node_id, force=None): LOG.error(msg) raise exceptions.PowerFlexClientException(msg) - return self.get(entity_id=node_id) \ No newline at end of file + return self.get(entity_id=node_id)