Skip to content

Commit

Permalink
updater: return 130 if user cancels updating
Browse files Browse the repository at this point in the history
  • Loading branch information
piotrbartman committed Jun 24, 2024
1 parent a677000 commit 644299a
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 23 deletions.
13 changes: 8 additions & 5 deletions qui/updater/progress_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -461,16 +461,19 @@ def get_update_summary(self):
2. number of vms that tried to update but no update was found,
3. vms that update was canceled before starting.
"""
vm_updated_num = len(
updated = len(
[row for row in self.vms_to_update
if row.status == UpdateStatus.Success])
vm_no_updates_num = len(
no_updates = len(
[row for row in self.vms_to_update
if row.status == UpdateStatus.NoUpdatesFound])
vm_failed_num = len(
failed = len(
[row for row in self.vms_to_update
if row.status in (UpdateStatus.Error, UpdateStatus.Cancelled)])
return vm_updated_num, vm_no_updates_num, vm_failed_num
if row.status == UpdateStatus.Error])
cancelled = len(
[row for row in self.vms_to_update
if row.status == UpdateStatus.Cancelled])
return updated, no_updates, failed, cancelled


class Ticker:
Expand Down
9 changes: 5 additions & 4 deletions qui/updater/tests/test_progress_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,11 +258,12 @@ def test_get_update_summary(

sut.vms_to_update = updatable_vms_list

vm_updated_num, vm_no_updates_num, vm_failed_num = sut.get_update_summary()
updated, no_updates, failed, cancelled = sut.get_update_summary()

assert vm_updated_num == 1
assert vm_no_updates_num == 1
assert vm_failed_num == 2
assert updated == 1
assert no_updates == 1
assert failed == 1
assert cancelled == 1
mock_callback.assert_not_called()


Expand Down
22 changes: 13 additions & 9 deletions qui/updater/tests/test_updater.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,16 @@ def test_setup(populate_vm_list, _mock_logging, __mock_logging, test_qapp):
@pytest.mark.parametrize(
"update_results, ret_code",
(
pytest.param((0, 0, 0), 100, id="nothing to do"),
pytest.param((0, 0, 1), 1, id="failed"),
pytest.param((0, 1, 0), 100, id="no updates"),
pytest.param((0, 1, 1), 1, id="no updates + failed"),
pytest.param((1, 0, 0), 0, id="success"),
pytest.param((1, 0, 1), 1, id="success + failed"),
pytest.param((1, 1, 0), 0, id="success + no updated"),
pytest.param((1, 1, 1), 1, id="all"),
pytest.param((0, 0, 0, 0), 100, id="nothing to do"),
pytest.param((0, 0, 1, 0), 1, id="failed"),
pytest.param((0, 0, 0, 1), 130, id="cancelled"),
pytest.param((0, 0, 1, 1), 130, id="failed + cancelled"),
pytest.param((0, 1, 0, 0), 100, id="no updates"),
pytest.param((0, 1, 1, 0), 1, id="no updates + failed"),
pytest.param((1, 0, 0, 0), 0, id="success"),
pytest.param((1, 0, 1, 0), 1, id="success + failed"),
pytest.param((1, 1, 0, 0), 0, id="success + no updated"),
pytest.param((1, 1, 1, 1), 130, id="all"),
)
)
def test_retcode(_populate_vm_list, _mock_logging, __mock_logging,
Expand Down Expand Up @@ -86,4 +88,6 @@ def populate(**_kwargs):
sut.summary_page.populate_restart_list.assert_called_once_with(
restart=True, vm_updated=vms_to_update, settings=sut.settings)
assert sut.retcode == ret_code
sut.summary_page.show.assert_called_once_with(*update_results)
expected_summary = (update_results[0], update_results[1],
update_results[2] + update_results[3])
sut.summary_page.show.assert_called_once_with(*expected_summary)
12 changes: 7 additions & 5 deletions qui/updater/updater.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,15 +219,17 @@ def next_clicked(self, _emitter, skip_intro=False):
vm_updated=self.progress_page.vms_to_update,
settings=self.settings
)
updated, no_updates, failed = (
updated, no_updates, failed, cancelled = (
self.progress_page.get_update_summary())
if failed:
self.retcode = 1
if updated == 0 and failed == 0:
if updated == 0:
# no updates
self.retcode = 100
if failed:
self.retcode = 1
if cancelled:
self.retcode = 130
if failed or not self.cliargs.non_interactive:
self.summary_page.show(updated, no_updates, failed)
self.summary_page.show(updated, no_updates, failed + cancelled)
else:
self._restart_phase()
if self.cliargs.non_interactive:
Expand Down

0 comments on commit 644299a

Please sign in to comment.