Skip to content

Commit

Permalink
Use constants for repeated reboot reasons
Browse files Browse the repository at this point in the history
  • Loading branch information
themylogin committed Sep 20, 2024
1 parent dd54d49 commit 2201373
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
10 changes: 7 additions & 3 deletions src/middlewared/middlewared/plugins/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
TRUENAS_ADMIN_KEYS_UPLOADED = '/data/truenas_admin_authorized_keys_uploaded'
ROOT_KEYS_UPLOADED = '/data/root_authorized_keys_uploaded'
DATABASE_NAME = os.path.basename(FREENAS_DATABASE)
CONFIGURATION_UPLOAD_REBOOT_REASON = 'Configuration upload'
CONFIGURATION_RESET_REBOOT_REASON = 'Configuration reset'


class ConfigService(Service):
Expand Down Expand Up @@ -184,7 +186,7 @@ def upload_impl(self, file_or_tar, is_tar_file=False):
'failover.call_remote', 'core.call_hook', ['config.on_upload', [UPLOADED_DB_PATH]]
)
self.middleware.run_coroutine(
self.middleware.call('failover.call_remote', 'system.reboot', 'Configuration upload'),
self.middleware.call('failover.call_remote', 'system.reboot', CONFIGURATION_UPLOAD_REBOOT_REASON),
wait=False,
)
except Exception as e:
Expand Down Expand Up @@ -229,7 +231,9 @@ def reset(self, app, job, options):

if options['reboot']:
self.middleware.run_coroutine(
self.middleware.call('failover.call_remote', 'system.reboot', 'Configuration upload'),
self.middleware.call(
'failover.call_remote', 'system.reboot', CONFIGURATION_UPLOAD_REBOOT_REASON,
),
wait=False,
)
except Exception as e:
Expand All @@ -245,7 +249,7 @@ def reset(self, app, job, options):
if options['reboot']:
job.set_progress(95, 'Will reboot in 10 seconds')
self.middleware.run_coroutine(
self.middleware.call('system.reboot', 'Configuration reset', {'delay': 10}, app=app),
self.middleware.call('system.reboot', CONFIGURATION_RESET_REBOOT_REASON, {'delay': 10}, app=app),
wait=False,
)

Expand Down
3 changes: 2 additions & 1 deletion src/middlewared/middlewared/plugins/failover.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
from middlewared.plugins.failover_.configure import HA_LICENSE_CACHE_KEY
from middlewared.plugins.failover_.remote import NETWORK_ERRORS
from middlewared.plugins.system.reboot import RebootReason
from middlewared.plugins.update import SYSTEM_UPGRADE_REBOOT_REASON
from middlewared.plugins.update_.install import STARTING_INSTALLER
from middlewared.plugins.update_.utils import DOWNLOAD_UPDATE_FILE
from middlewared.plugins.update_.utils_linux import mount_update
Expand Down Expand Up @@ -858,7 +859,7 @@ def callback(j, controller):
rjob.result()

self.middleware.call_sync(
'failover.call_remote', 'system.reboot', 'System upgrade', [{'delay': 5}], {'job': True},
'failover.call_remote', 'system.reboot', SYSTEM_UPGRADE_REBOOT_REASON, [{'delay': 5}], {'job': True},
)
except Exception:
raise
Expand Down
2 changes: 2 additions & 0 deletions src/middlewared/middlewared/plugins/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
import textwrap
import pathlib

SYSTEM_UPGRADE_REBOOT_REASON = 'System upgrade'


def parse_train_name(name):
split = (name + '-').split('-')
Expand Down

0 comments on commit 2201373

Please sign in to comment.