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

radosgw_zonegroup: support check mode #7506

Merged
merged 2 commits into from
Mar 16, 2024
Merged
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
31 changes: 9 additions & 22 deletions library/radosgw_zonegroup.py
Original file line number Diff line number Diff line change
Expand Up @@ -343,27 +343,16 @@ def run_module():
name = module.params.get('name')
state = module.params.get('state')
endpoints = module.params.get('endpoints')
master = str(module.params.get('master')).lower()

if module.check_mode:
module.exit_json(
changed=False,
stdout='',
stderr='',
rc=0,
start='',
end='',
delta='',
)
master = module.params.get('master')

startd = datetime.datetime.now()
changed = False

# will return either the image name or None
container_image = is_containerized()

rc, cmd, out, err = exec_commands(module, get_zonegroup(module, container_image=container_image)) # noqa: E501
if state == "present":
rc, cmd, out, err = exec_commands(module, get_zonegroup(module, container_image=container_image)) # noqa: E501
if rc == 0:
zonegroup = json.loads(out)
_rc, _cmd, _out, _err = exec_commands(module, get_realm(module, container_image=container_image)) # noqa: E501
Expand All @@ -372,33 +361,31 @@ def run_module():
realm = json.loads(_out)
current = {
'endpoints': zonegroup['endpoints'],
'master': zonegroup.get('is_master', 'false'),
'master': zonegroup.get('is_master', False),
'realm_id': zonegroup['realm_id']
}
asked = {
'endpoints': endpoints,
'master': master,
'realm_id': realm['id']
}
if current != asked:
changed = current != asked
if changed and not module.check_mode:
rc, cmd, out, err = exec_commands(module, modify_zonegroup(module, container_image=container_image)) # noqa: E501
changed = True
else:
rc, cmd, out, err = exec_commands(module, create_zonegroup(module, container_image=container_image)) # noqa: E501
if not module.check_mode:
rc, cmd, out, err = exec_commands(module, create_zonegroup(module, container_image=container_image)) # noqa: E501
changed = True

elif state == "absent":
rc, cmd, out, err = exec_commands(module, get_zonegroup(module, container_image=container_image)) # noqa: E501
if rc == 0:
rc, cmd, out, err = exec_commands(module, remove_zonegroup(module, container_image=container_image)) # noqa: E501
if not module.check_mode:
rc, cmd, out, err = exec_commands(module, remove_zonegroup(module, container_image=container_image)) # noqa: E501
changed = True
else:
rc = 0
out = "Zonegroup {} doesn't exist".format(name)

elif state == "info":
rc, cmd, out, err = exec_commands(module, get_zonegroup(module, container_image=container_image)) # noqa: E501

exit_module(module=module, out=out, rc=rc, cmd=cmd, err=err, startd=startd, changed=changed) # noqa: E501


Expand Down
Loading