Skip to content

Commit

Permalink
updated flag file behaviour - sdw-last-updated written after both upd…
Browse files Browse the repository at this point in the history
…ates_ok and reboot_required status set, sdw-update-status updated by launcher after a required reboot
  • Loading branch information
zenmonkeykstop committed Feb 12, 2020
1 parent c3cbec3 commit e2fda14
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 20 deletions.
27 changes: 12 additions & 15 deletions launcher/sdw_updater_gui/Updater.py
Original file line number Diff line number Diff line change
Expand Up @@ -437,9 +437,19 @@ def should_launch_updater(interval):
sdlog.info("Update interval expired: launching updater.")
return True
else:
if _status_ok_or_rebooted(status):
sdlog.info("Update interval not expired, launching client.")
if status["status"] == UpdateStatus.UPDATES_OK.value:
sdlog.info("Updates OK and interval not expired, launching client.")
return False
elif status["status"] == UpdateStatus.REBOOT_REQUIRED.value:
if last_required_reboot_performed():
sdlog.info(
"Required reboot performed, updating status and launching client."
)
_write_updates_status_flag_to_disk(UpdateStatus.UPDATES_OK)
return False
else:
sdlog.info("Required reboot pending, launching updater")
return True
else:
sdlog.info(
"Update status is {}, launching updater.".format(
Expand Down Expand Up @@ -476,19 +486,6 @@ def _interval_expired(interval, status):
return True


def _status_ok_or_rebooted(status):
"""
Check if update status is OK or post-reboot.
"""

if status["status"] == UpdateStatus.UPDATES_OK.value or ( # noqa W504
status["status"] == UpdateStatus.REBOOT_REQUIRED.value
and last_required_reboot_performed() # noqa W504
):
return True
return False


class UpdateStatus(Enum):
"""
Standardizes return codes for update/upgrade methods
Expand Down
2 changes: 1 addition & 1 deletion launcher/sdw_updater_gui/UpdaterApp.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ def run(self):
# write the flags to disk
run_results = Updater.overall_update_status(results)
Updater._write_updates_status_flag_to_disk(run_results)
if run_results == UpdateStatus.UPDATES_OK:
if run_results in {UpdateStatus.UPDATES_OK, UpdateStatus.REBOOT_REQUIRED }:
Updater._write_last_updated_flags_to_disk()
# populate signal contents
message = results # copy all the information from results
Expand Down
12 changes: 8 additions & 4 deletions launcher/tests/test_updater.py
Original file line number Diff line number Diff line change
Expand Up @@ -839,7 +839,8 @@ def test_last_required_reboot_performed_not_required(
(UpdateStatus.UPDATES_FAILED, True, False),
],
)
def test_should_run_updater_status_interval_expired(status, expected, rebooted):
@mock.patch("Updater._write_updates_status_flag_to_disk")
def test_should_run_updater_status_interval_expired(mocked_write, status, expected, rebooted):
TEST_INTERVAL = 3600
with mock.patch("Updater.last_required_reboot_performed") as mocked_last:
mocked_last.return_value = rebooted
Expand Down Expand Up @@ -869,7 +870,8 @@ def test_should_run_updater_status_interval_expired(status, expected, rebooted):
(UpdateStatus.UPDATES_FAILED, True, False),
],
)
def test_should_run_updater_status_interval_not_expired(status, expected, rebooted):
@mock.patch("Updater._write_updates_status_flag_to_disk")
def test_should_run_updater_status_interval_not_expired(mocked_write, status, expected, rebooted):
TEST_INTERVAL = 3600
with mock.patch("Updater.last_required_reboot_performed") as mocked_last:
mocked_last.return_value = rebooted
Expand All @@ -882,7 +884,8 @@ def test_should_run_updater_status_interval_not_expired(status, expected, reboot
assert expected == updater.should_launch_updater(TEST_INTERVAL)


def test_should_run_updater_invalid_status():
@mock.patch("Updater._write_updates_status_flag_to_disk")
def test_should_run_updater_invalid_status(mocked_write):
TEST_INTERVAL = 3600
with mock.patch("Updater.last_required_reboot_performed") as mocked_last:
mocked_last.return_value = True
Expand All @@ -892,7 +895,8 @@ def test_should_run_updater_invalid_status():
assert updater.should_launch_updater(TEST_INTERVAL) is True


def test_should_run_updater_invalid_timestamp():
@mock.patch("Updater._write_updates_status_flag_to_disk")
def test_should_run_updater_invalid_timestamp(mocked_write):
TEST_INTERVAL = 3600
with mock.patch("Updater.last_required_reboot_performed") as mocked_last:
mocked_last.return_value = True
Expand Down

0 comments on commit e2fda14

Please sign in to comment.