diff options
author | Rohit Thakur <rohitthakur2590@outlook.com> | 2021-04-28 17:39:24 +0530 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-04-28 12:09:24 +0000 |
commit | e1c29bf3b6e0ba4887693fcc347d8887051aa148 (patch) | |
tree | d0cd7ae2fb73c8fab1cd470328564058a316faf8 | |
parent | dccc17eb6956a9a09485b90198219559acd3a209 (diff) | |
download | vyos.vyos-e1c29bf3b6e0ba4887693fcc347d8887051aa148.tar.gz vyos.vyos-e1c29bf3b6e0ba4887693fcc347d8887051aa148.zip |
VyOS: available_network_resources implemented in vyos_facts (#148)
VyOS: available_network_resources implemented in vyos_facts
Reviewed-by: https://github.com/apps/ansible-zuul
6 files changed, 34 insertions, 7 deletions
diff --git a/changelogs/fragments/160_available_network_resources.yaml b/changelogs/fragments/160_available_network_resources.yaml new file mode 100644 index 00000000..c7a92f21 --- /dev/null +++ b/changelogs/fragments/160_available_network_resources.yaml @@ -0,0 +1,3 @@ +--- +minor_changes: + - Add support for available_network_resources key, which allows to fetch the available resources for a platform (https://github.com/ansible-collections/vyos.vyos/issues/138). diff --git a/plugins/module_utils/network/vyos/argspec/facts/facts.py b/plugins/module_utils/network/vyos/argspec/facts/facts.py index d78dd3ab..efd98e36 100644 --- a/plugins/module_utils/network/vyos/argspec/facts/facts.py +++ b/plugins/module_utils/network/vyos/argspec/facts/facts.py @@ -20,4 +20,5 @@ class FactsArgs(object): # pylint: disable=R0903 default=["!config"], type="list", elements="str" ), "gather_network_resources": dict(type="list", elements="str"), + "available_network_resources": {"type": "bool", "default": False}, } diff --git a/plugins/module_utils/network/vyos/facts/ospf_interfaces/ospf_interfaces.py b/plugins/module_utils/network/vyos/facts/ospf_interfaces/ospf_interfaces.py index 7ef05cb6..4057db5c 100644 --- a/plugins/module_utils/network/vyos/facts/ospf_interfaces/ospf_interfaces.py +++ b/plugins/module_utils/network/vyos/facts/ospf_interfaces/ospf_interfaces.py @@ -40,7 +40,7 @@ class Ospf_interfacesFacts(object): ) def get_config_set(self, data): - """ To classify the configurations beased on interface """ + """To classify the configurations beased on interface""" interface_list = [] config_set = [] int_string = "" diff --git a/plugins/modules/vyos_facts.py b/plugins/modules/vyos_facts.py index 01c43c2e..8bffcda3 100644 --- a/plugins/modules/vyos_facts.py +++ b/plugins/modules/vyos_facts.py @@ -52,6 +52,10 @@ options: required: false type: list elements: str + available_network_resources: + description: When 'True' a list of network resources for which resource modules are available will be provided. + type: bool + default: false """ EXAMPLES = """ @@ -140,6 +144,7 @@ from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.argspec.fac ) from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.facts import ( Facts, + FACT_RESOURCE_SUBSETS, ) from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.vyos import ( vyos_argument_spec, @@ -165,9 +170,14 @@ def main(): "default value for `gather_subset` will be changed to `min` from `!config` v2.11 onwards" ) + ansible_facts = {} + if module.params.get("available_network_resources"): + ansible_facts["available_network_resources"] = sorted( + FACT_RESOURCE_SUBSETS.keys() + ) result = Facts(module).get_facts() - - ansible_facts, additional_warnings = result + additional_facts, additional_warnings = result + ansible_facts.update(additional_facts) warnings.extend(additional_warnings) module.exit_json(ansible_facts=ansible_facts, warnings=warnings) diff --git a/tests/integration/targets/vyos_facts/tests/cli/basic_facts.yaml b/tests/integration/targets/vyos_facts/tests/cli/basic_facts.yaml index 5802f731..ede7ca2d 100644 --- a/tests/integration/targets/vyos_facts/tests/cli/basic_facts.yaml +++ b/tests/integration/targets/vyos_facts/tests/cli/basic_facts.yaml @@ -40,3 +40,16 @@ that: - result.ansible_facts.ansible_net_commits is defined - result.ansible_facts.ansible_net_config is defined + +- name: Get list of avaliable network resources for VyOS + register: result + vyos.vyos.vyos_facts: + available_network_resources: true + gather_network_resources: all + +- name: Assert that correct available_resources_list returned + assert: + that: + - result.changed == false + - "{{ result['ansible_facts']['available_network_resources'] | symmetric_difference(result['ansible_facts']['ansible_net_gather_network_resources']) |length\ + \ == 0 }}" diff --git a/tests/unit/modules/network/vyos/test_vyos_ping.py b/tests/unit/modules/network/vyos/test_vyos_ping.py index e3076103..f3ba2ee5 100644 --- a/tests/unit/modules/network/vyos/test_vyos_ping.py +++ b/tests/unit/modules/network/vyos/test_vyos_ping.py @@ -56,22 +56,22 @@ class TestVyosPingModule(TestVyosModule): self.run_commands.side_effect = load_from_file def test_vyos_ping_expected_success(self): - """ Test for successful pings when destination should be reachable """ + """Test for successful pings when destination should be reachable""" set_module_args(dict(count=2, dest="10.10.10.10")) self.execute_module() def test_vyos_ping_expected_failure(self): - """ Test for unsuccessful pings when destination should not be reachable """ + """Test for unsuccessful pings when destination should not be reachable""" set_module_args(dict(count=4, dest="10.10.10.20", state="absent")) self.execute_module() def test_vyos_ping_unexpected_success(self): - """ Test for successful pings when destination should not be reachable - FAIL. """ + """Test for successful pings when destination should not be reachable - FAIL.""" set_module_args(dict(count=2, dest="10.10.10.10", state="absent")) self.execute_module(failed=True) def test_vyos_ping_unexpected_failure(self): - """ Test for unsuccessful pings when destination should be reachable - FAIL. """ + """Test for unsuccessful pings when destination should be reachable - FAIL.""" set_module_args(dict(count=4, dest="10.10.10.20")) self.execute_module(failed=True) |