From 48e1c788204f83d414b96fd1c67f754fba3e4051 Mon Sep 17 00:00:00 2001 From: yuhao_liu Date: Tue, 14 Jan 2025 21:27:51 -0500 Subject: [PATCH] Fix Lint Issue - Final --- .github/workflows/pylint.yml | 4 ++++ .pylintrc | 3 +++ PyPowerFlex/base_client.py | 2 +- PyPowerFlex/exceptions.py | 3 --- PyPowerFlex/objects/acceleration_pool.py | 10 +++++----- PyPowerFlex/objects/snapshot_policy.py | 8 ++++---- PyPowerFlex/objects/storage_pool.py | 7 ++++--- PyPowerFlex/objects/utility.py | 15 +++++++++++---- PyPowerFlex/utils.py | 12 ++++++------ README.md | 2 +- setup.py | 2 ++ tests/__init__.py | 7 +++---- tests/test_acceleration_pool.py | 6 +++--- tests/test_replication_consistency_group.py | 1 - tests/test_utility.py | 1 - 15 files changed, 47 insertions(+), 36 deletions(-) create mode 100644 .pylintrc diff --git a/.github/workflows/pylint.yml b/.github/workflows/pylint.yml index 79cf081..bb496d8 100644 --- a/.github/workflows/pylint.yml +++ b/.github/workflows/pylint.yml @@ -23,5 +23,9 @@ jobs: - name: Install dependencies run: python -m pip install --upgrade pip && pip install pylint + - name: Install requirements + run: | + if [ -f requirements.txt ]; then pip install -r requirements.txt; fi + - name: Analyzing the code with pylint run: pylint $(git ls-files '*.py') diff --git a/.pylintrc b/.pylintrc new file mode 100644 index 0000000..b0dca4d --- /dev/null +++ b/.pylintrc @@ -0,0 +1,3 @@ +[MESSAGES CONTROL] + +disable-msg=E1101 for PyPowerFlex/*.py diff --git a/PyPowerFlex/base_client.py b/PyPowerFlex/base_client.py index 615a895..b4604ad 100644 --- a/PyPowerFlex/base_client.py +++ b/PyPowerFlex/base_client.py @@ -335,7 +335,7 @@ def _login(self): else f'Login failed with error: {str(e)}' ) LOG.error(error_msg) - raise Exception(error_msg) + raise Exception(error_msg) from e def _logout(self): """ diff --git a/PyPowerFlex/exceptions.py b/PyPowerFlex/exceptions.py index feab6ef..a3e70c0 100644 --- a/PyPowerFlex/exceptions.py +++ b/PyPowerFlex/exceptions.py @@ -42,21 +42,18 @@ class InvalidConfiguration(PowerFlexClientException): """ Exception raised when the configuration is invalid. """ - pass class FieldsNotFound(PowerFlexClientException): """ Exception raised when the required fields are not found. """ - pass class InvalidInput(PowerFlexClientException): """ Exception raised when the input is invalid. """ - pass class PowerFlexFailCreating(PowerFlexClientException): diff --git a/PyPowerFlex/objects/acceleration_pool.py b/PyPowerFlex/objects/acceleration_pool.py index 5de1124..55471e7 100644 --- a/PyPowerFlex/objects/acceleration_pool.py +++ b/PyPowerFlex/objects/acceleration_pool.py @@ -40,25 +40,25 @@ def create(self, media_type, protection_domain_id, name=None, - isRfcache=None): + is_rfcache=None): """Create PowerFlex acceleration pool. :param media_type: one of predefined attributes of MediaType :type media_type: str :type protection_domain_id: str :type name: str - :type isRfcache: bool + :type is_rfcache: bool :rtype: dict """ - if media_type == MediaType.ssd and not isRfcache: - msg = 'isRfcache must be set for media_type SSD.' + if media_type == MediaType.ssd and not is_rfcache: + msg = 'is_rfcache must be set for media_type SSD.' raise exceptions.InvalidInput(msg) params = { 'mediaType': media_type, 'protectionDomainId': protection_domain_id, 'name': name, - 'isRfcache': isRfcache + 'isRfcache': is_rfcache } return self._create_entity(params) diff --git a/PyPowerFlex/objects/snapshot_policy.py b/PyPowerFlex/objects/snapshot_policy.py index 8228dae..8d911e0 100644 --- a/PyPowerFlex/objects/snapshot_policy.py +++ b/PyPowerFlex/objects/snapshot_policy.py @@ -70,8 +70,8 @@ def create(self, retained_snaps_per_level, name=None, paused=None, - snapshotAccessMode=None, - secureSnapshots=None): + snapshot_access_mode=None, + secure_snapshots=None): """Create PowerFlex snapshot policy. :type auto_snap_creation_cadence_in_min: int @@ -86,8 +86,8 @@ def create(self, "numOfRetainedSnapshotsPerLevel": retained_snaps_per_level, "name": name, "paused": paused, - "snapshotAccessMode": snapshotAccessMode, - "secureSnapshots": secureSnapshots + "snapshotAccessMode": snapshot_access_mode, + "secureSnapshots": secure_snapshots } return self._create_entity(params) diff --git a/PyPowerFlex/objects/storage_pool.py b/PyPowerFlex/objects/storage_pool.py index c4c3615..6943374 100644 --- a/PyPowerFlex/objects/storage_pool.py +++ b/PyPowerFlex/objects/storage_pool.py @@ -562,7 +562,7 @@ def set_cap_alert_thresholds( params=params) if r.status_code != requests.codes.ok: msg = ( - f'Failed to set the capacity alert thresholds for PowerFlex {self.entity}' + f'Failed to set the capacity alert thresholds for PowerFlex {self.entity}' f'with id {storage_pool_id}. Error: {response}') LOG.error(msg) raise exceptions.PowerFlexClientException(msg) @@ -595,8 +595,9 @@ def set_protected_maintenance_mode_io_priority_policy( params=params) if r.status_code != requests.codes.ok: msg = ( - f'Failed to set the protected maintenance mode IO priority policy for PowerFlex {self.entity} ' - f'with id {storage_pool_id}. Error: {response}') + f'Failed to set the protected maintenance mode IO priority policy for ' + f'PowerFlex {self.entity} with id {storage_pool_id}. Error: {response}' + ) LOG.error(msg) raise exceptions.PowerFlexClientException(msg) diff --git a/PyPowerFlex/objects/utility.py b/PyPowerFlex/objects/utility.py index ef723b2..c653a9a 100644 --- a/PyPowerFlex/objects/utility.py +++ b/PyPowerFlex/objects/utility.py @@ -21,7 +21,6 @@ from PyPowerFlex import base_client from PyPowerFlex import exceptions -from PyPowerFlex import utils from PyPowerFlex.constants import StoragePoolConstants, VolumeConstants, SnapshotPolicyConstants @@ -79,7 +78,12 @@ def get_statistics_for_all_volumes(self, ids=None, properties=None): action = 'querySelectedStatistics' params = { - 'properties': VolumeConstants.DEFAULT_STATISTICS_PROPERTIES if properties is None else properties} + 'properties': ( + VolumeConstants.DEFAULT_STATISTICS_PROPERTIES + if properties is None + else properties + ) + } if ids is None: params['allIds'] = "" else: @@ -110,8 +114,11 @@ def get_statistics_for_all_snapshot_policies( action = 'querySelectedStatistics' - params = { - 'properties': SnapshotPolicyConstants.DEFAULT_STATISTICS_PROPERTIES if properties is None else properties} + params = {} + if properties is None: + params['properties'] = SnapshotPolicyConstants.DEFAULT_STATISTICS_PROPERTIES + else: + params['properties'] = properties if ids is None: params['allIds'] = "" else: diff --git a/PyPowerFlex/utils.py b/PyPowerFlex/utils.py index d9a50f6..177229e 100644 --- a/PyPowerFlex/utils.py +++ b/PyPowerFlex/utils.py @@ -80,7 +80,7 @@ def query_response_fields(response, fields): def query_entity_fields(entity): entity_fields = {} - fields_not_found = list() + fields_not_found = [] for field in fields: try: entity_fields[field] = entity[field] @@ -96,8 +96,9 @@ def query_entity_fields(entity): if isinstance(response, list): return list(map(query_entity_fields, response)) - elif isinstance(response, dict): + if isinstance(response, dict): return query_entity_fields(response) + return None def convert(param): @@ -109,12 +110,11 @@ def convert(param): """ if isinstance(param, list): return [convert(item) for item in param] - elif isinstance(param, (numbers.Number, bool)): + if isinstance(param, (numbers.Number, bool)): # Convert numbers and boolean to string. return str(param) - else: - # Other types are not converted. - return param + # Other types are not converted. + return param def prepare_params(params, dump=True): diff --git a/README.md b/README.md index 71ca540..c38be70 100644 --- a/README.md +++ b/README.md @@ -177,7 +177,7 @@ from PyPowerFlex.objects.acceleration_pool import MediaType client.acceleration_pool.create(media_type=MediaType.ssd, protection_domain_id='1caf743100000000', name='ACP_SSD', - isRfcache=True) + is_rfcache=True) client.acceleration_pool.get(filter_fields={'id': '9c8c5c7800000001'}, fields=['name', 'id']) [{'name': 'ACP_SSD', 'id': '9c8c5c7800000001'}] diff --git a/setup.py b/setup.py index b9d3303..9122771 100644 --- a/setup.py +++ b/setup.py @@ -13,6 +13,8 @@ # License for the specific language governing permissions and limitations # under the License. +"""Module for general setup.""" + from setuptools import setup setup( diff --git a/tests/__init__.py b/tests/__init__.py index 459f35e..8e2036c 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -198,7 +198,7 @@ def get_mock_response(self, url, request_url=None, mode=None, *args, **kwargs): response = self.RESPONSE_MODE.Valid[2] else: response = self.MOCK_RESPONSES[mode][api_path] - except KeyError: + except KeyError as e: try: response = self.DEFAULT_MOCK_RESPONSES[mode][api_path] except KeyError: @@ -208,7 +208,7 @@ def get_mock_response(self, url, request_url=None, mode=None, *args, **kwargs): raise Exception( f"Mock API Endpoint is not implemented: [{mode}]" f"{api_path}" - ) + ) from e if not isinstance(response, MockResponse): response = self._get_mock_response(response) @@ -228,5 +228,4 @@ def _get_mock_response(self, response): """ if "204" in str(response): return MockResponse(response, 204) - else: - return MockResponse(response, 200) + return MockResponse(response, 200) diff --git a/tests/test_acceleration_pool.py b/tests/test_acceleration_pool.py index dfd467a..b15ec8e 100644 --- a/tests/test_acceleration_pool.py +++ b/tests/test_acceleration_pool.py @@ -60,7 +60,7 @@ def test_acceleration_pool_create(self): self.client.acceleration_pool.create( media_type=acceleration_pool.MediaType.ssd, protection_domain_id=self.fake_pd_id, - isRfcache=True) + is_rfcache=True) def test_acceleration_pool_create_bad_status(self): """ @@ -71,7 +71,7 @@ def test_acceleration_pool_create_bad_status(self): self.client.acceleration_pool.create, media_type=acceleration_pool.MediaType.ssd, protection_domain_id=self.fake_pd_id, - isRfcache=True) + is_rfcache=True) def test_acceleration_pool_create_no_id_in_response(self): """ @@ -82,7 +82,7 @@ def test_acceleration_pool_create_no_id_in_response(self): self.client.acceleration_pool.create, media_type=acceleration_pool.MediaType.ssd, protection_domain_id=self.fake_pd_id, - isRfcache=True) + is_rfcache=True) def test_acceleration_pool_delete(self): """ diff --git a/tests/test_replication_consistency_group.py b/tests/test_replication_consistency_group.py index e7bddaa..7491d33 100644 --- a/tests/test_replication_consistency_group.py +++ b/tests/test_replication_consistency_group.py @@ -16,7 +16,6 @@ """Module for testing replication consistency group client.""" from PyPowerFlex import exceptions -from PyPowerFlex.objects import replication_consistency_group as rcg import tests diff --git a/tests/test_utility.py b/tests/test_utility.py index 84457fd..8414860 100644 --- a/tests/test_utility.py +++ b/tests/test_utility.py @@ -16,7 +16,6 @@ """Module for testing PowerFlex utility.""" from PyPowerFlex import exceptions -from PyPowerFlex.objects import utility import tests