Skip to content

Commit

Permalink
SnapshotSchedule - wait on create and delete
Browse files Browse the repository at this point in the history
See https://github.com/ScaleComputing/HyperCoreAnsibleCollection/actions/runs/6334360083/job/17229911477#step:8:62
A guess - we tried to use SnapshotSchedule before it was fully created.

Signed-off-by: Justin Cinkelj <[email protected]>
  • Loading branch information
justinc1 committed Sep 28, 2023
1 parent 77a0ce1 commit 7efec74
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
9 changes: 7 additions & 2 deletions plugins/modules/snapshot_schedule.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,13 @@
"""

from ansible.module_utils.basic import AnsibleModule
import time

from ..module_utils import arguments, errors
from ..module_utils.client import Client
from ..module_utils.rest_client import RestClient
from ..module_utils.snapshot_schedule import SnapshotSchedule
from ..module_utils.task_tag import TaskTag


def ensure_present(module, rest_client):
Expand Down Expand Up @@ -160,11 +162,12 @@ def ensure_present(module, rest_client):
else:
before = None
new_snapshot_schedule = SnapshotSchedule.from_ansible(module.params)
rest_client.create_record(
task = rest_client.create_record(
"/rest/v1/VirDomainSnapshotSchedule",
new_snapshot_schedule.create_post_payload(),
module.check_mode,
)
TaskTag.wait_task(rest_client, task)
changed = True
after = SnapshotSchedule.get_by_name(module.params, rest_client).to_ansible()
return changed, [after], dict(before=before, after=after)
Expand All @@ -174,12 +177,14 @@ def ensure_absent(module, rest_client):
snapshot_schedule = SnapshotSchedule.get_by_name(module.params, rest_client)
if snapshot_schedule:
# No task tag is returned with DELETE on "/rest/v1/VirDomainSnapshotSchedule/{uuid}"
rest_client.delete_record(
task = rest_client.delete_record(
"{0}/{1}".format(
"/rest/v1/VirDomainSnapshotSchedule", snapshot_schedule.uuid
),
module.check_mode,
)
if task["taskTag"] == "":
time.sleep(1)
output = snapshot_schedule.to_ansible()
return True, [output], dict(before=output, after=None)
return False, [], dict()
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/plugins/modules/test_snapshot_schedule.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def test_ensure_absent(self, create_module, rest_client):
name="SnapshotSchedule-test-name",
rrules=[],
)
rest_client.delete_record.return_value = None
rest_client.delete_record.return_value = dict(taskTag="", createdUUID="")
result = snapshot_schedule.ensure_absent(module, rest_client)
assert result == (
True,
Expand Down

0 comments on commit 7efec74

Please sign in to comment.