From 2bf2e941bedff1d49f4317764017dfd67fdf69b6 Mon Sep 17 00:00:00 2001 From: Christopher Gallo Date: Fri, 15 Dec 2017 12:01:19 -0600 Subject: [PATCH 1/2] fixed/ignored a bunch of new pylint errors --- SoftLayer/API.py | 4 +--- SoftLayer/CLI/__init__.py | 2 +- SoftLayer/CLI/exceptions.py | 1 + SoftLayer/CLI/firewall/edit.py | 2 -- SoftLayer/CLI/formatting.py | 2 +- SoftLayer/CLI/virt/__init__.py | 8 +++----- SoftLayer/__init__.py | 2 +- SoftLayer/config.py | 2 +- SoftLayer/managers/hardware.py | 2 +- SoftLayer/managers/vs.py | 11 ++++++----- SoftLayer/shell/completer.py | 7 +++---- 11 files changed, 19 insertions(+), 24 deletions(-) diff --git a/SoftLayer/API.py b/SoftLayer/API.py index 2a79264c2..b1557537b 100644 --- a/SoftLayer/API.py +++ b/SoftLayer/API.py @@ -5,6 +5,7 @@ :license: MIT, see LICENSE for more details. """ +# pylint: disable=invalid-name import warnings from SoftLayer import auth as slauth @@ -12,9 +13,6 @@ from SoftLayer import consts from SoftLayer import transports -# pylint: disable=invalid-name - - API_PUBLIC_ENDPOINT = consts.API_PUBLIC_ENDPOINT API_PRIVATE_ENDPOINT = consts.API_PRIVATE_ENDPOINT __all__ = [ diff --git a/SoftLayer/CLI/__init__.py b/SoftLayer/CLI/__init__.py index 5e4389c65..3d5d6bf79 100644 --- a/SoftLayer/CLI/__init__.py +++ b/SoftLayer/CLI/__init__.py @@ -5,6 +5,6 @@ :license: MIT, see LICENSE for more details. """ -# pylint: disable=w0401 +# pylint: disable=w0401, invalid-name from SoftLayer.CLI.helpers import * # NOQA diff --git a/SoftLayer/CLI/exceptions.py b/SoftLayer/CLI/exceptions.py index 8f5917f55..98b3f2830 100644 --- a/SoftLayer/CLI/exceptions.py +++ b/SoftLayer/CLI/exceptions.py @@ -7,6 +7,7 @@ """ +# pylint: disable=keyword-arg-before-vararg class CLIHalt(SystemExit): """Smoothly halt the execution of the command. No error.""" def __init__(self, code=0, *args): diff --git a/SoftLayer/CLI/firewall/edit.py b/SoftLayer/CLI/firewall/edit.py index c41e696a1..f58be4439 100644 --- a/SoftLayer/CLI/firewall/edit.py +++ b/SoftLayer/CLI/firewall/edit.py @@ -104,8 +104,6 @@ def open_editor(rules=None, content=None): data = tfile.read() return data - return - def get_formatted_rule(rule=None): """Helper to format the rule into a user friendly format. diff --git a/SoftLayer/CLI/formatting.py b/SoftLayer/CLI/formatting.py index bb3d72d12..403ba8a6f 100644 --- a/SoftLayer/CLI/formatting.py +++ b/SoftLayer/CLI/formatting.py @@ -6,7 +6,7 @@ :license: MIT, see LICENSE for more details. """ -# pylint: disable=E0202, consider-merging-isinstance, arguments-differ +# pylint: disable=E0202, consider-merging-isinstance, arguments-differ, keyword-arg-before-vararg import collections import json import os diff --git a/SoftLayer/CLI/virt/__init__.py b/SoftLayer/CLI/virt/__init__.py index bf1d16203..90c2ad1fa 100644 --- a/SoftLayer/CLI/virt/__init__.py +++ b/SoftLayer/CLI/virt/__init__.py @@ -12,12 +12,11 @@ class MemoryType(click.ParamType): """Memory type.""" name = 'integer' - def convert(self, value, param, ctx): + def convert(self, value, param, ctx): # pylint: disable=inconsistent-return-statements """Validate memory argument. Returns the memory value in megabytes.""" matches = MEMORY_RE.match(value.lower()) if matches is None: - self.fail('%s is not a valid value for memory amount' - % value, param, ctx) + self.fail('%s is not a valid value for memory amount' % value, param, ctx) amount_str, unit = matches.groups() amount = int(amount_str) if unit in [None, 'm', 'mb']: @@ -26,8 +25,7 @@ def convert(self, value, param, ctx): return amount * 1024 else: if amount % 1024 != 0: - self.fail('%s is not an integer that is divisable by 1024' - % value, param, ctx) + self.fail('%s is not an integer that is divisable by 1024' % value, param, ctx) return amount elif unit in ['g', 'gb']: return amount * 1024 diff --git a/SoftLayer/__init__.py b/SoftLayer/__init__.py index 3a641e8b2..3e79f6cd4 100644 --- a/SoftLayer/__init__.py +++ b/SoftLayer/__init__.py @@ -14,7 +14,7 @@ :license: MIT, see LICENSE for more details. """ -# pylint: disable=w0401 +# pylint: disable=w0401,invalid-name from SoftLayer import consts from SoftLayer.API import * # NOQA diff --git a/SoftLayer/config.py b/SoftLayer/config.py index 748c5df24..c69e8311a 100644 --- a/SoftLayer/config.py +++ b/SoftLayer/config.py @@ -61,7 +61,7 @@ def get_client_settings_config_file(**kwargs): config.read(config_files) if not config.has_section('softlayer'): - return + raise KeyError("Softlayer section not found in config file") return { 'endpoint_url': config.get('softlayer', 'endpoint_url'), diff --git a/SoftLayer/managers/hardware.py b/SoftLayer/managers/hardware.py index e137ee6f3..070f0e38f 100644 --- a/SoftLayer/managers/hardware.py +++ b/SoftLayer/managers/hardware.py @@ -490,7 +490,7 @@ def _get_ids_from_hostname(self, hostname): results = self.list_hardware(hostname=hostname, mask="id") return [result['id'] for result in results] - def _get_ids_from_ip(self, ip): + def _get_ids_from_ip(self, ip): # pylint: disable=inconsistent-return-statements """Returns list of matching hardware IDs for a given ip address.""" try: # Does it look like an ip address? diff --git a/SoftLayer/managers/vs.py b/SoftLayer/managers/vs.py index a83a4f536..8df324187 100644 --- a/SoftLayer/managers/vs.py +++ b/SoftLayer/managers/vs.py @@ -482,6 +482,7 @@ def wait_for_ready(self, instance_id, limit, delay=10, pending=False): return False LOGGER.info('Auto retry in %s seconds', str(min(delay, until - now))) time.sleep(min(delay, until - now)) + return False def verify_create_instance(self, **kwargs): """Verifies an instance creation command. @@ -670,7 +671,7 @@ def _get_ids_from_hostname(self, hostname): results = self.list_instances(hostname=hostname, mask="id") return [result['id'] for result in results] - def _get_ids_from_ip(self, ip_address): + def _get_ids_from_ip(self, ip_address): # pylint: disable=inconsistent-return-statements """List VS ids which match the given ip address.""" try: # Does it look like an ip address? @@ -893,8 +894,8 @@ def _get_upgrade_prices(self, instance_id, include_downgrade_options=True): mask = "mask[%s]" % ','.join(mask) return self.guest.getUpgradeItemPrices(include_downgrade_options, id=instance_id, mask=mask) - def _get_price_id_for_upgrade_option(self, upgrade_prices, option, value, - public=True): + # pylint: disable=inconsistent-return-statements + def _get_price_id_for_upgrade_option(self, upgrade_prices, option, value, public=True): """Find the price id for the option and value to upgrade. This :param list upgrade_prices: Contains all the prices related to a VS upgrade @@ -934,8 +935,8 @@ def _get_price_id_for_upgrade_option(self, upgrade_prices, option, value, else: return price.get('id') - def _get_price_id_for_upgrade(self, package_items, option, value, - public=True): + # pylint: disable=inconsistent-return-statements + def _get_price_id_for_upgrade(self, package_items, option, value, public=True): """Find the price id for the option and value to upgrade. Deprecated in favor of _get_price_id_for_upgrade_option() diff --git a/SoftLayer/shell/completer.py b/SoftLayer/shell/completer.py index 66e5051fb..62602e9e7 100644 --- a/SoftLayer/shell/completer.py +++ b/SoftLayer/shell/completer.py @@ -23,6 +23,7 @@ def get_completions(self, document, complete_event): return _click_autocomplete(self.root, document.text_before_cursor) +# pylint: disable=stop-iteration-return def _click_autocomplete(root, text): """Completer generator for click applications.""" try: @@ -41,8 +42,7 @@ def _click_autocomplete(root, text): continue for opt in itertools.chain(param.opts, param.secondary_opts): if opt.startswith(incomplete): - yield completion.Completion(opt, -len(incomplete), - display_meta=param.help) + yield completion.Completion(opt, -len(incomplete), display_meta=param.help) elif isinstance(location, (click.MultiCommand, click.core.Group)): ctx = click.Context(location) @@ -50,8 +50,7 @@ def _click_autocomplete(root, text): for command in commands: if command.startswith(incomplete): cmd = location.get_command(ctx, command) - yield completion.Completion(command, -len(incomplete), - display_meta=cmd.short_help) + yield completion.Completion(command, -len(incomplete), display_meta=cmd.short_help) def _click_resolve_command(root, parts): From 8594fa0030a6edf7a2ab8d209525660effec2a3f Mon Sep 17 00:00:00 2001 From: Christopher Gallo Date: Fri, 15 Dec 2017 13:26:51 -0600 Subject: [PATCH 2/2] pylint fixes and @retry to a few functions in vs and hw managers --- SoftLayer/config.py | 20 +++++++++----------- SoftLayer/managers/hardware.py | 10 ++++++++++ SoftLayer/managers/vs.py | 4 ++++ 3 files changed, 23 insertions(+), 11 deletions(-) diff --git a/SoftLayer/config.py b/SoftLayer/config.py index c69e8311a..6301ff3a0 100644 --- a/SoftLayer/config.py +++ b/SoftLayer/config.py @@ -42,7 +42,7 @@ def get_client_settings_env(**_): } -def get_client_settings_config_file(**kwargs): +def get_client_settings_config_file(**kwargs): # pylint: disable=inconsistent-return-statements """Retrieve client settings from the possible config file locations. :param \\*\\*kwargs: Arguments that are passed into the client instance @@ -60,16 +60,14 @@ def get_client_settings_config_file(**kwargs): }) config.read(config_files) - if not config.has_section('softlayer'): - raise KeyError("Softlayer section not found in config file") - - return { - 'endpoint_url': config.get('softlayer', 'endpoint_url'), - 'timeout': config.getfloat('softlayer', 'timeout'), - 'proxy': config.get('softlayer', 'proxy'), - 'username': config.get('softlayer', 'username'), - 'api_key': config.get('softlayer', 'api_key'), - } + if config.has_section('softlayer'): + return { + 'endpoint_url': config.get('softlayer', 'endpoint_url'), + 'timeout': config.getfloat('softlayer', 'timeout'), + 'proxy': config.get('softlayer', 'proxy'), + 'username': config.get('softlayer', 'username'), + 'api_key': config.get('softlayer', 'api_key'), + } SETTING_RESOLVERS = [get_client_settings_args, diff --git a/SoftLayer/managers/hardware.py b/SoftLayer/managers/hardware.py index 070f0e38f..f6fcf68fc 100644 --- a/SoftLayer/managers/hardware.py +++ b/SoftLayer/managers/hardware.py @@ -5,11 +5,17 @@ :license: MIT, see LICENSE for more details. """ +import logging import socket import SoftLayer +from SoftLayer.decoration import retry +from SoftLayer import exceptions from SoftLayer.managers import ordering from SoftLayer import utils + +LOGGER = logging.getLogger(__name__) + # Invalid names are ignored due to long method names and short argument names # pylint: disable=invalid-name, no-self-use @@ -82,6 +88,7 @@ def cancel_hardware(self, hardware_id, reason='unneeded', comment='', immediate, False, cancel_reason, comment, id=billing_id) + @retry(exceptions.SoftLayerAPIError, logger=LOGGER) def list_hardware(self, tags=None, cpus=None, memory=None, hostname=None, domain=None, datacenter=None, nic_speed=None, public_ip=None, private_ip=None, **kwargs): @@ -169,6 +176,7 @@ def list_hardware(self, tags=None, cpus=None, memory=None, hostname=None, kwargs['filter'] = _filter.to_dict() return self.account.getHardware(**kwargs) + @retry(exceptions.SoftLayerAPIError, logger=LOGGER) def get_hardware(self, hardware_id, **kwargs): """Get details about a hardware device. @@ -335,6 +343,7 @@ def get_cancellation_reasons(self): 'moving': 'Moving to competitor', } + @retry(exceptions.SoftLayerAPIError, logger=LOGGER) def get_create_options(self): """Returns valid options for ordering hardware.""" @@ -395,6 +404,7 @@ def get_create_options(self): 'extras': extras, } + @retry(exceptions.SoftLayerAPIError, logger=LOGGER) def _get_package(self): """Get the package related to simple hardware ordering.""" mask = ''' diff --git a/SoftLayer/managers/vs.py b/SoftLayer/managers/vs.py index 8df324187..c0456a87b 100644 --- a/SoftLayer/managers/vs.py +++ b/SoftLayer/managers/vs.py @@ -58,6 +58,7 @@ def __init__(self, client, ordering_manager=None): else: self.ordering_manager = ordering_manager + @retry(exceptions.SoftLayerAPIError, logger=LOGGER) def list_instances(self, hourly=True, monthly=True, tags=None, cpus=None, memory=None, hostname=None, domain=None, local_disk=None, datacenter=None, nic_speed=None, @@ -161,6 +162,7 @@ def list_instances(self, hourly=True, monthly=True, tags=None, cpus=None, func = getattr(self.account, call) return func(**kwargs) + @retry(exceptions.SoftLayerAPIError, logger=LOGGER) def get_instance(self, instance_id, **kwargs): """Get details about a virtual server instance. @@ -235,6 +237,7 @@ def get_instance(self, instance_id, **kwargs): return self.guest.getObject(id=instance_id, **kwargs) + @retry(exceptions.SoftLayerAPIError, logger=LOGGER) def get_create_options(self): """Retrieves the available options for creating a VS. @@ -411,6 +414,7 @@ def _generate_create_dict( return data + @retry(exceptions.SoftLayerAPIError, logger=LOGGER) def wait_for_transaction(self, instance_id, limit, delay=10): """Waits on a VS transaction for the specified amount of time.