From: Yu Watanabe Date: Wed, 13 Jul 2022 01:24:53 +0000 (+0900) Subject: test-network: save and restore timezone X-Git-Tag: v252-rc1~670 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f54dce2d4fd1199dcf2dfcae44455bf77985f819;p=thirdparty%2Fsystemd.git test-network: save and restore timezone Several DHCP client tests change the system timezone. Let's save the current timezone at the beginning, and restore it with the saved value at the end. --- diff --git a/test/test-network/systemd-networkd-tests.py b/test/test-network/systemd-networkd-tests.py index bb9ca435856..50ce9538498 100755 --- a/test/test-network/systemd-networkd-tests.py +++ b/test/test-network/systemd-networkd-tests.py @@ -71,6 +71,7 @@ protected_links = { saved_routes = None saved_ipv4_rules = None saved_ipv6_rules = None +saved_timezone = None def rm_f(path): if os.path.exists(path): @@ -466,6 +467,17 @@ def flush_l2tp_tunnels(): else: print(f'Cannot remove L2TP tunnel {tid}, ignoring.') +def save_timezone(): + global saved_timezone + r = run('timedatectl show --value --property Timezone') + if r.returncode == 0: + saved_timezone = r.stdout.rstrip() + print(f'### Saved timezone: {saved_timezone}') + +def restore_timezone(): + if saved_timezone: + call(f'timedatectl set-timezone {saved_timezone}') + def read_link_attr(*args): with open(os.path.join('/sys/class/net', *args), encoding='utf-8') as f: return f.readline().strip() @@ -615,6 +627,7 @@ def setUpModule(): save_existing_links() save_routes() save_routing_policy_rules() + save_timezone() drop_in = [ '[Unit]', @@ -711,6 +724,8 @@ def tearDownModule(): clear_network_units() clear_networkd_conf_dropins() + restore_timezone() + rm_rf('/run/systemd/system/systemd-networkd.service.d') rm_rf('/run/systemd/system/systemd-resolved.service.d') rm_rf('/run/systemd/system/systemd-udevd.service.d')