rockstor / rockstor-core

Linux/BTRFS based Network Attached Storage(NAS)
http://rockstor.com/docs/contribute_section.html
GNU General Public License v3.0
553 stars 137 forks source link

Scheduled shutdown task fails due to type issue #2805 #2812

Closed phillxnet closed 6 months ago

phillxnet commented 6 months ago

Add type hints to the shutdown/reboot run_command() wrapper parameters in osi.py, and to command.py's use of these wrappers. Includes fix for legacy inadvertent integer in delay during scheduled task calls.

Fixes #2805

phillxnet commented 6 months ago

Testing

Before

Before the proposed changes we have (line numbers approximate):

[22/Mar/2024 11:30:03] ERROR [storageadmin.util:45] Exception: Failed to shutdown the system due to a low level error: (Exception while running command(['/sbin/shutdown', '-h', 3]): expected str, bytes or os.PathLike object, not int).
Traceback (most recent call last):
  File "/opt/rockstor/src/rockstor/system/osi.py", line 237, in run_command
    p = subprocess.Popen(
        ^^^^^^^^^^^^^^^^^
  File "/usr/lib64/python3.11/subprocess.py", line 1026, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "/usr/lib64/python3.11/subprocess.py", line 1883, in _execute_child
    self.pid = _fork_exec(
               ^^^^^^^^^^^
TypeError: expected str, bytes or os.PathLike object, not int

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/opt/rockstor/src/rockstor/storageadmin/views/command.py", line 316, in post
    system_shutdown(delay)
  File "/opt/rockstor/src/rockstor/system/osi.py", line 1372, in system_shutdown
    o, e, rc = run_command(cmd)
               ^^^^^^^^^^^^^^^^
  File "/opt/rockstor/src/rockstor/system/osi.py", line 254, in run_command
    raise Exception("Exception while running command({}): {}".format(cmd, e))
Exception: Exception while running command(['/sbin/shutdown', '-h', 3]): expected str, bytes or os.PathLike object, not int

After

Using an rpm build with this PR's associated changes (against current testing branch, with the following squecheduled task:

Task name Type Frequency Execution time window Enabled Last run Actions
pr2812 shutdown 12:05 on Fri Run always      

We see the following in an ssh terminal:

Broadcast message from root@rleap15-5 (Fri 2024-03-22 12:05:03 WET):

The system is going down for poweroff at Fri 2024-03-22 12:08:03 WET!

Broadcast message from root@rleap15-5 (Fri 2024-03-22 12:06:03 WET):

The system is going down for poweroff at Fri 2024-03-22 12:08:03 WET!

Broadcast message from root@rleap15-5 (Fri 2024-03-22 12:07:03 WET):

The system is going down for poweroff at Fri 2024-03-22 12:08:03 WET!

Broadcast message from root@rleap15-5 (Fri 2024-03-22 12:08:03 WET):

The system is going down for poweroff NOW!

Connection to rleap15-5 closed by remote host.
Connection to rleap15-5 closed.

On next boot-up we have the following scheduled task report:

ID Status Start Time End Time
1 finished March 22nd 2024, 12:05:00 pm March 22nd 2024, 12:08:00 pm
phillxnet commented 6 months ago

Scheduled Reboot test

Again with the custom rpm built to test these modifications:

Task name Type Frequency Execution time window Enabled Last run Actions
pr2812-reboot reboot 12:20 on Fri Run always      

Terminal output:

Broadcast message from root@rleap15-5 (Fri 2024-03-22 12:20:03 WET):

The system is going down for reboot at Fri 2024-03-22 12:23:03 WET!

Broadcast message from root@rleap15-5 (Fri 2024-03-22 12:21:03 WET):

The system is going down for reboot at Fri 2024-03-22 12:23:03 WET!

Broadcast message from root@rleap15-5 (Fri 2024-03-22 12:22:03 WET):

The system is going down for reboot at Fri 2024-03-22 12:23:03 WET!

Broadcast message from root@rleap15-5 (Fri 2024-03-22 12:23:03 WET):

The system is going down for reboot NOW!

Connection to rleap15-5 closed by remote host.
Connection to rleap15-5 closed.

Re-visiting the Web-UI post scheduled reboot completion and we have the task details as follows:

Task name Type Frequency Execution time window Enabled Last run Actions
pr2812-reboot reboot 12:20 on Fri Run always   2 minutes ago  

With the details (2 minutes ago link) for this task as follows:

ID Status Start Time End Time
2 finished March 22nd 2024, 12:20:00 pm March 22nd 2024, 12:23:00 pm
phillxnet commented 6 months ago

@FroggyFlox & @Hooverdan96 I'll go ahead and merge this as it's a spin-off of sorts to the ongoing development in draft PR:

[t] Add Group with custom GID fails with type error #2807 #2811

Where I'm also adding some more type-hints and type casting. And I'd like to re-base that work on these changes. And from the testing comments above, and rpmbuild tests, these changes look to be doing what we intend again.