From: Martin Pitt Date: Wed, 30 Nov 2016 07:02:49 +0000 (+0100) Subject: test: retry checking for transient hostname in hostnamectl (#4769) X-Git-Tag: v233~374 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=2926b130b69651539a90e866db43466b9b0ccfc5;p=thirdparty%2Fsystemd.git test: retry checking for transient hostname in hostnamectl (#4769) Sometimes setting the transient hostname does not happen synchronously, so retry up to five times. It is not yet clear whether this is legitimate behaviour or an underlying bug, but this will at least show whether the wrong transient hostname is just a race condition or permanently wrong. Fixes #4753 --- diff --git a/test/networkd-test.py b/test/networkd-test.py index f8914a78957..3023cac97d7 100755 --- a/test/networkd-test.py +++ b/test/networkd-test.py @@ -452,8 +452,17 @@ Domains= ~company ~lab''') # should have received the fixed IP above out = subprocess.check_output(['ip', '-4', 'a', 'show', 'dev', self.iface]) self.assertRegex(out, b'inet 192.168.5.210/24 .* scope global dynamic') - # should have set transient hostname in hostnamed - self.assertIn(b'testgreen', subprocess.check_output(['hostnamectl'])) + # should have set transient hostname in hostnamed; this is + # sometimes a bit lagging (issue #4753), so retry a few times + for retry in range(1, 6): + out = subprocess.check_output(['hostnamectl']) + if b'testgreen' in out: + break + time.sleep(5) + sys.stdout.write('[retry %i] ' % retry) + sys.stdout.flush() + else: + self.fail('Transient hostname not found in hostnamectl:\n%s' % out.decode()) # and also applied to the system self.assertEqual(socket.gethostname(), 'testgreen') except AssertionError: