[stable-2.7] openstack: fix parameter handling when cloud provided as dict (#42899) (#49745)

* [stable-2.7] openstack: fix parameter handling when cloud provided as dict (#42899)

* openstack: fix parameter handling when cloud provided as dict

If a cloud is provided as dictionary:

 * Do not assert that 'interface' parameter is None. Instead,
   assert that it is 'public'.
 * Assert that 'auth_type' parameter is not set.

Fixes #42858

* os_user: Include domain parameter in user lookup

If a "domain" parameter is provided, use it in looking up
whether the user already exists.

Fixes #42901

* os_user: Include domain parameter in user deletion

If a "domain" parameter is provided, use it in deleting
the user also.

Fixes #42901
(cherry picked from commit e25dac9)

Co-authored-by: Carsten Koester <carsten@ckoester.net>

* Add changelog for openstack fixes
This commit is contained in:
Toshio Kuratomi 2018-12-10 12:33:34 -08:00 committed by GitHub
parent 87e01a0640
commit 012d38eae6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 19 additions and 6 deletions

View file

@ -0,0 +1,8 @@
---
bugfixes:
- openstack - fix parameter handling when cloud provided as dict
https://github.com/ansible/ansible/issues/42858
- os_user - Include domain parameter in user lookup
https://github.com/ansible/ansible/issues/42901
- os_user - Include domain parameter in user deletion
https://github.com/ansible/ansible/issues/42901

View file

@ -134,11 +134,12 @@ def openstack_cloud_from_module(module, min_version='0.12.0'):
" excluded.") " excluded.")
for param in ( for param in (
'auth', 'region_name', 'verify', 'auth', 'region_name', 'verify',
'cacert', 'key', 'api_timeout', 'interface'): 'cacert', 'key', 'api_timeout', 'auth_type'):
if module.params[param] is not None: if module.params[param] is not None:
module.fail_json(msg=fail_message.format(param=param)) module.fail_json(msg=fail_message.format(param=param))
if module.params['auth_type'] != 'password': # For 'interface' parameter, fail if we receive a non-default value
module.fail_json(msg=fail_message.format(param='auth_type')) if module.params['interface'] != 'public':
module.fail_json(msg=fail_message.format(param='interface'))
return sdk, sdk.connect(**cloud_config) return sdk, sdk.connect(**cloud_config)
else: else:
return sdk, sdk.connect( return sdk, sdk.connect(

View file

@ -201,11 +201,12 @@ def main():
sdk, cloud = openstack_cloud_from_module(module) sdk, cloud = openstack_cloud_from_module(module)
try: try:
user = cloud.get_user(name)
domain_id = None domain_id = None
if domain: if domain:
domain_id = _get_domain_id(cloud, domain) domain_id = _get_domain_id(cloud, domain)
user = cloud.get_user(name, domain_id=domain_id)
else:
user = cloud.get_user(name)
if state == 'present': if state == 'present':
if update_password in ('always', 'on_create'): if update_password in ('always', 'on_create'):
@ -271,7 +272,10 @@ def main():
if user is None: if user is None:
changed = False changed = False
else: else:
cloud.delete_user(user['id']) if domain:
cloud.delete_user(user['id'], domain_id=domain_id)
else:
cloud.delete_user(user['id'])
changed = True changed = True
module.exit_json(changed=changed) module.exit_json(changed=changed)