Commit Graph

5748 Commits

Author SHA1 Message Date
Dan Bungert 87a9876ef7
Merge pull request #1453 from ogayot/LP#1992977
drivers: make overlay unmount error not fatal
2022-10-17 09:22:35 -06:00
Olivier Gayot 6954b309e6 drivers: do not consider overlay cleanup error fatal
For some reason that we have not yet determined, the overlay that we use
for the drivers code sometimes fails to unmount with EBUSY.

When it happens, the _list_drivers task would fail, making subsequent
GET calls to /drivers?wait=true fail as well and produce an error
report.

We now mark failures in the overlay unmount operation as non fatal.

Signed-off-by: Olivier Gayot <olivier.gayot@canonical.com>
2022-10-17 12:42:30 +02:00
Olivier Gayot aae52dd6ba apt: introduce OverlayCleanupError in overlay context manager
The apt.overlay construct unmounts the overlay at the end of the with
body. To do so, it leans on subprocess.run(["umount", ...], check=True).

If we want to catch the unmount error, we need to do:

  try:
      with apt.overlay():
          # do stuff
  except subprocess.CalledProcessError:
     # handle the unmount exception

However, we do not want the subprocess exceptions that happen in
the with body to be caught in the same except block.

If the umount call fails, we now wrap the exception in a
OverlayCleanupError ; therefore we can make the distinction between an
unmount error and a subprocess error that would happen in the body.

Signed-off-by: Olivier Gayot <olivier.gayot@canonical.com>
2022-10-17 12:31:31 +02:00
Dan Bungert 7387625e8d
Merge pull request #1452 from dbungert/lp-1992990-flash-kernel
curtin: rev for flash-kernel fix
2022-10-14 16:20:49 -06:00
Dan Bungert 1c59596913 curtin: rev for flash-kernel fix
LP: #1992990
2022-10-14 16:10:36 -06:00
Dan Bungert 36705829ff
Merge pull request #1450 from dbungert/guided-lvm-bad-offset
filesystem: ensure bootfs at aligned size
2022-10-12 08:42:52 -06:00
Dan Bungert 62ed92505a filesystem: ensure bootfs at aligned size
Certain disk sizes could trigger unaligned bootfs size.  This can result
in the next partition overlapping into the bootfs partition.

LP: #1992541
2022-10-11 20:45:57 -06:00
Dan Bungert c2e1daa35c
Merge pull request #1449 from dbungert/autoinstall-umount
apt: workaround umount failure
2022-10-11 18:54:13 -06:00
Dan Bungert 24c28a89c2 apt: workaround umount failure
When the apt overlay fails to umount, this directory removal will also
fail due to the mount still being present.

LP: #1992531
2022-10-11 17:07:26 -06:00
Michael Hudson-Doyle c1dd281040
Merge pull request #1444 from mwhudson/device-paths
track fs model objects device paths
2022-10-11 13:09:41 +13:00
Olivier Gayot f0e5c19ee7 loop: replace use of asyncio.get_event_loop
The behavior of asyncio.get_event_loop() will change in a future Python
version. It is deprecated starting Python 3.10.

The functions that we can use instead are:

 * asyncio.new_event_loop() - which creates a new event loop
 * asyncio.get_running_loop() - which returns the event loop only if it
   is already running

Signed-off-by: Olivier Gayot <olivier.gayot@canonical.com>
2022-10-07 18:45:11 +02:00
Olivier Gayot 1fbef3354c client: move aiohttp connector creation in coroutine
Creating a aiohttp connector when no event loop is running is not
considered safe. Under the hood, aiohttp invokes
asyncio.get_event_loop() which:

 1. currently creates a new event loop if one does not already exist
 2. will stop creating a new event loop in a future Python release
 3. is deprecated starting Python 3.10

We want to make sure Subiquity creates the event loop itself, so we now
create the aiohttp connector in a coroutine.

Signed-off-by: Olivier Gayot <olivier.gayot@canonical.com>
2022-10-07 18:36:39 +02:00
Olivier Gayot d27fec6480 filesystem: split logical and primary using more_itertools.partition
Signed-off-by: Olivier Gayot <olivier.gayot@canonical.com>
2022-10-07 09:57:32 +02:00
Olivier Gayot 01060fc14b filesystem: add complex use-case as a test for offsets and sizes
Signed-off-by: Olivier Gayot <olivier.gayot@canonical.com>
2022-10-06 16:08:01 +02:00
Olivier Gayot b831d7ccae filesystem: fix use of negative size in gaps calculations
When size: -1 is specified on a given partition, we attempt to determine
the its right size by looping through the partitions and computing a
list of available gaps.

That said, when looping through the partitions, we also include the one
which has an incomplete (i.e. = -1) size. This makes the computation
rely on a negative value and this often leads to incorrect result.

Fixed by excluding the current partition when determining its
appropriate size.

https://bugs.launchpad.net/ubuntu/+source/subiquity/+bug/1991929

Signed-off-by: Olivier Gayot <olivier.gayot@canonical.com>
2022-10-06 16:08:01 +02:00
Olivier Gayot 78ac4408d5 filesystem: guess missing offsets in autoinstall
When storage version 2 is used, partitions require an offset. When
loading partitions via an autoinstall file, we now make sure to assign
offsets automatically if the user did not specify offsets.

https://bugs.launchpad.net/ubuntu/+source/subiquity/+bug/1991413

Signed-off-by: Olivier Gayot <olivier.gayot@canonical.com>
2022-10-06 16:08:01 +02:00
Olivier Gayot 06f5e24904 filesystem: fix implem of available_for_partitions
The available_for_partitions function wrongly assumed that the
underlying disk had a GPT partition table. Updated the implementation to
use the alignment data as expected.

Signed-off-by: Olivier Gayot <olivier.gayot@canonical.com>
2022-10-06 15:52:39 +02:00
Olivier Gayot dd2553723f filesystem: mark ptable msdos in tests at the right place
In the new tests recently added to test_filesystem.py, the initial disk
object was marked having a msdos partition table.

This is fine for computing offsets manually. However, what really needs
to be done is to mark the partition table as msdos in the YAML itself.
Otherwise, the disk is reformatted as GPT.

This makes gap functions use the right alignment data when computing the
list of gaps available.

Sadly it breaks the tests because of other issues, so I added FIXME tags
in the broken tests.

Signed-off-by: Olivier Gayot <olivier.gayot@canonical.com>
2022-10-06 15:52:39 +02:00
Michael Hudson-Doyle c2c8460b50 remove with_context decorator from CurtinPartitioningStep.run
To avoid having nested contexts for one step. It's a bit unsatisfying
because conceptually the code in CurtinPartitioningStep.run should be
considered part of the same context but I don't see a good way to do
that and it's not of practical significance.
2022-10-06 14:01:27 +13:00
Michael Hudson-Doyle 631fbcad6a
Merge pull request #1443 from mwhudson/snapdapi-again
rich snapdapi again
2022-10-06 13:48:25 +13:00
Michael Hudson-Doyle 8b47359ef2 update filesystem model object paths after curtin runs 2022-10-05 16:52:10 +13:00
Michael Hudson-Doyle 8e658998ef add "path" attributes to fs model objects that curtin now provides a path for 2022-10-05 16:14:22 +13:00
Michael Hudson-Doyle 501054329f update curtin 2022-10-05 16:12:41 +13:00
Michael Hudson-Doyle b57139de9c the publisher is not returned by the API for a unasserted snap 2022-10-05 15:29:52 +13:00
Michael Hudson-Doyle faf78a1be1 Revert "Merge pull request #1442 from mwhudson/main"
This reverts commit cc33a668a2, reversing
changes made to f219cd717e.
2022-10-05 15:28:39 +13:00
Michael Hudson-Doyle f5dd2ec01f
Merge pull request #1431 from mwhudson/cleaner-cdrom-cleanup
remove special cases around mounting/unmounting /target/cdrom
2022-10-05 15:01:59 +13:00
Michael Hudson-Doyle cc33a668a2
Merge pull request #1442 from mwhudson/main
Revert "Merge pull request #1435 from mwhudson/snapdapi"
2022-10-05 14:47:58 +13:00
Michael Hudson-Doyle 1a68b4759c Revert "Merge pull request #1435 from mwhudson/snapdapi"
This reverts commit f219cd717e, reversing
changes made to 7fe070dec3.
2022-10-05 14:37:34 +13:00
Michael Hudson-Doyle f219cd717e
Merge pull request #1435 from mwhudson/snapdapi
create and use a more richly typed snapd api
2022-10-05 14:14:23 +13:00
Michael Hudson-Doyle 7fe070dec3
Merge pull request #1440 from mwhudson/small-serialization-tweaks
small serialization and api tweaks
2022-10-05 13:53:18 +13:00
Olivier Gayot 9232561393
Merge pull request #1433 from ogayot/LP1989977-extended-partition-no-size
filesystem: accept extended partition with size -1 in autoinstall
2022-10-04 10:39:50 +02:00
Olivier Gayot 73d9ecd1be filesystem: fix logical part. using gap outside extended
When defining a partition with size: -1, the partition should expand to
the size of the largest gap. To determine which gap to use, we call the
function largest_gap(partition.disk).

That being said, the gap returned is sometimes bigger than expected when
using a msdos partition table. This happens because we return the
largest gap without checking if it is inside or outside the extended
partition.

Fixed by making sure that:

* for a logical partition, we pick the largest gap within the extended
  partition
* for a primary partition, we pick the largest gap outside the extended
  partition (if any).

Signed-off-by: Olivier Gayot <olivier.gayot@canonical.com>
2022-10-04 09:39:12 +02:00
Olivier Gayot 45a00c0864 gaps: mark ptable as dos for tests with extended partitions
Signed-off-by: Olivier Gayot <olivier.gayot@canonical.com>
2022-10-04 09:39:12 +02:00
Olivier Gayot 721d6bae67 filesystem: accept extended partition with size -1 in autoinstall
Our documentation of autoinstall mentions that one can specify the size
of a partition as -1 to use the remaining space on the disk.

Because it only makes sense in practice to support this option for the
right-most partition of a given disk, specifying size: -1 is only
accepted when defining the last partition of the disk.

Having said that, when making an autoinstall configuration that includes
an extended partition, the user must define the logical partitions after
the extended partition.

For the following configuration:

|                                  disk                                |
+--------------+--------------+--------------+-------------------------|
| p1 (primary) | p2 (primary) | p3 (primary) | p4 (extended)           |
|              |              |              | p5 (logic) | p6 (logic) |

, the representation in Subiquity will be analogous to:

[
  Partition(p1, "primary"),
  Partition(p2, "primary"),
  Partition(p3, "primary"),
  Partition(p4, "extended"),
  Partition(p5, "logical"),
  Partition(p6, "logical"),
]

This means that specifying size: -1 on p4 gets rejected because it is
not the last partition defined.p6 is the last partition defined.

This is however a valid use-case because p5 and p6 are contained within
p4. So p4 should be able to use the remaining space and there is no
reason to reject this configuration

Fixed by ignoring logical partitions when checking if a size of -1 is
allowed on an extended partition.

Signed-off-by: Olivier Gayot <olivier.gayot@canonical.com>
2022-10-04 09:39:12 +02:00
Michael Hudson-Doyle 90bc1eab98 use rich snapd api in refresh code 2022-10-04 16:18:22 +13:00
Michael Hudson-Doyle 750db28f19 Add a way to talk to snapd using a richly typed API 2022-10-04 16:16:04 +13:00
Michael Hudson-Doyle 521e7026de tweak AsyncSnapd api slightly
also remove dry-run delay for requests to /v2/change/{id}
2022-10-04 16:15:19 +13:00
Michael Hudson-Doyle 97c276faca Support typing.Any as a seralization annotation 2022-10-04 16:01:06 +13:00
Michael Hudson-Doyle ff8bb0c8ba APIs that do not serialize query args can have rich payloads of course 2022-10-04 16:00:22 +13:00
Olivier Gayot d5182af065
Merge pull request #1421 from ogayot/kvm-test-cloud-config
kvm-test: allow to specify a cloud-init file not meant for autoinstall
2022-09-29 14:31:47 +02:00
Dan Bungert ea9732fcc0
Merge pull request #1438 from dbungert/revert-fs-id-uglification
Revert "filesystem: part ids are not part nums"
2022-09-28 15:25:44 -06:00
Dan Bungert 9fb1b32e1d
Merge pull request #1436 from dbungert/runtests-exit-message
runtests: ensure message shown at end
2022-09-28 15:18:54 -06:00
Dan Bungert bd79c1d0a7 Revert "filesystem: part ids are not part nums"
This reverts commit 5fcd6776c1.
2022-09-28 13:36:44 -06:00
Dan Bungert 2928ab88ce runtests: ensure message shown at end
The second `trap ... EXIT` registration meant that the first one, the
one repsonsible for providing a clear PASS / FAIL at the end, was not
being shown.
2022-09-28 10:02:04 -06:00
Carlos Nihelton a434bdd311
Merge pull request #1434 from EduardGomezEscandell/fix-wsl-snap-version-bug
Fix unset SNAP_VERSION in WSL
2022-09-27 09:46:23 -03:00
Edu Gómez Escandell b939b0e552 Fix 2022-09-27 14:13:36 +02:00
Olivier Gayot b59141304e
Merge pull request #1430 from ogayot/LP#1987341
reserved-usernames: add groups created by udev (src:systemd)
2022-09-27 14:05:45 +02:00
Olivier Gayot d4f76d1ce8
Merge pull request #1426 from ogayot/fix-snaplist
Make snaplist more robust to races and fix snap info prefetch
2022-09-22 15:18:31 +02:00
Olivier Gayot 15151675d6 snaplist: fix cancellation of loader preventing retry
The SingleInstanceTask does not allow us to control cancellation the way
we want. We now use a standard asyncio.Task to execute the coroutine
that fetches the list of snaps.

Signed-off-by: Olivier Gayot <olivier.gayot@canonical.com>
2022-09-22 15:02:18 +02:00
Olivier Gayot 507b025059 snaplist: make list snap task raise on error
The list snaps task used to return successfully even in case of error.

To make the distinction between and error and a successful fetch, we
used to rely on the task to set an attribute at the loader level:
 * failed = True; or
 * failed = False

The task was responsible for setting this attribute and there were
scenarios where it would not set the attribute properly. Usually, this
was when an exception was raised in the task.

We now raise an exception when an error occurs in the task ; instead of
returning. This is better because we can know if the task:
 * got cancelled - by calling "task.cancelled()"
 * finished successfully - by calling "task.done() and not
   task.exception()"
 * failed - by calling "task.done() and task.exception()"
 * has not finished - by calling "not task.done()"

This also allows us to detect errors and retry

Signed-off-by: Olivier Gayot <olivier.gayot@canonical.com>
2022-09-22 15:02:18 +02:00