diff --git a/.pylintrc b/.pylintrc index b3669826b..779e8a8c5 100644 --- a/.pylintrc +++ b/.pylintrc @@ -31,7 +31,6 @@ disable = no-else-break, no-else-continue, no-else-raise, - no-else-return, no-member, no-self-use, no-value-for-parameter, diff --git a/tripleoclient/command.py b/tripleoclient/command.py index edccc6852..255b37bbb 100644 --- a/tripleoclient/command.py +++ b/tripleoclient/command.py @@ -90,8 +90,8 @@ class Command(command.Command): 'the --overcloud-ssh-key switch.' ) return key - else: - return parsed_args.overcloud_ssh_key + + return parsed_args.overcloud_ssh_key class Lister(Command, command.Lister): diff --git a/tripleoclient/tests/v1/overcloud_deploy/test_overcloud_deploy.py b/tripleoclient/tests/v1/overcloud_deploy/test_overcloud_deploy.py index 6a7a9893c..94e0b1c75 100644 --- a/tripleoclient/tests/v1/overcloud_deploy/test_overcloud_deploy.py +++ b/tripleoclient/tests/v1/overcloud_deploy/test_overcloud_deploy.py @@ -1683,8 +1683,7 @@ class TestArgumentValidation(fakes.TestDeployOvercloud): def is_dir(arg): if arg == '/tmp/real_dir': return True - else: - return False + return False patcher = mock.patch('os.path.isdir') mock_isdir = patcher.start() diff --git a/tripleoclient/tests/v1/tripleo/test_tripleo_deploy.py b/tripleoclient/tests/v1/tripleo/test_tripleo_deploy.py index 20197ef96..edac05859 100644 --- a/tripleoclient/tests/v1/tripleo/test_tripleo_deploy.py +++ b/tripleoclient/tests/v1/tripleo/test_tripleo_deploy.py @@ -589,10 +589,9 @@ class TestDeployUndercloud(TestPluginV1): def abs_path_stub(*args, **kwargs): if 'notenv.yaml' in args: return os.path.join(tht_render, 'notenv.yaml') - elif 'env.yaml' in args: + if 'env.yaml' in args: return os.path.join(tht_render, 'env.yaml') - else: - return original_abs(*args, **kwargs) + return original_abs(*args, **kwargs) # logic handled in _standalone_deploy self.cmd.output_dir = tht_to diff --git a/tripleoclient/utils.py b/tripleoclient/utils.py index ac02d3fe4..f8cf2909e 100644 --- a/tripleoclient/utils.py +++ b/tripleoclient/utils.py @@ -235,11 +235,9 @@ def playbook_verbosity(self): if self.app.options.debug: return 3 - else: - if self.app_args.verbose_level <= 1: - return 0 - else: - return self.app_args.verbose_level + if self.app_args.verbose_level <= 1: + return 0 + return self.app_args.verbose_level def run_ansible_playbook(playbook, inventory, workdir, playbook_dir=None, @@ -377,8 +375,7 @@ def run_ansible_playbook(playbook, inventory, workdir, playbook_dir=None, if timeout and timeout > 0: return ('Running Ansible playbook with timeout %sm: %s,' % (timeout, playbook)) - else: - return ('Running Ansible playbook: %s,' % playbook) + return ('Running Ansible playbook: %s,' % playbook) if not playbook_dir: playbook_dir = workdir @@ -736,12 +733,11 @@ def convert(data): """Recursively converts dictionary keys,values to strings.""" if isinstance(data, six.string_types): return str(data) - elif isinstance(data, collectionsAbc.Mapping): + if isinstance(data, collectionsAbc.Mapping): return dict(map(convert, six.iteritems(data))) - elif isinstance(data, collectionsAbc.Iterable): + if isinstance(data, collectionsAbc.Iterable): return type(data)(map(convert, data)) - else: - return data + return data def bracket_ipv6(address): @@ -1019,8 +1015,7 @@ def get_endpoint(key, stack): endpoint_map = get_endpoint_map(stack) if endpoint_map: return endpoint_map[key]['host'] - else: - return get_service_ips(stack).get(key + 'Vip') + return get_service_ips(stack).get(key + 'Vip') def get_stack(orchestration_client, stack_name): @@ -1506,16 +1501,15 @@ def prompt_user_for_confirmation(message, logger, positive_response='y'): if not sys.stdin.isatty(): logger.error(_('User interaction required, cannot confirm.')) return False - else: - sys.stdout.write(message) - sys.stdout.flush() - prompt_response = sys.stdin.readline().lower() - if not prompt_response.startswith(positive_response): - logger.info(_( - 'User did not confirm action so taking no action.')) - return False - logger.info(_('User confirmed action.')) - return True + sys.stdout.write(message) + sys.stdout.flush() + prompt_response = sys.stdin.readline().lower() + if not prompt_response.startswith(positive_response): + logger.info(_( + 'User did not confirm action so taking no action.')) + return False + logger.info(_('User confirmed action.')) + return True except KeyboardInterrupt: # ctrl-c logger.info(_( 'User did not confirm action (ctrl-c) so taking no action.')) @@ -1564,8 +1558,7 @@ def replace_links_in_template(template_part, link_replacement): if ((key == 'get_file' or key == 'type') and isinstance(value, six.string_types)): return link_replacement.get(value, value) - else: - return replace_links_in_template(value, link_replacement) + return replace_links_in_template(value, link_replacement) def replaced_list_value(value): return replace_links_in_template(value, link_replacement) @@ -1573,10 +1566,9 @@ def replace_links_in_template(template_part, link_replacement): if isinstance(template_part, dict): return {k: replaced_dict_value(k, v) for k, v in six.iteritems(template_part)} - elif isinstance(template_part, list): + if isinstance(template_part, list): return list(map(replaced_list_value, template_part)) - else: - return template_part + return template_part def relative_link_replacement(link_replacement, current_dir): @@ -1680,9 +1672,9 @@ def get_tripleo_ansible_inventory(inventory_file=None, with open(inventory_file, "r") as f: inventory = f.read() return inventory - else: - raise exceptions.InvalidConfiguration(_( - "Inventory file %s can not be found.") % inventory_file) + + raise exceptions.InvalidConfiguration(_( + "Inventory file %s can not be found.") % inventory_file) def cleanup_tripleo_ansible_inventory_file(path): @@ -2051,8 +2043,7 @@ def run_command_and_log(log, cmd, cwd=None, env=None, retcode_only=True): break proc.stdout.close() return proc.wait() - else: - return proc + return proc def build_prepare_env(environment_files, environment_directories): @@ -2647,10 +2638,9 @@ def test_heat_api_port(heat_api_socket, host, port): def get_heat_launcher(heat_type, *args, **kwargs): if heat_type == 'native': return heat_launcher.HeatNativeLauncher(*args, **kwargs) - elif heat_type == 'container': + if heat_type == 'container': return heat_launcher.HeatContainerLauncher(*args, **kwargs) - else: - return heat_launcher.HeatPodLauncher(*args, **kwargs) + return heat_launcher.HeatPodLauncher(*args, **kwargs) def kill_heat(launcher): diff --git a/tripleoclient/v1/overcloud_backup.py b/tripleoclient/v1/overcloud_backup.py index d03a0f82c..6d0ca4146 100644 --- a/tripleoclient/v1/overcloud_backup.py +++ b/tripleoclient/v1/overcloud_backup.py @@ -121,7 +121,7 @@ class BackupOvercloud(command.Command): def _parse_extra_vars(self, raw_extra_vars): if raw_extra_vars is None: - return {} + extra_vars = {} elif os.path.exists(raw_extra_vars): with open(raw_extra_vars, 'r') as fp: extra_vars = yaml.safe_load(fp.read()) diff --git a/tripleoclient/v1/overcloud_image.py b/tripleoclient/v1/overcloud_image.py index b23afa207..3e8663650 100644 --- a/tripleoclient/v1/overcloud_image.py +++ b/tripleoclient/v1/overcloud_image.py @@ -206,7 +206,7 @@ class FileImageClientAdapter(BaseClientAdapter): if os.path.exists(path.replace("file://", "")): return path return None - elif prop == 'ramdisk_id': + if prop == 'ramdisk_id': path = os.path.splitext(image.id)[0] + '.initrd' if os.path.exists(path.replace("file://", "")): return path @@ -267,15 +267,12 @@ class FileImageClientAdapter(BaseClientAdapter): if self.updated is not None: self.updated.append(dest_path) return None - else: - print('Image "%s" already exists and can be updated' - ' with --update-existing.' % dest_path) - return image - else: - print('Image "%s" is up-to-date, skipping.' % dest_path) + print('Image "%s" already exists and can be updated' + ' with --update-existing.' % dest_path) return image - else: - return None + print('Image "%s" is up-to-date, skipping.' % dest_path) + return image + return None def _upload_image(self, src_path, dest_path): dest_dir = os.path.split(dest_path)[0] @@ -337,15 +334,12 @@ class GlanceClientAdapter(BaseClientAdapter): if self.updated is not None: self.updated.append(image.id) return None - else: - print('Image "%s" already exists and can be updated' - ' with --update-existing.' % image_name) - return image - else: - print('Image "%s" is up-to-date, skipping.' % image_name) + print('Image "%s" already exists and can be updated' + ' with --update-existing.' % image_name) return image - else: - return None + print('Image "%s" is up-to-date, skipping.' % image_name) + return image + return None def _upload_image(self, name, data, properties=None, visibility='public', disk_format='raw', container_format='bare'): diff --git a/tripleoclient/v1/tripleo_deploy.py b/tripleoclient/v1/tripleo_deploy.py index b090eac1e..c623eea36 100644 --- a/tripleoclient/v1/tripleo_deploy.py +++ b/tripleoclient/v1/tripleo_deploy.py @@ -188,8 +188,7 @@ class Deploy(command.Command): if not parsed_args.networks_file: return os.path.join(parsed_args.templates, constants.STANDALONE_NETWORKS_FILE) - else: - return parsed_args.networks_file + return parsed_args.networks_file def _get_primary_role_name(self, roles_file_path, templates): """Return the primary role name""" diff --git a/tripleoclient/v1/undercloud_backup.py b/tripleoclient/v1/undercloud_backup.py index 43b682408..96e4514ab 100644 --- a/tripleoclient/v1/undercloud_backup.py +++ b/tripleoclient/v1/undercloud_backup.py @@ -155,11 +155,10 @@ class BackupUndercloud(command.Command): def _parse_extra_vars(self, raw_extra_vars): if raw_extra_vars is None: - return raw_extra_vars + extra_vars = None elif os.path.exists(raw_extra_vars): with open(raw_extra_vars, 'r') as fp: extra_vars = yaml.safe_load(fp.read()) - else: try: extra_vars = yaml.safe_load(raw_extra_vars) diff --git a/tripleoclient/v1/undercloud_config.py b/tripleoclient/v1/undercloud_config.py index 7a32fd0f7..bf9cd9a59 100644 --- a/tripleoclient/v1/undercloud_config.py +++ b/tripleoclient/v1/undercloud_config.py @@ -122,8 +122,7 @@ def _get_unknown_instack_tags(env, src): known_tags = set(INSTACK_NETCONF_MAPPING.keys()) if found_tags <= known_tags: return (', ').join(found_tags - known_tags) - else: - return None + return None def _process_drivers_and_hardware_types(conf, env): diff --git a/tripleoclient/v2/tripleo_container_image.py b/tripleoclient/v2/tripleo_container_image.py index 6050b6700..e8dc685fa 100644 --- a/tripleoclient/v2/tripleo_container_image.py +++ b/tripleoclient/v2/tripleo_container_image.py @@ -268,8 +268,7 @@ class Build(command.Command): if content: if tree: return {tree: content} - else: - return content + return content return tree diff --git a/tripleoclient/workflows/baremetal.py b/tripleoclient/workflows/baremetal.py index 861790f47..a779c6df1 100644 --- a/tripleoclient/workflows/baremetal.py +++ b/tripleoclient/workflows/baremetal.py @@ -44,8 +44,7 @@ def validate_nodes(clients, nodes_json): validated_nodes = node_utils.validate_nodes(nodes_json) if not validated_nodes: return True - else: - raise exceptions.RegisterOrUpdateError(validated_nodes) + raise exceptions.RegisterOrUpdateError(validated_nodes) def register_or_update(clients, nodes_json, kernel_name=None,