From 2926b130b69651539a90e866db43466b9b0ccfc5 Mon Sep 17 00:00:00 2001 From: Martin Pitt Date: Wed, 30 Nov 2016 08:02:49 +0100 Subject: [PATCH] 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 --- test/networkd-test.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) 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: -- 2.47.3