Meraki: Improved integration testing and results (#39761)
* Improved integration testing and results - Added get_org() function to return data for single org - Added a lot of new integration tests - Changed result now shows, still probably could be better * Fix formatting errors for PEP8
This commit is contained in:
parent
b8a93c12e2
commit
aa8aee538e
2 changed files with 110 additions and 26 deletions
|
@ -98,6 +98,15 @@ from ansible.module_utils._text import to_native
|
||||||
from ansible.module_utils.network.meraki.meraki import MerakiModule, meraki_argument_spec
|
from ansible.module_utils.network.meraki.meraki import MerakiModule, meraki_argument_spec
|
||||||
|
|
||||||
|
|
||||||
|
def get_org(meraki, org_id, data):
|
||||||
|
# meraki.fail_json(msg=str(org_id), data=data, oid0=data[0]['id'], oid1=data[1]['id'])
|
||||||
|
for o in data:
|
||||||
|
# meraki.fail_json(msg='o', data=o['id'], type=str(type(o['id'])))
|
||||||
|
if o['id'] == org_id:
|
||||||
|
return o
|
||||||
|
return -1
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
|
||||||
# define the available arguments/parameters that a user can pass to
|
# define the available arguments/parameters that a user can pass to
|
||||||
|
@ -164,7 +173,6 @@ def main():
|
||||||
if o['id'] == meraki.params['org_id']:
|
if o['id'] == meraki.params['org_id']:
|
||||||
meraki.result['data'] = o
|
meraki.result['data'] = o
|
||||||
else: # Query all organizations, no matter what
|
else: # Query all organizations, no matter what
|
||||||
orgs = meraki.get_orgs()
|
|
||||||
meraki.result['data'] = orgs
|
meraki.result['data'] = orgs
|
||||||
elif meraki.params['state'] == 'present':
|
elif meraki.params['state'] == 'present':
|
||||||
if meraki.params['clone']: # Cloning
|
if meraki.params['clone']: # Cloning
|
||||||
|
@ -177,6 +185,7 @@ def main():
|
||||||
),
|
),
|
||||||
payload=json.dumps(payload),
|
payload=json.dumps(payload),
|
||||||
method='POST'))
|
method='POST'))
|
||||||
|
meraki.result['changed'] = True
|
||||||
elif not meraki.params['org_id'] and meraki.params['org_name']: # Create new organization
|
elif not meraki.params['org_id'] and meraki.params['org_name']: # Create new organization
|
||||||
payload = {'name': meraki.params['org_name']}
|
payload = {'name': meraki.params['org_name']}
|
||||||
meraki.result['data'] = json.loads(
|
meraki.result['data'] = json.loads(
|
||||||
|
@ -184,10 +193,17 @@ def main():
|
||||||
meraki.construct_path('create'),
|
meraki.construct_path('create'),
|
||||||
method='POST',
|
method='POST',
|
||||||
payload=json.dumps(payload)))
|
payload=json.dumps(payload)))
|
||||||
|
meraki.result['changed'] = True
|
||||||
elif meraki.params['org_id'] and meraki.params['org_name']: # Update an existing organization
|
elif meraki.params['org_id'] and meraki.params['org_name']: # Update an existing organization
|
||||||
payload = {'name': meraki.params['org_name'],
|
payload = {'name': meraki.params['org_name'],
|
||||||
'id': meraki.params['org_id'],
|
'id': meraki.params['org_id'],
|
||||||
}
|
}
|
||||||
|
if meraki.is_update_required(
|
||||||
|
get_org(
|
||||||
|
meraki,
|
||||||
|
meraki.params['org_id'],
|
||||||
|
orgs),
|
||||||
|
payload):
|
||||||
meraki.result['data'] = json.loads(
|
meraki.result['data'] = json.loads(
|
||||||
meraki.request(
|
meraki.request(
|
||||||
meraki.construct_path(
|
meraki.construct_path(
|
||||||
|
@ -196,7 +212,7 @@ def main():
|
||||||
),
|
),
|
||||||
method='PUT',
|
method='PUT',
|
||||||
payload=json.dumps(payload)))
|
payload=json.dumps(payload)))
|
||||||
|
meraki.result['changed'] = True
|
||||||
# in the event of a successful module execution, you will want to
|
# in the event of a successful module execution, you will want to
|
||||||
# simple AnsibleModule.exit_json(), passing the key/value results
|
# simple AnsibleModule.exit_json(), passing the key/value results
|
||||||
meraki.exit_json(**meraki.result)
|
meraki.exit_json(**meraki.result)
|
||||||
|
|
|
@ -8,6 +8,33 @@
|
||||||
msg: Please define an API key
|
msg: Please define an API key
|
||||||
when: auth_key is not defined
|
when: auth_key is not defined
|
||||||
|
|
||||||
|
- name: Use an invalid domain
|
||||||
|
meraki_organization:
|
||||||
|
auth_key: '{{ auth_key }}'
|
||||||
|
host: marrrraki.com
|
||||||
|
state: present
|
||||||
|
org_name: IntTestOrg
|
||||||
|
output_level: debug
|
||||||
|
delegate_to: localhost
|
||||||
|
register: invalid_domain
|
||||||
|
ignore_errors: yes
|
||||||
|
|
||||||
|
- name: Disable HTTP
|
||||||
|
meraki_organization:
|
||||||
|
auth_key: '{{ auth_key }}'
|
||||||
|
use_https: false
|
||||||
|
state: query
|
||||||
|
output_level: debug
|
||||||
|
delegate_to: localhost
|
||||||
|
register: http
|
||||||
|
ignore_errors: yes
|
||||||
|
|
||||||
|
- name: Connection assertions
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- '"Failed to connect to" in invalid_domain.msg'
|
||||||
|
- '"http" in http.url'
|
||||||
|
|
||||||
- name: Create a new organization named IntTestOrg
|
- name: Create a new organization named IntTestOrg
|
||||||
meraki_organization:
|
meraki_organization:
|
||||||
auth_key: '{{ auth_key }}'
|
auth_key: '{{ auth_key }}'
|
||||||
|
@ -17,6 +44,54 @@
|
||||||
delegate_to: localhost
|
delegate_to: localhost
|
||||||
register: new_org
|
register: new_org
|
||||||
|
|
||||||
|
- debug:
|
||||||
|
msg: '{{new_org}}'
|
||||||
|
|
||||||
|
- name: Clone IntTestOrg
|
||||||
|
meraki_organization:
|
||||||
|
auth_key: '{{ auth_key }}'
|
||||||
|
clone: IntTestOrg
|
||||||
|
org_name: IntTestOrgCloned
|
||||||
|
state: present
|
||||||
|
delegate_to: localhost
|
||||||
|
register: cloned_org
|
||||||
|
|
||||||
|
- debug:
|
||||||
|
msg: '{{cloned_org}}'
|
||||||
|
|
||||||
|
- name: Rename IntTestOrg
|
||||||
|
meraki_organization:
|
||||||
|
auth_key: '{{ auth_key }}'
|
||||||
|
org_name: IntTestOrgRenamed
|
||||||
|
org_id: '{{ new_org.data.id }}'
|
||||||
|
state: present
|
||||||
|
delegate_to: localhost
|
||||||
|
register: modify_org
|
||||||
|
|
||||||
|
- debug:
|
||||||
|
msg: '{{ modify_org }}'
|
||||||
|
|
||||||
|
- name: Rename IntTestOrg idempotent
|
||||||
|
meraki_organization:
|
||||||
|
auth_key: '{{ auth_key }}'
|
||||||
|
org_name: IntTestOrgRenamed
|
||||||
|
org_id: '{{ new_org.data.id }}'
|
||||||
|
state: present
|
||||||
|
delegate_to: localhost
|
||||||
|
register: modify_org_idempotent
|
||||||
|
|
||||||
|
- name: Present assertions
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- '"https" in new_org.url'
|
||||||
|
- new_org.changed == True
|
||||||
|
- new_org.data.id is defined
|
||||||
|
- cloned_org.changed == True
|
||||||
|
- cloned_org.data.id is defined
|
||||||
|
- modify_org.changed == True
|
||||||
|
- 'modify_org.data.name == "IntTestOrgRenamed"'
|
||||||
|
- modify_org_idempotent.changed == False
|
||||||
|
|
||||||
- name: List all organizations
|
- name: List all organizations
|
||||||
meraki_organization:
|
meraki_organization:
|
||||||
auth_key: '{{ auth_key }}'
|
auth_key: '{{ auth_key }}'
|
||||||
|
@ -27,11 +102,14 @@
|
||||||
- name: Query information about a single organization named IntTestOrg
|
- name: Query information about a single organization named IntTestOrg
|
||||||
meraki_organization:
|
meraki_organization:
|
||||||
auth_key: '{{ auth_key }}'
|
auth_key: '{{ auth_key }}'
|
||||||
org_name: IntTestOrg
|
org_name: IntTestOrgRenamed
|
||||||
state: query
|
state: query
|
||||||
delegate_to: localhost
|
delegate_to: localhost
|
||||||
register: query_org
|
register: query_org
|
||||||
|
|
||||||
|
- debug:
|
||||||
|
msg: '{{query_org}}'
|
||||||
|
|
||||||
- name: Query information about IntTestOrg by organization ID
|
- name: Query information about IntTestOrg by organization ID
|
||||||
meraki_organization:
|
meraki_organization:
|
||||||
auth_key: '{{ auth_key }}'
|
auth_key: '{{ auth_key }}'
|
||||||
|
@ -40,21 +118,11 @@
|
||||||
delegate_to: localhost
|
delegate_to: localhost
|
||||||
register: query_org_id
|
register: query_org_id
|
||||||
|
|
||||||
- name: Clone IntTestOrg
|
- name: Query assertions
|
||||||
meraki_organization:
|
|
||||||
auth_key: '{{ auth_key }}'
|
|
||||||
clone: IntTestOrg
|
|
||||||
org_name: IntTestOrgCloned
|
|
||||||
state: present
|
|
||||||
delegate_to: localhost
|
|
||||||
register: cloned_org
|
|
||||||
|
|
||||||
- name: Present assertions
|
|
||||||
assert:
|
assert:
|
||||||
that:
|
that:
|
||||||
- new_org.data.id is defined
|
|
||||||
- '{{ query_all | length}} > 0'
|
|
||||||
- query_org.data.id is defined
|
- query_org.data.id is defined
|
||||||
- 'query_org.data.name == "IntTestOrg"'
|
- query_all.changed == False
|
||||||
- cloned_org.data.id is defined
|
- query_all.data | length >= 1
|
||||||
|
- 'query_org.data.name == "IntTestOrgRenamed"'
|
||||||
- 'query_org_id.data.id == query_org.data.id'
|
- 'query_org_id.data.id == query_org.data.id'
|
Loading…
Reference in a new issue