From 63b7afb127da037921bca0a1514bd92a5cf82b4b Mon Sep 17 00:00:00 2001 From: alaa-bish Date: Mon, 21 Feb 2022 16:43:16 +0200 Subject: [PATCH] Fix Sanity --- plugins/modules/ntnx_pbrs.py | 7 +- .../targets/nutanix_pbrs/tasks/main.yml | 1 - .../nutanix_pbrs/tasks/negative_scenarios.yml | 374 +++++++++--------- 3 files changed, 188 insertions(+), 194 deletions(-) diff --git a/plugins/modules/ntnx_pbrs.py b/plugins/modules/ntnx_pbrs.py index 10b3a1531..791bdbb1b 100644 --- a/plugins/modules/ntnx_pbrs.py +++ b/plugins/modules/ntnx_pbrs.py @@ -61,7 +61,6 @@ priority: description: The policy priority number type: int - required: true pbr_uuid: description: PBR UUID type: str @@ -69,7 +68,6 @@ description: - Virtual Private Clouds type: dict - required: true suboptions: name: description: @@ -84,7 +82,6 @@ source: description: Where the traffic come from type: dict - default: any suboptions: any: description: @@ -111,7 +108,6 @@ destination: type: dict description: Where the traffic going to - default: any suboptions: any: description: @@ -138,7 +134,6 @@ protocol: type: dict description: The Network Protocol that will be used - default: any suboptions: any: description: @@ -195,7 +190,6 @@ action: type: dict description: The behavior on the request - default: allow suboptions: deny: description: @@ -256,6 +250,7 @@ external: True action: allow: True + type: bool protocol: number: "{{ protocol.number }}" diff --git a/tests/integration/targets/nutanix_pbrs/tasks/main.yml b/tests/integration/targets/nutanix_pbrs/tasks/main.yml index 95e9f8404..e205a2b69 100644 --- a/tests/integration/targets/nutanix_pbrs/tasks/main.yml +++ b/tests/integration/targets/nutanix_pbrs/tasks/main.yml @@ -1,4 +1,3 @@ - block: - import_tasks: "create_pbrs.yml" - import_tasks: "negative_scenarios.yml" - diff --git a/tests/integration/targets/nutanix_pbrs/tasks/negative_scenarios.yml b/tests/integration/targets/nutanix_pbrs/tasks/negative_scenarios.yml index 8e1de48bc..9aca46397 100644 --- a/tests/integration/targets/nutanix_pbrs/tasks/negative_scenarios.yml +++ b/tests/integration/targets/nutanix_pbrs/tasks/negative_scenarios.yml @@ -1,187 +1,187 @@ -- debug: - msg: "Started Negative Creation Cases" - -- name: Create PBR with unknown vpc name - ntnx_pbrs: - validate_certs: False - state: present - nutanix_host: "{{ ip }}" - nutanix_username: "{{ username }}" - nutanix_password: "{{ password }}" - priority: "{{ priority.8 }}" - vpc: - name: vpc - source: - network: - ip: "{{ network.ip }}" - prefix: "{{ network.prefix }}" - destination: - external: True - action: - reroute: "{{reroute_ip}}" - protocol: - icmp: - type: "*" - code: "*" - register: result - ignore_errors: True - -- name: Creation Status - assert: - that: - - result.failed is defined - success_msg: ' Success: returned error as expected ' -################################################################## -- name: Create PBR with priority less than 10 - ntnx_pbrs: - validate_certs: False - state: present - nutanix_host: "{{ ip }}" - nutanix_username: "{{ username }}" - nutanix_password: "{{ password }}" - priority: 8 - vpc: - name: "{{ vpc.name }}" - source: - network: - ip: "{{ network.ip }}" - prefix: "{{ network.prefix }}" - destination: - external: True - action: - reroute: "{{reroute_ip}}" - protocol: - icmp: - type: "*" - code: "*" - register: result - ignore_errors: True - -- name: Creation Status - assert: - that: - - result.failed is defined - success_msg: ' Success: returned error as expected ' -################################################################### -- name: Create PBR with invalid network ip - ntnx_pbrs: - validate_certs: False - state: present - nutanix_host: "{{ ip }}" - nutanix_username: "{{ username }}" - nutanix_password: "{{ password }}" - priority: "{{ priority.5 }}" - vpc: - name: "{{ vpc.name }}" - source: - network: - ip: 192.168.0.5 - prefix: 24 - destination: - external: True - action: - reroute: "{{reroute_ip}}" - protocol: - icmp: - code: "{{ icmp.code }}" - type: "{{ icmp.type }}" - register: result - ignore_errors: True - -- set_fact: - todelete: "{{ todelete + [ result.pbr_uuid ] }}" -################################################################# -- name: Create PBR with unknown vpc uuid - ntnx_pbrs: - validate_certs: False - state: present - nutanix_host: "{{ ip }}" - nutanix_username: "{{ username }}" - nutanix_password: "{{ password }}" - priority: "{{ priority.8 }}" - vpc: - uuid: ebf8130e-09b8-48d9-a9d3-5ef29983 - source: - network: - ip: "{{ network.ip }}" - prefix: "{{ network.prefix }}" - destination: - external: True - action: - reroute: "{{reroute_ip}}" - protocol: - icmp: - type: "*" - code: "*" - register: result - ignore_errors: True - -- name: Creation Status - assert: - that: - - result.failed is defined - success_msg: ' Success: returned error as expected ' -################################################################# -- name: Create PBR with invalid type and code values for icmp - ntnx_pbrs: - validate_certs: False - state: present - nutanix_host: "{{ ip }}" - nutanix_username: "{{ username }}" - nutanix_password: "{{ password }}" - priority: "{{ priority.8 }}" - vpc: - uuid: "{{ vpc.uuid }}" - source: - network: - ip: "{{ network.ip }}" - prefix: "{{ network.prefix }}" - destination: - external: True - action: - reroute: "{{reroute_ip}}" - protocol: - icmp: - type: "*" - code: "10" - register: result - ignore_errors: True - -- name: Creation Status - assert: - that: - - result.failed is defined - success_msg: ' Success: returned error as expected ' -##################################################################### -- name: Delete pbrs with unknown uuid - ntnx_pbrs: - state: absent - nutanix_host: "{{ ip }}" - nutanix_username: "{{ username }}" - nutanix_password: "{{ password }}" - validate_certs: false - pbr_uuid: 5 - register: result - loop: "{{ todelete }}" - ignore_errors: True -- name: Creation Status - assert: - that: - - result.failed is defined - success_msg: ' Success: returned error as expected ' -####################################################################### -- name: Delete pbrs with unknown uuid - ntnx_pbrs: - state: absent - nutanix_host: "{{ ip }}" - nutanix_username: "{{ username }}" - nutanix_password: "{{ password }}" - validate_certs: false - register: result - loop: "{{ todelete }}" - ignore_errors: True -- name: Creation Status - assert: - that: - - result.failed is defined - success_msg: ' Success: returned error as expected ' +- debug: + msg: "Started Negative Creation Cases" + +- name: Create PBR with unknown vpc name + ntnx_pbrs: + validate_certs: False + state: present + nutanix_host: "{{ ip }}" + nutanix_username: "{{ username }}" + nutanix_password: "{{ password }}" + priority: "{{ priority.8 }}" + vpc: + name: vpc + source: + network: + ip: "{{ network.ip }}" + prefix: "{{ network.prefix }}" + destination: + external: True + action: + reroute: "{{reroute_ip}}" + protocol: + icmp: + type: "*" + code: "*" + register: result + ignore_errors: True + +- name: Creation Status + assert: + that: + - result.failed is defined + success_msg: ' Success: returned error as expected ' +################################################################## +- name: Create PBR with priority less than 10 + ntnx_pbrs: + validate_certs: False + state: present + nutanix_host: "{{ ip }}" + nutanix_username: "{{ username }}" + nutanix_password: "{{ password }}" + priority: 8 + vpc: + name: "{{ vpc.name }}" + source: + network: + ip: "{{ network.ip }}" + prefix: "{{ network.prefix }}" + destination: + external: True + action: + reroute: "{{reroute_ip}}" + protocol: + icmp: + type: "*" + code: "*" + register: result + ignore_errors: True + +- name: Creation Status + assert: + that: + - result.failed is defined + success_msg: ' Success: returned error as expected ' +################################################################### +- name: Create PBR with invalid network ip + ntnx_pbrs: + validate_certs: False + state: present + nutanix_host: "{{ ip }}" + nutanix_username: "{{ username }}" + nutanix_password: "{{ password }}" + priority: "{{ priority.5 }}" + vpc: + name: "{{ vpc.name }}" + source: + network: + ip: 192.168.0.5 + prefix: 24 + destination: + external: True + action: + reroute: "{{reroute_ip}}" + protocol: + icmp: + code: "{{ icmp.code }}" + type: "{{ icmp.type }}" + register: result + ignore_errors: True + +- set_fact: + todelete: "{{ todelete + [ result.pbr_uuid ] }}" +################################################################# +- name: Create PBR with unknown vpc uuid + ntnx_pbrs: + validate_certs: False + state: present + nutanix_host: "{{ ip }}" + nutanix_username: "{{ username }}" + nutanix_password: "{{ password }}" + priority: "{{ priority.8 }}" + vpc: + uuid: ebf8130e-09b8-48d9-a9d3-5ef29983 + source: + network: + ip: "{{ network.ip }}" + prefix: "{{ network.prefix }}" + destination: + external: True + action: + reroute: "{{reroute_ip}}" + protocol: + icmp: + type: "*" + code: "*" + register: result + ignore_errors: True + +- name: Creation Status + assert: + that: + - result.failed is defined + success_msg: ' Success: returned error as expected ' +################################################################# +- name: Create PBR with invalid type and code values for icmp + ntnx_pbrs: + validate_certs: False + state: present + nutanix_host: "{{ ip }}" + nutanix_username: "{{ username }}" + nutanix_password: "{{ password }}" + priority: "{{ priority.8 }}" + vpc: + uuid: "{{ vpc.uuid }}" + source: + network: + ip: "{{ network.ip }}" + prefix: "{{ network.prefix }}" + destination: + external: True + action: + reroute: "{{reroute_ip}}" + protocol: + icmp: + type: "*" + code: "10" + register: result + ignore_errors: True + +- name: Creation Status + assert: + that: + - result.failed is defined + success_msg: ' Success: returned error as expected ' +##################################################################### +- name: Delete pbrs with unknown uuid + ntnx_pbrs: + state: absent + nutanix_host: "{{ ip }}" + nutanix_username: "{{ username }}" + nutanix_password: "{{ password }}" + validate_certs: false + pbr_uuid: 5 + register: result + loop: "{{ todelete }}" + ignore_errors: True +- name: Creation Status + assert: + that: + - result.failed is defined + success_msg: ' Success: returned error as expected ' +####################################################################### +- name: Delete pbrs with unknown uuid + ntnx_pbrs: + state: absent + nutanix_host: "{{ ip }}" + nutanix_username: "{{ username }}" + nutanix_password: "{{ password }}" + validate_certs: false + register: result + loop: "{{ todelete }}" + ignore_errors: True +- name: Creation Status + assert: + that: + - result.failed is defined + success_msg: ' Success: returned error as expected '