]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
test: retry checking for transient hostname in hostnamectl (#4769)
authorMartin Pitt <martin.pitt@ubuntu.com>
Wed, 30 Nov 2016 07:02:49 +0000 (08:02 +0100)
committerGitHub <noreply@github.com>
Wed, 30 Nov 2016 07:02:49 +0000 (08:02 +0100)
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

index f8914a789576a47a42f7e89c7772e2884dae6910..3023cac97d7d9debfe76fd8ee9baa3ec2f7070a9 100755 (executable)
@@ -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: