1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

Meraki - Integration tests now clean up on failure (#42227)

* Added block and always support to meraki_network integration test

* Add blocks to admin and vlan integration test

* Resolved bad variable names
This commit is contained in:
Kevin Breit 2018-07-03 03:42:04 -05:00 committed by Dag Wieers
parent 75c8d8bfc2
commit f9cbdcd426
3 changed files with 723 additions and 724 deletions

View file

@ -1,254 +1,260 @@
# Test code for the Meraki Organization module # Test code for the Meraki Admin module
# Copyright: (c) 2018, Kevin Breit (@kbreit) # Copyright: (c) 2018, Kevin Breit (@kbreit)
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
--- ---
- name: Create new administrator - block:
meraki_admin: - name: Create new administrator
auth_key: '{{auth_key}}' meraki_admin:
state: present auth_key: '{{auth_key}}'
org_name: '{{test_org_name}}' state: present
name: Jane Doe org_name: '{{test_org_name}}'
email: '{{email_prefix}}+janedoe@{{email_domain}}' name: Jane Doe
orgAccess: read-only email: '{{email_prefix}}+janedoe@{{email_domain}}'
delegate_to: localhost orgAccess: read-only
register: create_orgaccess delegate_to: localhost
register: create_orgaccess
- name: Create new admin assertion - name: Create new admin assertion
assert: assert:
that: that:
- create_orgaccess.changed == true - create_orgaccess.changed == true
- 'create_orgaccess.data.name == "Jane Doe"' - 'create_orgaccess.data.name == "Jane Doe"'
- name: Delete recently created administrator - name: Delete recently created administrator
meraki_admin: meraki_admin:
auth_key: '{{auth_key}}' auth_key: '{{auth_key}}'
state: absent state: absent
org_name: '{{test_org_name}}' org_name: '{{test_org_name}}'
email: '{{email_prefix}}+janedoe@{{email_domain}}' email: '{{email_prefix}}+janedoe@{{email_domain}}'
delegate_to: localhost delegate_to: localhost
register: delete_one register: delete_one
- name: Create new administrator with org_id - name: Create new administrator with org_id
meraki_admin: meraki_admin:
auth_key: '{{auth_key}}' auth_key: '{{auth_key}}'
state: present state: present
org_id: '{{test_org_id}}' org_id: '{{test_org_id}}'
name: Jane Doe name: Jane Doe
email: '{{email_prefix}}+janedoe@{{email_domain}}' email: '{{email_prefix}}+janedoe@{{email_domain}}'
orgAccess: read-only orgAccess: read-only
delegate_to: localhost delegate_to: localhost
register: create_orgaccess_id register: create_orgaccess_id
- name: Create new admin assertion - name: Create new admin assertion
assert: assert:
that: that:
- create_orgaccess_id.changed == true - create_orgaccess_id.changed == true
- 'create_orgaccess_id.data.name == "Jane Doe"' - 'create_orgaccess_id.data.name == "Jane Doe"'
- name: Create administrator with tags - name: Create administrator with tags
meraki_admin: meraki_admin:
auth_key: '{{auth_key}}' auth_key: '{{auth_key}}'
state: present state: present
org_name: '{{test_org_name}}' org_name: '{{test_org_name}}'
name: John Doe name: John Doe
email: '{{email_prefix}}+johndoe@{{email_domain}}' email: '{{email_prefix}}+johndoe@{{email_domain}}'
orgAccess: none orgAccess: none
tags: tags:
- { "tag": "production", "access": "read-only" } - { "tag": "production", "access": "read-only" }
- { "tag": "beta", "access": "full" } - { "tag": "beta", "access": "full" }
delegate_to: localhost delegate_to: localhost
register: create_tags register: create_tags
- assert: - assert:
that: that:
- create_tags.changed == true - create_tags.changed == true
- create_tags.data.name == "John Doe" - create_tags.data.name == "John Doe"
- create_tags.data.tags | length == 2 - create_tags.data.tags | length == 2
- name: Create administrator with invalid tags - name: Create administrator with invalid tags
meraki_admin: meraki_admin:
auth_key: '{{auth_key}}' auth_key: '{{auth_key}}'
state: present state: present
org_name: '{{test_org_name}}' org_name: '{{test_org_name}}'
name: Jake Doe name: Jake Doe
email: '{{email_prefix}}+jakedoe@{{email_domain}}' email: '{{email_prefix}}+jakedoe@{{email_domain}}'
orgAccess: none orgAccess: none
tags: tags:
- { "tag": "production", "access": "read-only" } - { "tag": "production", "access": "read-only" }
- { "tag": "alpha", "access": "invalid" } - { "tag": "alpha", "access": "invalid" }
delegate_to: localhost delegate_to: localhost
register: create_tags_invalid register: create_tags_invalid
ignore_errors: yes ignore_errors: yes
- assert: - assert:
that: that:
- '"400" in create_tags_invalid.msg' - '"400" in create_tags_invalid.msg'
# - '"must contain only valid tags" in create_tags_invalid.msg' # - '"must contain only valid tags" in create_tags_invalid.msg'
- name: Create administrator with invalid tag permission - name: Create administrator with invalid tag permission
meraki_admin: meraki_admin:
auth_key: '{{auth_key}}' auth_key: '{{auth_key}}'
state: present state: present
org_name: '{{test_org_name}}' org_name: '{{test_org_name}}'
name: Jake Doe name: Jake Doe
email: '{{email_prefix}}+jakedoe@{{email_domain}}' email: '{{email_prefix}}+jakedoe@{{email_domain}}'
orgAccess: none orgAccess: none
tags: tags:
- { "tag": "production", "access": "read-only" } - { "tag": "production", "access": "read-only" }
- { "tag": "beta", "access": "invalid" } - { "tag": "beta", "access": "invalid" }
delegate_to: localhost delegate_to: localhost
register: create_tags_invalid_permission register: create_tags_invalid_permission
ignore_errors: yes ignore_errors: yes
- assert: - assert:
that: that:
- '"400" in create_tags_invalid_permission.msg' - '"400" in create_tags_invalid_permission.msg'
# - '"Invalid permission type" in create_tags_invalid_permission.msg' # - '"Invalid permission type" in create_tags_invalid_permission.msg'
- name: Make sure TestNet and TestNet2 are created - name: Make sure TestNet and TestNet2 are created
meraki_network: meraki_network:
auth_key: '{{auth_key}}' auth_key: '{{auth_key}}'
state: present state: present
org_name: '{{test_org_name}}' org_name: '{{test_org_name}}'
net_name: '{{item}}' net_name: '{{item}}'
type: switch type: switch
loop: loop:
- TestNet - TestNet
- TestNet2 - TestNet2
- name: Create administrator with networks - name: Create administrator with networks
meraki_admin: meraki_admin:
auth_key: '{{auth_key}}' auth_key: '{{auth_key}}'
state: present state: present
org_name: '{{test_org_name}}' org_name: '{{test_org_name}}'
name: Jim Doe name: Jim Doe
email: '{{email_prefix}}+jimdoe@{{email_domain}}' email: '{{email_prefix}}+jimdoe@{{email_domain}}'
orgAccess: none orgAccess: none
networks: networks:
- { "network": "TestNet", "access": "read-only" } - { "network": "TestNet", "access": "read-only" }
- { "network": "TestNet2", "access": "full" } - { "network": "TestNet2", "access": "full" }
delegate_to: localhost delegate_to: localhost
register: create_network register: create_network
- assert: - assert:
that: that:
- create_network.changed == true - create_network.changed == true
- create_network.data.name == "Jim Doe" - create_network.data.name == "Jim Doe"
- create_network.data.networks | length == 2 - create_network.data.networks | length == 2
- name: Update administrator - name: Update administrator
meraki_admin: meraki_admin:
auth_key: '{{auth_key}}' auth_key: '{{auth_key}}'
state: present state: present
org_name: '{{test_org_name}}' org_name: '{{test_org_name}}'
name: Jim Doe name: Jim Doe
email: '{{email_prefix}}+jimdoe@{{email_domain}}' email: '{{email_prefix}}+jimdoe@{{email_domain}}'
orgAccess: none orgAccess: none
networks: networks:
- { "network": "TestNet", "access": "full" } - { "network": "TestNet", "access": "full" }
delegate_to: localhost delegate_to: localhost
register: update_network register: update_network
- assert: - assert:
that: that:
- update_network.changed == true - update_network.changed == true
- update_network.data.networks.0.access == "full" - update_network.data.networks.0.access == "full"
- update_network.data.networks | length == 1 - update_network.data.networks | length == 1
- name: Update administrator for idempotency check - name: Update administrator for idempotency check
meraki_admin: meraki_admin:
auth_key: '{{auth_key}}' auth_key: '{{auth_key}}'
state: present state: present
org_name: '{{test_org_name}}' org_name: '{{test_org_name}}'
name: Jim Doe name: Jim Doe
email: '{{email_prefix}}+jimdoe@{{email_domain}}' email: '{{email_prefix}}+jimdoe@{{email_domain}}'
orgAccess: none orgAccess: none
networks: networks:
- { "network": "TestNet", "access": "full" } - { "network": "TestNet", "access": "full" }
delegate_to: localhost delegate_to: localhost
register: update_network_idempotent register: update_network_idempotent
- assert: - assert:
that: that:
- update_network_idempotent.changed == false - update_network_idempotent.changed == false
- name: Create administrator with invalid network - name: Create administrator with invalid network
meraki_admin: meraki_admin:
auth_key: '{{auth_key}}' auth_key: '{{auth_key}}'
state: present state: present
org_name: '{{test_org_name}}' org_name: '{{test_org_name}}'
name: John Doe name: John Doe
email: '{{email_prefix}}+John@{{email_domain}}' email: '{{email_prefix}}+John@{{email_domain}}'
orgAccess: none orgAccess: none
networks: networks:
- { "network": "readnet", "access": "read-only" } - { "network": "readnet", "access": "read-only" }
delegate_to: localhost delegate_to: localhost
register: create_network_invalid register: create_network_invalid
ignore_errors: yes ignore_errors: yes
- assert: - assert:
that: that:
- '"No network found with the name" in create_network_invalid.msg' - '"No network found with the name" in create_network_invalid.msg'
# - '"400" in create_network_invalid.msg' # - '"400" in create_network_invalid.msg'
- name: Query all administrators - name: Query all administrators
meraki_admin: meraki_admin:
auth_key: '{{auth_key}}' auth_key: '{{auth_key}}'
state: query state: query
org_name: '{{test_org_name}}' org_name: '{{test_org_name}}'
delegate_to: localhost delegate_to: localhost
register: query_all register: query_all
- assert: - assert:
that: that:
- query_all.data | length == 4 - query_all.data | length == 4
- query_all.changed == False - query_all.changed == False
- name: Query admin by name - name: Query admin by name
meraki_admin: meraki_admin:
auth_key: '{{auth_key}}' auth_key: '{{auth_key}}'
state: query state: query
org_name: '{{test_org_name}}' org_name: '{{test_org_name}}'
name: Jane Doe name: Jane Doe
delegate_to: localhost delegate_to: localhost
register: query_name register: query_name
- name: Query admin by email - name: Query admin by email
meraki_admin: meraki_admin:
auth_key: '{{auth_key}}' auth_key: '{{auth_key}}'
state: query state: query
org_name: '{{test_org_name}}' org_name: '{{test_org_name}}'
email: '{{email_prefix}}+janedoe@{{email_domain}}' email: '{{email_prefix}}+janedoe@{{email_domain}}'
delegate_to: localhost delegate_to: localhost
register: query_email register: query_email
- assert: - assert:
that: that:
- query_name.data.name == "Jane Doe" - query_name.data.name == "Jane Doe"
- 'query_email.data.email == "{{email_prefix}}+janedoe@{{email_domain}}"' - 'query_email.data.email == "{{email_prefix}}+janedoe@{{email_domain}}"'
- name: Delete administrators always:
meraki_admin: #############################################################################
auth_key: '{{auth_key}}' # Tear down starts here
state: absent #############################################################################
org_name: '{{test_org_name}}' - name: Delete administrators
email: '{{item}}' meraki_admin:
delegate_to: localhost auth_key: '{{auth_key}}'
register: delete_all state: absent
loop: org_name: '{{test_org_name}}'
- '{{email_prefix}}+janedoe@{{email_domain}}' email: '{{item}}'
- '{{email_prefix}}+johndoe@{{email_domain}}' delegate_to: localhost
- '{{email_prefix}}+jimdoe@{{email_domain}}' register: delete_all
ignore_errors: yes
loop:
- '{{email_prefix}}+janedoe@{{email_domain}}'
- '{{email_prefix}}+johndoe@{{email_domain}}'
- '{{email_prefix}}+jimdoe@{{email_domain}}'
- name: Query all administrators - name: Query all administrators
meraki_admin: meraki_admin:
auth_key: '{{auth_key}}' auth_key: '{{auth_key}}'
state: query state: query
org_name: '{{test_org_name}}' org_name: '{{test_org_name}}'
delegate_to: localhost delegate_to: localhost
register: query_all_deleted register: query_all_deleted
- assert: - assert:
that: that:
- query_all_deleted.data | length == 1 - query_all_deleted.data | length == 1

View file

@ -3,245 +3,234 @@
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
--- ---
- name: Create network without type - block:
meraki_network: - name: Create network without type
auth_key: '{{ auth_key }}' meraki_network:
state: present auth_key: '{{ auth_key }}'
org_name: '{{test_org_name}}' state: present
net_name: IntTestNetwork org_name: '{{test_org_name}}'
timezone: America/Chicago net_name: IntTestNetwork
delegate_to: localhost timezone: America/Chicago
register: create_net_no_type delegate_to: localhost
ignore_errors: yes register: create_net_no_type
ignore_errors: yes
- name: Create network without organization - name: Create network without organization
meraki_network: meraki_network:
auth_key: '{{ auth_key }}' auth_key: '{{ auth_key }}'
state: present state: present
net_name: IntTestNetwork net_name: IntTestNetwork
timezone: America/Chicago timezone: America/Chicago
delegate_to: localhost delegate_to: localhost
register: create_net_no_org register: create_net_no_org
ignore_errors: yes ignore_errors: yes
- name: Create network with type switch - name: Create network with type switch
meraki_network: meraki_network:
auth_key: '{{ auth_key }}' auth_key: '{{ auth_key }}'
state: present state: present
org_name: '{{test_org_name}}' org_name: '{{test_org_name}}'
net_name: IntTestNetworkSwitch net_name: IntTestNetworkSwitch
type: switch type: switch
timezone: America/Chicago timezone: America/Chicago
delegate_to: localhost delegate_to: localhost
register: create_net_switch register: create_net_switch
- name: Create network with type switch by org ID
meraki_network:
auth_key: '{{ auth_key }}'
state: present
org_id: '{{test_org_id}}'
net_name: IntTestNetworkSwitchOrgID
type: switch
timezone: America/Chicago
delegate_to: localhost
register: create_net_switch_org_id
- name: Create network with type appliance and no timezone
meraki_network:
auth_key: '{{ auth_key }}'
state: present
org_name: '{{test_org_name}}'
net_name: IntTestNetworkAppliance
type: appliance
delegate_to: localhost
register: create_net_appliance_no_tz
- name: Create network with type wireless
meraki_network:
auth_key: '{{ auth_key }}'
state: present
org_name: '{{test_org_name}}'
net_name: IntTestNetworkWireless
type: wireless
timezone: America/Chicago
delegate_to: localhost
register: create_net_wireless
- name: Create network with type wireless and check for idempotency
meraki_network:
auth_key: '{{ auth_key }}'
state: present
org_name: '{{test_org_name}}'
net_name: IntTestNetworkWireless
type: wireless
timezone: America/Chicago
delegate_to: localhost
register: create_net_wireless_idempotent
- name: Create network with type combined
meraki_network:
auth_key: '{{ auth_key }}'
state: present
org_name: '{{test_org_name}}'
net_name: IntTestNetworkCombined
type: combined
timezone: America/Chicago
delegate_to: localhost
register: create_net_combined
- name: Create network with one tag
meraki_network:
auth_key: '{{ auth_key }}'
state: present
org_name: '{{test_org_name}}'
net_name: IntTestNetworkTag
type: switch
timezone: America/Chicago
tags: first_tag
delegate_to: localhost
register: create_net_tag
- debug:
msg: '{{create_net_tag}}'
- name: Create network with two tags
meraki_network:
auth_key: '{{ auth_key }}'
state: present
org_name: '{{test_org_name}}'
net_name: IntTestNetworkTags
type: switch
timezone: America/Chicago
tags: first_tag, second_tag
delegate_to: localhost
register: create_net_tags
- debug:
msg: '{{create_net_tags}}'
- name: Modify network
meraki_network:
auth_key: '{{ auth_key }}'
state: present
org_name: '{{test_org_name}}'
net_name: IntTestNetworkTags
type: switch
timezone: America/Chicago
tags: first_tag, second_tag, third_tag
delegate_to: localhost
register: create_net_modified
- name: Modify network with idempotency
meraki_network:
auth_key: '{{ auth_key }}'
state: present
org_name: '{{test_org_name}}'
net_name: IntTestNetworkTags
type: switch
timezone: America/Chicago
tags: first_tag, second_tag, third_tag
delegate_to: localhost
register: create_net_modified_idempotent
- name: Present assertions
assert:
that:
- create_net_no_type.status == 500
- '"org_name or org_id parameters are required" in create_net_no_org.msg'
- '"IntTestNetworkAppliance" in create_net_appliance_no_tz.data.name'
- create_net_appliance_no_tz.changed == True
- '"IntTestNetworkSwitch" in create_net_switch.data.name'
- '"IntTestNetworkSwitchOrgID" in create_net_switch_org_id.data.name'
- '"IntTestNetworkWireless" in create_net_wireless.data.name'
- create_net_wireless_idempotent.changed == False
- '"first_tag" in create_net_tag.data.tags'
- '"second_tag" in create_net_tags.data.tags'
- '"third_tag" in create_net_modified.data.tags'
- create_net_modified.changed == True
- create_net_modified_idempotent.changed == False
- name: Query all networks
meraki_network:
auth_key: '{{ auth_key }}'
state: query
org_name: '{{test_org_name}}'
delegate_to: localhost
register: net_query_all
- name: Query one network - name: Create network with type switch by org ID
meraki_network: meraki_network:
auth_key: '{{ auth_key }}' auth_key: '{{ auth_key }}'
state: query state: present
org_name: '{{test_org_name}}' org_id: '{{test_org_id}}'
net_name: IntTestNetworkSwitch net_name: IntTestNetworkSwitchOrgID
delegate_to: localhost type: switch
register: net_query_one timezone: America/Chicago
delegate_to: localhost
register: create_net_switch_org_id
- name: Create network with type appliance and no timezone
meraki_network:
auth_key: '{{ auth_key }}'
state: present
org_name: '{{test_org_name}}'
net_name: IntTestNetworkAppliance
type: appliance
delegate_to: localhost
register: create_net_appliance_no_tz
- name: Create network with type wireless
meraki_network:
auth_key: '{{ auth_key }}'
state: present
org_name: '{{test_org_name}}'
net_name: IntTestNetworkWireless
type: wireless
timezone: America/Chicago
delegate_to: localhost
register: create_net_wireless
- name: Query assertions - name: Create network with type wireless and check for idempotency
assert: meraki_network:
that: auth_key: '{{ auth_key }}'
# - net_query_all.data | length == 7 state: present
- 'net_query_one.data.name == "IntTestNetworkSwitch"' org_name: '{{test_org_name}}'
net_name: IntTestNetworkWireless
type: wireless
timezone: America/Chicago
delegate_to: localhost
register: create_net_wireless_idempotent
- name: Create network with type combined
meraki_network:
auth_key: '{{ auth_key }}'
state: present
org_name: '{{test_org_name}}'
net_name: IntTestNetworkCombined
type: combined
timezone: America/Chicago
delegate_to: localhost
register: create_net_combined
- name: Create network with one tag
meraki_network:
auth_key: '{{ auth_key }}'
state: present
org_name: '{{test_org_name}}'
net_name: IntTestNetworkTag
type: switch
timezone: America/Chicago
tags: first_tag
delegate_to: localhost
register: create_net_tag
- debug:
msg: '{{create_net_tag}}'
- name: Create network with two tags
meraki_network:
auth_key: '{{ auth_key }}'
state: present
org_name: '{{test_org_name}}'
net_name: IntTestNetworkTags
type: switch
timezone: America/Chicago
tags: first_tag, second_tag
delegate_to: localhost
register: create_net_tags
- debug:
msg: '{{create_net_tags}}'
- name: Modify network
meraki_network:
auth_key: '{{ auth_key }}'
state: present
org_name: '{{test_org_name}}'
net_name: IntTestNetworkTags
type: switch
timezone: America/Chicago
tags: first_tag, second_tag, third_tag
delegate_to: localhost
register: create_net_modified
- name: Modify network with idempotency
meraki_network:
auth_key: '{{ auth_key }}'
state: present
org_name: '{{test_org_name}}'
net_name: IntTestNetworkTags
type: switch
timezone: America/Chicago
tags: first_tag, second_tag, third_tag
delegate_to: localhost
register: create_net_modified_idempotent
- name: Present assertions
assert:
that:
- create_net_no_type.status == 500
- '"org_name or org_id parameters are required" in create_net_no_org.msg'
- '"IntTestNetworkAppliance" in create_net_appliance_no_tz.data.name'
- create_net_appliance_no_tz.changed == True
- '"IntTestNetworkSwitch" in create_net_switch.data.name'
- '"IntTestNetworkSwitchOrgID" in create_net_switch_org_id.data.name'
- '"IntTestNetworkWireless" in create_net_wireless.data.name'
- create_net_wireless_idempotent.changed == False
- '"first_tag" in create_net_tag.data.tags'
- '"second_tag" in create_net_tags.data.tags'
- '"third_tag" in create_net_modified.data.tags'
- create_net_modified.changed == True
- create_net_modified_idempotent.changed == False
- name: Query all networks
meraki_network:
auth_key: '{{ auth_key }}'
state: query
org_name: '{{test_org_name}}'
delegate_to: localhost
register: net_query_all
- name: Delete network without org - name: Query one network
meraki_network: meraki_network:
auth_key: '{{ auth_key }}' auth_key: '{{ auth_key }}'
state: absent state: query
net_name: IntTestNetworkSwitch org_name: '{{test_org_name}}'
delegate_to: localhost net_name: IntTestNetworkSwitch
register: delete_all_no_org delegate_to: localhost
ignore_errors: yes register: net_query_one
- debug: - name: Query assertions
msg: '{{delete_all_no_org}}' assert:
that:
- name: Delete network by org ID - 'net_query_one.data.name == "IntTestNetworkSwitch"'
meraki_network:
auth_key: '{{ auth_key }}'
state: absent
org_id: '{{test_org_id}}'
net_name: IntTestNetworkSwitchOrgID
delegate_to: localhost
register: delete_net_org_id
- debug: #############################################################################
msg: '{{delete_net_org_id}}' # Tear down starts here
#############################################################################
always:
- name: Delete network without org
meraki_network:
auth_key: '{{ auth_key }}'
state: absent
net_name: IntTestNetworkSwitch
delegate_to: localhost
register: delete_all_no_org
ignore_errors: yes
- name: Delete network by org ID
meraki_network:
auth_key: '{{ auth_key }}'
state: absent
org_id: '{{test_org_id}}'
net_name: IntTestNetworkSwitchOrgID
delegate_to: localhost
register: delete_net_org_id
- name: Query after delete with org ID - name: Query after delete with org ID
meraki_network: meraki_network:
auth_key: '{{ auth_key }}' auth_key: '{{ auth_key }}'
state: query state: query
org_name: '{{test_org_name}}' org_name: '{{test_org_name}}'
delegate_to: localhost delegate_to: localhost
register: query_deleted_org_id register: query_deleted_org_id
- name: Delete all networks - name: Delete all networks
meraki_network: meraki_network:
auth_key: '{{ auth_key }}' auth_key: '{{ auth_key }}'
state: absent state: absent
org_name: '{{test_org_name}}' org_name: '{{test_org_name}}'
net_name: '{{ item }}' net_name: '{{ item }}'
delegate_to: localhost delegate_to: localhost
register: delete_all register: delete_all
loop: ignore_errors: yes
- IntTestNetworkSwitch loop:
- IntTestNetworkWireless - IntTestNetworkSwitch
- IntTestNetworkAppliance - IntTestNetworkWireless
- IntTestNetworkCombined - IntTestNetworkAppliance
- IntTestNetworkTag - IntTestNetworkCombined
- IntTestNetworkTags - IntTestNetworkTag
- IntTestNetworkTags
- name: Query after delete all
meraki_network: - assert:
auth_key: '{{ auth_key }}' that:
state: query - 'delete_all_no_org.msg == "org_name or org_id parameters are required"'
org_name: '{{test_org_name}}'
delegate_to: localhost
register: query_deleted
- name: Delete assertions
assert:
that:
- '"org_name or org_id parameters are required" in delete_all_no_org.msg'
# - query_deleted_org_id.data | length == 6
# - query_deleted.data | length == 0

View file

@ -1,303 +1,307 @@
# Test code for the Meraki Organization module # Test code for the Meraki VLAN module
# Copyright: (c) 2018, Kevin Breit (@kbreit) # Copyright: (c) 2018, Kevin Breit (@kbreit)
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
--- ---
- name: Test an API key is provided - block:
fail: - name: Test an API key is provided
msg: Please define an API key fail:
when: auth_key is not defined msg: Please define an API key
when: auth_key is not defined
- name: Use an invalid domain
meraki_vlan: - name: Use an invalid domain
auth_key: '{{ auth_key }}' meraki_vlan:
host: marrrraki.com auth_key: '{{ auth_key }}'
state: present host: marrrraki.com
org_name: '{{test_org_name}}' state: present
output_level: debug org_name: IntTestOrg
delegate_to: localhost output_level: debug
register: invalid_domain delegate_to: localhost
ignore_errors: yes register: invalid_domain
ignore_errors: yes
- name: Disable HTTP
meraki_vlan: - name: Disable HTTP
auth_key: '{{ auth_key }}' meraki_vlan:
use_https: false auth_key: '{{ auth_key }}'
state: query use_https: false
org_name: '{{test_org_name}}' state: query
output_level: debug output_level: debug
delegate_to: localhost delegate_to: localhost
register: http register: http
ignore_errors: yes ignore_errors: yes
- name: Connection assertions - name: Connection assertions
assert: assert:
that: that:
- '"Failed to connect to" in invalid_domain.msg' - '"Failed to connect to" in invalid_domain.msg'
- '"http" in http.url' - '"http" in http.url'
- name: Create test network - name: Create test network
meraki_network: meraki_network:
auth_key: '{{auth_key}}' auth_key: '{{auth_key}}'
state: present state: present
org_name: '{{test_org_name}}' org_name: '{{test_org_name}}'
net_name: '{{test_net_name}}' net_name: '{{test_net_name}}'
type: appliance type: appliance
delegate_to: localhost delegate_to: localhost
- name: Create VLAN - name: Create VLAN
meraki_vlan: meraki_vlan:
auth_key: '{{auth_key}}' auth_key: '{{auth_key}}'
state: present state: present
org_name: '{{test_org_name}}' org_name: '{{test_org_name}}'
net_name: '{{test_net_name}}' net_name: '{{test_net_name}}'
vlan_id: 2 vlan_id: 2
name: TestVLAN name: TestVLAN
subnet: 192.168.250.0/24 subnet: 192.168.250.0/24
appliance_ip: 192.168.250.1 appliance_ip: 192.168.250.1
delegate_to: localhost delegate_to: localhost
register: create_vlan register: create_vlan
- debug: - debug:
msg: '{{create_vlan}}' msg: '{{create_vlan}}'
- assert: - assert:
that: that:
- create_vlan.data.id == 2 - create_vlan.data.id == 2
- create_vlan.changed == True - create_vlan.changed == True
- name: Update VLAN - name: Update VLAN
meraki_vlan: meraki_vlan:
auth_key: '{{auth_key}}' auth_key: '{{auth_key}}'
state: present state: present
org_name: '{{test_org_name}}' org_name: '{{test_org_name}}'
net_name: '{{test_net_name}}' net_name: '{{test_net_name}}'
vlan_id: 2 vlan_id: 2
name: TestVLAN name: TestVLAN
subnet: 192.168.250.0/24 subnet: 192.168.250.0/24
appliance_ip: 192.168.250.2 appliance_ip: 192.168.250.2
fixed_ip_assignments: fixed_ip_assignments:
- mac: "13:37:de:ad:be:ef" - mac: "13:37:de:ad:be:ef"
ip: 192.168.250.10 ip: 192.168.250.10
name: fixed_ip name: fixed_ip
reserved_ip_range: reserved_ip_range:
- start: 192.168.250.10 - start: 192.168.250.10
end: 192.168.250.20 end: 192.168.250.20
comment: reserved_range comment: reserved_range
dns_nameservers: opendns dns_nameservers: opendns
delegate_to: localhost delegate_to: localhost
register: update_vlan register: update_vlan
- debug: - debug:
msg: '{{update_vlan}}' msg: '{{update_vlan}}'
- assert: - assert:
that: that:
- update_vlan.data.applianceIp == '192.168.250.2' - update_vlan.data.applianceIp == '192.168.250.2'
- update_vlan.changed == True - update_vlan.changed == True
- name: Update VLAN with idempotency - name: Update VLAN with idempotency
meraki_vlan: meraki_vlan:
auth_key: '{{auth_key}}' auth_key: '{{auth_key}}'
state: present state: present
org_name: '{{test_org_name}}' org_name: '{{test_org_name}}'
net_name: '{{test_net_name}}' net_name: '{{test_net_name}}'
vlan_id: 2 vlan_id: 2
name: TestVLAN name: TestVLAN
subnet: 192.168.250.0/24 subnet: 192.168.250.0/24
appliance_ip: 192.168.250.2 appliance_ip: 192.168.250.2
fixed_ip_assignments: fixed_ip_assignments:
- mac: "13:37:de:ad:be:ef" - mac: "13:37:de:ad:be:ef"
ip: 192.168.250.10 ip: 192.168.250.10
name: fixed_ip name: fixed_ip
reserved_ip_range: reserved_ip_range:
- start: 192.168.250.10 - start: 192.168.250.10
end: 192.168.250.20 end: 192.168.250.20
comment: reserved_range comment: reserved_range
dns_nameservers: opendns dns_nameservers: opendns
delegate_to: localhost delegate_to: localhost
register: update_vlan_idempotent register: update_vlan_idempotent
- debug: - debug:
msg: '{{update_vlan_idempotent}}' msg: '{{update_vlan_idempotent}}'
- assert: - assert:
that: that:
- update_vlan_idempotent.changed == False - update_vlan_idempotent.changed == False
- name: Add IP assignments and reserved IP ranges - name: Add IP assignments and reserved IP ranges
meraki_vlan: meraki_vlan:
auth_key: '{{auth_key}}' auth_key: '{{auth_key}}'
state: present state: present
org_name: '{{test_org_name}}' org_name: '{{test_org_name}}'
net_name: '{{test_net_name}}' net_name: '{{test_net_name}}'
vlan_id: 2 vlan_id: 2
name: TestVLAN name: TestVLAN
subnet: 192.168.250.0/24 subnet: 192.168.250.0/24
appliance_ip: 192.168.250.2 appliance_ip: 192.168.250.2
fixed_ip_assignments: fixed_ip_assignments:
- mac: "13:37:de:ad:be:ef" - mac: "13:37:de:ad:be:ef"
ip: 192.168.250.10 ip: 192.168.250.10
name: fixed_ip name: fixed_ip
- mac: "12:34:56:78:90:12" - mac: "12:34:56:78:90:12"
ip: 192.168.250.11 ip: 192.168.250.11
name: another_fixed_ip name: another_fixed_ip
reserved_ip_range: reserved_ip_range:
- start: 192.168.250.10 - start: 192.168.250.10
end: 192.168.250.20 end: 192.168.250.20
comment: reserved_range comment: reserved_range
- start: 192.168.250.100 - start: 192.168.250.100
end: 192.168.250.120 end: 192.168.250.120
comment: reserved_range_high comment: reserved_range_high
dns_nameservers: opendns dns_nameservers: opendns
delegate_to: localhost delegate_to: localhost
register: update_vlan_add_ip register: update_vlan_add_ip
- debug: - debug:
msg: '{{update_vlan_add_ip}}' msg: '{{update_vlan_add_ip}}'
- assert: - assert:
that: that:
- update_vlan_add_ip.changed == True - update_vlan_add_ip.changed == True
- update_vlan_add_ip.data.fixedIpAssignments | length == 2 - update_vlan_add_ip.data.fixedIpAssignments | length == 2
- update_vlan_add_ip.data.reservedIpRanges | length == 2 - update_vlan_add_ip.data.reservedIpRange | length == 2
- name: Remove IP assignments and reserved IP ranges - name: Remove IP assignments and reserved IP ranges
meraki_vlan: meraki_vlan:
auth_key: '{{auth_key}}' auth_key: '{{auth_key}}'
state: present state: present
org_name: '{{test_org_name}}' org_name: '{{test_org_name}}'
net_name: '{{test_net_name}}' net_name: '{{test_net_name}}'
vlan_id: 2 vlan_id: 2
name: TestVLAN name: TestVLAN
subnet: 192.168.250.0/24 subnet: 192.168.250.0/24
appliance_ip: 192.168.250.2 appliance_ip: 192.168.250.2
fixed_ip_assignments: fixed_ip_assignments:
- mac: "13:37:de:ad:be:ef" - mac: "13:37:de:ad:be:ef"
ip: 192.168.250.10 ip: 192.168.250.10
name: fixed_ip name: fixed_ip
reserved_ip_range: reserved_ip_range:
- start: 192.168.250.10 - start: 192.168.250.10
end: 192.168.250.20 end: 192.168.250.20
comment: reserved_range comment: reserved_range
dns_nameservers: opendns dns_nameservers: opendns
delegate_to: localhost delegate_to: localhost
register: update_vlan_remove_ip register: update_vlan_remove_ip
- debug: - debug:
msg: '{{update_vlan_remove_ip}}' msg: '{{update_vlan_remove_ip}}'
- assert: - assert:
that: that:
- update_vlan_remove_ip.changed == True - update_vlan_remove_ip.changed == True
- update_vlan_remove_ip.data.fixedIpAssignments | length == 1 - update_vlan_remove_ip.data.fixedIpAssignments | length == 1
- update_vlan_remove_ip.data.reservedIpRanges | length == 1 - update_vlan_remove_ip.data.reservedIpRange | length == 1
- name: Update VLAN with idempotency - name: Update VLAN with idempotency
meraki_vlan: meraki_vlan:
auth_key: '{{auth_key}}' auth_key: '{{auth_key}}'
state: present state: present
org_name: '{{test_org_name}}' org_name: '{{test_org_name}}'
net_name: '{{test_net_name}}' net_name: '{{test_net_name}}'
vlan_id: 2 vlan_id: 2
name: TestVLAN name: TestVLAN
subnet: 192.168.250.0/24 subnet: 192.168.250.0/24
appliance_ip: 192.168.250.2 appliance_ip: 192.168.250.2
fixed_ip_assignments: fixed_ip_assignments:
- mac: "13:37:de:ad:be:ef" - mac: "13:37:de:ad:be:ef"
ip: 192.168.250.10 ip: 192.168.250.10
name: fixed_ip name: fixed_ip
reserved_ip_range: reserved_ip_range:
- start: 192.168.250.10 - start: 192.168.250.10
end: 192.168.250.20 end: 192.168.250.20
comment: reserved_range comment: reserved_range
dns_nameservers: opendns dns_nameservers: opendns
delegate_to: localhost delegate_to: localhost
register: update_vlan_idempotent register: update_vlan_idempotent
- debug: - debug:
msg: '{{update_vlan_idempotent}}' msg: '{{update_vlan_idempotent}}'
- assert: - assert:
that: that:
- update_vlan_idempotent.changed == False - update_vlan_idempotent.changed == False
- name: Update VLAN with list of DNS entries - name: Update VLAN with list of DNS entries
meraki_vlan: meraki_vlan:
auth_key: '{{auth_key}}' auth_key: '{{auth_key}}'
state: present state: present
org_name: '{{test_org_name}}' org_name: '{{test_org_name}}'
net_name: '{{test_net_name}}' net_name: '{{test_net_name}}'
vlan_id: 2 vlan_id: 2
name: TestVLAN name: TestVLAN
subnet: 192.168.250.0/24 subnet: 192.168.250.0/24
appliance_ip: 192.168.250.2 appliance_ip: 192.168.250.2
fixed_ip_assignments: fixed_ip_assignments:
- mac: "13:37:de:ad:be:ef" - mac: "13:37:de:ad:be:ef"
ip: 192.168.250.10 ip: 192.168.250.10
name: fixed_ip name: fixed_ip
reserved_ip_range: reserved_ip_range:
- start: 192.168.250.10 - start: 192.168.250.10
end: 192.168.250.20 end: 192.168.250.20
comment: reserved_range comment: reserved_range
dns_nameservers: 1.1.1.1;8.8.8.8 dns_nameservers: 1.1.1.1;8.8.8.8
delegate_to: localhost delegate_to: localhost
register: update_vlan_dns_list register: update_vlan_dns_list
- debug: - debug:
msg: '{{update_vlan_dns_list}}' msg: '{{update_vlan_dns_list}}'
- assert: - assert:
that: that:
- '"1.1.1.1" in update_vlan_dns_list.data.dnsNameservers' - '"1.1.1.1" in update_vlan_dns_list.data.dnsNameservers'
- update_vlan_dns_list.changed == True - update_vlan_dns_list.changed == True
- name: Query all VLANs in network - name: Query all VLANs in network
meraki_vlan: meraki_vlan:
auth_key: '{{ auth_key }}' auth_key: '{{ auth_key }}'
org_name: '{{test_org_name}}' org_name: '{{test_org_name}}'
net_name: '{{test_net_name}}' net_name: '{{test_net_name}}'
state: query state: query
delegate_to: localhost delegate_to: localhost
register: query_vlans register: query_vlans
- debug: - debug:
msg: '{{query_vlans}}' msg: '{{query_vlans}}'
- assert: - assert:
that: that:
- query_vlans.data | length >= 2 - query_vlans.data | length >= 2
- query_vlans.data.1.id == 2 - query_vlans.data.1.id == 2
- query_vlans.changed == False - query_vlans.changed == False
- name: Query single VLAN - name: Query single VLAN
meraki_vlan: meraki_vlan:
auth_key: '{{ auth_key }}' auth_key: '{{ auth_key }}'
org_name: '{{test_org_name}}' org_name: '{{test_org_name}}'
net_name: '{{test_net_name}}' net_name: '{{test_net_name}}'
vlan_id: 2 vlan_id: 2
state: query state: query
output_level: debug output_level: debug
delegate_to: localhost delegate_to: localhost
register: query_vlan register: query_vlan
- debug: - debug:
msg: '{{query_vlan}}' msg: '{{query_vlan}}'
- assert: - assert:
that: that:
- query_vlan.data.id == 2 - query_vlan.data.id == 2
- query_vlan.changed == False - query_vlan.changed == False
- name: Delete VLAN always:
meraki_vlan: #############################################################################
auth_key: '{{auth_key}}' # Tear down starts here
state: absent #############################################################################
org_name: '{{test_org_name}}' - name: Delete VLAN
net_name: '{{test_net_name}}' meraki_vlan:
vlan_id: 2 auth_key: '{{auth_key}}'
delegate_to: localhost state: absent
register: delete_vlan org_name: '{{test_org_name}}'
net_name: '{{test_net_name}}'
vlan_id: 2
delegate_to: localhost
register: delete_vlan
- debug: - debug:
msg: '{{delete_vlan}}' msg: '{{delete_vlan}}'