Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow for specifying the autoinstall file over the kernel command line #1803

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 39 additions & 16 deletions doc/intro-to-autoinstall.rst
Original file line number Diff line number Diff line change
Expand Up @@ -78,24 +78,47 @@ Autoinstall on the install media
Another option for supplying autoinstall to the Ubuntu installer is to place a
file named :code:`autoinstall.yaml` on the install media itself.

There are two potential locations for the :code:`autoinstall.yaml` file:
* At the root of the "CD-ROM". When you write the installation ISO to a USB
Flash Drive, this can be done by copying the :code:`autoinstall.yaml` to the
partition containing the contents of the ISO - i.e.,
in the directory containing the ``casper`` sub-directory.
* On the rootfs of the installation system - this option will typically
require modifying the installation ISO and is not suggested, but is
supported.

Directly specifying autoinstall as a :code:`autoinstall.yaml` file does not
require a :code:`#cloud-config` header, and does not use a top level
``autoinstall:`` key. The autoinstall directives are placed at the top
level. For example:
There are two potential locations that subiquity will check for the
:code:`autoinstall.yaml` file:

.. code-block:: yaml
* At the root of the "CD-ROM". When you write the installation ISO to a USB
Flash Drive, this can be done by copying the :code:`autoinstall.yaml` to the
partition containing the contents of the ISO - i.e.,
in the directory containing the ``casper`` sub-directory.
* On the rootfs of the installation system - this option will typically
require modifying the installation ISO and is not suggested, but is
supported.

Alternatively, you can pass the location of the autoinstall file on the kernel
command line via the :code:`subiquity.autoinstallpath` parameter, where the
path is relative to the rootfs of the installation system. For example:

* :code:`subiquity.autoinstallpath=path/to/autoinstall.yaml`

.. note::

Directly specifying autoinstall as a :code:`autoinstall.yaml` file does not
require a :code:`#cloud-config` header, and does not use a top level
``autoinstall:`` key. The autoinstall directives are placed at the top
level. For example:

.. code-block:: yaml

version: 1
....


Order precedence of the autoinstall locations
======================================

Since there are many ways to specify the autoinstall file, it may happen that
multiple locations are specified at once. Subiquity will look for the
autoinstall file in the following order and pick the first existing one:

version: 1
....
1. Kernel command line
2. Root of the installation system
3. Cloud Config
4. Root of the CD-ROM (ISO)


Cloud-init and autoinstall interaction
Expand Down
14 changes: 9 additions & 5 deletions subiquity/server/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -574,10 +574,11 @@ async def wait_for_cloudinit(self):

def select_autoinstall(self):
# precedence
# 1. autoinstall at root of drive
# 2. command line argument autoinstall
# 3. autoinstall supplied by cloud config
# 4. autoinstall baked into the iso, found at /cdrom/autoinstall.yaml
# 1. command line argument autoinstall
Chris-Peterson444 marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for move CLI argument up the chain. It feels more natural.

# 2. kernel command line argument subiquity.autoinstallpath
# 3. autoinstall at root of drive
# 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
# autoinstall has been explicitly disabled.
Expand All @@ -588,9 +589,12 @@ def select_autoinstall(self):
):
raise Exception(f"Autoinstall argument {self.opts.autoinstall} not found")

kernel_install_path = self.kernel_cmdline.get("subiquity.autoinstallpath", None)

locations = (
self.base_relative(root_autoinstall_path),
self.opts.autoinstall,
kernel_install_path,
self.base_relative(root_autoinstall_path),
self.base_relative(cloud_autoinstall_path),
self.base_relative(iso_autoinstall_path),
)
Expand Down
38 changes: 28 additions & 10 deletions subiquity/server/tests/test_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,39 +54,57 @@ def create(self, path, contents):
return path

def test_autoinstall_disabled(self):
self.server.opts.autoinstall = ""
self.server.kernel_cmdline = {"subiquity.autoinstallpath": "kernel"}
self.create(root_autoinstall_path, "root")
self.create(cloud_autoinstall_path, "cloud")
self.create(iso_autoinstall_path, "iso")
self.server.opts.autoinstall = ""
self.assertIsNone(self.server.select_autoinstall())

def test_root_wins(self):
def test_arg_wins(self):
arg = self.create(self.path("arg.autoinstall.yaml"), "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")
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")
self.assert_contents(root, "arg")

def test_arg_wins(self):
root = self.path(root_autoinstall_path)
arg = self.create(self.path("arg.autoinstall.yaml"), "arg")
self.server.opts.autoinstall = 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, "arg")
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):
self.server.opts.autoinstall = None
self.server.kernel_cmdline = {}
root = self.path(root_autoinstall_path)
self.create(cloud_autoinstall_path, "cloud")
self.create(iso_autoinstall_path, "iso")
self.assertEqual(root, self.server.select_autoinstall())
self.assert_contents(root, "cloud")

def test_iso_wins(self):
self.server.opts.autoinstall = None
self.server.kernel_cmdline = {}
root = self.path(root_autoinstall_path)
# No cloud config file
self.create(iso_autoinstall_path, "iso")
self.assertEqual(root, self.server.select_autoinstall())
self.assert_contents(root, "iso")
Expand Down
Loading