diff --git a/.pylintrc b/.pylintrc index 338b361f9..ea1ba7bd2 100644 --- a/.pylintrc +++ b/.pylintrc @@ -17,8 +17,6 @@ disable = import-error, inconsistent-return-statements, invalid-name, - logging-format-interpolation, - logging-not-lazy, lost-exception, missing-class-docstring, missing-function-docstring, diff --git a/tripleo_common/inventory.py b/tripleo_common/inventory.py index bf87d6251..71868f3ea 100644 --- a/tripleo_common/inventory.py +++ b/tripleo_common/inventory.py @@ -154,7 +154,7 @@ class TripleoInventory(object): stack = self.hclient.stacks.get(self.plan_name) except HTTPNotFound: LOG.warning("Stack not found: %s. Only the undercloud will " - "be added to the inventory." % self.plan_name) + "be added to the inventory.", self.plan_name) stack = None return stack diff --git a/tripleo_common/tests/utils/test_template.py b/tripleo_common/tests/utils/test_template.py index d67b216eb..2bf3a9777 100644 --- a/tripleo_common/tests/utils/test_template.py +++ b/tripleo_common/tests/utils/test_template.py @@ -552,47 +552,47 @@ class ProcessTemplatesTest(base.TestCase): self.assertEqual(expected, role_data) mock_log.assert_has_calls([ mock.call.warning( - "DEPRECATED: Role 'CephStorageFoo' without the 'ceph' tag " + "DEPRECATED: Role '%s' without the 'ceph' tag " "detected, the tag was added automatically. Please add the " "'ceph' tag in roles data. The function to automatically " "add tags based on role name will be removed in the next " - "release."), + "release.", "CephStorageFoo"), mock.call.warning( - "DEPRECATED: Role 'CephStorageFoo' without the 'storage' " + "DEPRECATED: Role '%s' without the 'storage' " "tag detected, the tag was added automatically. Please add " "the 'storage' tag in roles data. The function to " "automatically add tags based on role name will be removed in " - "the next release."), + "the next release.", "CephStorageFoo"), mock.call.warning( - "DEPRECATED: Role 'ObjectStorageFoo' without the 'storage' " + "DEPRECATED: Role '%s' without the 'storage' " "tag detected, the tag was added automatically. Please add " "the 'storage' tag in roles data. The function to " "automatically add tags based on role name will be " - "removed in the next release."), + "removed in the next release.", "ObjectStorageFoo"), mock.call.warning( - "DEPRECATED: Role 'BlockStorageFoo' without the 'storage' tag " + "DEPRECATED: Role '%s' without the 'storage' tag " "detected, the tag was added automatically. Please add " "the 'storage' tag in roles data. The function to " "automatically add tags based on role name will be removed " - "in the next release."), + "in the next release.", "BlockStorageFoo"), mock.call.warning( - "DEPRECATED: Role 'ComputeOvsDpdkFoo' without the 'compute' " + "DEPRECATED: Role '%s' without the 'compute' " "tag detected, the tag was added automatically. Please add " "the 'compute' tag in roles data. The function to " "automatically add tags based on role name will be removed in " - "the next release."), + "the next release.", "ComputeOvsDpdkFoo"), mock.call.warning( - "DEPRECATED: Role 'ComputeOvsDpdkFoo' without the 'ovsdpdk' " + "DEPRECATED: Role '%s' without the 'ovsdpdk' " "tag detected, the tag was added automatically. Please add " "the 'ovsdpdk' tag in roles data. The function to " "automatically add tags based on role name will be removed in " - "the next release."), + "the next release.", "ComputeOvsDpdkFoo"), mock.call.warning( - "DEPRECATED: Role 'ComputeOvsDpdkBar' without the 'compute' " + "DEPRECATED: Role '%s' without the 'compute' " "tag detected, the tag was added automatically. Please add " "the 'compute' tag in roles data. The function to " "automatically add tags based on role name will be removed in " - "the next release."), + "the next release.", "ComputeOvsDpdkBar"), ]) diff --git a/tripleo_common/utils/config.py b/tripleo_common/utils/config.py index 6c4430263..5b8467344 100644 --- a/tripleo_common/utils/config.py +++ b/tripleo_common/utils/config.py @@ -179,12 +179,12 @@ class Config(object): def snapshot_config_dir(self, repo, commit_message): if repo.is_dirty(untracked_files=True): - self.log.info('Snapshotting {}'.format(repo.working_dir)) + self.log.info('Snapshotting %s', repo.working_dir) # Use repo.git.add directly as repo.index.add defaults to forcing # commit of ignored files, which we don't want. repo.git.add('.') commit = repo.index.commit(commit_message) - self.log.info('Created commit {}'.format(commit.hexsha)) + self.log.info('Created commit %s', commit.hexsha) else: self.log.info('No changes to commit') @@ -201,8 +201,8 @@ class Config(object): # Create config directory if os.path.exists(config_dir) and preserve_config_dir is False: try: - self.log.info("Directory %s already exists, removing" - % config_dir) + self.log.info("Directory %s already exists, removing", + config_dir) shutil.rmtree(config_dir) except OSError as e: message = 'Failed to remove: %s, error: %s' % (config_dir, @@ -220,8 +220,8 @@ class Config(object): try: yaml.safe_load(template_data) except (yaml.scanner.ScannerError, yaml.YAMLError) as e: - self.log.error("Config for file {} contains invalid yaml, got " - "error {}".format(yaml_file, e)) + self.log.error("Config for file %s contains invalid yaml, got " + "error %s", yaml_file, e) raise e def render_network_config(self, config_dir): @@ -427,7 +427,7 @@ class Config(object): []).append(config_dict) except KeyError: self.log.warning('Server with id %s is ignored from config ' - '(may be blacklisted)' % server_id) + '(may be blacklisted)', server_id) # continue the loop as this server_id is probably excluded continue except Exception as err: @@ -567,7 +567,7 @@ class Config(object): os.path.join(config_dir, 'deployments.yaml')) self.log.info("The TripleO configuration has been successfully " - "generated into: %s" % config_dir) + "generated into: %s", config_dir) return config_dir def download_config(self, name, config_dir, config_type=None, @@ -582,7 +582,7 @@ class Config(object): self._mkdir(config_dir) git_repo = self.initialize_git_repo(config_dir) self.log.info("Generating configuration under the directory: " - "%s" % config_dir) + "%s", config_dir) self.write_config(stack, name, config_dir, config_type) self.snapshot_config_dir(git_repo, commit_message) return config_dir diff --git a/tripleo_common/utils/nodes.py b/tripleo_common/utils/nodes.py index 680c0b264..f57853b92 100644 --- a/tripleo_common/utils/nodes.py +++ b/tripleo_common/utils/nodes.py @@ -395,8 +395,9 @@ def register_ironic_node(node, client): ironic_node = client.node.create(**create_map) for port in node.get('ports', []): - LOG.debug('Creating Bare Metal port for node: %s, with properties: %s.' - % (ironic_node.uuid, port)) + LOG.debug( + 'Creating Bare Metal port for node: %s, with properties: %s.', + ironic_node.uuid, port) client.port.create( address=port.get('address'), physical_network=port.get('physical_network', 'ctlplane'), @@ -527,10 +528,10 @@ def _clean_up_extra_nodes(seen, client, remove=False): extra_nodes = all_nodes - {n.uuid for n in seen} for node in extra_nodes: if remove: - LOG.debug('Removing extra registered node %s.' % node) + LOG.debug('Removing extra registered node %s.', node) remove_func(node) else: - LOG.debug('Extra registered node %s found.' % node) + LOG.debug('Extra registered node %s found.', node) def register_all_nodes(nodes_list, client, remove=False, glance_client=None, diff --git a/tripleo_common/utils/plan.py b/tripleo_common/utils/plan.py index 43502c8de..3bb4834e5 100644 --- a/tripleo_common/utils/plan.py +++ b/tripleo_common/utils/plan.py @@ -289,8 +289,8 @@ def get_role_data(swift, container=constants.DEFAULT_CONTAINER_NAME): constants.OVERCLOUD_J2_ROLES_NAME) role_data = yaml.safe_load(j2_role_file) except swiftexceptions.ClientException: - LOG.info("No %s file found, not filtering container images by role" - % constants.OVERCLOUD_J2_ROLES_NAME) + LOG.info("No %s file found, not filtering container images by role", + constants.OVERCLOUD_J2_ROLES_NAME) role_data = None return role_data @@ -396,7 +396,7 @@ def generate_passwords(swift, heat, mistral=None, env = get_env(swift, container) except swiftexceptions.ClientException as err: err_msg = ("Error retrieving environment for plan %s: %s" % ( - container, err)) + container, err)) # pylint: disable=logging-not-lazy LOG.exception(err_msg) return RuntimeError(err_msg) @@ -412,7 +412,7 @@ def generate_passwords(swift, heat, mistral=None, param_defaults = stack_env.get('parameter_defaults', {}) param_defaults[pw_res] = res.attributes['value'] except heat_exc.HTTPNotFound: - LOG.debug('Heat resouce not found: %s' % pw_res) + LOG.debug('Heat resouce not found: %s', pw_res) pass except heat_exc.HTTPNotFound: diff --git a/tripleo_common/utils/swift.py b/tripleo_common/utils/swift.py index b889331b0..5ffbb0fcf 100644 --- a/tripleo_common/utils/swift.py +++ b/tripleo_common/utils/swift.py @@ -157,8 +157,9 @@ def create_and_upload_tarball(swiftservice, LOG.info(r['object']) elif 'for_object' in r: LOG.info( - '%s segment %s' % (r['for_object'], - r['segment_index']) + '%s segment %s', + r['for_object'], + r['segment_index'] ) else: error = r['error'] @@ -169,11 +170,11 @@ def create_and_upload_tarball(swiftservice, ) elif r['action'] == "upload_object": LOG.error( - "Failed to upload object %s to container %s: %s" % - (container, r['object'], error) + "Failed to upload object %s to container %s: %s", + container, r['object'], error ) else: - LOG.error("%s" % error) + LOG.error("%s", error) except SwiftError as e: LOG.error(e.value) diff --git a/tripleo_common/utils/tarball.py b/tripleo_common/utils/tarball.py index bf21fcbde..8eeaa4bdd 100644 --- a/tripleo_common/utils/tarball.py +++ b/tripleo_common/utils/tarball.py @@ -24,7 +24,7 @@ DEFAULT_TARBALL_EXCLUDES = ['.git', '.tox', '*.pyc', '*.pyo'] def create_tarball(directory, filename, options='-czf', excludes=DEFAULT_TARBALL_EXCLUDES): """Create a tarball of a directory.""" - LOG.debug('Creating tarball of %s at location %s' % (directory, filename)) + LOG.debug('Creating tarball of %s at location %s', directory, filename) cmd = ['/usr/bin/tar', '-C', directory, options, filename] for x in excludes: cmd.extend(['--exclude', x]) @@ -33,8 +33,8 @@ def create_tarball(directory, filename, options='-czf', def tarball_extract_to_swift_container(object_client, filename, container): - LOG.debug('Uploading filename %s to Swift container %s' % (filename, - container)) + LOG.debug('Uploading filename %s to Swift container %s', + filename, container) with open(filename, 'rb') as f: object_client.put_object( container=container, @@ -49,11 +49,11 @@ def extract_tarball(directory, tarball, options='-xf', remove=False): """Extracts the tarball contained in the directory.""" full_path = directory + '/' + tarball if not os.path.exists(full_path): - LOG.debug('Tarball %s does not exist' % full_path) + LOG.debug('Tarball %s does not exist', full_path) else: - LOG.debug('Extracting tarball %s' % full_path) + LOG.debug('Extracting tarball %s', full_path) cmd = ['/usr/bin/tar', '-C', directory, options, full_path] processutils.execute(*cmd) if remove: - LOG.debug('Removing tarball %s' % full_path) + LOG.debug('Removing tarball %s', full_path) os.remove(full_path) diff --git a/tripleo_common/utils/template.py b/tripleo_common/utils/template.py index 1d8f8d7ad..498952d21 100644 --- a/tripleo_common/utils/template.py +++ b/tripleo_common/utils/template.py @@ -85,12 +85,12 @@ def j2_render_and_put(swift, j2_template, j2_data, yaml_f, try: # write the template back to the plan container - LOG.info("Writing rendered template %s" % yaml_f) + LOG.info("Writing rendered template %s", yaml_f) swiftutils.put_object_string(swift, container, yaml_f, r_template) except swiftexceptions.ClientException: - error_msg = ("Error storing file %s in container %s" - % (yaml_f, container)) + error_msg = ("Error storing file %s in container %s", + yaml_f, container) LOG.error(error_msg) raise RuntimeError(error_msg) @@ -104,11 +104,11 @@ def get_j2_excludes_file(swift, container=constants.DEFAULT_CONTAINER_NAME): j2_excl_data = {"name": []} LOG.info("j2_excludes.yaml is either empty or there are " "no templates to exclude, defaulting the J2 " - "excludes list to: %s" % j2_excl_data) + "excludes list to: %s", j2_excl_data) except swiftexceptions.ClientException: j2_excl_data = {"name": []} LOG.info("No J2 exclude file found, defaulting " - "the J2 excludes list to: %s" % j2_excl_data) + "the J2 excludes list to: %s", j2_excl_data) return j2_excl_data @@ -121,18 +121,18 @@ def heat_resource_exists(heat, stack, nested_stack_name, resource_name): nested_stack = heat.resources.get(stack.id, nested_stack_name) except heat_exc.HTTPNotFound: LOG.debug( - "Resource does not exist because {} stack does " - "not exist".format(nested_stack_name)) + "Resource does not exist because %s stack does " + "not exist", nested_stack_name) return False try: heat.resources.get(nested_stack.physical_resource_id, resource_name) except heat_exc.HTTPNotFound: - LOG.debug("Resource does not exist: {}".format(resource_name)) + LOG.debug("Resource does not exist: %s", resource_name) return False else: - LOG.debug("Resource exists: {}".format(resource_name)) + LOG.debug("Resource exists: %s", resource_name) return True @@ -149,14 +149,14 @@ def _set_tags_based_on_role_name(role_data): "detected, the tag was added automatically. Please " "add the 'compute' tag in roles data. The function to " "automatically add tags based on role name will be " - "removed in the next release." % role_name) + "removed in the next release.", role_name) if role_name.startswith('Ceph') and 'ceph' not in role['tags']: role['tags'].append('ceph') LOG.warning("DEPRECATED: Role '%s' without the 'ceph' tag " "detected, the tag was added automatically. Please " "add the 'ceph' tag in roles data. The function to " "automatically add tags based on role name will be " - "removed in the next release." % role_name) + "removed in the next release.", role_name) if (role_name.startswith('ComputeOvsDpdk') and 'ovsdpdk' not in role['tags']): role['tags'].append('ovsdpdk') @@ -164,7 +164,7 @@ def _set_tags_based_on_role_name(role_data): "detected, the tag was added automatically. Please " "add the 'ovsdpdk' tag in roles data. The function to " "automatically add tags based on role name will be " - "removed in the next release." % role_name) + "removed in the next release.", role_name) if ((role_name.startswith('ObjectStorage') or role_name.startswith('BlockStorage') or role_name.startswith('Ceph')) @@ -174,7 +174,7 @@ def _set_tags_based_on_role_name(role_data): "detected, the tag was added automatically. Please " "add the 'storage' tag in roles data. The function to " "automatically add tags based on role name will be " - "removed in the next release." % role_name) + "removed in the next release.", role_name) def process_custom_roles(swift, heat, @@ -184,8 +184,8 @@ def process_custom_roles(swift, heat, swift, container, constants.OVERCLOUD_J2_ROLES_NAME) role_data = yaml.safe_load(j2_role_file) except swiftexceptions.ClientException: - LOG.info("No %s file found, skipping jinja templating" - % constants.OVERCLOUD_J2_ROLES_NAME) + LOG.info("No %s file found, skipping jinja templating", + constants.OVERCLOUD_J2_ROLES_NAME) return try: @@ -197,8 +197,8 @@ def process_custom_roles(swift, heat, network_data = [] except swiftexceptions.ClientException: # Until t-h-t contains network_data.yaml we tolerate a missing file - LOG.warning("No %s file found, ignoring" - % constants.OVERCLOUD_J2_ROLES_NAME) + LOG.warning("No %s file found, ignoring", + constants.OVERCLOUD_J2_ROLES_NAME) network_data = [] j2_excl_data = get_j2_excludes_file(swift, container) @@ -208,8 +208,8 @@ def process_custom_roles(swift, heat, # we j2 render any with the .j2.yaml suffix container_files = swift.get_container(container) except swiftexceptions.ClientException as ex: - error_msg = ("Error listing contents of container %s : %s" - % (container, six.text_type(ex))) + error_msg = ("Error listing contents of container %s : %s", + container, six.text_type(ex)) LOG.error(error_msg) raise RuntimeError(error_msg) @@ -245,7 +245,7 @@ def process_custom_roles(swift, heat, LOG.info("Upgrade compatibility enabled for legacy " "network resource Internal.") else: - LOG.info("skipping %s network: network is disabled." % + LOG.info("skipping %s network: network is disabled.", n.get('name')) plan_utils.cache_delete(swift, container, "tripleo.parameters.get") @@ -260,13 +260,13 @@ def process_custom_roles(swift, heat, # 3. *.j2.yaml - we template with all roles_data, # and create one file common to all roles if f.endswith('.role.j2.yaml'): - LOG.info("jinja2 rendering role template %s" % f) + LOG.info("jinja2 rendering role template %s", f) j2_template = swiftutils.get_object_string(swift, container, f) - LOG.info("jinja2 rendering roles %s" % "," + LOG.info("jinja2 rendering roles %s", "," .join(role_names)) for role in role_names: - LOG.info("jinja2 rendering role %s" % role) + LOG.info("jinja2 rendering role %s", role) out_f = "-".join( [role.lower(), os.path.basename(f).replace('.role.j2.yaml', @@ -290,20 +290,20 @@ def process_custom_roles(swift, heat, # Backwards compatibility with templates # that specify {{role}} vs {{role.name}} j2_data = {'role': role, 'networks': network_data} - LOG.debug("role legacy path for role %s" % role) + LOG.debug("role legacy path for role %s", role) j2_render_and_put(swift, j2_template, j2_data, out_f_path, container) else: - LOG.info("Skipping rendering of %s, defined in %s" % - (out_f_path, j2_excl_data)) + LOG.info("Skipping rendering of %s, defined in %s", + out_f_path, j2_excl_data) elif (f.endswith('.network.j2.yaml')): - LOG.info("jinja2 rendering network template %s" % f) + LOG.info("jinja2 rendering network template %s", f) j2_template = swiftutils.get_object_string(swift, container, f) - LOG.info("jinja2 rendering networks %s" % ",".join(n_map)) + LOG.info("jinja2 rendering networks %s", ",".join(n_map)) for network in n_map: j2_data = {'network': n_map[network]} # Output file names in ".yaml" format @@ -321,11 +321,11 @@ def process_custom_roles(swift, heat, j2_data, out_f_path, container) else: - LOG.info("Skipping rendering of %s, defined in %s" % - (out_f_path, j2_excl_data)) + LOG.info("Skipping rendering of %s, defined in %s", + out_f_path, j2_excl_data) elif f.endswith('.j2.yaml'): - LOG.info("jinja2 rendering %s" % f) + LOG.info("jinja2 rendering %s", f) j2_template = swiftutils.get_object_string(swift, container, f) @@ -367,8 +367,7 @@ def prune_unused_services(swift, role_data, for service in to_remove: try: role.get('ServicesDefault', []).remove(service) - LOG.debug('Removing {} from {} role'.format( - service, role_name)) + LOG.debug('Removing %s from %s role', service, role_name) except ValueError: pass LOG.debug('Saving updated role data to swift') @@ -404,13 +403,13 @@ def build_heat_args(swift, heat, container=constants.DEFAULT_CONTAINER_NAME): template_object = os.path.join(swift.url, container, template_name) - LOG.debug('Template: %s' % template_name) + LOG.debug('Template: %s', template_name) try: template_files, template = plan_utils.get_template_contents( swift, template_object) except Exception as err: error_text = six.text_type(err) - LOG.exception("Error occurred while fetching %s" % template_object) + LOG.exception("Error occurred while fetching %s", template_object) temp_env_paths = [] try: