Skip to content

Commit 0f87ff3

Browse files
committed
fix: migrate from ntp client package installed from ntp to ntpsec
Change the installed ntp client package from ntp to ntpsec when user-data requests `ntp_client: ntp`. Fix inability to install ntp deb packages from universe in Ubuntu for some time which resulted in errors from `cloud-init status` and failed integration tests. Most distributions have migrated away from ntp to ntpsec as replacement implementation which has better security and maintenance as a project. Package migration has happened in many distributions already: - Ubuntu was in Xenial 2016 - OpenSUSE available since 2019 - Fedora 34 2021 - Debian Bookworm 2023 - Alpine 3.10 2019
1 parent d2bf883 commit 0f87ff3

File tree

2 files changed

+23
-7
lines changed

2 files changed

+23
-7
lines changed

cloudinit/config/cc_ntp.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@
6868
"ntp": {
6969
"check_exe": "ntpd",
7070
"confpath": NTP_CONF,
71-
"packages": ["ntp"],
71+
"packages": ["ntpsec"],
7272
"service_name": "ntp",
7373
"template_name": "ntp.conf.{distro}",
7474
"template": None,
@@ -347,8 +347,6 @@ def install_ntp_client(install_func, packages=None, check_exe="ntpd"):
347347
"""
348348
if subp.which(check_exe):
349349
return
350-
if packages is None:
351-
packages = ["ntp"]
352350

353351
install_func(packages)
354352

tests/unittests/config/test_cc_ntp.py

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -577,15 +577,25 @@ def test_user_cfg_ntp_client_auto_uses_distro_clients(self, m_which):
577577
m_which.assert_has_calls(expected_calls)
578578
assert sorted(expected_cfg) == sorted(cfg)
579579

580+
@pytest.mark.parametrize(
581+
"client,command,installed_package",
582+
(("ntpdate", "ntpdate", "ntpdate"), ("ntp", "ntpd", "ntpsec")),
583+
)
580584
@mock.patch("cloudinit.config.cc_ntp.write_ntp_config_template")
581585
@mock.patch("cloudinit.cloud.Cloud.get_template_filename")
582586
@mock.patch("cloudinit.config.cc_ntp.subp.which")
583587
@mock.patch("cloudinit.util.rename")
584588
def test_ntp_custom_client_overrides_installed_clients(
585-
self, m_rename, m_which, m_tmpfn, m_write
589+
self,
590+
m_rename,
591+
m_which,
592+
m_tmpfn,
593+
m_write,
594+
client,
595+
command,
596+
installed_package,
586597
):
587598
"""Test user client is installed despite other clients present"""
588-
client = "ntpdate"
589599
cfg = {"ntp": {"ntp_client": client}}
590600
for distro in cc_ntp.distros:
591601
# client is not installed
@@ -597,8 +607,16 @@ def test_ntp_custom_client_overrides_installed_clients(
597607
mycloud.distro, "manage_service"
598608
):
599609
cc_ntp.handle("notimportant", cfg, mycloud, [])
600-
m_install.assert_called_with([client])
601-
m_which.assert_called_with(client)
610+
distro_client_packages = (
611+
cc_ntp.DISTRO_CLIENT_CONFIG.get(distro, {})
612+
.get(client, {})
613+
.get("packages")
614+
)
615+
if distro_client_packages is None:
616+
m_install.assert_called_with([installed_package])
617+
else:
618+
m_install.assert_called_with(distro_client_packages)
619+
m_which.assert_called_with(command)
602620

603621
@mock.patch("cloudinit.config.cc_ntp.subp.which")
604622
def test_ntp_system_config_overrides_distro_builtin_clients(self, m_which):

0 commit comments

Comments
 (0)