autoinstall: allow for specifying autoinstall path on kernel command line

This commit is contained in:
Chris Peterson 2023-09-20 15:10:08 -07:00
parent aaaf87355c
commit 76b520afa9
2 changed files with 38 additions and 16 deletions

View File

@ -574,10 +574,11 @@ class SubiquityServer(Application):
def select_autoinstall(self): def select_autoinstall(self):
# precedence # precedence
# 1. autoinstall at root of drive # 1. command line argument autoinstall
# 2. command line argument autoinstall # 2. kernel command line argument subiquity.autoinstallpath
# 3. autoinstall supplied by cloud config # 3. autoinstall at root of drive
# 4. autoinstall baked into the iso, found at /cdrom/autoinstall.yaml # 4. autoinstall supplied by cloud config
# 5. autoinstall baked into the iso, found at /cdrom/autoinstall.yaml
# if opts.autoinstall is set and empty, that means # if opts.autoinstall is set and empty, that means
# autoinstall has been explicitly disabled. # autoinstall has been explicitly disabled.
@ -588,9 +589,12 @@ class SubiquityServer(Application):
): ):
raise Exception(f"Autoinstall argument {self.opts.autoinstall} not found") raise Exception(f"Autoinstall argument {self.opts.autoinstall} not found")
kernel_install_path = self.kernel_cmdline.get("subiquity.autoinstallpath", None)
locations = ( locations = (
self.base_relative(root_autoinstall_path),
self.opts.autoinstall, self.opts.autoinstall,
kernel_install_path,
self.base_relative(root_autoinstall_path),
self.base_relative(cloud_autoinstall_path), self.base_relative(cloud_autoinstall_path),
self.base_relative(iso_autoinstall_path), self.base_relative(iso_autoinstall_path),
) )

View File

@ -54,31 +54,46 @@ class TestAutoinstallLoad(SubiTestCase):
return path return path
def test_autoinstall_disabled(self): def test_autoinstall_disabled(self):
self.server.opts.autoinstall = ""
self.server.kernel_cmdline = {"subiquity.autoinstallpath": "kernel"}
self.create(root_autoinstall_path, "root") self.create(root_autoinstall_path, "root")
self.create(cloud_autoinstall_path, "cloud") self.create(cloud_autoinstall_path, "cloud")
self.create(iso_autoinstall_path, "iso") self.create(iso_autoinstall_path, "iso")
self.server.opts.autoinstall = ""
self.assertIsNone(self.server.select_autoinstall()) self.assertIsNone(self.server.select_autoinstall())
def test_root_wins(self):
root = self.create(root_autoinstall_path, "root")
autoinstall = self.create(self.path("arg.autoinstall.yaml"), "arg")
self.server.opts.autoinstall = autoinstall
self.create(cloud_autoinstall_path, "cloud")
self.create(iso_autoinstall_path, "iso")
self.assertEqual(root, self.server.select_autoinstall())
self.assert_contents(root, "root")
def test_arg_wins(self): def test_arg_wins(self):
root = self.path(root_autoinstall_path)
arg = self.create(self.path("arg.autoinstall.yaml"), "arg") arg = self.create(self.path("arg.autoinstall.yaml"), "arg")
self.server.opts.autoinstall = arg self.server.opts.autoinstall = arg
kernel = self.create(self.path("kernel.autoinstall.yaml"), "kernel")
self.server.kernel_cmdline = {"subiquity.autoinstallpath": kernel}
root = self.create(root_autoinstall_path, "root")
self.create(cloud_autoinstall_path, "cloud") self.create(cloud_autoinstall_path, "cloud")
self.create(iso_autoinstall_path, "iso") self.create(iso_autoinstall_path, "iso")
self.assertEqual(root, self.server.select_autoinstall()) self.assertEqual(root, self.server.select_autoinstall())
self.assert_contents(root, "arg") self.assert_contents(root, "arg")
def test_kernel_wins(self):
self.server.opts.autoinstall = None
kernel = self.create(self.path("kernel.autoinstall.yaml"), "kernel")
self.server.kernel_cmdline = {"subiquity.autoinstallpath": kernel}
root = self.create(root_autoinstall_path, "root")
self.create(cloud_autoinstall_path, "cloud")
self.create(iso_autoinstall_path, "iso")
self.assertEqual(root, self.server.select_autoinstall())
self.assert_contents(root, "kernel")
def test_root_wins(self):
self.server.opts.autoinstall = None
self.server.kernel_cmdline = {}
root = self.create(root_autoinstall_path, "root")
self.create(cloud_autoinstall_path, "cloud")
self.create(iso_autoinstall_path, "iso")
self.assertEqual(root, self.server.select_autoinstall())
self.assert_contents(root, "root")
def test_cloud_wins(self): def test_cloud_wins(self):
self.server.opts.autoinstall = None
self.server.kernel_cmdline = {}
root = self.path(root_autoinstall_path) root = self.path(root_autoinstall_path)
self.create(cloud_autoinstall_path, "cloud") self.create(cloud_autoinstall_path, "cloud")
self.create(iso_autoinstall_path, "iso") self.create(iso_autoinstall_path, "iso")
@ -86,7 +101,10 @@ class TestAutoinstallLoad(SubiTestCase):
self.assert_contents(root, "cloud") self.assert_contents(root, "cloud")
def test_iso_wins(self): def test_iso_wins(self):
self.server.opts.autoinstall = None
self.server.kernel_cmdline = {}
root = self.path(root_autoinstall_path) root = self.path(root_autoinstall_path)
# No cloud config file
self.create(iso_autoinstall_path, "iso") self.create(iso_autoinstall_path, "iso")
self.assertEqual(root, self.server.select_autoinstall()) self.assertEqual(root, self.server.select_autoinstall())
self.assert_contents(root, "iso") self.assert_contents(root, "iso")