Commit Graph

972 Commits

Author SHA1 Message Date
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
Dan Bungert f9ce25f15f tests: patch parameterized to handle async
parameterized async tests run into cpython bug gh-101486

We use parameterized.expand, which works by creating new functions and
inserting those into the list of tests.  It's a wonder this worked at
all before for the async tests.

Update the function generation to create a coroutine function, if
appropriate.

LP: #2007554
2023-02-16 19:17:37 -07:00
Olivier Gayot 4247846270 network: add override mechanism to force offline install
Signed-off-by: Olivier Gayot <olivier.gayot@canonical.com>
2023-02-15 09:05:14 +01:00
Dan Bungert 9d12871f15 many: s/create_task/run_bg_task/
create_task has the following note:
  Important: Save a reference to the result of this function, to avoid a
  task disappearing mid-execution.

Convert existing usage of create_task to run_bg_task, if that
create_task is not actually storing the result.
2023-02-13 14:56:07 -07:00
J-P Nurmi 10833a848f network: reset SNAP when calling netplan in dry-run mode 2023-02-08 17:49:57 +01:00
Olivier Gayot f284d25757 utils: add parameter to avoid clearing the LC_* variables
We used to set LC_ALL=C unconditionally when executing a command. This
is a problem if we want the output of a specific command to be
translated (provided a locale definition and an actual translation exist
for the requested language).

This patch adds the clean_locale parameter, which can be used to specify
if we want the locale variable to be cleaned, to most of the helpers
that execute commands.

The value defaults to True so the default behavior is preserved.
If one wants a command to be translated, they have to  explicitly pass
clean_locale=False.

Signed-off-by: Olivier Gayot <olivier.gayot@canonical.com>
2023-02-07 18:18:16 +01:00
Olivier Gayot b0ced5afb0 async: add helper to run fire-and-forget tasks
calling asyncio.create_task(...) without storing a reference to the
result can lead to the task being garbage collected before it actually
executed.

https://docs.python.org/3/library/asyncio-task.html#asyncio.create_task

The documentation gives an example of a reliable way to run
fire-and-forget background tasks.

This patch adds an helper to do exactly that.

Signed-off-by: Olivier Gayot <olivier.gayot@canonical.com>
2023-01-24 12:50:23 +01:00
Olivier Gayot 69264ad7f2
Merge pull request #1525 from ogayot/confirmation-overlay
Add helper to create confirmation dialog and use it for Ubuntu Pro
2023-01-05 10:50:54 +01:00
Olivier Gayot 51b6772175 ui: add a helper to open a confirmation dialog and get the response
The new ConfirmationOverlay object along with the
BaseView.ask_confirmation helper can be used to open a confirmation
dialog and get back the decision from the user.

Signed-off-by: Olivier Gayot <olivier.gayot@canonical.com>
2023-01-05 09:54:51 +01:00
Olivier Gayot 108b26d76d utils: fix unused stdin parameter in astart_command
Specifying the value of subprocess.PIPE as the stdin argument of
astart_command did not have any effect. This happened because the
parameter was not forwarded to the subprocess function. The parameter
was effectively unused.

Signed-off-by: Olivier Gayot <olivier.gayot@canonical.com>
2023-01-03 19:00:16 +01:00
Olivier Gayot e47f667e15
Merge pull request #1324 from ogayot/remove_overlay_no_overlay_ok
ui: avoid crashing when removing overlay that does not exist
2022-12-12 09:09:19 +01:00
Michael Hudson-Doyle 50ac03eacb Remove Application.aio_loop attribute 2022-12-08 12:52:14 +13:00
Olivier Gayot 163e6cfb4a ui: make not_found_ok false by default for overlays and pass it where needed
Attempting to close an overlay that does not exist is pretty much always
a bug in the code. Making not_found_ok true by default will hide obvious
bugs from us ; which is not a good thing. Perhaps more importantly, we
might just remove the wrong overlay.

Instead, we should just pass not_found_ok=True as a workaround when we
know the code is buggy and don't have time to fix the bug cleanly.

This is what happens for SSH keys import. If the import fails, we remove
the loading animation. However for answers-based runs, we do not have a
loading animation so the code bails. Let's add not_found_ok=True in this
context and we can fix the code later.

Signed-off-by: Olivier Gayot <olivier.gayot@canonical.com>
2022-12-07 10:31:15 +01:00
Olivier Gayot 4025cbf97f ui: avoid crashing when removing overlay that does not exist
BaseView.remove_overlay() would crash with AttributeError if no overlay
was found. We now add a not_found_ok parameter (defaulting to True) that
makes the function silently return if the overlay could not be found.

Passing not_found_ok=False and catching OverlayNotFoundError can be
helpful in some scenarios to do something different if no overlay was
found.

Signed-off-by: Olivier Gayot <olivier.gayot@canonical.com>
2022-12-07 10:31:05 +01:00
Michael Hudson-Doyle 06d7f04032 remove --script/--click command line arguments
I implemented these a long time ago to help working on parts of the ui
by allowing a way to script moving past some screens. I haven't used
them in ages, it's pretty bad code and probably a fragmentary answers
file is a better solution to the same problem. What do you think?
2022-12-07 14:56:00 +13:00
Michael Hudson-Doyle 7aab0b5de4 rewrite Spinner to not require a loop parameter 2022-12-07 14:19:27 +13:00
Michael Hudson-Doyle 7c3e966356 fix getting ssh info when sshd is not installed 2022-11-30 11:12:51 +13: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 5dafdb916d call into snapd to set up encryption when required 2022-11-11 14:46:44 +13:00
Michael Hudson-Doyle 7618ce2af6 extend "unit" test to cover finish_install
and fix the bug it inevitably found.
2022-11-10 11:57:21 +13:00
Michael Hudson-Doyle 2bb3aab362 add sample data which will fail at the finish-install step 2022-11-10 11:48:37 +13:00
Michael Hudson-Doyle c24cfd3d04 call into snapd to finish the installation of a core boot classic system 2022-11-10 11:48:37 +13:00
Michael Hudson-Doyle 85b3cd0724 switch from loop.create_task to asyncio.create_task
mostly done with sed
2022-11-08 10:08:46 +13:00
Olivier Gayot fa351ed7bc
Merge pull request #1446 from ogayot/pr/event-loop-rework
Stop calling deprecated asyncio.get_event_loop() function
2022-10-28 17:50:24 +02:00
Olivier Gayot a62a0b6002 loop: start running the event loop before doing anything else
This allows us to use asyncio.run() and to avoid many pitfalls.

Signed-off-by: Olivier Gayot <olivier.gayot@canonical.com>
2022-10-28 17:05:54 +02:00
Olivier Gayot 01567251f6 loop: invoke asyncio.create_task() directly
asyncio.create_task() calls asyncio.get_running_loop() under the hood so
there is no need to call get_running_loop() ourselves if the sole
purpose is to create a task.

Signed-off-by: Olivier Gayot <olivier.gayot@canonical.com>
2022-10-28 17:05:54 +02:00