Skip to content
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

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

Conversation

phillxnet
Copy link
Member

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

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.
@phillxnet
Copy link
Member Author

phillxnet commented Mar 22, 2024

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
Copy link
Member Author

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
Copy link
Member Author

phillxnet commented Mar 22, 2024

@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.

@phillxnet phillxnet merged commit 5f02795 into rockstor:testing Mar 22, 2024
@phillxnet phillxnet deleted the 2805-Scheduled-shutdown-task-fails-due-to-type-issue branch March 22, 2024 13:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant