← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] ~lgp171188/launchpad-buildd:fix-failing-test-sudo-apparmor-restart-mock-sudo into launchpad-buildd:master

 

Guruprasad has proposed merging ~lgp171188/launchpad-buildd:fix-failing-test-sudo-apparmor-restart-mock-sudo into launchpad-buildd:master.

Commit message:
Mock the 'sudo' command to restart apparmor

Unit tests shouldn't be able to run actual sudo


Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~lgp171188/launchpad-buildd/+git/launchpad-buildd/+merge/494940
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of ~lgp171188/launchpad-buildd:fix-failing-test-sudo-apparmor-restart-mock-sudo into launchpad-buildd:master.
diff --git a/lpbuildd/target/run_ci.py b/lpbuildd/target/run_ci.py
index 71074ff..79a7732 100644
--- a/lpbuildd/target/run_ci.py
+++ b/lpbuildd/target/run_ci.py
@@ -69,7 +69,6 @@ class RunCIPrepare(
         result = subprocess.run(
             ["sudo", "service", "apparmor", "restart"],
             capture_output=True,
-            text=True,
             check=True
         )
         logger.info("Command output: %s" % result.stdout)
diff --git a/lpbuildd/target/tests/test_run_ci.py b/lpbuildd/target/tests/test_run_ci.py
index 8ea5eef..0f4f34e 100644
--- a/lpbuildd/target/tests/test_run_ci.py
+++ b/lpbuildd/target/tests/test_run_ci.py
@@ -9,7 +9,7 @@ from textwrap import dedent
 
 import responses
 from fixtures import FakeLogger, TempDir
-from systemfixtures import FakeFilesystem
+from systemfixtures import FakeFilesystem, FakeProcesses
 from testtools import TestCase
 from testtools.matchers import AnyMatch, MatchesAll, MatchesListwise
 
@@ -66,6 +66,9 @@ class TestRunCIPrepare(TestCase):
 
     @responses.activate
     def test_install_snap_store_proxy(self):
+        processes_fixture = self.useFixture(FakeProcesses())
+        processes_fixture.add(lambda _: {}, name="sudo")
+
         store_assertion = dedent(
             """\
             type: store
@@ -253,6 +256,9 @@ class TestRunCIPrepare(TestCase):
         )
 
     def test_install_scan_malware_with_clamav_database_url(self):
+        processes_fixture = self.useFixture(FakeProcesses())
+        processes_fixture.add(lambda _: {}, name="sudo")
+
         args = [
             "run-ci-prepare",
             "--backend=fake",
@@ -516,6 +522,9 @@ class TestRunCIPrepare(TestCase):
             self.assertEqual({"revision_id": "0" * 40}, json.load(status))
 
     def test_run_succeeds(self):
+        processes_fixture = self.useFixture(FakeProcesses())
+        processes_fixture.add(lambda _: {}, name="sudo")
+
         args = [
             "run-ci-prepare",
             "--backend=fake",
@@ -566,6 +575,9 @@ class TestRunCIPrepare(TestCase):
         self.assertEqual(RETCODE_FAILURE_INSTALL, run_ci_prepare.run())
 
     def test_run_repo_fails(self):
+        processes_fixture = self.useFixture(FakeProcesses())
+        processes_fixture.add(lambda _: {}, name="sudo")
+
         class FailRepo(FakeMethod):
             def __call__(self, run_args, *args, **kwargs):
                 super().__call__(run_args, *args, **kwargs)