Skip to content

Commit

Permalink
Fix junos facts integration test failures (#42623)
Browse files Browse the repository at this point in the history
*  Make fetching old style facts optional
   and try to fetch the old style facts only when
   `ofacts` value is present in `gather_facts`
* Fix in junos_facts integration test
  • Loading branch information
ganeshrn committed Jul 12, 2018
1 parent d723b85 commit 6a94090
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
18 changes: 11 additions & 7 deletions lib/ansible/modules/network/junos/junos_facts.py
Expand Up @@ -35,10 +35,10 @@
values to include a larger subset. Values can also be used
with an initial C(M(!)) to specify that a specific subset should
not be collected. To maintain backward compatbility old style facts
can be retrieved using all value, this reqires junos-eznc to be installed
as a prerequisite. Valid value of gather_subset are default, hardware,
config, interfaces, ofacts. If C(ofacts) is present in the list it fetches
the old style facts (fact keys without 'ansible_' prefix) and it requires
can be retrieved by explicilty adding C(ofacts) to value, this reqires
junos-eznc to be installed as a prerequisite. Valid value of gather_subset
are default, hardware, config, interfaces, ofacts. If C(ofacts) is present in the
list it fetches the old style facts (fact keys without 'ansible_' prefix) and it requires
junos-eznc library to be installed on control node and the device login credentials
must be given in C(provider) option.
required: false
Expand All @@ -51,7 +51,7 @@
only when C(config) value is present in I(gather_subset).
The I(config_format) should be supported by the junos version running on
device. This value is not applicable while fetching old style facts that is
when value of I(gather_subset) C(all) or C(ofacts) is present in the value.
when C(ofacts) value is present in value if I(gather_subset) value.
required: false
default: 'text'
choices: ['xml', 'text', 'set', 'json']
Expand Down Expand Up @@ -354,19 +354,23 @@ def main():
runable_subsets.difference_update(exclude_subsets)
runable_subsets.add('default')

# handle fetching old style facts seperately
runable_subsets.discard('ofacts')

facts = dict()
facts['gather_subset'] = list(runable_subsets)

instances = list()
ansible_facts = dict()

if 'ofacts' in runable_subsets:
# fetch old style facts only when explicitly mentioned in gather_subset option
if 'ofacts' in gather_subset:
if HAS_PYEZ:
ansible_facts.update(OFacts(module).populate())
else:
warnings += ['junos-eznc is required to gather old style facts but does not appear to be installed. '
'It can be installed using `pip install junos-eznc`']
runable_subsets.remove('ofacts')
facts['gather_subset'].append('ofacts')

for key in runable_subsets:
instances.append(FACT_SUBSETS[key](module))
Expand Down
4 changes: 2 additions & 2 deletions test/integration/targets/junos_facts/tests/netconf/facts.yaml
Expand Up @@ -50,7 +50,7 @@
- assert:
that:
- "result.failed == true"
- "result.msg == 'Subset must be one of [hardware, default, interfaces, config], got test'"
- "result.msg == 'Subset must be one of [hardware, default, ofacts, config, interfaces], got test'"

- name: Collect config facts from device in set format
junos_facts:
Expand Down Expand Up @@ -92,7 +92,7 @@
- assert:
that:
- "result.changed == false"
- "'{{ result['ansible_facts']['ansible_net_config']['configuration']['system']['service']['netconf'] }}' is defined"
- "'ssh' in result['ansible_facts']['ansible_net_config']['configuration']['system']['services']['netconf']"
when: ansible_net_version == "17.3R1.10"

- name: Collect config facts from device in text format
Expand Down

0 comments on commit 6a94090

Please sign in to comment.