Merge ~jugmac00/lpci:always-update-repositories into lpci:main

Proposed by Jürgen Gmach
Status: Merged
Merged at revision: 8e8e77965ff8f29d306c3dbf3a91ea96d0526e3d
Proposed branch: ~jugmac00/lpci:always-update-repositories
Merge into: lpci:main
Diff against target: 173 lines (+63/-24)
4 files modified
NEWS.rst (+1/-1)
lpcraft/commands/run.py (+18/-18)
lpcraft/commands/tests/test_run.py (+23/-5)
lpcraft/plugin/tests/test_plugins.py (+21/-0)
Reviewer Review Type Date Requested Status
Colin Watson (community) Approve
Review via email: mp+422126@code.launchpad.net

Commit message

Always update apt cache index

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

Your failed test run is at https://launchpad.net/~jugmac00/lpcraft/+git/lpcraft/+build/381, with a coverage failure: looks like you will have to figure out how to test `apt update` vs. `apt install` failures before this can land. I've left a suggestion.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/NEWS.rst b/NEWS.rst
2index da24023..9e35a13 100644
3--- a/NEWS.rst
4+++ b/NEWS.rst
5@@ -5,7 +5,7 @@ Version history
6 0.0.13 (unreleased)
7 ===================
8
9-- Nothing yet.
10+- Always update apt cache index before installing a package.
11
12 0.0.12 (2022-05-12)
13 ===================
14diff --git a/lpcraft/commands/run.py b/lpcraft/commands/run.py
15index fc0c80c..106ac2f 100644
16--- a/lpcraft/commands/run.py
17+++ b/lpcraft/commands/run.py
18@@ -278,24 +278,24 @@ def _run_job(
19 group="root",
20 user="root",
21 )
22- # update local repository information
23- apt_update = ["apt", "update"]
24- with emit.open_stream(f"Running {apt_update}") as stream:
25- proc = instance.execute_run(
26- apt_update,
27- cwd=remote_cwd,
28- env=environment,
29- stdout=stream,
30- stderr=stream,
31- )
32- if proc.returncode != 0:
33- raise CommandError(
34- f"Job {job_name!r} for "
35- f"{job.series}/{host_architecture} failed with "
36- f"exit status {proc.returncode} "
37- f"while running `{shlex.join(apt_update)}`.",
38- retcode=proc.returncode,
39- )
40+ # update local repository information
41+ apt_update = ["apt", "update"]
42+ with emit.open_stream(f"Running {apt_update}") as stream:
43+ proc = instance.execute_run(
44+ apt_update,
45+ cwd=remote_cwd,
46+ env=environment,
47+ stdout=stream,
48+ stderr=stream,
49+ )
50+ if proc.returncode != 0:
51+ raise CommandError(
52+ f"Job {job_name!r} for "
53+ f"{job.series}/{host_architecture} failed with "
54+ f"exit status {proc.returncode} "
55+ f"while running `{shlex.join(apt_update)}`.",
56+ retcode=proc.returncode,
57+ )
58 packages_cmd = ["apt", "install", "-y"] + packages
59 emit.progress("Installing system packages")
60 with emit.open_stream(f"Running {packages_cmd}") as stream:
61diff --git a/lpcraft/commands/tests/test_run.py b/lpcraft/commands/tests/test_run.py
62index df96d69..165d435 100644
63--- a/lpcraft/commands/tests/test_run.py
64+++ b/lpcraft/commands/tests/test_run.py
65@@ -6,7 +6,7 @@ import json
66 import os
67 import re
68 import subprocess
69-from pathlib import Path
70+from pathlib import Path, PosixPath
71 from textwrap import dedent
72 from typing import Any, AnyStr, Dict, List, Optional
73 from unittest.mock import ANY, Mock, call, patch
74@@ -493,7 +493,11 @@ class TestRun(RunBaseTestCase):
75 provider = makeLXDProvider(lxd_launcher=launcher)
76 mock_get_provider.return_value = provider
77 execute_run = launcher.return_value.execute_run
78- execute_run.return_value = subprocess.CompletedProcess([], 100)
79+ # `apt update` should pass -> 0
80+ # `apt install` should fails -> 100
81+ execute_run.side_effect = iter(
82+ [subprocess.CompletedProcess([], ret) for ret in (0, 100)]
83+ )
84 config = dedent(
85 """
86 pipeline:
87@@ -521,7 +525,14 @@ class TestRun(RunBaseTestCase):
88 env={},
89 stdout=ANY,
90 stderr=ANY,
91- )
92+ ),
93+ call(
94+ ["apt", "install", "-y", "git"],
95+ cwd=PosixPath("/root/lpcraft/project"),
96+ env={},
97+ stdout=ANY,
98+ stderr=ANY,
99+ ),
100 ],
101 execute_run.call_args_list,
102 )
103@@ -1530,6 +1541,13 @@ class TestRun(RunBaseTestCase):
104 self.assertEqual(
105 [
106 call(
107+ ["apt", "update"],
108+ cwd=PosixPath("/root/lpcraft/project"),
109+ env={},
110+ stdout=ANY,
111+ stderr=ANY,
112+ ),
113+ call(
114 [
115 "apt",
116 "install",
117@@ -1584,8 +1602,8 @@ class TestRun(RunBaseTestCase):
118 self.assertEqual(
119 [
120 call(
121- ["apt", "install", "-y", "unknown_package"],
122- cwd=Path("/root/lpcraft/project"),
123+ ["apt", "update"],
124+ cwd=PosixPath("/root/lpcraft/project"),
125 env={},
126 stdout=ANY,
127 stderr=ANY,
128diff --git a/lpcraft/plugin/tests/test_plugins.py b/lpcraft/plugin/tests/test_plugins.py
129index dbdd2c2..cda49e4 100644
130--- a/lpcraft/plugin/tests/test_plugins.py
131+++ b/lpcraft/plugin/tests/test_plugins.py
132@@ -51,6 +51,13 @@ class TestPlugins(CommandBaseTestCase):
133 self.assertEqual(
134 [
135 call(
136+ ["apt", "update"],
137+ cwd=PosixPath("/root/lpcraft/project"),
138+ env={"TOX_TESTENV_PASSENV": "http_proxy https_proxy"},
139+ stdout=ANY,
140+ stderr=ANY,
141+ ),
142+ call(
143 [
144 "apt",
145 "install",
146@@ -143,6 +150,13 @@ class TestPlugins(CommandBaseTestCase):
147 self.assertEqual(
148 [
149 call(
150+ ["apt", "update"],
151+ cwd=PosixPath("/root/lpcraft/project"),
152+ env={"TOX_TESTENV_PASSENV": "http_proxy https_proxy"},
153+ stdout=ANY,
154+ stderr=ANY,
155+ ),
156+ call(
157 [
158 "apt",
159 "install",
160@@ -196,6 +210,13 @@ class TestPlugins(CommandBaseTestCase):
161 self.assertEqual(
162 [
163 call(
164+ ["apt", "update"],
165+ cwd=PosixPath("/root/lpcraft/project"),
166+ env={},
167+ stdout=ANY,
168+ stderr=ANY,
169+ ),
170+ call(
171 [
172 "apt",
173 "install",

Subscribers

People subscribed via source and target branches