* Fixes to improve ios_system idempotency (#38303)

Added detection of additional formatting for domain_name, domain_search,
lookup_source, and lookup_enabled on some software versions. In each
case they failed to detect existing commands with a '-' in it.

Fix: #38301
(cherry picked from commit 67acffb5f2)

* Nxos fixes (#40117)

* Alter nxos_nxapi tests to test the right thing

* Defend #40027

(cherry picked from commit f04c876ecd)
This commit is contained in:
Nathaniel Case 2018-05-15 12:33:51 -04:00 committed by Trishna Guha
parent a55fd1e415
commit abb0f4498f
8 changed files with 47 additions and 12 deletions

View file

@ -254,7 +254,7 @@ def parse_hostname(config):
def parse_domain_name(config):
match = re.findall(r'^ip domain name (?:vrf (\S+) )*(\S+)', config, re.M)
match = re.findall(r'^ip domain[- ]name (?:vrf (\S+) )*(\S+)', config, re.M)
matches = list()
for vrf, name in match:
if not vrf:
@ -264,7 +264,7 @@ def parse_domain_name(config):
def parse_domain_search(config):
match = re.findall(r'^ip domain list (?:vrf (\S+) )*(\S+)', config, re.M)
match = re.findall(r'^ip domain[- ]list (?:vrf (\S+) )*(\S+)', config, re.M)
matches = list()
for vrf, name in match:
if not vrf:
@ -285,7 +285,7 @@ def parse_name_servers(config):
def parse_lookup_source(config):
match = re.search(r'ip domain lookup source-interface (\S+)', config, re.M)
match = re.search(r'ip domain[- ]lookup source-interface (\S+)', config, re.M)
if match:
return match.group(1)
@ -297,7 +297,7 @@ def map_config_to_obj(module):
'domain_name': parse_domain_name(config),
'domain_search': parse_domain_search(config),
'lookup_source': parse_lookup_source(config),
'lookup_enabled': 'no ip domain lookup' not in config,
'lookup_enabled': 'no ip domain lookup' not in config and 'no ip domain-lookup' not in config,
'name_servers': parse_name_servers(config)
}

View file

@ -43,6 +43,9 @@ class ActionModule(_ActionModule):
socket_path = None
if self._task.args.get('provider', {}).get('transport') == 'nxapi' and self._task.action == 'nxos_nxapi':
return {'failed': True, 'msg': "Transport type 'nxapi' is not valid for '%s' module." % (self._task.action)}
if self._play_context.connection == 'network_cli':
provider = self._task.args.get('provider', {})
if any(provider.values()):

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,7 +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

View file

@ -1,4 +1,3 @@
---
# Only cli tests for this module since cli is used
# to test nxapi
- { include: cli.yaml, tags: ['cli'] }
- { include: nxapi.yaml, tags: ['nxapi'] }

View file

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

View file

@ -1,5 +1,5 @@
---
- debug: msg="START cli/badtransport.yaml"
- debug: msg="START nxapi/badtransport.yaml"
- name: Sending transport other than cli should fail
nxos_nxapi:
@ -12,6 +12,6 @@
- assert:
that:
- result.failed and result.msg is search('transport')
- result.failed and result.msg is search('Transport')
- debug: msg="END cli/badtransport.yaml"
- debug: msg="END nxapi/badtransport.yaml"

View file

@ -21,7 +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 connection={{ cli }}"
with_items: "{{ test_items }}"
loop_control:
loop_var: test_case_to_run

View file

@ -22,3 +22,9 @@
- assert:
that:
- result.stdout|length == 10
- name: combine with provider
nxos_command:
commands:
- show hostname
provider: "{{ connection | combine({'timeout': 500}) }}"