Skip to content

Fix reboot without message #250

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion host_modules/reboot.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ def issue_reboot(self, options):
return err, errstr

# Sets reboot_status_flag to be in active state
self.populate_reboot_status_flag(True, int(time.time()), reboot_request["message"])
self.populate_reboot_status_flag(True, int(time.time()), reboot_request.get("message", ""))

# Issue reboot in a new thread and reset the reboot_status_flag if the reboot fails
try:
Expand Down
23 changes: 20 additions & 3 deletions tests/host_modules/reboot_test.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
"""Tests for reboot."""

import imp
import json
import sys
import os
import pytest
import datetime
import logging
import time
from itertools import repeat

if sys.version_info >= (3, 3):
from unittest import mock
Expand Down Expand Up @@ -275,6 +273,25 @@ def test_issue_reboot_success_cold_boot(self):
)
mock_thread.return_value.start.assert_called_once_with()

def test_issue_reboot_success_cold_no_message(self):
with (
mock.patch("threading.Thread") as mock_thread,
mock.patch("reboot.Reboot.validate_reboot_request", return_value=(0, "")),
):
request = json.loads(VALID_REBOOT_REQUEST_COLD)
del request["message"]
request_str = json.dumps(request)

self.reboot_module.populate_reboot_status_flag()
result = self.reboot_module.issue_reboot([request_str])
assert result[0] == 0
assert result[1] == "Successfully issued reboot"
mock_thread.assert_called_once_with(
target=self.reboot_module.execute_reboot,
args=(REBOOT_METHOD_COLD_BOOT_ENUM,),
)
mock_thread.return_value.start.assert_called_once_with()

def test_issue_reboot_success_halt(self):
with (
mock.patch("threading.Thread") as mock_thread,
Expand Down
Loading