summaryrefslogtreecommitdiff
path: root/tests/unittests
diff options
context:
space:
mode:
authoraswinrajamannar <39812128+aswinrajamannar@users.noreply.github.com>2021-08-12 12:44:53 -0700
committerGitHub <noreply@github.com>2021-08-12 14:44:53 -0500
commite119ceceb7d76af7d75c04a8779b9c5fc68083a8 (patch)
tree25f04b412fc662e1940166a558fafa13bcae1113 /tests/unittests
parent7781dec3306e9467f216cfcb36b7e10a8b38547a (diff)
downloadvyos-cloud-init-e119ceceb7d76af7d75c04a8779b9c5fc68083a8.tar.gz
vyos-cloud-init-e119ceceb7d76af7d75c04a8779b9c5fc68083a8.zip
Azure: Check if interface is up after sleep when trying to bring it up (#972)
When bringing interface up by unbinding and then binding hv_netvsc driver, it might take a short delay after binding for the link to be up. So before trying unbind/bind again after sleep, check if the link is up. This is a corner case when a preprovisioned VM is reused and the NICs are hot-attached.
Diffstat (limited to 'tests/unittests')
-rw-r--r--tests/unittests/test_datasource/test_azure.py19
1 files changed, 19 insertions, 0 deletions
diff --git a/tests/unittests/test_datasource/test_azure.py b/tests/unittests/test_datasource/test_azure.py
index 63eaf384..03609c3d 100644
--- a/tests/unittests/test_datasource/test_azure.py
+++ b/tests/unittests/test_datasource/test_azure.py
@@ -2907,6 +2907,25 @@ class TestPreprovisioningHotAttachNics(CiTestCase):
dsa.wait_for_link_up("eth0")
self.assertEqual(1, m_is_link_up.call_count)
+ @mock.patch(MOCKPATH + 'net.is_up', autospec=True)
+ @mock.patch(MOCKPATH + 'util.write_file')
+ @mock.patch('cloudinit.net.read_sys_net')
+ @mock.patch('cloudinit.distros.networking.LinuxNetworking.try_set_link_up')
+ def test_wait_for_link_up_checks_link_after_sleep(
+ self, m_is_link_up, m_read_sys_net, m_writefile, m_is_up):
+ """Waiting for link to be up should return immediately if the link is
+ already up."""
+
+ distro_cls = distros.fetch('ubuntu')
+ distro = distro_cls('ubuntu', {}, self.paths)
+ dsa = dsaz.DataSourceAzure({}, distro=distro, paths=self.paths)
+ m_is_link_up.return_value = False
+ m_is_up.return_value = True
+
+ dsa.wait_for_link_up("eth0")
+ self.assertEqual(2, m_is_link_up.call_count)
+ self.assertEqual(1, m_is_up.call_count)
+
@mock.patch(MOCKPATH + 'util.write_file')
@mock.patch('cloudinit.net.read_sys_net')
@mock.patch('cloudinit.distros.networking.LinuxNetworking.try_set_link_up')