From: Dan Streetman Date: Wed, 8 Jan 2020 12:32:19 +0000 (-0500) Subject: test-network: simplify wait_online() by calling wait_operstate() X-Git-Tag: v245-rc1~154^2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=0c020321c83e6f09834ae5be57a2a3c3acf1427a;p=thirdparty%2Fsystemd.git test-network: simplify wait_online() by calling wait_operstate() The wait_operstate() function now rechecks the condition for a timeout, so the wait_online() function can simply call it to check for the setup_state. --- diff --git a/test/test-network/systemd-networkd-tests.py b/test/test-network/systemd-networkd-tests.py index 7a796d479e1..f45e948b682 100755 --- a/test/test-network/systemd-networkd-tests.py +++ b/test/test-network/systemd-networkd-tests.py @@ -405,6 +405,25 @@ class Utilities(): return False def wait_online(self, links_with_operstate, timeout='20s', bool_any=False, setup_state='configured', setup_timeout=5): + """Wait for the link(s) to reach the specified operstate and/or setup state. + + This is similar to wait_operstate() but can be used for multiple links, + and it also calls systemd-networkd-wait-online to wait for the given operstate. + The operstate should be specified in the link name, like 'eth0:degraded'. + If just a link name is provided, wait-online's default operstate to wait for is degraded. + + The 'timeout' parameter controls the systemd-networkd-wait-online timeout, and the + 'setup_timeout' controls the per-link timeout waiting for the setup_state. + + Set 'bool_any' to True to wait for any (instead of all) of the given links. + If this is set, no setup_state checks are done. + + Note that this function waits for the link(s) to reach *or exceed* the given operstate. + However, the setup_state, if specified, must be matched *exactly*. + + This returns if the link(s) reached the requested operstate/setup_state; otherwise it + raises CalledProcessError or fails test assertion. + """ args = wait_online_cmd + [f'--timeout={timeout}'] + [f'--interface={link}' for link in links_with_operstate] if bool_any: args += ['--any'] @@ -416,22 +435,8 @@ class Utilities(): print(output) raise if not bool_any and setup_state: - # check at least once now, then once per sec for setup_timeout secs - for secs in range(setup_timeout + 1): - for link in links_with_operstate: - output = check_output(*networkctl_cmd, '-n', '0', 'status', link.split(':')[0]) - print(output) - if not re.search(rf'(?m)^\s*State:.*({setup_state}).*$', output): - # this link isn't in the right state; break into the sleep below - break - else: - # all the links were in the right state; break to exit the timer loop - break - # don't bother sleeping if time is up - if secs < setup_timeout: - time.sleep(1) - else: - self.fail(f'link {link} state does not match {setup_state}') + for link in links_with_operstate: + self.wait_operstate(link.split(':')[0], None, setup_state, setup_timeout) def wait_address(self, link, address_regex, scope='global', ipv='', timeout_sec=100): for i in range(timeout_sec):