mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-22 21:00:22 -07:00
Various small fixes to MSC modules and tests (#48417)
This commit is contained in:
parent
475844d1ae
commit
24d7b4a660
8 changed files with 76 additions and 61 deletions
|
@ -186,9 +186,9 @@ class MSCModule(object):
|
|||
except:
|
||||
payload = json.loads(info['body'])
|
||||
if 'code' in payload:
|
||||
self.fail_json(msg='MSC Error {code}: {message} [{info}]'.format(**payload), payload=data)
|
||||
self.fail_json(msg='MSC Error {code}: {message}'.format(**payload), data=data, info=info, payload=payload)
|
||||
else:
|
||||
self.fail_json(msg='MSC Error:'.format(**payload), info=info, output=output)
|
||||
self.fail_json(msg='MSC Error:'.format(**payload), data=data, info=info, payload=payload)
|
||||
|
||||
return {}
|
||||
|
||||
|
@ -213,18 +213,20 @@ class MSCModule(object):
|
|||
self.fail_json(msg='More than one object matches unique filter: {0}'.format(kwargs))
|
||||
return objs[0]
|
||||
|
||||
def sanitize(self, updates, collate=False):
|
||||
def sanitize(self, updates, collate=False, required_keys=None):
|
||||
if required_keys is None:
|
||||
required_keys = []
|
||||
self.proposed = deepcopy(self.existing)
|
||||
self.sent = deepcopy(self.existing)
|
||||
|
||||
# Clean up self.sent
|
||||
for key in updates:
|
||||
# Always retain 'id'
|
||||
if key in ('id'):
|
||||
if key in required_keys:
|
||||
pass
|
||||
|
||||
# Remove unspecified values
|
||||
elif updates[key] is None:
|
||||
elif not collate and updates[key] is None:
|
||||
if key in self.existing:
|
||||
del(self.sent[key])
|
||||
continue
|
||||
|
@ -265,8 +267,8 @@ class MSCModule(object):
|
|||
|
||||
if self.module._diff:
|
||||
self.result['diff'] = dict(
|
||||
before=self.existing,
|
||||
after=self.sent,
|
||||
before=self.previous,
|
||||
after=self.existing,
|
||||
)
|
||||
|
||||
self.result.update(**kwargs)
|
||||
|
|
|
@ -29,9 +29,6 @@ options:
|
|||
- The name of the label.
|
||||
required: yes
|
||||
aliases: [ label_name, name ]
|
||||
display_name:
|
||||
description:
|
||||
- The name of the label displayed in the web UI.
|
||||
type:
|
||||
description:
|
||||
- The type of the label.
|
||||
|
@ -99,7 +96,6 @@ def main():
|
|||
argument_spec.update(
|
||||
label=dict(type='str', required=False, aliases=['name', 'label_name']),
|
||||
label_id=dict(type='str', required=False),
|
||||
display_name=dict(type='str'),
|
||||
type=dict(type='str', default='site', choices=['site']),
|
||||
state=dict(type='str', default='present', choices=['absent', 'present', 'query']),
|
||||
)
|
||||
|
@ -116,7 +112,6 @@ def main():
|
|||
label = module.params['label']
|
||||
label_id = module.params['label_id']
|
||||
label_type = module.params['type']
|
||||
display_name = module.params['display_name']
|
||||
state = module.params['state']
|
||||
|
||||
msc = MSCModule(module)
|
||||
|
@ -158,7 +153,7 @@ def main():
|
|||
|
||||
msc.sanitize(dict(
|
||||
id=label_id,
|
||||
displayName=display_name,
|
||||
displayName=label,
|
||||
type=label_type,
|
||||
), collate=True)
|
||||
|
||||
|
|
|
@ -23,20 +23,28 @@ options:
|
|||
apic_password:
|
||||
description:
|
||||
- The password for the APICs.
|
||||
type: str
|
||||
required: yes
|
||||
apic_site_id:
|
||||
description:
|
||||
- The site ID of the APICs.
|
||||
type: str
|
||||
required: yes
|
||||
apic_username:
|
||||
description:
|
||||
- The username for the APICs.
|
||||
type: str
|
||||
required: yes
|
||||
default: admin
|
||||
site_id:
|
||||
description:
|
||||
- The ID of the site.
|
||||
type: str
|
||||
required: yes
|
||||
site:
|
||||
description:
|
||||
- The name of the site.
|
||||
type: str
|
||||
required: yes
|
||||
aliases: [ name, site_name ]
|
||||
labels:
|
||||
|
@ -51,6 +59,7 @@ options:
|
|||
description:
|
||||
- Use C(present) or C(absent) for adding or removing.
|
||||
- Use C(query) for listing an object or multiple objects.
|
||||
type: str
|
||||
choices: [ absent, present, query ]
|
||||
default: present
|
||||
extends_documentation_fragment: msc
|
||||
|
@ -122,7 +131,7 @@ def main():
|
|||
supports_check_mode=True,
|
||||
required_if=[
|
||||
['state', 'absent', ['site']],
|
||||
['state', 'present', ['site']],
|
||||
['state', 'present', ['apic_site_id', 'site']],
|
||||
],
|
||||
)
|
||||
|
||||
|
@ -178,7 +187,7 @@ def main():
|
|||
urls=urls,
|
||||
username=apic_username,
|
||||
password=apic_password,
|
||||
))
|
||||
), collate=True)
|
||||
|
||||
if msc.existing:
|
||||
if not issubset(msc.sent, msc.existing):
|
||||
|
|
|
@ -23,22 +23,28 @@ options:
|
|||
tenant_id:
|
||||
description:
|
||||
- The ID of the tenant.
|
||||
type: str
|
||||
required: yes
|
||||
tenant:
|
||||
description:
|
||||
- The name of the tenant.
|
||||
type: str
|
||||
required: yes
|
||||
aliases: [ name, tenant_name ]
|
||||
display_name:
|
||||
description:
|
||||
- The name of the tenant to be displayed in the web UI.
|
||||
type: str
|
||||
required: yes
|
||||
description:
|
||||
description:
|
||||
- The description for this tenant.
|
||||
type: str
|
||||
state:
|
||||
description:
|
||||
- Use C(present) or C(absent) for adding or removing.
|
||||
- Use C(query) for listing an object or multiple objects.
|
||||
type: str
|
||||
choices: [ absent, present, query ]
|
||||
default: present
|
||||
extends_documentation_fragment: msc
|
||||
|
@ -52,7 +58,8 @@ EXAMPLES = r'''
|
|||
password: SomeSecretPassword
|
||||
tenant: north_europe
|
||||
tenant_id: 101
|
||||
description: North European Datacenter
|
||||
display_name: North European Datacenter
|
||||
description: This tenant manages the NEDC environment.
|
||||
state: present
|
||||
delegate_to: localhost
|
||||
|
||||
|
@ -161,7 +168,7 @@ def main():
|
|||
displayName=display_name,
|
||||
siteAssociations=[],
|
||||
userAssociations=[dict(userId="0000ffff0000000000000020")],
|
||||
))
|
||||
), collate=True)
|
||||
|
||||
if msc.existing:
|
||||
if not issubset(msc.sent, msc.existing):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue