From 539f37ede3b1cd1104f044a1417d742c21e0676c Mon Sep 17 00:00:00 2001 From: Sumit Jaiswal Date: Mon, 1 Jul 2019 12:26:04 +0530 Subject: [PATCH] PR to implement ansible_net_model for iosxr facts module (#58488) * resolves 57767 Signed-off-by: Sumit Jaiswal * added test Signed-off-by: Sumit Jaiswal --- lib/ansible/modules/network/iosxr/iosxr_facts.py | 4 ++++ lib/ansible/plugins/cliconf/iosxr.py | 9 ++++++--- .../targets/iosxr_facts/tests/cli/all_facts.yaml | 4 +--- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/lib/ansible/modules/network/iosxr/iosxr_facts.py b/lib/ansible/modules/network/iosxr/iosxr_facts.py index 4cfcf419b2f..c5edd2ba70e 100644 --- a/lib/ansible/modules/network/iosxr/iosxr_facts.py +++ b/lib/ansible/modules/network/iosxr/iosxr_facts.py @@ -84,6 +84,10 @@ ansible_net_python_version: description: The Python version Ansible controller is using returned: always type: str +ansible_net_model: + description: The model name returned from the device + returned: always + type: str # hardware ansible_net_filesystems: diff --git a/lib/ansible/plugins/cliconf/iosxr.py b/lib/ansible/plugins/cliconf/iosxr.py index bf78a9e03f9..d9dad198857 100644 --- a/lib/ansible/plugins/cliconf/iosxr.py +++ b/lib/ansible/plugins/cliconf/iosxr.py @@ -60,9 +60,12 @@ class Cliconf(CliconfBase): if match: device_info['network_os_image'] = match.group(1) - match = re.search(r'^Cisco (.+) \(revision', data, re.M) - if match: - device_info['network_os_model'] = match.group(1) + model_search_strs = [r'^Cisco (.+) \(revision', r'^[Cc]isco (\S+ \S+).+bytes of .*memory'] + for item in model_search_strs: + match = re.search(item, data, re.M) + if match: + device_info['network_os_model'] = match.group(1) + break match = re.search(r'^(.+) uptime', data, re.M) if match: diff --git a/test/integration/targets/iosxr_facts/tests/cli/all_facts.yaml b/test/integration/targets/iosxr_facts/tests/cli/all_facts.yaml index 2522c49b7bf..eda117236c2 100644 --- a/test/integration/targets/iosxr_facts/tests/cli/all_facts.yaml +++ b/test/integration/targets/iosxr_facts/tests/cli/all_facts.yaml @@ -9,8 +9,6 @@ provider: "{{ cli }}" register: result - - - assert: that: # _facts modules should never report a change @@ -21,7 +19,7 @@ - "'hardware' 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" - + - "result.ansible_facts.ansible_net_model == 'IOS XRv'" # Items from those subsets are present - "result.ansible_facts.ansible_net_filesystems is defined"