Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
67dd75e
typing: fix mypy annotation errors in test_apt_configure_sources_list_v3
sshedi Sep 1, 2026
fb92212
typing: fix mypy annotation errors in test_apt_source_v1
sshedi Sep 1, 2026
79d2efb
typing: fix mypy annotation errors in test_cc_apt_pipelining
sshedi Sep 1, 2026
0a74f66
typing: fix mypy annotation errors in test_cc_chef
sshedi Sep 1, 2026
5ee2749
typing: fix mypy annotation errors in test_cc_final_message
sshedi Sep 1, 2026
19d9236
typing: fix mypy annotation errors in test_cc_growpart
sshedi Sep 1, 2026
c87c1ea
typing: fix mypy annotation errors in test_cc_install_hotplug
sshedi Sep 1, 2026
4b4e018
typing: fix mypy annotation errors in test_cc_keys_to_console
sshedi Aug 30, 2026
da208df
typing: fix mypy annotation errors in test_cc_puppet
sshedi Sep 1, 2026
7ba300a
typing: fix mypy annotation errors in test_cc_resizefs
sshedi Sep 1, 2026
74387d3
typing: fix mypy annotation errors in test_cc_resolv_conf
sshedi Sep 1, 2026
e1ca63f
typing: fix mypy annotation errors in test_cc_rh_subscription
sshedi Sep 1, 2026
898220f
typing: fix mypy annotation errors in test_cc_ubuntu_autoinstall
sshedi Sep 1, 2026
0fc7e17
typing: fix mypy annotation errors in test_cc_update_etc_hosts
sshedi Aug 30, 2026
34089f4
typing: fix mypy annotation errors in test_cc_users_groups
sshedi Sep 1, 2026
3e45825
typing: fix mypy annotation errors in test_cc_wireguard
sshedi Sep 1, 2026
8617ac1
typing: fix mypy annotation errors in test_cc_yum_add_repo
sshedi Sep 1, 2026
6fecd99
typing: fix mypy annotation errors in test_cc_zypper_add_repo
sshedi Sep 1, 2026
de3c43e
typing: fix mypy annotation errors in test_modules
sshedi Sep 1, 2026
0745339
typing: fix mypy annotation errors in test_schema
sshedi Sep 1, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 0 additions & 20 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -69,26 +69,6 @@ module = [
"cloudinit.sources.helpers.vmware.imc.config_nic",
"cloudinit.user_data",
"tests.unittests.analyze.test_show",
"tests.unittests.config.test_apt_configure_sources_list_v3",
"tests.unittests.config.test_apt_source_v1",
"tests.unittests.config.test_cc_apt_pipelining",
"tests.unittests.config.test_cc_chef",
"tests.unittests.config.test_cc_final_message",
"tests.unittests.config.test_cc_growpart",
"tests.unittests.config.test_cc_install_hotplug",
"tests.unittests.config.test_cc_keys_to_console",
"tests.unittests.config.test_cc_puppet",
"tests.unittests.config.test_cc_resizefs",
"tests.unittests.config.test_cc_resolv_conf",
"tests.unittests.config.test_cc_rh_subscription",
"tests.unittests.config.test_cc_ubuntu_autoinstall",
"tests.unittests.config.test_cc_update_etc_hosts",
"tests.unittests.config.test_cc_users_groups",
"tests.unittests.config.test_cc_wireguard",
"tests.unittests.config.test_cc_yum_add_repo",
"tests.unittests.config.test_cc_zypper_add_repo",
"tests.unittests.config.test_modules",
"tests.unittests.config.test_schema",
"tests.unittests.distros.test_ifconfig",
"tests.unittests.distros.test_netbsd",
"tests.unittests.distros.test_netconfig",
Expand Down
15 changes: 8 additions & 7 deletions tests/unittests/config/test_apt_configure_sources_list_v3.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"""

import stat
from typing import Any

import pytest

Expand Down Expand Up @@ -238,7 +239,7 @@ def test_apt_v3_empty_cfg_source_list_by_distro(
"_should_configure_on_empty_apt",
return_value=SubpResult(True, "test"),
)
cc_apt_configure.handle("test", {"apt": {}}, mycloud, None)
cc_apt_configure.handle("test", {"apt": {}}, mycloud, [])

sources_file = tmpdir.join(f"/etc/apt/sources.list.d/{distro}.sources")
if template_present:
Expand All @@ -257,13 +258,13 @@ def test_apt_v3_empty_cfg_source_list_by_distro(
def test_apt_v3_source_list_ubuntu_snappy(self, mocker):
"""test_apt_v3_source_list_ubuntu_snappy - without custom sources or
params"""
cfg = {"apt": {}}
cfg: dict = {"apt": {}}
mycloud = get_cloud()

mock_writefile = mocker.patch.object(util, "write_file")
mock_issnappy = mocker.patch.object(util, "system_is_snappy")
mock_issnappy.return_value = True
cc_apt_configure.handle("test", cfg, mycloud, None)
cc_apt_configure.handle("test", cfg, mycloud, [])
mock_writefile.assert_not_called()
assert 1 == mock_issnappy.call_count

Expand Down Expand Up @@ -315,7 +316,7 @@ def test_apt_v3_source_list_psm_deb822_feature_aware(

util.write_file(tmpl_file, tmpl_content)
mycloud = get_cloud("ubuntu")
cc_apt_configure.handle("test", {"apt": cfg}, mycloud, None)
cc_apt_configure.handle("test", {"apt": cfg}, mycloud, [])

sources_file = tmpdir.join(apt_file)
assert expected == sources_file.read()
Expand Down Expand Up @@ -369,7 +370,7 @@ def test_apt_v3_srcl_custom_deb822_feature_aware(
cc_apt_configure.features, "APT_DEB822_SOURCE_LIST_FILE", deb822
)
mocker.patch.object(Distro, "get_primary_arch", return_value="amd64")
cc_apt_configure.handle("notimportant", cfg, mycloud, None)
cc_apt_configure.handle("notimportant", cfg, mycloud, [])
sources_file = tmpdir.join(apt_file)
assert expected == sources_file.read()
assert 0o644 == stat.S_IMODE(sources_file.stat().mode)
Expand Down Expand Up @@ -428,7 +429,7 @@ def test_apt_v3_srcl_deb822_custom_psm_keys(
util.write_file(tmpl_file, tmpl_content)

# Base config
cfg = {
cfg: dict[str, Any] = {
"preserve_sources_list": False,
"primary": [{"arches": ["default"], "uri": pm}],
}
Expand All @@ -442,7 +443,7 @@ def test_apt_v3_srcl_deb822_custom_psm_keys(
cfg["security"][0]["key"] = smkey

mycloud = get_cloud(distro)
cc_apt_configure.handle("test", {"apt": cfg}, mycloud, None)
cc_apt_configure.handle("test", {"apt": cfg}, mycloud, [])

apt_file = f"/etc/apt/sources.list.d/{distro}.sources"
sources_file = tmpdir.join(apt_file)
Expand Down
11 changes: 8 additions & 3 deletions tests/unittests/config/test_apt_source_v1.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import re
from functools import partial
from textwrap import dedent
from typing import Any
from unittest import mock
from unittest.mock import call

Expand Down Expand Up @@ -844,7 +845,7 @@ def test_convert_to_new_format_dict_collision(self, apt_lists, m_gpg):
},
}
cfg_3_only = {"apt": {"sources": fullv3}}
cfg_1_and_3 = {"apt_sources": [cfg1, cfg2, cfg3]}
cfg_1_and_3: dict[str, Any] = {"apt_sources": [cfg1, cfg2, cfg3]}
cfg_1_and_3.update(cfg_3_only)

# collision (equal, so ok to remove)
Expand All @@ -869,7 +870,9 @@ def test_convert_to_new_format_dict_collision(self, apt_lists, m_gpg):
},
}
cfg_3_only = {"apt": {"sources": diff}}
cfg_1_and_3_different = {"apt_sources": [cfg1, cfg2, cfg3]}
cfg_1_and_3_different: dict[str, Any] = {
"apt_sources": [cfg1, cfg2, cfg3]
}
cfg_1_and_3_different.update(cfg_3_only)

# collision (unequal by dict having a different entry)
Expand All @@ -883,7 +886,9 @@ def test_convert_to_new_format_dict_collision(self, apt_lists, m_gpg):
}
}
cfg_3_only = {"apt": {"sources": missing}}
cfg_1_and_3_missing = {"apt_sources": [cfg1, cfg2, cfg3]}
cfg_1_and_3_missing: dict[str, Any] = {
"apt_sources": [cfg1, cfg2, cfg3]
}
cfg_1_and_3_missing.update(cfg_3_only)
# collision (unequal by dict missing an entry)
with pytest.raises(ValueError):
Expand Down
4 changes: 2 additions & 2 deletions tests/unittests/config/test_cc_apt_pipelining.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ class TestAptPipelining:
@mock.patch("cloudinit.config.cc_apt_pipelining.util.write_file")
def test_not_disabled_by_default(self, m_write_file):
"""ensure that default behaviour is to not disable pipelining"""
cc_apt_pipelining.handle("foo", {}, None, None)
cc_apt_pipelining.handle("foo", {}, mock.Mock(), [])
assert 0 == m_write_file.call_count

@mock.patch("cloudinit.config.cc_apt_pipelining.util.write_file")
def test_false_disables_pipelining(self, m_write_file):
"""ensure that pipelining can be disabled with correct config"""
cc_apt_pipelining.handle(
"foo", {"apt_pipelining": "false"}, None, None
"foo", {"apt_pipelining": "false"}, mock.Mock(), []
)
assert 1 == m_write_file.call_count
args, _ = m_write_file.call_args
Expand Down
6 changes: 3 additions & 3 deletions tests/unittests/config/test_cc_chef.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ class TestChef:

def test_no_config(self):
"""No chef directories are created on when no chef config provided"""
cfg = {}
cfg: dict = {}
cc_chef.handle("chef", cfg, get_cloud(), [])
for d in cc_chef.CHEF_DIRS:
assert not os.path.isdir(d)
Expand Down Expand Up @@ -180,11 +180,11 @@ def test_basic_config(self):
if k in unrendered_keys:
continue
assert v in c
for k, v in cc_chef.CHEF_RB_TPL_DEFAULTS.items():
for k, default_v in cc_chef.CHEF_RB_TPL_DEFAULTS.items():
if k in unrendered_keys:
continue
# the value from the cfg overrides that in the default
val = cfg["chef"].get(k, v)
val = cfg["chef"].get(k, default_v)
if isinstance(val, str):
assert val in c
c = util.load_text_file(cc_chef.CHEF_FB_PATH)
Expand Down
4 changes: 2 additions & 2 deletions tests/unittests/config/test_cc_final_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def test_boot_finished_written(
boot_finished = instance_dir / "boot-finished"

m_cloud = get_cloud(paths=paths)
handle(None, {}, m_cloud, [])
handle("", {}, m_cloud, [])

# We should not change the status of the instance directory
assert instance_dir_exists == instance_dir.exists()
Expand Down Expand Up @@ -69,7 +69,7 @@ def test_only_warn_when_datasourcenone_is_fallback_in_datasource_list(
m_cloud.datasource.dsname = dsname
Path(paths.get_ipath_cur()).mkdir()
with caplog.at_level(log_level):
handle(None, {}, m_cloud, [])
handle("", {}, m_cloud, [])

# We should not change the status of the instance directory
if expected_log:
Expand Down
25 changes: 17 additions & 8 deletions tests/unittests/config/test_cc_growpart.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def test_mode_off(mocker):
cc_growpart.handle(
name="growpart",
cfg=config,
cloud=None,
cloud=mock.Mock(),
args=[],
)
mock_resizer.assert_not_called()
Expand All @@ -127,11 +127,11 @@ def freebsd_cloud(mocker):
distro = cls("freebsd", {}, None)

cloud_obj = cloud.Cloud(
None,
None,
mock.Mock(),
mock.Mock(),
{},
distro,
None,
mock.Mock(),
)
return cloud_obj

Expand Down Expand Up @@ -333,7 +333,13 @@ def test_simple_devices(self, mocker):
)
resize_calls = []

class myresizer:
class myresizer(cc_growpart.Resizer):
def __init__(self):
pass

def available(self, devices: list) -> bool:
return True

def resize(self, diskdev, partnum, partdev, fs):
resize_calls.append((diskdev, partnum, partdev, fs))
if partdev == "/dev/YYda2":
Expand Down Expand Up @@ -518,8 +524,11 @@ def common_mocks(self, mocker):
# when needed

self.distro = MockDistro()
original_device_part_info = self.distro.device_part_info
self.distro.device_part_info = self._device_part_info_side_effect
mocker.patch.object(
self.distro,
"device_part_info",
side_effect=self._device_part_info_side_effect,
)
mocker.patch("os.stat")
mocker.patch("stat.S_ISBLK")
mocker.patch("stat.S_ISCHR")
Expand Down Expand Up @@ -553,7 +562,7 @@ def common_mocks(self, mocker):
self.resizer = mock.Mock()
self.resizer.resize = mock.Mock(return_value=(1024, 1024))
yield
self.distro.device_part_info = original_device_part_info
# device_part_info is restored automatically by mocker

def test_resize_when_encrypted(self, common_mocks, caplog):
info = cc_growpart.resize_devices(
Expand Down
30 changes: 14 additions & 16 deletions tests/unittests/config/test_cc_install_hotplug.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# This file is part of cloud-init. See LICENSE file for license information.
from collections import namedtuple
from types import SimpleNamespace
from unittest import mock

import pytest
Expand All @@ -22,15 +22,13 @@ def mocks():
m_which = mock.patch("cloudinit.subp.which", return_value=None)
m_path_exists = mock.patch("os.path.exists", return_value=False)

yield namedtuple(
"Mocks", "m_update_enabled m_write m_del m_subp m_which m_path_exists"
)(
m_update_enabled.start(),
m_write.start(),
m_del.start(),
m_subp.start(),
m_which.start(),
m_path_exists.start(),
yield SimpleNamespace(
m_update_enabled=m_update_enabled.start(),
m_write=m_write.start(),
m_del=m_del.start(),
m_subp=m_subp.start(),
m_which=m_which.start(),
m_path_exists=m_path_exists.start(),
)

m_update_enabled.stop()
Expand Down Expand Up @@ -59,7 +57,7 @@ def test_rules_installed_when_supported_and_enabled(
else:
libexecdir = "/usr/lib/cloud-init"
with mock.patch("os.path.exists", return_value=libexec_exists):
handle(None, {}, m_cloud, None)
handle("", {}, m_cloud, [])
mocks.m_write.assert_called_once_with(
filename=HOTPLUG_UDEV_PATH,
content=HOTPLUG_UDEV_RULES_TEMPLATE.format(
Expand All @@ -82,7 +80,7 @@ def test_rules_not_installed_when_unsupported(self, mocks):
m_cloud = mock.MagicMock()
m_cloud.datasource.get_supported_events.return_value = {}

handle(None, {}, m_cloud, None)
handle("", {}, m_cloud, [])
assert mocks.m_write.call_args_list == []
assert mocks.m_del.call_args_list == []
assert mocks.m_subp.call_args_list == []
Expand All @@ -94,7 +92,7 @@ def test_rules_not_installed_when_disabled(self, mocks):
EventScope.NETWORK: {EventType.HOTPLUG}
}

handle(None, {}, m_cloud, None)
handle("", {}, m_cloud, [])
assert mocks.m_write.call_args_list == []
assert mocks.m_del.call_args_list == []
assert mocks.m_subp.call_args_list == []
Expand All @@ -105,7 +103,7 @@ def test_rules_uninstalled_when_disabled(self, mocks):
m_cloud = mock.MagicMock()
m_cloud.datasource.get_supported_events.return_value = {}

handle(None, {}, m_cloud, None)
handle("", {}, m_cloud, [])
mocks.m_del.assert_called_with(HOTPLUG_UDEV_PATH)
assert mocks.m_subp.call_args_list == [
mock.call(
Expand All @@ -125,7 +123,7 @@ def test_rules_not_installed_when_no_udevadm(self, mocks):
EventScope.NETWORK: {EventType.HOTPLUG}
}

handle(None, {}, m_cloud, None)
handle("", {}, m_cloud, [])
assert mocks.m_del.call_args_list == []
assert mocks.m_write.call_args_list == []
assert mocks.m_subp.call_args_list == []
Expand All @@ -142,7 +140,7 @@ def test_rules_installed_on_ec2(self, mocks):
)

with mock.patch("os.path.exists", return_value=True):
handle(None, {}, m_cloud, None)
handle("", {}, m_cloud, [])

udev_rules = """\
# Installed by cloud-init due to network hotplug userdata
Expand Down
2 changes: 1 addition & 1 deletion tests/unittests/config/test_cc_keys_to_console.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def test_emit_keys_to_console_config(
m_path_exists.return_value = True
m_subp.return_value = ("", "")

cc_keys_to_console.handle("name", cfg, mock.Mock(), ())
cc_keys_to_console.handle("name", cfg, mock.Mock(), [])

assert subp_called == (m_subp.call_count == 1)

Expand Down
Loading
Loading