Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/pr/203'
Browse files Browse the repository at this point in the history
* origin/pr/203:
  updater: unify retcodes with backend updater
  • Loading branch information
marmarek committed Jul 5, 2024
2 parents bce0f8c + 8d1c88b commit f96a369
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 3 deletions.
2 changes: 2 additions & 0 deletions qui/updater/progress_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ def __init__(
self.exit_triggered = False
self.update_thread = None
self.after_update_callback = callback
self.retcode = None

self.update_details = QubeUpdateDetails(self.builder)

Expand Down Expand Up @@ -355,6 +356,7 @@ def do_update_templates(
proc.wait()
read_err_thread.join()
read_out_thread.join()
self.retcode = proc.returncode

def read_stderrs(self, proc, rows):
for untrusted_line in iter(proc.stderr.readline, ''):
Expand Down
6 changes: 4 additions & 2 deletions qui/updater/tests/test_progress_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,18 +195,19 @@ def test_do_update_templates(
class MockPorc:
def __init__(self, finish_after_n_polls=2):
self.polls = 0
self.returncode = 40
self.finish_after_n_polls = finish_after_n_polls

def wait(self):
"""Mock waiting."""
"""Mock waiting."""
pass

def poll(self):
"""After several polls return 0 (process finished)."""
self.polls += 1
if self.polls < self.finish_after_n_polls:
return None
return 0
return self.returncode


mock_subprocess.return_value = MockPorc()
Expand Down Expand Up @@ -239,6 +240,7 @@ def poll(self):
stderr=subprocess.PIPE, stdout=subprocess.PIPE)]
mock_subprocess.assert_has_calls(calls)
mock_callback.assert_not_called()
assert sut.retcode == 40


def test_get_update_summary(
Expand Down
2 changes: 2 additions & 0 deletions qui/updater/tests/test_updater.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ def test_setup_apply(
(
pytest.param((0, 0, 0, 0), 100, id="nothing to do"),
pytest.param((0, 0, 1, 0), 1, id="failed"),
pytest.param((0, 0, 1, 0), 40, id="failed with retcode"),
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"),
Expand Down Expand Up @@ -152,6 +153,7 @@ def set_vms(_vms_to_update, _settings):
def populate(**_kwargs):
sut.summary_page.list_store = []
sut.summary_page.populate_restart_list = Mock(side_effect=populate)
sut.progress_page.retcode = ret_code
sut.progress_page.get_update_summary = Mock()
sut.progress_page.get_update_summary.return_value = update_results
sut.summary_page.show = Mock()
Expand Down
5 changes: 4 additions & 1 deletion qui/updater/updater.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,10 @@ def next_clicked(self, _emitter, skip_intro=False):
# no updates
self.retcode = 100
if failed:
self.retcode = 1
if self.progress_page.retcode not in (None, 0, 100, 130):
self.retcode = self.progress_page.retcode
else:
self.retcode = 1
if cancelled:
self.retcode = 130
if failed or cancelled or not self.cliargs.non_interactive:
Expand Down

0 comments on commit f96a369

Please sign in to comment.