curtin-dev team mailing list archive
-
curtin-dev team
-
Mailing list archive
-
Message #03425
[Merge] ~cpete/curtin:cdrom-info into curtin:master
Chris Peterson has proposed merging ~cpete/curtin:cdrom-info into curtin:master.
Requested reviews:
curtin developers (curtin-dev)
For more details, see:
https://code.launchpad.net/~cpete/curtin/+git/curtin/+merge/462092
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.
--
Your team curtin developers is requested to review the proposed merge of ~cpete/curtin:cdrom-info into curtin:master.
diff --git a/curtin/commands/curthooks.py b/curtin/commands/curthooks.py
index 63a24fe..98cb34b 100644
--- a/curtin/commands/curthooks.py
+++ b/curtin/commands/curthooks.py
@@ -920,6 +920,29 @@ def copy_crypttab(crypttab, target):
shutil.copy(crypttab, os.path.sep.join([target, 'etc/crypttab']))
+def copy_cdrom(cdrom: str, target: str) -> None:
+ """Copy installation media metadata"""
+
+ base: str = f"{cdrom}/.disk"
+ ubuntu_dist_channel: str = f"{base}/ubuntu_dist_channel"
+ media_info: str = f"{base}/info"
+
+ tdir: str = os.path.sep.join([target, "/var/log/installer"])
+ util.ensure_dir(tdir)
+
+ if os.path.exists(media_info):
+ LOG.info("copying media-info into target")
+ shutil.copy(media_info, f"{tdir}/media-info")
+ else:
+ LOG.warn(f"{media_info} not found, skipping")
+
+ if os.path.exists(ubuntu_dist_channel):
+ LOG.info("copying ubuntu_dist_channel into target")
+ shutil.copy(ubuntu_dist_channel, f"{tdir}/ubuntu_dist_channel")
+ else:
+ LOG.warn(f"{ubuntu_dist_channel} not found, skipping")
+
+
def copy_iscsi_conf(nodes_dir, target, target_nodes_dir='etc/iscsi/nodes'):
if not nodes_dir:
LOG.warn("nodes directory must be specified, not copying")
@@ -2168,6 +2191,14 @@ def builtin_curthooks(cfg, target, state):
setup_grub(cfg, target, osfamily=osfamily,
variant=distro_info.variant)
+ # Copy information from installation media
+ with events.ReportEventStack(
+ name=f"{stack_prefix}/copy-cdrom-metadata",
+ reporting_enabled=True, level="INFO",
+ description="copying metadata from /cdrom"):
+ cdrom_loc: str = "/cdrom"
+ copy_cdrom(cdrom_loc, target)
+
def curthooks(args):
state = util.load_command_environment()
diff --git a/tests/unittests/test_curthooks.py b/tests/unittests/test_curthooks.py
index 61cad9f..86a4667 100644
--- a/tests/unittests/test_curthooks.py
+++ b/tests/unittests/test_curthooks.py
@@ -1933,6 +1933,42 @@ class TestCurthooksChzdev(CiTestCase):
self.assertEqual(self.chzdev_import, output)
+class TestCurthooksCopyCdrom(CiTestCase):
+ with_logs = True
+
+ def setUp(self):
+ super().setUp()
+ self.host_dir = self.tmp_dir()
+ self.target = f"{self.host_dir}/target"
+ self.cdrom = f"{self.host_dir}/cdrom"
+
+ def test_pass_on_empty(self):
+ curthooks.copy_cdrom(self.cdrom, self.target)
+ logs = self.logs.getvalue()
+ self.assertIn("/cdrom/.disk/info not found", logs)
+ self.assertIn("/cdrom/.disk/ubuntu_dist_channel not found", logs)
+
+ def test_copy_on_exist(self):
+ util.write_file(f"{self.cdrom}/.disk/info", "")
+ util.write_file(f"{self.cdrom}/.disk/ubuntu_dist_channel", "")
+
+ curthooks.copy_cdrom(self.cdrom, self.target)
+
+ logs = self.logs.getvalue()
+ self.assertNotIn("/cdrom/.disk/info not found", logs)
+ self.assertNotIn("/cdrom/.disk/ubuntu_dist_channel not found", logs)
+ self.assertTrue(
+ os.path.exists(
+ f"{self.target}/var/log/installer/media-info"
+ )
+ )
+ self.assertTrue(
+ os.path.exists(
+ f"{self.target}/var/log/installer/ubuntu_dist_channel"
+ )
+ )
+
+
class TestCurthooksCopyZkey(CiTestCase):
def setUp(self):
super(TestCurthooksCopyZkey, self).setUp()
Follow ups
-
[Merge] ~cpete/curtin:cdrom-info into curtin:master
From: Server Team CI bot, 2024-03-13
-
[Merge] ~cpete/curtin:cdrom-info into curtin:master
From: Chris Peterson, 2024-03-13
-
Re: [Merge] ~cpete/curtin:cdrom-info into curtin:master
From: Server Team CI bot, 2024-03-13
-
Re: [Merge] ~cpete/curtin:cdrom-info into curtin:master
From: Chris Peterson, 2024-03-13
-
Re: [Merge] ~cpete/curtin:cdrom-info into curtin:master
From: Olivier Gayot, 2024-03-13
-
Re: [Merge] ~cpete/curtin:cdrom-info into curtin:master
From: Olivier Gayot, 2024-03-13
-
Re: [Merge] ~cpete/curtin:cdrom-info into curtin:master
From: Chris Peterson, 2024-03-12
-
Re: [Merge] ~cpete/curtin:cdrom-info into curtin:master
From: Server Team CI bot, 2024-03-12
-
Re: [Merge] ~cpete/curtin:cdrom-info into curtin:master
From: Dan Bungert, 2024-03-12
-
[Merge] ~cpete/curtin:cdrom-info into curtin:master
From: Chris Peterson, 2024-03-12
-
Re: [Merge] ~cpete/curtin:cdrom-info into curtin:master
From: Chris Peterson, 2024-03-12
-
Re: [Merge] ~cpete/curtin:cdrom-info into curtin:master
From: Dan Bungert, 2024-03-12
-
Re: [Merge] ~cpete/curtin:cdrom-info into curtin:master
From: Server Team CI bot, 2024-03-08