Backport 2.5: Return correct version on installed VyOS (#39115) (#45715)

* 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 235b11f681)

* Added changelog
pull/46131/head
Nilashish Chakraborty 6 years ago committed by Matt Davis
parent 6eb21c7852
commit c60c27b7da

@ -0,0 +1,3 @@
---
bugfixes:
- vyos_facts - fix vyos_facts not returning version number issue (https://github.com/ansible/ansible/pull/39115)

@ -135,7 +135,7 @@ class Default(FactsBase):
self.facts['hostname'] = self.responses[1] self.facts['hostname'] = self.responses[1]
def parse_version(self, data): def parse_version(self, data):
match = re.search(r'Version:\s*(\S+)', data) match = re.search(r'Version:\s*(.*)', data)
if match: if match:
return match.group(1) return match.group(1)

@ -63,7 +63,7 @@ class TestVyosFactsModule(TestVyosModule):
facts = result.get('ansible_facts') facts = result.get('ansible_facts')
self.assertEqual(len(facts), 5) self.assertEqual(len(facts), 5)
self.assertEqual(facts['ansible_net_hostname'].strip(), 'vyos01') 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): def test_vyos_facts_not_all(self):
set_module_args(dict(gather_subset='!all')) set_module_args(dict(gather_subset='!all'))
@ -71,7 +71,7 @@ class TestVyosFactsModule(TestVyosModule):
facts = result.get('ansible_facts') facts = result.get('ansible_facts')
self.assertEqual(len(facts), 5) self.assertEqual(len(facts), 5)
self.assertEqual(facts['ansible_net_hostname'].strip(), 'vyos01') 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): def test_vyos_facts_exclude_most(self):
set_module_args(dict(gather_subset=['!neighbors', '!config'])) set_module_args(dict(gather_subset=['!neighbors', '!config']))
@ -79,7 +79,7 @@ class TestVyosFactsModule(TestVyosModule):
facts = result.get('ansible_facts') facts = result.get('ansible_facts')
self.assertEqual(len(facts), 5) self.assertEqual(len(facts), 5)
self.assertEqual(facts['ansible_net_hostname'].strip(), 'vyos01') 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): def test_vyos_facts_invalid_subset(self):
set_module_args(dict(gather_subset='cereal')) set_module_args(dict(gather_subset='cereal'))

Loading…
Cancel
Save