HTTP(S) API connection plugin (#39224)

* HTTPAPI connection

* Punt run_commands to cliconf or httpapi

* Fake enable_mode on eapi

* Pull changes to nxos

* Move load_config to edit_config for future-preparedness

* Don't fail on lldp disabled

* Re-enable check_rc on nxos' run_commands

* Reorganize nxos httpapi plugin for compatibility

* draft docs for connection: httpapi

* restores docs for connection:local for eapi

* Add _remote_is_local to httpapi
This commit is contained in:
Nathaniel Case 2018-05-17 18:47:15 -04:00 committed by GitHub
commit e9d7fa0418
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
277 changed files with 1325 additions and 1676 deletions

View file

@ -1,5 +1,5 @@
---
- name: collect common cli test cases
- name: collect common test cases
find:
paths: "{{ role_path }}/tests/common"
patterns: "{{ testcase }}.yaml"
@ -21,13 +21,7 @@
set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}"
- name: run test cases (connection=network_cli)
include: "{{ test_case_to_run }} ansible_connection=network_cli connection={}"
include: "{{ test_case_to_run }} ansible_connection=network_cli"
with_items: "{{ test_items }}"
loop_control:
loop_var: test_case_to_run
- name: run test case (connection=local)
include: "{{ test_case_to_run }} ansible_connection=local connection={{ cli }}"
with_first_found: "{{ test_items }}"
loop_control:
loop_var: test_case_to_run

View file

@ -1,5 +1,5 @@
---
- name: collect common nxapi test cases
- name: collect common test cases
find:
paths: "{{ role_path }}/tests/common"
patterns: "{{ testcase }}.yaml"
@ -20,8 +20,8 @@
- name: set test_items
set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}"
- name: run test cases (connection=local)
include: "{{ test_case_to_run }} ansible_connection=local connection={{ nxapi }}"
- name: run test cases (connection=httpapi)
include: "{{ test_case_to_run }} ansible_connection=httpapi"
with_items: "{{ test_items }}"
loop_control:
loop_var: test_case_to_run

View file

@ -1,20 +1,16 @@
---
- debug: msg="START TRANSPORT:CLI nxos_command sanity test"
- debug: msg="Using provider={{ connection.transport }}"
when: ansible_connection == "local"
- debug: msg="START cli/sanity.yaml on connection={{ ansible_connection }}"
- name: "Disable feature BGP"
nxos_feature:
feature: bgp
state: disabled
provider: "{{ cli }}"
- block:
- name: "Run show running-config bgp - should fail"
nxos_command:
commands:
- sh running-config bgp
provider: "{{ cli }}"
ignore_errors: yes
register: result
@ -26,14 +22,12 @@
nxos_feature:
feature: bgp
state: enabled
provider: "{{ cli }}"
- name: "Configure BGP defaults"
nxos_bgp: &configure_default
asn: 65535
router_id: 1.1.1.1
state: present
provider: "{{ cli }}"
register: result
- assert: &true
@ -44,7 +38,6 @@
nxos_command:
commands:
- sh running-config bgp
provider: "{{ cli }}"
register: result
- assert:
@ -56,7 +49,6 @@
nxos_command:
commands:
- show interface bief
provider: "{{ cli }}"
ignore_errors: yes
register: result
@ -70,6 +62,5 @@
nxos_feature:
feature: bgp
state: disabled
provider: "{{ cli }}"
- debug: msg="END TRANSPORT:CLI nxos_command sanity test"
- debug: msg="END cli/sanity.yaml on connection={{ ansible_connection }}"

View file

@ -1,5 +1,5 @@
---
- debug: msg="START cli/bad_operator.yaml"
- debug: msg="START common/bad_operator.yaml on connection={{ ansible_connection }}"
- name: test bad operator
nxos_command:
@ -8,7 +8,6 @@
- show interface mgmt0 | json
wait_for:
- "result[1].TABLE_interface.ROW_interface.state foo up"
provider: "{{ cli }}"
register: result
ignore_errors: yes
@ -17,4 +16,4 @@
- "result.failed == true"
- "result.msg is defined"
- debug: msg="END cli/bad_operator.yaml"
- debug: msg="END common/bad_operator.yaml on connection={{ ansible_connection }}"

View file

@ -1,5 +1,5 @@
---
- debug: msg="START cli/contains.yaml"
- debug: msg="START common/contains.yaml on connection={{ ansible_connection }}"
- name: test contains operator
nxos_command:
@ -9,11 +9,10 @@
wait_for:
- "result[0] contains NX-OS"
- "result[1].TABLE_interface.ROW_interface.interface contains mgmt"
provider: "{{ cli }}"
register: result
- assert:
that:
- "result.changed == false"
- debug: msg="END cli/contains.yaml"
- debug: msg="END common/contains.yaml on connection={{ ansible_connection }}"

View file

@ -1,5 +1,5 @@
---
- debug: msg="START cli/equal.yaml"
- debug: msg="START common/equal.yaml on connection={{ ansible_connection }}"
- name: test eq operator
nxos_command:
@ -8,7 +8,6 @@
- show interface mgmt0 | json
wait_for:
- "result[1].TABLE_interface.ROW_interface.state eq up"
provider: "{{ cli }}"
register: result
- assert:
@ -22,11 +21,10 @@
- show interface mgmt0 | json
wait_for:
- "result[1].TABLE_interface.ROW_interface.state == up"
provider: "{{ cli }}"
register: result
- assert:
that:
- "result.changed == false"
- debug: msg="END cli/equal.yaml"
- debug: msg="END common/equal.yaml on connection={{ ansible_connection }}"

View file

@ -1,5 +1,5 @@
---
- debug: msg="START cli/greaterthan.yaml"
- debug: msg="START common/greaterthan.yaml on connection={{ ansible_connection }}"
- name: test gt operator
nxos_command:
@ -8,7 +8,6 @@
- show interface mgmt0 | json
wait_for:
- "result[1].TABLE_interface.ROW_interface.eth_ip_mask gt 0"
provider: "{{ cli }}"
register: result
- assert:
@ -22,11 +21,10 @@
- show interface mgmt0 | json
wait_for:
- "result[1].TABLE_interface.ROW_interface.eth_ip_mask > 0"
provider: "{{ cli }}"
register: result
- assert:
that:
- "result.changed == false"
- debug: msg="END cli/greaterthan.yaml"
- debug: msg="END common/greaterthan.yaml on connection={{ ansible_connection }}"

View file

@ -1,5 +1,5 @@
---
- debug: msg="START cli/greaterthanorequal.yaml"
- debug: msg="START common/greaterthanorequal.yaml on connection={{ ansible_connection }}"
- name: test ge operator
nxos_command:
@ -8,7 +8,6 @@
- show interface mgmt0 | json
wait_for:
- "result[1].TABLE_interface.ROW_interface.eth_ip_mask ge 0"
provider: "{{ cli }}"
register: result
- assert:
@ -22,11 +21,10 @@
- show interface mgmt0 | json
wait_for:
- "result[1].TABLE_interface.ROW_interface.eth_ip_mask >= 0"
provider: "{{ cli }}"
register: result
- assert:
that:
- "result.changed == false"
- debug: msg="END cli/greaterthanorequal.yaml"
- debug: msg="END common/greaterthanorequal.yaml on connection={{ ansible_connection }}"

View file

@ -1,10 +1,9 @@
---
- debug: msg="START cli/invalid.yaml"
- debug: msg="START common/invalid.yaml on connection={{ ansible_connection }}"
- name: run invalid command
nxos_command:
commands: ['show foo']
provider: "{{ cli }}"
register: result
ignore_errors: yes
@ -17,7 +16,6 @@
commands:
- show version
- show foo
provider: "{{ cli }}"
register: result
ignore_errors: yes
@ -25,4 +23,4 @@
that:
- "result.failed == true"
- debug: msg="END cli/invalid.yaml"
- debug: msg="END common/invalid.yaml on connection={{ ansible_connection }}"

View file

@ -1,5 +1,5 @@
---
- debug: msg="START cli/lessthan.yaml"
- debug: msg="START common/lessthan.yaml on connection={{ ansible_connection }}"
- name: test lt operator
nxos_command:
@ -8,7 +8,6 @@
- show interface mgmt0 | json
wait_for:
- "result[1].TABLE_interface.ROW_interface.eth_ip_mask lt 33"
provider: "{{ cli }}"
register: result
- assert:
@ -22,11 +21,10 @@
- show interface mgmt0 | json
wait_for:
- "result[1].TABLE_interface.ROW_interface.eth_ip_mask lt 33"
provider: "{{ cli }}"
register: result
- assert:
that:
- "result.changed == false"
- debug: msg="END cli/lessthan.yaml"
- debug: msg="END common/lessthan.yaml on connection={{ ansible_connection }}"

View file

@ -1,5 +1,5 @@
---
- debug: msg="START cli/lessthanorequal.yaml"
- debug: msg="START common/lessthanorequal.yaml on connection={{ ansible_connection }}"
- name: test le operator
nxos_command:
@ -8,7 +8,6 @@
- show interface mgmt0 | json
wait_for:
- "result[1].TABLE_interface.ROW_interface.eth_ip_mask le 32"
provider: "{{ cli }}"
register: result
- assert:
@ -22,11 +21,10 @@
- show interface mgmt0 | json
wait_for:
- "result[1].TABLE_interface.ROW_interface.eth_ip_mask <= 32"
provider: "{{ cli }}"
register: result
- assert:
that:
- "result.changed == false"
- debug: msg="END cli/lessthanorequal.yaml"
- debug: msg="END common/lessthanorequal.yaml on connection={{ ansible_connection }}"

View file

@ -1,29 +0,0 @@
---
- debug: msg="START connection={{ ansible_connection }}/negative.yaml"
- debug: msg="Using provider={{ connection.transport }}"
when: ansible_connection == "local"
- name: run 11 commands
nxos_command:
commands:
- show version
- show version
- show version
- show version
- show version
- show version
- show version
- show version
- show version
- show version
- show version
provier: "{{ connection }}"
ignore_errors: yes
register: result
- assert:
that:
- result.failed
- debug: msg="END connection={{ ansible_connection }}/negative.yaml"

View file

@ -1,5 +1,5 @@
---
- debug: msg="START cli/notequal.yaml"
- debug: msg="START common/notequal.yaml on connection={{ ansible_connection }}"
- name: test neq operator
nxos_command:
@ -8,7 +8,6 @@
- show interface mgmt0 | json
wait_for:
- "result[1].TABLE_interface.ROW_interface.state neq down"
provider: "{{ cli }}"
register: result
- assert:
@ -23,7 +22,6 @@
- show interface mgmt0 | json
wait_for:
- "result[1].TABLE_interface.ROW_interface.state != down"
provider: "{{ cli }}"
register: result
- assert:
@ -31,4 +29,4 @@
- "result.changed == false"
- "result.stdout is defined"
- debug: msg="END cli/notequal.yaml"
- debug: msg="END common/notequal.yaml on connection={{ ansible_connection }}"

View file

@ -1,10 +1,9 @@
---
- debug: msg="START cli/output.yaml"
- debug: msg="START common/output.yaml on connection={{ ansible_connection }}"
- name: get output for single command
nxos_command:
commands: ['show version']
provider: "{{ cli }}"
register: result
- assert:
@ -16,11 +15,10 @@
commands:
- show version
- show interface
provider: "{{ cli }}"
register: result
- assert:
that:
- "result.changed == false"
- debug: msg="END cli/output.yaml"
- debug: msg="END common/output.yaml on connection={{ ansible_connection }}"

View file

@ -1,5 +1,5 @@
---
- debug: msg="START cli/timeout.yaml"
- debug: msg="START common/timeout.yaml on connection={{ ansible_connection }}"
- name: test bad condition
nxos_command:
@ -7,7 +7,6 @@
- show version
wait_for:
- "result[0] contains bad_value_string"
provider: "{{ cli }}"
register: result
ignore_errors: yes
@ -16,4 +15,4 @@
- "result.failed == true"
- "result.msg is defined"
- debug: msg="END cli/timeout.yaml"
- debug: msg="END common/timeout.yaml on connection={{ ansible_connection }}"

View file

@ -1,20 +0,0 @@
---
- debug: msg="START nxapi/bad_operator.yaml"
- name: test bad operator
nxos_command:
commands:
- show version
- show interface mgmt0
wait_for:
- "result[1].TABLE_interface.ROW_interface.state foo up"
provider: "{{ nxapi }}"
register: result
ignore_errors: yes
- assert:
that:
- "result.failed == true"
- "result.msg is defined"
- debug: msg="END nxapi/bad_operator.yaml"

View file

@ -1,20 +0,0 @@
---
- debug: msg="START nxapi/contains.yaml"
- name: test contains operator
nxos_command:
commands:
- show version
- show interface mgmt0
wait_for:
- "result[0].header_str contains NX-OS"
- "result[1].TABLE_interface.ROW_interface.interface contains mgmt"
provider: "{{ nxapi }}"
register: result
- assert:
that:
- "result.changed == false"
- "result.stdout is defined"
- debug: msg="END nxapi/contains.yaml"

View file

@ -1,34 +0,0 @@
---
- debug: msg="START nxapi/equal.yaml"
- name: test eq operator
nxos_command:
commands:
- show version
- show interface mgmt0
wait_for:
- "result[1].TABLE_interface.ROW_interface.state eq up"
provider: "{{ nxapi }}"
register: result
- assert:
that:
- "result.changed == false"
- "result.stdout is defined"
- name: test == operator
nxos_command:
commands:
- show version
- show interface mgmt0
wait_for:
- "result[1].TABLE_interface.ROW_interface.state == up"
provider: "{{ nxapi }}"
register: result
- assert:
that:
- "result.changed == false"
- "result.stdout is defined"
- debug: msg="END nxapi/equal.yaml"

View file

@ -1,34 +0,0 @@
---
- debug: msg="START nxapi/greaterthan.yaml"
- name: test gt operator
nxos_command:
commands:
- show version
- show interface mgmt0
wait_for:
- "result[1].TABLE_interface.ROW_interface.eth_ip_mask gt 0"
provider: "{{ nxapi }}"
register: result
- assert:
that:
- "result.changed == false"
- "result.stdout is defined"
- name: test > operator
nxos_command:
commands:
- show version
- show interface mgmt0
wait_for:
- "result[1].TABLE_interface.ROW_interface.eth_ip_mask gt 0"
provider: "{{ nxapi }}"
register: result
- assert:
that:
- "result.changed == false"
- "result.stdout is defined"
- debug: msg="END nxapi/greaterthan.yaml"

View file

@ -1,34 +0,0 @@
---
- debug: msg="START nxapi/greaterthanorequal.yaml"
- name: test ge operator
nxos_command:
commands:
- show version
- show interface mgmt0
wait_for:
- "result[1].TABLE_interface.ROW_interface.eth_ip_mask ge 0"
provider: "{{ nxapi }}"
register: result
- assert:
that:
- "result.changed == false"
- "result.stdout is defined"
- name: test >= operator
nxos_command:
commands:
- show version
- show interface mgmt0
wait_for:
- "result[1].TABLE_interface.ROW_interface.eth_ip_mask >= 0"
provider: "{{ nxapi }}"
register: result
- assert:
that:
- "result.changed == false"
- "result.stdout is defined"
- debug: msg="END nxapi/greaterthanorequal.yaml"

View file

@ -1,30 +0,0 @@
---
- debug: msg="START nxapi/invalid.yaml"
- name: run invalid command
nxos_command:
commands: ['show foo']
provider: "{{ nxapi }}"
register: result
ignore_errors: yes
- assert:
that:
- "result.failed == true"
- "result.msg is defined"
- name: run commands that include invalid command
nxos_command:
commands:
- show version
- show foo
provider: "{{ nxapi }}"
register: result
ignore_errors: yes
- assert:
that:
- "result.failed == true"
- "result.msg is defined"
- debug: msg="END nxapi/invalid.yaml"

View file

@ -1,34 +0,0 @@
---
- debug: msg="START nxapi/lessthan.yaml"
- name: test lt operator
nxos_command:
commands:
- show version
- show interface mgmt0
wait_for:
- "result[1].TABLE_interface.ROW_interface.eth_ip_mask lt 33"
provider: "{{ nxapi }}"
register: result
- assert:
that:
- "result.changed == false"
- "result.stdout is defined"
- name: test < operator
nxos_command:
commands:
- show version
- show interface mgmt0
wait_for:
- "result[1].TABLE_interface.ROW_interface.eth_ip_mask lt 33"
provider: "{{ nxapi }}"
register: result
- assert:
that:
- "result.changed == false"
- "result.stdout is defined"
- debug: msg="END nxapi/lessthan.yaml"

View file

@ -1,34 +0,0 @@
---
- debug: msg="START nxapi/lessthanorequal.yaml"
- name: test le operator
nxos_command:
commands:
- show version
- show interface mgmt0
wait_for:
- "result[1].TABLE_interface.ROW_interface.eth_ip_mask le 32"
provider: "{{ nxapi }}"
register: result
- assert:
that:
- "result.changed == false"
- "result.stdout is defined"
- name: test <= operator
nxos_command:
commands:
- show version
- show interface mgmt0
wait_for:
- "result[1].TABLE_interface.ROW_interface.eth_ip_mask <= 32"
provider: "{{ nxapi }}"
register: result
- assert:
that:
- "result.changed == false"
- "result.stdout is defined"
- debug: msg="END nxapi/lessthanorequal.yaml"

View file

@ -1,34 +0,0 @@
---
- debug: msg="START nxapi/notequal.yaml"
- name: test neq operator
nxos_command:
commands:
- show version
- show interface mgmt0
wait_for:
- "result[1].TABLE_interface.ROW_interface.state neq down"
provider: "{{ nxapi }}"
register: result
- assert:
that:
- "result.changed == false"
- "result.stdout is defined"
- name: test != operator
nxos_command:
commands:
- show version
- show interface mgmt0
wait_for:
- "result[1].TABLE_interface.ROW_interface.state != down"
provider: "{{ nxapi }}"
register: result
- assert:
that:
- "result.changed == false"
- "result.stdout is defined"
- debug: msg="START nxapi/notequal.yaml"

View file

@ -1,28 +0,0 @@
---
- debug: msg="START nxapi/output.yaml"
- name: get output for single command
nxos_command:
commands: ['show version']
provider: "{{ nxapi }}"
register: result
- assert:
that:
- "result.changed == false"
- "result.stdout is defined"
- name: get output for multiple commands
nxos_command:
commands:
- show version
- show interface
provider: "{{ nxapi }}"
register: result
- assert:
that:
- "result.changed == false"
- "result.stdout is defined"
- debug: msg="END nxapi/output.yaml"

View file

@ -1,20 +1,16 @@
---
- debug: msg="START TRANSPORT:NXAPI nxos_command sanity test"
- debug: msg="Using provider={{ connection.transport }}"
when: ansible_connection == "local"
- debug: msg="START nxapi/sanity.yaml on connection={{ ansible_connection }}"
- name: "Disable feature BGP"
nxos_feature:
feature: bgp
state: disabled
provider: "{{ nxapi }}"
- block:
- name: "Run show running-config bgp - should fail"
nxos_command:
commands:
- sh running-config bgp
provider: "{{ nxapi }}"
ignore_errors: yes
register: result
@ -26,14 +22,12 @@
nxos_feature:
feature: bgp
state: enabled
provider: "{{ nxapi }}"
- name: "Configure BGP defaults"
nxos_bgp: &configure_default
asn: 65535
router_id: 1.1.1.1
state: present
provider: "{{ nxapi }}"
register: result
- assert: &true
@ -43,10 +37,7 @@
- name: "Run show running-config bgp - should pass"
nxos_command:
commands:
- command: sh running-config bgp
output: text
provider: "{{ nxapi }}"
timeout: 120
- sh running-config bgp
register: result
- assert:
@ -58,7 +49,6 @@
nxos_command:
commands:
- show interface bief
provider: "{{ nxapi }}"
ignore_errors: yes
register: result
@ -72,6 +62,5 @@
nxos_feature:
feature: bgp
state: disabled
provider: "{{ nxapi }}"
- debug: msg="END TRANSPORT:NXAPI nxos_command sanity test"
- debug: msg="END nxapi/sanity.yaml on connection={{ ansible_connection }}"

View file

@ -1,20 +0,0 @@
---
- debug: msg="START nxapi/timeout.yaml"
- name: test bad condition
nxos_command:
commands:
- show version
wait_for:
- "result[0].header_str contains foo"
retries: 1
provider: "{{ nxapi }}"
register: result
ignore_errors: yes
- assert:
that:
- "result.failed == true"
- "result.msg is defined"
- debug: msg="END nxapi/timeout.yaml"