Commit Graph

955 Commits

Author SHA1 Message Date
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
Olivier Gayot 561fff1d5b
Merge pull request #1336 from ogayot/password-passphrase
Refactor how we handle confirmation fields - use passphrase instead of password where relevant
2022-10-28 14:06:54 +02: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
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 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 521e7026de tweak AsyncSnapd api slightly
also remove dry-run delay for requests to /v2/change/{id}
2022-10-04 16:15:19 +13:00
Dan Bungert 9e0a90fc22 network: use routes instead of gateway directives 2022-09-06 16:44:12 -06:00
Dan Bungert 943ea53fbc
Merge pull request #1402 from dbungert/terminology
fix some easier cases of impolite language
2022-08-29 18:00:35 -06:00
Michael Hudson-Doyle 60953951fe
Merge pull request #1394 from CarlosNihelton/style-help-gray
Defaults help text style to gray
2022-08-30 11:34:42 +12:00
Dan Bungert d73772258d fix some easier cases of impolite language 2022-08-29 12:30:39 -06:00
Carlos Nihelton 6d51deedb6
Assign style if a str is passed
Otherwise assign self.help as passed.

Co-authored-by: Dan Bungert <danielbungert@gmail.com>
2022-08-29 13:55:07 -03:00
J-P Nurmi 05ca22b320 Log NetworkModel.has_network changes 2022-08-26 15:06:15 +02:00
Dan Bungert d3275c3e90
Merge pull request #1393 from CarlosNihelton/fix-gray-contrast
Makes our gray ligther to increase contrast.
2022-08-24 08:44:45 -06:00
Carlos Nihelton eb722fef0b
Defaults help text style to gray
Per
https://github.com/canonical/ubuntu-desktop-installer/issues/1073#issuecomment-1224493840.
Custom styles can still be applied.
2022-08-24 11:24:24 -03:00
Carlos Nihelton 5763f33813
Makes our gray ligther to increase contrast.
Per Design's recommendation in:
https://github.com/canonical/ubuntu-desktop-installer/issues/1073#issuecomment-1225569053
2022-08-24 10:16:59 -03:00
Olivier Gayot eb69f23ce7 ubuntu-pro: update the view to include magic-attach
We now have the view display the user-code fetched via u-a-c and
automatically validate the contract token when the contract selection
succeeds.

If the magic token expires (i.e., u-a-c times out), a new contract
selection is initiated.

Signed-off-by: Olivier Gayot <olivier.gayot@canonical.com>
2022-08-18 16:10:44 +02:00
Chad Smith ddaf48b334 models: subiquitycore.network.rendered_config_paths to list generated files 2022-07-14 21:48:51 -06:00
Chad Smith a531ade6c3 file_util: generate_timestamped_header function to any subiquity written files 2022-07-14 21:48:51 -06:00