Fix eos_facts over local eapi (#64570)
* Fix eos_facts over local eapi * Much better feedback when querying resources over local * No need for that anymore * Update comment * Mkae sure facts are tested on local resource modules might break this otherwise * This test was not checking anything * Pass over nxos_facts as well
This commit is contained in:
parent
9dc94b32d2
commit
fed0496005
17 changed files with 59 additions and 116 deletions
|
@ -216,6 +216,10 @@ def get_resource_connection(module):
|
||||||
module._connection = Connection(module._socket_path)
|
module._connection = Connection(module._socket_path)
|
||||||
elif network_api == 'netconf':
|
elif network_api == 'netconf':
|
||||||
module._connection = NetconfConnection(module._socket_path)
|
module._connection = NetconfConnection(module._socket_path)
|
||||||
|
elif network_api == "local":
|
||||||
|
# This isn't supported, but we shouldn't fail here.
|
||||||
|
# Set the connection to a fake connection so it fails sensibly.
|
||||||
|
module._connection = LocalResourceConnection(module)
|
||||||
else:
|
else:
|
||||||
module.fail_json(msg='Invalid connection type {0!s}'.format(network_api))
|
module.fail_json(msg='Invalid connection type {0!s}'.format(network_api))
|
||||||
|
|
||||||
|
@ -229,6 +233,17 @@ def get_capabilities(module):
|
||||||
capabilities = Connection(module._socket_path).get_capabilities()
|
capabilities = Connection(module._socket_path).get_capabilities()
|
||||||
except ConnectionError as exc:
|
except ConnectionError as exc:
|
||||||
module.fail_json(msg=to_text(exc, errors='surrogate_then_replace'))
|
module.fail_json(msg=to_text(exc, errors='surrogate_then_replace'))
|
||||||
|
except AssertionError:
|
||||||
|
# No socket_path, connection most likely local.
|
||||||
|
return dict(network_api="local")
|
||||||
module._capabilities = json.loads(capabilities)
|
module._capabilities = json.loads(capabilities)
|
||||||
|
|
||||||
return module._capabilities
|
return module._capabilities
|
||||||
|
|
||||||
|
|
||||||
|
class LocalResourceConnection:
|
||||||
|
def __init__(self, module):
|
||||||
|
self.module = module
|
||||||
|
|
||||||
|
def get(self, *args, **kwargs):
|
||||||
|
self.module.fail_json(msg="Network resource modules not supported over local connection.")
|
||||||
|
|
|
@ -388,6 +388,15 @@ class LocalEapi:
|
||||||
diff['config_diff'] = configdiff if configdiffobjs else {}
|
diff['config_diff'] = configdiff if configdiffobjs else {}
|
||||||
return diff
|
return diff
|
||||||
|
|
||||||
|
def get_capabilities(self):
|
||||||
|
# Implement the bare minimum to support eos_facts
|
||||||
|
return dict(
|
||||||
|
device_info=dict(
|
||||||
|
network_os="eos",
|
||||||
|
),
|
||||||
|
network_api="eapi",
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class HttpApi:
|
class HttpApi:
|
||||||
def __init__(self, module):
|
def __init__(self, module):
|
||||||
|
|
|
@ -329,7 +329,7 @@ class LocalNxapi:
|
||||||
|
|
||||||
headers = {'Content-Type': 'application/json'}
|
headers = {'Content-Type': 'application/json'}
|
||||||
result = list()
|
result = list()
|
||||||
timeout = self._module.params['timeout']
|
timeout = self._module.params['provider']['timeout']
|
||||||
use_proxy = self._module.params['provider']['use_proxy']
|
use_proxy = self._module.params['provider']['use_proxy']
|
||||||
|
|
||||||
for req in requests:
|
for req in requests:
|
||||||
|
|
|
@ -14,3 +14,9 @@
|
||||||
with_items: "{{ test_items }}"
|
with_items: "{{ test_items }}"
|
||||||
loop_control:
|
loop_control:
|
||||||
loop_var: test_case_to_run
|
loop_var: test_case_to_run
|
||||||
|
|
||||||
|
- name: run test cases (connection=local)
|
||||||
|
include: "{{ test_case_to_run }} ansible_connection=local"
|
||||||
|
with_items: "{{ test_items }}"
|
||||||
|
loop_control:
|
||||||
|
loop_var: test_case_to_run
|
||||||
|
|
|
@ -3,8 +3,8 @@
|
||||||
find:
|
find:
|
||||||
paths: "{{ role_path }}/tests/eapi"
|
paths: "{{ role_path }}/tests/eapi"
|
||||||
patterns: "{{ testcase }}.yaml"
|
patterns: "{{ testcase }}.yaml"
|
||||||
delegate_to: localhost
|
|
||||||
register: test_cases
|
register: test_cases
|
||||||
|
delegate_to: localhost
|
||||||
|
|
||||||
- name: set test_items
|
- name: set test_items
|
||||||
set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}"
|
set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}"
|
||||||
|
@ -14,3 +14,9 @@
|
||||||
with_items: "{{ test_items }}"
|
with_items: "{{ test_items }}"
|
||||||
loop_control:
|
loop_control:
|
||||||
loop_var: test_case_to_run
|
loop_var: test_case_to_run
|
||||||
|
|
||||||
|
- name: run test cases (connection=local)
|
||||||
|
include: "{{ test_case_to_run }} ansible_connection=local"
|
||||||
|
with_items: "{{ test_items }}"
|
||||||
|
loop_control:
|
||||||
|
loop_var: test_case_to_run
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
---
|
---
|
||||||
- debug: msg="START cli/all_facts.yaml on connection={{ ansible_connection }}"
|
- debug: msg="START cli/all_facts.yaml on connection={{ ansible_connection }}"
|
||||||
|
|
||||||
|
|
||||||
- name: test getting all facts
|
- name: test getting all facts
|
||||||
eos_facts:
|
eos_facts:
|
||||||
gather_subset:
|
gather_subset:
|
||||||
- all
|
- all
|
||||||
|
provider: "{{ cli }}"
|
||||||
become: yes
|
become: yes
|
||||||
register: result
|
register: result
|
||||||
|
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
---
|
---
|
||||||
- debug: msg="START cli/default_facts.yaml on connection={{ ansible_connection }}"
|
- debug: msg="START cli/default_facts.yaml on connection={{ ansible_connection }}"
|
||||||
|
|
||||||
|
|
||||||
- name: test getting default facts
|
- name: test getting default facts
|
||||||
eos_facts:
|
eos_facts:
|
||||||
|
provider: "{{ cli }}"
|
||||||
become: yes
|
become: yes
|
||||||
register: result
|
register: result
|
||||||
|
|
||||||
|
@ -28,4 +28,4 @@
|
||||||
# ... and not present
|
# ... and not present
|
||||||
- "result.ansible_facts.ansible_net_config is not defined" # config
|
- "result.ansible_facts.ansible_net_config is not defined" # config
|
||||||
|
|
||||||
- debug: msg="END cli/default.yaml on connection={{ ansible_connection }}"
|
- debug: msg="END cli/default_facts.yaml on connection={{ ansible_connection }}"
|
||||||
|
|
|
@ -1,11 +1,12 @@
|
||||||
---
|
---
|
||||||
- debug: msg="START cli/invalid_subset.yaml on connection={{ ansible_connection }}"
|
- debug: msg="START cli/invalid_subset.yaml on connection={{ ansible_connection }}"
|
||||||
|
|
||||||
|
|
||||||
- name: test invalid subset (foobar)
|
- name: test invalid subset (foobar)
|
||||||
eos_facts:
|
eos_facts:
|
||||||
gather_subset:
|
gather_subset:
|
||||||
- "foobar"
|
- "foobar"
|
||||||
|
provider: "{{ cli }}"
|
||||||
|
become: yes
|
||||||
register: result
|
register: result
|
||||||
ignore_errors: true
|
ignore_errors: true
|
||||||
|
|
||||||
|
@ -19,28 +20,4 @@
|
||||||
# Sensible Failure message
|
# Sensible Failure message
|
||||||
- "'Subset must be one of' in result.msg"
|
- "'Subset must be one of' in result.msg"
|
||||||
|
|
||||||
###############
|
|
||||||
# FIXME Future
|
|
||||||
# We may in the future want to add a test for
|
|
||||||
|
|
||||||
- name: test subset specified multiple times
|
|
||||||
eos_facts:
|
|
||||||
gather_subset:
|
|
||||||
- "!hardware"
|
|
||||||
- "hardware"
|
|
||||||
register: result
|
|
||||||
ignore_errors: true
|
|
||||||
|
|
||||||
- assert:
|
|
||||||
that:
|
|
||||||
# Failures shouldn't return changes
|
|
||||||
- "result.changed == false"
|
|
||||||
# It's a failure
|
|
||||||
- "result.failed == true"
|
|
||||||
# Sensible Failure message
|
|
||||||
- "'Subset must be one of' in result.msg"
|
|
||||||
ignore_errors: true
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
- debug: msg="END cli/invalid_subset.yaml on connection={{ ansible_connection }}"
|
- debug: msg="END cli/invalid_subset.yaml on connection={{ ansible_connection }}"
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
---
|
---
|
||||||
- debug: msg="START cli/not_hardware.yaml on connection={{ ansible_connection }}"
|
- debug: msg="START cli/not_hardware.yaml on connection={{ ansible_connection }}"
|
||||||
|
|
||||||
|
|
||||||
- name: test not hardware
|
- name: test not hardware
|
||||||
eos_facts:
|
eos_facts:
|
||||||
gather_subset:
|
gather_subset:
|
||||||
- "!hardware"
|
- "!hardware"
|
||||||
|
provider: "{{ cli }}"
|
||||||
become: yes
|
become: yes
|
||||||
register: result
|
register: result
|
||||||
|
|
||||||
|
|
|
@ -1,15 +1,11 @@
|
||||||
---
|
---
|
||||||
- debug: msg="START eapi/all_facts.yaml"
|
- debug: msg="START eapi/all_facts.yaml on connection={{ ansible_connection }}"
|
||||||
|
|
||||||
- name: Make sure LLDP is running (setup)
|
|
||||||
eos_config:
|
|
||||||
lines: lldp run
|
|
||||||
become: yes
|
|
||||||
|
|
||||||
- name: test getting all facts
|
- name: test getting all facts
|
||||||
eos_facts:
|
eos_facts:
|
||||||
gather_subset:
|
gather_subset:
|
||||||
- all
|
- all
|
||||||
|
provider: "{{ eapi }}"
|
||||||
become: yes
|
become: yes
|
||||||
register: result
|
register: result
|
||||||
|
|
||||||
|
@ -30,4 +26,4 @@
|
||||||
- "result.ansible_facts.ansible_net_memfree_mb > 1"
|
- "result.ansible_facts.ansible_net_memfree_mb > 1"
|
||||||
- "result.ansible_facts.ansible_net_memtotal_mb > 1"
|
- "result.ansible_facts.ansible_net_memtotal_mb > 1"
|
||||||
|
|
||||||
- debug: msg="END eapi/all_facts.yaml"
|
- debug: msg="END eapi/all_facts.yaml on connection={{ ansible_connection }}"
|
||||||
|
|
|
@ -1,13 +1,9 @@
|
||||||
---
|
---
|
||||||
- debug: msg="START eapi/default_facts.yaml"
|
- debug: msg="START eapi/default_facts.yaml on connection={{ ansible_connection }}"
|
||||||
|
|
||||||
- name: Make sure LLDP is running (setup)
|
|
||||||
eos_config:
|
|
||||||
lines: lldp run
|
|
||||||
become: yes
|
|
||||||
|
|
||||||
- name: test getting default facts
|
- name: test getting default facts
|
||||||
eos_facts:
|
eos_facts:
|
||||||
|
provider: "{{ eapi }}"
|
||||||
become: yes
|
become: yes
|
||||||
register: result
|
register: result
|
||||||
|
|
||||||
|
@ -32,4 +28,4 @@
|
||||||
# ... and not present
|
# ... and not present
|
||||||
- "result.ansible_facts.ansible_net_config is not defined" # config
|
- "result.ansible_facts.ansible_net_config is not defined" # config
|
||||||
|
|
||||||
- debug: msg="END eapi/default.yaml"
|
- debug: msg="END eapi/default_facts.yaml on connection={{ ansible_connection }}"
|
||||||
|
|
|
@ -1,11 +1,12 @@
|
||||||
---
|
---
|
||||||
- debug: msg="START eapi/invalid_subset.yaml"
|
- debug: msg="START eapi/invalid_subset.yaml on connection={{ ansible_connection }}"
|
||||||
|
|
||||||
|
|
||||||
- name: test invalid subset (foobar)
|
- name: test invalid subset (foobar)
|
||||||
eos_facts:
|
eos_facts:
|
||||||
gather_subset:
|
gather_subset:
|
||||||
- "foobar"
|
- "foobar"
|
||||||
|
provider: "{{ eapi }}"
|
||||||
|
become: yes
|
||||||
register: result
|
register: result
|
||||||
ignore_errors: true
|
ignore_errors: true
|
||||||
|
|
||||||
|
@ -19,28 +20,4 @@
|
||||||
# Sensible Failure message
|
# Sensible Failure message
|
||||||
- "'Subset must be one of' in result.msg"
|
- "'Subset must be one of' in result.msg"
|
||||||
|
|
||||||
###############
|
- debug: msg="END eapi/invalid_subset.yaml on connection={{ ansible_connection }}"
|
||||||
# FIXME Future
|
|
||||||
# We may in the future want to add a test for
|
|
||||||
|
|
||||||
- name: test subset specified multiple times
|
|
||||||
eos_facts:
|
|
||||||
gather_subset:
|
|
||||||
- "!hardware"
|
|
||||||
- "hardware"
|
|
||||||
register: result
|
|
||||||
ignore_errors: true
|
|
||||||
|
|
||||||
- assert:
|
|
||||||
that:
|
|
||||||
# Failures shouldn't return changes
|
|
||||||
- "result.changed == false"
|
|
||||||
# It's a failure
|
|
||||||
- "result.failed == true"
|
|
||||||
# Sensible Failure message
|
|
||||||
#- "result.msg == 'Bad subset'"
|
|
||||||
ignore_errors: true
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
- debug: msg="END eapi/invalid_subset.yaml"
|
|
||||||
|
|
|
@ -1,15 +1,11 @@
|
||||||
---
|
---
|
||||||
- debug: msg="START eapi/not_hardware.yaml"
|
- debug: msg="START eapi/not_hardware.yaml on connection={{ ansible_connection }}"
|
||||||
|
|
||||||
- name: Make sure LLDP is running (setup)
|
|
||||||
eos_config:
|
|
||||||
lines: lldp run
|
|
||||||
become: yes
|
|
||||||
|
|
||||||
- name: test not hardware
|
- name: test not hardware
|
||||||
eos_facts:
|
eos_facts:
|
||||||
gather_subset:
|
gather_subset:
|
||||||
- "!hardware"
|
- "!hardware"
|
||||||
|
provider: "{{ eapi }}"
|
||||||
become: yes
|
become: yes
|
||||||
register: result
|
register: result
|
||||||
|
|
||||||
|
@ -31,4 +27,4 @@
|
||||||
# ... and not present
|
# ... and not present
|
||||||
- "result.ansible_facts.ansible_net_filesystems is not defined"
|
- "result.ansible_facts.ansible_net_filesystems is not defined"
|
||||||
|
|
||||||
- debug: msg="END eapi/not_hardware.yaml"
|
- debug: msg="END eapi/not_hardware.yaml on connection={{ ansible_connection }}"
|
||||||
|
|
|
@ -3,17 +3,13 @@
|
||||||
- debug: msg="Using provider={{ connection.transport }}"
|
- debug: msg="Using provider={{ connection.transport }}"
|
||||||
when: ansible_connection == "local"
|
when: ansible_connection == "local"
|
||||||
|
|
||||||
|
|
||||||
- name: test getting all facts
|
- name: test getting all facts
|
||||||
nxos_facts:
|
nxos_facts:
|
||||||
gather_subset:
|
gather_subset:
|
||||||
- all
|
- all
|
||||||
timeout: 60
|
|
||||||
provider: "{{ connection }}"
|
provider: "{{ connection }}"
|
||||||
register: result
|
register: result
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
- assert:
|
- assert:
|
||||||
that:
|
that:
|
||||||
# _facts modules should never report a change
|
# _facts modules should never report a change
|
||||||
|
|
|
@ -3,7 +3,6 @@
|
||||||
- debug: msg="Using provider={{ connection.transport }}"
|
- debug: msg="Using provider={{ connection.transport }}"
|
||||||
when: ansible_connection == "local"
|
when: ansible_connection == "local"
|
||||||
|
|
||||||
|
|
||||||
- name: test getting default facts
|
- name: test getting default facts
|
||||||
nxos_facts:
|
nxos_facts:
|
||||||
provider: "{{ connection }}"
|
provider: "{{ connection }}"
|
||||||
|
@ -27,7 +26,7 @@
|
||||||
- "result.ansible_facts.ansible_net_memtotal_mb > 10" #hw
|
- "result.ansible_facts.ansible_net_memtotal_mb > 10" #hw
|
||||||
- "result.ansible_facts.ansible_net_model is defined" #default
|
- "result.ansible_facts.ansible_net_model is defined" #default
|
||||||
- "result.ansible_facts.ansible_net_interfaces is defined" #interfaces
|
- "result.ansible_facts.ansible_net_interfaces is defined" #interfaces
|
||||||
# FIXME
|
# FIXME
|
||||||
# - "result.ansible_facts.ansible_net_interfaces.Ethernet1.ipv4.masklen > 1" # interfaces
|
# - "result.ansible_facts.ansible_net_interfaces.Ethernet1.ipv4.masklen > 1" # interfaces
|
||||||
|
|
||||||
# ... and not present
|
# ... and not present
|
||||||
|
|
|
@ -3,7 +3,6 @@
|
||||||
- debug: msg="Using provider={{ connection.transport }}"
|
- debug: msg="Using provider={{ connection.transport }}"
|
||||||
when: ansible_connection == "local"
|
when: ansible_connection == "local"
|
||||||
|
|
||||||
|
|
||||||
- name: test invalid subset (foobar)
|
- name: test invalid subset (foobar)
|
||||||
nxos_facts:
|
nxos_facts:
|
||||||
gather_subset:
|
gather_subset:
|
||||||
|
@ -12,7 +11,6 @@
|
||||||
register: result
|
register: result
|
||||||
ignore_errors: true
|
ignore_errors: true
|
||||||
|
|
||||||
|
|
||||||
- assert:
|
- assert:
|
||||||
that:
|
that:
|
||||||
# Failures shouldn't return changes
|
# Failures shouldn't return changes
|
||||||
|
@ -22,29 +20,4 @@
|
||||||
# Sensible Failure message
|
# Sensible Failure message
|
||||||
- "'Subset must be one of' in result.msg"
|
- "'Subset must be one of' in result.msg"
|
||||||
|
|
||||||
###############
|
|
||||||
# FIXME Future
|
|
||||||
# We may in the future want to add a test for
|
|
||||||
|
|
||||||
- name: test subset specified multiple times
|
|
||||||
nxos_facts:
|
|
||||||
gather_subset:
|
|
||||||
- "!hardware"
|
|
||||||
- "hardware"
|
|
||||||
provider: "{{ connection }}"
|
|
||||||
register: result
|
|
||||||
ignore_errors: true
|
|
||||||
|
|
||||||
- assert:
|
|
||||||
that:
|
|
||||||
# Failures shouldn't return changes
|
|
||||||
- "result.changed == false"
|
|
||||||
# It's a failure
|
|
||||||
- "result.failed == true"
|
|
||||||
# Sensible Failure message
|
|
||||||
- "result.msg == 'Bad subset'"
|
|
||||||
ignore_errors: true
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
- debug: msg="END connection={{ ansible_connection }}/invalid_subset.yaml"
|
- debug: msg="END connection={{ ansible_connection }}/invalid_subset.yaml"
|
||||||
|
|
|
@ -3,12 +3,10 @@
|
||||||
- debug: msg="Using provider={{ connection.transport }}"
|
- debug: msg="Using provider={{ connection.transport }}"
|
||||||
when: ansible_connection == "local"
|
when: ansible_connection == "local"
|
||||||
|
|
||||||
|
|
||||||
- name: test not hardware
|
- name: test not hardware
|
||||||
nxos_facts:
|
nxos_facts:
|
||||||
gather_subset:
|
gather_subset:
|
||||||
- "!hardware"
|
- "!hardware"
|
||||||
timeout: 30
|
|
||||||
provider: "{{ connection }}"
|
provider: "{{ connection }}"
|
||||||
register: result
|
register: result
|
||||||
|
|
||||||
|
@ -21,13 +19,12 @@
|
||||||
- "'config' in result.ansible_facts.ansible_net_gather_subset"
|
- "'config' in result.ansible_facts.ansible_net_gather_subset"
|
||||||
- "'default' in result.ansible_facts.ansible_net_gather_subset"
|
- "'default' in result.ansible_facts.ansible_net_gather_subset"
|
||||||
- "'interfaces' in result.ansible_facts.ansible_net_gather_subset"
|
- "'interfaces' in result.ansible_facts.ansible_net_gather_subset"
|
||||||
|
|
||||||
# ... and not present
|
# ... and not present
|
||||||
- "'hardware' not in result.ansible_facts.ansible_net_gather_subset"
|
- "'hardware' not in result.ansible_facts.ansible_net_gather_subset"
|
||||||
|
|
||||||
# Items from those subsets are present
|
# Items from those subsets are present
|
||||||
# FIXME
|
# FIXME
|
||||||
# - "result.ansible_facts.ansible_net_interfaces.['Ethernet2/15'].mtu > 1" # interfaces
|
# - "result.ansible_facts.ansible_net_interfaces.['Ethernet2/15'].mtu > 1" # interfaces
|
||||||
# ... and not present
|
# ... and not present
|
||||||
- "result.ansible_facts.ansible_net_filesystems is not defined"
|
- "result.ansible_facts.ansible_net_filesystems is not defined"
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue