diff --git a/cloudinit/cmd/main.py b/cloudinit/cmd/main.py index a2851a2682c..d1ff6ba7660 100644 --- a/cloudinit/cmd/main.py +++ b/cloudinit/cmd/main.py @@ -91,17 +91,6 @@ def print_exc(msg=""): sys.stderr.write("\n") -DEPRECATE_BOOT_STAGE_MESSAGE = ( - "Triggering cloud-init boot stages outside of intial system boot is not a" - " fully supported operation which can lead to incomplete or incorrect" - " configuration. As such, cloud-init is deprecating this feature in the" - " future. If you currently use cloud-init in this way," - " please file an issue describing in detail your use case so that" - " cloud-init can better support your needs:" - " https://github.com/canonical/cloud-init/issues/new" -) - - def welcome(action, msg=None): if not msg: msg = welcome_format(action) diff --git a/cloudinit/config/cc_growpart.py b/cloudinit/config/cc_growpart.py index 4815b14a9b9..141d2d1d9da 100644 --- a/cloudinit/config/cc_growpart.py +++ b/cloudinit/config/cc_growpart.py @@ -27,8 +27,6 @@ from cloudinit.distros import ALL_DISTROS, Distro from cloudinit.settings import PER_ALWAYS -MODULE_DESCRIPTION = """\ -""" frequency = PER_ALWAYS meta: MetaSchema = { "id": "cc_growpart", diff --git a/cloudinit/config/cc_grub_dpkg.py b/cloudinit/config/cc_grub_dpkg.py index 7107f1fe3c2..b24d50b05dc 100644 --- a/cloudinit/config/cc_grub_dpkg.py +++ b/cloudinit/config/cc_grub_dpkg.py @@ -18,8 +18,6 @@ from cloudinit.settings import PER_INSTANCE from cloudinit.subp import ProcessExecutionError -MODULE_DESCRIPTION = """\ -""" meta: MetaSchema = { "id": "cc_grub_dpkg", "distros": ["ubuntu", "debian"], diff --git a/cloudinit/config/cc_landscape.py b/cloudinit/config/cc_landscape.py index e22757a5e5a..ea208c19961 100644 --- a/cloudinit/config/cc_landscape.py +++ b/cloudinit/config/cc_landscape.py @@ -20,7 +20,6 @@ from cloudinit.settings import PER_INSTANCE LSC_CLIENT_CFG_FILE = "/etc/landscape/client.conf" -LS_DEFAULT_FILE = "/etc/default/landscape-client" # defaults taken from stock client.conf in landscape-client 11.07.1.1-0ubuntu2 LSC_BUILTIN_CFG = { diff --git a/cloudinit/config/cc_reset_rmc.py b/cloudinit/config/cc_reset_rmc.py index 44264cf524f..c6ce4881c53 100644 --- a/cloudinit/config/cc_reset_rmc.py +++ b/cloudinit/config/cc_reset_rmc.py @@ -3,20 +3,8 @@ # Author: Aman Kumar Sinha # # This file is part of cloud-init. See LICENSE file for license information. -"""Reset RMC: Reset rsct node id""" -import logging -import os - -from cloudinit import subp, util -from cloudinit.cloud import Cloud -from cloudinit.config import Config -from cloudinit.config.schema import MetaSchema -from cloudinit.distros import ALL_DISTROS -from cloudinit.settings import PER_INSTANCE +"""Reset RMC: Reset rsct node id -# Since this module is undocumented, this variable is unused. -# Keeping it here for documentation purposes -MODULE_DESCRIPTION = """\ Reset RMC module is IBM PowerVM Hypervisor specific Reliable Scalable Cluster Technology (RSCT) is a set of software components, @@ -36,6 +24,15 @@ Prerequisite of using this module is to install RSCT packages. """ +import logging +import os + +from cloudinit import subp, util +from cloudinit.cloud import Cloud +from cloudinit.config import Config +from cloudinit.config.schema import MetaSchema +from cloudinit.distros import ALL_DISTROS +from cloudinit.settings import PER_INSTANCE meta: MetaSchema = { "id": "cc_reset_rmc", diff --git a/cloudinit/config/cc_ubuntu_pro.py b/cloudinit/config/cc_ubuntu_pro.py index d39a0fa4acc..81acf0439d2 100644 --- a/cloudinit/config/cc_ubuntu_pro.py +++ b/cloudinit/config/cc_ubuntu_pro.py @@ -14,7 +14,6 @@ from cloudinit.config.schema import MetaSchema from cloudinit.settings import PER_INSTANCE -PRO_URL = "https://ubuntu.com/pro" DEPRECATED_KEYS = set(["ubuntu-advantage", "ubuntu_advantage"]) meta: MetaSchema = { diff --git a/cloudinit/config/cc_yum_add_repo.py b/cloudinit/config/cc_yum_add_repo.py index 308e5d603c1..f20f7ea0018 100644 --- a/cloudinit/config/cc_yum_add_repo.py +++ b/cloudinit/config/cc_yum_add_repo.py @@ -17,19 +17,6 @@ from cloudinit.config.schema import MetaSchema from cloudinit.settings import PER_INSTANCE -COPR_BASEURL = ( - "https://download.copr.fedorainfracloud.org/results/@cloud-init/" - "cloud-init-dev/epel-8-$basearch/" -) -COPR_GPG_URL = ( - "https://download.copr.fedorainfracloud.org/results/@cloud-init/" - "cloud-init-dev/pubkey.gpg" -) -EPEL_TESTING_BASEURL = ( - "https://download.copr.fedorainfracloud.org/results/@cloud-init/" - "cloud-init-dev/pubkey.gpg" -) - meta: MetaSchema = { "id": "cc_yum_add_repo", "distros": [ diff --git a/cloudinit/config/schema.py b/cloudinit/config/schema.py index 769e5ade3ab..ecdb6d7a1c1 100644 --- a/cloudinit/config/schema.py +++ b/cloudinit/config/schema.py @@ -55,8 +55,6 @@ # If we change the location of versions.schema.json in github, we need # to provide an updated PR to # https://github.com/SchemaStore/schemastore. -VERSIONED_USERDATA_SCHEMA_FILE = "versions.schema.cloud-config.json" - # When bumping schema version due to incompatible changes: # 1. Add a new schema-cloud-config-v#.json # 2. change the USERDATA_SCHEMA_FILE to cloud-init-schema-v#.json @@ -638,7 +636,6 @@ def netplan_validate_network_schema( _, marks = safeyaml.load_with_marks(src_content) print( annotated_cloudconfig_file( - net_cfg, src_content, marks, schema_errors=errors, @@ -811,11 +808,9 @@ def validate_cloudconfig_schema( class _Annotator: def __init__( self, - cloudconfig: dict, original_content: str, schemamarks: dict, ): - self._cloudconfig = cloudconfig self._original_content = original_content self._schemamarks = schemamarks @@ -916,7 +911,6 @@ def annotate( def annotated_cloudconfig_file( - cloudconfig: dict, original_content: str, schemamarks: dict, *, @@ -934,7 +928,7 @@ def annotated_cloudconfig_file( @return Annotated schema """ - return _Annotator(cloudconfig, original_content, schemamarks).annotate( + return _Annotator(original_content, schemamarks).annotate( schema_errors or [], schema_deprecations or [] ) @@ -1111,7 +1105,7 @@ def validate_cloudconfig_file( if annotate: print( annotated_cloudconfig_file( - {}, content, {}, schema_errors=schema_error.schema_errors + content, {}, schema_errors=schema_error.schema_errors ) ) raise schema_error from e @@ -1161,7 +1155,6 @@ def validate_cloudconfig_file( if annotate: print( annotated_cloudconfig_file( - cloudconfig, content, marks, schema_errors=errors, diff --git a/cloudinit/distros/package_management/apt.py b/cloudinit/distros/package_management/apt.py index 11742797646..3149692f5c4 100644 --- a/cloudinit/distros/package_management/apt.py +++ b/cloudinit/distros/package_management/apt.py @@ -174,7 +174,6 @@ def run_package_command(self, command, args=None, pkgs=None): full_command.extend(pkglist) self._wait_for_apt_command( - short_cmd=command, subp_kwargs={ "args": full_command, "update_env": self.environment, @@ -199,11 +198,10 @@ def _apt_lock_available(self): return True def _wait_for_apt_command( - self, short_cmd, subp_kwargs, timeout=APT_LOCK_WAIT_TIMEOUT + self, subp_kwargs, timeout=APT_LOCK_WAIT_TIMEOUT ): """Wait for apt install to complete. - short_cmd: Name of command like "upgrade" or "install" subp_kwargs: kwargs to pass to subp """ start_time = time.monotonic() diff --git a/cloudinit/net/eni.py b/cloudinit/net/eni.py index 146c0167435..2eda92e7ac6 100644 --- a/cloudinit/net/eni.py +++ b/cloudinit/net/eni.py @@ -576,26 +576,6 @@ def render_network_state( ) -def network_state_to_eni(network_state, header=None, render_hwaddress=False): - # render the provided network state, return a string of equivalent eni - eni_path = "etc/network/interfaces" - renderer = Renderer( - config={ - "eni_path": eni_path, - "eni_header": header, - "netrules_path": None, - } - ) - if not header: - header = "" - if not header.endswith("\n"): - header += "\n" - contents = renderer._render_interfaces( - network_state, render_hwaddress=render_hwaddress - ) - return header + contents - - def available(target=None): expected = ["ifquery", "ifup", "ifdown"] search = ["/sbin", "/usr/sbin"] diff --git a/cloudinit/sources/DataSourceScaleway.py b/cloudinit/sources/DataSourceScaleway.py index 4952e314edd..589ef615141 100644 --- a/cloudinit/sources/DataSourceScaleway.py +++ b/cloudinit/sources/DataSourceScaleway.py @@ -255,30 +255,6 @@ def ds_detect(): if "scaleway" in cmdline: return True - def _set_urls_on_ip_version(self, proto, urls): - - if proto not in ["ipv4", "ipv6"]: - LOG.debug("Invalid IP version : %s", proto) - return [] - - filtered_urls = [] - for url in urls: - # Numeric IPs - address = urlparse(url).netloc - if address[0] == "[": - address = address[1:-1] - addr_proto = socket.getaddrinfo( - address, None, proto=socket.IPPROTO_TCP - )[0][0] - if addr_proto == socket.AF_INET and proto == "ipv4": - filtered_urls += [url] - continue - elif addr_proto == socket.AF_INET6 and proto == "ipv6": - filtered_urls += [url] - continue - - return filtered_urls - def _get_data(self): # The DataSource uses EventType.BOOT so we are called more than once. diff --git a/cloudinit/util.py b/cloudinit/util.py index e2f04a40209..261e138eabc 100644 --- a/cloudinit/util.py +++ b/cloudinit/util.py @@ -1811,18 +1811,6 @@ def hash_blob(blob, routine: str, mlen=None) -> str: return digest -def hash_buffer(f: io.BufferedIOBase) -> bytes: - """Hash the content of a binary buffer using SHA1. - - @param f: buffered binary stream to hash. - @return: digested data as bytes. - """ - hasher = hashlib.sha1() - for chunk in iter(lambda: f.read(io.DEFAULT_BUFFER_SIZE), b""): - hasher.update(chunk) - return hasher.digest() - - def is_user(name): try: if pwd.getpwnam(name): diff --git a/tests/unittests/config/test_cc_landscape.py b/tests/unittests/config/test_cc_landscape.py index 7ddbe77f37a..bc79da7c081 100644 --- a/tests/unittests/config/test_cc_landscape.py +++ b/tests/unittests/config/test_cc_landscape.py @@ -43,14 +43,12 @@ def test_handler_restarts_landscape_client(self, m_subp, tmpdir): mycloud = get_cloud("ubuntu") mycloud.distro = mock.MagicMock() cfg = {"landscape": {"client": {}}} - default_fn = tmpdir.join("default") wrap_and_call( "cloudinit.config.cc_landscape", { "LSC_CLIENT_CFG_FILE": { "new": tmpdir.join("client.conf").strpath }, - "LS_DEFAULT_FILE": {"new": default_fn.strpath}, }, cc_landscape.handle, "notimportant", @@ -87,7 +85,6 @@ def test_handler_installs_client_from_ppa_and_supports_overrides( """Call landscape-config with any filesystem overrides.""" mycloud = get_cloud("ubuntu") mycloud.distro = mock.MagicMock() - default_fn = tmpdir.join("default") client_fn = tmpdir.join("client.conf") client_fn.write("[client]\ndata_path = /var/lib/data\n") cfg = { @@ -119,7 +116,6 @@ def test_handler_installs_client_from_ppa_and_supports_overrides( "cloudinit.config.cc_landscape", { "LSC_CLIENT_CFG_FILE": {"new": client_fn.strpath}, - "LS_DEFAULT_FILE": {"new": default_fn.strpath}, }, cc_landscape.handle, "notimportant", @@ -139,7 +135,6 @@ def test_handler_writes_merged_client_config_file_with_defaults( # Write existing sparse client.conf file client_fn = tmpdir.join("client.conf") client_fn.write("[client]\ncomputer_title = My PC\n") - default_fn = tmpdir.join("default") mycloud = get_cloud("ubuntu") mycloud.distro = mock.MagicMock() cfg = {"landscape": {"client": {}}} @@ -168,7 +163,6 @@ def test_handler_writes_merged_client_config_file_with_defaults( "cloudinit.config.cc_landscape", { "LSC_CLIENT_CFG_FILE": {"new": client_fn.strpath}, - "LS_DEFAULT_FILE": {"new": default_fn.strpath}, }, cc_landscape.handle, "notimportant", @@ -185,7 +179,6 @@ def test_handler_writes_merged_provided_cloudconfig_with_defaults( # Write empty sparse client.conf file client_fn = tmpdir.join("client.conf") client_fn.write("") - default_fn = tmpdir.join("default") mycloud = get_cloud("ubuntu") mycloud.distro = mock.MagicMock() cfg = {"landscape": {"client": {"computer_title": 'My" PC'}}} @@ -214,7 +207,6 @@ def test_handler_writes_merged_provided_cloudconfig_with_defaults( "cloudinit.config.cc_landscape", { "LSC_CLIENT_CFG_FILE": {"new": client_fn.strpath}, - "LS_DEFAULT_FILE": {"new": default_fn.strpath}, }, cc_landscape.handle, "notimportant", diff --git a/tests/unittests/config/test_schema.py b/tests/unittests/config/test_schema.py index 0d335bad996..428a2f86a32 100644 --- a/tests/unittests/config/test_schema.py +++ b/tests/unittests/config/test_schema.py @@ -22,7 +22,6 @@ from cloudinit import features, performance from cloudinit.config.schema import ( - VERSIONED_USERDATA_SCHEMA_FILE, SchemaProblem, SchemaType, SchemaValidationError, @@ -57,6 +56,7 @@ M_PATH = "cloudinit.config.schema." DEPRECATED_LOG_LEVEL = 35 +VERSIONED_USERDATA_SCHEMA_FILE = "versions.schema.cloud-config.json" def get_schemas() -> dict: @@ -973,9 +973,8 @@ class TestAnnotatedCloudconfigFile: def test_annotated_cloudconfig_file_no_schema_errors(self): """With no schema_errors, print the original content.""" content = b"ntp:\n pools: [ntp1.pools.com]\n" - parse_cfg, schemamarks = load_with_marks(content) + _, schemamarks = load_with_marks(content) assert content == annotated_cloudconfig_file( - parse_cfg, content, schemamarks=schemamarks, schema_errors=[], @@ -1005,14 +1004,13 @@ def test_annotated_cloudconfig_file_schema_annotates_and_adds_footer(self): """ ) - parsed_config, schemamarks = load_with_marks(content[13:]) + _, schemamarks = load_with_marks(content[13:]) schema_errors = [ SchemaProblem("ntp", "Some type error"), SchemaProblem("ntp.pools.0", "-99 is not a string"), SchemaProblem("ntp.pools.1", "75 is not a string"), ] assert expected == annotated_cloudconfig_file( - parsed_config, content, schemamarks=schemamarks, schema_errors=schema_errors, @@ -1038,13 +1036,12 @@ def test_annotated_cloudconfig_file_annotates_separate_line_items(self): - 75 # E2 """ ) - parsed_config, schemamarks = load_with_marks(content[13:]) + _, schemamarks = load_with_marks(content[13:]) schema_errors = [ SchemaProblem("ntp.pools.0", "-99 is not a string"), SchemaProblem("ntp.pools.1", "75 is not a string"), ] assert expected in annotated_cloudconfig_file( - parsed_config, content, schemamarks=schemamarks, schema_errors=schema_errors, diff --git a/tests/unittests/distros/package_management/test_apt.py b/tests/unittests/distros/package_management/test_apt.py index 5589b36a9f8..00523873f3b 100644 --- a/tests/unittests/distros/package_management/test_apt.py +++ b/tests/unittests/distros/package_management/test_apt.py @@ -40,7 +40,7 @@ def test_simple_command(self, m_apt_avail, m_subp, m_which): @mock.patch("cloudinit.distros.package_management.apt.time.sleep") def test_wait_for_lock(self, m_sleep, m_apt_avail, m_subp, m_which): apt = Apt(runner=mock.Mock(), apt_get_wrapper_command=("dontcare",)) - apt._wait_for_apt_command("stub", {"args": "stub2"}) + apt._wait_for_apt_command({"args": "stub2"}) assert m_sleep.call_args_list == [mock.call(1), mock.call(1)] assert m_subp.call_args_list == [mock.call(args="stub2")] @@ -58,7 +58,7 @@ def test_lock_wait_timeout( ): apt = Apt(runner=mock.Mock(), apt_get_wrapper_command=("dontcare",)) with pytest.raises(TimeoutError): - apt._wait_for_apt_command("stub", "stub2", timeout=5) + apt._wait_for_apt_command("stub2", timeout=5) assert m_subp.call_args_list == [] @mock.patch( @@ -72,7 +72,7 @@ def test_lock_exception_wait(self, m_sleep, m_apt_avail, m_subp, m_which): exit_code=100, stderr="Could not get apt lock" ) m_subp.side_effect = [exception, exception, "return_thing"] - ret = apt._wait_for_apt_command("stub", {"args": "stub2"}) + ret = apt._wait_for_apt_command({"args": "stub2"}) assert ret == "return_thing" @mock.patch( @@ -92,7 +92,7 @@ def test_lock_exception_timeout( exit_code=100, stderr="Could not get apt lock" ) with pytest.raises(TimeoutError): - apt._wait_for_apt_command("stub", {"args": "stub2"}, timeout=5) + apt._wait_for_apt_command({"args": "stub2"}, timeout=5) def test_search_stem(self, m_subp, m_which, mocker): """Test that containing `-`, `^`, `/`, or `=` is handled correctly.""" diff --git a/tests/unittests/test_net.py b/tests/unittests/test_net.py index 3e0d789c73e..531302f70e1 100644 --- a/tests/unittests/test_net.py +++ b/tests/unittests/test_net.py @@ -3892,47 +3892,6 @@ def test_netplan_postcmds( mock_subp.assert_has_calls(expected) -class TestEniNetworkStateToEni: - mycfg = { - "config": [ - { - "type": "physical", - "name": "eth0", - "mac_address": "c0:d6:9f:2c:e8:80", - "subnets": [{"type": "dhcp"}], - } - ], - "version": 1, - } - my_mac = "c0:d6:9f:2c:e8:80" - - def test_no_header(self): - rendered = eni.network_state_to_eni( - network_state=network_state.parse_net_config_data(self.mycfg), - render_hwaddress=True, - ) - assert self.my_mac in rendered - assert "hwaddress" in rendered - - def test_with_header(self): - header = "# hello world\n" - rendered = eni.network_state_to_eni( - network_state=network_state.parse_net_config_data(self.mycfg), - header=header, - render_hwaddress=True, - ) - assert header in rendered - assert self.my_mac in rendered - - def test_no_hwaddress(self): - rendered = eni.network_state_to_eni( - network_state=network_state.parse_net_config_data(self.mycfg), - render_hwaddress=False, - ) - assert self.my_mac not in rendered - assert "hwaddress" not in rendered - - class TestCmdlineConfigParsing: simple_cfg = { "config": [ diff --git a/tests/unittests/test_util.py b/tests/unittests/test_util.py index 221e21de5c2..8a107191b0e 100644 --- a/tests/unittests/test_util.py +++ b/tests/unittests/test_util.py @@ -3248,27 +3248,6 @@ def test_ips_need_not_be_resolved(self, m_getaddr, m_dns): assert not m_getaddr.called -class TestHashBuffer: - def test_in_memory(self): - buf = io.BytesIO(b"hola") - assert ( - util.hash_buffer(buf) - == b"\x99\x80\x0b\x85\xd38>:/\xb4^\xb7\xd0\x06jHy\xa9\xda\xd0" - ) - - def test_file(self, tmp_path): - content = b"hola" - file = tmp_path / "file.txt" - with file.open("wb") as f: - f.write(content) - - with file.open("rb") as f: - assert ( - util.hash_buffer(f) - == b"\x99\x80\x0b\x85\xd38>:/\xb4^\xb7\xd0\x06jHy\xa9\xda\xd0" - ) - - class TestMaybeB64Decode: """Test the maybe_b64decode helper function."""