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)
|
||||
elif network_api == 'netconf':
|
||||
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:
|
||||
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()
|
||||
except ConnectionError as exc:
|
||||
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)
|
||||
|
||||
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 {}
|
||||
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:
|
||||
def __init__(self, module):
|
||||
|
|
|
@ -329,7 +329,7 @@ class LocalNxapi:
|
|||
|
||||
headers = {'Content-Type': 'application/json'}
|
||||
result = list()
|
||||
timeout = self._module.params['timeout']
|
||||
timeout = self._module.params['provider']['timeout']
|
||||
use_proxy = self._module.params['provider']['use_proxy']
|
||||
|
||||
for req in requests:
|
||||
|
|
|
@ -14,3 +14,9 @@
|
|||
with_items: "{{ test_items }}"
|
||||
loop_control:
|
||||
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:
|
||||
paths: "{{ role_path }}/tests/eapi"
|
||||
patterns: "{{ testcase }}.yaml"
|
||||
delegate_to: localhost
|
||||
register: test_cases
|
||||
delegate_to: localhost
|
||||
|
||||
- name: set test_items
|
||||
set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}"
|
||||
|
@ -14,3 +14,9 @@
|
|||
with_items: "{{ test_items }}"
|
||||
loop_control:
|
||||
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 }}"
|
||||
|
||||
|
||||
- name: test getting all facts
|
||||
eos_facts:
|
||||
gather_subset:
|
||||
- all
|
||||
provider: "{{ cli }}"
|
||||
become: yes
|
||||
register: result
|
||||
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
---
|
||||
- debug: msg="START cli/default_facts.yaml on connection={{ ansible_connection }}"
|
||||
|
||||
|
||||
- name: test getting default facts
|
||||
eos_facts:
|
||||
provider: "{{ cli }}"
|
||||
become: yes
|
||||
register: result
|
||||
|
||||
|
@ -28,4 +28,4 @@
|
|||
# ... and not present
|
||||
- "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 }}"
|
||||
|
||||
|
||||
- name: test invalid subset (foobar)
|
||||
eos_facts:
|
||||
gather_subset:
|
||||
- "foobar"
|
||||
provider: "{{ cli }}"
|
||||
become: yes
|
||||
register: result
|
||||
ignore_errors: true
|
||||
|
||||
|
@ -19,28 +20,4 @@
|
|||
# Sensible Failure message
|
||||
- "'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 }}"
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
---
|
||||
- debug: msg="START cli/not_hardware.yaml on connection={{ ansible_connection }}"
|
||||
|
||||
|
||||
- name: test not hardware
|
||||
eos_facts:
|
||||
gather_subset:
|
||||
- "!hardware"
|
||||
provider: "{{ cli }}"
|
||||
become: yes
|
||||
register: result
|
||||
|
||||
|
|
|
@ -1,15 +1,11 @@
|
|||
---
|
||||
- debug: msg="START eapi/all_facts.yaml"
|
||||
|
||||
- name: Make sure LLDP is running (setup)
|
||||
eos_config:
|
||||
lines: lldp run
|
||||
become: yes
|
||||
- debug: msg="START eapi/all_facts.yaml on connection={{ ansible_connection }}"
|
||||
|
||||
- name: test getting all facts
|
||||
eos_facts:
|
||||
gather_subset:
|
||||
- all
|
||||
provider: "{{ eapi }}"
|
||||
become: yes
|
||||
register: result
|
||||
|
||||
|
@ -30,4 +26,4 @@
|
|||
- "result.ansible_facts.ansible_net_memfree_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"
|
||||
|
||||
- name: Make sure LLDP is running (setup)
|
||||
eos_config:
|
||||
lines: lldp run
|
||||
become: yes
|
||||
- debug: msg="START eapi/default_facts.yaml on connection={{ ansible_connection }}"
|
||||
|
||||
- name: test getting default facts
|
||||
eos_facts:
|
||||
provider: "{{ eapi }}"
|
||||
become: yes
|
||||
register: result
|
||||
|
||||
|
@ -32,4 +28,4 @@
|
|||
# ... and not present
|
||||
- "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)
|
||||
eos_facts:
|
||||
gather_subset:
|
||||
- "foobar"
|
||||
provider: "{{ eapi }}"
|
||||
become: yes
|
||||
register: result
|
||||
ignore_errors: true
|
||||
|
||||
|
@ -19,28 +20,4 @@
|
|||
# Sensible Failure message
|
||||
- "'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
|
||||
#- "result.msg == 'Bad subset'"
|
||||
ignore_errors: true
|
||||
|
||||
|
||||
|
||||
- debug: msg="END eapi/invalid_subset.yaml"
|
||||
- debug: msg="END eapi/invalid_subset.yaml on connection={{ ansible_connection }}"
|
||||
|
|
|
@ -1,15 +1,11 @@
|
|||
---
|
||||
- debug: msg="START eapi/not_hardware.yaml"
|
||||
|
||||
- name: Make sure LLDP is running (setup)
|
||||
eos_config:
|
||||
lines: lldp run
|
||||
become: yes
|
||||
- debug: msg="START eapi/not_hardware.yaml on connection={{ ansible_connection }}"
|
||||
|
||||
- name: test not hardware
|
||||
eos_facts:
|
||||
gather_subset:
|
||||
- "!hardware"
|
||||
provider: "{{ eapi }}"
|
||||
become: yes
|
||||
register: result
|
||||
|
||||
|
@ -31,4 +27,4 @@
|
|||
# ... and not present
|
||||
- "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 }}"
|
||||
when: ansible_connection == "local"
|
||||
|
||||
|
||||
- name: test getting all facts
|
||||
nxos_facts:
|
||||
gather_subset:
|
||||
- all
|
||||
timeout: 60
|
||||
provider: "{{ connection }}"
|
||||
register: result
|
||||
|
||||
|
||||
|
||||
- assert:
|
||||
that:
|
||||
# _facts modules should never report a change
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
- debug: msg="Using provider={{ connection.transport }}"
|
||||
when: ansible_connection == "local"
|
||||
|
||||
|
||||
- name: test getting default facts
|
||||
nxos_facts:
|
||||
provider: "{{ connection }}"
|
||||
|
@ -27,7 +26,7 @@
|
|||
- "result.ansible_facts.ansible_net_memtotal_mb > 10" #hw
|
||||
- "result.ansible_facts.ansible_net_model is defined" #default
|
||||
- "result.ansible_facts.ansible_net_interfaces is defined" #interfaces
|
||||
# FIXME
|
||||
# FIXME
|
||||
# - "result.ansible_facts.ansible_net_interfaces.Ethernet1.ipv4.masklen > 1" # interfaces
|
||||
|
||||
# ... and not present
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
- debug: msg="Using provider={{ connection.transport }}"
|
||||
when: ansible_connection == "local"
|
||||
|
||||
|
||||
- name: test invalid subset (foobar)
|
||||
nxos_facts:
|
||||
gather_subset:
|
||||
|
@ -12,7 +11,6 @@
|
|||
register: result
|
||||
ignore_errors: true
|
||||
|
||||
|
||||
- assert:
|
||||
that:
|
||||
# Failures shouldn't return changes
|
||||
|
@ -22,29 +20,4 @@
|
|||
# Sensible Failure message
|
||||
- "'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"
|
||||
|
|
|
@ -3,12 +3,10 @@
|
|||
- debug: msg="Using provider={{ connection.transport }}"
|
||||
when: ansible_connection == "local"
|
||||
|
||||
|
||||
- name: test not hardware
|
||||
nxos_facts:
|
||||
gather_subset:
|
||||
- "!hardware"
|
||||
timeout: 30
|
||||
provider: "{{ connection }}"
|
||||
register: result
|
||||
|
||||
|
@ -21,13 +19,12 @@
|
|||
- "'config' 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"
|
||||
|
||||
# ... and not present
|
||||
- "'hardware' not in result.ansible_facts.ansible_net_gather_subset"
|
||||
|
||||
# Items from those subsets are present
|
||||
# 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
|
||||
- "result.ansible_facts.ansible_net_filesystems is not defined"
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue