Fix junos facts integration test failures (#42623)
* 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
This commit is contained in:
parent
d723b8541d
commit
6a94090e7f
2 changed files with 13 additions and 9 deletions
|
@ -35,10 +35,10 @@ options:
|
||||||
values to include a larger subset. Values can also be used
|
values to include a larger subset. Values can also be used
|
||||||
with an initial C(M(!)) to specify that a specific subset should
|
with an initial C(M(!)) to specify that a specific subset should
|
||||||
not be collected. To maintain backward compatbility old style facts
|
not be collected. To maintain backward compatbility old style facts
|
||||||
can be retrieved using all value, this reqires junos-eznc to be installed
|
can be retrieved by explicilty adding C(ofacts) to value, this reqires
|
||||||
as a prerequisite. Valid value of gather_subset are default, hardware,
|
junos-eznc to be installed as a prerequisite. Valid value of gather_subset
|
||||||
config, interfaces, ofacts. If C(ofacts) is present in the list it fetches
|
are default, hardware, config, interfaces, ofacts. If C(ofacts) is present in the
|
||||||
the old style facts (fact keys without 'ansible_' prefix) and it requires
|
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
|
junos-eznc library to be installed on control node and the device login credentials
|
||||||
must be given in C(provider) option.
|
must be given in C(provider) option.
|
||||||
required: false
|
required: false
|
||||||
|
@ -51,7 +51,7 @@ options:
|
||||||
only when C(config) value is present in I(gather_subset).
|
only when C(config) value is present in I(gather_subset).
|
||||||
The I(config_format) should be supported by the junos version running on
|
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
|
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
|
required: false
|
||||||
default: 'text'
|
default: 'text'
|
||||||
choices: ['xml', 'text', 'set', 'json']
|
choices: ['xml', 'text', 'set', 'json']
|
||||||
|
@ -354,19 +354,23 @@ def main():
|
||||||
runable_subsets.difference_update(exclude_subsets)
|
runable_subsets.difference_update(exclude_subsets)
|
||||||
runable_subsets.add('default')
|
runable_subsets.add('default')
|
||||||
|
|
||||||
|
# handle fetching old style facts seperately
|
||||||
|
runable_subsets.discard('ofacts')
|
||||||
|
|
||||||
facts = dict()
|
facts = dict()
|
||||||
facts['gather_subset'] = list(runable_subsets)
|
facts['gather_subset'] = list(runable_subsets)
|
||||||
|
|
||||||
instances = list()
|
instances = list()
|
||||||
ansible_facts = dict()
|
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:
|
if HAS_PYEZ:
|
||||||
ansible_facts.update(OFacts(module).populate())
|
ansible_facts.update(OFacts(module).populate())
|
||||||
else:
|
else:
|
||||||
warnings += ['junos-eznc is required to gather old style facts but does not appear to be installed. '
|
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`']
|
'It can be installed using `pip install junos-eznc`']
|
||||||
runable_subsets.remove('ofacts')
|
facts['gather_subset'].append('ofacts')
|
||||||
|
|
||||||
for key in runable_subsets:
|
for key in runable_subsets:
|
||||||
instances.append(FACT_SUBSETS[key](module))
|
instances.append(FACT_SUBSETS[key](module))
|
||||||
|
|
|
@ -50,7 +50,7 @@
|
||||||
- assert:
|
- assert:
|
||||||
that:
|
that:
|
||||||
- "result.failed == true"
|
- "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
|
- name: Collect config facts from device in set format
|
||||||
junos_facts:
|
junos_facts:
|
||||||
|
@ -92,7 +92,7 @@
|
||||||
- assert:
|
- assert:
|
||||||
that:
|
that:
|
||||||
- "result.changed == false"
|
- "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"
|
when: ansible_net_version == "17.3R1.10"
|
||||||
|
|
||||||
- name: Collect config facts from device in text format
|
- name: Collect config facts from device in text format
|
||||||
|
|
Loading…
Reference in a new issue