Skip to content

Conversation

@mssonicbld
Copy link

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

  1. Set a non-UTC timezone on the current image: config clock timezone Asia/Jerusalem
  2. Run config save
  3. Install a new image
  4. Reboot and check that hostcfgd is up: systemctl status hostcfgd (~1m)
  5. 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"

**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 <timezone>
(as is already done in timezone_update).
The same pattern exists in hostcfgd::DnsCfg:load.

**How to verify it**
1. Set a non-UTC timezone on the current image: config clock timezone Asia/Jerusalem
2. Run config save
3. Install a new image
4. Reboot and check that hostcfgd is up: systemctl status hostcfgd (~1m)
5. 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"
@mssonicbld
Copy link
Author

Original PR: #312

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant