From 56658ec5f037748a11f107e77fb758fbe7fa8753 Mon Sep 17 00:00:00 2001 From: Brett Holman Date: Mon, 12 Aug 2024 16:47:39 -0600 Subject: [PATCH] chore(black): Bump version (#5607) --- cloudinit/cmd/devel/parser.py | 2 +- cloudinit/config/cc_ansible.py | 1 + cloudinit/config/cc_growpart.py | 6 +-- cloudinit/config/cc_phone_home.py | 4 +- cloudinit/config/cc_resizefs.py | 2 +- cloudinit/config/cc_ssh.py | 2 +- .../config/cc_ssh_authkey_fingerprints.py | 2 +- cloudinit/config/cc_ssh_import_id.py | 2 +- cloudinit/config/cc_users_groups.py | 4 +- cloudinit/config/cc_write_files.py | 2 +- cloudinit/config/cc_yum_add_repo.py | 8 ++-- cloudinit/config/cc_zypper_add_repo.py | 4 +- cloudinit/config/schema.py | 6 +-- cloudinit/distros/aosc.py | 2 +- .../package_management/package_manager.py | 3 +- cloudinit/distros/parsers/hostname.py | 6 +-- cloudinit/distros/parsers/hosts.py | 6 +-- cloudinit/distros/parsers/resolv_conf.py | 6 +-- cloudinit/distros/rhel_util.py | 2 +- cloudinit/helpers.py | 12 +++--- cloudinit/mergers/__init__.py | 4 +- cloudinit/mergers/m_dict.py | 2 +- cloudinit/net/__init__.py | 2 +- cloudinit/net/ephemeral.py | 8 ++-- cloudinit/net/sysconfig.py | 2 +- cloudinit/netinfo.py | 6 +-- cloudinit/safeyaml.py | 6 +-- cloudinit/sources/DataSourceAliYun.py | 1 + cloudinit/sources/DataSourceConfigDrive.py | 4 +- cloudinit/sources/DataSourceEc2.py | 8 ++-- cloudinit/sources/DataSourceGCE.py | 2 +- cloudinit/sources/DataSourceHetzner.py | 2 +- cloudinit/sources/DataSourceLXD.py | 17 +++++---- cloudinit/sources/DataSourceMAAS.py | 2 +- cloudinit/sources/DataSourceScaleway.py | 2 +- cloudinit/sources/DataSourceVultr.py | 6 +-- cloudinit/sources/__init__.py | 6 +-- cloudinit/sources/helpers/ec2.py | 2 +- cloudinit/sources/helpers/openstack.py | 8 ++-- .../sources/helpers/vmware/imc/config_file.py | 2 +- cloudinit/ssh_util.py | 2 +- cloudinit/stages.py | 12 +++--- cloudinit/url_helper.py | 2 +- conftest.py | 1 + tests/integration_tests/bugs/test_gh626.py | 1 + tests/integration_tests/bugs/test_gh632.py | 1 + tests/integration_tests/bugs/test_gh868.py | 1 + .../integration_tests/bugs/test_lp1835584.py | 1 + .../integration_tests/bugs/test_lp1886531.py | 1 + .../integration_tests/bugs/test_lp1898997.py | 1 + .../integration_tests/bugs/test_lp1901011.py | 1 + .../integration_tests/bugs/test_lp1910835.py | 1 + .../integration_tests/bugs/test_lp1912844.py | 1 + tests/integration_tests/cmd/test_schema.py | 1 + tests/integration_tests/cmd/test_status.py | 1 + .../datasources/test_none.py | 1 + .../modules/test_ca_certs.py | 1 + .../modules/test_command_output.py | 1 + .../modules/test_keys_to_console.py | 1 + tests/integration_tests/modules/test_lxd.py | 1 + .../modules/test_ntp_servers.py | 1 + .../integration_tests/modules/test_puppet.py | 1 + .../modules/test_ssh_auth_key_fingerprints.py | 1 + .../modules/test_users_groups.py | 1 + .../modules/test_wireguard.py | 1 + tests/unittests/config/test_cc_seed_random.py | 2 +- tests/unittests/config/test_cc_ubuntu_pro.py | 38 ++++++++++--------- tests/unittests/conftest.py | 2 +- tests/unittests/distros/test_netconfig.py | 6 +-- .../distros/test_user_data_normalize.py | 6 +-- tests/unittests/filters/test_launch_index.py | 2 +- tests/unittests/helpers.py | 10 ++--- tests/unittests/net/test_net_rendering.py | 1 + tests/unittests/sources/test_akamai.py | 6 +-- tests/unittests/sources/test_nocloud.py | 2 +- tests/unittests/sources/test_openstack.py | 2 +- tests/unittests/sources/test_oracle.py | 6 +-- tests/unittests/test_data.py | 6 +-- tests/unittests/test_merging.py | 6 +-- tools/mock-meta.py | 2 +- 80 files changed, 168 insertions(+), 141 deletions(-) diff --git a/cloudinit/cmd/devel/parser.py b/cloudinit/cmd/devel/parser.py index 7ddb8fc74e3..a5dffc010c3 100644 --- a/cloudinit/cmd/devel/parser.py +++ b/cloudinit/cmd/devel/parser.py @@ -39,7 +39,7 @@ def get_parser(parser=None): make_mime.handle_args, ), ] - for (subcmd, helpmsg, get_parser, handler) in subcmds: + for subcmd, helpmsg, get_parser, handler in subcmds: parser = subparsers.add_parser(subcmd, help=helpmsg) get_parser(parser) parser.set_defaults(action=(subcmd, handler)) diff --git a/cloudinit/config/cc_ansible.py b/cloudinit/config/cc_ansible.py index 3b9e931a58d..b14781adf97 100644 --- a/cloudinit/config/cc_ansible.py +++ b/cloudinit/config/cc_ansible.py @@ -1,4 +1,5 @@ """ansible enables running on first boot either ansible-pull""" + import abc import logging import os diff --git a/cloudinit/config/cc_growpart.py b/cloudinit/config/cc_growpart.py index 459f0a3cded..8f2978b0579 100644 --- a/cloudinit/config/cc_growpart.py +++ b/cloudinit/config/cc_growpart.py @@ -65,12 +65,10 @@ def __init__(self, distro: Distro): self._distro = distro @abstractmethod - def available(self, devices: list) -> bool: - ... + def available(self, devices: list) -> bool: ... @abstractmethod - def resize(self, diskdev, partnum, partdev, fs): - ... + def resize(self, diskdev, partnum, partdev, fs): ... class ResizeGrowPart(Resizer): diff --git a/cloudinit/config/cc_phone_home.py b/cloudinit/config/cc_phone_home.py index 50cecc03bd2..b9dc22a4cfb 100644 --- a/cloudinit/config/cc_phone_home.py +++ b/cloudinit/config/cc_phone_home.py @@ -95,7 +95,7 @@ def handle(name: str, cfg: Config, cloud: Cloud, args: list) -> None: "pub_key_ed25519": "/etc/ssh/ssh_host_ed25519_key.pub", } - for (n, path) in pubkeys.items(): + for n, path in pubkeys.items(): try: all_keys[n] = util.load_text_file(path) except Exception: @@ -117,7 +117,7 @@ def handle(name: str, cfg: Config, cloud: Cloud, args: list) -> None: # Get them read to be posted real_submit_keys = {} - for (k, v) in submit_keys.items(): + for k, v in submit_keys.items(): if v is None: real_submit_keys[k] = "N/A" else: diff --git a/cloudinit/config/cc_resizefs.py b/cloudinit/config/cc_resizefs.py index 87d278710b8..70bd4e17f3b 100644 --- a/cloudinit/config/cc_resizefs.py +++ b/cloudinit/config/cc_resizefs.py @@ -293,7 +293,7 @@ def handle(name: str, cfg: Config, cloud: Cloud, args: list) -> None: return fstype_lc = fs_type.lower() - for (pfix, root_cmd) in RESIZE_FS_PREFIXES_CMDS: + for pfix, root_cmd in RESIZE_FS_PREFIXES_CMDS: if fstype_lc.startswith(pfix): resizer = root_cmd break diff --git a/cloudinit/config/cc_ssh.py b/cloudinit/config/cc_ssh.py index 947469b5b6d..4c4f0c33e18 100644 --- a/cloudinit/config/cc_ssh.py +++ b/cloudinit/config/cc_ssh.py @@ -111,7 +111,7 @@ def handle(name: str, cfg: Config, cloud: Cloud, args: list) -> None: if "ssh_keys" in cfg: # if there are keys and/or certificates in cloud-config, use them cert_config = [] - for (key, val) in cfg["ssh_keys"].items(): + for key, val in cfg["ssh_keys"].items(): if key not in CONFIG_KEY_TO_FILE: if pattern_unsupported_config_keys.match(key): reason = "unsupported" diff --git a/cloudinit/config/cc_ssh_authkey_fingerprints.py b/cloudinit/config/cc_ssh_authkey_fingerprints.py index 106b3cbd0c3..8b02789b739 100644 --- a/cloudinit/config/cc_ssh_authkey_fingerprints.py +++ b/cloudinit/config/cc_ssh_authkey_fingerprints.py @@ -112,7 +112,7 @@ def handle(name: str, cfg: Config, cloud: Cloud, args: list) -> None: hash_meth = util.get_cfg_option_str(cfg, "authkey_hash", "sha256") (users, _groups) = ug_util.normalize_users_groups(cfg, cloud.distro) - for (user_name, _cfg) in users.items(): + for user_name, _cfg in users.items(): if _cfg.get("no_create_home") or _cfg.get("system"): LOG.debug( "Skipping printing of ssh fingerprints for user '%s' because " diff --git a/cloudinit/config/cc_ssh_import_id.py b/cloudinit/config/cc_ssh_import_id.py index 8abf3914fc6..7c1422dee3d 100644 --- a/cloudinit/config/cc_ssh_import_id.py +++ b/cloudinit/config/cc_ssh_import_id.py @@ -59,7 +59,7 @@ def handle(name: str, cfg: Config, cloud: Cloud, args: list) -> None: # import for cloudinit created users (users, _groups) = ug_util.normalize_users_groups(cfg, cloud.distro) elist = [] - for (user, user_cfg) in users.items(): + for user, user_cfg in users.items(): import_ids = [] if user_cfg["default"]: import_ids = util.get_cfg_option_list(cfg, "ssh_import_id", []) diff --git a/cloudinit/config/cc_users_groups.py b/cloudinit/config/cc_users_groups.py index ace17733c3a..0f3b2121cf4 100644 --- a/cloudinit/config/cc_users_groups.py +++ b/cloudinit/config/cc_users_groups.py @@ -37,10 +37,10 @@ def handle(name: str, cfg: Config, cloud: Cloud, args: list) -> None: (default_user, _user_config) = ug_util.extract_default(users) cloud_keys = cloud.get_public_ssh_keys() or [] - for (name, members) in groups.items(): + for name, members in groups.items(): cloud.distro.create_group(name, members) - for (user, config) in users.items(): + for user, config in users.items(): no_home = [key for key in NO_HOME if config.get(key)] need_home = [key for key in NEED_HOME if config.get(key)] diff --git a/cloudinit/config/cc_write_files.py b/cloudinit/config/cc_write_files.py index 004ede438d9..c05f227a40b 100644 --- a/cloudinit/config/cc_write_files.py +++ b/cloudinit/config/cc_write_files.py @@ -78,7 +78,7 @@ def write_files(name, files, owner: str, ssl_details: Optional[dict] = None): if not files: return - for (i, f_info) in enumerate(files): + for i, f_info in enumerate(files): path = f_info.get("path") if not path: LOG.warning( diff --git a/cloudinit/config/cc_yum_add_repo.py b/cloudinit/config/cc_yum_add_repo.py index 548c83bab6d..d857d89d30d 100644 --- a/cloudinit/config/cc_yum_add_repo.py +++ b/cloudinit/config/cc_yum_add_repo.py @@ -89,7 +89,7 @@ def _format_repository_config(repo_id, repo_config): to_be = ConfigParser() to_be.add_section(repo_id) # Do basic translation of the items -> values - for (k, v) in repo_config.items(): + for k, v in repo_config.items(): # For now assume that people using this know # the format of yum and don't verify keys/values further to_be.set(repo_id, k, _format_repo_value(v)) @@ -114,7 +114,7 @@ def handle(name: str, cfg: Config, cloud: Cloud, args: list) -> None: ) repo_locations = {} repo_configs = {} - for (repo_id, repo_config) in repos.items(): + for repo_id, repo_config in repos.items(): canon_repo_id = _canonicalize_id(repo_id) repo_fn_pth = os.path.join(repo_base_path, "%s.repo" % (canon_repo_id)) if os.path.exists(repo_fn_pth): @@ -135,7 +135,7 @@ def handle(name: str, cfg: Config, cloud: Cloud, args: list) -> None: repo_config = {} # Do some basic sanity checks/cleaning n_repo_config = {} - for (k, v) in repo_config.items(): + for k, v in repo_config.items(): k = k.lower().strip().replace("-", "_") if k: n_repo_config[k] = v @@ -157,7 +157,7 @@ def handle(name: str, cfg: Config, cloud: Cloud, args: list) -> None: repo_configs[canon_repo_id] = repo_config repo_locations[canon_repo_id] = repo_fn_pth - for (c_repo_id, path) in repo_locations.items(): + for c_repo_id, path in repo_locations.items(): repo_blob = _format_repository_config( c_repo_id, repo_configs.get(c_repo_id) ) diff --git a/cloudinit/config/cc_zypper_add_repo.py b/cloudinit/config/cc_zypper_add_repo.py index 02b372dcc70..fa55e09b07c 100644 --- a/cloudinit/config/cc_zypper_add_repo.py +++ b/cloudinit/config/cc_zypper_add_repo.py @@ -54,7 +54,7 @@ def _format_repository_config(repo_id, repo_config): to_be = configobj.ConfigObj() to_be[repo_id] = {} # Do basic translation of the items -> values - for (k, v) in repo_config.items(): + for k, v in repo_config.items(): # For now assume that people using this know the format # of zypper repos and don't verify keys/values further to_be[repo_id][k] = _format_repo_value(v) @@ -115,7 +115,7 @@ def _write_repos(repos, repo_base_path): valid_repos[repo_id] = (repo_fn_pth, repo_config) - for (repo_id, repo_data) in valid_repos.items(): + for repo_id, repo_data in valid_repos.items(): repo_blob = _format_repository_config(repo_id, repo_data[-1]) util.write_file(repo_data[0], repo_blob) diff --git a/cloudinit/config/schema.py b/cloudinit/config/schema.py index f34db025457..de9547b987c 100644 --- a/cloudinit/config/schema.py +++ b/cloudinit/config/schema.py @@ -1557,9 +1557,9 @@ def get_meta_doc(meta: MetaSchema, schema: Optional[dict] = None) -> str: LOG.warning("Unable to render property_doc due to invalid schema") meta_copy["property_doc"] = "" if not meta_copy.get("property_doc", ""): - meta_copy[ - "property_doc" - ] = " No schema definitions for this module" + meta_copy["property_doc"] = ( + " No schema definitions for this module" + ) meta_copy["examples"] = textwrap.indent(_get_examples(meta), " ") if not meta_copy["examples"]: meta_copy["examples"] = " No examples for this module" diff --git a/cloudinit/distros/aosc.py b/cloudinit/distros/aosc.py index 5f126136a02..96fa48b8b6e 100644 --- a/cloudinit/distros/aosc.py +++ b/cloudinit/distros/aosc.py @@ -131,7 +131,7 @@ def update_locale_conf(sys_path, locale_cfg): return (exists, contents) = read_locale_conf(sys_path) updated_am = 0 - for (k, v) in locale_cfg.items(): + for k, v in locale_cfg.items(): if v is None: continue v = str(v) diff --git a/cloudinit/distros/package_management/package_manager.py b/cloudinit/distros/package_management/package_manager.py index 32c4cac246c..9b45bb870b4 100644 --- a/cloudinit/distros/package_management/package_manager.py +++ b/cloudinit/distros/package_management/package_manager.py @@ -22,8 +22,7 @@ def available(self) -> bool: """Return if package manager is installed on system.""" @abstractmethod - def update_package_sources(self, *, force=False): - ... + def update_package_sources(self, *, force=False): ... @abstractmethod def install_packages(self, pkglist: Iterable) -> UninstalledPackages: diff --git a/cloudinit/distros/parsers/hostname.py b/cloudinit/distros/parsers/hostname.py index 7e498a5fab1..7250b6a8eb2 100644 --- a/cloudinit/distros/parsers/hostname.py +++ b/cloudinit/distros/parsers/hostname.py @@ -22,7 +22,7 @@ def parse(self): def __str__(self): self.parse() contents = StringIO() - for (line_type, components) in self._contents: + for line_type, components in self._contents: if line_type == "blank": contents.write("%s\n" % (components[0])) elif line_type == "all_comment": @@ -39,7 +39,7 @@ def __str__(self): @property def hostname(self): self.parse() - for (line_type, components) in self._contents: + for line_type, components in self._contents: if line_type == "hostname": return components[0] return None @@ -50,7 +50,7 @@ def set_hostname(self, your_hostname): return self.parse() replaced = False - for (line_type, components) in self._contents: + for line_type, components in self._contents: if line_type == "hostname": components[0] = str(your_hostname) replaced = True diff --git a/cloudinit/distros/parsers/hosts.py b/cloudinit/distros/parsers/hosts.py index d907e8b67f8..8d2f73ac91f 100644 --- a/cloudinit/distros/parsers/hosts.py +++ b/cloudinit/distros/parsers/hosts.py @@ -24,7 +24,7 @@ def parse(self): def get_entry(self, ip): self.parse() options = [] - for (line_type, components) in self._contents: + for line_type, components in self._contents: if line_type == "option": (pieces, _tail) = components if len(pieces) and pieces[0] == ip: @@ -34,7 +34,7 @@ def get_entry(self, ip): def del_entries(self, ip): self.parse() n_entries = [] - for (line_type, components) in self._contents: + for line_type, components in self._contents: if line_type != "option": n_entries.append((line_type, components)) continue @@ -68,7 +68,7 @@ def _parse(self, contents): def __str__(self): self.parse() contents = StringIO() - for (line_type, components) in self._contents: + for line_type, components in self._contents: if line_type == "blank": contents.write("%s\n" % (components[0])) elif line_type == "all_comment": diff --git a/cloudinit/distros/parsers/resolv_conf.py b/cloudinit/distros/parsers/resolv_conf.py index 000d0b577ab..6884c740989 100644 --- a/cloudinit/distros/parsers/resolv_conf.py +++ b/cloudinit/distros/parsers/resolv_conf.py @@ -57,7 +57,7 @@ def search_domains(self): def __str__(self): self.parse() contents = StringIO() - for (line_type, components) in self._contents: + for line_type, components in self._contents: if line_type == "blank": contents.write("\n") elif line_type == "all_comment": @@ -72,7 +72,7 @@ def __str__(self): def _retr_option(self, opt_name): found = [] - for (line_type, components) in self._contents: + for line_type, components in self._contents: if line_type == "option": (cfg_opt, cfg_value, _comment_tail) = components if cfg_opt == opt_name: @@ -134,7 +134,7 @@ def add_search_domain(self, search_domain): def _parse(self, contents): entries = [] - for (i, line) in enumerate(contents.splitlines()): + for i, line in enumerate(contents.splitlines()): sline = line.strip() if not sline: entries.append(("blank", [line])) diff --git a/cloudinit/distros/rhel_util.py b/cloudinit/distros/rhel_util.py index 426335f9b96..6a1b28163fd 100644 --- a/cloudinit/distros/rhel_util.py +++ b/cloudinit/distros/rhel_util.py @@ -22,7 +22,7 @@ def update_sysconfig_file(fn, adjustments, allow_empty=False): return (exists, contents) = read_sysconfig_file(fn) updated_am = 0 - for (k, v) in adjustments.items(): + for k, v in adjustments.items(): if v is None: continue v = str(v) diff --git a/cloudinit/helpers.py b/cloudinit/helpers.py index d12944258b1..470a5b2013f 100644 --- a/cloudinit/helpers.py +++ b/cloudinit/helpers.py @@ -369,13 +369,13 @@ def _unpickle(self, ci_pkl_version: int) -> None: if "instance_data" not in self.lookups: self.lookups["instance_data"] = "instance-data.json" if "instance_data_sensitive" not in self.lookups: - self.lookups[ - "instance_data_sensitive" - ] = "instance-data-sensitive.json" + self.lookups["instance_data_sensitive"] = ( + "instance-data-sensitive.json" + ) if "combined_cloud_config" not in self.lookups: - self.lookups[ - "combined_cloud_config" - ] = "combined-cloud-config.json" + self.lookups["combined_cloud_config"] = ( + "combined-cloud-config.json" + ) if "hotplug.enabled" not in self.lookups: self.lookups["hotplug.enabled"] = "hotplug.enabled" diff --git a/cloudinit/mergers/__init__.py b/cloudinit/mergers/__init__.py index dcbd5c82e60..ce1d8ebce5f 100644 --- a/cloudinit/mergers/__init__.py +++ b/cloudinit/mergers/__init__.py @@ -127,7 +127,7 @@ def default_mergers(): def construct(parsed_mergers): mergers_to_be = [] - for (m_name, m_ops) in parsed_mergers: + for m_name, m_ops in parsed_mergers: if not m_name.startswith(MERGER_PREFIX): m_name = MERGER_PREFIX + str(m_name) merger_locs, looked_locs = importer.find_module( @@ -147,6 +147,6 @@ def construct(parsed_mergers): # Now form them... mergers = [] root = LookupMerger(mergers) - for (attr, opts) in mergers_to_be: + for attr, opts in mergers_to_be: mergers.append(attr(root, opts)) return root diff --git a/cloudinit/mergers/m_dict.py b/cloudinit/mergers/m_dict.py index 9c51bc982b2..20d2716ffa4 100644 --- a/cloudinit/mergers/m_dict.py +++ b/cloudinit/mergers/m_dict.py @@ -61,7 +61,7 @@ def merge_same_key(old_v, new_v): # Otherwise leave it be... return old_v - for (k, v) in merge_with.items(): + for k, v in merge_with.items(): if k in value: if v is None and self._allow_delete: value.pop(k) diff --git a/cloudinit/net/__init__.py b/cloudinit/net/__init__.py index 6a213f78865..28ac814b6e9 100644 --- a/cloudinit/net/__init__.py +++ b/cloudinit/net/__init__.py @@ -668,7 +668,7 @@ def _get_current_rename_info(check_downable=True): }} """ cur_info = {} - for (name, mac, driver, device_id) in get_interfaces(): + for name, mac, driver, device_id in get_interfaces(): cur_info[name] = { "downable": None, "device_id": device_id, diff --git a/cloudinit/net/ephemeral.py b/cloudinit/net/ephemeral.py index c8730fb1e8a..39dd8ba3c8e 100644 --- a/cloudinit/net/ephemeral.py +++ b/cloudinit/net/ephemeral.py @@ -356,10 +356,10 @@ def obtain_lease(self): kwargs["prefix_or_mask"], kwargs["ip"] ) if kwargs["static_routes"]: - kwargs[ - "static_routes" - ] = self.distro.dhcp_client.parse_static_routes( - kwargs["static_routes"] + kwargs["static_routes"] = ( + self.distro.dhcp_client.parse_static_routes( + kwargs["static_routes"] + ) ) ephipv4 = EphemeralIPv4Network( self.distro, diff --git a/cloudinit/net/sysconfig.py b/cloudinit/net/sysconfig.py index 015c4494928..0684116c0b9 100644 --- a/cloudinit/net/sysconfig.py +++ b/cloudinit/net/sysconfig.py @@ -675,7 +675,7 @@ def _render_subnet_routes(cls, iface_cfg, route_cfg, subnets, flavor): @classmethod def _render_bonding_opts(cls, iface_cfg, iface, flavor): bond_opts = [] - for (bond_key, value_tpl) in cls.bond_tpl_opts: + for bond_key, value_tpl in cls.bond_tpl_opts: # Seems like either dash or underscore is possible? bond_keys = [bond_key, bond_key.replace("_", "-")] for bond_key in bond_keys: diff --git a/cloudinit/netinfo.py b/cloudinit/netinfo.py index 6aee531638d..be455b889c7 100644 --- a/cloudinit/netinfo.py +++ b/cloudinit/netinfo.py @@ -579,7 +579,7 @@ def netdev_pformat(): return "\n" fields = ["Device", "Up", "Address", "Mask", "Scope", "Hw-Address"] tbl = SimpleTable(fields) - for (dev, data) in sorted(netdev.items()): + for dev, data in sorted(netdev.items()): for addr in data.get("ipv4"): tbl.add_row( ( @@ -635,7 +635,7 @@ def route_pformat(): "Flags", ] tbl_v4 = SimpleTable(fields_v4) - for (n, r) in enumerate(routes.get("ipv4")): + for n, r in enumerate(routes.get("ipv4")): route_id = str(n) try: tbl_v4.add_row( @@ -663,7 +663,7 @@ def route_pformat(): "Flags", ] tbl_v6 = SimpleTable(fields_v6) - for (n, r) in enumerate(routes.get("ipv6")): + for n, r in enumerate(routes.get("ipv6")): route_id = str(n) if r["iface"] == "lo": continue diff --git a/cloudinit/safeyaml.py b/cloudinit/safeyaml.py index 5ee626bda06..a4328068f66 100644 --- a/cloudinit/safeyaml.py +++ b/cloudinit/safeyaml.py @@ -137,9 +137,9 @@ class _CustomSafeLoaderWithMarks(yaml.SafeLoader): def __init__(self, stream): super().__init__(stream) - self.schemamarks_by_line: Dict[ - int, List[SchemaPathMarks] - ] = defaultdict(list) + self.schemamarks_by_line: Dict[int, List[SchemaPathMarks]] = ( + defaultdict(list) + ) def _get_nested_path_prefix(self, node): if node.start_mark.line in self.schemamarks_by_line: diff --git a/cloudinit/sources/DataSourceAliYun.py b/cloudinit/sources/DataSourceAliYun.py index 727477df462..d674e1fc081 100644 --- a/cloudinit/sources/DataSourceAliYun.py +++ b/cloudinit/sources/DataSourceAliYun.py @@ -94,6 +94,7 @@ class DataSourceAliYunLocal(DataSourceAliYun): (DataSourceAliYun, (sources.DEP_FILESYSTEM, sources.DEP_NETWORK)), ] + # Return a list of data sources that match this set of dependencies def get_datasource_list(depends): return sources.list_from_depends(depends, datasources) diff --git a/cloudinit/sources/DataSourceConfigDrive.py b/cloudinit/sources/DataSourceConfigDrive.py index 5ca6c27d176..6ddfff429dd 100644 --- a/cloudinit/sources/DataSourceConfigDrive.py +++ b/cloudinit/sources/DataSourceConfigDrive.py @@ -208,7 +208,7 @@ def read_config_drive(source_dir): (reader.read_v1, [], {}), ] excps = [] - for (functor, args, kwargs) in finders: + for functor, args, kwargs in finders: try: return functor(*args, **kwargs) except openstack.NonReadable as e: @@ -244,7 +244,7 @@ def on_first_boot(data, distro=None, network=True): def write_injected_files(files): if files: LOG.debug("Writing %s injected files", len(files)) - for (filename, content) in files.items(): + for filename, content in files.items(): if not filename.startswith(os.sep): filename = os.sep + filename try: diff --git a/cloudinit/sources/DataSourceEc2.py b/cloudinit/sources/DataSourceEc2.py index e1ab1c5fe03..526520be2c0 100644 --- a/cloudinit/sources/DataSourceEc2.py +++ b/cloudinit/sources/DataSourceEc2.py @@ -943,9 +943,11 @@ def _get_key_as_int_or(dikt, key, alt_value): _get_key_as_int_or( mmd[1], "device-number", float("infinity") ), - mmd[2] - if fallback_nic_order == NicOrder.NIC_NAME - else mmd[0], + ( + mmd[2] + if fallback_nic_order == NicOrder.NIC_NAME + else mmd[0] + ), ), ) ) diff --git a/cloudinit/sources/DataSourceGCE.py b/cloudinit/sources/DataSourceGCE.py index 1e2a422cd03..f3bcd5315a2 100644 --- a/cloudinit/sources/DataSourceGCE.py +++ b/cloudinit/sources/DataSourceGCE.py @@ -292,7 +292,7 @@ def read_md(address=None, url_params=None, platform_check=True): ) md = {} # Iterate over url_map keys to get metadata items. - for (mkey, paths, required, is_text, is_recursive) in url_map: + for mkey, paths, required, is_text, is_recursive in url_map: value = None for path in paths: new_value = metadata_fetcher.get_value(path, is_text, is_recursive) diff --git a/cloudinit/sources/DataSourceHetzner.py b/cloudinit/sources/DataSourceHetzner.py index 7ef5a5c31fd..6529e2ff1c6 100644 --- a/cloudinit/sources/DataSourceHetzner.py +++ b/cloudinit/sources/DataSourceHetzner.py @@ -76,7 +76,7 @@ def _get_data(self): sec_between=self.wait_retry, retries=self.retries, ) - except (NoDHCPLeaseError) as e: + except NoDHCPLeaseError as e: LOG.error("Bailing, DHCP Exception: %s", e) raise diff --git a/cloudinit/sources/DataSourceLXD.py b/cloudinit/sources/DataSourceLXD.py index 43be28e0a15..cb3f5ece009 100644 --- a/cloudinit/sources/DataSourceLXD.py +++ b/cloudinit/sources/DataSourceLXD.py @@ -176,14 +176,15 @@ class DataSourceLXD(sources.DataSource): _network_config: Union[Dict, str] = sources.UNSET _crawled_metadata: Optional[Union[Dict, str]] = sources.UNSET - sensitive_metadata_keys: Tuple[ - str, ... - ] = sources.DataSource.sensitive_metadata_keys + ( - "user.meta-data", - "user.vendor-data", - "user.user-data", - "cloud-init.user-data", - "cloud-init.vendor-data", + sensitive_metadata_keys: Tuple[str, ...] = ( + sources.DataSource.sensitive_metadata_keys + + ( + "user.meta-data", + "user.vendor-data", + "user.user-data", + "cloud-init.user-data", + "cloud-init.vendor-data", + ) ) skip_hotplug_detect = True diff --git a/cloudinit/sources/DataSourceMAAS.py b/cloudinit/sources/DataSourceMAAS.py index 136cea82495..933d95c924b 100644 --- a/cloudinit/sources/DataSourceMAAS.py +++ b/cloudinit/sources/DataSourceMAAS.py @@ -372,7 +372,7 @@ def main(): ) subcmds = parser.add_subparsers(title="subcommands", dest="subcmd") - for (name, help) in ( + for name, help in ( ("crawl", "crawl the datasource"), ("get", "do a single GET of provided url"), ("check-seed", "read and verify seed at url"), diff --git a/cloudinit/sources/DataSourceScaleway.py b/cloudinit/sources/DataSourceScaleway.py index 05b50b98ee2..1ee7bf25287 100644 --- a/cloudinit/sources/DataSourceScaleway.py +++ b/cloudinit/sources/DataSourceScaleway.py @@ -337,7 +337,7 @@ def _get_data(self): func=self._crawl_metadata, ) self.metadata["net_in_use"] = "ipv6" - except (ConnectionError): + except ConnectionError: return False return True diff --git a/cloudinit/sources/DataSourceVultr.py b/cloudinit/sources/DataSourceVultr.py index 2d7f1f31a1e..d62fbe72ea5 100644 --- a/cloudinit/sources/DataSourceVultr.py +++ b/cloudinit/sources/DataSourceVultr.py @@ -30,9 +30,9 @@ class DataSourceVultr(sources.DataSource): dsname = "Vultr" - sensitive_metadata_keys: Tuple[ - str, ... - ] = sources.DataSource.sensitive_metadata_keys + ("startup-script",) + sensitive_metadata_keys: Tuple[str, ...] = ( + sources.DataSource.sensitive_metadata_keys + ("startup-script",) + ) def __init__(self, sys_cfg, distro, paths): super(DataSourceVultr, self).__init__(sys_cfg, distro, paths) diff --git a/cloudinit/sources/__init__.py b/cloudinit/sources/__init__.py index a3958d9b918..d8182086fa0 100644 --- a/cloudinit/sources/__init__.py +++ b/cloudinit/sources/__init__.py @@ -764,7 +764,7 @@ def _remap_device(self, short_name): # we want to return the correct value for what will actually # exist in this instance mappings = {"sd": ("vd", "xvd", "vtb")} - for (nfrom, tlist) in mappings.items(): + for nfrom, tlist in mappings.items(): if not short_name.startswith(nfrom): continue for nto in tlist: @@ -1014,7 +1014,7 @@ def normalize_pubkey_data(pubkey_data): return list(pubkey_data) if isinstance(pubkey_data, (dict)): - for (_keyname, klist) in pubkey_data.items(): + for _keyname, klist in pubkey_data.items(): # lp:506332 uec metadata service responds with # data that makes boto populate a string for 'klist' rather # than a list. @@ -1170,7 +1170,7 @@ class BrokenMetadata(IOError): def list_from_depends(depends, ds_list): ret_list = [] depset = set(depends) - for (cls, deps) in ds_list: + for cls, deps in ds_list: if depset == set(deps): ret_list.append(cls) return ret_list diff --git a/cloudinit/sources/helpers/ec2.py b/cloudinit/sources/helpers/ec2.py index ffb41dbfd7a..a3590a6e4b2 100644 --- a/cloudinit/sources/helpers/ec2.py +++ b/cloudinit/sources/helpers/ec2.py @@ -121,7 +121,7 @@ def _materialize(self, blob, base_url): child_blob = self._caller(child_url) child_contents[c] = self._materialize(child_blob, child_url) leaf_contents = {} - for (field, resource) in leaves.items(): + for field, resource in leaves.items(): leaf_url = url_helper.combine_url(base_url, resource) leaf_blob = self._caller(leaf_url) leaf_contents[field] = self._leaf_decoder(field, leaf_blob) diff --git a/cloudinit/sources/helpers/openstack.py b/cloudinit/sources/helpers/openstack.py index 9b46a22c37d..97ec18faf98 100644 --- a/cloudinit/sources/helpers/openstack.py +++ b/cloudinit/sources/helpers/openstack.py @@ -87,7 +87,7 @@ def _ec2_name_to_device(self, name): if not self.ec2_metadata: return None bdm = self.ec2_metadata.get("block-device-mapping", {}) - for (ent_name, device) in bdm.items(): + for ent_name, device in bdm.items(): if name == ent_name: return device return None @@ -266,7 +266,7 @@ def datafiles(version): "version": 2, } data = datafiles(self._find_working_version()) - for (name, (path, required, translator)) in data.items(): + for name, (path, required, translator) in data.items(): path = self._path_join(self.base_path, path) data = None found = False @@ -346,7 +346,7 @@ def datafiles(version): results["ec2-metadata"] = self._read_ec2_metadata() # Perform some misc. metadata key renames... - for (target_key, source_key, is_required) in KEY_COPIES: + for target_key, source_key, is_required in KEY_COPIES: if is_required and source_key not in metadata: raise BrokenMetadata("No '%s' entry in metadata" % source_key) if source_key in metadata: @@ -412,7 +412,7 @@ def read_v1(self): raise NonReadable("%s: no files found" % (self.base_path)) md = {} - for (name, (key, translator, default)) in FILES_V1.items(): + for name, (key, translator, default) in FILES_V1.items(): if name in found: path = found[name] try: diff --git a/cloudinit/sources/helpers/vmware/imc/config_file.py b/cloudinit/sources/helpers/vmware/imc/config_file.py index 9f86838964f..ec17cbc736c 100644 --- a/cloudinit/sources/helpers/vmware/imc/config_file.py +++ b/cloudinit/sources/helpers/vmware/imc/config_file.py @@ -66,7 +66,7 @@ def _loadConfigFile(self, filename): for category in config.sections(): logger.debug("FOUND CATEGORY = '%s'", category) - for (key, value) in config.items(category): + for key, value in config.items(category): self._insertKey(category + "|" + key, value) def get_count_with_prefix(self, prefix): diff --git a/cloudinit/ssh_util.py b/cloudinit/ssh_util.py index 70002086738..f7661929e49 100644 --- a/cloudinit/ssh_util.py +++ b/cloudinit/ssh_util.py @@ -593,7 +593,7 @@ def update_ssh_config_lines(lines, updates): # Keywords are case-insensitive and arguments are case-sensitive casemap = dict([(k.lower(), k) for k in updates.keys()]) - for (i, line) in enumerate(lines, start=1): + for i, line in enumerate(lines, start=1): if not line.key: continue if line.key in casemap: diff --git a/cloudinit/stages.py b/cloudinit/stages.py index 1d911aaf3ac..854e318e992 100644 --- a/cloudinit/stages.py +++ b/cloudinit/stages.py @@ -81,9 +81,9 @@ def update_event_enabled( case, we only have the data source's `default_update_events`, so an event that should be enabled in userdata may be denied. """ - default_events: Dict[ - EventScope, Set[EventType] - ] = datasource.default_update_events + default_events: Dict[EventScope, Set[EventType]] = ( + datasource.default_update_events + ) user_events: Dict[EventScope, Set[EventType]] = userdata_to_events( cfg.get("updates", {}) ) @@ -985,9 +985,9 @@ def _find_networking_config( } if self.datasource and hasattr(self.datasource, "network_config"): - available_cfgs[ - NetworkConfigSource.DS - ] = self.datasource.network_config + available_cfgs[NetworkConfigSource.DS] = ( + self.datasource.network_config + ) if self.datasource: order = self.datasource.network_config_sources diff --git a/cloudinit/url_helper.py b/cloudinit/url_helper.py index f2c6eb2e634..f404d1130bd 100644 --- a/cloudinit/url_helper.py +++ b/cloudinit/url_helper.py @@ -462,7 +462,7 @@ def readurl( req_args["headers"] = headers filtered_req_args = {} - for (k, v) in req_args.items(): + for k, v in req_args.items(): if k == "data": continue if k == "headers" and headers_redact: diff --git a/conftest.py b/conftest.py index 11aeae8facd..77111a81cab 100644 --- a/conftest.py +++ b/conftest.py @@ -7,6 +7,7 @@ any of these tests run: that is to say, they must be listed in ``integration-requirements.txt`` and in ``test-requirements.txt``. """ + # If we don't import this early, lru_cache may get applied before we have the # chance to patch. This is also too early for the pytest-antilru plugin # to work. diff --git a/tests/integration_tests/bugs/test_gh626.py b/tests/integration_tests/bugs/test_gh626.py index 204161e2c2e..a1f3b97e13c 100644 --- a/tests/integration_tests/bugs/test_gh626.py +++ b/tests/integration_tests/bugs/test_gh626.py @@ -3,6 +3,7 @@ Ensure if wakeonlan is specified in the network config that it is rendered in the /etc/network/interfaces or netplan config. """ + import pytest import yaml diff --git a/tests/integration_tests/bugs/test_gh632.py b/tests/integration_tests/bugs/test_gh632.py index 9e67fe593a4..bd26e6b39d2 100644 --- a/tests/integration_tests/bugs/test_gh632.py +++ b/tests/integration_tests/bugs/test_gh632.py @@ -3,6 +3,7 @@ Verify that if cloud-init is using DataSourceRbxCloud, there is no traceback if the metadata disk cannot be found. """ + import pytest from tests.integration_tests.instances import IntegrationInstance diff --git a/tests/integration_tests/bugs/test_gh868.py b/tests/integration_tests/bugs/test_gh868.py index 67ac9b3a6af..7c0af6b2ff8 100644 --- a/tests/integration_tests/bugs/test_gh868.py +++ b/tests/integration_tests/bugs/test_gh868.py @@ -1,4 +1,5 @@ """Ensure no Traceback when 'chef_license' is set""" + import pytest from tests.integration_tests.instances import IntegrationInstance diff --git a/tests/integration_tests/bugs/test_lp1835584.py b/tests/integration_tests/bugs/test_lp1835584.py index b2d1b1bd866..f44edca80e3 100644 --- a/tests/integration_tests/bugs/test_lp1835584.py +++ b/tests/integration_tests/bugs/test_lp1835584.py @@ -25,6 +25,7 @@ https://bugs.launchpad.net/cloud-init/+bug/1835584 """ + import re import pytest diff --git a/tests/integration_tests/bugs/test_lp1886531.py b/tests/integration_tests/bugs/test_lp1886531.py index d56ca320e2b..d170a133d35 100644 --- a/tests/integration_tests/bugs/test_lp1886531.py +++ b/tests/integration_tests/bugs/test_lp1886531.py @@ -9,6 +9,7 @@ https://bugs.launchpad.net/ubuntu/+source/cloud-init/+bug/1886531 """ + import pytest from tests.integration_tests.util import verify_clean_log diff --git a/tests/integration_tests/bugs/test_lp1898997.py b/tests/integration_tests/bugs/test_lp1898997.py index 631285955d7..d183223b9ac 100644 --- a/tests/integration_tests/bugs/test_lp1898997.py +++ b/tests/integration_tests/bugs/test_lp1898997.py @@ -9,6 +9,7 @@ network configuration, and confirms that the bridge can be used to ping the default gateway. """ + import pytest from tests.integration_tests import random_mac_address diff --git a/tests/integration_tests/bugs/test_lp1901011.py b/tests/integration_tests/bugs/test_lp1901011.py index e94caf9b520..4a25c602c14 100644 --- a/tests/integration_tests/bugs/test_lp1901011.py +++ b/tests/integration_tests/bugs/test_lp1901011.py @@ -4,6 +4,7 @@ See https://github.com/canonical/cloud-init/pull/800 """ + import pytest from tests.integration_tests.clouds import IntegrationCloud diff --git a/tests/integration_tests/bugs/test_lp1910835.py b/tests/integration_tests/bugs/test_lp1910835.py index aa0fb75c27b..ff8390f7e0a 100644 --- a/tests/integration_tests/bugs/test_lp1910835.py +++ b/tests/integration_tests/bugs/test_lp1910835.py @@ -17,6 +17,7 @@ material: if the Azure datasource has removed the CRLFs correctly, then they will match. """ + import pytest from tests.integration_tests.integration_settings import PLATFORM diff --git a/tests/integration_tests/bugs/test_lp1912844.py b/tests/integration_tests/bugs/test_lp1912844.py index b5aafa76797..15fcf81635f 100644 --- a/tests/integration_tests/bugs/test_lp1912844.py +++ b/tests/integration_tests/bugs/test_lp1912844.py @@ -14,6 +14,7 @@ the traceback that they cause. We work around this by calling ``get_interfaces_by_mac` directly in the test code. """ + import pytest from tests.integration_tests import random_mac_address diff --git a/tests/integration_tests/cmd/test_schema.py b/tests/integration_tests/cmd/test_schema.py index c954484012a..b019e4c2f4f 100644 --- a/tests/integration_tests/cmd/test_schema.py +++ b/tests/integration_tests/cmd/test_schema.py @@ -1,4 +1,5 @@ """Tests for `cloud-init status`""" + from textwrap import dedent import pytest diff --git a/tests/integration_tests/cmd/test_status.py b/tests/integration_tests/cmd/test_status.py index 50396be709c..fe9946b06a0 100644 --- a/tests/integration_tests/cmd/test_status.py +++ b/tests/integration_tests/cmd/test_status.py @@ -1,4 +1,5 @@ """Tests for `cloud-init status`""" + import json import pytest diff --git a/tests/integration_tests/datasources/test_none.py b/tests/integration_tests/datasources/test_none.py index 6d7216e3dca..d79c30404d8 100644 --- a/tests/integration_tests/datasources/test_none.py +++ b/tests/integration_tests/datasources/test_none.py @@ -1,4 +1,5 @@ """DataSourceNone integration tests on LXD.""" + import json from tests.integration_tests.instances import IntegrationInstance diff --git a/tests/integration_tests/modules/test_ca_certs.py b/tests/integration_tests/modules/test_ca_certs.py index 03b362302f0..352dad164ce 100644 --- a/tests/integration_tests/modules/test_ca_certs.py +++ b/tests/integration_tests/modules/test_ca_certs.py @@ -6,6 +6,7 @@ * Mark this as running on Debian and Alpine (once we have marks for that) * Implement testing for the RHEL-specific paths """ + import os.path import pytest diff --git a/tests/integration_tests/modules/test_command_output.py b/tests/integration_tests/modules/test_command_output.py index 96525cac0c4..5179b11150d 100644 --- a/tests/integration_tests/modules/test_command_output.py +++ b/tests/integration_tests/modules/test_command_output.py @@ -4,6 +4,7 @@ (This is ported from ``tests/cloud_tests/testcases/main/command_output_simple.yaml``.)""" + import pytest from tests.integration_tests.instances import IntegrationInstance diff --git a/tests/integration_tests/modules/test_keys_to_console.py b/tests/integration_tests/modules/test_keys_to_console.py index a6d644396f4..70f5c1c7007 100644 --- a/tests/integration_tests/modules/test_keys_to_console.py +++ b/tests/integration_tests/modules/test_keys_to_console.py @@ -2,6 +2,7 @@ (This is ported from ``tests/cloud_tests/testcases/modules/keys_to_console.yaml``.)""" + import pytest from tests.integration_tests.decorators import retry diff --git a/tests/integration_tests/modules/test_lxd.py b/tests/integration_tests/modules/test_lxd.py index 308ef185357..a4ff5906a23 100644 --- a/tests/integration_tests/modules/test_lxd.py +++ b/tests/integration_tests/modules/test_lxd.py @@ -3,6 +3,7 @@ (This is ported from ``tests/cloud_tests/testcases/modules/lxd_bridge.yaml``.) """ + import warnings import pytest diff --git a/tests/integration_tests/modules/test_ntp_servers.py b/tests/integration_tests/modules/test_ntp_servers.py index fc62e63b346..217140c5268 100644 --- a/tests/integration_tests/modules/test_ntp_servers.py +++ b/tests/integration_tests/modules/test_ntp_servers.py @@ -7,6 +7,7 @@ ``tests/cloud_tests/testcases/modules/ntp_pools.yaml``, and ``tests/cloud_tests/testcases/modules/ntp_chrony.yaml``) """ + import re import pytest diff --git a/tests/integration_tests/modules/test_puppet.py b/tests/integration_tests/modules/test_puppet.py index 796f316a711..9598b8ec971 100644 --- a/tests/integration_tests/modules/test_puppet.py +++ b/tests/integration_tests/modules/test_puppet.py @@ -1,4 +1,5 @@ """Test installation configuration of puppet module.""" + import pytest from tests.integration_tests.instances import IntegrationInstance diff --git a/tests/integration_tests/modules/test_ssh_auth_key_fingerprints.py b/tests/integration_tests/modules/test_ssh_auth_key_fingerprints.py index 158eb880e09..f13672a6c47 100644 --- a/tests/integration_tests/modules/test_ssh_auth_key_fingerprints.py +++ b/tests/integration_tests/modules/test_ssh_auth_key_fingerprints.py @@ -8,6 +8,7 @@ ``tests/cloud_tests/testcases/modules/ssh_auth_key_fingerprints_disable.yaml``, ``tests/cloud_tests/testcases/modules/ssh_auth_key_fingerprints_enable.yaml``. )""" + import re import pytest diff --git a/tests/integration_tests/modules/test_users_groups.py b/tests/integration_tests/modules/test_users_groups.py index f1352f860cf..a904cd9f6f2 100644 --- a/tests/integration_tests/modules/test_users_groups.py +++ b/tests/integration_tests/modules/test_users_groups.py @@ -4,6 +4,7 @@ * This module assumes that the "ubuntu" user will be created when "default" is specified; this will need modification to run on other OSes. """ + import re import pytest diff --git a/tests/integration_tests/modules/test_wireguard.py b/tests/integration_tests/modules/test_wireguard.py index e685a269cbe..9ff1a21b2dc 100644 --- a/tests/integration_tests/modules/test_wireguard.py +++ b/tests/integration_tests/modules/test_wireguard.py @@ -1,4 +1,5 @@ """Integration test for the wireguard module.""" + import pytest from pycloudlib.lxd.instance import LXDInstance diff --git a/tests/unittests/config/test_cc_seed_random.py b/tests/unittests/config/test_cc_seed_random.py index 76b9b796a65..15c59523466 100644 --- a/tests/unittests/config/test_cc_seed_random.py +++ b/tests/unittests/config/test_cc_seed_random.py @@ -225,7 +225,7 @@ def test_file_in_environment_for_command(self): def apply_patches(patches): ret = [] - for (ref, name, replace) in patches: + for ref, name, replace in patches: if replace is None: continue orig = getattr(ref, name) diff --git a/tests/unittests/config/test_cc_ubuntu_pro.py b/tests/unittests/config/test_cc_ubuntu_pro.py index 40f8035b30d..07ba8c69bc8 100644 --- a/tests/unittests/config/test_cc_ubuntu_pro.py +++ b/tests/unittests/config/test_cc_ubuntu_pro.py @@ -450,12 +450,14 @@ class TestUbuntuProSchema: # If __version__ no longer exists on jsonschema, that means # we're using a high enough version of jsonschema to not need # to skip this test. - JSONSCHEMA_SKIP_REASON - if lifecycle.Version.from_str( - getattr(jsonschema, "__version__", "999") - ) - < lifecycle.Version(4) - else "", + ( + JSONSCHEMA_SKIP_REASON + if lifecycle.Version.from_str( + getattr(jsonschema, "__version__", "999") + ) + < lifecycle.Version(4) + else "" + ), id="deprecation_of_ubuntu_advantage_skip_old_json", ), # Strict keys @@ -1121,9 +1123,9 @@ def test_should_auto_attach_error(self, caplog, fake_uaclient): m_should_auto_attach.should_auto_attach.side_effect = ( FakeUserFacingError("Some error") # noqa: E501 ) - sys.modules[ - "uaclient.api.u.pro.attach.auto.should_auto_attach.v1" - ] = m_should_auto_attach + sys.modules["uaclient.api.u.pro.attach.auto.should_auto_attach.v1"] = ( + m_should_auto_attach + ) assert not _should_auto_attach({}) assert "Error during `should_auto_attach`: Some error" in caplog.text assert ( @@ -1145,9 +1147,9 @@ def test_happy_path( self, ua_section, expected_result, caplog, fake_uaclient ): m_should_auto_attach = mock.Mock() - sys.modules[ - "uaclient.api.u.pro.attach.auto.should_auto_attach.v1" - ] = m_should_auto_attach + sys.modules["uaclient.api.u.pro.attach.auto.should_auto_attach.v1"] = ( + m_should_auto_attach + ) should_auto_attach_value = object() m_should_auto_attach.should_auto_attach.return_value.should_auto_attach = ( # noqa: E501 should_auto_attach_value @@ -1174,9 +1176,9 @@ def test_full_auto_attach_error(self, caplog, mocker, fake_uaclient): m_full_auto_attach.full_auto_attach.side_effect = FakeUserFacingError( "Some error" ) - sys.modules[ - "uaclient.api.u.pro.attach.auto.full_auto_attach.v1" - ] = m_full_auto_attach + sys.modules["uaclient.api.u.pro.attach.auto.full_auto_attach.v1"] = ( + m_full_auto_attach + ) expected_msg = "Error during `full_auto_attach`: Some error" with pytest.raises(RuntimeError, match=re.escape(expected_msg)): _auto_attach(self.ua_section) @@ -1185,9 +1187,9 @@ def test_full_auto_attach_error(self, caplog, mocker, fake_uaclient): def test_happy_path(self, caplog, mocker, fake_uaclient): mocker.patch.dict("sys.modules") sys.modules["uaclient.config"] = mock.Mock() - sys.modules[ - "uaclient.api.u.pro.attach.auto.full_auto_attach.v1" - ] = mock.Mock() + sys.modules["uaclient.api.u.pro.attach.auto.full_auto_attach.v1"] = ( + mock.Mock() + ) _auto_attach(self.ua_section) assert "Attaching to Ubuntu Pro took" in caplog.text diff --git a/tests/unittests/conftest.py b/tests/unittests/conftest.py index 9401f2235ef..375e1d14840 100644 --- a/tests/unittests/conftest.py +++ b/tests/unittests/conftest.py @@ -85,7 +85,7 @@ def fake_filesystem(mocker, tmpdir): # exists, but then it fails because of the retargeting that happens here. tmpdir.mkdir("tmp") - for (mod, funcs) in FS_FUNCS.items(): + for mod, funcs in FS_FUNCS.items(): for f, nargs in funcs: func = getattr(mod, f) trap_func = retarget_many_wrapper(str(tmpdir), nargs, func) diff --git a/tests/unittests/distros/test_netconfig.py b/tests/unittests/distros/test_netconfig.py index d0c64a24a39..b447757bef6 100644 --- a/tests/unittests/distros/test_netconfig.py +++ b/tests/unittests/distros/test_netconfig.py @@ -313,11 +313,11 @@ def assertCfgEquals(self, blob1, blob2): b1 = dict(SysConf(blob1.strip().splitlines())) b2 = dict(SysConf(blob2.strip().splitlines())) self.assertEqual(b1, b2) - for (k, v) in b1.items(): + for k, v in b1.items(): self.assertIn(k, b2) - for (k, v) in b2.items(): + for k, v in b2.items(): self.assertIn(k, b1) - for (k, v) in b1.items(): + for k, v in b1.items(): self.assertEqual(v, b2[k]) diff --git a/tests/unittests/distros/test_user_data_normalize.py b/tests/unittests/distros/test_user_data_normalize.py index 8fd187b4754..3ff2c49fb14 100644 --- a/tests/unittests/distros/test_user_data_normalize.py +++ b/tests/unittests/distros/test_user_data_normalize.py @@ -302,7 +302,7 @@ def test_create_snap_user(self, mock_subp): ], } users, _groups = self._norm(ug_cfg, distro) - for (user, config) in users.items(): + for user, config in users.items(): print("user=%s config=%s" % (user, config)) username = distro.create_user(user, **config) @@ -322,7 +322,7 @@ def test_create_snap_user_known(self, mock_subp): ], } users, _groups = self._norm(ug_cfg, distro) - for (user, config) in users.items(): + for user, config in users.items(): print("user=%s config=%s" % (user, config)) username = distro.create_user(user, **config) @@ -353,7 +353,7 @@ def test_add_user_on_snappy_system( ], } users, _groups = self._norm(ug_cfg, distro) - for (user, config) in users.items(): + for user, config in users.items(): print("user=%s config=%s" % (user, config)) distro.add_user(user, **config) diff --git a/tests/unittests/filters/test_launch_index.py b/tests/unittests/filters/test_launch_index.py index 071cc66f563..1b2ebfb2e20 100644 --- a/tests/unittests/filters/test_launch_index.py +++ b/tests/unittests/filters/test_launch_index.py @@ -21,7 +21,7 @@ def count_messages(root): class TestLaunchFilter(helpers.ResourceUsingTestCase): def assertCounts(self, message, expected_counts): orig_message = copy.deepcopy(message) - for (index, count) in expected_counts.items(): + for index, count in expected_counts.items(): index = util.safe_int(index) filtered_message = launch_index.Filter(index).apply(message) self.assertEqual(count_messages(filtered_message), count) diff --git a/tests/unittests/helpers.py b/tests/unittests/helpers.py index b214170c3ef..dfd9a508c25 100644 --- a/tests/unittests/helpers.py +++ b/tests/unittests/helpers.py @@ -313,7 +313,7 @@ def tearDown(self): def replicateTestRoot(self, example_root, target_root): real_root = resourceLocation() real_root = os.path.join(real_root, "roots", example_root) - for (dir_path, _dirnames, filenames) in os.walk(real_root): + for dir_path, _dirnames, filenames in os.walk(real_root): real_path = dir_path make_path = rebase_path(real_path[len(real_root) :], target_root) util.ensure_dir(make_path) @@ -340,8 +340,8 @@ def patchUtils(self, new_root): ("write_json", 1), ], } - for (mod, funcs) in patch_funcs.items(): - for (f, am) in funcs: + for mod, funcs in patch_funcs.items(): + for f, am in funcs: func = getattr(mod, f) trap_func = retarget_many_wrapper(new_root, am, func) self.patched_funcs.enter_context( @@ -388,7 +388,7 @@ def patchOS(self, new_root): # py27 does not have scandir patch_funcs[os].append(("scandir", 1)) - for (mod, funcs) in patch_funcs.items(): + for mod, funcs in patch_funcs.items(): for f, nargs in funcs: func = getattr(mod, f) trap_func = retarget_many_wrapper(new_root, nargs, func) @@ -511,7 +511,7 @@ def populate_dir(path, files): if not os.path.exists(path): os.makedirs(path) ret = [] - for (name, content) in files.items(): + for name, content in files.items(): p = os.path.sep.join([path, name]) util.ensure_dir(os.path.dirname(p)) with open(p, "wb") as fp: diff --git a/tests/unittests/net/test_net_rendering.py b/tests/unittests/net/test_net_rendering.py index 3e1490b2713..0f3c766fdeb 100644 --- a/tests/unittests/net/test_net_rendering.py +++ b/tests/unittests/net/test_net_rendering.py @@ -24,6 +24,7 @@ in `unittests/test_net.py`. While that file contains similar tests, it has become too large to be maintainable. """ + import glob from enum import Flag, auto from pathlib import Path diff --git a/tests/unittests/sources/test_akamai.py b/tests/unittests/sources/test_akamai.py index 2480269f6e6..e0472139037 100644 --- a/tests/unittests/sources/test_akamai.py +++ b/tests/unittests/sources/test_akamai.py @@ -38,9 +38,9 @@ def _get_datasource( return_value="", ): if local: - ds: Union[ - DataSourceAkamai, DataSourceAkamaiLocal - ] = DataSourceAkamaiLocal(sys_cfg, None, None) + ds: Union[DataSourceAkamai, DataSourceAkamaiLocal] = ( + DataSourceAkamaiLocal(sys_cfg, None, None) + ) else: ds = DataSourceAkamai(sys_cfg, None, None) diff --git a/tests/unittests/sources/test_nocloud.py b/tests/unittests/sources/test_nocloud.py index b98ff73c9ac..8701b9bd131 100644 --- a/tests/unittests/sources/test_nocloud.py +++ b/tests/unittests/sources/test_nocloud.py @@ -384,7 +384,7 @@ def test_parse_cmdline_data_valid(self): ), ) - for (fmt, expected) in pairs: + for fmt, expected in pairs: fill = {} cmdline = fmt % {"ds_id": ds_id} ret = parse_cmdline_data(ds_id=ds_id, fill=fill, cmdline=cmdline) diff --git a/tests/unittests/sources/test_openstack.py b/tests/unittests/sources/test_openstack.py index 380fe340890..154a7620759 100644 --- a/tests/unittests/sources/test_openstack.py +++ b/tests/unittests/sources/test_openstack.py @@ -99,7 +99,7 @@ def match_ec2_url(uri, headers): return (200, headers, ec2_files.get(path)) if path == "latest/meta-data/": buf = StringIO() - for (k, v) in ec2_meta.items(): + for k, v in ec2_meta.items(): if isinstance(v, (list, tuple)): buf.write("%s/" % (k)) else: diff --git a/tests/unittests/sources/test_oracle.py b/tests/unittests/sources/test_oracle.py index f1625fbf9f2..2372ca5ecfc 100644 --- a/tests/unittests/sources/test_oracle.py +++ b/tests/unittests/sources/test_oracle.py @@ -1076,9 +1076,9 @@ def test_secondary_nic_addition( """ if configure_secondary_nics is not None: - oracle_ds.ds_cfg[ - "configure_secondary_nics" - ] = configure_secondary_nics + oracle_ds.ds_cfg["configure_secondary_nics"] = ( + configure_secondary_nics + ) oracle_ds._vnics_data = "DummyData" with mock.patch.object( diff --git a/tests/unittests/test_data.py b/tests/unittests/test_data.py index 14be6fa48e3..7621c5f6c80 100644 --- a/tests/unittests/test_data.py +++ b/tests/unittests/test_data.py @@ -362,9 +362,9 @@ def test_merging_cloud_config(self, tmpdir): - morestuff """ message2 = MIMEBase("text", "cloud-config") - message2[ - "X-Merge-Type" - ] = "dict(recurse_array,recurse_str)+list(append)+str(append)" + message2["X-Merge-Type"] = ( + "dict(recurse_array,recurse_str)+list(append)+str(append)" + ) message2.set_payload(blob2) blob3 = """ diff --git a/tests/unittests/test_merging.py b/tests/unittests/test_merging.py index 81c878d2ee2..efb71618ce3 100644 --- a/tests/unittests/test_merging.py +++ b/tests/unittests/test_merging.py @@ -31,7 +31,7 @@ def _old_mergedict(src, cand): Nested dictionaries are merged recursively. """ if isinstance(src, dict) and isinstance(cand, dict): - for (k, v) in cand.items(): + for k, v in cand.items(): if k not in src: src[k] = v else: @@ -145,10 +145,10 @@ def test_merge_cc_samples(self): paths = c_helpers.Paths({}) cc_handler = cloud_config.CloudConfigPartHandler(paths) cc_handler.cloud_fn = None - for (payloads, (expected_merge, expected_fn)) in tests: + for payloads, (expected_merge, expected_fn) in tests: cc_handler.handle_part(None, CONTENT_START, None, None, None, None) merging_fns = [] - for (fn, contents) in payloads: + for fn, contents in payloads: cc_handler.handle_part( None, None, "%s.yaml" % (fn), contents, None, {} ) diff --git a/tools/mock-meta.py b/tools/mock-meta.py index a52536165f9..f8fcd776284 100755 --- a/tools/mock-meta.py +++ b/tools/mock-meta.py @@ -280,7 +280,7 @@ def get_data(self, params, who, **kwargs): return result else: contents = [] - for (i, key_id) in enumerate(key_ids): + for i, key_id in enumerate(key_ids): contents.append("%s=%s" % (i, key_id)) return "\n".join(contents) elif action == "placement":