Merge ~jugmac00/lpci:add-lpcraft-environment-configuration into lpci:main

Proposed by Jürgen Gmach
Status: Merged
Merge reported by: Jürgen Gmach
Merged at revision: 47262b8dbfd39403d4ccbc824f48eaff8cc6d745
Proposed branch: ~jugmac00/lpci:add-lpcraft-environment-configuration
Merge into: lpci:main
Diff against target: 166 lines (+75/-1)
4 files modified
lpcraft/commands/run.py (+1/-0)
lpcraft/commands/tests/test_run.py (+50/-1)
lpcraft/config.py (+1/-0)
lpcraft/tests/test_config.py (+23/-0)
Reviewer Review Type Date Requested Status
Colin Watson (community) Approve
Review via email: mp+412409@code.launchpad.net

Commit message

Jobs can now have an environment configuration

To post a comment you must log in.
Revision history for this message
Colin Watson (cjwatson) :
review: Approve
Revision history for this message
Jürgen Gmach (jugmac00) wrote :

Thanks for the review!

Revision history for this message
Colin Watson (cjwatson) :

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/lpcraft/commands/run.py b/lpcraft/commands/run.py
2index e5a5fcc..6975436 100644
3--- a/lpcraft/commands/run.py
4+++ b/lpcraft/commands/run.py
5@@ -96,6 +96,7 @@ def _run_pipeline(args: Namespace) -> None:
6 proc = instance.execute_run(
7 cmd,
8 cwd=env.get_managed_environment_project_path(),
9+ env=job.environment,
10 stdout=stream,
11 stderr=stream,
12 )
13diff --git a/lpcraft/commands/tests/test_run.py b/lpcraft/commands/tests/test_run.py
14index b31b75c..6dec643 100644
15--- a/lpcraft/commands/tests/test_run.py
16+++ b/lpcraft/commands/tests/test_run.py
17@@ -3,7 +3,7 @@
18
19 import os
20 import subprocess
21-from pathlib import Path
22+from pathlib import Path, PosixPath
23 from textwrap import dedent
24 from typing import Optional
25 from unittest.mock import ANY, Mock, call, patch
26@@ -362,6 +362,7 @@ class RunPipelineTestCase(CommandBaseTestCase):
27 call(
28 ["lpcraft", "run", "--series", "focal", "test"],
29 cwd=Path("/root/project"),
30+ env=None,
31 stdout=ANY,
32 stderr=ANY,
33 )
34@@ -416,6 +417,7 @@ class RunPipelineTestCase(CommandBaseTestCase):
35 execute_run.assert_called_once_with(
36 ["lpcraft", "run", "--series", "focal", "test"],
37 cwd=Path("/root/project"),
38+ env=None,
39 stdout=ANY,
40 stderr=ANY,
41 )
42@@ -457,12 +459,14 @@ class RunPipelineTestCase(CommandBaseTestCase):
43 call(
44 ["lpcraft", "run", "--series", "focal", "test"],
45 cwd=Path("/root/project"),
46+ env=None,
47 stdout=ANY,
48 stderr=ANY,
49 ),
50 call(
51 ["lpcraft", "run", "--series", "bionic", "build-wheel"],
52 cwd=Path("/root/project"),
53+ env=None,
54 stdout=ANY,
55 stderr=ANY,
56 ),
57@@ -510,21 +514,66 @@ class RunPipelineTestCase(CommandBaseTestCase):
58 call(
59 ["lpcraft", "run", "--series", "bionic", "test"],
60 cwd=Path("/root/project"),
61+ env=None,
62 stdout=ANY,
63 stderr=ANY,
64 ),
65 call(
66 ["lpcraft", "run", "--series", "focal", "test"],
67 cwd=Path("/root/project"),
68+ env=None,
69 stdout=ANY,
70 stderr=ANY,
71 ),
72 call(
73 ["lpcraft", "run", "--series", "bionic", "build-wheel"],
74 cwd=Path("/root/project"),
75+ env=None,
76 stdout=ANY,
77 stderr=ANY,
78 ),
79 ],
80 execute_run.call_args_list,
81 )
82+
83+ @patch("lpcraft.commands.run.get_provider")
84+ @patch("lpcraft.commands.run.get_host_architecture", return_value="amd64")
85+ def test_pass_in_environment_variables(
86+ self, mock_get_host_architecture, mock_get_provider
87+ ):
88+ launcher = Mock(spec=launch)
89+ provider = self.makeLXDProvider(lxd_launcher=launcher)
90+ mock_get_provider.return_value = provider
91+ execute_run = launcher.return_value.execute_run
92+ execute_run.return_value = subprocess.CompletedProcess([], 0)
93+ config = dedent(
94+ """
95+ pipeline:
96+ - test
97+
98+ jobs:
99+ test:
100+ series: focal
101+ architectures: amd64
102+ run: tox
103+ environment:
104+ TOX_SKIP_ENV: '^(?!lint-)'
105+ """
106+ )
107+ Path(".launchpad.yaml").write_text(config)
108+
109+ result = self.run_command("run")
110+ self.assertEqual(0, result.exit_code)
111+
112+ self.assertEqual(
113+ [
114+ call(
115+ ["lpcraft", "run", "--series", "focal", "test"],
116+ cwd=PosixPath("/root/project"),
117+ env={"TOX_SKIP_ENV": "^(?!lint-)"},
118+ stdout=ANY,
119+ stderr=ANY,
120+ )
121+ ],
122+ execute_run.call_args_list,
123+ )
124diff --git a/lpcraft/config.py b/lpcraft/config.py
125index 0a6d0af..e4011f3 100644
126--- a/lpcraft/config.py
127+++ b/lpcraft/config.py
128@@ -26,6 +26,7 @@ class Job(ModelConfigDefaults):
129 series: StrictStr
130 architectures: List[StrictStr]
131 run: Optional[StrictStr]
132+ environment: Optional[Dict[str, Optional[str]]]
133
134 @pydantic.validator("architectures", pre=True)
135 def validate_architectures(
136diff --git a/lpcraft/tests/test_config.py b/lpcraft/tests/test_config.py
137index 6fb98f9..16649ad 100644
138--- a/lpcraft/tests/test_config.py
139+++ b/lpcraft/tests/test_config.py
140@@ -127,3 +127,26 @@ class TestConfig(TestCase):
141 ),
142 ),
143 )
144+
145+ def test_load_environment(self):
146+ path = self.create_config(
147+ dedent(
148+ """
149+ pipeline:
150+ - test
151+
152+ jobs:
153+ test:
154+ series: focal
155+ architectures: amd64
156+ environment:
157+ ACTIVE: 1
158+ SKIP: 0
159+
160+ """
161+ )
162+ )
163+ config = Config.load(path)
164+ self.assertEqual(
165+ {"ACTIVE": "1", "SKIP": "0"}, config.jobs["test"][0].environment
166+ )

Subscribers

People subscribed via source and target branches