diff --git a/lib/ansible/module_utils/network/common/network.py b/lib/ansible/module_utils/network/common/network.py index 55c37cd5728..e76d31e9837 100644 --- a/lib/ansible/module_utils/network/common/network.py +++ b/lib/ansible/module_utils/network/common/network.py @@ -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.") diff --git a/lib/ansible/module_utils/network/eos/eos.py b/lib/ansible/module_utils/network/eos/eos.py index 438554ebdf0..7ac11d0d7f0 100644 --- a/lib/ansible/module_utils/network/eos/eos.py +++ b/lib/ansible/module_utils/network/eos/eos.py @@ -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): diff --git a/lib/ansible/module_utils/network/nxos/nxos.py b/lib/ansible/module_utils/network/nxos/nxos.py index 0b9c7eea28c..a049cf46937 100644 --- a/lib/ansible/module_utils/network/nxos/nxos.py +++ b/lib/ansible/module_utils/network/nxos/nxos.py @@ -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: diff --git a/test/integration/targets/eos_facts/tasks/cli.yaml b/test/integration/targets/eos_facts/tasks/cli.yaml index 87a42971bbc..06b9c7a3161 100644 --- a/test/integration/targets/eos_facts/tasks/cli.yaml +++ b/test/integration/targets/eos_facts/tasks/cli.yaml @@ -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 diff --git a/test/integration/targets/eos_facts/tasks/eapi.yaml b/test/integration/targets/eos_facts/tasks/eapi.yaml index 1109c6bf6ac..9c00b41b431 100644 --- a/test/integration/targets/eos_facts/tasks/eapi.yaml +++ b/test/integration/targets/eos_facts/tasks/eapi.yaml @@ -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 diff --git a/test/integration/targets/eos_facts/tests/cli/all_facts.yaml b/test/integration/targets/eos_facts/tests/cli/all_facts.yaml index 05312e861a1..18f3282924c 100644 --- a/test/integration/targets/eos_facts/tests/cli/all_facts.yaml +++ b/test/integration/targets/eos_facts/tests/cli/all_facts.yaml @@ -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 diff --git a/test/integration/targets/eos_facts/tests/cli/default_facts.yaml b/test/integration/targets/eos_facts/tests/cli/default_facts.yaml index b99437fb731..7e05f01390a 100644 --- a/test/integration/targets/eos_facts/tests/cli/default_facts.yaml +++ b/test/integration/targets/eos_facts/tests/cli/default_facts.yaml @@ -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 }}" diff --git a/test/integration/targets/eos_facts/tests/cli/invalid_subset.yaml b/test/integration/targets/eos_facts/tests/cli/invalid_subset.yaml index d445b22adbf..c310430cd02 100644 --- a/test/integration/targets/eos_facts/tests/cli/invalid_subset.yaml +++ b/test/integration/targets/eos_facts/tests/cli/invalid_subset.yaml @@ -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 }}" diff --git a/test/integration/targets/eos_facts/tests/cli/not_hardware.yaml b/test/integration/targets/eos_facts/tests/cli/not_hardware.yaml index f528ce77c11..1954bcb8e48 100644 --- a/test/integration/targets/eos_facts/tests/cli/not_hardware.yaml +++ b/test/integration/targets/eos_facts/tests/cli/not_hardware.yaml @@ -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 diff --git a/test/integration/targets/eos_facts/tests/eapi/all_facts.yaml b/test/integration/targets/eos_facts/tests/eapi/all_facts.yaml index 5d755e1119d..ba701b45779 100644 --- a/test/integration/targets/eos_facts/tests/eapi/all_facts.yaml +++ b/test/integration/targets/eos_facts/tests/eapi/all_facts.yaml @@ -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 }}" diff --git a/test/integration/targets/eos_facts/tests/eapi/default_facts.yaml b/test/integration/targets/eos_facts/tests/eapi/default_facts.yaml index baa1216227c..3c6d70ac57a 100644 --- a/test/integration/targets/eos_facts/tests/eapi/default_facts.yaml +++ b/test/integration/targets/eos_facts/tests/eapi/default_facts.yaml @@ -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 }}" diff --git a/test/integration/targets/eos_facts/tests/eapi/invalid_subset.yaml b/test/integration/targets/eos_facts/tests/eapi/invalid_subset.yaml index ec8bc75d5a2..de583038fb9 100644 --- a/test/integration/targets/eos_facts/tests/eapi/invalid_subset.yaml +++ b/test/integration/targets/eos_facts/tests/eapi/invalid_subset.yaml @@ -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 }}" diff --git a/test/integration/targets/eos_facts/tests/eapi/not_hardware.yaml b/test/integration/targets/eos_facts/tests/eapi/not_hardware.yaml index 37a901319e8..7b1d4c797e6 100644 --- a/test/integration/targets/eos_facts/tests/eapi/not_hardware.yaml +++ b/test/integration/targets/eos_facts/tests/eapi/not_hardware.yaml @@ -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 }}" diff --git a/test/integration/targets/nxos_facts/tests/common/all_facts.yaml b/test/integration/targets/nxos_facts/tests/common/all_facts.yaml index e6afa967b10..4289e2359ae 100644 --- a/test/integration/targets/nxos_facts/tests/common/all_facts.yaml +++ b/test/integration/targets/nxos_facts/tests/common/all_facts.yaml @@ -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 diff --git a/test/integration/targets/nxos_facts/tests/common/default_facts.yaml b/test/integration/targets/nxos_facts/tests/common/default_facts.yaml index 78648564528..82775e516cf 100644 --- a/test/integration/targets/nxos_facts/tests/common/default_facts.yaml +++ b/test/integration/targets/nxos_facts/tests/common/default_facts.yaml @@ -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 diff --git a/test/integration/targets/nxos_facts/tests/common/invalid_subset.yaml b/test/integration/targets/nxos_facts/tests/common/invalid_subset.yaml index 4e71d10e80d..9df2fe53d66 100644 --- a/test/integration/targets/nxos_facts/tests/common/invalid_subset.yaml +++ b/test/integration/targets/nxos_facts/tests/common/invalid_subset.yaml @@ -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" diff --git a/test/integration/targets/nxos_facts/tests/common/not_hardware.yaml b/test/integration/targets/nxos_facts/tests/common/not_hardware.yaml index 48e1a40801a..6c06ec3a244 100644 --- a/test/integration/targets/nxos_facts/tests/common/not_hardware.yaml +++ b/test/integration/targets/nxos_facts/tests/common/not_hardware.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"