|
54 | 54 | GEN_TIME_KERNEL_PANIC = "2021_3_28_13_48_49"
|
55 | 55 |
|
56 | 56 |
|
| 57 | +REBOOT_CAUSE_UNKNOWN = "Unknown" |
| 58 | +REBOOT_CAUSE_NON_HARDWARE = "Non-Hardware" |
| 59 | +EXPECTED_NON_HARDWARE_REBOOT_CAUSE = {REBOOT_CAUSE_NON_HARDWARE, "N/A"} |
| 60 | +REBOOT_CAUSE_HARDWARE_OTHER = "Hardware - Other" |
| 61 | +EXPECTED_HARDWARE_REBOOT_CAUSE = {REBOOT_CAUSE_HARDWARE_OTHER, ""} |
| 62 | + |
57 | 63 | EXPECTED_PARSE_WARMFAST_REBOOT_FROM_PROC_CMDLINE = "warm-reboot"
|
58 | 64 | EXPECTED_FIND_SOFTWARE_REBOOT_CAUSE_USER = "User issued 'warm-reboot' command [User: admin, Time: Mon Nov 2 22:37:45 UTC 2020]"
|
59 | 65 | EXPECTED_FIND_FIRSTBOOT_VERSION = " (First boot of SONiC version 20191130.52)"
|
60 | 66 | EXPECTED_FIND_SOFTWARE_REBOOT_CAUSE_FIRSTBOOT = "Unknown (First boot of SONiC version 20191130.52)"
|
61 |
| -EXPECTED_HARDWARE_REBOOT_CAUSE = {"warm-reboot", ""} |
62 | 67 |
|
63 | 68 | EXPECTED_WATCHDOG_REBOOT_CAUSE_DICT = {'comment': '', 'gen_time': '2020_10_22_03_15_08', 'cause': 'Watchdog', 'user': 'N/A', 'time': 'N/A'}
|
64 | 69 | EXPECTED_USER_REBOOT_CAUSE_DICT = {'comment': '', 'gen_time': '2020_10_22_03_14_07', 'cause': 'reboot', 'user': 'admin', 'time': 'Thu Oct 22 03:11:08 UTC 2020'}
|
@@ -119,33 +124,49 @@ def test_get_reboot_cause_dict_kernel_panic(self):
|
119 | 124 | assert reboot_cause_dict == EXPECTED_KERNEL_PANIC_REBOOT_CAUSE_DICT
|
120 | 125 |
|
121 | 126 | def test_determine_reboot_cause_hardware(self):
|
122 |
| - with mock.patch("determine_reboot_cause.determine_reboot_cause.find_proc_cmdline_reboot_cause", return_value="Unknown"): |
123 |
| - with mock.patch("determine_reboot_cause.determine_reboot_cause.find_software_reboot_cause", return_value="Power Cycle"): |
124 |
| - with mock.patch("determine_reboot_cause.determine_reboot_cause.find_hardware_reboot_cause", return_value="Unknown"): |
125 |
| - previous_reboot_cause, additional_info = determine_reboot_cause.determine_reboot_cause() |
126 |
| - assert previous_reboot_cause == "Power Cycle" |
127 |
| - assert additional_info == "N/A" |
| 127 | + with mock.patch("determine_reboot_cause.find_proc_cmdline_reboot_cause", return_value=None): |
| 128 | + with mock.patch("determine_reboot_cause.find_software_reboot_cause", return_value=REBOOT_CAUSE_UNKNOWN): |
| 129 | + with mock.patch("determine_reboot_cause.find_hardware_reboot_cause", return_value=EXPECTED_HARDWARE_REBOOT_CAUSE): |
| 130 | + previous_reboot_cause, additional_reboot_info = determine_reboot_cause.determine_reboot_cause() |
| 131 | + assert previous_reboot_cause == EXPECTED_HARDWARE_REBOOT_CAUSE |
| 132 | + assert additional_reboot_info == "N/A" |
128 | 133 |
|
129 | 134 | def test_determine_reboot_cause_software(self):
|
130 |
| - with mock.patch("determine_reboot_cause.determine_reboot_cause.find_proc_cmdline_reboot_cause", return_value="Unknown"): |
| 135 | + with mock.patch("determine_reboot_cause.determine_reboot_cause.find_proc_cmdline_reboot_cause", return_value=None): |
131 | 136 | with mock.patch("determine_reboot_cause.determine_reboot_cause.find_software_reboot_cause", return_value=EXPECTED_FIND_SOFTWARE_REBOOT_CAUSE_USER):
|
132 |
| - with mock.patch("determine_reboot_cause.determine_reboot_cause.find_hardware_reboot_cause", return_value="Unknown"): |
| 137 | + with mock.patch("determine_reboot_cause.determine_reboot_cause.find_hardware_reboot_cause", return_value=EXPECTED_NON_HARDWARE_REBOOT_CAUSE): |
133 | 138 | previous_reboot_cause, additional_info = determine_reboot_cause.determine_reboot_cause()
|
134 | 139 | assert previous_reboot_cause == EXPECTED_FIND_SOFTWARE_REBOOT_CAUSE_USER
|
135 | 140 | assert additional_info == "N/A"
|
136 | 141 |
|
137 |
| - def test_determine_reboot_cause_cmdline(self): |
| 142 | + def test_determine_reboot_cause_cmdline_software(self): |
138 | 143 | with mock.patch("determine_reboot_cause.determine_reboot_cause.find_proc_cmdline_reboot_cause", return_value=EXPECTED_PARSE_WARMFAST_REBOOT_FROM_PROC_CMDLINE):
|
139 | 144 | with mock.patch("determine_reboot_cause.determine_reboot_cause.find_software_reboot_cause", return_value=EXPECTED_FIND_SOFTWARE_REBOOT_CAUSE_USER):
|
140 |
| - with mock.patch("determine_reboot_cause.determine_reboot_cause.find_hardware_reboot_cause", return_value="Unknown"): |
| 145 | + with mock.patch("determine_reboot_cause.determine_reboot_cause.find_hardware_reboot_cause", return_value=EXPECTED_NON_HARDWARE_REBOOT_CAUSE): |
141 | 146 | previous_reboot_cause, additional_info = determine_reboot_cause.determine_reboot_cause()
|
142 | 147 | assert previous_reboot_cause == EXPECTED_FIND_SOFTWARE_REBOOT_CAUSE_USER
|
143 | 148 | assert additional_info == "N/A"
|
144 | 149 |
|
| 150 | + def test_determine_reboot_cause_cmdline_no_software(self): |
| 151 | + with mock.patch("determine_reboot_cause.determine_reboot_cause.find_proc_cmdline_reboot_cause", return_value=EXPECTED_PARSE_WARMFAST_REBOOT_FROM_PROC_CMDLINE): |
| 152 | + with mock.patch("determine_reboot_cause.determine_reboot_cause.find_software_reboot_cause", return_value=REBOOT_CAUSE_UNKNOWN): |
| 153 | + with mock.patch("determine_reboot_cause.determine_reboot_cause.find_hardware_reboot_cause", return_value=EXPECTED_NON_HARDWARE_REBOOT_CAUSE): |
| 154 | + previous_reboot_cause, additional_info = determine_reboot_cause.determine_reboot_cause() |
| 155 | + assert previous_reboot_cause == EXPECTED_PARSE_WARMFAST_REBOOT_FROM_PROC_CMDLINE |
| 156 | + assert additional_info == "N/A" |
| 157 | + |
145 | 158 | def test_determine_reboot_cause_cmdline_hardware(self):
|
146 | 159 | with mock.patch("determine_reboot_cause.determine_reboot_cause.find_proc_cmdline_reboot_cause", return_value=EXPECTED_PARSE_WARMFAST_REBOOT_FROM_PROC_CMDLINE):
|
147 |
| - with mock.patch("determine_reboot_cause.determine_reboot_cause.find_software_reboot_cause", return_value=EXPECTED_FIND_SOFTWARE_REBOOT_CAUSE_USER): |
148 |
| - with mock.patch("determine_reboot_cause.determine_reboot_cause.find_hardware_reboot_cause", return_value=REBOOT_CAUSE_WATCHDOG): |
| 160 | + with mock.patch("determine_reboot_cause.determine_reboot_cause.find_software_reboot_cause", return_value=REBOOT_CAUSE_UNKNOWN): |
| 161 | + with mock.patch("determine_reboot_cause.determine_reboot_cause.find_hardware_reboot_cause", return_value=EXPECTED_HARDWARE_REBOOT_CAUSE): |
| 162 | + previous_reboot_cause, additional_info = determine_reboot_cause.determine_reboot_cause() |
| 163 | + assert previous_reboot_cause == EXPECTED_HARDWARE_REBOOT_CAUSE |
| 164 | + assert additional_info == EXPECTED_PARSE_WARMFAST_REBOOT_FROM_PROC_CMDLINE |
| 165 | + |
| 166 | + def test_determine_reboot_cause_software_hardware(self): |
| 167 | + with mock.patch("determine_reboot_cause.find_proc_cmdline_reboot_cause", return_value=EXPECTED_PARSE_WARMFAST_REBOOT_FROM_PROC_CMDLINE): |
| 168 | + with mock.patch("determine_reboot_cause.find_software_reboot_cause", return_value=EXPECTED_FIND_SOFTWARE_REBOOT_CAUSE_USER): |
| 169 | + with mock.patch("determine_reboot_cause.find_hardware_reboot_cause", return_value=EXPECTED_HARDWARE_REBOOT_CAUSE): |
149 | 170 | previous_reboot_cause, additional_info = determine_reboot_cause.determine_reboot_cause()
|
150 | 171 | assert previous_reboot_cause == REBOOT_CAUSE_WATCHDOG
|
151 | 172 | assert additional_info == EXPECTED_FIND_SOFTWARE_REBOOT_CAUSE_USER
|
|
0 commit comments