2019-12-02 22:28:53 +00:00
|
|
|
import ./make-test-python.nix (
|
|
|
|
{ pkgs, ... }:
|
|
|
|
{
|
|
|
|
name = "timezone";
|
2024-06-21 11:41:50 +00:00
|
|
|
meta.maintainers = with pkgs.lib.maintainers; [ ];
|
2024-12-10 19:26:33 +00:00
|
|
|
|
2019-12-02 22:28:53 +00:00
|
|
|
nodes = {
|
|
|
|
node_eutz =
|
|
|
|
{ pkgs, ... }:
|
|
|
|
{
|
|
|
|
time.timeZone = "Europe/Amsterdam";
|
2024-12-10 19:26:33 +00:00
|
|
|
};
|
|
|
|
|
2019-12-02 22:28:53 +00:00
|
|
|
node_nulltz =
|
|
|
|
{ pkgs, ... }:
|
2024-12-10 19:26:33 +00:00
|
|
|
{
|
2019-12-02 22:28:53 +00:00
|
|
|
time.timeZone = null;
|
2024-12-10 19:26:33 +00:00
|
|
|
};
|
2019-12-02 22:28:53 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
testScript =
|
|
|
|
{ nodes, ... }:
|
|
|
|
''
|
|
|
|
node_eutz.wait_for_unit("dbus.socket")
|
2024-12-10 19:26:33 +00:00
|
|
|
|
2019-12-02 22:28:53 +00:00
|
|
|
with subtest("static - Ensure timezone change gives the correct result"):
|
|
|
|
node_eutz.fail("timedatectl set-timezone Asia/Tokyo")
|
|
|
|
date_result = node_eutz.succeed('date -d @0 "+%Y-%m-%d %H:%M:%S"')
|
|
|
|
assert date_result == "1970-01-01 01:00:00\n", "Timezone seems to be wrong"
|
2024-12-10 19:26:33 +00:00
|
|
|
|
2019-12-02 22:28:53 +00:00
|
|
|
node_nulltz.wait_for_unit("dbus.socket")
|
2024-12-10 19:26:33 +00:00
|
|
|
|
2019-12-02 22:28:53 +00:00
|
|
|
with subtest("imperative - Ensure timezone defaults to UTC"):
|
|
|
|
date_result = node_nulltz.succeed('date -d @0 "+%Y-%m-%d %H:%M:%S"')
|
|
|
|
print(date_result)
|
|
|
|
assert (
|
|
|
|
date_result == "1970-01-01 00:00:00\n"
|
|
|
|
), "Timezone seems to be wrong (not UTC)"
|
2024-12-10 19:26:33 +00:00
|
|
|
|
2019-12-02 22:28:53 +00:00
|
|
|
with subtest("imperative - Ensure timezone adjustment produces expected result"):
|
|
|
|
node_nulltz.succeed("timedatectl set-timezone Asia/Tokyo")
|
2024-12-10 19:26:33 +00:00
|
|
|
|
2019-12-02 22:28:53 +00:00
|
|
|
# Adjustment should be taken into account
|
|
|
|
date_result = node_nulltz.succeed('date -d @0 "+%Y-%m-%d %H:%M:%S"')
|
|
|
|
print(date_result)
|
|
|
|
assert date_result == "1970-01-01 09:00:00\n", "Timezone was not adjusted"
|
2024-12-10 19:26:33 +00:00
|
|
|
|
2019-12-02 22:28:53 +00:00
|
|
|
with subtest("imperative - Ensure timezone adjustment persists across reboot"):
|
|
|
|
# Adjustment should persist across a reboot
|
|
|
|
node_nulltz.shutdown()
|
|
|
|
node_nulltz.wait_for_unit("dbus.socket")
|
|
|
|
date_result = node_nulltz.succeed('date -d @0 "+%Y-%m-%d %H:%M:%S"')
|
|
|
|
print(date_result)
|
|
|
|
assert (
|
|
|
|
date_result == "1970-01-01 09:00:00\n"
|
|
|
|
), "Timezone adjustment was not persisted"
|
|
|
|
'';
|
|
|
|
}
|
|
|
|
)
|