Skip to content

Commit 19564a4

Browse files
committed
Fix reboot without message
1 parent 00393e3 commit 19564a4

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed

host_modules/reboot.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ def issue_reboot(self, options):
185185
return err, errstr
186186

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

190190
# Issue reboot in a new thread and reset the reboot_status_flag if the reboot fails
191191
try:

tests/host_modules/reboot_test.py

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
"""Tests for reboot."""
22

33
import imp
4+
import json
45
import sys
56
import os
67
import pytest
7-
import datetime
88
import logging
9-
import time
10-
from itertools import repeat
119

1210
if sys.version_info >= (3, 3):
1311
from unittest import mock
@@ -275,6 +273,25 @@ def test_issue_reboot_success_cold_boot(self):
275273
)
276274
mock_thread.return_value.start.assert_called_once_with()
277275

276+
def test_issue_reboot_success_cold_no_message(self):
277+
with (
278+
mock.patch("threading.Thread") as mock_thread,
279+
mock.patch("reboot.Reboot.validate_reboot_request", return_value=(0, "")),
280+
):
281+
request = json.loads(VALID_REBOOT_REQUEST_COLD)
282+
del request["message"]
283+
request_str = json.dumps(request)
284+
285+
self.reboot_module.populate_reboot_status_flag()
286+
result = self.reboot_module.issue_reboot([request_str])
287+
assert result[0] == 0
288+
assert result[1] == "Successfully issued reboot"
289+
mock_thread.assert_called_once_with(
290+
target=self.reboot_module.execute_reboot,
291+
args=(REBOOT_METHOD_COLD_BOOT_ENUM,),
292+
)
293+
mock_thread.return_value.start.assert_called_once_with()
294+
278295
def test_issue_reboot_success_halt(self):
279296
with (
280297
mock.patch("threading.Thread") as mock_thread,

0 commit comments

Comments
 (0)