From 0e48544ae1f6ea1e5d0e28504b0fcf8202175604 Mon Sep 17 00:00:00 2001 From: Nilashish Chakraborty Date: Thu, 11 Oct 2018 19:56:09 +0530 Subject: [PATCH] Backport 2.7: Return correct version on installed VyOS (#39115) (#46730) * Return correct version on installed VyOS (#39115) * Return correct version on installed VyOS Previously existing regexp will shows only "VyOS" without numeric output of router version. For example: from "Version: VyOS 1.1.6" only VyOS will be written in ansible_net_version variable For more informative output numeric value should be returned as well * Fixed unittests (cherry picked from commit 235b11f681558c614b8b44e05d6679d48784a34c) * Added changelog --- changelogs/fragments/fix_vyos_version.yaml | 2 ++ lib/ansible/modules/network/vyos/vyos_facts.py | 2 +- test/units/modules/network/vyos/test_vyos_facts.py | 6 +++--- 3 files changed, 6 insertions(+), 4 deletions(-) create mode 100644 changelogs/fragments/fix_vyos_version.yaml diff --git a/changelogs/fragments/fix_vyos_version.yaml b/changelogs/fragments/fix_vyos_version.yaml new file mode 100644 index 00000000000..e714c317776 --- /dev/null +++ b/changelogs/fragments/fix_vyos_version.yaml @@ -0,0 +1,2 @@ +bugfixes: +- vyos_facts - fix vyos_facts not returning version number issue (https://github.com/ansible/ansible/pull/39115) diff --git a/lib/ansible/modules/network/vyos/vyos_facts.py b/lib/ansible/modules/network/vyos/vyos_facts.py index 1d50f415ea7..88588557f96 100644 --- a/lib/ansible/modules/network/vyos/vyos_facts.py +++ b/lib/ansible/modules/network/vyos/vyos_facts.py @@ -135,7 +135,7 @@ class Default(FactsBase): self.facts['hostname'] = self.responses[1] def parse_version(self, data): - match = re.search(r'Version:\s*(\S+)', data) + match = re.search(r'Version:\s*(.*)', data) if match: return match.group(1) diff --git a/test/units/modules/network/vyos/test_vyos_facts.py b/test/units/modules/network/vyos/test_vyos_facts.py index 82a71fba315..4c421d80a3f 100644 --- a/test/units/modules/network/vyos/test_vyos_facts.py +++ b/test/units/modules/network/vyos/test_vyos_facts.py @@ -63,7 +63,7 @@ class TestVyosFactsModule(TestVyosModule): facts = result.get('ansible_facts') self.assertEqual(len(facts), 5) self.assertEqual(facts['ansible_net_hostname'].strip(), 'vyos01') - self.assertEqual(facts['ansible_net_version'], 'VyOS') + self.assertEqual(facts['ansible_net_version'], 'VyOS 1.1.7') def test_vyos_facts_not_all(self): set_module_args(dict(gather_subset='!all')) @@ -71,7 +71,7 @@ class TestVyosFactsModule(TestVyosModule): facts = result.get('ansible_facts') self.assertEqual(len(facts), 5) self.assertEqual(facts['ansible_net_hostname'].strip(), 'vyos01') - self.assertEqual(facts['ansible_net_version'], 'VyOS') + self.assertEqual(facts['ansible_net_version'], 'VyOS 1.1.7') def test_vyos_facts_exclude_most(self): set_module_args(dict(gather_subset=['!neighbors', '!config'])) @@ -79,7 +79,7 @@ class TestVyosFactsModule(TestVyosModule): facts = result.get('ansible_facts') self.assertEqual(len(facts), 5) self.assertEqual(facts['ansible_net_hostname'].strip(), 'vyos01') - self.assertEqual(facts['ansible_net_version'], 'VyOS') + self.assertEqual(facts['ansible_net_version'], 'VyOS 1.1.7') def test_vyos_facts_invalid_subset(self): set_module_args(dict(gather_subset='cereal'))