Commit Graph

997 Commits

Author SHA1 Message Date
Maciej Borzecki b4708b0a51 subiquitycore: helpers for probing for snap execution environment
Add helpers for probing if the process is executing inside a snap.

Signed-off-by: Maciej Borzecki <maciej.borzecki@canonical.com>
2024-02-06 16:02:08 +01:00
Chris Peterson 48e5f9c616
Merge pull request #1897 from Chris-Peterson444/autoinstall-exception-FR-6293
AutoinstallError exception
2024-02-05 16:19:15 -08:00
Chris Peterson 24de248cec AutoinstallError: Disable apport reporting
Autoinstall related failures are more likely than not going to be
user caused, so we shouldn't immediately generate a crash report
for these types of failures. This should hopefully allow the user
to debug their autoinstall data much faster and reduce the number
of autoinstall-related bugs reported.
2024-02-05 09:37:42 -08:00
Maciej Borzecki 5c266cc38c subiquitycore/log: use 'root' as group for strictly confined snaps
When setting up the logging in a strictly confined snap, use the 'root' group,
rather than 'adm'. This will not interfere with the sandbox's policy but also
does not result in providing wider access to the logs.

Signed-off-by: Maciej Borzecki <maciej.borzecki@canonical.com>
2024-02-05 16:18:03 +01:00
Chris Peterson e3a0f6d215
Merge pull request #1882 from Chris-Peterson444/link2doc-ai-user-data-FR-5802 2024-01-05 07:35:54 -08:00
Chris Peterson 5350d01715 ai: include link to docs in post-install user data
We write out the autoinstall data to make the install repeatable
but this should also include a reference to the autoinstall
documentation to increase usability.
2024-01-03 16:02:30 -08:00
Olivier Gayot 0b7a4d16af network: ensure we pass tasks to asyncio.wait
In Python < 3.11, when passing a coroutine to asyncio.wait, it would
automatically be scheduled as a task. This isn't the case anymore with
Python 3.11. Now passing coroutines to asyncio.wait fails with:

 TypeError: Passing coroutines is forbidden, use tasks explicitly.

Let's ensure we schedule the coroutines as tasks before passing them on
to asyncio.wait.

Signed-off-by: Olivier Gayot <olivier.gayot@canonical.com>
2023-12-08 14:27:00 +01:00
Robert Krátký 4e81b0d81d Unify UI screen titles and minor lang. fixes 2023-11-21 14:05:59 +01:00
Chris Peterson 6c27d656f2 tests: add shared mocks and remove bad import
This commit re-adds some of the shared mock fields for testing
and removes a bad import from test_snaplist. These are changes
that shouldn't have been part of the previously reverted patch:
0a70a969d4
2023-10-25 15:34:23 -07:00
Chris Peterson 0a70a969d4 Revert "autoinstall: Don't use snap env when invoking early and late commands"
This reverts commit 39f1ea9cb6. The fix proposed
in this patch caused more issues than it fixed. We will have to revisit this in
a more nuanced way in the future. In the meantime users can make use of env
directly to strip/modify the subcommand environment.
2023-10-25 15:13:26 -07:00
Dan Bungert 84bcd5f7c8 log: move /var/log/installer back to 0770 root:adm 2023-10-10 13:25:26 +01:00
Dan Bungert c9cfdafe0c log: create /var/log/installer root only 2023-10-05 18:03:32 -06:00
Dan Bungert 80b144f220 file_util: just make written files root only 2023-10-05 17:22:18 -06:00
Dan Bungert a2b63dae13 util: ensure log file is root owned 2023-10-04 14:06:09 -06:00
Dan Bungert 8ab052c200 util: set_log_perms tests 2023-10-03 19:02:16 -06:00
Dan Bungert 4a4e8ba886 util: explicit isdir arg from set_log_perms
target already exists, we should just inspect target and find if it is a
directory or not.
2023-10-03 18:56:07 -06:00
Dan Bungert ddc11d8687 util: more control on file writer mode and group 2023-10-03 17:09:05 -06:00
Dan Bungert ddc3345eb6 util: standardize on term 'mode' 2023-10-03 17:09:01 -06:00
Chris Peterson 39f1ea9cb6 autoinstall: Don't use snap env when invoking early and late commands 2023-10-03 10:09:26 -07:00
Olivier Gayot c9f3e252af
Merge pull request #1802 from ogayot/rich-mode-s390x
ui: have a distinct state file for rich mode over serial
2023-09-25 09:06:58 +02:00
Dan Bungert 5a573f2cef snapd api: wait longer
While these changes are not supposed to take nearly this long,
per LP: #2034715 we know that they are, and that some systems will
correctly perform the finish_install() step if just given more time.
2023-09-22 15:05:01 -06:00
Olivier Gayot c95261e0de ui: have a distinct state file for rich mode over serial
We recently made sure that after doing a snap refresh, the rich mode
(i.e., either rich or basic) is preserved. This was implemented by
storing the rich mode in a state file. When the client starts, it loads
the rich mode from said state file if it exists.

Unfortunately, on s390x, it causes installs to default to basic mode.
This happens because on this architecture, a subiquity install consists
of:

 * a first client (over serial) showing the SSH password
 * a second client (logging over SSH) actually going through the
   installation UI.

Since the first client uses a serial connection, the state file is
created with rich-mode set to basic. Upon connecting using SSH, the
state file is read and the rich-mode is set to basic as well.

Fixed by storing the rich-mode in two separate files, one for clients
over serial and one for other clients.

LP: #2036096

Signed-off-by: Olivier Gayot <olivier.gayot@canonical.com>
2023-09-22 09:27:13 +02:00
Dan Bungert d84c445612 network: fix import during snap build
Adding this import means a dependency on probert, which also means
anybody importing subiquity.common.types also has that requirement.

The make-kbd-info script imports types, and that steps was causing
snapcraft build failures due to not finding probert.
2023-09-11 09:45:28 -06:00
Olivier Gayot 16688c56c4
Merge pull request #1789 from ogayot/netdev-deleted
network: fix crash when Wi-Fi or eth interface gets removed from the system
2023-09-07 13:47:30 +02:00
Olivier Gayot e10343b7e5 network: fix crash when Wi-Fi or eth interface gets removed from the system
When a network interface is disconnected from the system (e.g.,
physically removed if it's a USB adapter), probert asynchronously calls
the del_link() method.

Upon receiving this notification, Subiquity server wants to send an
update to the Subiquity clients. The update contains information about
the interface that disappeared - which is obtained through a call to
netdev_info.

Unfortunately, for Wi-Fi and Ethernet interfaces, netdev_info
dereferences the NetworkDev.info variable. Interfaces that no longer
exist on the system (and also interfaces that do not yet exist), have
their "info" variable set to None - so an exception is raised when
dereferencing it.

Wi-Fi interface:

    File "subiquitycore/models/network.py", line 227, in netdev_info
      scan_state=self.info.wlan['scan_state'],
  AttributeError: 'NoneType' object has no attribute 'wlan'

Ethernet interface:

    File "subiquitycore/models/network.py", line 201, in netdev_info
      is_connected = bool(self.info.is_connected)
  AttributeError: 'NoneType' object has no attribute 'is_connected'

Fixed by making sure netdev_info does not raise if the dev.info variable
is None. This is a valid use-case.

Signed-off-by: Olivier Gayot <olivier.gayot@canonical.com>
2023-09-07 09:56:55 +02:00
Olivier Gayot 221466aa70 network: document and add type hint for NetworkDev.info
Signed-off-by: Olivier Gayot <olivier.gayot@canonical.com>
2023-09-06 14:59:51 +02:00
Dan Bungert c73fac697e utils: add gen_zsys_uuid
Add gen_zsys_uuid, to generate a uuid of the same form as used in the
ubiquity zsys-setup script.
2023-08-24 17:42:09 -06:00
Olivier Gayot cda6c54b87 filesystem: store the actual size in bytes alongside the human readable size
Currently, the partition form stores the size as a human readable value.
(e.g., 123456K, 1.1G, 1.876G, 100G). When we exit the size field (i.e., upon
losing focus), we convert the value to a number of bytes and then align
it up to the nearest MiB (or whatever the alignment requirement is).

Unfortunately, after computing the aligned value, we turn it back into a
human-readable string and store it as is. It is not okay because the
conversion does not ensure that the alignment requirement is still
honored.

For instance, if the user types in 1.1G, we do the following:

 * convert it to a number of bytes -> 1181116006.4 (surprise, it is not
   even an integer).

 * round it up to the nearest MiB -> 1181745152 (this is the correct
   value)

 * transform it into a human readable string and store it as is -> 1.1G
   - which actually corresponds to the original value.

This leads to an exception later when creating the partition:

    File "subiquity/models/filesystem.py", line 1841, in add_partition
      raise Exception(
   Exception: ('size %s or offset %s not aligned to %s', 1181116006, 1048576, 1048576)

Fixed by storing the actual size as a number of bytes - alongside the
human readable size.

Signed-off-by: Olivier Gayot <olivier.gayot@canonical.com>
2023-08-09 16:50:03 +02:00
Michael Hudson-Doyle a4c924f1f9 persist rich mode across updates 2023-08-08 14:16:36 +12:00
Michael Hudson-Doyle ce9a130f37 make initial setup of rich mode less confusing 2023-08-08 14:07:10 +12:00
Michael Hudson-Doyle 0395b6e9b0 add support for 'dd' image sources
I think only a core dd image source will work for now. Probably.
2023-08-03 09:07:06 +12:00
Dan Bungert c08fdab2f8 one-off format of long lines with black 2023-07-25 15:27:49 -06:00
Dan Bungert 34d40643ad format with black + isort 2023-07-25 15:27:42 -06:00
Michael Hudson-Doyle 6b35e5e4a1 tidy up examples/ directory
Move machine configs, sources, autoinstall files and dry-run configs
into their own subdirectories.
2023-07-11 12:49:22 +12:00
Olivier Gayot a270019387 prober: turn on parallelism for probert storage
Signed-off-by: Olivier Gayot <olivier.gayot@canonical.com>
2023-04-27 11:09:23 +02:00
Olivier Gayot 60f2b506db prober: move to asyncio for probert storage
Signed-off-by: Olivier Gayot <olivier.gayot@canonical.com>
2023-04-25 15:12:19 +02:00
Dan Bungert 7c5a7f4289 utils: stdout/stderr logger 2023-04-11 13:53:20 -06:00
Dan Bungert 15518fafd0 utils: matching_dicts handle key=None, typing
Co-authored-by: Olivier Gayot <olivier.gayot@canonical.com>
2023-04-03 12:36:40 -06:00
Dan Bungert 6e15c46135 util: add matching_dicts
Move some of this logic to a common util, so it can be used in
unittests.  The curtin version is close but expects to work on a storage
config, which is not a flat list.
2023-04-03 11:41:47 -06:00
Dan Bungert 1d9ad848fe utils: orig_environ cleans LD_LIBRARY_PATH
LD_LIBRARY_PATH is set earlier than some of the other environment
variables like PATH or PYTHONPATH, so trying to save a clean version in
snapcraft is not viable.  Remove it here.
2023-03-30 16:34:12 -06:00
Dan Bungert 2bfff57f41 network: run `netplan apply` without snap env
netplan isn't staged in the snap, and the environment variables being
passed around don't help it.
2023-03-29 13:23:57 -06:00
Michael Hudson-Doyle c0438b44ca fix "make lint" when run with the new pycodestyle/flake8 2023-03-23 16:38:35 +13:00
Olivier Gayot 5680c6f2ec
Merge pull request #1597 from ogayot/core22-userbase
snapcraft: upgrade to core22
2023-03-17 09:15:23 +01:00
Dan Bungert c6530c16b3 api: delay most endpoints until controllers start
In LP: 2009797, an exception of this form happens:
AttributeError: 'FilesystemController' object has no attribute '_start_task'

The installer client, u-d-i, is asking for storage information ASAP
after the socket starts listening, and in this case that happened before
all controllers were started.  The sync primitive the probe is waiting
on wasn't created yet.

With one known exception, /meta/status, we really shouldn't be
responding to random API calls, and the startup sequence of the
controllers should be relatively quick (sub 1 second to be sure).
Just delay them, except for the special one.
2023-03-16 12:53:55 -06:00
Olivier Gayot 9b18f45700 snapcraft: upgrade to core22
Signed-off-by: Olivier Gayot <olivier.gayot@canonical.com>
2023-03-16 12:21:44 +01:00
Dan Bungert 98a2ff8647 async_helpers: simplify task done check
Another version of the task-created-yet problem is the non-blocking
check to see if it is done or not.  Add a wrapper here to simplify
calling code.
2023-03-13 15:50:33 -06:00
Dan Bungert 075b06ce70 async_helpers: make SingleInstanceTask.wait safer
SingleInstanceTask has distinct steps for creation of the object, and
starting the task.  If a different coroutine is waiting on the
SingleInstanceTask, it isn't safe to directly call
SingleInstanceTask.wait() as the task may or may not have been created
yet.

Existing code usage of SingleInstanceTask is in 4 categories, with
reguards to SingleInstanceTask.wait():
1) using SingleInstanceTask without using SingleInstanceTask.wait().
   This is unchanged.
2) using SingleInstanceTask.wait without a check on task is not None.
   This may be safe now, but is fragile in the face of innocent-looking
   refactors around the SingleInstanceTask.
3) using SingleInstanceTask.wait after confirming that the task is not
   None.  This is fine but a leaky abstraction.
4) directly waiting on the SingleInstanceTask.task.  Another leaky
   abstraction, but it's solving a cancellation problem.  Leaving this
   alone.

By enhancing SingleInstanceTask.wait(), cases 2 and 3 are improved.  The
code not checking the task today is made safer, and the code checking
the task today can be simplified.
2023-03-13 15:50:33 -06:00
Dan Bungert 69bb8307eb network: do not accept route metric > 20000
Network manager can create routes at metric aka priority above 20000.
These can stick around if they are not the best choice, or they may
disappear quickly.

Do not consider one of these routes as a valid default route for
has_network purposes.
2023-02-21 13:30:05 -07:00
Dan Bungert e095d5040f network: use pyroute2 to manage default routes
The existing event based method of watching for has_network has a flaw.

The incoming route_change events from probert do not distinguish routes
on the same interface but a different metric, so if 2 routes on one
interface appear, we only get one event.  Then if one of those routes is
removed, we will inappropriately remove this route from the
default_routes list.

Aside from the code watching the event stream, the set of default routes
is an elaborate boolean value.

Simplify the code by passing around a boolean, and when we get a
route_change event, use that to go looking again at the list of default
routes.

LP: #2004659
2023-02-21 13:30:05 -07:00
Dan Bungert 8d9ad23ca6
Merge pull request #1566 from dbungert/lp-2007554-async-parameterized
tests: patch parameterized to handle async
2023-02-18 18:48:06 -07:00