Merge maas-images:fix_packer_build into maas-images:master

Proposed by Alexsander de Souza
Status: Merged
Merged at revision: d71d0540c40543b24fef06952fd100196157ccb4
Proposed branch: maas-images:fix_packer_build
Merge into: maas-images:master
Diff against target: 222 lines (+26/-105)
4 files modified
.gitmodules (+1/-1)
conf/packer-maas.yaml (+10/-10)
meph2/commands/mimport.py (+14/-93)
packer-maas (+1/-1)
Reviewer Review Type Date Requested Status
Stamatis Katsaounis Approve
Review via email: mp+456460@code.launchpad.net

Commit message

fix packer-maas compatibility

To post a comment you must log in.
Revision history for this message
Stamatis Katsaounis (skatsaounis) wrote :

LGTM +1

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/.gitmodules b/.gitmodules
2index c376bef..4ed4e67 100644
3--- a/.gitmodules
4+++ b/.gitmodules
5@@ -1,4 +1,4 @@
6 [submodule "packer-maas"]
7 path = packer-maas
8 url = https://github.com/canonical/packer-maas.git
9- branch = master
10+ branch = main
11diff --git a/conf/packer-maas.yaml b/conf/packer-maas.yaml
12index ffa82ef..a9ee0e9 100644
13--- a/conf/packer-maas.yaml
14+++ b/conf/packer-maas.yaml
15@@ -1,13 +1,13 @@
16 packer-maas:
17- centos8:
18- os: centos
19- release: 8
20- version: 8
21- release_title: "CentOS 8"
22- support_eol: 2029-05-31
23- # The build system lp:maas-images runs on only has limited access
24- # to the Internet. Use this specific mirror during build.
25- yum_mirror: http://mirrors.edge.kernel.org/centos
26+ # centos8:
27+ # os: centos
28+ # release: 8
29+ # version: 8
30+ # release_title: "CentOS 8"
31+ # support_eol: 2021-12-31
32+ # # The build system lp:maas-images runs on only has limited access
33+ # # to the Internet. Use this specific mirror during build.
34+ # yum_mirror: http://mirrors.edge.kernel.org/centos
35 centos7:
36 os: centos
37 # images.maas.io always contained CentOS 7 with the latest point
38@@ -19,7 +19,7 @@ packer-maas:
39 support_eol: 2024-06-30
40 # The build system lp:maas-images runs on only has limited access
41 # to the Internet. Use this specific mirror during build.
42- yum_mirror: http://mirrors.edge.kernel.org/centos
43+ yum_mirror: http://mirrors.edge.kernel.org/centos/7
44 # Curtin added native support for CentOS in 18.1-59 which was
45 # released with MAAS 2.3. Since the stream may be used by older
46 # versions of MAAS add the hooks back in.
47diff --git a/meph2/commands/mimport.py b/meph2/commands/mimport.py
48index b2d4a94..f27b57b 100644
49--- a/meph2/commands/mimport.py
50+++ b/meph2/commands/mimport.py
51@@ -6,7 +6,6 @@ from copy import deepcopy
52 from datetime import datetime
53 import argparse
54 import hashlib
55-import json
56 import os
57 import re
58 import shutil
59@@ -210,6 +209,7 @@ def import_bootloaders(args, product_tree, cfgdata):
60 'items': items
61 }
62
63+
64 def import_release_notifications(args, product_tree, cfgdata):
65 product_id = cfgdata["product_id"]
66 release_notification = cfgdata['release-notification']
67@@ -217,7 +217,7 @@ def import_release_notifications(args, product_tree, cfgdata):
68 # Simple check to ensure the maas_version is a string. It is very easy to
69 # typo and write it as a float.
70 if (not isinstance(release_notification["maas_version"], str)
71- or not re.match('\d+\.\d+\.\d+', release_notification["maas_version"])):
72+ or not re.match(r'\d+\.\d+\.\d+', release_notification["maas_version"])):
73 raise ValueError(
74 "maas_version should be a string with the full SemVer version. for example: '2.9.1'")
75
76@@ -244,17 +244,14 @@ def import_release_notifications(args, product_tree, cfgdata):
77 else:
78 point += 1
79
80- notification_dir = os.path.abspath(os.path.join(
81- os.path.dirname(__file__), '..', '..', 'release-notifications'))
82-
83 version_dir = os.path.join(os.path.realpath(args.target), "release-notifications/{}/".format(version))
84 versioned_notification = os.path.join(version_dir, "release-notification.yaml")
85 os.makedirs(version_dir, exist_ok=True)
86
87 with open(versioned_notification, "w") as f:
88 f.write("This file is unused.")
89- with open(versioned_notification,"rb") as f:
90- hash = hashlib.sha256(f.read()).hexdigest();
91+ with open(versioned_notification, "rb") as f:
92+ hash = hashlib.sha256(f.read()).hexdigest()
93
94 path = "release-notifications/{}/release-notification.yaml".format(version)
95 item = {
96@@ -269,6 +266,7 @@ def import_release_notifications(args, product_tree, cfgdata):
97 "release_notification": item
98 }}
99
100+
101 def get_image_index_images(url):
102 """ Given a URL to an image-index config file return a dictionary of
103 filenames and SHA256 checksums keyed off the revision.
104@@ -413,84 +411,17 @@ def import_packer_maas(args, cfgdata):
105 if not os.path.exists(packer_dir):
106 sys.exit("Error: Unable to find packer directory %s" % name)
107
108- # Packer refuses to run if build artifacts are still around.
109- for build_artifact in [
110- 'output-qemu', "%s.tar.gz" % name, "%s.dd.gz" % name]:
111- build_artifact_path = os.path.join(packer_dir, build_artifact)
112- if os.path.isdir(build_artifact_path):
113- shutil.rmtree(build_artifact_path)
114- elif os.path.exists(build_artifact_path):
115- os.remove(build_artifact_path)
116+ env = deepcopy(os.environ)
117
118- packer_template = data.get('template', "%s.json" % name)
119+ # Packer refuses to run if build artifacts are still around.
120+ packer_cmd = ["make", "clean"]
121+ proc = subprocess.run(packer_cmd, cwd=packer_dir, env=env)
122+ if proc.returncode != 0:
123+ raise subprocess.CalledProcessError(
124+ cmd=' '.join(packer_cmd), returncode=proc.returncode)
125
126 if 'yum_mirror' in data:
127- # A yum mirrorlist allows yum to pick the fastest mirror from
128- # a set of servers given by a remote host. A yum baseurl is a
129- # specific mirror. If 'yum_mirror' is given replace any
130- # mirrorlists used in the kickstart file with baseurls. This
131- # is needed for the builder as it only allows external access
132- # to specific domains.
133- orig_kickstart_path = os.path.join(
134- packer_dir, 'http', "%s.ks" % name)
135- kickstart_path = os.path.join(
136- packer_dir, 'http', "%s-maas-images.ks" % name)
137- if os.path.exists(kickstart_path):
138- os.remove(kickstart_path)
139- mirrorlist_re = re.compile(
140- r'^.*(?P<mirrorlist>--mirrorlist=[\'"]?\S+[\'"]?)')
141- # For CentOS 6
142- url_re = re.compile(
143- r'^\w*url\s+--url=[\'"]?(?P<url>.+/centos)\S+')
144- with open(orig_kickstart_path, 'r') as orig_kickstart, open(kickstart_path, 'w') as kickstart:
145- for line in orig_kickstart:
146- mirrorlist_m = mirrorlist_re.search(line)
147- url_m = url_re.search(line)
148- if mirrorlist_m is not None:
149- mirrorlist = mirrorlist_m.group('mirrorlist')
150- mirrorlist_query = mirrorlist.split('/')[-1]
151- if '?' in mirrorlist_query:
152- mirrorlist_query = mirrorlist_query.split(
153- '?', 1)[1]
154- if mirrorlist_query.endswith(("'", '"')):
155- mirrorlist_query = mirrorlist_query[:-1]
156- repo = {'yum_mirror': data['yum_mirror']}
157- for q in mirrorlist_query.split('&'):
158- k, v = q.split('=', 2)
159- repo[k] = v
160- # url and repo lines define this differently...
161- if line.startswith('url'):
162- baseurl = '--url="'
163- else:
164- baseurl = '--baseurl="'
165- if 'release' not in repo:
166- repo['release'] = repo['repo']
167- baseurl += '{yum_mirror}/{release}/{repo}/{arch}'.format(
168- **repo)
169- if data['version'] >= 8:
170- baseurl += '/os'
171- baseurl += '"'
172- line = line.replace(mirrorlist, baseurl)
173- elif url_m is not None:
174- line = line.replace(
175- url_m.group('url'), data['yum_mirror'])
176- kickstart.write(line)
177-
178- # Modify the given template to use the modified kickstart file.
179- template_path = os.path.join(packer_dir, packer_template)
180- with open(template_path, 'r') as f:
181- template = json.load(f)
182- for builder in template['builders']:
183- for i, cmd in enumerate(builder['boot_command']):
184- if cmd.startswith("inst.ks"):
185- builder['boot_command'][i] = cmd.replace(
186- "%s.ks" % name, "%s-maas-images.ks" % name)
187- packer_template = "%s-mass-images.json" % name
188- template_path = os.path.join(packer_dir, packer_template)
189- if os.path.exists(template_path):
190- os.remove(template_path)
191- with open(template_path, 'w') as f:
192- json.dump(template, f, indent=4)
193+ env["KS_MIRROR"] = data["yum_mirror"]
194
195 # Add the given Curtin hooks when creating the tar from the
196 # disk image.
197@@ -502,17 +433,7 @@ def import_packer_maas(args, cfgdata):
198 else:
199 curtin_hooks = ''
200
201- # Packer must be run in the same directory as the template so the post
202- # processor can convert image into something usable by MAAS.
203- packer_path = os.environ.get('PACKER_PATH', 'packer')
204- packer_cmd = [packer_path, 'build']
205- # Set packer variables which are used to define the path to an ISO
206- # if required to build the image.
207- if 'packer_vars' in data:
208- for key, value in data['packer_vars'].items():
209- packer_cmd += ['-var', "%s=%s" % (key, value)]
210- packer_cmd += [packer_template]
211- env = deepcopy(os.environ)
212+ packer_cmd = ["make", "all"]
213 env['CURTIN_HOOKS'] = curtin_hooks
214 packer_manifest_path = os.path.join(packer_dir, "manifest")
215 env['MANIFEST'] = packer_manifest_path
216diff --git a/packer-maas b/packer-maas
217index db9c961..4659bc4 160000
218--- a/packer-maas
219+++ b/packer-maas
220@@ -1 +1 @@
221-Subproject commit db9c9614a2e6af284e69c4f9250b629c485c9b9d
222+Subproject commit 4659bc405a236cf77d532014b865cf4abe1c521e

Subscribers

People subscribed via source and target branches

to all changes: