Merge ~andersson123/lpci:devel-release-support into lpci:main

Proposed by Tim Andersson
Status: Work in progress
Proposed branch: ~andersson123/lpci:devel-release-support
Merge into: lpci:main
Diff against target: 158 lines (+79/-0)
4 files modified
lpci/commands/run.py (+74/-0)
lpci/providers/_lxd.py (+3/-0)
requirements.in (+1/-0)
setup.cfg (+1/-0)
Reviewer Review Type Date Requested Status
Launchpad code reviewers Pending
Review via email: mp+461564@code.launchpad.net
To post a comment you must log in.
925ef1c... by Tim Andersson

progress

Unmerged commits

925ef1c... by Tim Andersson

progress

Failed
[FAILED] test:0 (build)
[WAITING] build:0 (build)
12 of 2 results
f3faba9... by Tim Andersson

feat: add support for running lpci on the development release

Failed
[FAILED] test:0 (build)
[WAITING] build:0 (build)
12 of 2 results

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/lpci/commands/run.py b/lpci/commands/run.py
2index e42a8a9..c0ec942 100644
3--- a/lpci/commands/run.py
4+++ b/lpci/commands/run.py
5@@ -11,6 +11,7 @@ import subprocess
6 import tempfile
7 from argparse import ArgumentParser, Namespace
8 from pathlib import Path, PurePath
9+from distro_info import UbuntuDistroInfo
10 from tempfile import NamedTemporaryFile
11 from typing import Dict, List, Optional, Set
12
13@@ -425,6 +426,35 @@ def _install_apt_packages(
14 )
15
16
17+def _run_instance_command_silent(
18+ command: str,
19+ job_name: str,
20+ job: Job,
21+ instance: lxd.LXDInstance,
22+ host_architecture: str,
23+ remote_cwd: Path,
24+ environment: Optional[Dict[str, Optional[str]]],
25+ root: bool = True,
26+) -> None:
27+ full_run_cmd = ["bash", "--noprofile", "--norc", "-ec", command]
28+ emit.message(f"Running command for the job: {full_run_cmd}")
29+ with open("/dev/null", "w") as stream:
30+ proc = instance.execute_run(
31+ full_run_cmd,
32+ cwd=remote_cwd,
33+ env=environment,
34+ stdout=stream,
35+ stderr=stream,
36+ )
37+ if proc.returncode != 0:
38+ raise CommandError(
39+ f"Job {job_name!r} for "
40+ f"{job.series}/{host_architecture} failed with "
41+ f"exit status {proc.returncode}.",
42+ retcode=proc.returncode,
43+ )
44+
45+
46 def _run_instance_command(
47 command: str,
48 job_name: str,
49@@ -551,6 +581,7 @@ def _run_job(
50 gpu_nvidia=gpu_nvidia,
51 root=root,
52 ) as instance:
53+ # Has to go here?
54 snaps = list(itertools.chain(*pm.hook.lpci_install_snaps()))
55 for snap in snaps:
56 emit.progress(
57@@ -579,6 +610,46 @@ def _run_job(
58 environment=environment,
59 secrets=secrets,
60 )
61+ # try move it here
62+ if job.series == "devel":
63+ udi = UbuntuDistroInfo()
64+ supported = udi.supported()
65+ # only caveat is that distro-info-data must be up to date for this to work on
66+ # the machine hosting the container.
67+ devel = udi.devel()
68+ if devel in supported:
69+ supported.remove(devel)
70+ job.series = supported[-1]
71+ emit.message("Job series is 'devel', upgrading from latest release to development release.")
72+ # with provider.launched_environment(
73+ # project_name=cwd.name,
74+ # project_path=cwd,
75+ # series=job.series,
76+ # architecture=host_architecture,
77+ # gpu_nvidia=gpu_nvidia,
78+ # root=root,
79+ # ) as instance:
80+ upgrade_commands = [
81+ f"sed -i 's/{job.series}/{devel}/g' /etc/apt/sources.list",
82+ "sudo DEBIAN_FRONTEND=noninteractive apt update -y",
83+ "sudo DEBIAN_FRONTEND=noninteractive apt upgrade -y",
84+ "sudo DEBIAN_FRONTEND=noninteractive apt-get dist-upgrade -y",
85+ # "sudo DEBIAN_FRONTEND=noninteractive apt-get autoclean -y",
86+ # "sudo DEBIAN_FRONTEND=noninteractive apt-get autoremove -y",
87+ # neither of these two things cause the vm to shut off
88+ ]
89+ for cmd in upgrade_commands:
90+ _run_instance_command_silent(
91+ command=cmd,
92+ job_name=job_name,
93+ job=job,
94+ instance=instance,
95+ host_architecture=host_architecture,
96+ remote_cwd=remote_cwd,
97+ environment=environment,
98+ root=root,
99+ )
100+ # gets up to here then for some reason the instance stops?
101
102 if job.input is not None and output is not None:
103 _copy_input_paths(job.input, remote_cwd, instance, output)
104@@ -720,6 +791,9 @@ class RunCommand(BaseCommand):
105
106 provider = get_provider()
107 provider.ensure_provider_is_available()
108+ # Actually I think we can do the upgrade here?
109+ # Just after we've created the provider right?
110+ # if args.
111
112 secrets = {}
113 if args.secrets_file:
114diff --git a/lpci/providers/_lxd.py b/lpci/providers/_lxd.py
115index c673502..83c97bc 100644
116--- a/lpci/providers/_lxd.py
117+++ b/lpci/providers/_lxd.py
118@@ -285,6 +285,7 @@ class LXDProvider(Provider):
119 :param series: Distribution series name.
120 :param architecture: Targeted architecture name.
121 """
122+ # I guess this'd be somewhere I'd be looking at for looking at devel support
123 alias = SERIES_TO_BUILDD_IMAGE_ALIAS[series]
124 instance_name = self.get_instance_name(
125 project_name=project_name,
126@@ -347,6 +348,8 @@ class LXDProvider(Provider):
127 )
128 except (bases.BaseConfigurationError, lxd.LXDError) as error:
129 raise CommandError(str(error)) from error
130+
131+ # I think we want to upgrade here ?
132
133 managed_project_path = get_managed_environment_project_path()
134 try:
135diff --git a/requirements.in b/requirements.in
136index 7cdae3e..fdc1bd7 100644
137--- a/requirements.in
138+++ b/requirements.in
139@@ -2,6 +2,7 @@ craft-cli
140 craft-providers>=1.19.0 # 1.19.0 added support of bases.BuilddBaseAlias.MANTIC
141 launchpadlib[keyring]
142 pydantic
143+distro-info
144 PyYAML>=6.0.1 # 6.0.0 is not compatible with a current cython version
145 python-dotenv
146 pluggy
147diff --git a/setup.cfg b/setup.cfg
148index edde67e..35001e2 100644
149--- a/setup.cfg
150+++ b/setup.cfg
151@@ -30,6 +30,7 @@ install_requires =
152 launchpadlib[keyring]
153 lazr.restfulclient
154 pluggy
155+ distro-info
156 pydantic
157 python-dotenv
158 python_requires = >=3.8

Subscribers

People subscribed via source and target branches