Skip to content

Commit

Permalink
Fix Lint Issue - Final
Browse files Browse the repository at this point in the history
  • Loading branch information
RayLiu7 committed Jan 17, 2025
1 parent 231eb1d commit 48e1c78
Show file tree
Hide file tree
Showing 15 changed files with 47 additions and 36 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/pylint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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')
3 changes: 3 additions & 0 deletions .pylintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[MESSAGES CONTROL]

disable-msg=E1101 for PyPowerFlex/*.py
2 changes: 1 addition & 1 deletion PyPowerFlex/base_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand Down
3 changes: 0 additions & 3 deletions PyPowerFlex/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
10 changes: 5 additions & 5 deletions PyPowerFlex/objects/acceleration_pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions PyPowerFlex/objects/snapshot_policy.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down
7 changes: 4 additions & 3 deletions PyPowerFlex/objects/storage_pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)

Expand Down
15 changes: 11 additions & 4 deletions PyPowerFlex/objects/utility.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@

from PyPowerFlex import base_client
from PyPowerFlex import exceptions
from PyPowerFlex import utils
from PyPowerFlex.constants import StoragePoolConstants, VolumeConstants, SnapshotPolicyConstants


Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
12 changes: 6 additions & 6 deletions PyPowerFlex/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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):
Expand All @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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'}]
Expand Down
2 changes: 2 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
7 changes: 3 additions & 4 deletions tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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)

Expand All @@ -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)
6 changes: 3 additions & 3 deletions tests/test_acceleration_pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand All @@ -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):
"""
Expand All @@ -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):
"""
Expand Down
1 change: 0 additions & 1 deletion tests/test_replication_consistency_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
1 change: 0 additions & 1 deletion tests/test_utility.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
"""Module for testing PowerFlex utility."""

from PyPowerFlex import exceptions
from PyPowerFlex.objects import utility
import tests


Expand Down

0 comments on commit 48e1c78

Please sign in to comment.