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

Revert "Modified reboot action and playbook" #427

Merged
merged 1 commit into from
Mar 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 8 additions & 14 deletions playbooks/demo_reboot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,16 @@
post_reboot_delay_v: 0
reboot_timeout_v: 0
test_command_v: ""
original: 1
collections:
- ibm.power_aix
tasks:

# - name: "reboot the machine"
# reboot:
# pre_reboot_delay: "{{ pre_reboot_delay_v }}"
# post_reboot_delay: "{{ post_reboot_delay_v }}"
# reboot_timeout: "{{ reboot_timeout_v }}"
# test_command: "{{ test_command_v }}"
# register: reboot_result
- name: "reboot the machine"
reboot:
pre_reboot_delay: "{{ pre_reboot_delay_v }}"
post_reboot_delay: "{{ post_reboot_delay_v }}"
reboot_timeout: "{{ reboot_timeout_v }}"
test_command: "{{ test_command_v }}"
register: reboot_result

# - debug: var=reboot_result

- name: "Print statement to not use this playbook"
ansible.builtin.fail:
msg: "Please use demo_reboot_workaround.yml"
when: "{{ original }}"
- debug: var=reboot_result
41 changes: 0 additions & 41 deletions playbooks/demo_reboot_workaround.yml

This file was deleted.

102 changes: 51 additions & 51 deletions plugins/action/reboot.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,51 +69,51 @@ def perform_reboot(self, pre_reboot_delay):

return reboot_result

# def validate_reboot(self, test_command, reboot_timeout=None, action_kwargs=None):
# self._display.vvv('Validating reboot....')
# result = {}

# try:
# if reboot_timeout is None:
# reboot_timeout = 300

# self.do_until_success_or_timeout(
# action_desc="post-reboot test command",
# reboot_timeout=reboot_timeout,
# test_command=test_command,
# action_kwargs=action_kwargs)

# result['rebooted'] = True
# result['changed'] = True
# result['msg'] = "System has been rebooted SUCCESSFULLY"

# except TimedOutException:
# result['failed'] = True
# result['rebooted'] = True
# result['msg'] = "Reboot Validation failed due to timeout"
# return result

# return result

# def do_until_success_or_timeout(self, action_desc, reboot_timeout, test_command, action_kwargs=None):
# max_end_time = datetime.utcnow() + timedelta(seconds=reboot_timeout)
# if action_kwargs is None:
# action_kwargs = {}
# if test_command is None:
# test_command = 'whoami'

# while datetime.utcnow() < max_end_time:
# try:
# result = self._low_level_execute_command(test_command, sudoable=True)
# if result['rc'] == 0:
# return
# except Exception as e:
# if isinstance(e, AnsibleConnectionFailure):
# try:
# self._connection.reset()
# except AttributeError:
# pass
# raise TimedOutException("Connection reset failed while validating the reboot.")
def validate_reboot(self, test_command, reboot_timeout=None, action_kwargs=None):
self._display.vvv('Validating reboot....')
result = {}

try:
if reboot_timeout is None:
reboot_timeout = 300

self.do_until_success_or_timeout(
action_desc="post-reboot test command",
reboot_timeout=reboot_timeout,
test_command=test_command,
action_kwargs=action_kwargs)

result['rebooted'] = True
result['changed'] = True
result['msg'] = "System has been rebooted SUCCESSFULLY"

except TimedOutException:
result['failed'] = True
result['rebooted'] = True
result['msg'] = "Reboot Validation failed due to timeout"
return result

return result

def do_until_success_or_timeout(self, action_desc, reboot_timeout, test_command, action_kwargs=None):
max_end_time = datetime.utcnow() + timedelta(seconds=reboot_timeout)
if action_kwargs is None:
action_kwargs = {}
if test_command is None:
test_command = 'whoami'

while datetime.utcnow() < max_end_time:
try:
result = self._low_level_execute_command(test_command, sudoable=True)
if result['rc'] == 0:
return
except Exception as e:
if isinstance(e, AnsibleConnectionFailure):
try:
self._connection.reset()
except AttributeError:
pass
raise TimedOutException("Connection reset failed while validating the reboot.")

def run(self, tmp=None, task_vars=None):
self._supports_async = True
Expand Down Expand Up @@ -146,13 +146,13 @@ def run(self, tmp=None, task_vars=None):
result['elapsed'] = str(elapsed.seconds) + ' sec'
return result

# if self.post_reboot_delay != 0:
# self._display.vvv("waiting for post reboot delay of {delay} seconds".format(delay=self.post_reboot_delay))
# time.sleep(self.post_reboot_delay)
if self.post_reboot_delay != 0:
self._display.vvv("waiting for post reboot delay of {delay} seconds".format(delay=self.post_reboot_delay))
time.sleep(self.post_reboot_delay)

# result = self.validate_reboot(test_command, reboot_timeout, action_kwargs=None)
result = self.validate_reboot(test_command, reboot_timeout, action_kwargs=None)

# elapsed = datetime.utcnow() - start
# result['elapsed'] = str(elapsed.seconds) + ' sec'
elapsed = datetime.utcnow() - start
result['elapsed'] = str(elapsed.seconds) + ' sec'

return result
Loading