Skip to content

Commit

Permalink
deny system-actions if upgrade is being performed (fix #97)
Browse files Browse the repository at this point in the history
  • Loading branch information
ansibleguy committed Oct 7, 2024
1 parent bfab9d8 commit adc5e23
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
14 changes: 9 additions & 5 deletions plugins/module_utils/helper/system.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,14 @@ def wait_for_response(module: AnsibleModule) -> bool:
raise TimeoutError


def get_upgrade_status(s: Session) -> dict:
return s.get({
'command': 'upgradestatus',
'module': 'core',
'controller': 'firmware',
})


def wait_for_update(module: AnsibleModule, s: Session) -> bool:
timeout = time() + module.params['wait_timeout']

Expand All @@ -65,11 +73,7 @@ def wait_for_update(module: AnsibleModule, s: Session) -> bool:
poll_interval_start = time()

try:
result = s.get({
'command': 'upgradestatus',
'module': 'core',
'controller': 'firmware',
})
result = get_upgrade_status(s)
status = result['status']

_wait_msg(module, f"Got response: {status}")
Expand Down
8 changes: 7 additions & 1 deletion plugins/modules/system.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from ansible_collections.ansibleguy.opnsense.plugins.module_utils.base.api import Session
from ansible_collections.ansibleguy.opnsense.plugins.module_utils.defaults.main import OPN_MOD_ARGS
from ansible_collections.ansibleguy.opnsense.plugins.module_utils.helper.system import wait_for_response, \
wait_for_update
wait_for_update, get_upgrade_status

except MODULE_EXCEPTIONS:
module_dependency_error()
Expand Down Expand Up @@ -59,6 +59,12 @@ def run_module():

if not module.check_mode:
with Session(module=module) as s:
upgrade_status = get_upgrade_status(s)
if upgrade_status['status'] != 'done':
module.fail_json(
f'System may be upgrading! System-actions are currently blocked! Details: {upgrade_status}'
)

s.post({
'command': module.params['action'],
'module': 'core',
Expand Down

0 comments on commit adc5e23

Please sign in to comment.