From 35ba55599a3b0abb47ed543a96c8e938d19da304 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 (cherry picked from commit 539f37ede3b1cd1104f044a1417d742c21e0676c) Handle lowercase in version info (#59565) Signed-off-by: NilashishC (cherry picked from commit 3a103405b19f7fcb0e803b32f64c41856b504f7f) Add changelog for iosxr_facts fix Signed-off-by: NilashishC --- changelogs/fragments/fix_iosxr_facts.yaml | 2 ++ 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 +--- 4 files changed, 13 insertions(+), 6 deletions(-) create mode 100644 changelogs/fragments/fix_iosxr_facts.yaml diff --git a/changelogs/fragments/fix_iosxr_facts.yaml b/changelogs/fragments/fix_iosxr_facts.yaml new file mode 100644 index 00000000000..c70cbb89d59 --- /dev/null +++ b/changelogs/fragments/fix_iosxr_facts.yaml @@ -0,0 +1,2 @@ +bugfixes: + - Fixed issue where `ansible_net_model` was not being populated in iosxr_facts (https://github.com/ansible/ansible/pull/58488) diff --git a/lib/ansible/modules/network/iosxr/iosxr_facts.py b/lib/ansible/modules/network/iosxr/iosxr_facts.py index 0e6b866e5ea..3c1c1269c23 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 b63aa83e6e5..befef6c5b6d 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'^[Cc]isco (.+) \(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"