Commit Graph

5748 Commits

Author SHA1 Message Date
Olivier Gayot 66c82b3227 drivers: query again list of drivers if the source variant changes
The list of drivers suggested to the user may vary based on whether we
are installing a server or desktop image / source.

In the current implementation of the drivers controller, the value of
the source variant (e.g., server or desktop) is read early in the
initializer.

This is a problem because it happens before the client gets the
opportunity to tell us if we are installing a server or a desktop image.

If the source variant ever changes, we want to query again the list of
drivers to suggest.

Upon configuring the source, the drivers controller will query (again)
the list of drivers.

Signed-off-by: Olivier Gayot <olivier.gayot@canonical.com>
2022-12-05 11:29:07 +01:00
Michael Hudson-Doyle dc0cd5a131 address review comments 2022-12-05 12:16:18 +13:00
Michael Hudson-Doyle 404856aaf6
Merge pull request #1503 from mwhudson/no-snaps-ssh-desktop
skip ssh and snaplist screens for desktop install
2022-12-02 11:40:57 +13:00
Olivier Gayot f2afda4e15 drivers: don't mark configured automatically, the client decides
The drivers controller used to mark the model configured automatically
if no drivers were found. This is okay in most cases but sometimes, we
want to query again the list of drivers (after the client_variant gets
set for instance) and we don't want the model to remain configured.

Let's leave this up to the client to decide if the model should be
configured.

Signed-off-by: Olivier Gayot <olivier.gayot@canonical.com>
2022-12-01 15:41:59 +01:00
Michael Hudson-Doyle f71de2e16d
Merge pull request #1504 from mwhudson/no-sshd
fix getting ssh info when sshd is not installed
2022-12-01 09:46:35 +13:00
Michael Hudson-Doyle 0db89dfc47
Merge pull request #1499 from mwhudson/fix-on_volumes
fix the value passed as on-volumes to snapd
2022-11-30 11:20:16 +13:00
Michael Hudson-Doyle 7c3e966356 fix getting ssh info when sshd is not installed 2022-11-30 11:12:51 +13:00
Michael Hudson-Doyle 9de44c95ec Support for autoinstalling a core boot classic system
This adds support for a 'hybrid' layout, which can only be used with a
core boot classic system (and no other style can be used).
2022-11-30 11:11:32 +13:00
Michael Hudson-Doyle a7af1cc5c2 fix the value passed as on-volumes to snapd
The data passed to on-volumes needs to indicate, for each "structure"
(partition) defined by the gadget the path to the underlying device. The
current code attempts to this by tracking the partition for each role
but this doesn't work: there maybe be more than one partition with no
role. So refactor to have the controller convert the "volume" structure
to an "on-volume" structure early and update the device fields after
curtin runs.
2022-11-30 11:11:07 +13:00
Michael Hudson-Doyle 71d18a7daa
Merge pull request #1496 from mwhudson/relax-alignment
do not round up partition size in add_partition
2022-11-30 11:04:54 +13:00
Michael Hudson-Doyle 36520a2d34 test and ensure that calculate_guided_resize returns aligned values 2022-11-30 10:55:52 +13:00
Michael Hudson-Doyle 44fca22175 maybe a good idea? 2022-11-30 10:55:51 +13:00
Michael Hudson-Doyle b61874a3f9 do not round up partition size in add_partition
I'm like 99% sure that all call paths to here align the size properly,
apart from the one in apply_system, which I want to be able to create
improperly sized partitions.
2022-11-30 10:54:53 +13:00
Michael Hudson-Doyle bf2e233c6c
Merge pull request #1500 from mwhudson/apply-system-fixes
a few fixes for apply_system
2022-11-30 09:50:34 +13:00
Michael Hudson-Doyle f33a42aed2 skip ssh and snaplist screens for desktop install
If and when the desktop installer adds a snaps screen, we should
probably fetch information for a different set of snaps for a desktop
install. But for now this is OK.
2022-11-30 09:37:57 +13:00
Michael Hudson-Doyle 2419522462 set grub_device on ESP in apply_system
Some other code expects this to be there.
2022-11-30 09:36:42 +13:00
Michael Hudson-Doyle 8fd499593f recreate the partition table if no partitions are being preserved
I think at the end of the day this is not very important. But it seems cleaner somehow.
2022-11-30 09:36:42 +13:00
Michael Hudson-Doyle 0b6a829a1e always set partition type guid from gadget
Previously it only set it if the particular type guid was known to
curtin.
2022-11-30 09:36:42 +13:00
Michael Hudson-Doyle a96903e4da fix removing more than one partition when applying gadget data 2022-11-30 09:36:42 +13:00
Michael Hudson-Doyle 6fdceba167
Merge pull request #1501 from mwhudson/tpm-fstab-swap
create fstab and configure swap for core boot classic
2022-11-30 09:32:56 +13:00
Michael Hudson-Doyle 50ff026cad
Merge pull request #1488 from mwhudson/system-seed-null
add a new member of the snapdapi.Role enum
2022-11-30 09:08:34 +13:00
Michael Hudson-Doyle 6bb8baee59
Merge pull request #1498 from mwhudson/better-logs
improve a few log messages and file paths
2022-11-30 06:36:55 +13:00
Dan Bungert 8ce87d9656
Merge pull request #1497 from mwhudson/curtin-update
update curtin to get swap, quick_zero, first-lba fixes
2022-11-29 10:28:30 -07:00
Olivier Gayot f875d59ed7
Merge pull request #1494 from ogayot/ubuntu-pro-test
MagicAttach: add ability to test in dry-run against the staging environment & demo web portal
2022-11-29 10:29:50 +01:00
Olivier Gayot 0b5c32a8e2
Merge pull request #1495 from ogayot/ubuntu-pro-fix
ubuntu-pro: cancel any contract selection before initiating a new one
2022-11-29 10:29:27 +01:00
Michael Hudson-Doyle fb4eb50999 apply default swap configuration for core boot classic 2022-11-29 16:12:07 +13:00
Michael Hudson-Doyle 05050d9788 create an fstab for a core boot classic system 2022-11-29 15:53:58 +13:00
Michael Hudson-Doyle 756fda0f91 stop having Role be an enum
I do not want getting an unexpected value here to crash subiquity.
2022-11-29 15:14:14 +13:00
Michael Hudson-Doyle b90419af41 improve a few log messages and file paths 2022-11-29 15:04:28 +13:00
Michael Hudson-Doyle b1d95a2982 update curtin to get swap, quick_zero, first-lba fixes 2022-11-29 14:55:39 +13:00
Olivier Gayot 0736885d46 ubuntu-pro: cancel any contract selection before initiating a new one
Upon reaching the Ubuntu Pro screen that shows the user-code, we need to
initiate a contract selection. If we are navigating to the screen a
second time though, we need to cancel existing contract selections
before initiating a new one.

Failing to do so results in a UPCSAlreadyInitiatedError.

Signed-off-by: Olivier Gayot <olivier.gayot@canonical.com>
2022-11-28 19:15:52 +01:00
Olivier Gayot fc056b0fbe ubuntu-pro: add ability to choose contracts env in dryrun mode
In dry-run mode, instead of reading the uacontracts environment URL from
/etc/ubuntu-advantage/uaclient.conf, we can now override this variable
by specifying the 'pro_ua_contracts_url' dry-run parameter.

In conjunction with 'pro_magic_attach_run_locally', this allows us to
test Subiquity against testing environments. By default it will use the
staging environment (i.e., https://contracts.staging.canonical.com).

Signed-off-by: Olivier Gayot <olivier.gayot@canonical.com>
2022-11-28 17:27:23 +01:00
Olivier Gayot d74a506f98 ubuntu-pro: add ability to run magic-attach locally in dry-run mode
In dry-run mode, the 'magic_attach_run_locally' variable can now be used
to execute uaclient on the host (against the uacontracts environment
specified in /etc/ubuntu-advantage/uaclient.conf) instead of relying on
a mock mechanism.

Signed-off-by: Olivier Gayot <olivier.gayot@canonical.com>
2022-11-28 17:27:23 +01:00
Olivier Gayot e887232ea1
Merge pull request #1493 from ogayot/fix-mount-snapd-systems
Fix crash when /var/lib/snapd/seed/systems does not exist on source
2022-11-28 10:52:45 +01:00
Michael Hudson-Doyle cba5313b47
Merge pull request #1492 from ogayot/test_api-x
test_api: remove execution bit from the test_api.py script
2022-11-28 09:33:20 +13:00
Olivier Gayot 217ac98fc6 filesystem: mount snapd/seed/systems only if it exists
The "$source"/var/lib/snapd/seed/systems directory only exists in certain
scenarios related to TPM-backed FDE. When the directory does not exist,
attempting to bind-mount it to /var/lib/snapd/seed/systems crashes the
install with a CalledProcessError.

We now make sure the directory exists before trying to mount it. For
dry-run test cases, we added a configuration item that simulates the
presence (or the non-presence) of the systems directory on the source.

Signed-off-by: Olivier Gayot <olivier.gayot@canonical.com>
2022-11-25 15:50:01 +01:00
Olivier Gayot 93f06eeb0f dry-run: add configuration object to control dry-run behavior
Oftentimes, we want to simulate a specific behavior of the application
when running in dry-run mode. To do so, we use either command line
parameters or environment variables.

This patch introduces a configuration object for dry-run executions
only. The object can be automatically loaded from a JSON file specified
via the --dry-run-config CLI argument.

Such a configuration object should help us cover way more test cases.
Going forward, I would like to use this object for things like:

 * drivers - to instruct Subiquity what third-party drivers it should
   suggest ; or if Subiquity should run ubuntu-drivers on the host
   instead.
 * ubuntu-pro - to specify the ua-contracts test environment URL - or
   predefined automatic replies for the server
 * to assume that /var/lib/snapd/seed/systems directory exists on the
   source (or not).
 * to specify the Ubuntu release that is returned by lsb_release ; can
   be used to test behavior on LTS vs non LTS releases.
 *
 * ...

Signed-off-by: Olivier Gayot <olivier.gayot@canonical.com>
2022-11-25 15:49:01 +01:00
Olivier Gayot 6d851e348c test_api: remove execution bit from the test_api.py script
The test_api.py is not meant to be used as en entry point. There is no
shebang so executing the script from a sh-compatible shell can be pretty
messy.

Signed-off-by: Olivier Gayot <olivier.gayot@canonical.com>
2022-11-25 13:02:36 +01:00
Olivier Gayot 9eea4cf220
Merge pull request #1490 from ogayot/fetch-keys-with-proxy
Fetch SSH keys through the configured proxy
2022-11-23 12:06:52 +01:00
Olivier Gayot 0f4376ccd3 ssh: split code to import SSH keys and add unit tests
Signed-off-by: Olivier Gayot <olivier.gayot@canonical.com>
2022-11-22 16:47:53 +01:00
Olivier Gayot 18f8735c49 ssh: call ssh-keygen once for each key to import
ssh-keygen -l supports an input file that has multiple keys. As a
result, it will output multiple key fingerprints.

That being said, ssh-keygen will ignore empty newlines from the input
(and maybe other things?).
It makes it slightly challenging to associate each key with its
fingerprint because the number of lines in the input and output can
differ, e.g.:

             input               |               output
  -----------------------------------------------------------------------
  ssh-rsa AA[...] user@host     ◀-▶ 256 SHA256:[...] user@host (RSA)
  <empty line>                   ┌▶ 3072 SHA256:[...] user@host (ED25519)
  ssh-ed25519 AA[...] user@host ◀┘

To simplify this process, we will do one call to ssh-keygen -l for each
key from the input.

Signed-off-by: Olivier Gayot <olivier.gayot@canonical.com>
2022-11-22 16:36:34 +01:00
Olivier Gayot aa4a674352 ssh: use specified proxy when importing SSH keys
When fetching SSH keys, the proxy settings specified by the user were
not used. This resulted in the inability to import keys in networks where
a HTTP proxy is mandatory.

We now explicitly set the https_proxy environment variable when calling
ssh-import-id if a proxy was configured by the user.

Signed-off-by: Olivier Gayot <olivier.gayot@canonical.com>
2022-11-22 16:36:09 +01:00
Olivier Gayot e107504748 ssh: fetch SSH keys on the server side and expose API for it
Instead of fetching SSH keys on the client side, we now make the client
consume an API and have the implementation on the server.

The main benefit is that it gives us more control over the environment
where the ssh-import-id command is executed.

This should allow us to set HTTP proxy environment variables (and
optionally locale-related variables such as LC_MESSAGES) according to
the user's selection.

Signed-off-by: Olivier Gayot <olivier.gayot@canonical.com>
2022-11-22 16:36:08 +01:00
Olivier Gayot 69c120e235 ssh: ignore empty lines when importing multiple SSH keys
ssh-import-id will include empty lines when multiple keys get imported.
These empty lines end up included in the array of authorized keys that
Subiquity manages and subsequently get passed to cloud-init and get
stored in autoinstall-user-data:

  authorized_keys = [
    'ssh-rsa AAAA[...] user@hostname',
    '',
    'ssh-ed255129 AAAA[...] user@hostname2',
  ]

Although cloud-init successfully ignores empty lines, it seems cleaner
to filter those out in Subiquity.

Signed-off-by: Olivier Gayot <olivier.gayot@canonical.com>
2022-11-22 09:55:04 +01:00
Olivier Gayot fd3a856bc4
Merge pull request #1489 from ogayot/inc-proc-output-in-except
utils: inc. captured stdout / stderr when forging CalledProcessError
2022-11-22 09:36:48 +01:00
Olivier Gayot fcebcac568 utils: inc. captured stdout / stderr when forging CalledProcessError
When executing a command via arun_command with check=True, we forge
and then raise a CalledProcessError exception if the command exits
abnormally (i.e., exit code != 0).

When doing so, we only instantiate the exception with the exit code and
the command executed. This means that we lose access to any output
captured so far. This is usually fine for stdout but stderr oftentimes
contains invaluable information to understand what caused the command to
exit abnormally.

Back in Python 3.5, stdout and stderr were introduced as new attributes
for CalledProcessError.
We now also include stdout and stderr in the CalledProcessError
instances that we forge. This allows us to access stderr (if any) when
catching the exception with:

  try:
      ...
  except CalledProcessError as exc:
      print(exc.stderr)

Signed-off-by: Olivier Gayot <olivier.gayot@canonical.com>
2022-11-21 15:11:09 +01:00
Michael Hudson-Doyle 83d1046128 add a new member of the snapdapi.Role enum
This kind of change is a bit of a problem with the current approach to
talking to snapd I guess -- deserialization will fail if we encounter a
new value for one of these fields.
2022-11-21 11:23:07 +13:00
Dan Bungert fa0aa32117
Merge pull request #1485 from mwhudson/tpm-reuse-part
reuse an existing partition if possible in apply_system
2022-11-17 10:00:45 -07:00
Dan Bungert 21713022e4
Merge pull request #1487 from ogayot/fix-tpm-race
Cherry-pick patch - fix answers race (maybe)
2022-11-17 09:09:00 -07:00
Michael Hudson-Doyle 9d3b6cc616 fix answers race (maybe) 2022-11-17 10:51:33 +01:00