kdevops.lists.linux.dev archive mirror
 help / color / mirror / Atom feed
From: Luis Chamberlain <mcgrof@kernel.org>
To: kdevops@lists.linux.dev
Cc: Luis Chamberlain <mcgrof@kernel.org>
Subject: [PATCH] devconfig: fix setting node timezone
Date: Mon,  8 Apr 2024 15:25:15 -0700	[thread overview]
Message-ID: <20240408222515.4055475-1-mcgrof@kernel.org> (raw)

It turns out that just relying on the clock offset being set won't
ensure we have the right time set on the nodes, so when timectl is
enabled for NTP, we still need to set the timezone on the nodes based
on the hypervisor to be very sure we get the right time.

Below is an example where the clock offset XML settings were set on
guests with guestfs and yet the timezone on the nodes was set to
Eastern. To fix this we must keep a kconfig option which matches the
hypervisor, and use that value on the nodes to set the timezone.

mcgrof@some-hypervisor-01 /xfs1/base/kdevops (git::main)$ grep "clock offset" guestfs/base-xfs-nocrc/base-xfs-nocrc.xml
  <clock offset='localtime'>
mcgrof@some-hypervisor-01 /xfs1/base/kdevops (git::main)$ ssh base-xfs-reflink timedatectl
               Local time: Mon 2024-04-08 17:32:38 EDT
           Universal time: Mon 2024-04-08 21:32:38 UTC
                 RTC time: Mon 2024-04-08 21:32:38
                Time zone: US/Eastern (EDT, -0400)
System clock synchronized: yes
              NTP service: active
          RTC in local TZ: no
mcgrof@some-hypervisor-01 /xfs1/base/kdevops (git::main)$ timedatectl
               Local time: Mon 2024-04-08 21:32:42 UTC
           Universal time: Mon 2024-04-08 21:32:42 UTC
                 RTC time: Mon 2024-04-08 21:32:42
                Time zone: UTC (UTC, +0000)
System clock synchronized: yes
              NTP service: active
          RTC in local TZ: no

Fixes: de233a386941 ("devconfig: Remove DEVCONFIG_ENABLE_SYSTEMD_TIMESYNCD_TIMEZONE"
Signed-off-by: Luis Chamberlain <mcgrof@kernel.org>
---
 Makefile.min_deps                           | 1 +
 kconfigs/Kconfig.ansible_provisioning       | 4 ++++
 playbooks/roles/devconfig/defaults/main.yml | 1 +
 playbooks/roles/devconfig/tasks/main.yml    | 9 +++++++++
 scripts/systemd-timesync.Makefile           | 1 +
 5 files changed, 16 insertions(+)

diff --git a/Makefile.min_deps b/Makefile.min_deps
index 9d8f205799c4..ce0a82595074 100644
--- a/Makefile.min_deps
+++ b/Makefile.min_deps
@@ -10,6 +10,7 @@ BINARY_DEPS += sudo
 BINARY_DEPS += make
 BINARY_DEPS += nc
 BINARY_DEPS += ansible-playbook
+BINARY_DEPS += timedatectl
 
 BINARY_DEPS_VCHECKS := $(subst $(TOPDIR)/,,$(wildcard $(TOPDIR)/scripts/version_check/*))
 
diff --git a/kconfigs/Kconfig.ansible_provisioning b/kconfigs/Kconfig.ansible_provisioning
index 82a6f822c3f5..347992e24ab2 100644
--- a/kconfigs/Kconfig.ansible_provisioning
+++ b/kconfigs/Kconfig.ansible_provisioning
@@ -217,6 +217,10 @@ config DEVCONFIG_ENABLE_SYSTEMD_TIMESYNCD
 
 if DEVCONFIG_ENABLE_SYSTEMD_TIMESYNCD
 
+config DEVCONFIG_SYSTEMD_TIMESYNCD_TIMEZONE
+	string
+	default $(shell, timedatectl show -p Timezone --value)
+
 config DEVCONFIG_ENABLE_SYSTEMD_TIMESYNCD_NTP
 	bool "Enable systemd-timesyncd NTP"
 	default y
diff --git a/playbooks/roles/devconfig/defaults/main.yml b/playbooks/roles/devconfig/defaults/main.yml
index b48b4cce8e00..3fe2605c87e8 100644
--- a/playbooks/roles/devconfig/defaults/main.yml
+++ b/playbooks/roles/devconfig/defaults/main.yml
@@ -50,6 +50,7 @@ devconfig_systemd_journal_remote_url: "http://192.168.124.1"
 devconfig_systemd_journal_remote_path: "/var/log/journal/remote/"
 
 devconfig_enable_systemd_timesyncd: False
+devconfig_systemd_timesyncd_timezone: "UTC"
 devconfig_enable_systemd_timesyncd_ntp: False
 devconfig_enable_systemd_timesyncd_ntp_google: False
 devconfig_enable_systemd_timesyncd_ntp_debian: False
diff --git a/playbooks/roles/devconfig/tasks/main.yml b/playbooks/roles/devconfig/tasks/main.yml
index fec6ea3b5939..a76106b2a997 100644
--- a/playbooks/roles/devconfig/tasks/main.yml
+++ b/playbooks/roles/devconfig/tasks/main.yml
@@ -526,6 +526,15 @@
   when:
     - devconfig_enable_systemd_timesyncd_ntp|bool
 
+- name: Override timezone on nodes
+  tags: [ 'timesyncd' ]
+  become: yes
+  become_flags: 'su - -c'
+  become_method: sudo
+  command: "timedatectl set-timezone {{ devconfig_systemd_timesyncd_timezone }}"
+  when:
+    - devconfig_enable_systemd_timesyncd_ntp|bool
+
 - name: Restart systemd-timesyncd.service on the client
   become: yes
   become_flags: 'su - -c'
diff --git a/scripts/systemd-timesync.Makefile b/scripts/systemd-timesync.Makefile
index 11950cd9e598..d11d135113d8 100644
--- a/scripts/systemd-timesync.Makefile
+++ b/scripts/systemd-timesync.Makefile
@@ -2,6 +2,7 @@
 
 ifeq (y,$(CONFIG_DEVCONFIG_ENABLE_SYSTEMD_TIMESYNCD))
 ANSIBLE_EXTRA_ARGS += devconfig_enable_systemd_timesyncd='True'
+ANSIBLE_EXTRA_ARGS_DIRECT += devconfig_systemd_timesyncd_timezone='$(subst ",,$(CONFIG_DEVCONFIG_SYSTEMD_TIMESYNCD_TIMEZONE))'
 
 ifeq (y,$(CONFIG_DEVCONFIG_ENABLE_SYSTEMD_TIMESYNCD_NTP))
 ANSIBLE_EXTRA_ARGS += devconfig_enable_systemd_timesyncd_ntp='True'
-- 
2.43.0


             reply	other threads:[~2024-04-08 22:25 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-08 22:25 Luis Chamberlain [this message]
2024-04-09  0:53 ` [PATCH] devconfig: fix setting node timezone Chuck Lever
2024-04-09  3:36   ` Luis Chamberlain
2024-04-09 13:29     ` Chuck Lever
2024-04-09 14:22       ` Chuck Lever
2024-04-09 16:51         ` Chuck Lever
2024-04-10 15:43       ` Luis Chamberlain
2024-04-10 15:45         ` Chuck Lever
2024-04-11  0:53           ` Luis Chamberlain

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240408222515.4055475-1-mcgrof@kernel.org \
    --to=mcgrof@kernel.org \
    --cc=kdevops@lists.linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).