Skip to content

Commit df5291f

Browse files
committed
updater: update tests and code refformating
1 parent 343caa0 commit df5291f

8 files changed

Lines changed: 64 additions & 41 deletions

File tree

qui/updater/intro_page.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -205,14 +205,15 @@ def select_rows(self):
205205
for row in self.list_store:
206206
row.selected = row.updates_available in self.head_checkbox.allowed
207207

208-
def select_rows_ignoring_conditions(self, cliargs, dom0):
208+
def select_rows_ignoring_conditions(self, cliargs):
209209
cmd = ["qubes-vm-update", "--dry-run", "--quiet"]
210210

211211
args = [a for a in dir(cliargs) if not a.startswith("_")]
212212
for arg in args:
213213
if arg in (
214214
"non_interactive",
215215
"non_default_select",
216+
"dom0",
216217
"restart",
217218
"apply_to_sys",
218219
"apply_to_all",
@@ -229,10 +230,12 @@ def select_rows_ignoring_conditions(self, cliargs, dom0):
229230
cmd.append(f"--{arg.replace('_', '-')}")
230231
if not isinstance(value, bool):
231232
cmd.append(str(value))
233+
if cliargs.dom0:
234+
cmd.extend(["--targets", "dom0"])
232235

233236
to_update = set()
234237
non_default_select = [
235-
"--" + arg for arg in cliargs.non_default_select if arg != "dom0" # TODO remove dom0 flag
238+
"--" + arg for arg in cliargs.non_default_select if arg != "dom0"
236239
]
237240
non_default = [a for a in cmd if a in non_default_select]
238241
if non_default or cliargs.non_interactive:
@@ -251,12 +254,14 @@ def _get_stale_qubes(self, cmd):
251254
result = set()
252255
if "dom0" in output_lines[0]:
253256
result.add("dom0")
254-
if ":" not in output_lines[1]:
257+
258+
second_line = output_lines[1] if len(output_lines) > 1 else ""
259+
if ":" not in second_line:
255260
return result
256261

257262
return result.union({
258263
vm_name.strip()
259-
for vm_name in output_lines[1].split(":", maxsplit=1)[1].split(",")
264+
for vm_name in second_line.split(":", maxsplit=1)[1].split(",")
260265
})
261266
except subprocess.CalledProcessError as err:
262267
if err.returncode != 100:

qui/updater/progress_page.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
import threading
2525
import time
2626
import gi
27-
from typing import Dict, List
27+
from typing import Dict
2828

2929
gi.require_version("Gtk", "3.0") # isort:skip
3030
from gi.repository import Gtk, Gdk, GLib, GObject # isort:skip
@@ -231,7 +231,9 @@ def handle_err_line(self, untrusted_line, rows):
231231

232232
def read_stdouts(self, proc, rows):
233233
curr_name_out = ""
234-
for untrusted_line in iter(proc.stdout.readline, "__COMMUNICATION_IS_DONE__"):
234+
for untrusted_line in iter(
235+
proc.stdout.readline, "__COMMUNICATION_IS_DONE__"
236+
):
235237
if untrusted_line != "__COMMUNICATION_IS_DONE__":
236238
line = self._sanitize_line(untrusted_line)
237239
maybe_name, text = line.split(" ", 1)

qui/updater/tests/conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ def all_vms_list(test_qapp, mock_list_store):
188188

189189

190190
@pytest.fixture
191-
def updatable_vms_list(test_qapp, mock_list_store):
191+
def updateable_vms_list(test_qapp, mock_list_store):
192192
result = ListWrapper(UpdateRowWrapper, mock_list_store)
193193
for vm in test_qapp.domains:
194194
if vm.klass in ("AdminVM", "TemplateVM", "StandaloneVM"):

qui/updater/tests/test_intro_page.py

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,7 @@ def test_populate_vm_list(
4040
("test-standalone", "admin.vm.feature.Get", "updates-available", None)
4141
] = (b"0\x00" + str(1).encode())
4242
# inconsistent output of qubes-vm-update, but it does not matter
43-
mock_subprocess.return_value = (
44-
b"Following templates will be updated:test-standalone"
45-
)
43+
mock_subprocess.return_value = b"The admin VM will not be updated.\nFollowing templates will be updated:test-standalone"
4644

4745
assert not sut.is_populated
4846

@@ -56,12 +54,13 @@ def test_populate_vm_list(
5654
("fedora-36", "admin.vm.feature.Get", "updates-available", None)
5755
] = (b"0\x00" + str(1).encode())
5856
mock_subprocess.return_value = (
57+
b"The admin VM (dom0) will be updated.\n"
5958
b"Following templates will be updated:test-standalone,fedora-36"
6059
)
6160

6261
sut.populate_vm_list(test_qapp, mock_settings)
6362
assert len(sut.list_store) == 4
64-
assert len(sut.get_vms_to_update()) == 2
63+
assert len(sut.get_vms_to_update()) == 3
6564

6665

6766
# i-th expectations value is an expected number of selected VMs after clicking on the
@@ -342,33 +341,46 @@ def test_prohibit_start_rationale_tooltip(
342341
# Comma separated list of VMs to target
343342
pytest.param(
344343
("--targets", "dom0,fedora-36"),
345-
b"fedora-36",
344+
b"dom0,fedora-36",
346345
b"",
347346
{"dom0", "fedora-36"},
348-
("--targets", "fedora-36"),
347+
("--targets", "dom0,fedora-36"),
349348
id="targets",
350349
),
351350
# `qubes-update-gui --standalones`
352351
# Target all StandaloneVMs
353352
pytest.param(
354353
("--standalones",),
355-
b"",
356354
",".join(_standalones).encode(),
355+
b"",
357356
_standalones,
358357
("--standalones",),
359358
id="standalones",
360359
),
361360
# `qubes-update-gui --dom0`
362361
# Target dom0
363-
pytest.param(("--dom0", "--force-update"), b"", b"", {"dom0"}, None, id="dom0"),
362+
pytest.param(("--dom0", "--force-update"), b"", b"", {"dom0"},
363+
("--force-update", "--targets", "dom0"), id="dom0"),
364364
# `qubes-update-gui --dom0 --skip dom0`
365365
# Comma separated list of VMs to be skipped,
366366
# works with all other options.
367367
pytest.param(
368-
("--dom0", "--skip", "dom0"), b"", b"", set(), None, id="skip all"
368+
("--dom0", "--skip", "dom0"),
369+
b"",
370+
b"",
371+
set(),
372+
("--skip", "dom0", "--targets", "dom0"),
373+
id="skip all",
369374
),
370375
# `qubes-update-gui --skip dom0`
371-
pytest.param(("--skip", "dom0"), b"", b"", set(), None, id="skip dom0"),
376+
pytest.param(
377+
("--skip", "dom0"),
378+
b"",
379+
b"",
380+
set(),
381+
("--skip", "dom0"),
382+
id="skip dom0",
383+
),
372384
# `qubes-update-gui --skip garbage-name`
373385
pytest.param(
374386
("--skip", "garbage-name"),
@@ -385,7 +397,7 @@ def test_prohibit_start_rationale_tooltip(
385397
b"",
386398
b"",
387399
set(),
388-
None,
400+
("--skip", "dom0", "--targets", "dom0"),
389401
id="skip all targets",
390402
),
391403
# `qubes-update-gui --templates dom0 --skip fedora-36,garbage-name`
@@ -424,7 +436,11 @@ def test_select_rows_ignoring_conditions(
424436

425437
assert len(sut.list_store) == 13
426438

427-
result = b""
439+
if "dom0" in expected_selection:
440+
result = b"The admin VM (dom0) will be updated.\n"
441+
else:
442+
result = b"The admin VM will not be updated.\n"
443+
428444
if tmpls_and_stndas:
429445
result += (
430446
b"Following templates and standalones will be updated: " + tmpls_and_stndas
@@ -443,7 +459,7 @@ def test_select_rows_ignoring_conditions(
443459
] = (b"0\x00" + b"3020-01-01 00:00:00")
444460

445461
cliargs = parse_args(args, test_qapp)
446-
sut.select_rows_ignoring_conditions(cliargs, test_qapp.domains["dom0"])
462+
sut.select_rows_ignoring_conditions(cliargs)
447463
to_update = {row.name for row in sut.list_store if row.selected}
448464

449465
assert to_update == expected_selection

qui/updater/tests/test_progress_page.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ def test_perform_update(
8484
mock_next_button,
8585
mock_cancel_button,
8686
mock_label,
87-
updatable_vms_list,
87+
updateable_vms_list,
8888
):
8989
mock_log = Mock()
9090
mock_callback = Mock()
@@ -97,7 +97,7 @@ def test_perform_update(
9797
mock_callback,
9898
)
9999

100-
sut.vms_to_update = updatable_vms_list
100+
sut.vms_to_update = updateable_vms_list
101101

102102
class VMConsumer:
103103
def __call__(self, vm_rows, *args, **kwargs):
@@ -130,7 +130,7 @@ def test_update_templates(
130130
idle_add,
131131
interrupted,
132132
real_builder,
133-
updatable_vms_list,
133+
updateable_vms_list,
134134
mock_next_button,
135135
mock_cancel_button,
136136
mock_label,
@@ -154,15 +154,15 @@ def test_update_templates(
154154

155155
sut.update_details.progress_textview = mock_text_view
156156
# chose vm to show details
157-
sut.update_details.active_row = updatable_vms_list[0]
158-
for i, row in enumerate(updatable_vms_list):
157+
sut.update_details.active_row = updateable_vms_list[0]
158+
for i, row in enumerate(updateable_vms_list):
159159
row.buffer = f"Details {i}"
160160

161161
if interrupted:
162162
sut.interrupt_update()
163-
sut.update_selected(updatable_vms_list, mock_settings)
163+
sut.update_selected(updateable_vms_list, mock_settings)
164164

165-
sut.update_details.set_active_row(updatable_vms_list[2])
165+
sut.update_details.set_active_row(updateable_vms_list[2])
166166

167167
calls = [
168168
call(sut.set_total_progress, 100),
@@ -252,7 +252,7 @@ def test_get_update_summary(
252252
mock_next_button,
253253
mock_cancel_button,
254254
mock_label,
255-
updatable_vms_list,
255+
updateable_vms_list,
256256
):
257257
mock_log = Mock()
258258
mock_callback = Mock()
@@ -265,12 +265,12 @@ def test_get_update_summary(
265265
mock_callback,
266266
)
267267

268-
updatable_vms_list[0].set_status(UpdateStatus.NoUpdatesFound)
269-
updatable_vms_list[1].set_status(UpdateStatus.Error)
270-
updatable_vms_list[2].set_status(UpdateStatus.Cancelled)
271-
updatable_vms_list[3].set_status(UpdateStatus.Success)
268+
updateable_vms_list[0].set_status(UpdateStatus.NoUpdatesFound)
269+
updateable_vms_list[1].set_status(UpdateStatus.Error)
270+
updateable_vms_list[2].set_status(UpdateStatus.Cancelled)
271+
updateable_vms_list[3].set_status(UpdateStatus.Success)
272272

273-
sut.vms_to_update = updatable_vms_list
273+
sut.vms_to_update = updateable_vms_list
274274

275275
updated, no_updates, failed, cancelled = sut.get_update_summary()
276276

@@ -281,9 +281,9 @@ def test_get_update_summary(
281281
mock_callback.assert_not_called()
282282

283283

284-
def test_set_active_row(real_builder, updatable_vms_list):
284+
def test_set_active_row(real_builder, updateable_vms_list):
285285
sut = QubeUpdateDetails(real_builder)
286-
row = updatable_vms_list[0]
286+
row = updateable_vms_list[0]
287287
sut.set_active_row(row)
288288

289289
assert sut.details_label.get_text().strip() == "Details for"

qui/updater/tests/test_summary_page.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ def test_populate_restart_list(
201201
expected,
202202
real_builder,
203203
test_qapp,
204-
updatable_vms_list,
204+
updateable_vms_list,
205205
mock_next_button,
206206
mock_cancel_button,
207207
mock_settings,
@@ -224,7 +224,7 @@ def test_populate_restart_list(
224224
)
225225
sut.summary_list = mock_tree_view
226226

227-
for row in updatable_vms_list:
227+
for row in updateable_vms_list:
228228
row.set_status(UpdateStatus.Success)
229229
if row.vm.klass == "TemplateVM":
230230
for i, appvm in enumerate(row.vm.appvms):
@@ -233,7 +233,7 @@ def test_populate_restart_list(
233233
else:
234234
appvm.is_running = lambda *_args: False
235235

236-
sut.populate_restart_list(True, updatable_vms_list, mock_settings)
236+
sut.populate_restart_list(True, updateable_vms_list, mock_settings)
237237

238238
assert len(sut.list_store) == UP_VMS
239239
assert sum(row.selected for row in sut.list_store) == expected

qui/updater/tests/test_updater.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def test_setup_non_interactive_nothing_to_do(
4646
get_vms, select, subproc, _mock_logging, __mock_logging, test_qapp
4747
):
4848
sut = QubesUpdater(test_qapp, parse_args(("-n",), test_qapp))
49-
subproc.return_value = b""
49+
subproc.return_value = b"The admin VM will not be updated."
5050
get_vms.return_value = ()
5151
sut.perform_setup()
5252
select.assert_called_once()

qui/updater/updater.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ def cell_data_func(_column, cell, model, it, data):
194194
if skip_intro_if_args(self.cliargs):
195195
self.log.info("Skipping intro page.")
196196
self.intro_page.select_rows_ignoring_conditions(
197-
cliargs=self.cliargs, dom0=self.qapp.domains["dom0"]
197+
cliargs=self.cliargs
198198
)
199199
if len(self.intro_page.get_vms_to_update()) == 0:
200200
self.do_nothing = True
@@ -473,7 +473,7 @@ def parse_args(args, app):
473473
parser.add_argument(
474474
"--dom0",
475475
action="store_true",
476-
help="Target dom0. If present, skip manual selection of qubes to update.",
476+
help="Target dom0. Short version of --targets dom0.",
477477
)
478478

479479
parser.add_argument(

0 commit comments

Comments
 (0)