summaryrefslogtreecommitdiff
path: root/cloudinit
diff options
context:
space:
mode:
authorMina Galić <me+git@igalic.co>2022-10-14 20:01:19 +0100
committerGitHub <noreply@github.com>2022-10-14 14:01:19 -0500
commita5c9e4ad6577c1c2ff64552d6d67101da4cfe6cf (patch)
tree5cb6495b1570ed81571def1fd5359c010a9a4878 /cloudinit
parentee8fa37a049226f4b01284854d858aa0fa1073ee (diff)
downloadcloud-init-git-a5c9e4ad6577c1c2ff64552d6d67101da4cfe6cf.tar.gz
cc_ntp: add support for BSDs (#1759)
cc_ntp: add support for BSDs *BSDs have ntpd installed in base the base system This PR extends cc_ntp to add support for ntpd, openntpd, and chrony on the FreeBSD, and OpenBSD. To make tests pass, we ensure that we are mocking functions, not entire classes. Co-authored-by: Ryan Harper <rharper@woxford.com> Co-authored-by: James Falcon <james.falcon@canonical.com> Sponsored by: FreeBSD Foundation LP: #1990041
Diffstat (limited to 'cloudinit')
-rw-r--r--cloudinit/config/cc_ntp.py51
-rw-r--r--cloudinit/config/schemas/schema-cloud-config-v1.json2
2 files changed, 52 insertions, 1 deletions
diff --git a/cloudinit/config/cc_ntp.py b/cloudinit/config/cc_ntp.py
index fd58873e..b03b2074 100644
--- a/cloudinit/config/cc_ntp.py
+++ b/cloudinit/config/cc_ntp.py
@@ -31,7 +31,9 @@ distros = [
"debian",
"eurolinux",
"fedora",
+ "freebsd",
"miraclelinux",
+ "openbsd",
"openEuler",
"openmandriva",
"opensuse",
@@ -68,6 +70,14 @@ NTP_CLIENT_CONFIG = {
"template_name": "ntp.conf.{distro}",
"template": None,
},
+ "openntpd": {
+ "check_exe": "ntpd",
+ "confpath": "/etc/ntpd.conf",
+ "packages": [],
+ "service_name": "ntpd",
+ "template_name": "ntpd.conf.{distro}",
+ "template": None,
+ },
"systemd-timesyncd": {
"check_exe": "/lib/systemd/systemd-timesyncd",
"confpath": "/etc/systemd/timesyncd.conf.d/cloud-init.conf",
@@ -104,6 +114,29 @@ DISTRO_CLIENT_CONFIG = {
"confpath": "/etc/chrony/chrony.conf",
},
},
+ "freebsd": {
+ "ntp": {
+ "confpath": "/etc/ntp.conf",
+ "service_name": "ntpd",
+ "template_name": "ntp.conf.{distro}",
+ },
+ "chrony": {
+ "confpath": "/usr/local/etc/chrony.conf",
+ "packages": ["chrony"],
+ "service_name": "chronyd",
+ "template_name": "chrony.conf.{distro}",
+ },
+ "openntpd": {
+ "check_exe": "/usr/local/sbin/ntpd",
+ "confpath": "/usr/local/etc/ntp.conf",
+ "packages": ["openntpd"],
+ "service_name": "openntpd",
+ "template_name": "ntpd.conf.openbsd",
+ },
+ },
+ "openbsd": {
+ "openntpd": {},
+ },
"openmandriva": {
"chrony": {
"service_name": "chronyd",
@@ -550,6 +583,24 @@ def handle(
packages=ntp_client_config["packages"],
check_exe=ntp_client_config["check_exe"],
)
+ if util.is_BSD():
+ if ntp_client_config.get("service_name") != "ntpd":
+ try:
+ cloud.distro.manage_service("stop", "ntpd")
+ except subp.ProcessExecutionError:
+ LOG.warning("Failed to stop base ntpd service")
+ try:
+ cloud.distro.manage_service("disable", "ntpd")
+ except subp.ProcessExecutionError:
+ LOG.warning("Failed to disable base ntpd service")
+
+ try:
+ cloud.distro.manage_service(
+ "enable", ntp_client_config.get("service_name")
+ )
+ except subp.ProcessExecutionError as e:
+ LOG.exception("Failed to enable ntp service: %s", e)
+ raise
try:
cloud.distro.manage_service(
"reload", ntp_client_config.get("service_name")
diff --git a/cloudinit/config/schemas/schema-cloud-config-v1.json b/cloudinit/config/schemas/schema-cloud-config-v1.json
index 9b314077..737decbb 100644
--- a/cloudinit/config/schemas/schema-cloud-config-v1.json
+++ b/cloudinit/config/schemas/schema-cloud-config-v1.json
@@ -1488,7 +1488,7 @@
"ntp_client": {
"type": "string",
"default": "auto",
- "description": "Name of an NTP client to use to configure system NTP.\nWhen unprovided or 'auto' the default client preferred\nby the distribution will be used. The following\nbuilt-in client names can be used to override existing\nconfiguration defaults: chrony, ntp, ntpdate,\nsystemd-timesyncd."
+ "description": "Name of an NTP client to use to configure system NTP.\nWhen unprovided or 'auto' the default client preferred\nby the distribution will be used. The following\nbuilt-in client names can be used to override existing\nconfiguration defaults: chrony, ntp, openntpd,\nntpdate, systemd-timesyncd."
},
"enabled": {
"type": "boolean",