← Back to team overview

launchpad-reviewers team mailing list archive

[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.

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~tushar5526/launchpad-buildd/+git/launchpad-buildd/+merge/476482
-- 
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..6c0f4f4 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,51 @@ class TestLXD(TestCase):
             "lp-xenial-amd64", "lp-xenial-amd64"
         )
 
+    def test_create_with_snap_seeding_timing_out(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())
+
+        cmd = ["snap", "wait", "system", "seed.loaded"]
+        timeout_seconds = 3
+
+        def mock_sudo(proc_args):
+            # raise timeoutExpired error for snap wait.. command
+            # and let other sudo commands pass through
+            if proc_args["args"][1:] == cmd:
+                raise subprocess.TimeoutExpired(cmd, timeout_seconds)
+            return {}
+
+        processes_fixture.add(mock_sudo, name="sudo")
+        processes_fixture.add(lambda _: {}, name="lxc")
+        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
+
+        e = self.assertRaises(
+            subprocess.TimeoutExpired,
+            LXD("1", "xenial", "amd64").create,
+            source_image_path,
+            "lxd",
+        )
+
+        self.assertEqual(
+            "Command '['snap', 'wait', 'system', 'seed.loaded']'"
+            "timed out after %d seconds" % timeout_seconds,
+            str(e),
+        )
+
+        self.assertThat(processes_fixture.procs, Equals([]))
+
     def assert_correct_profile(
         self,
         extra_raw_lxc_config=None,

Follow ups