Commit Graph

898 Commits

Author SHA1 Message Date
Dan Bungert 77119a8e0b SingleInstanceTask: add cancel_restart
cancel_restart is a mode for SingleInstanceTask that changes the
behavior when starting the task - if the task is already running, do not
cancel it to start another.
2022-05-25 10:25:00 -06:00
Dan Bungert 884f1c87ae pubsub: fix test fragility 2022-05-24 13:36:02 -06:00
Olivier Gayot 37de61f245 snaplist: display starred indication (✪) in orange
Signed-off-by: Olivier Gayot <olivier.gayot@canonical.com>
2022-05-10 09:45:25 +02:00
Olivier Gayot 2fdeb55218 snaplist: improve hack to display double stars instead of ✓
We used to rely on the narrow non-breakable space to be displayed as a
star in basic mode. This is not great and could impact other screens.

We now make use of two check-marks (each replaced by a star in basic
mode) and mask one of them in rich mode using display attributes.

Signed-off-by: Olivier Gayot <olivier.gayot@canonical.com>
2022-05-10 09:45:25 +02:00
Olivier Gayot fcb33b8a0a snaplist: do not use green color for stars in basic mode
The "**" signs replace the check-mark for a verified publisher when in
basic mode.

These "**" signs where still used green foreground color. This was the
only place where we tried to display colors in basic mode.

Keep the default colors instead. This should be more compatible.

Signed-off-by: Olivier Gayot <olivier.gayot@canonical.com>
2022-05-04 10:32:32 +02:00
Olivier Gayot e5017256a2 snaplist: add visual indication for starred publishers
In addition to verified publishers being indicated by a check-mark, we
now have starred publishers indicated with a circled star.

If unicode support is not available, for instance with serial
connections, we use a different number of stars to represent:

 * verified publishers: 2 stars
 * starred publishers: 1 star
 * others: no star

Because our mechanism to substitute unicode characters with ascii
equivalents expect a 1:1 mapping, we cannot simply replace the circled
start by two stars. To workaround the issue, we added a narrow
non-breakable space.

When support of unicode is available, this character shows up as a
normal space.
When support of unicode is not available, it gets replaced by a star.

Signed-off-by: Olivier Gayot <olivier.gayot@canonical.com>
2022-05-04 10:32:32 +02:00
Olivier Gayot cb132611c2 ui: get rid of unreachable else block
The following commit added an unconditional return statement in the try
block of _move_screen, effectively making the associated else block
unreachable.

  a7bcc7fa add a way to wait for something with notification after 0.1s

Signed-off-by: Olivier Gayot <olivier.gayot@canonical.com>
2022-04-13 18:34:46 +02:00
Olivier Gayot 014d9d0d01 ui: introduce an optional level of indirection in make_ui
The make_ui() function / coroutine returns a BaseView (i.e., a
screen to display to the user).

That being said, when the application calls, make_ui(), it does not come
with a guarantee that the view returned will be displayed to the user
immediately.

One of the reason is that there are multiple await statements before the
we call the ui.set_body function. Therefore, tasks running concurrently
cannot reliably expect that they execute after the display is refreshed.

Perhaps more importantly, when the make_ui() function takes more than .1
second to execute, we display a "Progress" screen that stays visible for
at least one second. This can effectively delay a lot the moment when
the view returned by make_ui() is shown to the user. A lot can happen in
the meantime.

As the result, the view returned by make_ui can be outdated by the time
we show it on the screen.

One way to work around this problem is to store in the controller a
reference to the view that it returns in make_ui(). This way, the
controller can modify the view and keep it up-to-date until it gets
shown to the user.

Unfortunately, some controllers (e.g., the storage controller) do not
modify / mutate the existing view object when a modification is needed ;
but instead instantiate a new view object.

This patch introduces a level of indirection that can be used by these
controllers. Instead of returning a view object from make_ui(), the
controllers are now allowed to return a callback ; which in turn will
return a view object.

https://bugs.launchpad.net/subiquity/+bug/1968161

Signed-off-by: Olivier Gayot <olivier.gayot@canonical.com>
2022-04-13 18:34:46 +02:00
Michael Hudson-Doyle b07405a744
Merge pull request #1257 from ogayot/mypy-fixes
Some more code cleanup
2022-04-13 12:09:04 +12:00
Olivier Gayot a63a3ef753 utils: accept sequences of strings as commands
We used to only accept lists of strings for commands. We now accept
sequences of strings instead ; which are lists of strings or tuple of
strings.

Signed-off-by: Olivier Gayot <olivier.gayot@canonical.com>
2022-04-12 10:04:16 +02:00
Olivier Gayot dd788f9eee add assert statements following .communicate() to help type checkers
After calling .communicate() on an asyncio.subprocess.Process object,
the attribute returncode gets set to a non-None value. Type checkers are
not able to figure this out.

Fixed by adding an assert to help type checkers out.

Signed-off-by: Olivier Gayot <olivier.gayot@canonical.com>
2022-04-12 10:04:16 +02:00
Olivier Gayot f0ea1d16c2 network: initialize bond, vlan & wlan to None to avoid changing type
Signed-off-by: Olivier Gayot <olivier.gayot@canonical.com>
2022-04-12 09:50:21 +02:00
Dan Bungert 8ca83aa9cf file_util: genericize copy routine 2022-04-11 12:51:26 -06:00
Olivier Gayot f3634dc242 Add type hints where necessary to make mypy happy
Signed-off-by: Olivier Gayot <olivier.gayot@canonical.com>
2022-04-06 11:23:34 +02:00
Olivier Gayot 56192938a9 network: fixed typo addressesses -> addresses
Signed-off-by: Olivier Gayot <olivier.gayot@canonical.com>
2022-04-06 11:23:10 +02:00
Dan Bungert a3e1cfa6e4 probert: implement os prober arg 2022-03-29 15:09:21 -06:00
Dan Bungert 4b1277ae2d console-conf: fix crash on network info
If you run dryrun for console-conf, go to the network page, go to an
interface, then info, a crash of the form
TypeError: object str can't be used in 'await' expression
can be seen. The signature for the core version of get_info_for_netdev
is not async, but a non-async method returning str.

So mark the core version of the function async.

Co-authored-by: Michael Hudson-Doyle <michael.hudson@canonical.com>
2022-03-14 15:09:23 -06:00
Dan Bungert 4698dcd935 logging: raise warning when not adjusting perms 2022-03-14 09:48:19 -06:00
Dan Bungert 953998b23a logging: 0770 log dir in install env, 0750 later 2022-03-11 12:44:22 -07:00
Olivier Gayot 87c249d5d0 Add type annotations for command execution methods
Signed-off-by: Olivier Gayot <olivier.gayot@canonical.com>
2022-02-28 14:05:56 +01:00
Olivier Gayot 812bba1de1 Use logger names consistent with directory structure
Refreshed name of loggers to make them consistent with the directory
structure.

Signed-off-by: Olivier Gayot <olivier.gayot@canonical.com>
2022-02-25 17:35:45 +01:00
Dan Bungert 42db747a0d file_util: remove omode / copy_mode
omode used to be in use, but has been standardized to 'w'.
copy_mode was unused.  Remove both.
2022-02-14 11:23:39 -07:00
Dan Bungert f4a9836143 file_util generate_config -> generate_config_yaml
The two usages of generate_config were both for yaml, so make that
simpler.
2022-02-14 11:21:56 -07:00
Dan Bungert b7349241a9 standardize on useage of file_util methods 2022-02-14 11:14:10 -07:00
Dan Bungert fae24f3247 logging: log files 0640 root:adm 2022-02-14 11:14:10 -07:00
Dan Bungert 9b5513f311 file_util: add open_perms and generate_config
Create open_perms context manager for custom or multiple writes.
Create generate_config for a small removal of redundancy.
0640 root:adm the resulting files.
2022-02-14 11:14:10 -07:00
Dan Bungert 0f9c9eef3f options: add output_base for dryrun use
To enable parallel API testing, add an output_base argument to replace
the default '.subiquity' that is sprinkled everywhere.
2022-01-26 10:39:23 -07:00
Olivier Gayot de19b3abee Add type hinting for controller base class attributes
Signed-off-by: Olivier Gayot <olivier.gayot@canonical.com>
2022-01-14 13:02:44 +01:00
Olivier Gayot 475d71e166 Allow to pass dry_run boolean to lsb_release
So that we consistently return the same value from lsb_release() across
all calls that use dry-run, the function now accepts a dry_run argument
(defaulting to False). This way, in dry-run mode, the caller does not
need to supply the path to a specific example file anymore.

  lsb_release(dry_run=True) -> will load examples/lsb-release-focal

Having said that, the caller is still left with the possibility to
specify the example file by using the path argument:

  lsb_release(path="example/lsb-release-impish")

The path and dry_run arguments are mutually exclusive: providing both
will result in a ValueError.

Signed-off-by: Olivier Gayot <olivier.gayot@canonical.com>
2021-12-17 16:00:52 +01:00
Olivier Gayot 68b9c42fac Fix exception messages not interpolated properly
Signed-off-by: Olivier Gayot <olivier.gayot@canonical.com>
2021-12-16 11:35:40 +01:00
Dan Bungert 0308fa49b1 core test_view: don't prefix local class w/ Test
Fix warning:
  subiquitycore/tests/test_view.py:24
    subiquity/subiquitycore/tests/test_view.py:24:
    PytestCollectionWarning: cannot collect test class 'TestStretchy'
    because it has a __init__ constructor
2021-10-15 16:12:44 -06:00
Michael Hudson-Doyle 744269d074 remove stdlib backports from Python 3.8 2021-10-12 18:55:09 -06:00
Michael Hudson-Doyle 7cfc7d1215 close the session object after each request to the snapd API
As reported in https://bugs.launchpad.net/snapd/+bug/1946656,
not-quite idle connections between subiquity and snapd are piling up and
causing issues when trying to restart subiquity. I don't really
understand why, but using a fresh session for each API access makes the
problem go away.
2021-10-12 22:22:12 +13:00
Michael Hudson-Doyle b144f234ac install packages listed by check-language-support when locale_support == "langpack" 2021-09-30 12:09:57 +13:00
Dan Bungert af8dcfe6c3 pubsub: remove subscribe args, more broadcast args
Remove the subscribe time args, as they weren't used.
With that flexibility we can add many args at broadcast time.
2021-09-24 13:11:55 -06:00
Dan Bungert 350ce11dd9 pubsub: optional argument at broadcast time 2021-09-24 13:10:04 -06:00
Michael Hudson-Doyle 2f9c22961e
Merge pull request #1042 from canonical/wsl_oobe_auto_reconf_mode
DE-98/DE-99 - system_setup: Wsl oobe auto reconf mode
2021-09-24 14:26:23 +12:00
Michael Hudson-Doyle 7f6af23694 set wider permissions on log directory 2021-09-23 21:24:44 +12:00
Patrick Wu 1aac580dfd system_setup: update the detection logic 2021-09-20 21:58:16 +08:00
Michael Hudson-Doyle 1519c49d8e
Merge pull request #1030 from mwhudson/source-selection-3
install source selection
2021-09-14 15:10:58 +12:00
Michael Hudson-Doyle a6270cbaa1 server side implementation of source selection 2021-09-13 13:23:09 +12:00
Dan Bungert a005418cde pubsub: split channels into two classes 2021-09-08 18:33:57 -06:00
Dan Bungert bc8fda47f6 EventCallback: remove 2021-09-08 18:33:57 -06:00
Dan Bungert 3a69683128 geoip: switch to MessageHub 2021-09-08 18:33:57 -06:00
Dan Bungert fc95c72f35 pubsub: Add unit test for MessageHub
Also minor cleanup on the soon-to-be-removed EventCallback test to help
demonostrate that some of this code isn't needed.
2021-09-08 18:33:57 -06:00
Dan Bungert 0ea8139f32 MessageHub: Switch to using enum constants 2021-09-08 18:33:57 -06:00
Michael Hudson-Doyle 7f1beb1d64 add a mode argument to shutdown to allow reboot or power off 2021-08-22 09:36:41 +12:00
Dan Bungert c79aa602dc Proper fix for setting timezone inappropriately in dryrun
Reenable integration test for set of timezone.
Don't set it while in dryrun.
2021-07-15 10:49:32 -06:00
Dan Bungert ada889328d Verify that machine-config arg is a file
If machine-config is pointed to a non-existant file, dryrun can kind of
unhelpfully hang without much indication that anything is happening.
2021-07-14 16:40:22 -06:00
Dan Bungert 40945f1823
TimeZone: autoinstall and API (FR-1184) (#986)
* TimeZone: autoinstall and API

Add support for Get/Set timezone methods.  Get means that we inquire
with GeoIP as to which timezone is suggested.  Non-availability of
GeoIP, or a previous explicit Set, means that we return the system
timezone.  Set of timezone by Post results in set of the live system
timzeone, and queuing a set of the target system by way of cloud-init.

* Add clarifying comment about _request.
2021-07-13 06:25:03 -06:00