← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] ~jugmac00/lpcraft:fix-config-path-regression into lpcraft:main

 

Jürgen Gmach has proposed merging ~jugmac00/lpcraft:fix-config-path-regression into lpcraft:main.

Commit message:
fix config path regression

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~jugmac00/lpcraft/+git/lpcraft/+merge/415138
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of ~jugmac00/lpcraft:fix-config-path-regression into lpcraft:main.
diff --git a/lpcraft/commands/run.py b/lpcraft/commands/run.py
index 8b24fbd..bb75bee 100644
--- a/lpcraft/commands/run.py
+++ b/lpcraft/commands/run.py
@@ -265,7 +265,10 @@ def _run_job(
 
 def run(args: Namespace) -> int:
     """Run a pipeline, launching managed environments as needed."""
-    config = Config.load(args.config)
+    # XXX jugmac00 2022-02-04: this fallback may become obsolete once we
+    # use craft-cli's command dispatcher
+    config_path = getattr(args, "config", Path(".launchpad.yaml"))
+    config = Config.load(config_path)
 
     provider = get_provider()
     provider.ensure_provider_is_available()
diff --git a/lpcraft/commands/tests/test_run.py b/lpcraft/commands/tests/test_run.py
index fe903e8..95c3cd6 100644
--- a/lpcraft/commands/tests/test_run.py
+++ b/lpcraft/commands/tests/test_run.py
@@ -396,6 +396,48 @@ class TestRun(RunBaseTestCase):
 
     @patch("lpcraft.commands.run.get_provider")
     @patch("lpcraft.commands.run.get_host_architecture", return_value="amd64")
+    def test_default_to_run_command(
+        self, mock_get_host_architecture, mock_get_provider
+    ):
+        # calling `lpcraft` with no arguments triggers the run command
+        # and is functionally equivalent to `lpcraft run`
+        launcher = Mock(spec=launch)
+        provider = self.makeLXDProvider(lxd_launcher=launcher)
+        mock_get_provider.return_value = provider
+        execute_run = launcher.return_value.execute_run
+        execute_run.return_value = subprocess.CompletedProcess([], 0)
+        config = dedent(
+            """
+            pipeline:
+                - test
+
+            jobs:
+                test:
+                    series: focal
+                    architectures: amd64
+                    run: tox
+            """
+        )
+        Path(".launchpad.yaml").write_text(config)
+
+        result = self.run_command()
+
+        self.assertEqual(0, result.exit_code)
+        self.assertEqual(
+            [
+                call(
+                    ["bash", "--noprofile", "--norc", "-ec", "tox"],
+                    cwd=Path("/root/project"),
+                    env={},
+                    stdout=ANY,
+                    stderr=ANY,
+                ),
+            ],
+            execute_run.call_args_list,
+        )
+
+    @patch("lpcraft.commands.run.get_provider")
+    @patch("lpcraft.commands.run.get_host_architecture", return_value="amd64")
     def test_parallel_jobs_some_fail(
         self, mock_get_host_architecture, mock_get_provider
     ):