← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] ~cjwatson/lpcraft:fix-output-from-parent into lpcraft:main

 

Colin Watson has proposed merging ~cjwatson/lpcraft:fix-output-from-parent into lpcraft:main.

Commit message:
Ensure that parent of managed project path exists

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~cjwatson/lpcraft/+git/lpcraft/+merge/419661

https://code.launchpad.net/~cjwatson/lpcraft/+git/lpcraft/+merge/419463 broke lpcraft, because the project directory is now copied one level deeper to `/root/lpcraft/project` but nothing created `/root/lpcraft` first.
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of ~cjwatson/lpcraft:fix-output-from-parent into lpcraft:main.
diff --git a/lpcraft/providers/_lxd.py b/lpcraft/providers/_lxd.py
index aae538e..f0edf3c 100644
--- a/lpcraft/providers/_lxd.py
+++ b/lpcraft/providers/_lxd.py
@@ -286,6 +286,7 @@ class LXDProvider(Provider):
         except (bases.BaseConfigurationError, lxd.LXDError) as error:
             raise CommandError(str(error)) from error
 
+        managed_project_path = get_managed_environment_project_path()
         try:
             tmp_project_path = (
                 get_managed_environment_home_path() / "tmp-project"
@@ -295,11 +296,13 @@ class LXDProvider(Provider):
                 self._internal_execute_run(
                     instance,
                     instance_name,
-                    [
-                        "rm",
-                        "-rf",
-                        get_managed_environment_project_path().as_posix(),
-                    ],
+                    ["rm", "-rf", managed_project_path.as_posix()],
+                    check=True,
+                )
+                self._internal_execute_run(
+                    instance,
+                    instance_name,
+                    ["mkdir", "-p", managed_project_path.parent.as_posix()],
                     check=True,
                 )
                 self._internal_execute_run(
@@ -309,7 +312,7 @@ class LXDProvider(Provider):
                         "cp",
                         "-a",
                         tmp_project_path.as_posix(),
-                        get_managed_environment_project_path().as_posix(),
+                        managed_project_path.as_posix(),
                     ],
                     check=True,
                 )
@@ -324,11 +327,7 @@ class LXDProvider(Provider):
                 self._internal_execute_run(
                     instance,
                     instance_name,
-                    [
-                        "rm",
-                        "-rf",
-                        get_managed_environment_project_path().as_posix(),
-                    ],
+                    ["rm", "-rf", managed_project_path.as_posix()],
                     check=True,
                 )
                 instance.unmount_all()
diff --git a/lpcraft/providers/tests/test_lxd.py b/lpcraft/providers/tests/test_lxd.py
index 1a0afd4..0dffc88 100644
--- a/lpcraft/providers/tests/test_lxd.py
+++ b/lpcraft/providers/tests/test_lxd.py
@@ -417,6 +417,14 @@ class TestLXDProvider(TestCase):
                     ),
                     call().lxc.exec(
                         instance_name=expected_instance_name,
+                        command=["mkdir", "-p", "/root/lpcraft"],
+                        project="test-project",
+                        remote="test-remote",
+                        runner=subprocess.run,
+                        check=True,
+                    ),
+                    call().lxc.exec(
+                        instance_name=expected_instance_name,
                         command=[
                             "cp",
                             "-a",
@@ -526,6 +534,14 @@ class TestLXDProvider(TestCase):
                 ),
                 call().lxc.exec(
                     instance_name=expected_instance_name,
+                    command=["mkdir", "-p", "/root/lpcraft"],
+                    project="test-project",
+                    remote="test-remote",
+                    runner=subprocess.run,
+                    check=True,
+                ),
+                call().lxc.exec(
+                    instance_name=expected_instance_name,
                     command=[
                         "cp",
                         "-a",