You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[hostcfg] Fix timezone mismatch after image upgrade (#312)
Why I did it
To fix an issue where newly installed SONiC images default /etc/localtime to UTC even when the previous image
was configured with and used a different timezone, and config save was executed before the image update.
This causes a mismatch between the timezone defined in CONFIG_DB and the one defined in the Linux file /etc/localtime, because when the new image comes up with a new filesystem, the Linux file /etc/localtime is created with the default UTC, while the timezone value in CONFIG_DB (DEVICE_METADATA|localhost|timezone) is preserved from the previous image.
How I did it
In src/sonic-host-services/scripts/hostcfgd::DeviceMetaCfg:load, we already read the timezone from CONFIG_DB to save it for future events (DeviceMetaCfg:timezone_update observes changes in DEVICE_METADATA).
So at this point, when hostcfgd is up, we can simply update the Linux file /etc/localtime with the initial correct timezone value from CONFIG_DB by executing (only if it differs from the current /etc/localtime):
timedatectl set-timezone
(as is already done in timezone_update).
The same pattern exists in hostcfgd::DnsCfg:load.
How to verify it
Set a non-UTC timezone on the current image: config clock timezone Asia/Jerusalem
Run config save
Install a new image
Reboot and check that hostcfgd is up: systemctl status hostcfgd (~1m)
Verify that the timezone is identical in CONFIG_DB and /etc/localtime:
timedatectl
date
cat /etc/localtime
cat /etc/sonic/config_db.json | grep timezone
hget "DEVICE_METADATA|localhost" "timezone"
call(mock.ANY, 'DeviceMetaCfg: timezone update to America/New_York'),
928
+
call(mock.ANY, 'DeviceMetaCfg: Failed to set-timezone America/New_York and restart rsyslog: Command \'[\'timedatectl\', \'set-timezone\', \'America/New_York\']\' returned non-zero exit status 1.')
0 commit comments