launchpad-reviewers team mailing list archive
-
launchpad-reviewers team
-
Mailing list archive
-
Message #31836
[Merge] ~tushar5526/launchpad-buildd:add-test-to-ensure-timeout-while-waiting-for-snaps-seeding into launchpad-buildd:master
Tushar Gupta has proposed merging ~tushar5526/launchpad-buildd:add-test-to-ensure-timeout-while-waiting-for-snaps-seeding into launchpad-buildd:master.
Commit message:
tests: Add tests to ensure there is a timeout while waiting for snaps to get seeded
Requested reviews:
Launchpad code reviewers (launchpad-reviewers)
For more details, see:
https://code.launchpad.net/~tushar5526/launchpad-buildd/+git/launchpad-buildd/+merge/476491
--
Your team Launchpad code reviewers is requested to review the proposed merge of ~tushar5526/launchpad-buildd:add-test-to-ensure-timeout-while-waiting-for-snaps-seeding into launchpad-buildd:master.
diff --git a/lpbuildd/target/tests/test_lxd.py b/lpbuildd/target/tests/test_lxd.py
index 82d01bd..ea654d2 100644
--- a/lpbuildd/target/tests/test_lxd.py
+++ b/lpbuildd/target/tests/test_lxd.py
@@ -7,6 +7,7 @@ import json
import os
import random
import stat
+import subprocess
import tarfile
import time
from contextlib import closing
@@ -299,6 +300,78 @@ class TestLXD(TestCase):
"lp-xenial-amd64", "lp-xenial-amd64"
)
+ def test_ensure_timeout_while_waiting_for_snap_seeding(self):
+ """
+ This test ensures that there should always be a timeout
+ while waiting for snaps seeding to complete during LXD builds
+ """
+ fs_fixture = self.useFixture(FakeFilesystem())
+ fs_fixture.add("/var/snap/lxd/common/lxd")
+
+ processes_fixture = self.useFixture(FakeProcesses())
+ processes_fixture.add(lambda _: {}, name="sudo")
+ processes_fixture.add(lambda _: {}, name="lxc")
+
+ cmd = ["sudo", "snap", "wait", "system", "seed.loaded"]
+
+ tmp = self.useFixture(TempDir()).path
+ source_image_path = os.path.join(tmp, "source.tar.gz")
+ self.make_lxd_image(source_image_path)
+ self.useFixture(MockPatch("pylxd.Client"))
+ client = pylxd.Client()
+ client.images.all.return_value = []
+ image = mock.MagicMock()
+ client.images.create.return_value = image
+
+ with mock.patch("platform.machine", return_value="riscv64"):
+ timeout = 180
+ with mock.patch("subprocess.check_call") as mock_check_call:
+ mock_check_call.side_effect = subprocess.TimeoutExpired(
+ cmd, timeout
+ )
+ e = self.assertRaises(
+ subprocess.TimeoutExpired,
+ LXD("1", "xenial", "amd64").create,
+ source_image_path,
+ "lxd",
+ )
+ mock_check_call.assert_called_once_with(cmd, timeout=timeout)
+
+ self.assertEqual(
+ "Command "
+ "'['sudo', 'snap', 'wait', 'system', 'seed.loaded']'"
+ " timed out after %d seconds" % timeout,
+ str(e),
+ )
+
+ self.assertThat(processes_fixture.procs, Equals([]))
+
+ with mock.patch(
+ "platform.machine", return_value="other-non-riscv64-archs"
+ ):
+ timeout = 40
+ with mock.patch("subprocess.check_call") as mock_check_call:
+ mock_check_call.side_effect = subprocess.TimeoutExpired(
+ cmd, timeout
+ )
+ e = self.assertRaises(
+ subprocess.TimeoutExpired,
+ LXD("1", "xenial", "amd64").create,
+ source_image_path,
+ "lxd",
+ )
+ mock_check_call.assert_called_once_with(cmd, timeout=timeout)
+
+ self.assertEqual(
+ "Command "
+ "'['sudo', 'snap', 'wait', 'system', "
+ "'seed.loaded']'"
+ " timed out after %d seconds" % timeout,
+ str(e),
+ )
+
+ self.assertThat(processes_fixture.procs, Equals([]))
+
def assert_correct_profile(
self,
extra_raw_lxc_config=None,