Merge ~cpete/curtin:cdrom-info into curtin:master

Proposed by Chris Peterson
Status: Merged
Approved by: Chris Peterson
Approved revision: 5b35ba5326110607b7f8f0578e67722296435856
Merge reported by: Server Team CI bot
Merged at revision: not available
Proposed branch: ~cpete/curtin:cdrom-info
Merge into: curtin:master
Diff against target: 99 lines (+70/-0)
2 files modified
curtin/commands/curthooks.py (+34/-0)
tests/unittests/test_curthooks.py (+36/-0)
Reviewer Review Type Date Requested Status
Server Team CI bot continuous-integration Approve
Dan Bungert Approve
Review via email: mp+462092@code.launchpad.net

Commit message

curthooks: copy installation media metadata

Description of the change

Ubuntu ISOs contain metadata in the .disk/ directory, like the build date or sometimes an OEM Tracking ID, and we always want to copy this information over when we can. Subiquity currently always tries to write this information, and it's potentially useful for non-Subiquity installs, so let's move it here instead.

To post a comment you must log in.
Revision history for this message
Server Team CI bot (server-team-bot) wrote :

FAILED: Continuous integration, rev:528ebd94d94cfc0192ed57aebb50653a87bbf28d

No commit message was specified in the merge proposal. Click on the following link and set the commit message (if you want jenkins to rebuild you need to trigger it yourself):
https://code.launchpad.net/~cpete/curtin/+git/curtin/+merge/462092/+edit-commit-message

https://jenkins.canonical.com/server-team/job/curtin-ci/250/
Executed test runs:
    SUCCESS: https://jenkins.canonical.com/server-team/job/curtin-ci/nodes=metal-amd64/250/
    SUCCESS: https://jenkins.canonical.com/server-team/job/curtin-ci/nodes=metal-arm64/250/
    SUCCESS: https://jenkins.canonical.com/server-team/job/curtin-ci/nodes=metal-ppc64el/250/
    SUCCESS: https://jenkins.canonical.com/server-team/job/curtin-ci/nodes=metal-s390x/250/

Click here to trigger a rebuild:
https://jenkins.canonical.com/server-team/job/curtin-ci/250//rebuild

review: Needs Fixing (continuous-integration)
Revision history for this message
Dan Bungert (dbungert) wrote :

The commit message will need fixing. I often just copy a useful commit message from the commit stream.

If you have several commits and we don't want them squashed then I suggest adding "do not squash" like was done in https://code.launchpad.net/~curtin-dev/curtin/+git/curtin/+merge/461452

With a fix to the destination (see comments) and making the CI robot happy, this should be fine. Please also pull into a VM test to confirm.

review: Needs Fixing
Revision history for this message
Chris Peterson (cpete) :
Revision history for this message
Dan Bungert (dbungert) wrote :

LGTM

review: Approve
Revision history for this message
Server Team CI bot (server-team-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
Chris Peterson (cpete) wrote (last edit ):

Confirmed works in a VM. How do I tell the CI to retry? Edit: Nevermind, just slow I think.

Revision history for this message
Olivier Gayot (ogayot) wrote :

LGTM. Consider using pathlib next time :)

Revision history for this message
Olivier Gayot (ogayot) :
Revision history for this message
Chris Peterson (cpete) wrote :

@ogayot Thanks for the feedback!

> Consider using pathlib next time :)

Will do :)

Revision history for this message
Server Team CI bot (server-team-bot) wrote :
review: Approve (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/curtin/commands/curthooks.py b/curtin/commands/curthooks.py
2index 63a24fe..9eb8831 100644
3--- a/curtin/commands/curthooks.py
4+++ b/curtin/commands/curthooks.py
5@@ -920,6 +920,32 @@ def copy_crypttab(crypttab, target):
6 shutil.copy(crypttab, os.path.sep.join([target, 'etc/crypttab']))
7
8
9+def copy_cdrom(cdrom: str, target: str) -> None:
10+ """Copy installation media metadata"""
11+
12+ base: str = f"{cdrom}/.disk"
13+ ubuntu_dist_channel: str = f"{base}/ubuntu_dist_channel"
14+ media_info: str = f"{base}/info"
15+
16+ logdir: str = os.path.join(target, "var/log/installer")
17+ util.ensure_dir(logdir)
18+
19+ libdir: str = os.path.join(target, "var/lib")
20+ util.ensure_dir(libdir)
21+
22+ if os.path.exists(media_info):
23+ LOG.info("copying media-info into target")
24+ shutil.copy(media_info, f"{logdir}/media-info")
25+ else:
26+ LOG.warning(f"{media_info} not found, skipping")
27+
28+ if os.path.exists(ubuntu_dist_channel):
29+ LOG.info("copying ubuntu_dist_channel into target")
30+ shutil.copy(ubuntu_dist_channel, f"{libdir}/ubuntu_dist_channel")
31+ else:
32+ LOG.warning(f"{ubuntu_dist_channel} not found, skipping")
33+
34+
35 def copy_iscsi_conf(nodes_dir, target, target_nodes_dir='etc/iscsi/nodes'):
36 if not nodes_dir:
37 LOG.warn("nodes directory must be specified, not copying")
38@@ -2168,6 +2194,14 @@ def builtin_curthooks(cfg, target, state):
39 setup_grub(cfg, target, osfamily=osfamily,
40 variant=distro_info.variant)
41
42+ # Copy information from installation media
43+ with events.ReportEventStack(
44+ name=f"{stack_prefix}/copy-cdrom-metadata",
45+ reporting_enabled=True, level="INFO",
46+ description="copying metadata from /cdrom"):
47+ cdrom_loc: str = "/cdrom"
48+ copy_cdrom(cdrom_loc, target)
49+
50
51 def curthooks(args):
52 state = util.load_command_environment()
53diff --git a/tests/unittests/test_curthooks.py b/tests/unittests/test_curthooks.py
54index 61cad9f..4f65313 100644
55--- a/tests/unittests/test_curthooks.py
56+++ b/tests/unittests/test_curthooks.py
57@@ -1933,6 +1933,42 @@ class TestCurthooksChzdev(CiTestCase):
58 self.assertEqual(self.chzdev_import, output)
59
60
61+class TestCurthooksCopyCdrom(CiTestCase):
62+ with_logs = True
63+
64+ def setUp(self):
65+ super().setUp()
66+ self.host_dir = self.tmp_dir()
67+ self.target = f"{self.host_dir}/target"
68+ self.cdrom = f"{self.host_dir}/cdrom"
69+
70+ def test_pass_on_empty(self):
71+ curthooks.copy_cdrom(self.cdrom, self.target)
72+ logs = self.logs.getvalue()
73+ self.assertIn("/cdrom/.disk/info not found", logs)
74+ self.assertIn("/cdrom/.disk/ubuntu_dist_channel not found", logs)
75+
76+ def test_copy_on_exist(self):
77+ util.write_file(f"{self.cdrom}/.disk/info", "")
78+ util.write_file(f"{self.cdrom}/.disk/ubuntu_dist_channel", "")
79+
80+ curthooks.copy_cdrom(self.cdrom, self.target)
81+
82+ logs = self.logs.getvalue()
83+ self.assertNotIn("/cdrom/.disk/info not found", logs)
84+ self.assertNotIn("/cdrom/.disk/ubuntu_dist_channel not found", logs)
85+ self.assertTrue(
86+ os.path.exists(
87+ f"{self.target}/var/log/installer/media-info"
88+ )
89+ )
90+ self.assertTrue(
91+ os.path.exists(
92+ f"{self.target}/var/lib/ubuntu_dist_channel"
93+ )
94+ )
95+
96+
97 class TestCurthooksCopyZkey(CiTestCase):
98 def setUp(self):
99 super(TestCurthooksCopyZkey, self).setUp()

Subscribers

People subscribed via source and target branches