diff options
author | Kate Case <kcase@redhat.com> | 2023-01-25 08:37:58 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-01-25 08:37:58 -0500 |
commit | e9911888f6dcdf9031f3fdb2e32c52e45815fdbe (patch) | |
tree | dc22abb4a329ef04e98685b81d074679dc24c456 | |
parent | bcfe61a3b6ff69f08450f3dbd8f0f1827fb18ab3 (diff) | |
download | vyos.vyos-e9911888f6dcdf9031f3fdb2e32c52e45815fdbe.tar.gz vyos.vyos-e9911888f6dcdf9031f3fdb2e32c52e45815fdbe.zip |
Add prettier and isort to pre-commit. (#270)
* Add prettier and isort to pre-commit.
* Bump line-length to 100
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
379 files changed, 2294 insertions, 4037 deletions
diff --git a/.isort.cfg b/.isort.cfg new file mode 100644 index 0000000..516d62b --- /dev/null +++ b/.isort.cfg @@ -0,0 +1,4 @@ +[settings] +known_first_party=ansible_collections.vyos.vyos +line_length=100 +profile=black diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index aad517e..dc2764a 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -9,6 +9,20 @@ repos: - id: no-commit-to-branch - id: trailing-whitespace + - repo: https://github.com/pre-commit/mirrors-prettier + rev: "v2.7.1" + hooks: + - id: prettier + additional_dependencies: + - prettier + - prettier-plugin-toml + + - repo: https://github.com/PyCQA/isort + rev: 5.10.1 + hooks: + - id: isort + args: ["--filter-files"] + - repo: https://github.com/psf/black rev: 22.12.0 hooks: diff --git a/.prettierignore b/.prettierignore new file mode 100644 index 0000000..3b7645e --- /dev/null +++ b/.prettierignore @@ -0,0 +1,17 @@ +# Stuff we don't want priettier to ever to look into +.*/ +coverage/ + +# Environments +.env +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ + +# A linked collection directory created by pytest-ansible-units +collections/ + +README.md diff --git a/changelogs/changelog.yaml b/changelogs/changelog.yaml index d267b5f..a10c66c 100644 --- a/changelogs/changelog.yaml +++ b/changelogs/changelog.yaml @@ -2,402 +2,408 @@ ancestor: null releases: 1.0.0: modules: - - description: Manage multiline banners on VyOS devices - name: vyos_banner - namespace: '' - - description: Run one or more commands on VyOS devices - name: vyos_command - namespace: '' - - description: Manage VyOS configuration on remote device - name: vyos_config - namespace: '' - - description: Get facts about vyos devices. - name: vyos_facts - namespace: '' - - description: FIREWALL global resource module - name: vyos_firewall_global - namespace: '' - - description: FIREWALL interfaces resource module - name: vyos_firewall_interfaces - namespace: '' - - description: FIREWALL rules resource module - name: vyos_firewall_rules - namespace: '' - - description: (deprecated, removed after 2022-06-01) Manage Interface on VyOS - network devices - name: vyos_interface - namespace: '' - - description: Interfaces resource module - name: vyos_interfaces - namespace: '' - - description: (deprecated, removed after 2022-06-01) Manage L3 interfaces on - VyOS network devices - name: vyos_l3_interface - namespace: '' - - description: L3 interfaces resource module - name: vyos_l3_interfaces - namespace: '' - - description: LAG interfaces resource module - name: vyos_lag_interfaces - namespace: '' - - description: (deprecated, removed after 2022-06-01) Manage link aggregation - groups on VyOS network devices - name: vyos_linkagg - namespace: '' - - description: (deprecated, removed after 2022-06-01) Manage LLDP configuration - on VyOS network devices - name: vyos_lldp - namespace: '' - - description: LLDP global resource module - name: vyos_lldp_global - namespace: '' - - description: (deprecated, removed after 2022-06-01) Manage LLDP interfaces configuration - on VyOS network devices - name: vyos_lldp_interface - namespace: '' - - description: LLDP interfaces resource module - name: vyos_lldp_interfaces - namespace: '' - - description: Manage logging on network devices - name: vyos_logging - namespace: '' - - description: OSPFv2 resource module - name: vyos_ospfv2 - namespace: '' - - description: OSPFV3 resource module - name: vyos_ospfv3 - namespace: '' - - description: Tests reachability using ping from VyOS network devices - name: vyos_ping - namespace: '' - - description: (deprecated, removed after 2022-06-01) Manage static IP routes - on Vyatta VyOS network devices - name: vyos_static_route - namespace: '' - - description: Static routes resource module - name: vyos_static_routes - namespace: '' - - description: Run `set system` commands on VyOS devices - name: vyos_system - namespace: '' - - description: Manage the collection of local users on VyOS device - name: vyos_user - namespace: '' - - description: Manage VLANs on VyOS network devices - name: vyos_vlan - namespace: '' + - description: Manage multiline banners on VyOS devices + name: vyos_banner + namespace: "" + - description: Run one or more commands on VyOS devices + name: vyos_command + namespace: "" + - description: Manage VyOS configuration on remote device + name: vyos_config + namespace: "" + - description: Get facts about vyos devices. + name: vyos_facts + namespace: "" + - description: FIREWALL global resource module + name: vyos_firewall_global + namespace: "" + - description: FIREWALL interfaces resource module + name: vyos_firewall_interfaces + namespace: "" + - description: FIREWALL rules resource module + name: vyos_firewall_rules + namespace: "" + - description: + (deprecated, removed after 2022-06-01) Manage Interface on VyOS + network devices + name: vyos_interface + namespace: "" + - description: Interfaces resource module + name: vyos_interfaces + namespace: "" + - description: + (deprecated, removed after 2022-06-01) Manage L3 interfaces on + VyOS network devices + name: vyos_l3_interface + namespace: "" + - description: L3 interfaces resource module + name: vyos_l3_interfaces + namespace: "" + - description: LAG interfaces resource module + name: vyos_lag_interfaces + namespace: "" + - description: + (deprecated, removed after 2022-06-01) Manage link aggregation + groups on VyOS network devices + name: vyos_linkagg + namespace: "" + - description: + (deprecated, removed after 2022-06-01) Manage LLDP configuration + on VyOS network devices + name: vyos_lldp + namespace: "" + - description: LLDP global resource module + name: vyos_lldp_global + namespace: "" + - description: + (deprecated, removed after 2022-06-01) Manage LLDP interfaces configuration + on VyOS network devices + name: vyos_lldp_interface + namespace: "" + - description: LLDP interfaces resource module + name: vyos_lldp_interfaces + namespace: "" + - description: Manage logging on network devices + name: vyos_logging + namespace: "" + - description: OSPFv2 resource module + name: vyos_ospfv2 + namespace: "" + - description: OSPFV3 resource module + name: vyos_ospfv3 + namespace: "" + - description: Tests reachability using ping from VyOS network devices + name: vyos_ping + namespace: "" + - description: + (deprecated, removed after 2022-06-01) Manage static IP routes + on Vyatta VyOS network devices + name: vyos_static_route + namespace: "" + - description: Static routes resource module + name: vyos_static_routes + namespace: "" + - description: Run `set system` commands on VyOS devices + name: vyos_system + namespace: "" + - description: Manage the collection of local users on VyOS device + name: vyos_user + namespace: "" + - description: Manage VLANs on VyOS network devices + name: vyos_vlan + namespace: "" plugins: cliconf: - - description: Use vyos cliconf to run command on VyOS platform - name: vyos - namespace: null - release_date: '2020-06-23' + - description: Use vyos cliconf to run command on VyOS platform + name: vyos + namespace: null + release_date: "2020-06-23" 1.0.1: changes: minor_changes: - - Add doc plugin fixes (https://github.com/ansible-collections/vyos.vyos/pull/51) + - Add doc plugin fixes (https://github.com/ansible-collections/vyos.vyos/pull/51) fragments: - - 51-doc-plugin-fixes.yaml - release_date: '2020-06-23' + - 51-doc-plugin-fixes.yaml + release_date: "2020-06-23" 1.0.2: changes: bugfixes: - - Added workaround to avoid set_fact dynamically assigning value. This behavior - seems to have been broken after ansible2.9. - - Make `src`, `backup` and `backup_options` in vyos_config work when module - alias is used (https://github.com/ansible-collections/vyos.vyos/pull/67). - - vyos_config - fixed issue where config could be saved while in check mode - (https://github.com/ansible-collections/vyos.vyos/pull/53) + - Added workaround to avoid set_fact dynamically assigning value. This behavior + seems to have been broken after ansible2.9. + - Make `src`, `backup` and `backup_options` in vyos_config work when module + alias is used (https://github.com/ansible-collections/vyos.vyos/pull/67). + - vyos_config - fixed issue where config could be saved while in check mode + (https://github.com/ansible-collections/vyos.vyos/pull/53) minor_changes: - - Fixed the typo in the modulename of ospfv2 and ospfv3 unit tests. - - Updated docs. - - terminal plugin - Added additional escape sequence to be removed from terminal - output. + - Fixed the typo in the modulename of ospfv2 and ospfv3 unit tests. + - Updated docs. + - terminal plugin - Added additional escape sequence to be removed from terminal + output. fragments: - - 65-remove-unwanted-terminal-chars.yaml - - 70-workaround-set_fact.yaml - - 72-modulename-typofix.yaml - - 73-update-docs.yaml - - fix_src_backup_with_module_alias.yaml - - prevent-vyos_config-saving-in-check-mode.yaml - release_date: '2020-07-31' + - 65-remove-unwanted-terminal-chars.yaml + - 70-workaround-set_fact.yaml + - 72-modulename-typofix.yaml + - 73-update-docs.yaml + - fix_src_backup_with_module_alias.yaml + - prevent-vyos_config-saving-in-check-mode.yaml + release_date: "2020-07-31" 1.0.3: fragments: - - 1.0.3.yaml - release_date: '2020-08-06' + - 1.0.3.yaml + release_date: "2020-08-06" 1.0.4: changes: minor_changes: - - Moved intent testcases from integration suite to unit tests. - - Reformatted files with latest version of Black (20.8b1). + - Moved intent testcases from integration suite to unit tests. + - Reformatted files with latest version of Black (20.8b1). fragments: - - 71-refactor-interface-test.yaml - - 80-reformat-files.yaml - release_date: '2020-08-27' + - 71-refactor-interface-test.yaml + - 80-reformat-files.yaml + release_date: "2020-08-27" 1.0.5: changes: bugfixes: - - Added openvpn vtu interface support. - - Update network integration auth timeout for connection local. - - terminal plugin - Overhaul ansi_re to remove more escape sequences + - Added openvpn vtu interface support. + - Update network integration auth timeout for connection local. + - terminal plugin - Overhaul ansi_re to remove more escape sequences fragments: - - 86-openvpn_vtu_interface.yaml - - local_auth_timeout.yaml - - terminal-escape-codes.yaml - release_date: '2020-10-08' + - 86-openvpn_vtu_interface.yaml + - local_auth_timeout.yaml + - terminal-escape-codes.yaml + release_date: "2020-10-08" 1.1.0: changes: minor_changes: - - Added ospf_interfaces resource module. + - Added ospf_interfaces resource module. fragments: - - vyos_ospf_interfaces_rm.yaml + - vyos_ospf_interfaces_rm.yaml modules: - - description: OSPF Interfaces Resource Module. - name: vyos_ospf_interfaces - namespace: '' - release_date: '2020-10-30' + - description: OSPF Interfaces Resource Module. + name: vyos_ospf_interfaces + namespace: "" + release_date: "2020-10-30" 1.1.1: changes: bugfixes: - - Add version key to galaxy.yaml to work around ansible-galaxy bug - - Enable configuring an interface which is not present in the running config. - - vyos_config - Only process src files as commands when they actually contain - commands. This fixes an issue were the whitespace preceding a configuration - key named 'set' was stripped, tripping up the parser. + - Add version key to galaxy.yaml to work around ansible-galaxy bug + - Enable configuring an interface which is not present in the running config. + - vyos_config - Only process src files as commands when they actually contain + commands. This fixes an issue were the whitespace preceding a configuration + key named 'set' was stripped, tripping up the parser. fragments: - - 91-new-interface.yaml - - config-processed-as-command.yaml - - galaxy-version.yaml - release_date: '2021-01-27' + - 91-new-interface.yaml + - config-processed-as-command.yaml + - galaxy-version.yaml + release_date: "2021-01-27" 2.0.0: changes: bugfixes: - - Update docs to clarify the idemptonecy related caveat and add it in the output - warnings (https://github.com/ansible-collections/ansible.netcommon/pull/189) - - cliconf plugin - Prevent `get_capabilities()` from getting larger every time - it is called + - Update docs to clarify the idemptonecy related caveat and add it in the output + warnings (https://github.com/ansible-collections/ansible.netcommon/pull/189) + - cliconf plugin - Prevent `get_capabilities()` from getting larger every time + it is called major_changes: - - Please refer to ansible.netcommon `changelog <https://github.com/ansible-collections/ansible.netcommon/blob/main/changelogs/CHANGELOG.rst#ansible-netcommon-collection-release-notes>`_ - for more details. - - Requires ansible.netcommon v2.0.0+ to support `ansible_network_single_user_mode` - and `ansible_network_import_modules` - - ipaddress is no longer in ansible.netcommon. For Python versions without ipaddress - (< 3.0), the ipaddress package is now required. + - Please refer to ansible.netcommon `changelog <https://github.com/ansible-collections/ansible.netcommon/blob/main/changelogs/CHANGELOG.rst#ansible-netcommon-collection-release-notes>`_ + for more details. + - Requires ansible.netcommon v2.0.0+ to support `ansible_network_single_user_mode` + and `ansible_network_import_modules` + - ipaddress is no longer in ansible.netcommon. For Python versions without ipaddress + (< 3.0), the ipaddress package is now required. minor_changes: - - Add support for configuration caching (single_user_mode). - - Add vyos BGP global resource module.(https://github.com/ansible-collections/vyos.vyos/pull/125). - - Re-use device_info dictionary in cliconf. + - Add support for configuration caching (single_user_mode). + - Add vyos BGP global resource module.(https://github.com/ansible-collections/vyos.vyos/pull/125). + - Re-use device_info dictionary in cliconf. fragments: - - 120-remove-ipaddress.yaml - - 122-rpc-unbloat.yaml - - bgp_global_resource_module.yaml - - fix_docker_sanity_test_failures.yaml - - major_release_2.0.0.yaml - - modify_resource_module_class_import.yaml - - single_user_mode.yaml - - vyos_config_diff_doc_update.yaml + - 120-remove-ipaddress.yaml + - 122-rpc-unbloat.yaml + - bgp_global_resource_module.yaml + - fix_docker_sanity_test_failures.yaml + - major_release_2.0.0.yaml + - modify_resource_module_class_import.yaml + - single_user_mode.yaml + - vyos_config_diff_doc_update.yaml modules: - - description: BGP Global Resource Module. - name: vyos_bgp_global - namespace: '' - release_date: '2021-02-24' + - description: BGP Global Resource Module. + name: vyos_bgp_global + namespace: "" + release_date: "2021-02-24" 2.1.0: changes: minor_changes: - - Add regex for delete failures to terminal_stderr_re - - Add vyos BGP address_family resource module (https://github.com/ansible-collections/vyos.vyos/pull/132). - - Enabled addition and parsing of wireguard interface. + - Add regex for delete failures to terminal_stderr_re + - Add vyos BGP address_family resource module (https://github.com/ansible-collections/vyos.vyos/pull/132). + - Enabled addition and parsing of wireguard interface. fragments: - - 128-remove_tests_sanity_requirements.yml - - 132-add-vyos-bgp-address-family.yml - - parse_wireguard_interface.yml - - replace-check_required.yaml - - skip_no_log_sanity_error.yaml - - terminal_stderr_delete.yml + - 128-remove_tests_sanity_requirements.yml + - 132-add-vyos-bgp-address-family.yml + - parse_wireguard_interface.yml + - replace-check_required.yaml + - skip_no_log_sanity_error.yaml + - terminal_stderr_delete.yml modules: - - description: BGP Address Family Resource Module. - name: vyos_bgp_address_family - namespace: '' - release_date: '2021-03-30' + - description: BGP Address Family Resource Module. + name: vyos_bgp_address_family + namespace: "" + release_date: "2021-03-30" 2.2.0: changes: 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). + - 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). security_fixes: - - Mask values of sensitive keys in module result. + - Mask values of sensitive keys in module result. fragments: - - 147-add_ignore_txt.yml - - 160_available_network_resources.yaml - - no_log_mask.yaml - - remove-old-test-deps.yml - release_date: '2021-04-27' + - 147-add_ignore_txt.yml + - 160_available_network_resources.yaml + - no_log_mask.yaml + - remove-old-test-deps.yml + release_date: "2021-04-27" 2.3.0: changes: bugfixes: - - change admin_distance to distance while generating static_routes nexthop command. - - firewall_global - port-groups were not added (https://github.com/ansible-collections/vyos.vyos/issues/107) + - change admin_distance to distance while generating static_routes nexthop command. + - firewall_global - port-groups were not added (https://github.com/ansible-collections/vyos.vyos/issues/107) minor_changes: - - Add vyos_route_maps resource module (https://github.com/ansible-collections/vyos.vyos/pull/156.). + - Add vyos_route_maps resource module (https://github.com/ansible-collections/vyos.vyos/pull/156.). fragments: - - changelog_doc_path_update.yaml - - fix_delete_route_maps.yaml - - fix_port_groups.yaml - - fix_static_routes_distance.yaml - - vyos-route-maps.yaml + - changelog_doc_path_update.yaml + - fix_delete_route_maps.yaml + - fix_port_groups.yaml + - fix_static_routes_distance.yaml + - vyos-route-maps.yaml modules: - - description: Route Map Resource Module. - name: vyos_route_maps - namespace: '' - release_date: '2021-05-18' + - description: Route Map Resource Module. + name: vyos_route_maps + namespace: "" + release_date: "2021-05-18" 2.3.1: changes: bugfixes: - - Fix KeyError 'source' - vyos_firewall_rules - - Updated docs resolving spelling typos - - change interface to next-hop-interface while generating static_routes nexthop - command. + - Fix KeyError 'source' - vyos_firewall_rules + - Updated docs resolving spelling typos + - change interface to next-hop-interface while generating static_routes nexthop + command. fragments: - - 172-fix-source-keyerror-firewallrules.yml - - docs_common_error_correction.yaml - - fix_static_routes_next_hop_interface.yaml - - update_readme_freenode_to_liberachat.yml - release_date: '2021-06-22' + - 172-fix-source-keyerror-firewallrules.yml + - docs_common_error_correction.yaml + - fix_static_routes_next_hop_interface.yaml + - update_readme_freenode_to_liberachat.yml + release_date: "2021-06-22" 2.4.0: changes: minor_changes: - - Add vyos_prefix_lists Resource Module. + - Add vyos_prefix_lists Resource Module. fragments: - - vyos_prefix_lists.yml + - vyos_prefix_lists.yml modules: - - description: Prefix-Lists resource module for VyOS - name: vyos_prefix_lists - namespace: '' - release_date: '2021-07-06' + - description: Prefix-Lists resource module for VyOS + name: vyos_prefix_lists + namespace: "" + release_date: "2021-07-06" 2.5.0: changes: bugfixes: - - fix issue in route-maps facts code when route-maps facts are empty. + - fix issue in route-maps facts code when route-maps facts are empty. deprecated_features: - - The vyos_logging module has been deprecated in favor of the new vyos_logging_global - resource module and will be removed in a release after "2023-08-01". + - The vyos_logging module has been deprecated in favor of the new vyos_logging_global + resource module and will be removed in a release after "2023-08-01". minor_changes: - - vyos_logging_global logging resource module. + - vyos_logging_global logging resource module. fragments: - - fix_issue_vyos_facts.yaml - - vyos_logging_global_module.yaml - release_date: '2021-07-26' + - fix_issue_vyos_facts.yaml + - vyos_logging_global_module.yaml + release_date: "2021-07-26" 2.5.1: changes: bugfixes: - - fix issue in firewall rules facts code when IPV6 ICMP type name in vyos.vyos.vyos_firewall_rules - is not idempotent + - fix issue in firewall rules facts code when IPV6 ICMP type name in vyos.vyos.vyos_firewall_rules + is not idempotent fragments: - - doc_updated_correct_platform.yaml - - fix_issue170_vyos_firewall_rules.yaml - - fix_pylint_issues.yaml - - tests_become.yaml - release_date: '2021-08-27' + - doc_updated_correct_platform.yaml + - fix_issue170_vyos_firewall_rules.yaml + - fix_pylint_issues.yaml + - tests_become.yaml + release_date: "2021-08-27" 2.6.0: changes: bugfixes: - - Fix vyos_firewall_rules with state replaced to only replace the specified - rules. + - Fix vyos_firewall_rules with state replaced to only replace the specified + rules. minor_changes: - - Add vyos_ntp Resource Module - - Adds support for specifying an `afi` for an `address_group` for `vyos.vyos.firewall_global`. As - a result, `address_group` now supports IPv6. - - Adds support for specifying an `afi` for an `network_group` for `vyos.vyos.firewall_global`. As - a result, `network_group` now supports IPv6. + - Add vyos_ntp Resource Module + - Adds support for specifying an `afi` for an `address_group` for `vyos.vyos.firewall_global`. As + a result, `address_group` now supports IPv6. + - Adds support for specifying an `afi` for an `network_group` for `vyos.vyos.firewall_global`. As + a result, `network_group` now supports IPv6. fragments: - - 0-copy_ignore_txt.yml - - fix-firewall_rules-state-replaced.yaml - - set_allow_duplicates.yaml - - support_ipv6_address_and_network_groups.yaml - - vyos_ntp.yml - release_date: '2021-10-02' + - 0-copy_ignore_txt.yml + - fix-firewall_rules-state-replaced.yaml + - set_allow_duplicates.yaml + - support_ipv6_address_and_network_groups.yaml + - vyos_ntp.yml + release_date: "2021-10-02" 2.7.0: changes: major_changes: - - Add 'pool' as value to server key in ntp_global. + - Add 'pool' as value to server key in ntp_global. minor_changes: - - Add vyos_snmp_server resource module. + - Add vyos_snmp_server resource module. fragments: - - add_snmp_server_resource_module.yaml - - ntp_server_add_pool.yaml - - remove-swap-file.yml - - sanity_issue_fix.yaml + - add_snmp_server_resource_module.yaml + - ntp_server_add_pool.yaml + - remove-swap-file.yml + - sanity_issue_fix.yaml modules: - - description: Manages snmp_server resource module - name: vyos_snmp_server - namespace: '' - release_date: '2022-01-31' + - description: Manages snmp_server resource module + name: vyos_snmp_server + namespace: "" + release_date: "2022-01-31" 2.8.0: changes: minor_changes: - - Add vyos_hostname resource module. - - Rename V4-EGRESS/V6-EGRESS to EGRESS in the tests to test the same-name situation - - Update vyos_facts to support IPv4 and IPv6 rule sets having the same name - - Update vyos_firewall_rules to support IPv4 and IPv6 rule sets having the same - name - - vyos_firewall_rules - Add support for log enable on individual rules - - vyos_firewall_rules - fixed incorrect option 'disabled' passed to the rules. + - Add vyos_hostname resource module. + - Rename V4-EGRESS/V6-EGRESS to EGRESS in the tests to test the same-name situation + - Update vyos_facts to support IPv4 and IPv6 rule sets having the same name + - Update vyos_firewall_rules to support IPv4 and IPv6 rule sets having the same + name + - vyos_firewall_rules - Add support for log enable on individual rules + - vyos_firewall_rules - fixed incorrect option 'disabled' passed to the rules. fragments: - - rule_set_same_name.yaml - - vyos_firewall_rules_add_log.yaml - - vyos_firewall_rules_fix_rules_disable.yaml - - vyos_hostname_rm.yaml + - rule_set_same_name.yaml + - vyos_firewall_rules_add_log.yaml + - vyos_firewall_rules_fix_rules_disable.yaml + - vyos_hostname_rm.yaml modules: - - description: Manages hostname resource module - name: vyos_hostname - namespace: '' - release_date: '2022-03-01' + - description: Manages hostname resource module + name: vyos_hostname + namespace: "" + release_date: "2022-03-01" 3.0.0: changes: bugfixes: - - Add symlink of modules under plugins/action + - Add symlink of modules under plugins/action major_changes: - - Minimum required ansible.netcommon version is 2.5.1. - - Updated base plugin references to ansible.netcommon. - - '`vyos_facts` - change default gather_subset to `min` from `!config` (https://github.com/ansible-collections/vyos.vyos/issues/231).' + - Minimum required ansible.netcommon version is 2.5.1. + - Updated base plugin references to ansible.netcommon. + - "`vyos_facts` - change default gather_subset to `min` from `!config` (https://github.com/ansible-collections/vyos.vyos/issues/231)." minor_changes: - - Change preconfig hostname from vyos to vyosuser + - Change preconfig hostname from vyos to vyosuser fragments: - - add_fqcn_ansible_connection.yaml - - add_symlinks_redirection.yml - - change_host_name.yml - - netcommon_ref_update.yaml - - vyos_facts_remove_warning.yaml - - vyos_facts_update.yaml - release_date: '2022-04-26' + - add_fqcn_ansible_connection.yaml + - add_symlinks_redirection.yml + - change_host_name.yml + - netcommon_ref_update.yaml + - vyos_facts_remove_warning.yaml + - vyos_facts_update.yaml + release_date: "2022-04-26" 3.0.1: changes: minor_changes: - - firewall_rules - icmpv6 type - add support for vyos sw >= 1.4. + - firewall_rules - icmpv6 type - add support for vyos sw >= 1.4. fragments: - - firewall_rule_cli_change_version_1.4.yaml - release_date: '2022-05-25' + - firewall_rule_cli_change_version_1.4.yaml + release_date: "2022-05-25" 4.0.0: changes: major_changes: - - 'Use of connection: local and the provider option are no longer valid on any - modules in this collection.' + - "Use of connection: local and the provider option are no longer valid on any + modules in this collection." minor_changes: - - Update fact gathering to support v1.3 show version output + - Update fact gathering to support v1.3 show version output removed_features: - - vyos_interface - use vyos_interfaces instead. - - vyos_l3_interface - use vyos_l3_interfaces instead. - - vyos_linkagg - use vyos_lag_interfaces instead. - - vyos_lldp - use vyos_lldp_global instead. - - vyos_lldp_interface - use vyos_lldp_interfaces instead. - - vyos_static_route - use vyos_static_routes instead. + - vyos_interface - use vyos_interfaces instead. + - vyos_l3_interface - use vyos_l3_interfaces instead. + - vyos_linkagg - use vyos_lag_interfaces instead. + - vyos_lldp - use vyos_lldp_global instead. + - vyos_lldp_interface - use vyos_lldp_interfaces instead. + - vyos_static_route - use vyos_static_routes instead. fragments: - - 271_equuleus_facts.yaml - - 2H22-removal.yaml - - fix-precommit-issues.yml - - fqcn.yaml - - gha.yaml - - ignores-2.15.yaml - - net_mods.yaml - - renamed.yaml - release_date: '2022-10-13' + - 271_equuleus_facts.yaml + - 2H22-removal.yaml + - fix-precommit-issues.yml + - fqcn.yaml + - gha.yaml + - ignores-2.15.yaml + - net_mods.yaml + - renamed.yaml + release_date: "2022-10-13" diff --git a/changelogs/config.yaml b/changelogs/config.yaml index 5818697..7a1e3ed 100644 --- a/changelogs/config.yaml +++ b/changelogs/config.yaml @@ -10,21 +10,21 @@ prelude_section_name: release_summary prelude_section_title: Release Summary flatmap: true sections: -- - major_changes - - Major Changes -- - minor_changes - - Minor Changes -- - breaking_changes - - Breaking Changes / Porting Guide -- - deprecated_features - - Deprecated Features -- - removed_features - - Removed Features (previously deprecated) -- - security_fixes - - Security Fixes -- - bugfixes - - Bugfixes -- - known_issues - - Known Issues + - - major_changes + - Major Changes + - - minor_changes + - Minor Changes + - - breaking_changes + - Breaking Changes / Porting Guide + - - deprecated_features + - Deprecated Features + - - removed_features + - Removed Features (previously deprecated) + - - security_fixes + - Security Fixes + - - bugfixes + - Bugfixes + - - known_issues + - Known Issues title: Vyos Collection trivial_section_name: trivial diff --git a/changelogs/fragments/prettier.yaml b/changelogs/fragments/prettier.yaml new file mode 100644 index 0000000..53a9359 --- /dev/null +++ b/changelogs/fragments/prettier.yaml @@ -0,0 +1,3 @@ +--- +trivial: + - Add isort and prettier pre-commit hooks diff --git a/meta/runtime.yml b/meta/runtime.yml index 8c7c766..02e7896 100644 --- a/meta/runtime.yml +++ b/meta/runtime.yml @@ -35,11 +35,11 @@ plugin_routing: logging: redirect: vyos.vyos.vyos_logging deprecation: - removal_date: '2023-08-01' + removal_date: "2023-08-01" warning_text: See the plugin documentation for more details vyos_logging: deprecation: - removal_date: '2023-08-01' + removal_date: "2023-08-01" warning_text: See the plugin documentation for more details logging_global: redirect: vyos.vyos.vyos_logging_global diff --git a/plugins/action/vyos.py b/plugins/action/vyos.py index f6f9aad..df8e712 100644 --- a/plugins/action/vyos.py +++ b/plugins/action/vyos.py @@ -20,10 +20,10 @@ from __future__ import absolute_import, division, print_function __metaclass__ = type +from ansible.utils.display import Display from ansible_collections.ansible.netcommon.plugins.action.network import ( ActionModule as ActionNetworkModule, ) -from ansible.utils.display import Display display = Display() @@ -33,9 +33,7 @@ class ActionModule(ActionNetworkModule): del tmp # tmp no longer has any effect module_name = self._task.action.split(".")[-1] - self._config_module = ( - True if module_name in ["vyos_config", "config"] else False - ) + self._config_module = True if module_name in ["vyos_config", "config"] else False persistent_connection = self._play_context.connection.split(".")[-1] warnings = [] diff --git a/plugins/cliconf/vyos.py b/plugins/cliconf/vyos.py index 885cf1f..4916d52 100644 --- a/plugins/cliconf/vyos.py +++ b/plugins/cliconf/vyos.py @@ -42,8 +42,8 @@ options: - name: ansible_vyos_config_commands """ -import re import json +import re from ansible.errors import AnsibleConnectionFailure from ansible.module_utils._text import to_text @@ -51,12 +51,8 @@ from ansible.module_utils.common._collections_compat import Mapping from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.config import ( NetworkConfig, ) -from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.utils import ( - to_list, -) -from ansible_collections.ansible.netcommon.plugins.plugin_utils.cliconf_base import ( - CliconfBase, -) +from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.utils import to_list +from ansible_collections.ansible.netcommon.plugins.plugin_utils.cliconf_base import CliconfBase class Cliconf(CliconfBase): @@ -119,14 +115,10 @@ class Cliconf(CliconfBase): out = self.send_command(command) return out - def edit_config( - self, candidate=None, commit=True, replace=None, comment=None - ): + def edit_config(self, candidate=None, commit=True, replace=None, comment=None): resp = {} operations = self.get_device_operations() - self.check_edit_config_capability( - operations, candidate, commit, replace, comment - ) + self.check_edit_config_capability(operations, candidate, commit, replace, comment) results = [] requests = [] @@ -156,9 +148,7 @@ class Cliconf(CliconfBase): else: self.send_command("exit") if ( - to_text( - self._connection.get_prompt(), errors="surrogate_or_strict" - ) + to_text(self._connection.get_prompt(), errors="surrogate_or_strict") .strip() .endswith("#") ): @@ -183,9 +173,7 @@ class Cliconf(CliconfBase): if not command: raise ValueError("must provide value of command to execute") if output: - raise ValueError( - "'output' value %s is not supported for get" % output - ) + raise ValueError("'output' value %s is not supported for get" % output) return self.send_command( command=command, @@ -220,9 +208,7 @@ class Cliconf(CliconfBase): option_values = self.get_option_values() if candidate is None and device_operations["supports_generate_diff"]: - raise ValueError( - "candidate configuration is required to generate diff" - ) + raise ValueError("candidate configuration is required to generate diff") if diff_match not in option_values["diff_match"]: raise ValueError( @@ -239,9 +225,7 @@ class Cliconf(CliconfBase): if path: raise ValueError("'path' in diff is not supported") - set_format = candidate.startswith("set") or candidate.startswith( - "delete" - ) + set_format = candidate.startswith("set") or candidate.startswith("delete") candidate_obj = NetworkConfig(indent=4, contents=candidate) if not set_format: config = [c.line for c in candidate_obj.items] @@ -254,9 +238,7 @@ class Cliconf(CliconfBase): break commands.append(item) - candidate_commands = [ - "set %s" % cmd.replace(" {", "") for cmd in commands - ] + candidate_commands = ["set %s" % cmd.replace(" {", "") for cmd in commands] else: candidate_commands = str(candidate).strip().split("\n") @@ -265,9 +247,7 @@ class Cliconf(CliconfBase): diff["config_diff"] = list(candidate_commands) return diff - running_commands = [ - str(c).replace("'", "") for c in running.splitlines() - ] + running_commands = [str(c).replace("'", "") for c in running.splitlines()] updates = list() visited = set() @@ -276,9 +256,7 @@ class Cliconf(CliconfBase): item = str(line).replace("'", "") if not item.startswith("set") and not item.startswith("delete"): - raise ValueError( - "line must start with either `set` or `delete`" - ) + raise ValueError("line must start with either `set` or `delete`") elif item.startswith("set") and item not in running_commands: updates.append(line) @@ -307,10 +285,7 @@ class Cliconf(CliconfBase): output = cmd.pop("output", None) if output: - raise ValueError( - "'output' value %s is not supported for run_commands" - % output - ) + raise ValueError("'output' value %s is not supported for run_commands" % output) try: out = self.send_command(**cmd) @@ -358,6 +333,4 @@ class Cliconf(CliconfBase): :return: None """ if self._connection.connected: - self._update_cli_prompt_context( - config_context="#", exit_command="exit discard" - ) + self._update_cli_prompt_context(config_context="#", exit_command="exit discard") diff --git a/plugins/module_utils/network/vyos/argspec/firewall_rules/firewall_rules.py b/plugins/module_utils/network/vyos/argspec/firewall_rules/firewall_rules.py index 61d9a55..0e80031 100644 --- a/plugins/module_utils/network/vyos/argspec/firewall_rules/firewall_rules.py +++ b/plugins/module_utils/network/vyos/argspec/firewall_rules/firewall_rules.py @@ -73,12 +73,8 @@ class Firewall_rulesArgs(object): # pylint: disable=R0903 "address": {"type": "str"}, "group": { "options": { - "address_group": { - "type": "str" - }, - "network_group": { - "type": "str" - }, + "address_group": {"type": "str"}, + "network_group": {"type": "str"}, "port_group": {"type": "str"}, }, "type": "dict", @@ -203,12 +199,8 @@ class Firewall_rulesArgs(object): # pylint: disable=R0903 "address": {"type": "str"}, "group": { "options": { - "address_group": { - "type": "str" - }, - "network_group": { - "type": "str" - }, + "address_group": {"type": "str"}, + "network_group": {"type": "str"}, "port_group": {"type": "str"}, }, "type": "dict", diff --git a/plugins/module_utils/network/vyos/argspec/ospfv2/ospfv2.py b/plugins/module_utils/network/vyos/argspec/ospfv2/ospfv2.py index 0061e79..6c83372 100644 --- a/plugins/module_utils/network/vyos/argspec/ospfv2/ospfv2.py +++ b/plugins/module_utils/network/vyos/argspec/ospfv2/ospfv2.py @@ -145,9 +145,7 @@ class Ospfv2Args(object): # pylint: disable=R0903 }, "network": { "elements": "dict", - "options": { - "address": {"required": True, "type": "str"} - }, + "options": {"address": {"required": True, "type": "str"}}, "type": "list", }, "range": { diff --git a/plugins/module_utils/network/vyos/argspec/route_maps/route_maps.py b/plugins/module_utils/network/vyos/argspec/route_maps/route_maps.py index 790f5e6..6baa434 100644 --- a/plugins/module_utils/network/vyos/argspec/route_maps/route_maps.py +++ b/plugins/module_utils/network/vyos/argspec/route_maps/route_maps.py @@ -183,9 +183,7 @@ class Route_mapsArgs(object): # pylint: disable=R0903 "next_hop": {"type": "str"}, }, }, - "large_community_large_community_list": { - "type": "str" - }, + "large_community_large_community_list": {"type": "str"}, "metric": {"type": "int"}, "origin": { "type": "str", diff --git a/plugins/module_utils/network/vyos/config/bgp_address_family/bgp_address_family.py b/plugins/module_utils/network/vyos/config/bgp_address_family/bgp_address_family.py index a62e6a5..53defde 100644 --- a/plugins/module_utils/network/vyos/config/bgp_address_family/bgp_address_family.py +++ b/plugins/module_utils/network/vyos/config/bgp_address_family/bgp_address_family.py @@ -20,15 +20,14 @@ created. import re from ansible.module_utils.six import iteritems -from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.utils import ( - dict_merge, -) from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.rm_base.resource_module import ( ResourceModule, ) -from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.facts import ( - Facts, +from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.utils import ( + dict_merge, ) + +from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.facts import Facts from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.rm_templates.bgp_address_family import ( Bgp_address_familyTemplate, ) @@ -67,18 +66,13 @@ class Bgp_address_family(ResourceModule): wantd = {} haved = {} - if ( - self.want.get("as_number") == self.have.get("as_number") - or not self.have - ): + if self.want.get("as_number") == self.have.get("as_number") or not self.have: if self.want: wantd = {self.want["as_number"]: self.want} if self.have: haved = {self.have["as_number"]: self.have} else: - self._module.fail_json( - msg="Only one bgp instance is allowed per device" - ) + self._module.fail_json(msg="Only one bgp instance is allowed per device") # turn all lists of dicts into dicts prior to merge for entry in wantd, haved: @@ -133,9 +127,7 @@ class Bgp_address_family(ResourceModule): for name, entry in iteritems(haf): if name not in waf.keys() and self.state == "replaced": continue - self._compare_lists( - {}, entry, as_number=have["as_number"], afi=name - ) + self._compare_lists({}, entry, as_number=have["as_number"], afi=name) def _delete_af(self, want, have): for as_num, entry in iteritems(want): @@ -162,9 +154,7 @@ class Bgp_address_family(ResourceModule): self._tmplt.render( { "as_number": as_num, - "neighbors": { - "neighbor_address": neigh - }, + "neighbors": {"neighbor_address": neigh}, }, "neighbors", True, @@ -174,8 +164,7 @@ class Bgp_address_family(ResourceModule): for k in neigh_entry["address_family"].keys(): if ( hnentry.get("address_family") - and k - in hnentry["address_family"].keys() + and k in hnentry["address_family"].keys() ): self.commands.append( self._tmplt.render( @@ -183,9 +172,7 @@ class Bgp_address_family(ResourceModule): "as_number": as_num, "neighbors": { "neighbor_address": neigh, - "address_family": { - "afi": k - }, + "address_family": {"afi": k}, }, }, "neighbors.address_family", @@ -240,9 +227,7 @@ class Bgp_address_family(ResourceModule): "neighbor_address": name, "address_family": { "afi": afi, - k: hneigh[name]["address_family"][ - afi - ].pop(k, {}), + k: hneigh[name]["address_family"][afi].pop(k, {}), }, }, } diff --git a/plugins/module_utils/network/vyos/config/bgp_global/bgp_global.py b/plugins/module_utils/network/vyos/config/bgp_global/bgp_global.py index f8de74e..96c640f 100644 --- a/plugins/module_utils/network/vyos/config/bgp_global/bgp_global.py +++ b/plugins/module_utils/network/vyos/config/bgp_global/bgp_global.py @@ -17,16 +17,16 @@ necessary to bring the current configuration to its desired end-state is created. """ import re + from ansible.module_utils.six import iteritems -from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.utils import ( - dict_merge, -) from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.rm_base.resource_module import ( ResourceModule, ) -from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.facts import ( - Facts, +from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.utils import ( + dict_merge, ) + +from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.facts import Facts from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.rm_templates.bgp_global import ( Bgp_globalTemplate, ) @@ -65,18 +65,13 @@ class Bgp_global(ResourceModule): wantd = {} haved = {} - if ( - self.want.get("as_number") == self.have.get("as_number") - or not self.have - ): + if self.want.get("as_number") == self.have.get("as_number") or not self.have: if self.want: wantd = {self.want["as_number"]: self.want} if self.have: haved = {self.have["as_number"]: self.have} else: - self._module.fail_json( - msg="Only one bgp instance is allowed per device" - ) + self._module.fail_json(msg="Only one bgp instance is allowed per device") # turn all lists of dicts into dicts prior to merge for entry in wantd, haved: @@ -93,9 +88,7 @@ class Bgp_global(ResourceModule): if k in wantd or not wantd: h_del.update({k: v}) for num, entry in iteritems(h_del): - self.commands.append( - self._tmplt.render({"as_number": num}, "router", True) - ) + self.commands.append(self._tmplt.render({"as_number": num}, "router", True)) wantd = {} if self.state == "deleted": @@ -214,10 +207,7 @@ class Bgp_global(ResourceModule): self._module.fail_json(msg=msg) else: self.commands.append( - "delete protocols bgp " - + str(have["as_number"]) - + " neighbor " - + name + "delete protocols bgp " + str(have["as_number"]) + " neighbor " + name ) continue for k, v in entry.items(): @@ -297,18 +287,12 @@ class Bgp_global(ResourceModule): }, ) if not wbgp and hbgp: - self.commands.append( - "delete protocols bgp " - + str(have["as_number"]) - + " parameters" - ) + self.commands.append("delete protocols bgp " + str(have["as_number"]) + " parameters") hbgp = {} for name, entry in iteritems(hbgp): if name == "confederation": self.commands.append( - "delete protocols bgp " - + str(have["as_number"]) - + " parameters confederation" + "delete protocols bgp " + str(have["as_number"]) + " parameters confederation" ) elif name == "distance": distance_parsers = [ @@ -356,10 +340,7 @@ class Bgp_global(ResourceModule): if not wdict and hdict: attrib = re.sub("_", "-", attrib) self.commands.append( - "delete protocols bgp " - + str(have["as_number"]) - + " " - + attrib + "delete protocols bgp " + str(have["as_number"]) + " " + attrib ) hdict = {} for key, entry in iteritems(hdict): diff --git a/plugins/module_utils/network/vyos/config/firewall_global/firewall_global.py b/plugins/module_utils/network/vyos/config/firewall_global/firewall_global.py index be8b172..079cba6 100644 --- a/plugins/module_utils/network/vyos/config/firewall_global/firewall_global.py +++ b/plugins/module_utils/network/vyos/config/firewall_global/firewall_global.py @@ -15,17 +15,17 @@ from __future__ import absolute_import, division, print_function __metaclass__ = type from copy import deepcopy + +from ansible.module_utils.six import iteritems from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.cfg.base import ( ConfigBase, ) from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.utils import ( - to_list, remove_empties, + to_list, ) -from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.facts import ( - Facts, -) -from ansible.module_utils.six import iteritems + +from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.facts import Facts from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.utils.utils import ( list_diff_want_only, ) @@ -52,9 +52,7 @@ class Firewall_global(ConfigBase): facts, _warnings = Facts(self._module).get_facts( self.gather_subset, self.gather_network_resources, data=data ) - firewall_global_facts = facts["ansible_network_resources"].get( - "firewall_global" - ) + firewall_global_facts = facts["ansible_network_resources"].get("firewall_global") if not firewall_global_facts: return [] return firewall_global_facts @@ -95,9 +93,7 @@ class Firewall_global(ConfigBase): self._module.fail_json( msg="value of running_config parameter must not be empty for state parsed" ) - result["parsed"] = self.get_firewall_global_facts( - data=running_config - ) + result["parsed"] = self.get_firewall_global_facts(data=running_config) else: changed_firewall_global_facts = [] @@ -136,9 +132,7 @@ class Firewall_global(ConfigBase): commands = [] if self.state in ("merged", "replaced", "rendered") and not w: self._module.fail_json( - msg="value of config parameter must not be empty for state {0}".format( - self.state - ) + msg="value of config parameter must not be empty for state {0}".format(self.state) ) if self.state == "deleted": commands.extend(self._state_deleted(want=None, have=h)) @@ -191,13 +185,7 @@ class Firewall_global(ConfigBase): for key, val in iteritems(want): if val and key in b_set and not have: commands.append(self._form_attr_cmd(attr=key, opr=False)) - elif ( - val - and key in b_set - and have - and key in have - and have[key] != val - ): + elif val and key in b_set and have and key in have and have[key] != val: commands.append(self._form_attr_cmd(attr=key, opr=False)) else: commands.extend(self._render_attr_config(want, have, key)) @@ -252,22 +240,14 @@ class Firewall_global(ConfigBase): ) if w_fg: for key, val in iteritems(w_fg): - if ( - opr - and key in l_set - and not (h and self._is_w_same(w_fg, h, key)) - ): + if opr and key in l_set and not (h and self._is_w_same(w_fg, h, key)): commands.append( - self._form_attr_cmd( - attr=key, val=self._bool_to_str(val), opr=opr - ) + self._form_attr_cmd(attr=key, val=self._bool_to_str(val), opr=opr) ) elif not opr: if key and self._is_del(l_set, h): commands.append( - self._form_attr_cmd( - attr=key, key=self._bool_to_str(val), opr=opr - ) + self._form_attr_cmd(attr=key, key=self._bool_to_str(val), opr=opr) ) continue if ( @@ -276,14 +256,10 @@ class Firewall_global(ConfigBase): and not self._is_del(l_set, h) ): commands.append( - self._form_attr_cmd( - attr=key, val=self._bool_to_str(val), opr=opr - ) + self._form_attr_cmd(attr=key, val=self._bool_to_str(val), opr=opr) ) else: - commands.extend( - self._render_attr_config(w_fg, h, key, opr) - ) + commands.extend(self._render_attr_config(w_fg, h, key, opr)) return commands def _render_ping(self, attr, w, h, opr): @@ -314,9 +290,7 @@ class Firewall_global(ConfigBase): and not (h_ping and self._is_w_same(w[attr], h_ping, item)) ): commands.append( - self._form_attr_cmd( - attr=item, val=self._bool_to_str(value), opr=opr - ) + self._form_attr_cmd(attr=item, val=self._bool_to_str(value), opr=opr) ) elif ( not opr @@ -343,19 +317,9 @@ class Firewall_global(ConfigBase): if h: h_grp = h.get("group") or {} if w: - commands.extend( - self._render_grp_mem("port_group", w["group"], h_grp, opr) - ) - commands.extend( - self._render_grp_mem( - "address_group", w["group"], h_grp, opr - ) - ) - commands.extend( - self._render_grp_mem( - "network_group", w["group"], h_grp, opr - ) - ) + commands.extend(self._render_grp_mem("port_group", w["group"], h_grp, opr)) + commands.extend(self._render_grp_mem("address_group", w["group"], h_grp, opr)) + commands.extend(self._render_grp_mem("network_group", w["group"], h_grp, opr)) return commands def _render_grp_mem(self, attr, w, h, opr): @@ -380,20 +344,12 @@ class Firewall_global(ConfigBase): for want in w_grp: h = self.search_attrib_in_have(h_grp, want, "name") if "afi" in want and want["afi"] == "ipv6": - cmd = self._compute_command( - key="group", attr="ipv6-" + attr, opr=opr - ) + cmd = self._compute_command(key="group", attr="ipv6-" + attr, opr=opr) else: - cmd = self._compute_command( - key="group", attr=attr, opr=opr - ) + cmd = self._compute_command(key="group", attr=attr, opr=opr) for key, val in iteritems(want): if val: - if ( - opr - and key in l_set - and not (h and self._is_w_same(want, h, key)) - ): + if opr and key in l_set and not (h and self._is_w_same(want, h, key)): if key == "name": commands.append(cmd + " " + str(val)) else: @@ -408,22 +364,16 @@ class Firewall_global(ConfigBase): + "'" ) elif not opr and key in l_set: - if key == "name" and self._is_grp_del( - h, want, key - ): + if key == "name" and self._is_grp_del(h, want, key): commands.append(cmd + " " + want["name"]) continue - if not ( - h and self._in_target(h, key) - ) and not self._is_grp_del(h, want, key): - commands.append( - cmd + " " + want["name"] + " " + key - ) + if not (h and self._in_target(h, key)) and not self._is_grp_del( + h, want, key + ): + commands.append(cmd + " " + want["name"] + " " + key) elif key == "members": commands.extend( - self._render_ports_addrs( - key, want, h, opr, cmd, want["name"], attr - ) + self._render_ports_addrs(key, want, h, opr, cmd, want["name"], attr) ) return commands @@ -505,11 +455,7 @@ class Firewall_global(ConfigBase): h = self.search_attrib_in_have(have, w, "connection_type") for key, val in iteritems(w): if val and key != "connection_type": - if ( - opr - and key in l_set - and not (h and self._is_w_same(w, h, key)) - ): + if opr and key in l_set and not (h and self._is_w_same(w, h, key)): commands.append( self._form_attr_cmd( key=attr + " " + w["connection_type"], @@ -519,24 +465,20 @@ class Firewall_global(ConfigBase): ) ) elif not opr and key in l_set: - if not ( - h and self._in_target(h, key) - ) and not self._is_del(l_set, h): + if not (h and self._in_target(h, key)) and not self._is_del( + l_set, h + ): if key == "action": commands.append( self._form_attr_cmd( - attr=attr - + " " - + w["connection_type"], + attr=attr + " " + w["connection_type"], opr=opr, ) ) else: commands.append( self._form_attr_cmd( - attr=attr - + " " - + w["connection_type"], + attr=attr + " " + w["connection_type"], val=self._bool_to_str(val), opr=opr, ) @@ -566,11 +508,7 @@ class Firewall_global(ConfigBase): h = self.search_attrib_in_have(have, w, "afi") for key, val in iteritems(w): if val and key != "afi": - if ( - opr - and key in l_set - and not (h and self._is_w_same(w, h, key)) - ): + if opr and key in l_set and not (h and self._is_w_same(w, h, key)): commands.append( self._form_attr_cmd( attr=key, @@ -588,9 +526,7 @@ class Firewall_global(ConfigBase): ) ) continue - if not ( - h and self._in_target(h, key) - ) and not self._is_del(l_set, h): + if not (h and self._in_target(h, key)) and not self._is_del(l_set, h): commands.append( self._form_attr_cmd( attr=key, @@ -599,9 +535,7 @@ class Firewall_global(ConfigBase): ) ) elif key == "icmp_redirects": - commands.extend( - self._render_icmp_redirects(key, w, h, opr) - ) + commands.extend(self._render_icmp_redirects(key, w, h, opr)) return commands def _render_icmp_redirects(self, attr, w, h, opr): @@ -621,15 +555,9 @@ class Firewall_global(ConfigBase): if h and attr in h.keys(): h_red = h.get(attr) or {} for item, value in iteritems(w[attr]): - if ( - opr - and item in l_set - and not (h_red and self._is_w_same(w[attr], h_red, item)) - ): + if opr and item in l_set and not (h_red and self._is_w_same(w[attr], h_red, item)): commands.append( - self._form_attr_cmd( - attr=item, val=self._bool_to_str(value), opr=opr - ) + self._form_attr_cmd(attr=item, val=self._bool_to_str(value), opr=opr) ) elif ( not opr @@ -662,14 +590,10 @@ class Firewall_global(ConfigBase): :param opr: True/False. :return: generated command. """ - command = self._compute_command( - key=key, attr=self._map_attrib(attr), val=val, opr=opr - ) + command = self._compute_command(key=key, attr=self._map_attrib(attr), val=val, opr=opr) return command - def _compute_command( - self, key=None, attr=None, val=None, remove=False, opr=True - ): + def _compute_command(self, key=None, attr=None, val=None, remove=False, opr=True): """ This function construct the add/delete command based on passed attributes. :param key: parent key. @@ -697,13 +621,7 @@ class Firewall_global(ConfigBase): :param val: bool value. :return: enable/disable. """ - return ( - "enable" - if str(val) == "True" - else "disable" - if str(val) == "False" - else val - ) + return "enable" if str(val) == "True" else "disable" if str(val) == "False" else val def _grp_type(self, val): """ @@ -712,11 +630,7 @@ class Firewall_global(ConfigBase): :return: member type. """ return ( - "address" - if val == "address_group" - else "network" - if val == "network_group" - else "port" + "address" if val == "address_group" else "network" if val == "network_group" else "port" ) def _is_w_same(self, w, h, key): @@ -748,11 +662,7 @@ class Firewall_global(ConfigBase): :param key: group name. :return: True/False. """ - return ( - True - if h and key in h and (not w or key not in w or not w[key]) - else False - ) + return True if h and key in h and (not w or key not in w or not w[key]) else False def _is_root_del(self, w, h, key): """ @@ -763,11 +673,7 @@ class Firewall_global(ConfigBase): :param key: attribute name. :return: True/False. """ - return ( - True - if h and key in h and (not w or key not in w or not w[key]) - else False - ) + return True if h and key in h and (not w or key not in w or not w[key]) else False def _is_del(self, b_set, h, key="number"): """ diff --git a/plugins/module_utils/network/vyos/config/firewall_interfaces/firewall_interfaces.py b/plugins/module_utils/network/vyos/config/firewall_interfaces/firewall_interfaces.py index 45842f1..566bfeb 100644 --- a/plugins/module_utils/network/vyos/config/firewall_interfaces/firewall_interfaces.py +++ b/plugins/module_utils/network/vyos/config/firewall_interfaces/firewall_interfaces.py @@ -15,17 +15,17 @@ from __future__ import absolute_import, division, print_function __metaclass__ = type from copy import deepcopy + from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.cfg.base import ( ConfigBase, ) from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.utils import ( - to_list, remove_empties, search_obj_in_list, + to_list, ) -from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.facts import ( - Facts, -) + +from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.facts import Facts class Firewall_interfaces(ConfigBase): @@ -54,9 +54,7 @@ class Firewall_interfaces(ConfigBase): facts, _warnings = Facts(self._module).get_facts( self.gather_subset, self.gather_network_resources, data=data ) - firewall_interfaces_facts = facts["ansible_network_resources"].get( - "firewall_interfaces" - ) + firewall_interfaces_facts = facts["ansible_network_resources"].get("firewall_interfaces") if not firewall_interfaces_facts: return [] return firewall_interfaces_facts @@ -72,16 +70,12 @@ class Firewall_interfaces(ConfigBase): commands = list() if self.state in self.ACTION_STATES: - existing_firewall_interfaces_facts = ( - self.get_firewall_interfaces_facts() - ) + existing_firewall_interfaces_facts = self.get_firewall_interfaces_facts() else: existing_firewall_interfaces_facts = [] if self.state in self.ACTION_STATES or self.state == "rendered": - commands.extend( - self.set_config(existing_firewall_interfaces_facts) - ) + commands.extend(self.set_config(existing_firewall_interfaces_facts)) if commands and self.state in self.ACTION_STATES: if not self._module.check_mode: @@ -92,9 +86,7 @@ class Firewall_interfaces(ConfigBase): result["commands"] = commands if self.state in self.ACTION_STATES or self.state == "gathered": - changed_firewall_interfaces_facts = ( - self.get_firewall_interfaces_facts() - ) + changed_firewall_interfaces_facts = self.get_firewall_interfaces_facts() elif self.state == "rendered": result["rendered"] = commands elif self.state == "parsed": @@ -103,9 +95,7 @@ class Firewall_interfaces(ConfigBase): self._module.fail_json( msg="value of running_config parameter must not be empty for state parsed" ) - result["parsed"] = self.get_firewall_interfaces_facts( - data=running_config - ) + result["parsed"] = self.get_firewall_interfaces_facts(data=running_config) else: changed_firewall_interfaces_facts = [] @@ -142,14 +132,9 @@ class Firewall_interfaces(ConfigBase): to the desired configuration """ commands = [] - if ( - self.state in ("merged", "replaced", "overridden", "rendered") - and not w - ): + if self.state in ("merged", "replaced", "overridden", "rendered") and not w: self._module.fail_json( - msg="value of config parameter must not be empty for state {0}".format( - self.state - ) + msg="value of config parameter must not be empty for state {0}".format(self.state) ) if self.state == "overridden": commands.extend(self._state_overridden(w, h)) @@ -189,41 +174,27 @@ class Firewall_interfaces(ConfigBase): for h_ar in have: w_ar = search_obj_in_list(h_ar["name"], want) if not w_ar and "access_rules" in h_ar: - commands.append( - self._compute_command(name=h_ar["name"], opr=False) - ) + commands.append(self._compute_command(name=h_ar["name"], opr=False)) else: h_rules = h_ar.get("access_rules") or [] key = "direction" if w_ar: w_rules = w_ar.get("access_rules") or [] if not w_rules and h_rules: - commands.append( - self._compute_command( - name=h_ar["name"], opr=False - ) - ) + commands.append(self._compute_command(name=h_ar["name"], opr=False)) if h_rules: for h_rule in h_rules: - w_rule = search_obj_in_list( - h_rule["afi"], w_rules, key="afi" - ) + w_rule = search_obj_in_list(h_rule["afi"], w_rules, key="afi") have_rules = h_rule.get("rules") or [] if w_rule: want_rules = w_rule.get("rules") or [] for h in have_rules: if key in h: - w = search_obj_in_list( - h[key], want_rules, key=key - ) + w = search_obj_in_list(h[key], want_rules, key=key) if ( not w or key not in w - or ( - "name" in h - and w - and "name" not in w - ) + or ("name" in h and w and "name" not in w) ): commands.append( self._compute_command( @@ -267,9 +238,7 @@ class Firewall_interfaces(ConfigBase): elif have: for h in have: if "access_rules" in h: - commands.append( - self._compute_command(name=h["name"], opr=False) - ) + commands.append(self._compute_command(name=h["name"], opr=False)) return commands def _delete_access_rules(self, want, have, opr=False): @@ -321,9 +290,7 @@ class Firewall_interfaces(ConfigBase): for h in h_rules: if key in h: commands.append( - self._compute_command( - afi=want["afi"], name=name, attrib=h[key], opr=opr - ) + self._compute_command(afi=want["afi"], name=name, attrib=h[key], opr=opr) ) for w in w_rules: h = search_obj_in_list(w[key], h_rules, key=key) @@ -388,9 +355,7 @@ class Firewall_interfaces(ConfigBase): h = search_obj_in_list(w[key], h_rules, key=key) if key in w: if opr: - if "name" in w and not ( - h and h[key] == w[key] and h["name"] == w["name"] - ): + if "name" in w and not (h and h[key] == w[key] and h["name"] == w["name"]): commands.append( self._compute_command( afi=want["afi"], @@ -401,16 +366,10 @@ class Firewall_interfaces(ConfigBase): ) elif not (h and key in h): commands.append( - self._compute_command( - afi=want["afi"], name=name, attrib=w[key] - ) + self._compute_command(afi=want["afi"], name=name, attrib=w[key]) ) elif not opr: - if ( - not h - or key not in h - or ("name" in w and h and "name" not in h) - ): + if not h or key not in h or ("name" in w and h and "name" not in h): commands.append( self._compute_command( afi=want["afi"], @@ -421,9 +380,7 @@ class Firewall_interfaces(ConfigBase): ) return commands - def _compute_command( - self, afi=None, name=None, attrib=None, value=None, opr=True - ): + def _compute_command(self, afi=None, name=None, attrib=None, value=None, opr=True): """ This function construct the add/delete command based on passed attributes. :param afi: address type. diff --git a/plugins/module_utils/network/vyos/config/firewall_rules/firewall_rules.py b/plugins/module_utils/network/vyos/config/firewall_rules/firewall_rules.py index ca47652..aa18a7e 100644 --- a/plugins/module_utils/network/vyos/config/firewall_rules/firewall_rules.py +++ b/plugins/module_utils/network/vyos/config/firewall_rules/firewall_rules.py @@ -14,22 +14,22 @@ from __future__ import absolute_import, division, print_function __metaclass__ = type +import re from copy import deepcopy + +from ansible.module_utils.six import iteritems from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.cfg.base import ( ConfigBase, ) from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.utils import ( - to_list, remove_empties, + to_list, ) -from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.facts import ( - Facts, -) -from ansible.module_utils.six import iteritems + +from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.facts import Facts from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.utils.utils import ( list_diff_want_only, ) -import re class Firewall_rules(ConfigBase): @@ -58,9 +58,7 @@ class Firewall_rules(ConfigBase): facts, _warnings = Facts(self._module).get_facts( self.gather_subset, self.gather_network_resources, data=data ) - firewall_rules_facts = facts["ansible_network_resources"].get( - "firewall_rules" - ) + firewall_rules_facts = facts["ansible_network_resources"].get("firewall_rules") if not firewall_rules_facts: return [] return firewall_rules_facts @@ -101,9 +99,7 @@ class Firewall_rules(ConfigBase): self._module.fail_json( msg="value of running_config parameter must not be empty for state parsed" ) - result["parsed"] = self.get_firewall_rules_facts( - data=running_config - ) + result["parsed"] = self.get_firewall_rules_facts(data=running_config) else: changed_firewall_rules_facts = [] @@ -140,14 +136,9 @@ class Firewall_rules(ConfigBase): to the desired configuration """ commands = [] - if ( - self.state in ("merged", "replaced", "overridden", "rendered") - and not w - ): + if self.state in ("merged", "replaced", "overridden", "rendered") and not w: self._module.fail_json( - msg="value of config parameter must not be empty for state {0}".format( - self.state - ) + msg="value of config parameter must not be empty for state {0}".format(self.state) ) if self.state == "overridden": commands.extend(self._state_overridden(w, h)) @@ -206,19 +197,11 @@ class Firewall_rules(ConfigBase): for h in have: r_sets = self._get_r_sets(h) for rs in r_sets: - w = self.search_r_sets_in_have( - want, rs["name"], "r_list", h["afi"] - ) + w = self.search_r_sets_in_have(want, rs["name"], "r_list", h["afi"]) if not w: - commands.append( - self._compute_command( - h["afi"], rs["name"], remove=True - ) - ) + commands.append(self._compute_command(h["afi"], rs["name"], remove=True)) else: - commands.extend( - self._add_r_sets(h["afi"], rs, w, opr=False) - ) + commands.extend(self._add_r_sets(h["afi"], rs, w, opr=False)) commands.extend(self._state_merged(want, have)) return commands @@ -233,9 +216,7 @@ class Firewall_rules(ConfigBase): for w in want: r_sets = self._get_r_sets(w) for rs in r_sets: - h = self.search_r_sets_in_have( - have, rs["name"], "r_list", w["afi"] - ) + h = self.search_r_sets_in_have(have, rs["name"], "r_list", w["afi"]) commands.extend(self._add_r_sets(w["afi"], rs, h)) return commands @@ -252,28 +233,18 @@ class Firewall_rules(ConfigBase): r_sets = self._get_r_sets(w) if r_sets: for rs in r_sets: - h = self.search_r_sets_in_have( - have, rs["name"], "r_list", w["afi"] - ) + h = self.search_r_sets_in_have(have, rs["name"], "r_list", w["afi"]) if h: - commands.append( - self._compute_command( - w["afi"], h["name"], remove=True - ) - ) + commands.append(self._compute_command(w["afi"], h["name"], remove=True)) elif have: for h in have: if h["afi"] == w["afi"]: - commands.append( - self._compute_command(w["afi"], remove=True) - ) + commands.append(self._compute_command(w["afi"], remove=True)) elif have: for h in have: r_sets = self._get_r_sets(h) if r_sets: - commands.append( - self._compute_command(afi=h["afi"], remove=True) - ) + commands.append(self._compute_command(afi=h["afi"], remove=True)) return commands def _add_r_sets(self, afi, want, have, opr=True): @@ -297,26 +268,12 @@ class Firewall_rules(ConfigBase): h_rules = h_rs.pop("rules", None) if w_rs: for key, val in iteritems(w_rs): - if ( - opr - and key in l_set - and not (h_rs and self._is_w_same(w_rs, h_rs, key)) - ): + if opr and key in l_set and not (h_rs and self._is_w_same(w_rs, h_rs, key)): if key == "enable_default_log": - if val and ( - not h_rs or key not in h_rs or not h_rs[key] - ): - commands.append( - self._add_rs_base_attrib( - afi, want["name"], key, w_rs - ) - ) + if val and (not h_rs or key not in h_rs or not h_rs[key]): + commands.append(self._add_rs_base_attrib(afi, want["name"], key, w_rs)) else: - commands.append( - self._add_rs_base_attrib( - afi, want["name"], key, w_rs - ) - ) + commands.append(self._add_rs_base_attrib(afi, want["name"], key, w_rs)) elif not opr and key in l_set: if ( key == "enable_default_log" @@ -324,20 +281,10 @@ class Firewall_rules(ConfigBase): and h_rs and (key not in h_rs or not h_rs[key]) ): - commands.append( - self._add_rs_base_attrib( - afi, want["name"], key, w_rs, opr - ) - ) + commands.append(self._add_rs_base_attrib(afi, want["name"], key, w_rs, opr)) elif not (h_rs and self._in_target(h_rs, key)): - commands.append( - self._add_rs_base_attrib( - afi, want["name"], key, w_rs, opr - ) - ) - commands.extend( - self._add_rules(afi, want["name"], w_rules, h_rules, opr) - ) + commands.append(self._add_rs_base_attrib(afi, want["name"], key, w_rs, opr)) + commands.extend(self._add_rules(afi, want["name"], w_rules, h_rules, opr)) if h_rules: have["rules"] = h_rules if w_rules: @@ -366,87 +313,43 @@ class Firewall_rules(ConfigBase): if w_rules: for w in w_rules: cmd = self._compute_command(afi, name, w["number"], opr=opr) - h = self.search_r_sets_in_have( - h_rules, w["number"], type="rules" - ) + h = self.search_r_sets_in_have(h_rules, w["number"], type="rules") for key, val in iteritems(w): if val: - if ( - opr - and key in l_set - and not (h and self._is_w_same(w, h, key)) - ): + if opr and key in l_set and not (h and self._is_w_same(w, h, key)): if key == "disable": - if not ( - not val - and (not h or key not in h or not h[key]) - ): - commands.append( - self._add_r_base_attrib( - afi, name, key, w - ) - ) + if not (not val and (not h or key not in h or not h[key])): + commands.append(self._add_r_base_attrib(afi, name, key, w)) else: - commands.append( - self._add_r_base_attrib(afi, name, key, w) - ) + commands.append(self._add_r_base_attrib(afi, name, key, w)) elif not opr: if key == "number" and self._is_del(l_set, h): - commands.append( - self._add_r_base_attrib( - afi, name, key, w, opr=opr - ) - ) + commands.append(self._add_r_base_attrib(afi, name, key, w, opr=opr)) continue - if ( - key == "disable" - and val - and h - and (key not in h or not h[key]) - ): - commands.append( - self._add_r_base_attrib( - afi, name, key, w, opr=opr - ) - ) + if key == "disable" and val and h and (key not in h or not h[key]): + commands.append(self._add_r_base_attrib(afi, name, key, w, opr=opr)) elif ( key in l_set and not (h and self._in_target(h, key)) and not self._is_del(l_set, h) ): - commands.append( - self._add_r_base_attrib( - afi, name, key, w, opr=opr - ) - ) + commands.append(self._add_r_base_attrib(afi, name, key, w, opr=opr)) elif key == "p2p": commands.extend(self._add_p2p(key, w, h, cmd, opr)) elif key == "tcp": commands.extend(self._add_tcp(key, w, h, cmd, opr)) elif key == "time": - commands.extend( - self._add_time(key, w, h, cmd, opr) - ) + commands.extend(self._add_time(key, w, h, cmd, opr)) elif key == "icmp": - commands.extend( - self._add_icmp(key, w, h, cmd, opr) - ) + commands.extend(self._add_icmp(key, w, h, cmd, opr)) elif key == "state": - commands.extend( - self._add_state(key, w, h, cmd, opr) - ) + commands.extend(self._add_state(key, w, h, cmd, opr)) elif key == "limit": - commands.extend( - self._add_limit(key, w, h, cmd, opr) - ) + commands.extend(self._add_limit(key, w, h, cmd, opr)) elif key == "recent": - commands.extend( - self._add_recent(key, w, h, cmd, opr) - ) + commands.extend(self._add_recent(key, w, h, cmd, opr)) elif key == "destination" or key == "source": - commands.extend( - self._add_src_or_dest(key, w, h, cmd, opr) - ) + commands.extend(self._add_src_or_dest(key, w, h, cmd, opr)) return commands def _add_p2p(self, attr, w, h, cmd, opr): @@ -467,15 +370,11 @@ class Firewall_rules(ConfigBase): if opr: applications = list_diff_want_only(want, have) for app in applications: - commands.append( - cmd + (" " + attr + " " + app["application"]) - ) + commands.append(cmd + (" " + attr + " " + app["application"])) elif not opr and have: applications = list_diff_want_only(want, have) for app in applications: - commands.append( - cmd + (" " + attr + " " + app["application"]) - ) + commands.append(cmd + (" " + attr + " " + app["application"])) return commands def _add_state(self, attr, w, h, cmd, opr): @@ -497,26 +396,10 @@ class Firewall_rules(ConfigBase): if ( opr and item in l_set - and not ( - h_state and self._is_w_same(w[attr], h_state, item) - ) - ): - commands.append( - cmd - + ( - " " - + attr - + " " - + item - + " " - + self._bool_to_str(val) - ) - ) - elif ( - not opr - and item in l_set - and not (h_state and self._in_target(h_state, item)) + and not (h_state and self._is_w_same(w[attr], h_state, item)) ): + commands.append(cmd + (" " + attr + " " + item + " " + self._bool_to_str(val))) + elif not opr and item in l_set and not (h_state and self._in_target(h_state, item)): commands.append(cmd + (" " + attr + " " + item)) return commands @@ -539,17 +422,11 @@ class Firewall_rules(ConfigBase): if ( opr and item in l_set - and not ( - h_recent and self._is_w_same(w[attr], h_recent, item) - ) + and not (h_recent and self._is_w_same(w[attr], h_recent, item)) ): - commands.append( - cmd + (" " + attr + " " + item + " " + str(val)) - ) + commands.append(cmd + (" " + attr + " " + item + " " + str(val))) elif ( - not opr - and item in l_set - and not (h_recent and self._in_target(h_recent, item)) + not opr and item in l_set and not (h_recent and self._in_target(h_recent, item)) ): commands.append(cmd + (" " + attr + " " + item)) return commands @@ -587,38 +464,14 @@ class Firewall_rules(ConfigBase): else: param_name = "type" if "ipv6-name" in cmd: - commands.append( - cmd - + ( - " " - + "icmpv6" - + " " - + param_name - + " " - + val - ) - ) + commands.append(cmd + (" " + "icmpv6" + " " + param_name + " " + val)) else: commands.append( - cmd - + ( - " " - + attr - + " " - + item.replace("_", "-") - + " " - + val - ) + cmd + (" " + attr + " " + item.replace("_", "-") + " " + val) ) else: - commands.append( - cmd + (" " + attr + " " + item + " " + str(val)) - ) - elif ( - not opr - and item in l_set - and not (h_icmp and self._in_target(h_icmp, item)) - ): + commands.append(cmd + (" " + attr + " " + item + " " + str(val))) + elif not opr and item in l_set and not (h_icmp and self._in_target(h_icmp, item)): commands.append(cmd + (" " + attr + " " + item)) return commands @@ -652,14 +505,10 @@ class Firewall_rules(ConfigBase): and not (h_time and self._is_w_same(w[attr], h_time, item)) ): if item == "utc": - if not ( - not val and (not h_time or item not in h_time) - ): + if not (not val and (not h_time or item not in h_time)): commands.append(cmd + (" " + attr + " " + item)) else: - commands.append( - cmd + (" " + attr + " " + item + " " + val) - ) + commands.append(cmd + (" " + attr + " " + item + " " + val)) elif ( not opr and item in l_set @@ -686,18 +535,10 @@ class Firewall_rules(ConfigBase): if h and key in h[attr].keys(): h_tcp = h[attr].get(key) or {} if flags: - if opr and not ( - h_tcp and self._is_w_same(w[attr], h[attr], key) - ): - commands.append( - cmd + (" " + attr + " " + key + " " + flags) - ) - if not opr and not ( - h_tcp and self._is_w_same(w[attr], h[attr], key) - ): - commands.append( - cmd + (" " + attr + " " + key + " " + flags) - ) + if opr and not (h_tcp and self._is_w_same(w[attr], h[attr], key)): + commands.append(cmd + (" " + attr + " " + key + " " + flags)) + if not opr and not (h_tcp and self._is_w_same(w[attr], h[attr], key)): + commands.append(cmd + (" " + attr + " " + key + " " + flags)) return commands def _add_limit(self, attr, w, h, cmd, opr): @@ -716,27 +557,15 @@ class Firewall_rules(ConfigBase): if ( opr and key in w[attr].keys() - and not ( - h - and attr in h.keys() - and self._is_w_same(w[attr], h[attr], key) - ) + and not (h and attr in h.keys() and self._is_w_same(w[attr], h[attr], key)) ): - commands.append( - cmd - + (" " + attr + " " + key + " " + str(w[attr].get(key))) - ) + commands.append(cmd + (" " + attr + " " + key + " " + str(w[attr].get(key)))) elif ( not opr and key in w[attr].keys() - and not ( - h and attr in h.keys() and self._in_target(h[attr], key) - ) + and not (h and attr in h.keys() and self._in_target(h[attr], key)) ): - commands.append( - cmd - + (" " + attr + " " + key + " " + str(w[attr].get(key))) - ) + commands.append(cmd + (" " + attr + " " + key + " " + str(w[attr].get(key)))) key = "rate" rate = w[attr].get(key) or {} if rate: @@ -787,31 +616,15 @@ class Firewall_rules(ConfigBase): if ( opr and key in w[attr].keys() - and not ( - h - and attr in h.keys() - and self._is_w_same(w[attr], h[attr], key) - ) + and not (h and attr in h.keys() and self._is_w_same(w[attr], h[attr], key)) ): commands.append( - cmd - + ( - " " - + attr - + " " - + key.replace("_", "-") - + " " - + w[attr].get(key) - ) + cmd + (" " + attr + " " + key.replace("_", "-") + " " + w[attr].get(key)) ) elif ( not opr and key in w[attr].keys() - and not ( - h - and attr in h.keys() - and self._in_target(h[attr], key) - ) + and not (h and attr in h.keys() and self._in_target(h[attr], key)) ): commands.append(cmd + (" " + attr + " " + key)) @@ -826,10 +639,7 @@ class Firewall_rules(ConfigBase): if ( opr and item in g_set - and not ( - h_group - and self._is_w_same(group, h_group, item) - ) + and not (h_group and self._is_w_same(group, h_group, item)) ): commands.append( cmd @@ -847,20 +657,10 @@ class Firewall_rules(ConfigBase): elif ( not opr and item in g_set - and not ( - h_group and self._in_target(h_group, item) - ) + and not (h_group and self._in_target(h_group, item)) ): commands.append( - cmd - + ( - " " - + attr - + " " - + key - + " " - + item.replace("_", "-") - ) + cmd + (" " + attr + " " + key + " " + item.replace("_", "-")) ) return commands @@ -938,12 +738,7 @@ class Firewall_rules(ConfigBase): cmd += " rule " + str(number) if attrib: cmd += " " + attrib.replace("_", "-") - if ( - value - and opr - and attrib != "enable_default_log" - and attrib != "disable" - ): + if value and opr and attrib != "enable_default_log" and attrib != "disable": cmd += " '" + str(value) + "'" return cmd @@ -959,9 +754,7 @@ class Firewall_rules(ConfigBase): :return: generated command. """ if attr == "number": - command = self._compute_command( - afi=afi, name=name, number=rule["number"], opr=opr - ) + command = self._compute_command(afi=afi, name=name, number=rule["number"], opr=opr) else: command = self._compute_command( afi=afi, @@ -1062,7 +855,5 @@ class Firewall_rules(ConfigBase): def _get_os_version(self): os_version = "1.2" if self._connection: - os_version = self._connection.get_device_info()[ - "network_os_version" - ] + os_version = self._connection.get_device_info()["network_os_version"] return os_version diff --git a/plugins/module_utils/network/vyos/config/hostname/hostname.py b/plugins/module_utils/network/vyos/config/hostname/hostname.py index cf2c8c2..8b30a69 100644 --- a/plugins/module_utils/network/vyos/config/hostname/hostname.py +++ b/plugins/module_utils/network/vyos/config/hostname/hostname.py @@ -20,9 +20,8 @@ created. from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.rm_base.resource_module import ( ResourceModule, ) -from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.facts import ( - Facts, -) + +from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.facts import Facts from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.rm_templates.hostname import ( HostnameTemplate, ) diff --git a/plugins/module_utils/network/vyos/config/interfaces/interfaces.py b/plugins/module_utils/network/vyos/config/interfaces/interfaces.py index 484e600..852db46 100644 --- a/plugins/module_utils/network/vyos/config/interfaces/interfaces.py +++ b/plugins/module_utils/network/vyos/config/interfaces/interfaces.py @@ -14,22 +14,22 @@ from __future__ import absolute_import, division, print_function __metaclass__ = type from copy import deepcopy + +from ansible.module_utils.six import iteritems from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.cfg.base import ( ConfigBase, ) from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.utils import ( - to_list, dict_diff, remove_empties, + to_list, ) -from ansible.module_utils.six import iteritems -from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.facts import ( - Facts, -) + +from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.facts import Facts from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.utils.utils import ( - search_obj_in_list, - get_interface_type, dict_delete, + get_interface_type, + search_obj_in_list, ) @@ -135,14 +135,9 @@ class Interfaces(ConfigBase): """ commands = [] - if ( - self.state in ("merged", "replaced", "overridden", "rendered") - and not want - ): + if self.state in ("merged", "replaced", "overridden", "rendered") and not want: self._module.fail_json( - msg="value of config parameter must not be empty for state {0}".format( - self.state - ) + msg="value of config parameter must not be empty for state {0}".format(self.state) ) if self.state == "overridden": @@ -151,9 +146,7 @@ class Interfaces(ConfigBase): elif self.state == "deleted": if not want: for intf in have: - commands.extend( - self._state_deleted({"name": intf["name"]}, intf) - ) + commands.extend(self._state_deleted({"name": intf["name"]}, intf)) else: for item in want: obj_in_have = search_obj_in_list(item["name"], have) @@ -201,9 +194,7 @@ class Interfaces(ConfigBase): for intf in have: intf_in_want = search_obj_in_list(intf["name"], want) if not intf_in_want: - commands.extend( - self._state_deleted({"name": intf["name"]}, intf) - ) + commands.extend(self._state_deleted({"name": intf["name"]}, intf)) for intf in want: intf_in_have = search_obj_in_list(intf["name"], have) @@ -235,16 +226,12 @@ class Interfaces(ConfigBase): if updates: for key, value in iteritems(updates): commands.append( - self._compute_commands( - key=key, value=value, interface=want_copy["name"] - ) + self._compute_commands(key=key, value=value, interface=want_copy["name"]) ) if want_vifs: for want_vif in want_vifs: - have_vif = search_obj_in_list( - want_vif["vlan_id"], have_vifs, key="vlan_id" - ) + have_vif = search_obj_in_list(want_vif["vlan_id"], have_vifs, key="vlan_id") if not have_vif: have_vif = { "vlan_id": want_vif["vlan_id"], @@ -283,22 +270,16 @@ class Interfaces(ConfigBase): if key == "enabled": continue commands.append( - self._compute_commands( - key=key, interface=want_copy["name"], remove=True - ) + self._compute_commands(key=key, interface=want_copy["name"], remove=True) ) if have_copy["enabled"] is False: commands.append( - self._compute_commands( - key="enabled", value=True, interface=want_copy["name"] - ) + self._compute_commands(key="enabled", value=True, interface=want_copy["name"]) ) if have_vifs: for have_vif in have_vifs: - want_vif = search_obj_in_list( - have_vif["vlan_id"], want_vifs, key="vlan_id" - ) + want_vif = search_obj_in_list(have_vif["vlan_id"], want_vifs, key="vlan_id") if not want_vif: want_vif = { "vlan_id": have_vif["vlan_id"], @@ -327,12 +308,8 @@ class Interfaces(ConfigBase): ) return commands - def _compute_commands( - self, interface, key, vif=None, value=None, remove=False - ): - intf_context = "interfaces {0} {1}".format( - get_interface_type(interface), interface - ) + def _compute_commands(self, interface, key, vif=None, value=None, remove=False): + intf_context = "interfaces {0} {1}".format(get_interface_type(interface), interface) set_cmd = "set {0}".format(intf_context) del_cmd = "delete {0}".format(intf_context) diff --git a/plugins/module_utils/network/vyos/config/l3_interfaces/l3_interfaces.py b/plugins/module_utils/network/vyos/config/l3_interfaces/l3_interfaces.py index 6f143be..61dd1f4 100644 --- a/plugins/module_utils/network/vyos/config/l3_interfaces/l3_interfaces.py +++ b/plugins/module_utils/network/vyos/config/l3_interfaces/l3_interfaces.py @@ -17,21 +17,21 @@ __metaclass__ = type from copy import deepcopy + +from ansible.module_utils.six import iteritems from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.cfg.base import ( ConfigBase, ) from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.utils import ( - to_list, remove_empties, + to_list, ) -from ansible.module_utils.six import iteritems -from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.facts import ( - Facts, -) + +from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.facts import Facts from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.utils.utils import ( - search_obj_in_list, - get_interface_type, diff_list_of_dicts, + get_interface_type, + search_obj_in_list, ) @@ -61,9 +61,7 @@ class L3_interfaces(ConfigBase): facts, _warnings = Facts(self._module).get_facts( self.gather_subset, self.gather_network_resources, data=data ) - l3_interfaces_facts = facts["ansible_network_resources"].get( - "l3_interfaces" - ) + l3_interfaces_facts = facts["ansible_network_resources"].get("l3_interfaces") if not l3_interfaces_facts: return [] return l3_interfaces_facts @@ -104,9 +102,7 @@ class L3_interfaces(ConfigBase): self._module.fail_json( msg="value of running_config parameter must not be empty for state parsed" ) - result["parsed"] = self.get_l3_interfaces_facts( - data=running_config - ) + result["parsed"] = self.get_l3_interfaces_facts(data=running_config) else: changed_l3_interfaces_facts = [] @@ -145,14 +141,9 @@ class L3_interfaces(ConfigBase): commands = [] state = self._module.params["state"] - if ( - state in ("merged", "replaced", "overridden", "rendered") - and not want - ): + if state in ("merged", "replaced", "overridden", "rendered") and not want: self._module.fail_json( - msg="value of config parameter must not be empty for state {0}".format( - state - ) + msg="value of config parameter must not be empty for state {0}".format(state) ) if state == "overridden": @@ -161,9 +152,7 @@ class L3_interfaces(ConfigBase): elif state == "deleted": if not want: for intf in have: - commands.extend( - self._state_deleted({"name": intf["name"]}, intf) - ) + commands.extend(self._state_deleted({"name": intf["name"]}, intf)) else: for item in want: obj_in_have = search_obj_in_list(item["name"], have) @@ -211,9 +200,7 @@ class L3_interfaces(ConfigBase): for intf in have: intf_in_want = search_obj_in_list(intf["name"], want) if not intf_in_want: - commands.extend( - self._state_deleted({"name": intf["name"]}, intf) - ) + commands.extend(self._state_deleted({"name": intf["name"]}, intf)) for intf in want: intf_in_have = search_obj_in_list(intf["name"], have) @@ -238,16 +225,12 @@ class L3_interfaces(ConfigBase): for update in self._get_updates(want_copy, have_copy): for key, value in iteritems(update): commands.append( - self._compute_commands( - key=key, value=value, interface=want_copy["name"] - ) + self._compute_commands(key=key, value=value, interface=want_copy["name"]) ) if want_vifs: for want_vif in want_vifs: - have_vif = search_obj_in_list( - want_vif["vlan_id"], have_vifs, key="vlan_id" - ) + have_vif = search_obj_in_list(want_vif["vlan_id"], have_vifs, key="vlan_id") if not have_vif: have_vif = {} @@ -291,9 +274,7 @@ class L3_interfaces(ConfigBase): if have_vifs: for have_vif in have_vifs: - want_vif = search_obj_in_list( - have_vif["vlan_id"], want_vifs, key="vlan_id" - ) + want_vif = search_obj_in_list(have_vif["vlan_id"], want_vifs, key="vlan_id") if not want_vif: want_vif = {"vlan_id": have_vif["vlan_id"]} @@ -311,12 +292,8 @@ class L3_interfaces(ConfigBase): return commands - def _compute_commands( - self, interface, key, vif=None, value=None, remove=False - ): - intf_context = "interfaces {0} {1}".format( - get_interface_type(interface), interface - ) + def _compute_commands(self, interface, key, vif=None, value=None, remove=False): + intf_context = "interfaces {0} {1}".format(get_interface_type(interface), interface) set_cmd = "set {0}".format(intf_context) del_cmd = "delete {0}".format(intf_context) @@ -334,11 +311,7 @@ class L3_interfaces(ConfigBase): def _get_updates(self, want, have): updates = [] - updates = diff_list_of_dicts( - want.get("ipv4", []), have.get("ipv4", []) - ) - updates.extend( - diff_list_of_dicts(want.get("ipv6", []), have.get("ipv6", [])) - ) + updates = diff_list_of_dicts(want.get("ipv4", []), have.get("ipv4", [])) + updates.extend(diff_list_of_dicts(want.get("ipv6", []), have.get("ipv6", []))) return updates diff --git a/plugins/module_utils/network/vyos/config/lag_interfaces/lag_interfaces.py b/plugins/module_utils/network/vyos/config/lag_interfaces/lag_interfaces.py index 7e7b39a..314ff93 100644 --- a/plugins/module_utils/network/vyos/config/lag_interfaces/lag_interfaces.py +++ b/plugins/module_utils/network/vyos/config/lag_interfaces/lag_interfaces.py @@ -11,22 +11,21 @@ created from __future__ import absolute_import, division, print_function __metaclass__ = type +from ansible.module_utils.six import iteritems from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.cfg.base import ( ConfigBase, ) -from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.facts import ( - Facts, -) from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.utils import ( - to_list, dict_diff, + to_list, ) -from ansible.module_utils.six import iteritems + +from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.facts import Facts from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.utils.utils import ( - search_obj_in_list, get_lst_diff_for_dicts, - list_diff_want_only, list_diff_have_only, + list_diff_want_only, + search_obj_in_list, ) @@ -65,9 +64,7 @@ class Lag_interfaces(ConfigBase): facts, _warnings = Facts(self._module).get_facts( self.gather_subset, self.gather_network_resources, data=data ) - lag_interfaces_facts = facts["ansible_network_resources"].get( - "lag_interfaces" - ) + lag_interfaces_facts = facts["ansible_network_resources"].get("lag_interfaces") if not lag_interfaces_facts: return [] return lag_interfaces_facts @@ -108,9 +105,7 @@ class Lag_interfaces(ConfigBase): self._module.fail_json( msg="value of running_config parameter must not be empty for state parsed" ) - result["parsed"] = self.get_lag_interfaces_facts( - data=running_config - ) + result["parsed"] = self.get_lag_interfaces_facts(data=running_config) else: changed_lag_interfaces_facts = [] @@ -147,14 +142,9 @@ class Lag_interfaces(ConfigBase): to the desired configuration """ commands = [] - if ( - self.state in ("merged", "replaced", "overridden", "rendered") - and not want - ): + if self.state in ("merged", "replaced", "overridden", "rendered") and not want: self._module.fail_json( - msg="value of config parameter must not be empty for state {0}".format( - self.state - ) + msg="value of config parameter must not be empty for state {0}".format(self.state) ) if self.state == "overridden": commands.extend(self._state_overridden(want, have)) @@ -174,9 +164,7 @@ class Lag_interfaces(ConfigBase): if self.state in ("merged", "rendered"): commands.extend(self._state_merged(want_item, obj_in_have)) elif self.state == "replaced": - commands.extend( - self._state_replaced(want_item, obj_in_have) - ) + commands.extend(self._state_replaced(want_item, obj_in_have)) return commands def _state_replaced(self, want, have): @@ -257,15 +245,9 @@ class Lag_interfaces(ConfigBase): for key, value in iteritems(updates): if value: if key == "arp_monitor": - commands.extend( - self._add_arp_monitor(updates, key, want, have) - ) + commands.extend(self._add_arp_monitor(updates, key, want, have)) else: - commands.append( - self._compute_command( - have["name"], key, str(value) - ) - ) + commands.append(self._compute_command(have["name"], key, str(value))) return commands def _render_set_commands(self, want): @@ -278,17 +260,11 @@ class Lag_interfaces(ConfigBase): value = want[attrib] if value: if attrib == "arp_monitor": - commands.extend( - self._add_arp_monitor(want, attrib, want, have) - ) + commands.extend(self._add_arp_monitor(want, attrib, want, have)) elif attrib == "members": commands.extend(self._add_bond_members(want, have)) elif attrib != "name": - commands.append( - self._compute_command( - want["name"], attrib, value=str(value) - ) - ) + commands.append(self._compute_command(want["name"], attrib, value=str(value))) return commands def _purge_attribs(self, have): @@ -298,11 +274,7 @@ class Lag_interfaces(ConfigBase): if item == "members": commands.extend(self._delete_bond_members(have)) elif item != "name": - commands.append( - self._compute_command( - have["name"], attrib=item, remove=True - ) - ) + commands.append(self._compute_command(have["name"], attrib=item, remove=True)) return commands def _render_del_commands(self, want, have): @@ -315,9 +287,7 @@ class Lag_interfaces(ConfigBase): elif attrib == "arp_monitor": commands.extend(self._update_arp_monitor(attrib, want, have)) elif have.get(attrib) and not want.get(attrib): - commands.append( - self._compute_command(have["name"], attrib, remove=True) - ) + commands.append(self._compute_command(have["name"], attrib, remove=True)) return commands def _add_bond_members(self, want, have): @@ -338,9 +308,7 @@ class Lag_interfaces(ConfigBase): def _add_arp_monitor(self, updates, key, want, have): commands = [] arp_monitor = updates.get(key) or {} - diff_targets = self._get_arp_monitor_target_diff( - want, have, key, "target" - ) + diff_targets = self._get_arp_monitor_target_diff(want, have, key, "target") if "interval" in arp_monitor: commands.append( @@ -430,9 +398,7 @@ class Lag_interfaces(ConfigBase): ) return commands - def _get_arp_monitor_target_diff( - self, want_list, have_list, dict_name, lst - ): + def _get_arp_monitor_target_diff(self, want_list, have_list, dict_name, lst): want_arp_target = [] have_arp_target = [] @@ -450,9 +416,7 @@ class Lag_interfaces(ConfigBase): diff = list_diff_want_only(want_arp_target, have_arp_target) return diff - def _compute_command( - self, key, attrib, value=None, remove=False, type="bonding" - ): + def _compute_command(self, key, attrib, value=None, remove=False, type="bonding"): if remove: cmd = "delete interfaces " + type else: diff --git a/plugins/module_utils/network/vyos/config/lldp_global/lldp_global.py b/plugins/module_utils/network/vyos/config/lldp_global/lldp_global.py index d66e9c6..b2571e0 100644 --- a/plugins/module_utils/network/vyos/config/lldp_global/lldp_global.py +++ b/plugins/module_utils/network/vyos/config/lldp_global/lldp_global.py @@ -11,17 +11,16 @@ created from __future__ import absolute_import, division, print_function __metaclass__ = type +from ansible.module_utils.six import iteritems from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.cfg.base import ( ConfigBase, ) from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.utils import ( - to_list, dict_diff, + to_list, ) -from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.facts import ( - Facts, -) -from ansible.module_utils.six import iteritems + +from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.facts import Facts from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.utils.utils import ( get_lst_diff_for_dicts, list_diff_have_only, @@ -56,9 +55,7 @@ class Lldp_global(ConfigBase): facts, _warnings = Facts(self._module).get_facts( self.gather_subset, self.gather_network_resources, data=data ) - lldp_global_facts = facts["ansible_network_resources"].get( - "lldp_global" - ) + lldp_global_facts = facts["ansible_network_resources"].get("lldp_global") if not lldp_global_facts: return [] return lldp_global_facts @@ -138,9 +135,7 @@ class Lldp_global(ConfigBase): commands = [] if self.state in ("merged", "replaced", "rendered") and not want: self._module.fail_json( - msg="value of config parameter must not be empty for state {0}".format( - self.state - ) + msg="value of config parameter must not be empty for state {0}".format(self.state) ) if self.state == "deleted": commands.extend(self._state_deleted(want=None, have=have)) @@ -186,29 +181,17 @@ class Lldp_global(ConfigBase): for item in Lldp_global.params: if item == "legacy_protocols": commands.extend(self._update_lldp_protocols(want, have)) - elif ( - have.get(item) and not want.get(item) and item != "enable" - ): + elif have.get(item) and not want.get(item) and item != "enable": commands.append(Lldp_global.del_cmd + item) elif have: for item in Lldp_global.params: if have.get(item): if item == "legacy_protocols": - commands.append( - self._compute_command( - "legacy-protocols", remove=True - ) - ) + commands.append(self._compute_command("legacy-protocols", remove=True)) elif item == "address": - commands.append( - self._compute_command( - "management-address", remove=True - ) - ) + commands.append(self._compute_command("management-address", remove=True)) elif item == "snmp": - commands.append( - self._compute_command(item, remove=True) - ) + commands.append(self._compute_command(item, remove=True)) return commands @@ -235,20 +218,12 @@ class Lldp_global(ConfigBase): if key == "enable": commands.append(self._compute_command()) elif key == "address": - commands.append( - self._compute_command( - "management-address", str(value) - ) - ) + commands.append(self._compute_command("management-address", str(value))) elif key == "snmp": if value == "disable": - commands.append( - self._compute_command(key, remove=True) - ) + commands.append(self._compute_command(key, remove=True)) else: - commands.append( - self._compute_command(key, str(value)) - ) + commands.append(self._compute_command(key, str(value))) return commands def _add_lldp_protocols(self, want, have): @@ -266,11 +241,7 @@ class Lldp_global(ConfigBase): members_diff = list_diff_have_only(want_protocols, have_protocols) if members_diff: for member in members_diff: - commands.append( - self._compute_command( - "legacy-protocols", member, remove=True - ) - ) + commands.append(self._compute_command("legacy-protocols", member, remove=True)) return commands def _compute_command(self, key=None, value=None, remove=False): diff --git a/plugins/module_utils/network/vyos/config/lldp_interfaces/lldp_interfaces.py b/plugins/module_utils/network/vyos/config/lldp_interfaces/lldp_interfaces.py index f1f299f..11b950b 100644 --- a/plugins/module_utils/network/vyos/config/lldp_interfaces/lldp_interfaces.py +++ b/plugins/module_utils/network/vyos/config/lldp_interfaces/lldp_interfaces.py @@ -15,22 +15,21 @@ from __future__ import absolute_import, division, print_function __metaclass__ = type +from ansible.module_utils.six import iteritems from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.cfg.base import ( ConfigBase, ) -from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.facts import ( - Facts, -) from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.utils import ( - to_list, dict_diff, + to_list, ) -from ansible.module_utils.six import iteritems + +from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.facts import Facts from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.utils.utils import ( - search_obj_in_list, - search_dict_tv_in_list, - key_value_in_dict, is_dict_element_present, + key_value_in_dict, + search_dict_tv_in_list, + search_obj_in_list, ) @@ -62,9 +61,7 @@ class Lldp_interfaces(ConfigBase): facts, _warnings = Facts(self._module).get_facts( self.gather_subset, self.gather_network_resources, data=data ) - lldp_interfaces_facts = facts["ansible_network_resources"].get( - "lldp_interfaces" - ) + lldp_interfaces_facts = facts["ansible_network_resources"].get("lldp_interfaces") if not lldp_interfaces_facts: return [] return lldp_interfaces_facts @@ -105,9 +102,7 @@ class Lldp_interfaces(ConfigBase): self._module.fail_json( msg="value of running_config parameter must not be empty for state parsed" ) - result["parsed"] = self.get_lldp_interfaces_facts( - data=running_config - ) + result["parsed"] = self.get_lldp_interfaces_facts(data=running_config) else: changed_lldp_interfaces_facts = [] @@ -144,14 +139,9 @@ class Lldp_interfaces(ConfigBase): to the desired configuration """ commands = [] - if ( - self.state in ("merged", "replaced", "overridden", "rendered") - and not want - ): + if self.state in ("merged", "replaced", "overridden", "rendered") and not want: self._module.fail_json( - msg="value of config parameter must not be empty for state {0}".format( - self.state - ) + msg="value of config parameter must not be empty for state {0}".format(self.state) ) if self.state == "overridden": commands.extend(self._state_overridden(want=want, have=have)) @@ -160,26 +150,18 @@ class Lldp_interfaces(ConfigBase): for item in want: name = item["name"] have_item = search_obj_in_list(name, have) - commands.extend( - self._state_deleted(want=None, have=have_item) - ) + commands.extend(self._state_deleted(want=None, have=have_item)) else: for have_item in have: - commands.extend( - self._state_deleted(want=None, have=have_item) - ) + commands.extend(self._state_deleted(want=None, have=have_item)) else: for want_item in want: name = want_item["name"] have_item = search_obj_in_list(name, have) if self.state in ("merged", "rendered"): - commands.extend( - self._state_merged(want=want_item, have=have_item) - ) + commands.extend(self._state_merged(want=want_item, have=have_item)) if self.state == "replaced": - commands.extend( - self._state_replaced(want=want_item, have=have_item) - ) + commands.extend(self._state_replaced(want=want_item, have=have_item)) return commands def _state_replaced(self, want, have): @@ -207,9 +189,7 @@ class Lldp_interfaces(ConfigBase): lldp_name = have_item["name"] lldp_in_want = search_obj_in_list(lldp_name, want) if not lldp_in_want: - commands.append( - self._compute_command(have_item["name"], remove=True) - ) + commands.append(self._compute_command(have_item["name"], remove=True)) for want_item in want: name = want_item["name"] @@ -243,9 +223,7 @@ class Lldp_interfaces(ConfigBase): params = Lldp_interfaces.params for attrib in params: if attrib == "location": - commands.extend( - self._update_location(have["name"], want, have) - ) + commands.extend(self._update_location(have["name"], want, have)) elif have: commands.append(self._compute_command(have["name"], remove=True)) @@ -272,9 +250,7 @@ class Lldp_interfaces(ConfigBase): commands.extend(self._add_location(lldp_name, want, have)) elif attrib == "enable": if not value: - commands.append( - self._compute_command(lldp_name, value="disable") - ) + commands.append(self._compute_command(lldp_name, value="disable")) else: commands.append(self._compute_command(lldp_name)) @@ -288,9 +264,7 @@ class Lldp_interfaces(ConfigBase): temp_have_item = True if want_item["enable"] != temp_have_item: if want_item["enable"]: - commands.append( - self._compute_command(name, value="disable", remove=True) - ) + commands.append(self._compute_command(name, value="disable", remove=True)) else: commands.append(self._compute_command(name, value="disable")) return commands @@ -311,11 +285,7 @@ class Lldp_interfaces(ConfigBase): updates = dict_diff(have_dict, want_dict) for key, value in iteritems(updates): if value: - commands.append( - self._compute_command( - set_cmd + location_type, key, str(value) - ) - ) + commands.append(self._compute_command(set_cmd + location_type, key, str(value))) elif want_location_type["civic_based"]: location_type = "civic-based" @@ -345,9 +315,7 @@ class Lldp_interfaces(ConfigBase): elif want_location_type["elin"]: location_type = "elin" if is_dict_element_present(have_location_type, "elin"): - if want_location_type.get("elin") != have_location_type.get( - "elin" - ): + if want_location_type.get("elin") != have_location_type.get("elin"): commands.append( self._compute_command( set_cmd + location_type, @@ -378,9 +346,7 @@ class Lldp_interfaces(ConfigBase): only_in_have = key_value_in_dict(key, value, want_dict) if not only_in_have: commands.append( - self._compute_command( - del_cmd + location_type, key, str(value), True - ) + self._compute_command(del_cmd + location_type, key, str(value), True) ) else: commands.append(self._compute_command(del_cmd, remove=True)) @@ -391,20 +357,14 @@ class Lldp_interfaces(ConfigBase): if is_dict_element_present(have_location_type, "civic_based"): have_dict = have_location_type.get("civic_based") or {} have_ca = have_dict.get("ca_info") - commands.extend( - self._update_civic_address(name, want_ca, have_ca) - ) + commands.extend(self._update_civic_address(name, want_ca, have_ca)) else: commands.append(self._compute_command(del_cmd, remove=True)) else: if is_dict_element_present(have_location_type, "elin"): - if want_location_type.get("elin") != have_location_type.get( - "elin" - ): - commands.append( - self._compute_command(del_cmd, remove=True) - ) + if want_location_type.get("elin") != have_location_type.get("elin"): + commands.append(self._compute_command(del_cmd, remove=True)) else: commands.append(self._compute_command(del_cmd, remove=True)) return commands @@ -414,9 +374,7 @@ class Lldp_interfaces(ConfigBase): for item in want: ca_type = item["ca_type"] ca_value = item["ca_value"] - obj_in_have = search_dict_tv_in_list( - ca_type, ca_value, have, "ca_type", "ca_value" - ) + obj_in_have = search_dict_tv_in_list(ca_type, ca_value, have, "ca_type", "ca_value") if not obj_in_have: commands.append( self._compute_command( @@ -432,9 +390,7 @@ class Lldp_interfaces(ConfigBase): for item in have: ca_type = item["ca_type"] ca_value = item["ca_value"] - in_want = search_dict_tv_in_list( - ca_type, ca_value, want, "ca_type", "ca_value" - ) + in_want = search_dict_tv_in_list(ca_type, ca_value, want, "ca_type", "ca_value") if not in_want: commands.append( self._compute_command( diff --git a/plugins/module_utils/network/vyos/config/logging_global/logging_global.py b/plugins/module_utils/network/vyos/config/logging_global/logging_global.py index 696090d..27c33b3 100644 --- a/plugins/module_utils/network/vyos/config/logging_global/logging_global.py +++ b/plugins/module_utils/network/vyos/config/logging_global/logging_global.py @@ -20,16 +20,15 @@ created. from copy import deepcopy from ansible.module_utils.six import iteritems -from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.utils import ( - dict_merge, - get_from_dict, -) from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.rm_base.resource_module import ( ResourceModule, ) -from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.facts import ( - Facts, +from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.utils import ( + dict_merge, + get_from_dict, ) + +from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.facts import Facts from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.rm_templates.logging_global import ( Logging_globalTemplate, ) @@ -173,9 +172,7 @@ class Logging_global(ResourceModule): temp_param[pk + k] = { element: { "facilities": dat, - self.pkey.get(element): v.get( - self.pkey.get(element) - ), + self.pkey.get(element): v.get(self.pkey.get(element)), } } del v["facilities"] @@ -202,19 +199,9 @@ class Logging_global(ResourceModule): _tem_par = {} for par in val: if par.get("facility") and par.get("severity"): - _tem_par.update( - { - par.get("facility") - + par.get("severity"): par - } - ) + _tem_par.update({par.get("facility") + par.get("severity"): par}) elif par.get("facility") and par.get("protocol"): - _tem_par.update( - { - par.get("facility") - + par.get("protocol"): par - } - ) + _tem_par.update({par.get("facility") + par.get("protocol"): par}) else: _tem_par.update({par.get("facility"): par}) return _tem_par @@ -227,11 +214,7 @@ class Logging_global(ResourceModule): if v.get("facilities"): v["facilities"] = self.list_to_dict(v) if updated_param.get(element): - updated_param[element].update( - {v.get(self.pkey.get(element)): v} - ) + updated_param[element].update({v.get(self.pkey.get(element)): v}) else: - updated_param[element] = { - v.get(self.pkey.get(element)): v - } + updated_param[element] = {v.get(self.pkey.get(element)): v} return updated_param diff --git a/plugins/module_utils/network/vyos/config/ntp_global/ntp_global.py b/plugins/module_utils/network/vyos/config/ntp_global/ntp_global.py index 0a0e389..cd677d4 100644 --- a/plugins/module_utils/network/vyos/config/ntp_global/ntp_global.py +++ b/plugins/module_utils/network/vyos/config/ntp_global/ntp_global.py @@ -18,15 +18,14 @@ created. """ from ansible.module_utils.six import iteritems -from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.utils import ( - dict_merge, -) from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.rm_base.resource_module import ( ResourceModule, ) -from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.facts import ( - Facts, +from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.utils import ( + dict_merge, ) + +from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.facts import Facts from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.rm_templates.ntp_global import ( NtpTemplate, ) @@ -79,9 +78,7 @@ class Ntp_global(ResourceModule): # if state is deleted, empty out wantd and set haved to wantd if self.state == "deleted": - haved = { - k: v for k, v in iteritems(haved) if k in wantd or not wantd - } + haved = {k: v for k, v in iteritems(haved) if k in wantd or not wantd} wantd = {} commandlist = self._commandlist(haved) @@ -92,16 +89,12 @@ class Ntp_global(ResourceModule): for hk, hval in iteritems(have): if hk == "allow_clients" and hk in commandlist: self.commands.append( - self._tmplt.render( - {"": hk}, "allow_clients_delete", True - ) + self._tmplt.render({"": hk}, "allow_clients_delete", True) ) commandlist.remove(hk) elif hk == "listen_addresses" and hk in commandlist: self.commands.append( - self._tmplt.render( - {"": hk}, "listen_addresses_delete", True - ) + self._tmplt.render({"": hk}, "listen_addresses_delete", True) ) commandlist.remove(hk) elif hk == "server" and have["server"] in servernames: @@ -170,9 +163,7 @@ class Ntp_global(ResourceModule): dict = {} dict.update({"server": entry["server"]}) dict.update({Opk: val}) - serveroptions_dict.update( - {entry["server"] + "_" + val: dict} - ) + serveroptions_dict.update({entry["server"] + "_" + val: dict}) return serveroptions_dict def _commandlist(self, haved): diff --git a/plugins/module_utils/network/vyos/config/ospf_interfaces/ospf_interfaces.py b/plugins/module_utils/network/vyos/config/ospf_interfaces/ospf_interfaces.py index dbdce48..527f062 100644 --- a/plugins/module_utils/network/vyos/config/ospf_interfaces/ospf_interfaces.py +++ b/plugins/module_utils/network/vyos/config/ospf_interfaces/ospf_interfaces.py @@ -17,15 +17,14 @@ created. """ from ansible.module_utils.six import iteritems -from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.utils import ( - dict_merge, -) from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.rm_base.resource_module import ( ResourceModule, ) -from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.facts import ( - Facts, +from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.utils import ( + dict_merge, ) + +from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.facts import Facts from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.rm_templates.ospf_interfaces import ( Ospf_interfacesTemplate, ) diff --git a/plugins/module_utils/network/vyos/config/ospfv2/ospfv2.py b/plugins/module_utils/network/vyos/config/ospfv2/ospfv2.py index 059b92d..9287fbc 100644 --- a/plugins/module_utils/network/vyos/config/ospfv2/ospfv2.py +++ b/plugins/module_utils/network/vyos/config/ospfv2/ospfv2.py @@ -15,23 +15,22 @@ from __future__ import absolute_import, division, print_function __metaclass__ = type from copy import deepcopy + +from ansible.module_utils.six import iteritems from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.cfg.base import ( ConfigBase, ) from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.utils import ( - to_list, remove_empties, + to_list, ) -from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.facts import ( - Facts, -) -from ansible.module_utils.six import iteritems +from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.facts import Facts from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.utils.utils import ( - list_diff_want_only, + _bool_to_str, _in_target, _is_w_same, - _bool_to_str, + list_diff_want_only, ) @@ -137,14 +136,9 @@ class Ospfv2(ConfigBase): """ commands = [] - if ( - self.state in ("merged", "replaced", "overridden", "rendered") - and not w - ): + if self.state in ("merged", "replaced", "overridden", "rendered") and not w: self._module.fail_json( - msg="value of config parameter must not be empty for state {0}".format( - self.state - ) + msg="value of config parameter must not be empty for state {0}".format(self.state) ) if self.state == "deleted": @@ -226,21 +220,11 @@ class Ospfv2(ConfigBase): if w: for (key, val) in iteritems(w): if opr and key in leaf and not _is_w_same(w, have, key): - commands.append( - self._form_attr_cmd( - attr=key, val=_bool_to_str(val), opr=opr - ) - ) + commands.append(self._form_attr_cmd(attr=key, val=_bool_to_str(val), opr=opr)) elif not opr and key in leaf and not _in_target(have, key): - commands.append( - self._form_attr_cmd( - attr=key, val=_bool_to_str(val), opr=opr - ) - ) + commands.append(self._form_attr_cmd(attr=key, val=_bool_to_str(val), opr=opr)) else: - commands.extend( - self._render_child_param(w, have, key, opr) - ) + commands.extend(self._render_child_param(w, have, key, opr)) return commands def _render_child_param(self, w, h, key, opr=True): @@ -304,11 +288,7 @@ class Ospfv2(ConfigBase): } leaf = leaf_dict[attr] for (item, value) in iteritems(want[attr]): - if ( - opr - and item in leaf - and not _is_w_same(want[attr], h, item) - ): + if opr and item in leaf and not _is_w_same(want[attr], h, item): if item == "enabled": item = "enable" if item in ( @@ -316,26 +296,16 @@ class Ospfv2(ConfigBase): "enable", "rfc1583_compatibility", ): - commands.append( - self._form_attr_cmd(key=attr, attr=item, opr=opr) - ) + commands.append(self._form_attr_cmd(key=attr, attr=item, opr=opr)) else: commands.append( - self._form_attr_cmd( - key=attr, attr=item, val=value, opr=opr - ) + self._form_attr_cmd(key=attr, attr=item, val=value, opr=opr) ) elif not opr and item in leaf and not _in_target(h, item): if item == "enabled": - commands.append( - self._form_attr_cmd( - key=attr, attr="enable", opr=opr - ) - ) + commands.append(self._form_attr_cmd(key=attr, attr="enable", opr=opr)) else: - commands.append( - self._form_attr_cmd(key=attr, attr=item, opr=opr) - ) + commands.append(self._form_attr_cmd(key=attr, attr=item, opr=opr)) return commands def _render_list_param(self, attr, want, have, cmd=None, opr=True): @@ -371,19 +341,12 @@ class Ospfv2(ConfigBase): if h: for member in w: if attr == "network": - if not self.search_obj_in_have( - h, member, "address" - ): + if not self.search_obj_in_have(h, member, "address"): commands.append( - cmd - + attr.replace("_", "-") - + " " - + member["address"] + cmd + attr.replace("_", "-") + " " + member["address"] ) elif member not in h: - commands.append( - cmd + attr.replace("_", "-") + " " + member - ) + commands.append(cmd + attr.replace("_", "-") + " " + member) else: commands.append(cmd + " " + attr.replace("_", "-")) return commands @@ -424,15 +387,9 @@ class Ospfv2(ConfigBase): if not cmd: cmd = self._compute_command(opr=opr) h_item = self.search_obj_in_have(h, w_item, name[attr]) - if ( - opr - and key in leaf - and not _is_w_same(w_item, h_item, key) - ): + if opr and key in leaf and not _is_w_same(w_item, h_item, key): if key in "address": - commands.append( - cmd + attr.replace("_", "-") + " " + str(val) - ) + commands.append(cmd + attr.replace("_", "-") + " " + str(val)) else: commands.append( cmd @@ -444,21 +401,12 @@ class Ospfv2(ConfigBase): + " " + str(val) ) - elif ( - not opr and key in leaf and not _in_target(h_item, key) - ): + elif not opr and key in leaf and not _in_target(h_item, key): if key in "address": - commands.append( - cmd + attr.replace("_", "-") + " " + str(val) - ) + commands.append(cmd + attr.replace("_", "-") + " " + str(val)) else: commands.append( - cmd - + attr.replace("_", "-") - + " " - + w_item[name[attr]] - + " " - + key + cmd + attr.replace("_", "-") + " " + w_item[name[attr]] + " " + key ) elif key == "authentication": commands.extend( @@ -474,9 +422,7 @@ class Ospfv2(ConfigBase): ) return commands - def _render_vlink_auth( - self, attr, key, want, have, address, cmd=None, opr=True - ): + def _render_vlink_auth(self, attr, key, want, have, address, cmd=None, opr=True): """ This function forms the set/delete commands based on the 'opr' type for attributes with in desired list of dictionary. @@ -549,11 +495,7 @@ class Ospfv2(ConfigBase): if not cmd: cmd = self._compute_command(opr=opr) h_item = self.search_obj_in_have(h, w_item, name[attr]) - if ( - opr - and key in leaf - and not _is_w_same(w_item, h_item, key) - ): + if opr and key in leaf and not _is_w_same(w_item, h_item, key): if key in ( "route_type", "neighbor_id", @@ -563,23 +505,11 @@ class Ospfv2(ConfigBase): commands.append(cmd + attr + " " + str(val)) elif key == "cost": commands.append( - cmd - + attr - + " " - + w_item[name[attr]] - + " " - + key - + " " - + str(val) + cmd + attr + " " + w_item[name[attr]] + " " + key + " " + str(val) ) elif key == "not_advertise": commands.append( - cmd - + attr - + " " - + w_item[name[attr]] - + " " - + key.replace("_", "-") + cmd + attr + " " + w_item[name[attr]] + " " + key.replace("_", "-") ) elif key == "md5_key": commands.append( @@ -605,9 +535,7 @@ class Ospfv2(ConfigBase): + " " + str(val) ) - elif ( - not opr and key in leaf and not _in_target(h_item, key) - ): + elif not opr and key in leaf and not _in_target(h_item, key): if key in ( "route_type", "neighbor_id", @@ -616,14 +544,7 @@ class Ospfv2(ConfigBase): ): commands.append(cmd + attr + " " + str(val)) else: - commands.append( - cmd - + attr - + " " - + w_item[name[attr]] - + " " - + key - ) + commands.append(cmd + attr + " " + w_item[name[attr]] + " " + key) return commands def _render_nested_dict_param(self, attr, want, have, opr=True): @@ -668,11 +589,7 @@ class Ospfv2(ConfigBase): if h and key in h.keys(): h_attrib = h.get(key) or {} for (item, val) in iteritems(w[key]): - if ( - opr - and item in leaf - and not _is_w_same(w[key], h_attrib, item) - ): + if opr and item in leaf and not _is_w_same(w[key], h_attrib, item): if item in ("administrative", "always") and val: commands.append( cmd @@ -693,11 +610,7 @@ class Ospfv2(ConfigBase): + " " + str(val) ) - elif ( - not opr - and item in leaf - and not _in_target(h_attrib, item) - ): + elif not opr and item in leaf and not _in_target(h_attrib, item): commands.append(cmd + attr + " " + item) return commands @@ -734,17 +647,11 @@ class Ospfv2(ConfigBase): h_area = self.search_obj_in_have(h_lst, w_area, "area_id") if not opr and not h_area: commands.append( - self._form_attr_cmd( - key="area", attr=w_area["area_id"], opr=opr - ) + self._form_attr_cmd(key="area", attr=w_area["area_id"], opr=opr) ) else: for (key, val) in iteritems(w_area): - if ( - opr - and key in l_set - and not _is_w_same(w_area, h_area, key) - ): + if opr and key in l_set and not _is_w_same(w_area, h_area, key): if key == "area_id": commands.append( self._form_attr_cmd( @@ -755,45 +662,24 @@ class Ospfv2(ConfigBase): ) else: commands.append( - cmd - + key - + " " - + _bool_to_str(val).replace("_", "-") + cmd + key + " " + _bool_to_str(val).replace("_", "-") ) elif not opr and key in l_set: - if key == "area_id" and not _in_target( - h_area, key - ): + if key == "area_id" and not _in_target(h_area, key): commands.append(cmd) continue - if key != "area_id" and not _in_target( - h_area, key - ): + if key != "area_id" and not _in_target(h_area, key): commands.append(cmd + val + " " + key) elif key == "area_type": - commands.extend( - self._render_area_type( - w_area, h_area, key, cmd, opr - ) - ) + commands.extend(self._render_area_type(w_area, h_area, key, cmd, opr)) elif key == "network": - commands.extend( - self._render_list_param( - key, w_area, h_area, cmd, opr - ) - ) + commands.extend(self._render_list_param(key, w_area, h_area, cmd, opr)) elif key == "range": commands.extend( - self._render_list_dict_param( - key, w_area, h_area, cmd, opr - ) + self._render_list_dict_param(key, w_area, h_area, cmd, opr) ) elif key == "virtual_link": - commands.extend( - self._render_vlink( - key, w_area, h_area, cmd, opr - ) - ) + commands.extend(self._render_vlink(key, w_area, h_area, cmd, opr)) return commands def _render_area_type(self, want, have, attr, cmd, opr=True): @@ -817,28 +703,15 @@ class Ospfv2(ConfigBase): commands.append(cmd + attr.replace("_", "-")) elif w_type: key = "normal" - if ( - opr - and key in w_type.keys() - and not _is_w_same(w_type, h_type, key) - ): + if opr and key in w_type.keys() and not _is_w_same(w_type, h_type, key): if not w_type[key] and h_type and h_type[key]: commands.append( - cmd.replace("set", "delete") - + attr.replace("_", "-") - + " " - + key + cmd.replace("set", "delete") + attr.replace("_", "-") + " " + key ) elif w_type[key]: commands.append(cmd + attr.replace("_", "-") + " " + key) - elif ( - not opr - and key in w_type.keys() - and not (h_type and key in h_type.keys()) - ): - commands.append( - cmd + want["area"] + " " + attr.replace("_", "-") - ) + elif not opr and key in w_type.keys() and not (h_type and key in h_type.keys()): + commands.append(cmd + want["area"] + " " + attr.replace("_", "-")) a_type = { "nssa": ("set", "default_cost", "no_summary", "translate"), @@ -857,9 +730,7 @@ class Ospfv2(ConfigBase): and not _is_w_same(w_type[key], h_area, item) ): if item == "set" and val: - commands.append( - cmd + attr.replace("_", "-") + " " + key - ) + commands.append(cmd + attr.replace("_", "-") + " " + key) elif not val and h_area and h_area[item]: commands.append( cmd.replace("set", "delete") @@ -878,15 +749,9 @@ class Ospfv2(ConfigBase): + " " + str(val) ) - elif ( - not opr - and item in a_type[key] - and not (h_type and key in h_type) - ): + elif not opr and item in a_type[key] and not (h_type and key in h_type): if item == "set": - commands.append( - cmd + attr.replace("_", "-") + " " + key - ) + commands.append(cmd + attr.replace("_", "-") + " " + key) else: commands.append( cmd @@ -910,13 +775,9 @@ class Ospfv2(ConfigBase): :return: generated command. """ - return self._compute_command( - key, attr=self._map_attrib(attr), val=val, opr=opr - ) + return self._compute_command(key, attr=self._map_attrib(attr), val=val, opr=opr) - def _compute_command( - self, key=None, attr=None, val=None, remove=False, opr=True - ): + def _compute_command(self, key=None, attr=None, val=None, remove=False, opr=True): """ This function construct the add/delete command based on passed attributes. :param key: parent key. diff --git a/plugins/module_utils/network/vyos/config/ospfv3/ospfv3.py b/plugins/module_utils/network/vyos/config/ospfv3/ospfv3.py index c43dfe7..abafc90 100644 --- a/plugins/module_utils/network/vyos/config/ospfv3/ospfv3.py +++ b/plugins/module_utils/network/vyos/config/ospfv3/ospfv3.py @@ -15,23 +15,22 @@ from __future__ import absolute_import, division, print_function __metaclass__ = type from copy import deepcopy + +from ansible.module_utils.six import iteritems from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.cfg.base import ( ConfigBase, ) from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.utils import ( - to_list, remove_empties, search_obj_in_list, + to_list, ) -from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.facts import ( - Facts, -) -from ansible.module_utils.six import iteritems +from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.facts import Facts from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.utils.utils import ( + _bool_to_str, _in_target, _is_w_same, - _bool_to_str, ) @@ -137,14 +136,9 @@ class Ospfv3(ConfigBase): to the desired configuration """ commands = [] - if ( - self.state in ("merged", "replaced", "overridden", "rendered") - and not w - ): + if self.state in ("merged", "replaced", "overridden", "rendered") and not w: self._module.fail_json( - msg="value of config parameter must not be empty for state {0}".format( - self.state - ) + msg="value of config parameter must not be empty for state {0}".format(self.state) ) if self.state == "deleted": commands.extend(self._state_deleted(w, h)) @@ -245,20 +239,10 @@ class Ospfv3(ConfigBase): leaf_dict = {"parameters": "router_id"} leaf = leaf_dict[attr] for item, value in iteritems(want[attr]): - if ( - opr - and item in leaf - and not _is_w_same(want[attr], h, item) - ): - commands.append( - self._form_attr_cmd( - key=attr, attr=item, val=value, opr=opr - ) - ) + if opr and item in leaf and not _is_w_same(want[attr], h, item): + commands.append(self._form_attr_cmd(key=attr, attr=item, val=value, opr=opr)) elif not opr and item in leaf and not _in_target(h, item): - commands.append( - self._form_attr_cmd(key=attr, attr=item, opr=opr) - ) + commands.append(self._form_attr_cmd(key=attr, attr=item, opr=opr)) return commands def _render_list_dict_param(self, attr, want, have, cmd=None, opr=True): @@ -293,14 +277,8 @@ class Ospfv3(ConfigBase): for key, val in iteritems(w_item): if not cmd: cmd = self._compute_command(opr=opr) - h_item = search_obj_in_list( - w_item[name[attr]], h, name[attr] - ) - if ( - opr - and key in leaf - and not _is_w_same(w_item, h_item, key) - ): + h_item = search_obj_in_list(w_item[name[attr]], h, name[attr]) + if opr and key in leaf and not _is_w_same(w_item, h_item, key): if key == "route_type" or ( key == "address" and "advertise" not in w_item @@ -311,12 +289,7 @@ class Ospfv3(ConfigBase): commands.append(cmd + attr + " " + str(val)) elif key in leaf_dict["range"] and key != "address": commands.append( - cmd - + attr - + " " - + w_item[name[attr]] - + " " - + key.replace("_", "-") + cmd + attr + " " + w_item[name[attr]] + " " + key.replace("_", "-") ) elif key == "route_map": commands.append( @@ -329,16 +302,11 @@ class Ospfv3(ConfigBase): + " " + str(val) ) - elif ( - not opr and key in leaf and not _in_target(h_item, key) - ): + elif not opr and key in leaf and not _in_target(h_item, key): if key in ("route_type", "address"): commands.append(cmd + attr + " " + str(val)) else: - commands.append( - cmd - + (attr + " " + w_item[name[attr]] + " " + key) - ) + commands.append(cmd + (attr + " " + w_item[name[attr]] + " " + key)) return commands def _render_areas(self, attr, want, have, opr=True): @@ -369,22 +337,14 @@ class Ospfv3(ConfigBase): ) + " " ) - h_area = search_obj_in_list( - w_area["area_id"], h_lst, "area_id" - ) + h_area = search_obj_in_list(w_area["area_id"], h_lst, "area_id") if not opr and not h_area: commands.append( - self._form_attr_cmd( - key="area", attr=w_area["area_id"], opr=opr - ) + self._form_attr_cmd(key="area", attr=w_area["area_id"], opr=opr) ) else: for key, val in iteritems(w_area): - if ( - opr - and key in l_set - and not _is_w_same(w_area, h_area, key) - ): + if opr and key in l_set and not _is_w_same(w_area, h_area, key): if key == "area_id": commands.append( self._form_attr_cmd( @@ -401,20 +361,14 @@ class Ospfv3(ConfigBase): + _bool_to_str(val).replace("_", "-") ) elif not opr and key in l_set: - if key == "area_id" and not _in_target( - h_area, key - ): + if key == "area_id" and not _in_target(h_area, key): commands.append(cmd) continue - if key != "area_id" and not _in_target( - h_area, key - ): + if key != "area_id" and not _in_target(h_area, key): commands.append(cmd + val + " " + key) elif key == "range": commands.extend( - self._render_list_dict_param( - key, w_area, h_area, cmd, opr - ) + self._render_list_dict_param(key, w_area, h_area, cmd, opr) ) return commands @@ -427,13 +381,9 @@ class Ospfv3(ConfigBase): :param opr: True/False. :return: generated command. """ - return self._compute_command( - key, attr=self._map_attrib(attr), val=val, opr=opr - ) + return self._compute_command(key, attr=self._map_attrib(attr), val=val, opr=opr) - def _compute_command( - self, key=None, attr=None, val=None, remove=False, opr=True - ): + def _compute_command(self, key=None, attr=None, val=None, remove=False, opr=True): """ This function construct the add/delete command based on passed attributes. :param key: parent key. diff --git a/plugins/module_utils/network/vyos/config/prefix_lists/prefix_lists.py b/plugins/module_utils/network/vyos/config/prefix_lists/prefix_lists.py index b2c119d..a8cc69e 100644 --- a/plugins/module_utils/network/vyos/config/prefix_lists/prefix_lists.py +++ b/plugins/module_utils/network/vyos/config/prefix_lists/prefix_lists.py @@ -19,15 +19,14 @@ created. from ansible.module_utils.six import iteritems -from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.utils import ( - dict_merge, -) from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.rm_base.resource_module import ( ResourceModule, ) -from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.facts import ( - Facts, +from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.utils import ( + dict_merge, ) + +from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.facts import Facts from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.rm_templates.prefix_lists import ( Prefix_listsTemplate, ) @@ -86,18 +85,14 @@ class Prefix_lists(ResourceModule): # if state is deleted, empty out wantd and set haved to wantd if self.state == "deleted": - haved = { - k: v for k, v in iteritems(haved) if k in wantd or not wantd - } + haved = {k: v for k, v in iteritems(haved) if k in wantd or not wantd} for key, hvalue in iteritems(haved): wvalue = wantd.pop(key, {}) if wvalue: wplists = wvalue.get("prefix_lists", {}) hplists = hvalue.get("prefix_lists", {}) hvalue["prefix_lists"] = { - k: v - for k, v in iteritems(hplists) - if k in wplists or not wplists + k: v for k, v in iteritems(hplists) if k in wplists or not wplists } # remove superfluous config for overridden and deleted @@ -174,9 +169,5 @@ class Prefix_lists(ResourceModule): if "entries" in pl: for entry in pl["entries"]: entry.update({"afi": afi, "name": pl["name"]}) - pl["entries"] = { - x["sequence"]: x for x in pl["entries"] - } - value["prefix_lists"] = { - entry["name"]: entry for entry in value["prefix_lists"] - } + pl["entries"] = {x["sequence"]: x for x in pl["entries"]} + value["prefix_lists"] = {entry["name"]: entry for entry in value["prefix_lists"]} diff --git a/plugins/module_utils/network/vyos/config/route_maps/route_maps.py b/plugins/module_utils/network/vyos/config/route_maps/route_maps.py index c719e6d..dd6fbf6 100644 --- a/plugins/module_utils/network/vyos/config/route_maps/route_maps.py +++ b/plugins/module_utils/network/vyos/config/route_maps/route_maps.py @@ -19,15 +19,14 @@ created. from ansible.module_utils.six import iteritems -from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.utils import ( - dict_merge, -) from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.rm_base.resource_module import ( ResourceModule, ) -from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.facts import ( - Facts, +from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.utils import ( + dict_merge, ) + +from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.facts import Facts from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.rm_templates.route_maps import ( Route_mapsTemplate, ) @@ -116,18 +115,14 @@ class Route_maps(ResourceModule): # if state is deleted, empty out wantd and set haved to wantd if self.state == "deleted": - haved = { - k: v for k, v in iteritems(haved) if k in wantd or not wantd - } + haved = {k: v for k, v in iteritems(haved) if k in wantd or not wantd} wantd = {} # remove superfluous config for overridden and deleted if self.state in ["overridden", "deleted"]: for k, have in iteritems(haved): if k not in wantd: - self.commands.append( - self._tmplt.render({"route_map": k}, "route_map", True) - ) + self.commands.append(self._tmplt.render({"route_map": k}, "route_map", True)) for wk, want in iteritems(wantd): self._compare(want=want, have=haved.pop(wk, {})) @@ -154,7 +149,6 @@ class Route_maps(ResourceModule): for x in data["entries"]: x.update({"route_map": rmap}) data["entries"] = { - (rmap, entry.get("sequence")): entry - for entry in data["entries"] + (rmap, entry.get("sequence")): entry for entry in data["entries"] } return entry diff --git a/plugins/module_utils/network/vyos/config/snmp_server/snmp_server.py b/plugins/module_utils/network/vyos/config/snmp_server/snmp_server.py index 5ddd429..b942f8b 100644 --- a/plugins/module_utils/network/vyos/config/snmp_server/snmp_server.py +++ b/plugins/module_utils/network/vyos/config/snmp_server/snmp_server.py @@ -17,23 +17,21 @@ necessary to bring the current configuration to its desired end-state is created. """ +import re + from ansible.module_utils.six import iteritems -from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.utils import ( - dict_merge, -) from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.rm_base.resource_module import ( ResourceModule, ) -from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.facts import ( - Facts, +from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.utils import ( + dict_merge, + get_from_dict, ) + +from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.facts import Facts from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.rm_templates.snmp_server import ( Snmp_serverTemplate, ) -from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.utils import ( - get_from_dict, -) -import re class Snmp_server(ResourceModule): @@ -164,9 +162,7 @@ class Snmp_server(ResourceModule): want={}, ) else: - self.compare( - parsers=parsers, want={}, have={attrib: entry} - ) + self.compare(parsers=parsers, want={}, have={attrib: entry}) def _compare_snmp_v3(self, want, have): parsers = [ @@ -192,9 +188,7 @@ class Snmp_server(ResourceModule): wattrib = get_from_dict(wdict, attrib) or {} hattrib = get_from_dict(hdict, attrib) or {} for key, entry in iteritems(wattrib): - self._compare_snmp_v3_auth_privacy( - entry, hattrib.get(key, {}), attrib - ) + self._compare_snmp_v3_auth_privacy(entry, hattrib.get(key, {}), attrib) for k, v in iteritems(entry): if k != attribute_dict[attrib]: h = {} @@ -215,9 +209,7 @@ class Snmp_server(ResourceModule): "snmp_v3": { attrib: { k: v, - attribute_dict[attrib]: entry[ - attribute_dict[attrib] - ], + attribute_dict[attrib]: entry[attribute_dict[attrib]], } } }, @@ -226,9 +218,7 @@ class Snmp_server(ResourceModule): # remove remaining items in have for replaced for key, entry in iteritems(hattrib): self._compare_snmp_v3_auth_privacy({}, entry, attrib) - self.compare( - parsers=parsers, want={}, have={"snmp_v3": {attrib: entry}} - ) + self.compare(parsers=parsers, want={}, have={"snmp_v3": {attrib: entry}}) hdict.pop(attrib, {}) for key, entry in iteritems(wdict): # self.addcmd(entry, attrib, False) @@ -239,9 +229,7 @@ class Snmp_server(ResourceModule): ) # remove remaining items in have for replaced for key, entry in iteritems(hdict): - self.compare( - parsers=parsers, want={}, have={"snmp_v3": {key: entry}} - ) + self.compare(parsers=parsers, want={}, have={"snmp_v3": {key: entry}}) def _compare_snmp_v3_auth_privacy(self, wattrib, hattrib, attrib): parsers = [ diff --git a/plugins/module_utils/network/vyos/config/static_routes/static_routes.py b/plugins/module_utils/network/vyos/config/static_routes/static_routes.py index bd7fd15..230a47c 100644 --- a/plugins/module_utils/network/vyos/config/static_routes/static_routes.py +++ b/plugins/module_utils/network/vyos/config/static_routes/static_routes.py @@ -15,23 +15,23 @@ from __future__ import absolute_import, division, print_function __metaclass__ = type from copy import deepcopy + +from ansible.module_utils.six import iteritems from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.cfg.base import ( ConfigBase, ) from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.utils import ( - to_list, dict_diff, remove_empties, + to_list, ) -from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.facts import ( - Facts, -) -from ansible.module_utils.six import iteritems + +from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.facts import Facts from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.utils.utils import ( - get_route_type, + dict_delete, get_lst_diff_for_dicts, get_lst_same_for_dicts, - dict_delete, + get_route_type, ) @@ -56,9 +56,7 @@ class Static_routes(ConfigBase): facts, _warnings = Facts(self._module).get_facts( self.gather_subset, self.gather_network_resources, data=data ) - static_routes_facts = facts["ansible_network_resources"].get( - "static_routes" - ) + static_routes_facts = facts["ansible_network_resources"].get("static_routes") if not static_routes_facts: return [] return static_routes_facts @@ -99,9 +97,7 @@ class Static_routes(ConfigBase): self._module.fail_json( msg="value of running_config parameter must not be empty for state parsed" ) - result["parsed"] = self.get_static_routes_facts( - data=running_config - ) + result["parsed"] = self.get_static_routes_facts(data=running_config) else: changed_static_routes_facts = [] @@ -138,14 +134,9 @@ class Static_routes(ConfigBase): to the desired configuration """ commands = [] - if ( - self.state in ("merged", "replaced", "overridden", "rendered") - and not want - ): + if self.state in ("merged", "replaced", "overridden", "rendered") and not want: self._module.fail_json( - msg="value of config parameter must not be empty for state {0}".format( - self.state - ) + msg="value of config parameter must not be empty for state {0}".format(self.state) ) if self.state == "overridden": commands.extend(self._state_overridden(want=want, have=have)) @@ -189,9 +180,7 @@ class Static_routes(ConfigBase): if key == "next_hops": commands.extend(self._update_next_hop(want, have)) elif key == "blackhole_config": - commands.extend( - self._update_blackhole(key, want, have) - ) + commands.extend(self._update_blackhole(key, want, have)) commands.extend(self._state_merged(want, have)) return commands @@ -243,11 +232,7 @@ class Static_routes(ConfigBase): af = w["address_families"] for item in af: if self.afi_in_have(have, item): - commands.append( - self._compute_command( - afi=item["afi"], remove=True - ) - ) + commands.append(self._compute_command(afi=item["afi"], remove=True)) else: routes = self._get_routes(have) if self._is_ip_route_exist(routes): @@ -308,11 +293,7 @@ class Static_routes(ConfigBase): ) ) elif attrib == "type": - commands.append( - self._compute_command( - dest=want["dest"], key="blackhole" - ) - ) + commands.append(self._compute_command(dest=want["dest"], key="blackhole")) return commands def _add_next_hop(self, want, have, opr=True): @@ -327,13 +308,9 @@ class Static_routes(ConfigBase): want_copy = deepcopy(remove_empties(want)) have_copy = deepcopy(remove_empties(have)) if not opr: - diff_next_hops = get_lst_same_for_dicts( - want_copy, have_copy, "next_hops" - ) + diff_next_hops = get_lst_same_for_dicts(want_copy, have_copy, "next_hops") else: - diff_next_hops = get_lst_diff_for_dicts( - want_copy, have_copy, "next_hops" - ) + diff_next_hops = get_lst_diff_for_dicts(want_copy, have_copy, "next_hops") if diff_next_hops: for hop in diff_next_hops: for element in hop: @@ -361,9 +338,7 @@ class Static_routes(ConfigBase): self._compute_command( dest=want["dest"], key="next-hop", - attrib=hop["forward_router_address"] - + " " - + "distance", + attrib=hop["forward_router_address"] + " " + "distance", value=str(hop[element]), opr=opr, ) @@ -373,9 +348,7 @@ class Static_routes(ConfigBase): self._compute_command( dest=want["dest"], key="next-hop", - attrib=hop["forward_router_address"] - + " " - + "next-hop-interface", + attrib=hop["forward_router_address"] + " " + "next-hop-interface", value=hop[element], opr=opr, ) @@ -414,14 +387,9 @@ class Static_routes(ConfigBase): value=str(value), ) ) - elif ( - attrib == "type" - and "distance" not in want_blackhole.keys() - ): + elif attrib == "type" and "distance" not in want_blackhole.keys(): commands.append( - self._compute_command( - dest=want["dest"], key="blackhole", remove=True - ) + self._compute_command(dest=want["dest"], key="blackhole", remove=True) ) return commands @@ -438,9 +406,7 @@ class Static_routes(ConfigBase): want_copy = deepcopy(remove_empties(want)) have_copy = deepcopy(remove_empties(have)) - diff_next_hops = get_lst_diff_for_dicts( - have_copy, want_copy, "next_hops" - ) + diff_next_hops = get_lst_diff_for_dicts(have_copy, want_copy, "next_hops") if diff_next_hops: for hop in diff_next_hops: for element in hop: @@ -468,9 +434,7 @@ class Static_routes(ConfigBase): self._compute_command( dest=want["dest"], key="next-hop", - attrib=hop["forward_router_address"] - + " " - + "distance", + attrib=hop["forward_router_address"] + " " + "distance", value=str(hop[element]), remove=True, ) @@ -480,9 +444,7 @@ class Static_routes(ConfigBase): self._compute_command( dest=want["dest"], key="next-hop", - attrib=hop["forward_router_address"] - + " " - + "next-hop-interface", + attrib=hop["forward_router_address"] + " " + "next-hop-interface", value=hop[element], remove=True, ) @@ -502,9 +464,7 @@ class Static_routes(ConfigBase): want_nh = want.get("next_hops") or [] # delete static route operation per destination if not opr and not want_nh: - commands.append( - self._compute_command(dest=want["dest"], remove=True) - ) + commands.append(self._compute_command(dest=want["dest"], remove=True)) else: temp_have_next_hops = have.pop("next_hops", None) @@ -520,9 +480,7 @@ class Static_routes(ConfigBase): for key, value in iteritems(updates): if value: if key == "blackhole_config": - commands.extend( - self._add_blackhole(key, want, have) - ) + commands.extend(self._add_blackhole(key, want, have)) return commands def _compute_command( diff --git a/plugins/module_utils/network/vyos/facts/bgp_address_family/bgp_address_family.py b/plugins/module_utils/network/vyos/facts/bgp_address_family/bgp_address_family.py index a7296f2..5d60184 100644 --- a/plugins/module_utils/network/vyos/facts/bgp_address_family/bgp_address_family.py +++ b/plugins/module_utils/network/vyos/facts/bgp_address_family/bgp_address_family.py @@ -15,15 +15,15 @@ based on the configuration. """ import re -from ansible_collections.ansible.netcommon.plugins.module_utils.network.common import ( - utils, + +from ansible_collections.ansible.netcommon.plugins.module_utils.network.common import utils + +from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.argspec.bgp_address_family.bgp_address_family import ( + Bgp_address_familyArgs, ) from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.rm_templates.bgp_address_family import ( Bgp_address_familyTemplate, ) -from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.argspec.bgp_address_family.bgp_address_family import ( - Bgp_address_familyArgs, -) class Bgp_address_familyFacts(object): @@ -34,9 +34,7 @@ class Bgp_address_familyFacts(object): self.argument_spec = Bgp_address_familyArgs.argument_spec def get_device_data(self, connection): - return connection.get( - 'show configuration commands | match "set protocols bgp"' - ) + return connection.get('show configuration commands | match "set protocols bgp"') def populate_facts(self, connection, ansible_facts, data=None): """Populate the facts for Bgp_address_family network resource @@ -60,40 +58,28 @@ class Bgp_address_familyFacts(object): config_lines.append(re.sub("'", "", resource)) # parse native config using the Bgp_address_family template - bgp_address_family_parser = Bgp_address_familyTemplate( - lines=config_lines - ) + bgp_address_family_parser = Bgp_address_familyTemplate(lines=config_lines) objs = bgp_address_family_parser.parse() if objs: if "address_family" in objs: objs["address_family"] = list(objs["address_family"].values()) for af in objs["address_family"]: if "networks" in af: - af["networks"] = sorted( - af["networks"], key=lambda k: k["prefix"] - ) + af["networks"] = sorted(af["networks"], key=lambda k: k["prefix"]) if "aggregate_address" in af: af["aggregate_address"] = sorted( af["aggregate_address"], key=lambda k: k["prefix"] ) if "neighbors" in objs: objs["neighbors"] = list(objs["neighbors"].values()) - objs["neighbors"] = sorted( - objs["neighbors"], key=lambda k: k["neighbor_address"] - ) + objs["neighbors"] = sorted(objs["neighbors"], key=lambda k: k["neighbor_address"]) for neigh in objs["neighbors"]: if "address_family" in neigh: - neigh["address_family"] = list( - neigh["address_family"].values() - ) + neigh["address_family"] = list(neigh["address_family"].values()) - ansible_facts["ansible_network_resources"].pop( - "bgp_address_family", None - ) + ansible_facts["ansible_network_resources"].pop("bgp_address_family", None) - params = utils.remove_empties( - utils.validate_config(self.argument_spec, {"config": objs}) - ) + params = utils.remove_empties(utils.validate_config(self.argument_spec, {"config": objs})) facts["bgp_address_family"] = params.get("config", []) ansible_facts["ansible_network_resources"].update(facts) diff --git a/plugins/module_utils/network/vyos/facts/bgp_global/bgp_global.py b/plugins/module_utils/network/vyos/facts/bgp_global/bgp_global.py index 1efd877..c6105a0 100644 --- a/plugins/module_utils/network/vyos/facts/bgp_global/bgp_global.py +++ b/plugins/module_utils/network/vyos/facts/bgp_global/bgp_global.py @@ -14,16 +14,16 @@ for a given resource, parsed, and the facts tree is populated based on the configuration. """ -from ansible_collections.ansible.netcommon.plugins.module_utils.network.common import ( - utils, +import re + +from ansible_collections.ansible.netcommon.plugins.module_utils.network.common import utils + +from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.argspec.bgp_global.bgp_global import ( + Bgp_globalArgs, ) from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.rm_templates.bgp_global import ( Bgp_globalTemplate, ) -from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.argspec.bgp_global.bgp_global import ( - Bgp_globalArgs, -) -import re class Bgp_globalFacts(object): @@ -34,9 +34,7 @@ class Bgp_globalFacts(object): self.argument_spec = Bgp_globalArgs.argument_spec def get_device_data(self, connection): - return connection.get( - 'show configuration commands | match "set protocols bgp"' - ) + return connection.get('show configuration commands | match "set protocols bgp"') def populate_facts(self, connection, ansible_facts, data=None): """Populate the facts for Bgp_global network resource @@ -59,31 +57,21 @@ class Bgp_globalFacts(object): if "address-family" not in resource: config_lines.append(re.sub("'", "", resource)) - bgp_global_parser = Bgp_globalTemplate( - lines=config_lines, module=self._module - ) + bgp_global_parser = Bgp_globalTemplate(lines=config_lines, module=self._module) objs = bgp_global_parser.parse() if "neighbor" in objs: objs["neighbor"] = list(objs["neighbor"].values()) - objs["neighbor"] = sorted( - objs["neighbor"], key=lambda k: k["address"] - ) + objs["neighbor"] = sorted(objs["neighbor"], key=lambda k: k["address"]) if "network" in objs: - objs["network"] = sorted( - objs["network"], key=lambda k: k["address"] - ) + objs["network"] = sorted(objs["network"], key=lambda k: k["address"]) if "aggregate_address" in objs: - objs["aggregate_address"] = sorted( - objs["aggregate_address"], key=lambda k: k["prefix"] - ) + objs["aggregate_address"] = sorted(objs["aggregate_address"], key=lambda k: k["prefix"]) ansible_facts["ansible_network_resources"].pop("bgp_global", None) params = utils.remove_empties( - bgp_global_parser.validate_config( - self.argument_spec, {"config": objs}, redact=True - ) + bgp_global_parser.validate_config(self.argument_spec, {"config": objs}, redact=True) ) facts["bgp_global"] = params.get("config", []) diff --git a/plugins/module_utils/network/vyos/facts/facts.py b/plugins/module_utils/network/vyos/facts/facts.py index 867c427..f7b2b4e 100644 --- a/plugins/module_utils/network/vyos/facts/facts.py +++ b/plugins/module_utils/network/vyos/facts/facts.py @@ -13,6 +13,25 @@ __metaclass__ = type from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.facts.facts import ( FactsBase, ) + +from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.bgp_address_family.bgp_address_family import ( + Bgp_address_familyFacts, +) +from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.bgp_global.bgp_global import ( + Bgp_globalFacts, +) +from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.firewall_global.firewall_global import ( + Firewall_globalFacts, +) +from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.firewall_interfaces.firewall_interfaces import ( + Firewall_interfacesFacts, +) +from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.firewall_rules.firewall_rules import ( + Firewall_rulesFacts, +) +from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.hostname.hostname import ( + HostnameFacts, +) from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.interfaces.interfaces import ( InterfacesFacts, ) @@ -22,64 +41,45 @@ from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.l3_in from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.lag_interfaces.lag_interfaces import ( Lag_interfacesFacts, ) +from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.legacy.base import ( + Config, + Default, + Neighbors, +) from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.lldp_global.lldp_global import ( Lldp_globalFacts, ) from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.lldp_interfaces.lldp_interfaces import ( Lldp_interfacesFacts, ) -from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.firewall_rules.firewall_rules import ( - Firewall_rulesFacts, -) -from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.static_routes.static_routes import ( - Static_routesFacts, -) -from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.firewall_global.firewall_global import ( - Firewall_globalFacts, -) -from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.firewall_interfaces.firewall_interfaces import ( - Firewall_interfacesFacts, -) -from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.ospfv3.ospfv3 import ( - Ospfv3Facts, +from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.logging_global.logging_global import ( + Logging_globalFacts, ) -from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.ospfv2.ospfv2 import ( - Ospfv2Facts, +from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.ntp_global.ntp_global import ( + Ntp_globalFacts, ) from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.ospf_interfaces.ospf_interfaces import ( Ospf_interfacesFacts, ) -from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.bgp_global.bgp_global import ( - Bgp_globalFacts, -) -from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.bgp_address_family.bgp_address_family import ( - Bgp_address_familyFacts, +from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.ospfv2.ospfv2 import ( + Ospfv2Facts, ) -from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.route_maps.route_maps import ( - Route_mapsFacts, +from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.ospfv3.ospfv3 import ( + Ospfv3Facts, ) from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.prefix_lists.prefix_lists import ( Prefix_listsFacts, ) -from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.logging_global.logging_global import ( - Logging_globalFacts, -) -from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.ntp_global.ntp_global import ( - Ntp_globalFacts, +from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.route_maps.route_maps import ( + Route_mapsFacts, ) from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.snmp_server.snmp_server import ( Snmp_serverFacts, ) -from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.hostname.hostname import ( - HostnameFacts, -) -from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.legacy.base import ( - Default, - Neighbors, - Config, +from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.static_routes.static_routes import ( + Static_routesFacts, ) - FACT_LEGACY_SUBSETS = dict(default=Default, neighbors=Neighbors, config=Config) FACT_RESOURCE_SUBSETS = dict( interfaces=InterfacesFacts, @@ -114,9 +114,7 @@ class Facts(FactsBase): def __init__(self, module): super(Facts, self).__init__(module) - def get_facts( - self, legacy_facts_type=None, resource_facts_type=None, data=None - ): + def get_facts(self, legacy_facts_type=None, resource_facts_type=None, data=None): """Collect the facts for vyos :param legacy_facts_type: List of legacy facts types :param resource_facts_type: List of resource fact types @@ -125,11 +123,7 @@ class Facts(FactsBase): :return: the facts gathered """ if self.VALID_RESOURCE_SUBSETS: - self.get_network_resources_facts( - FACT_RESOURCE_SUBSETS, resource_facts_type, data - ) + self.get_network_resources_facts(FACT_RESOURCE_SUBSETS, resource_facts_type, data) if self.VALID_LEGACY_GATHER_SUBSETS: - self.get_network_legacy_facts( - FACT_LEGACY_SUBSETS, legacy_facts_type - ) + self.get_network_legacy_facts(FACT_LEGACY_SUBSETS, legacy_facts_type) return self.ansible_facts, self._warnings diff --git a/plugins/module_utils/network/vyos/facts/firewall_global/firewall_global.py b/plugins/module_utils/network/vyos/facts/firewall_global/firewall_global.py index 1b1076c..6441c26 100644 --- a/plugins/module_utils/network/vyos/facts/firewall_global/firewall_global.py +++ b/plugins/module_utils/network/vyos/facts/firewall_global/firewall_global.py @@ -14,10 +14,10 @@ from __future__ import absolute_import, division, print_function __metaclass__ = type from copy import deepcopy -from re import findall, search, M -from ansible_collections.ansible.netcommon.plugins.module_utils.network.common import ( - utils, -) +from re import M, findall, search + +from ansible_collections.ansible.netcommon.plugins.module_utils.network.common import utils + from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.argspec.firewall_global.firewall_global import ( Firewall_globalArgs, ) @@ -207,9 +207,7 @@ class Firewall_globalFacts(object): :return: generated config dictionary. """ cfg_dict = {} - cfg_dict["port_group"] = self.parse_group_lst( - conf, "port-group", False - ) + cfg_dict["port_group"] = self.parse_group_lst(conf, "port-group", False) cfg_dict["address_group"] = self.parse_group_lst( conf, "address-group" ) + self.parse_group_lst(conf, "ipv6-address-group") diff --git a/plugins/module_utils/network/vyos/facts/firewall_interfaces/firewall_interfaces.py b/plugins/module_utils/network/vyos/facts/firewall_interfaces/firewall_interfaces.py index d0cfb53..3e0d323 100644 --- a/plugins/module_utils/network/vyos/facts/firewall_interfaces/firewall_interfaces.py +++ b/plugins/module_utils/network/vyos/facts/firewall_interfaces/firewall_interfaces.py @@ -13,11 +13,11 @@ from __future__ import absolute_import, division, print_function __metaclass__ = type -from re import findall, search, M from copy import deepcopy -from ansible_collections.ansible.netcommon.plugins.module_utils.network.common import ( - utils, -) +from re import M, findall, search + +from ansible_collections.ansible.netcommon.plugins.module_utils.network.common import utils + from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.argspec.firewall_interfaces.firewall_interfaces import ( Firewall_interfacesArgs, ) @@ -57,20 +57,14 @@ class Firewall_interfacesFacts(object): # using mock data instead data = self.get_device_data(connection) objs = [] - interfaces = findall( - r"^set interfaces ethernet (?:\'*)(\S+)(?:\'*)", data, M - ) + interfaces = findall(r"^set interfaces ethernet (?:\'*)(\S+)(?:\'*)", data, M) if interfaces: objs = self.get_names(data, interfaces) - ansible_facts["ansible_network_resources"].pop( - "firewall_interfaces", None - ) + ansible_facts["ansible_network_resources"].pop("firewall_interfaces", None) facts = {} if objs: facts["firewall_interfaces"] = [] - params = utils.validate_config( - self.argument_spec, {"config": objs} - ) + params = utils.validate_config(self.argument_spec, {"config": objs}) for cfg in params["config"]: facts["firewall_interfaces"].append(utils.remove_empties(cfg)) @@ -127,9 +121,7 @@ class Firewall_interfacesFacts(object): if config: ar_lst.append(config) if v6_ar: - v6_conf = "\n".join( - findall(r"(^.*?%s.*?$)" % " ipv6-name", conf, M) - ) + v6_conf = "\n".join(findall(r"(^.*?%s.*?$)" % " ipv6-name", conf, M)) config = self.parse_int_rules(v6_conf, "ipv6") if config: ar_lst.append(config) diff --git a/plugins/module_utils/network/vyos/facts/firewall_rules/firewall_rules.py b/plugins/module_utils/network/vyos/facts/firewall_rules/firewall_rules.py index cb1d4bb..69daad9 100644 --- a/plugins/module_utils/network/vyos/facts/firewall_rules/firewall_rules.py +++ b/plugins/module_utils/network/vyos/facts/firewall_rules/firewall_rules.py @@ -14,11 +14,11 @@ from __future__ import absolute_import, division, print_function __metaclass__ = type import re -from re import findall, search, M from copy import deepcopy -from ansible_collections.ansible.netcommon.plugins.module_utils.network.common import ( - utils, -) +from re import M, findall, search + +from ansible_collections.ansible.netcommon.plugins.module_utils.network.common import utils + from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.argspec.firewall_rules.firewall_rules import ( Firewall_rulesArgs, ) @@ -59,9 +59,7 @@ class Firewall_rulesFacts(object): data = self.get_device_data(connection) # split the config into instances of the resource objs = [] - v6_rules = findall( - r"^set firewall ipv6-name (?:\'*)(\S+)(?:\'*)", data, M - ) + v6_rules = findall(r"^set firewall ipv6-name (?:\'*)(\S+)(?:\'*)", data, M) v4_rules = findall(r"^set firewall name (?:\'*)(\S+)(?:\'*)", data, M) if v6_rules: config = self.get_rules(data, v6_rules, type="ipv6") @@ -78,9 +76,7 @@ class Firewall_rulesFacts(object): facts = {} if objs: facts["firewall_rules"] = [] - params = utils.validate_config( - self.argument_spec, {"config": objs} - ) + params = utils.validate_config(self.argument_spec, {"config": objs}) for cfg in params["config"]: facts["firewall_rules"].append(utils.remove_empties(cfg)) diff --git a/plugins/module_utils/network/vyos/facts/hostname/hostname.py b/plugins/module_utils/network/vyos/facts/hostname/hostname.py index acdddca..77ecc8c 100644 --- a/plugins/module_utils/network/vyos/facts/hostname/hostname.py +++ b/plugins/module_utils/network/vyos/facts/hostname/hostname.py @@ -14,17 +14,16 @@ for a given resource, parsed, and the facts tree is populated based on the configuration. """ -from ansible_collections.ansible.netcommon.plugins.module_utils.network.common import ( - utils, +import re + +from ansible_collections.ansible.netcommon.plugins.module_utils.network.common import utils + +from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.argspec.hostname.hostname import ( + HostnameArgs, ) from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.rm_templates.hostname import ( HostnameTemplate, ) -from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.argspec.hostname.hostname import ( - HostnameArgs, -) - -import re class HostnameFacts(object): @@ -57,17 +56,13 @@ class HostnameFacts(object): config_lines.append(re.sub("'", "", resource)) # parse native config using the Hostname template - hostname_parser = HostnameTemplate( - lines=config_lines, module=self._module - ) + hostname_parser = HostnameTemplate(lines=config_lines, module=self._module) objs = hostname_parser.parse() ansible_facts["ansible_network_resources"].pop("hostname", None) params = utils.remove_empties( - hostname_parser.validate_config( - self.argument_spec, {"config": objs}, redact=True - ) + hostname_parser.validate_config(self.argument_spec, {"config": objs}, redact=True) ) facts["hostname"] = params.get("config", {}) diff --git a/plugins/module_utils/network/vyos/facts/interfaces/interfaces.py b/plugins/module_utils/network/vyos/facts/interfaces/interfaces.py index ea3933c..c9479db 100644 --- a/plugins/module_utils/network/vyos/facts/interfaces/interfaces.py +++ b/plugins/module_utils/network/vyos/facts/interfaces/interfaces.py @@ -15,11 +15,11 @@ from __future__ import absolute_import, division, print_function __metaclass__ = type -from re import findall, M from copy import deepcopy -from ansible_collections.ansible.netcommon.plugins.module_utils.network.common import ( - utils, -) +from re import M, findall + +from ansible_collections.ansible.netcommon.plugins.module_utils.network.common import utils + from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.argspec.interfaces.interfaces import ( InterfacesArgs, ) @@ -75,9 +75,7 @@ class InterfacesFacts(object): facts = {} if objs: facts["interfaces"] = [] - params = utils.validate_config( - self.argument_spec, {"config": objs} - ) + params = utils.validate_config(self.argument_spec, {"config": objs}) for cfg in params["config"]: facts["interfaces"].append(utils.remove_empties(cfg)) @@ -96,9 +94,7 @@ class InterfacesFacts(object): """ vif_conf = "\n".join(filter(lambda x: ("vif" in x), conf)) eth_conf = "\n".join(filter(lambda x: ("vif" not in x), conf)) - config = self.parse_attribs( - ["description", "speed", "mtu", "duplex"], eth_conf - ) + config = self.parse_attribs(["description", "speed", "mtu", "duplex"], eth_conf) config["vifs"] = self.parse_vifs(vif_conf) return utils.remove_empties(config) diff --git a/plugins/module_utils/network/vyos/facts/l3_interfaces/l3_interfaces.py b/plugins/module_utils/network/vyos/facts/l3_interfaces/l3_interfaces.py index 09ab994..ea4cf69 100644 --- a/plugins/module_utils/network/vyos/facts/l3_interfaces/l3_interfaces.py +++ b/plugins/module_utils/network/vyos/facts/l3_interfaces/l3_interfaces.py @@ -17,16 +17,16 @@ __metaclass__ = type import re from copy import deepcopy -from ansible_collections.ansible.netcommon.plugins.module_utils.network.common import ( - utils, -) + from ansible.module_utils.six import iteritems -from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.utils.utils import ( - get_ip_address_version, -) +from ansible_collections.ansible.netcommon.plugins.module_utils.network.common import utils + from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.argspec.l3_interfaces.l3_interfaces import ( L3_interfacesArgs, ) +from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.utils.utils import ( + get_ip_address_version, +) class L3_interfacesFacts(object): @@ -77,9 +77,7 @@ class L3_interfacesFacts(object): facts = {} if objs: facts["l3_interfaces"] = [] - params = utils.validate_config( - self.argument_spec, {"config": objs} - ) + params = utils.validate_config(self.argument_spec, {"config": objs}) for cfg in params["config"]: facts["l3_interfaces"].append(utils.remove_empties(cfg)) diff --git a/plugins/module_utils/network/vyos/facts/lag_interfaces/lag_interfaces.py b/plugins/module_utils/network/vyos/facts/lag_interfaces/lag_interfaces.py index ff02cb0..251178a 100644 --- a/plugins/module_utils/network/vyos/facts/lag_interfaces/lag_interfaces.py +++ b/plugins/module_utils/network/vyos/facts/lag_interfaces/lag_interfaces.py @@ -13,12 +13,11 @@ from __future__ import absolute_import, division, print_function __metaclass__ = type -from re import findall, search, M from copy import deepcopy +from re import M, findall, search + +from ansible_collections.ansible.netcommon.plugins.module_utils.network.common import utils -from ansible_collections.ansible.netcommon.plugins.module_utils.network.common import ( - utils, -) from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.argspec.lag_interfaces.lag_interfaces import ( Lag_interfacesArgs, ) @@ -77,9 +76,7 @@ class Lag_interfacesFacts(object): facts = {} if objs: facts["lag_interfaces"] = [] - params = utils.validate_config( - self.argument_spec, {"config": objs} - ) + params = utils.validate_config(self.argument_spec, {"config": objs}) for cfg in params["config"]: facts["lag_interfaces"].append(utils.remove_empties(cfg)) @@ -96,12 +93,8 @@ class Lag_interfacesFacts(object): :rtype: dictionary :returns: The generated config """ - arp_monitor_conf = "\n".join( - filter(lambda x: ("arp-monitor" in x), conf) - ) - hash_policy_conf = "\n".join( - filter(lambda x: ("hash-policy" in x), conf) - ) + arp_monitor_conf = "\n".join(filter(lambda x: ("arp-monitor" in x), conf)) + hash_policy_conf = "\n".join(filter(lambda x: ("hash-policy" in x), conf)) lag_conf = "\n".join(filter(lambda x: ("bond" in x), conf)) config = self.parse_attribs(["mode", "primary"], lag_conf) config["arp_monitor"] = self.parse_arp_monitor(arp_monitor_conf) diff --git a/plugins/module_utils/network/vyos/facts/legacy/base.py b/plugins/module_utils/network/vyos/facts/legacy/base.py index 6f063d6..719df3f 100644 --- a/plugins/module_utils/network/vyos/facts/legacy/base.py +++ b/plugins/module_utils/network/vyos/facts/legacy/base.py @@ -14,9 +14,10 @@ from __future__ import absolute_import, division, print_function __metaclass__ = type import platform import re + from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.vyos import ( - run_commands, get_capabilities, + run_commands, ) diff --git a/plugins/module_utils/network/vyos/facts/lldp_global/lldp_global.py b/plugins/module_utils/network/vyos/facts/lldp_global/lldp_global.py index 22b6bc8..e563999 100644 --- a/plugins/module_utils/network/vyos/facts/lldp_global/lldp_global.py +++ b/plugins/module_utils/network/vyos/facts/lldp_global/lldp_global.py @@ -13,12 +13,11 @@ from __future__ import absolute_import, division, print_function __metaclass__ = type -from re import findall, M from copy import deepcopy +from re import M, findall + +from ansible_collections.ansible.netcommon.plugins.module_utils.network.common import utils -from ansible_collections.ansible.netcommon.plugins.module_utils.network.common import ( - utils, -) from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.argspec.lldp_global.lldp_global import ( Lldp_globalArgs, ) @@ -84,12 +83,8 @@ class Lldp_globalFacts(object): :rtype: dictionary :returns: The generated config """ - protocol_conf = "\n".join( - filter(lambda x: ("legacy-protocols" in x), conf) - ) - att_conf = "\n".join( - filter(lambda x: ("legacy-protocols" not in x), conf) - ) + protocol_conf = "\n".join(filter(lambda x: ("legacy-protocols" in x), conf)) + att_conf = "\n".join(filter(lambda x: ("legacy-protocols" not in x), conf)) config = self.parse_attribs(["snmp", "address"], att_conf) config["legacy_protocols"] = self.parse_protocols(protocol_conf) return utils.remove_empties(config) diff --git a/plugins/module_utils/network/vyos/facts/lldp_interfaces/lldp_interfaces.py b/plugins/module_utils/network/vyos/facts/lldp_interfaces/lldp_interfaces.py index 64d6a79..bfe684f 100644 --- a/plugins/module_utils/network/vyos/facts/lldp_interfaces/lldp_interfaces.py +++ b/plugins/module_utils/network/vyos/facts/lldp_interfaces/lldp_interfaces.py @@ -15,12 +15,11 @@ from __future__ import absolute_import, division, print_function __metaclass__ = type -from re import findall, search, M from copy import deepcopy +from re import M, findall, search + +from ansible_collections.ansible.netcommon.plugins.module_utils.network.common import utils -from ansible_collections.ansible.netcommon.plugins.module_utils.network.common import ( - utils, -) from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.argspec.lldp_interfaces.lldp_interfaces import ( Lldp_interfacesArgs, ) @@ -87,9 +86,7 @@ class Lldp_interfacesFacts(object): civic_conf = "\n".join(filter(lambda x: ("civic-based" in x), conf)) elin_conf = "\n".join(filter(lambda x: ("elin" in x), conf)) - coordinate_conf = "\n".join( - filter(lambda x: ("coordinate-based" in x), conf) - ) + coordinate_conf = "\n".join(filter(lambda x: ("coordinate-based" in x), conf)) disable = "\n".join(filter(lambda x: ("disable" in x), conf)) coordinate_based_conf = self.parse_attribs( @@ -137,9 +134,7 @@ class Lldp_interfacesFacts(object): c_add["ca_value"] = ca[2].strip("'") civic_info_list.append(c_add) - country_code = search( - r"^.*civic-based country-code (.+)", conf, M - ) + country_code = search(r"^.*civic-based country-code (.+)", conf, M) civic_based = {} civic_based["ca_info"] = civic_info_list civic_based["country_code"] = country_code.group(1).strip("'") diff --git a/plugins/module_utils/network/vyos/facts/logging_global/logging_global.py b/plugins/module_utils/network/vyos/facts/logging_global/logging_global.py index 5f9d65d..e0434d9 100644 --- a/plugins/module_utils/network/vyos/facts/logging_global/logging_global.py +++ b/plugins/module_utils/network/vyos/facts/logging_global/logging_global.py @@ -15,15 +15,14 @@ based on the configuration. """ from ansible.module_utils.six import iteritems -from ansible_collections.ansible.netcommon.plugins.module_utils.network.common import ( - utils, +from ansible_collections.ansible.netcommon.plugins.module_utils.network.common import utils + +from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.argspec.logging_global.logging_global import ( + Logging_globalArgs, ) from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.rm_templates.logging_global import ( Logging_globalTemplate, ) -from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.argspec.logging_global.logging_global import ( - Logging_globalArgs, -) class Logging_globalFacts(object): @@ -44,25 +43,19 @@ class Logging_globalFacts(object): for k, v in vl.items(): _files.append(v) objFinal[ke] = _files - objFinal[ke] = sorted( - objFinal[ke], key=lambda item: item["path"] - ) + objFinal[ke] = sorted(objFinal[ke], key=lambda item: item["path"]) elif ke == "hosts": _hosts = [] for k, v in vl.items(): _hosts.append(v) objFinal[ke] = _hosts - objFinal[ke] = sorted( - objFinal[ke], key=lambda item: item["hostname"] - ) + objFinal[ke] = sorted(objFinal[ke], key=lambda item: item["hostname"]) elif ke == "users": _users = [] for k, v in vl.items(): _users.append(v) objFinal[ke] = _users - objFinal[ke] = sorted( - objFinal[ke], key=lambda item: item["username"] - ) + objFinal[ke] = sorted(objFinal[ke], key=lambda item: item["username"]) elif ke == "console" or ke == "global_params": if objFinal[ke].get("facilities"): objFinal[ke]["facilities"] = sorted( @@ -88,17 +81,13 @@ class Logging_globalFacts(object): data = self.get_logging_data(connection) # parse native config using the Logging_global template - logging_global_parser = Logging_globalTemplate( - lines=data.splitlines(), module=self._module - ) + logging_global_parser = Logging_globalTemplate(lines=data.splitlines(), module=self._module) objs = logging_global_parser.parse() ansible_facts["ansible_network_resources"].pop("logging_global", None) objs = self.process_facts(objs) params = utils.remove_empties( - logging_global_parser.validate_config( - self.argument_spec, {"config": objs}, redact=True - ) + logging_global_parser.validate_config(self.argument_spec, {"config": objs}, redact=True) ) facts["logging_global"] = params.get("config", {}) diff --git a/plugins/module_utils/network/vyos/facts/ntp_global/ntp_global.py b/plugins/module_utils/network/vyos/facts/ntp_global/ntp_global.py index bb20e2d..cead241 100644 --- a/plugins/module_utils/network/vyos/facts/ntp_global/ntp_global.py +++ b/plugins/module_utils/network/vyos/facts/ntp_global/ntp_global.py @@ -5,7 +5,6 @@ from __future__ import absolute_import, division, print_function - __metaclass__ = type """ @@ -17,15 +16,14 @@ based on the configuration. import re -from ansible_collections.ansible.netcommon.plugins.module_utils.network.common import ( - utils, +from ansible_collections.ansible.netcommon.plugins.module_utils.network.common import utils + +from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.argspec.ntp_global.ntp_global import ( + Ntp_globalArgs, ) from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.rm_templates.ntp_global import ( NtpTemplate, ) -from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.argspec.ntp_global.ntp_global import ( - Ntp_globalArgs, -) class Ntp_globalFacts(object): @@ -67,9 +65,7 @@ class Ntp_globalFacts(object): objs["allow_clients"] = sorted(list(objs["allow_clients"])) if "listen_addresses" in objs: - objs["listen_addresses"] = sorted( - list(objs["listen_addresses"]) - ) + objs["listen_addresses"] = sorted(list(objs["listen_addresses"])) """ if "options" in objs["servers"].values(): val = objs["servers"].values() @@ -77,9 +73,7 @@ class Ntp_globalFacts(object): if "servers" in objs: objs["servers"] = list(objs["servers"].values()) - objs["servers"] = sorted( - objs["servers"], key=lambda k: k["server"] - ) + objs["servers"] = sorted(objs["servers"], key=lambda k: k["server"]) for i in objs["servers"]: if "options" in i: i["options"] = sorted(list(i["options"])) @@ -87,9 +81,7 @@ class Ntp_globalFacts(object): ansible_facts["ansible_network_resources"].pop("ntp_global", None) params = utils.remove_empties( - ntp_parser.validate_config( - self.argument_spec, {"config": objs}, redact=True - ) + ntp_parser.validate_config(self.argument_spec, {"config": objs}, redact=True) ) if params.get("config"): 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 4057db5..c89e2bd 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 @@ -16,15 +16,14 @@ based on the configuration. import re -from ansible_collections.ansible.netcommon.plugins.module_utils.network.common import ( - utils, +from ansible_collections.ansible.netcommon.plugins.module_utils.network.common import utils + +from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.argspec.ospf_interfaces.ospf_interfaces import ( + Ospf_interfacesArgs, ) from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.rm_templates.ospf_interfaces import ( Ospf_interfacesTemplate, ) -from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.argspec.ospf_interfaces.ospf_interfaces import ( - Ospf_interfacesArgs, -) class Ospf_interfacesFacts(object): @@ -35,9 +34,7 @@ class Ospf_interfacesFacts(object): self.argument_spec = Ospf_interfacesArgs.argument_spec def get_device_data(self, connection): - return connection.get( - 'show configuration commands | match "set interfaces"' - ) + return connection.get('show configuration commands | match "set interfaces"') def get_config_set(self, data): """To classify the configurations beased on interface""" @@ -69,9 +66,7 @@ class Ospf_interfacesFacts(object): """ facts = {} objs = [] - ospf_interfaces_parser = Ospf_interfacesTemplate( - lines=[], module=self._module - ) + ospf_interfaces_parser = Ospf_interfacesTemplate(lines=[], module=self._module) if not data: data = self.get_device_data(connection) diff --git a/plugins/module_utils/network/vyos/facts/ospfv2/ospfv2.py b/plugins/module_utils/network/vyos/facts/ospfv2/ospfv2.py index b0c9df2..4dcd546 100644 --- a/plugins/module_utils/network/vyos/facts/ospfv2/ospfv2.py +++ b/plugins/module_utils/network/vyos/facts/ospfv2/ospfv2.py @@ -13,11 +13,10 @@ from __future__ import absolute_import, division, print_function __metaclass__ = type -from re import findall, search, M from copy import deepcopy -from ansible_collections.ansible.netcommon.plugins.module_utils.network.common import ( - utils, -) +from re import M, findall, search + +from ansible_collections.ansible.netcommon.plugins.module_utils.network.common import utils from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.argspec.ospfv2.ospfv2 import ( Ospfv2Args, @@ -99,18 +98,10 @@ class Ospfv2Facts(object): config["route_map"] = self.parse_leaf_list(conf, "route-map") config["mpls_te"] = self.parse_attrib(conf, "mpls_te", "mpls-te") config["areas"] = self.parse_attrib_list(conf, "area", "area_id") - config["parameters"] = self.parse_attrib( - conf, "parameters", "parameters" - ) - config["neighbor"] = self.parse_attrib_list( - conf, "neighbor", "neighbor_id" - ) - config["passive_interface"] = self.parse_leaf_list( - conf, "passive-interface" - ) - config["redistribute"] = self.parse_attrib_list( - conf, "redistribute", "route_type" - ) + config["parameters"] = self.parse_attrib(conf, "parameters", "parameters") + config["neighbor"] = self.parse_attrib_list(conf, "neighbor", "neighbor_id") + config["passive_interface"] = self.parse_leaf_list(conf, "passive-interface") + config["redistribute"] = self.parse_attrib_list(conf, "redistribute", "route_type") config["passive_interface_exclude"] = self.parse_leaf_list( conf, "passive-interface-exclude" ) @@ -199,9 +190,7 @@ class Ospfv2Facts(object): """ cfg_dict = {} - cfg_dict["router_lsa"] = self.parse_attrib( - conf, "router_lsa", match="router-lsa" - ) + cfg_dict["router_lsa"] = self.parse_attrib(conf, "router_lsa", match="router-lsa") return cfg_dict def parse_auto_cost(self, conf, attrib=None): @@ -223,9 +212,7 @@ class Ospfv2Facts(object): """ cfg_dict = {} - cfg_dict["originate"] = self.parse_attrib( - conf, "originate", "originate" - ) + cfg_dict["originate"] = self.parse_attrib(conf, "originate", "originate") return cfg_dict def parse_area(self, conf, area_id): @@ -241,9 +228,7 @@ class Ospfv2Facts(object): "area_type": self.parse_area_type(conf, "area-type"), "network": self.parse_network(conf), "range": self.parse_attrib_list(conf, "range", "address"), - "virtual_link": self.parse_attrib_list( - conf, "virtual-link", "address" - ), + "virtual_link": self.parse_attrib_list(conf, "virtual-link", "address"), } rule.update(r_sub) return rule @@ -297,9 +282,7 @@ class Ospfv2Facts(object): """ rule = self.parse_attrib(conf, "vlink") - r_sub = { - "authentication": self.parse_authentication(conf, "authentication") - } + r_sub = {"authentication": self.parse_authentication(conf, "authentication")} rule.update(r_sub) return rule @@ -451,9 +434,7 @@ class Ospfv2Facts(object): else ( "enable" if attrib == "enabled" - else ( - "area" if attrib == "area_id" else attrib.replace("_", "-") - ) + else ("area" if attrib == "area_id" else attrib.replace("_", "-")) ) ) diff --git a/plugins/module_utils/network/vyos/facts/ospfv3/ospfv3.py b/plugins/module_utils/network/vyos/facts/ospfv3/ospfv3.py index 414c65e..121a348 100644 --- a/plugins/module_utils/network/vyos/facts/ospfv3/ospfv3.py +++ b/plugins/module_utils/network/vyos/facts/ospfv3/ospfv3.py @@ -13,11 +13,11 @@ from __future__ import absolute_import, division, print_function __metaclass__ = type -from re import findall, search, M from copy import deepcopy -from ansible_collections.ansible.netcommon.plugins.module_utils.network.common import ( - utils, -) +from re import M, findall, search + +from ansible_collections.ansible.netcommon.plugins.module_utils.network.common import utils + from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.argspec.ospfv3.ospfv3 import ( Ospfv3Args, ) @@ -75,13 +75,9 @@ class Ospfv3Facts(object): """ conf = "\n".join(filter(lambda x: x, conf)) config = {} - config["parameters"] = self.parse_attrib( - conf, "parameters", "parameters" - ) + config["parameters"] = self.parse_attrib(conf, "parameters", "parameters") config["areas"] = self.parse_attrib_list(conf, "area", "area_id") - config["redistribute"] = self.parse_attrib_list( - conf, "redistribute", "route_type" - ) + config["redistribute"] = self.parse_attrib_list(conf, "redistribute", "route_type") return config def parse_attrib_list(self, conf, attrib, param): diff --git a/plugins/module_utils/network/vyos/facts/prefix_lists/prefix_lists.py b/plugins/module_utils/network/vyos/facts/prefix_lists/prefix_lists.py index 15a2db9..19004c8 100644 --- a/plugins/module_utils/network/vyos/facts/prefix_lists/prefix_lists.py +++ b/plugins/module_utils/network/vyos/facts/prefix_lists/prefix_lists.py @@ -15,15 +15,14 @@ based on the configuration. """ -from ansible_collections.ansible.netcommon.plugins.module_utils.network.common import ( - utils, +from ansible_collections.ansible.netcommon.plugins.module_utils.network.common import utils + +from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.argspec.prefix_lists.prefix_lists import ( + Prefix_listsArgs, ) from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.rm_templates.prefix_lists import ( Prefix_listsTemplate, ) -from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.argspec.prefix_lists.prefix_lists import ( - Prefix_listsArgs, -) class Prefix_listsFacts(object): @@ -53,9 +52,7 @@ class Prefix_listsFacts(object): data = self.get_config(connection) # parse native config using the Prefix_lists template - prefix_lists_parser = Prefix_listsTemplate( - lines=data.splitlines(), module=self._module - ) + prefix_lists_parser = Prefix_listsTemplate(lines=data.splitlines(), module=self._module) objs = prefix_lists_parser.parse() objs = sorted( @@ -79,9 +76,7 @@ class Prefix_listsFacts(object): ansible_facts["ansible_network_resources"].pop("prefix_lists", None) params = utils.remove_empties( - prefix_lists_parser.validate_config( - self.argument_spec, {"config": objs}, redact=True - ) + prefix_lists_parser.validate_config(self.argument_spec, {"config": objs}, redact=True) ) if params.get("config"): diff --git a/plugins/module_utils/network/vyos/facts/route_maps/route_maps.py b/plugins/module_utils/network/vyos/facts/route_maps/route_maps.py index 51e8f97..9f53264 100644 --- a/plugins/module_utils/network/vyos/facts/route_maps/route_maps.py +++ b/plugins/module_utils/network/vyos/facts/route_maps/route_maps.py @@ -16,15 +16,14 @@ based on the configuration. from copy import deepcopy -from ansible_collections.ansible.netcommon.plugins.module_utils.network.common import ( - utils, +from ansible_collections.ansible.netcommon.plugins.module_utils.network.common import utils + +from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.argspec.route_maps.route_maps import ( + Route_mapsArgs, ) from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.rm_templates.route_maps import ( Route_mapsTemplate, ) -from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.argspec.route_maps.route_maps import ( - Route_mapsArgs, -) class Route_mapsFacts(object): @@ -73,9 +72,7 @@ class Route_mapsFacts(object): ansible_facts["ansible_network_resources"].pop("route_maps", None) # import epdb;epdb.serve() - params = utils.remove_empties( - utils.validate_config(self.argument_spec, {"config": objs}) - ) + params = utils.remove_empties(utils.validate_config(self.argument_spec, {"config": objs})) if params.get("config"): facts["route_maps"] = params["config"] diff --git a/plugins/module_utils/network/vyos/facts/snmp_server/snmp_server.py b/plugins/module_utils/network/vyos/facts/snmp_server/snmp_server.py index 2a9ba48..54339f5 100644 --- a/plugins/module_utils/network/vyos/facts/snmp_server/snmp_server.py +++ b/plugins/module_utils/network/vyos/facts/snmp_server/snmp_server.py @@ -14,17 +14,17 @@ for a given resource, parsed, and the facts tree is populated based on the configuration. """ +import re + from ansible.module_utils.six import iteritems -from ansible_collections.ansible.netcommon.plugins.module_utils.network.common import ( - utils, +from ansible_collections.ansible.netcommon.plugins.module_utils.network.common import utils + +from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.argspec.snmp_server.snmp_server import ( + Snmp_serverArgs, ) from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.rm_templates.snmp_server import ( Snmp_serverTemplate, ) -from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.argspec.snmp_server.snmp_server import ( - Snmp_serverArgs, -) -import re class Snmp_serverFacts(object): @@ -57,9 +57,7 @@ class Snmp_serverFacts(object): config_lines.append(re.sub("'", "", resource)) # parse native config using the Snmp_server template - snmp_server_parser = Snmp_serverTemplate( - lines=config_lines, module=self._module - ) + snmp_server_parser = Snmp_serverTemplate(lines=config_lines, module=self._module) objs = snmp_server_parser.parse() if objs: if "communities" in objs: @@ -106,9 +104,7 @@ class Snmp_serverFacts(object): ansible_facts["ansible_network_resources"].pop("snmp_server", None) params = utils.remove_empties( - snmp_server_parser.validate_config( - self.argument_spec, {"config": objs}, redact=True - ) + snmp_server_parser.validate_config(self.argument_spec, {"config": objs}, redact=True) ) facts["snmp_server"] = params.get("config", {}) diff --git a/plugins/module_utils/network/vyos/facts/static_routes/static_routes.py b/plugins/module_utils/network/vyos/facts/static_routes/static_routes.py index bce2731..019706b 100644 --- a/plugins/module_utils/network/vyos/facts/static_routes/static_routes.py +++ b/plugins/module_utils/network/vyos/facts/static_routes/static_routes.py @@ -13,11 +13,11 @@ based on the configuration. from __future__ import absolute_import, division, print_function __metaclass__ = type -from re import findall, search, M from copy import deepcopy -from ansible_collections.ansible.netcommon.plugins.module_utils.network.common import ( - utils, -) +from re import M, findall, search + +from ansible_collections.ansible.netcommon.plugins.module_utils.network.common import utils + from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.argspec.static_routes.static_routes import ( Static_routesArgs, ) @@ -63,9 +63,7 @@ class Static_routesFacts(object): r_v4 = [] r_v6 = [] af = [] - static_routes = findall( - r"set protocols static route(6)? (\S+)", data, M - ) + static_routes = findall(r"set protocols static route(6)? (\S+)", data, M) if static_routes: for route in set(static_routes): route_regex = r" %s .+$" % route[1] @@ -91,9 +89,7 @@ class Static_routesFacts(object): facts = {} if objs: facts["static_routes"] = [] - params = utils.validate_config( - self.argument_spec, {"config": objs} - ) + params = utils.validate_config(self.argument_spec, {"config": objs}) for cfg in params["config"]: facts["static_routes"].append(utils.remove_empties(cfg)) @@ -151,9 +147,7 @@ class Static_routesFacts(object): dis = hop.find("disable") hop_info = hop.split(" ") - nh_info = { - "forward_router_address": hop_info[0].strip("'") - } + nh_info = {"forward_router_address": hop_info[0].strip("'")} if interface: nh_info["interface"] = interface.group(1).strip("'") if distance: @@ -162,16 +156,11 @@ class Static_routesFacts(object): elif dis >= 1: nh_info["enabled"] = False for element in nh_list: - if ( - element["forward_router_address"] - == nh_info["forward_router_address"] - ): + if element["forward_router_address"] == nh_info["forward_router_address"]: if "interface" in nh_info.keys(): element["interface"] = nh_info["interface"] if "admin_distance" in nh_info.keys(): - element["admin_distance"] = nh_info[ - "admin_distance" - ] + element["admin_distance"] = nh_info["admin_distance"] if "enabled" in nh_info.keys(): element["enabled"] = nh_info["enabled"] nh_info = None diff --git a/plugins/module_utils/network/vyos/rm_templates/bgp_address_family.py b/plugins/module_utils/network/vyos/rm_templates/bgp_address_family.py index ddff1bb..b1bb27c 100644 --- a/plugins/module_utils/network/vyos/rm_templates/bgp_address_family.py +++ b/plugins/module_utils/network/vyos/rm_templates/bgp_address_family.py @@ -15,6 +15,7 @@ the given network resource. """ import re + from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.rm_base.network_template import ( NetworkTemplate, ) @@ -38,9 +39,7 @@ def _tmplt_bgp_af_aggregate_address(config_data): def _tmplt_bgp_af_redistribute_metric(config_data): if config_data["address_family"]["redistribute"].get("metric"): afi = config_data["address_family"]["afi"] + "-unicast" - command = "protocols bgp {as_number} address-family ".format( - **config_data - ) + command = "protocols bgp {as_number} address-family ".format(**config_data) if config_data["address_family"]["redistribute"].get("metric"): command += afi + " redistribute {protocol} metric {metric}".format( **config_data["address_family"]["redistribute"] @@ -51,15 +50,10 @@ def _tmplt_bgp_af_redistribute_metric(config_data): def _tmplt_bgp_af_redistribute_route_map(config_data): if config_data["address_family"]["redistribute"].get("route_map"): afi = config_data["address_family"]["afi"] + "-unicast" - command = "protocols bgp {as_number} address-family ".format( - **config_data - ) + command = "protocols bgp {as_number} address-family ".format(**config_data) if config_data["address_family"]["redistribute"].get("route_map"): - command += ( - afi - + " redistribute {protocol} route-map {route_map}".format( - **config_data["address_family"]["redistribute"] - ) + command += afi + " redistribute {protocol} route-map {route_map}".format( + **config_data["address_family"]["redistribute"] ) return command @@ -67,9 +61,7 @@ def _tmplt_bgp_af_redistribute_route_map(config_data): def _tmplt_bgp_af_redistribute_table(config_data): if config_data["address_family"]["redistribute"].get("table"): afi = config_data["address_family"]["afi"] + "-unicast" - command = "protocols bgp {as_number} address-family ".format( - **config_data - ) + command = "protocols bgp {as_number} address-family ".format(**config_data) if config_data["address_family"]["redistribute"].get("table"): command += afi + " table {table}".format( **config_data["address_family"]["redistribute"] @@ -81,9 +73,7 @@ def _tmplt_bgp_af_delete_redistribute(config_data): afi = config_data["address_family"]["afi"] + "-unicast" command = "protocols bgp {as_number} address-family ".format(**config_data) config_data = config_data["address_family"] - command += afi + " redistribute {protocol}".format( - **config_data["redistribute"] - ) + command += afi + " redistribute {protocol}".format(**config_data["redistribute"]) return command @@ -91,18 +81,11 @@ def _tmplt_bgp_af_neighbor_distribute_list(config_data): command = [] afi = config_data["neighbors"]["address_family"]["afi"] + "-unicast" cmd = "protocols bgp {as_number} neighbor ".format(**config_data) - cmd += "{neighbor_address} address-family ".format( - **config_data["neighbors"] - ) + cmd += "{neighbor_address} address-family ".format(**config_data["neighbors"]) config_data = config_data["neighbors"]["address_family"] for list_el in config_data["distribute_list"]: command.append( - cmd - + afi - + " distribute-list " - + list_el["action"] - + " " - + str(list_el["acl"]) + cmd + afi + " distribute-list " + list_el["action"] + " " + str(list_el["acl"]) ) return command @@ -111,18 +94,11 @@ def _tmplt_bgp_af_neighbor_route_map(config_data): command = [] afi = config_data["neighbors"]["address_family"]["afi"] + "-unicast" cmd = "protocols bgp {as_number} neighbor ".format(**config_data) - cmd += "{neighbor_address} address-family ".format( - **config_data["neighbors"] - ) + cmd += "{neighbor_address} address-family ".format(**config_data["neighbors"]) config_data = config_data["neighbors"]["address_family"] for list_el in config_data["route_map"]: command.append( - cmd - + afi - + " route-map " - + list_el["action"] - + " " - + str(list_el["route_map"]) + cmd + afi + " route-map " + list_el["action"] + " " + str(list_el["route_map"]) ) return command @@ -131,18 +107,11 @@ def _tmplt_bgp_af_neighbor_prefix_list(config_data): command = [] afi = config_data["neighbors"]["address_family"]["afi"] + "-unicast" cmd = "protocols bgp {as_number} neighbor ".format(**config_data) - cmd += "{neighbor_address} address-family ".format( - **config_data["neighbors"] - ) + cmd += "{neighbor_address} address-family ".format(**config_data["neighbors"]) config_data = config_data["neighbors"]["address_family"] for list_el in config_data["prefix_list"]: command.append( - cmd - + afi - + " prefix-list " - + list_el["action"] - + " " - + str(list_el["prefix_list"]) + cmd + afi + " prefix-list " + list_el["action"] + " " + str(list_el["prefix_list"]) ) return command @@ -151,18 +120,11 @@ def _tmplt_bgp_af_neighbor_filter_list(config_data): command = [] afi = config_data["neighbors"]["address_family"]["afi"] + "-unicast" cmd = "protocols bgp {as_number} neighbor ".format(**config_data) - cmd += "{neighbor_address} address-family ".format( - **config_data["neighbors"] - ) + cmd += "{neighbor_address} address-family ".format(**config_data["neighbors"]) config_data = config_data["neighbors"]["address_family"] for list_el in config_data["filter_list"]: command.append( - cmd - + afi - + " filter-list " - + list_el["action"] - + " " - + str(list_el["path_list"]) + cmd + afi + " filter-list " + list_el["action"] + " " + str(list_el["path_list"]) ) return command @@ -171,9 +133,7 @@ def _tmplt_bgp_af_neighbor_attribute(config_data): command = [] afi = config_data["neighbors"]["address_family"]["afi"] + "-unicast" cmd = "protocols bgp {as_number} neighbor ".format(**config_data) - cmd += "{neighbor_address} address-family ".format( - **config_data["neighbors"] - ) + cmd += "{neighbor_address} address-family ".format(**config_data["neighbors"]) config_data = config_data["neighbors"]["address_family"] for k in config_data["attribute_unchanged"].keys(): if config_data["attribute_unchanged"][k]: @@ -187,10 +147,7 @@ def _tmplt_bgp_af_neighbor_delete(config_data): afi = config_data["neighbors"]["address_family"]["afi"] + "-unicast" command = "protocols bgp {as_number} ".format(**config_data) command += ( - "neighbor {neighbor_address} address-family ".format( - **config_data["neighbors"] - ) - + afi + "neighbor {neighbor_address} address-family ".format(**config_data["neighbors"]) + afi ) config_data = config_data["neighbors"]["address_family"] if config_data.get("allowas_in"): @@ -238,10 +195,7 @@ def _tmplt_bgp_af_neighbor(config_data): afi = config_data["neighbors"]["address_family"]["afi"] + "-unicast" command = "protocols bgp {as_number} ".format(**config_data) command += ( - "neighbor {neighbor_address} address-family ".format( - **config_data["neighbors"] - ) - + afi + "neighbor {neighbor_address} address-family ".format(**config_data["neighbors"]) + afi ) config_data = config_data["neighbors"]["address_family"] if config_data.get("allowas_in"): @@ -255,9 +209,7 @@ def _tmplt_bgp_af_neighbor(config_data): elif config_data["capability"].get("orf"): command += " prefix-list {orf}".format(**config_data["capability"]) elif config_data.get("default_originate"): - command += " default-originate route-map {default_originate}".format( - **config_data - ) + command += " default-originate route-map {default_originate}".format(**config_data) elif config_data.get("maximum_prefix"): command += " maximum-prefix {maximum_prefix}".format(**config_data) elif config_data.get("nexthop_local"): diff --git a/plugins/module_utils/network/vyos/rm_templates/bgp_global.py b/plugins/module_utils/network/vyos/rm_templates/bgp_global.py index 0671ff7..0f7fd8b 100644 --- a/plugins/module_utils/network/vyos/rm_templates/bgp_global.py +++ b/plugins/module_utils/network/vyos/rm_templates/bgp_global.py @@ -15,8 +15,8 @@ the given network resource. """ import re -from ansible.module_utils.six import iteritems +from ansible.module_utils.six import iteritems from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.rm_base.network_template import ( NetworkTemplate, ) @@ -27,9 +27,7 @@ def _tmplt_bgp_params_confederation(config_data): for list_el in config_data["bgp_params"]["confederation"]: for k, v in iteritems(list_el): command.append( - "protocols bgp {as_number} parameters confederation ".format( - **config_data - ) + "protocols bgp {as_number} parameters confederation ".format(**config_data) + k + " " + str(v) @@ -51,17 +49,11 @@ def _tmplt_bgp_maximum_paths(config_data): def _tmplt_bgp_aggregate_address(config_data): - command = "protocols bgp {as_number} aggregate-address".format( - **config_data - ) + command = "protocols bgp {as_number} aggregate-address".format(**config_data) if config_data["aggregate_address"].get("as_set"): - command += " {prefix} as-set".format( - **config_data["aggregate_address"] - ) + command += " {prefix} as-set".format(**config_data["aggregate_address"]) if config_data["aggregate_address"].get("summary_only"): - command += " {prefix} summary-only".format( - **config_data["aggregate_address"] - ) + command += " {prefix} summary-only".format(**config_data["aggregate_address"]) return command @@ -71,15 +63,11 @@ def _tmplt_delete_bgp_maximum_paths(config_data): def _tmplt_bgp_params_default(config_data): - command = "protocols bgp {as_number} parameters default".format( - **config_data - ) + command = "protocols bgp {as_number} parameters default".format(**config_data) if config_data["bgp_params"]["default"].get("no_ipv4_unicast"): command += " no-ipv4-unicast" if config_data["bgp_params"]["default"].get("local_pref"): - command += " local-pref {local_pref}".format( - **config_data["bgp_params"]["default"] - ) + command += " local-pref {local_pref}".format(**config_data["bgp_params"]["default"]) return command @@ -110,11 +98,7 @@ def _tmplt_bgp_timers(config_data): command = [] for k, v in iteritems(config_data["timers"]): command.append( - "protocols bgp {as_number} ".format(**config_data) - + "timers " - + k - + " " - + str(v) + "protocols bgp {as_number} ".format(**config_data) + "timers " + k + " " + str(v) ) return command @@ -123,27 +107,21 @@ def _tmplt_bgp_timers(config_data): def _tmplt_bgp_neighbor_attribute_unchanged_as_path(config_data): command = "protocols bgp {as_number} ".format( **config_data - ) + "neighbor {address} attribute-unchanged as-path".format( - **config_data["neighbor"] - ) + ) + "neighbor {address} attribute-unchanged as-path".format(**config_data["neighbor"]) return command def _tmplt_bgp_neighbor_attribute_unchanged_med(config_data): command = "protocols bgp {as_number} ".format( **config_data - ) + "neighbor {address} attribute-unchanged med".format( - **config_data["neighbor"] - ) + ) + "neighbor {address} attribute-unchanged med".format(**config_data["neighbor"]) return command def _tmplt_bgp_neighbor_attribute_unchanged_next_hop(config_data): command = "protocols bgp {as_number} ".format( **config_data - ) + "neighbor {address} attribute-unchanged next-hop".format( - **config_data["neighbor"] - ) + ) + "neighbor {address} attribute-unchanged next-hop".format(**config_data["neighbor"]) return command @@ -152,9 +130,7 @@ def _tmplt_bgp_neighbor_distribute_list(config_data): for list_el in config_data["neighbor"]["distribute_list"]: command.append( "protocols bgp {as_number} ".format(**config_data) - + "neighbor {address} distribute-list ".format( - **config_data["neighbor"] - ) + + "neighbor {address} distribute-list ".format(**config_data["neighbor"]) + list_el["action"] + " " + str(list_el["acl"]) @@ -180,9 +156,7 @@ def _tmplt_bgp_neighbor_prefix_list(config_data): for list_el in config_data["neighbor"]["prefix_list"]: command.append( "protocols bgp {as_number} ".format(**config_data) - + "neighbor {address} prefix-list ".format( - **config_data["neighbor"] - ) + + "neighbor {address} prefix-list ".format(**config_data["neighbor"]) + list_el["action"] + " " + str(list_el["prefix_list"]) @@ -195,9 +169,7 @@ def _tmplt_bgp_neighbor_filter_list(config_data): for list_el in config_data["neighbor"]["filter_list"]: command.append( "protocols bgp {as_number} ".format(**config_data) - + "neighbor {address} filter-list ".format( - **config_data["neighbor"] - ) + + "neighbor {address} filter-list ".format(**config_data["neighbor"]) + list_el["action"] + " " + str(list_el["path_list"]) @@ -207,9 +179,7 @@ def _tmplt_bgp_neighbor_filter_list(config_data): def _tmplt_bgp_params_distance(config_data): command = ( - "protocols bgp {as_number} parameters distance global ".format( - **config_data - ) + "protocols bgp {as_number} parameters distance global ".format(**config_data) + config_data["bgp_params"]["distance"]["type"] + " " + str(config_data["bgp_params"]["distance"]["value"]) diff --git a/plugins/module_utils/network/vyos/rm_templates/hostname.py b/plugins/module_utils/network/vyos/rm_templates/hostname.py index 79caee6..7352794 100644 --- a/plugins/module_utils/network/vyos/rm_templates/hostname.py +++ b/plugins/module_utils/network/vyos/rm_templates/hostname.py @@ -15,6 +15,7 @@ the given network resource. """ import re + from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.rm_base.network_template import ( NetworkTemplate, ) diff --git a/plugins/module_utils/network/vyos/rm_templates/logging_global.py b/plugins/module_utils/network/vyos/rm_templates/logging_global.py index 8cfe7a6..82a4963 100644 --- a/plugins/module_utils/network/vyos/rm_templates/logging_global.py +++ b/plugins/module_utils/network/vyos/rm_templates/logging_global.py @@ -15,6 +15,7 @@ the given network resource. """ import re + from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.rm_base.network_template import ( NetworkTemplate, ) @@ -43,21 +44,13 @@ def tmplt_params(config_data): elif config_data.get("users"): val = config_data.get("users") if val.get("username") and not val.get("archive"): - tmplt += "system syslog user {username}".format( - username=val["username"] - ) + tmplt += "system syslog user {username}".format(username=val["username"]) if val.get("facilities"): tmplt = templt_common(val.get("facilities"), tmplt) elif config_data.get("hosts"): val = config_data.get("hosts") - if ( - val.get("hostname") - and not val.get("archive") - and not val.get("port") - ): - tmplt += "system syslog host {hostname}".format( - hostname=val["hostname"] - ) + if val.get("hostname") and not val.get("archive") and not val.get("port"): + tmplt += "system syslog host {hostname}".format(hostname=val["hostname"]) if val.get("facilities"): tmplt = templt_common(val.get("facilities"), tmplt) elif config_data.get("files"): diff --git a/plugins/module_utils/network/vyos/rm_templates/ntp_global.py b/plugins/module_utils/network/vyos/rm_templates/ntp_global.py index f4589a2..5254035 100644 --- a/plugins/module_utils/network/vyos/rm_templates/ntp_global.py +++ b/plugins/module_utils/network/vyos/rm_templates/ntp_global.py @@ -15,6 +15,7 @@ the given network resource. """ import re + from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.rm_base.network_template import ( NetworkTemplate, ) @@ -23,9 +24,7 @@ from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.r class NtpTemplate(NetworkTemplate): def __init__(self, lines=None, module=None): prefix = {"set": "set", "remove": "delete"} - super(NtpTemplate, self).__init__( - lines=lines, tmplt=self, prefix=prefix, module=module - ) + super(NtpTemplate, self).__init__(lines=lines, tmplt=self, prefix=prefix, module=module) # fmt: off PARSERS = [ diff --git a/plugins/module_utils/network/vyos/rm_templates/ospf_interfaces.py b/plugins/module_utils/network/vyos/rm_templates/ospf_interfaces.py index bda17df..de3beba 100644 --- a/plugins/module_utils/network/vyos/rm_templates/ospf_interfaces.py +++ b/plugins/module_utils/network/vyos/rm_templates/ospf_interfaces.py @@ -15,6 +15,7 @@ the given network resource. """ import re + from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.rm_base.network_template import ( NetworkTemplate, ) @@ -36,12 +37,7 @@ def _tmplt_ospf_int_delete(config_data): int_type = get_interface_type(config_data["name"]) params = _get_parameters(config_data["address_family"]) command = ( - "interfaces " - + int_type - + " {name} ".format(**config_data) - + params[1] - + " " - + params[0] + "interfaces " + int_type + " {name} ".format(**config_data) + params[1] + " " + params[0] ) return command @@ -93,9 +89,7 @@ def _tmplt_ospf_int_auth_md5(config_data): + " authentication md5 key-id {key_id} ".format( **config_data["address_family"]["authentication"]["md5_key"] ) - + "md5-key {key}".format( - **config_data["address_family"]["authentication"]["md5_key"] - ) + + "md5-key {key}".format(**config_data["address_family"]["authentication"]["md5_key"]) ) return command @@ -143,9 +137,7 @@ def _tmplt_ospf_int_hello_interval(config_data): + params[1] + " " + params[0] - + " hello-interval {hello_interval}".format( - **config_data["address_family"] - ) + + " hello-interval {hello_interval}".format(**config_data["address_family"]) ) return command @@ -161,9 +153,7 @@ def _tmplt_ospf_int_dead_interval(config_data): + params[1] + " " + params[0] - + " dead-interval {dead_interval}".format( - **config_data["address_family"] - ) + + " dead-interval {dead_interval}".format(**config_data["address_family"]) ) return command @@ -227,9 +217,7 @@ def _tmplt_ospf_int_retransmit_interval(config_data): + params[1] + " " + params[0] - + " retransmit-interval {retransmit_interval}".format( - **config_data["address_family"] - ) + + " retransmit-interval {retransmit_interval}".format(**config_data["address_family"]) ) return command @@ -245,9 +233,7 @@ def _tmplt_ospf_int_transmit_delay(config_data): + params[1] + " " + params[0] - + " transmit-delay {transmit_delay}".format( - **config_data["address_family"] - ) + + " transmit-delay {transmit_delay}".format(**config_data["address_family"]) ) return command diff --git a/plugins/module_utils/network/vyos/rm_templates/prefix_lists.py b/plugins/module_utils/network/vyos/rm_templates/prefix_lists.py index 9a66a8d..00a157e 100644 --- a/plugins/module_utils/network/vyos/rm_templates/prefix_lists.py +++ b/plugins/module_utils/network/vyos/rm_templates/prefix_lists.py @@ -15,6 +15,7 @@ the given network resource. """ import re + from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.rm_base.network_template import ( NetworkTemplate, ) diff --git a/plugins/module_utils/network/vyos/rm_templates/route_maps.py b/plugins/module_utils/network/vyos/rm_templates/route_maps.py index 262721e..1652a23 100644 --- a/plugins/module_utils/network/vyos/rm_templates/route_maps.py +++ b/plugins/module_utils/network/vyos/rm_templates/route_maps.py @@ -15,6 +15,7 @@ the given network resource. """ import re + from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.rm_base.network_template import ( NetworkTemplate, ) @@ -23,9 +24,7 @@ from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.r class Route_mapsTemplate(NetworkTemplate): def __init__(self, lines=None): prefix = {"set": "set", "remove": "delete"} - super(Route_mapsTemplate, self).__init__( - lines=lines, tmplt=self, prefix=prefix - ) + super(Route_mapsTemplate, self).__init__(lines=lines, tmplt=self, prefix=prefix) # fmt: off PARSERS = [ diff --git a/plugins/module_utils/network/vyos/rm_templates/snmp_server.py b/plugins/module_utils/network/vyos/rm_templates/snmp_server.py index c1e385a..15a0804 100644 --- a/plugins/module_utils/network/vyos/rm_templates/snmp_server.py +++ b/plugins/module_utils/network/vyos/rm_templates/snmp_server.py @@ -15,6 +15,7 @@ the given network resource. """ import re + from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.rm_base.network_template import ( NetworkTemplate, ) @@ -25,9 +26,7 @@ def _tmplt_snmp_server_communities(config_data): command = [] cmd = "service snmp community {name}".format(**config_data) if "authorization_type" in config_data: - auth_cmd = cmd + " authorization {authorization_type}".format( - **config_data - ) + auth_cmd = cmd + " authorization {authorization_type}".format(**config_data) command.append(auth_cmd) if "clients" in config_data: for c in config_data["clients"]: @@ -103,18 +102,10 @@ def _tmplt_snmp_server_v3_user(config_data): type_cmd = cmd + val + " type {type}".format(**config) command.append(type_cmd) if "encrypted_key" in config: - enc_cmd = ( - cmd - + val - + " encrypted-key {encrypted_key}".format(**config) - ) + enc_cmd = cmd + val + " encrypted-key {encrypted_key}".format(**config) command.append(enc_cmd) if "plaintext_key" in config: - plain_cmd = ( - cmd - + val - + " plaintext-key {plaintext_key}".format(**config) - ) + plain_cmd = cmd + val + " plaintext-key {plaintext_key}".format(**config) command.append(plain_cmd) return command diff --git a/plugins/module_utils/network/vyos/utils/utils.py b/plugins/module_utils/network/vyos/utils/utils.py index 43f3fc9..4d44744 100644 --- a/plugins/module_utils/network/vyos/utils/utils.py +++ b/plugins/module_utils/network/vyos/utils/utils.py @@ -7,8 +7,8 @@ from __future__ import absolute_import, division, print_function __metaclass__ = type -from ansible.module_utils.six import iteritems from ansible.module_utils.basic import missing_required_lib +from ansible.module_utils.six import iteritems try: import ipaddress @@ -112,11 +112,7 @@ def get_lst_same_for_dicts(want, have, lst): if want and have: want_list = want.get(lst) or {} have_list = have.get(lst) or {} - diff = [ - i - for i in want_list and have_list - if i in have_list and i in want_list - ] + diff = [i for i in want_list and have_list if i in have_list and i in want_list] return diff @@ -133,11 +129,7 @@ def list_diff_have_only(want_list, have_list): elif not have_list: diff = None else: - diff = [ - i - for i in have_list + want_list - if i in have_list and i not in want_list - ] + diff = [i for i in have_list + want_list if i in have_list and i not in want_list] return diff @@ -154,11 +146,7 @@ def list_diff_want_only(want_list, have_list): elif not have_list: diff = want_list else: - diff = [ - i - for i in have_list + want_list - if i in want_list and i not in have_list - ] + diff = [i for i in have_list + want_list if i in want_list and i not in have_list] return diff @@ -173,11 +161,7 @@ def search_dict_tv_in_list(d_val1, d_val2, lst, key1, key2): :return: """ obj = next( - ( - item - for item in lst - if item[key1] == d_val1 and item[key2] == d_val2 - ), + (item for item in lst if item[key1] == d_val1 and item[key2] == d_val2), None, ) if obj: @@ -249,13 +233,7 @@ def _bool_to_str(val): :param val: bool value. :return: enable/disable. """ - return ( - "enable" - if str(val) == "True" - else "disable" - if str(val) == "False" - else val - ) + return "enable" if str(val) == "True" else "disable" if str(val) == "False" else val def _is_w_same(w, h, key): diff --git a/plugins/module_utils/network/vyos/vyos.py b/plugins/module_utils/network/vyos/vyos.py index 42fc57c..da364f9 100644 --- a/plugins/module_utils/network/vyos/vyos.py +++ b/plugins/module_utils/network/vyos/vyos.py @@ -83,9 +83,7 @@ def get_config(module, flags=None, format=None): def run_commands(module, commands, check_rc=True): connection = get_connection(module) try: - response = connection.run_commands( - commands=commands, check_rc=check_rc - ) + response = connection.run_commands(commands=commands, check_rc=check_rc) except ConnectionError as exc: module.fail_json(msg=to_text(exc, errors="surrogate_then_replace")) return response @@ -95,9 +93,7 @@ def load_config(module, commands, commit=False, comment=None): connection = get_connection(module) try: - response = connection.edit_config( - candidate=commands, commit=commit, comment=comment - ) + response = connection.edit_config(candidate=commands, commit=commit, comment=comment) except ConnectionError as exc: module.fail_json(msg=to_text(exc, errors="surrogate_then_replace")) diff --git a/plugins/modules/vyos_banner.py b/plugins/modules/vyos_banner.py index a5f3fb9..0ee10f5 100644 --- a/plugins/modules/vyos_banner.py +++ b/plugins/modules/vyos_banner.py @@ -91,6 +91,7 @@ commands: import re from ansible.module_utils.basic import AnsibleModule + from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.vyos import ( get_config, load_config, @@ -104,21 +105,13 @@ def spec_to_commands(updates, module): if state == "absent": if have.get("state") != "absent" or ( - have.get("state") != "absent" - and "text" in have.keys() - and have["text"] + have.get("state") != "absent" and "text" in have.keys() and have["text"] ): - commands.append( - "delete system login banner %s" % module.params["banner"] - ) + commands.append("delete system login banner %s" % module.params["banner"]) elif state == "present": - if want["text"] and want["text"].encode().decode( - "unicode_escape" - ) != have.get("text"): - banner_cmd = ( - "set system login banner %s " % module.params["banner"] - ) + if want["text"] and want["text"].encode().decode("unicode_escape") != have.get("text"): + banner_cmd = "set system login banner %s " % module.params["banner"] banner_cmd += want["text"].strip() commands.append(banner_cmd) diff --git a/plugins/modules/vyos_bgp_address_family.py b/plugins/modules/vyos_bgp_address_family.py index ab98e3b..ba56309 100644 --- a/plugins/modules/vyos_bgp_address_family.py +++ b/plugins/modules/vyos_bgp_address_family.py @@ -1163,6 +1163,7 @@ EXAMPLES = """ """ from ansible.module_utils.basic import AnsibleModule + from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.argspec.bgp_address_family.bgp_address_family import ( Bgp_address_familyArgs, ) diff --git a/plugins/modules/vyos_bgp_global.py b/plugins/modules/vyos_bgp_global.py index 49e0a72..1e3578d 100644 --- a/plugins/modules/vyos_bgp_global.py +++ b/plugins/modules/vyos_bgp_global.py @@ -1411,6 +1411,7 @@ EXAMPLES = """ """ from ansible.module_utils.basic import AnsibleModule + from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.argspec.bgp_global.bgp_global import ( Bgp_globalArgs, ) diff --git a/plugins/modules/vyos_command.py b/plugins/modules/vyos_command.py index d5ab918..94f16f3 100644 --- a/plugins/modules/vyos_command.py +++ b/plugins/modules/vyos_command.py @@ -148,13 +148,12 @@ from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.p Conditional, ) from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.utils import ( - transform_commands, to_lines, -) -from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.vyos import ( - run_commands, + transform_commands, ) +from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.vyos import run_commands + def parse_commands(module, warnings): commands = transform_commands(module) @@ -216,9 +215,7 @@ def main(): msg = "One or more conditional statements have not been satisfied" module.fail_json(msg=msg, failed_conditions=failed_conditions) - result.update( - {"stdout": responses, "stdout_lines": list(to_lines(responses))} - ) + result.update({"stdout": responses, "stdout_lines": list(to_lines(responses))}) module.exit_json(**result) diff --git a/plugins/modules/vyos_config.py b/plugins/modules/vyos_config.py index 4b2b31d..2a03d0c 100644 --- a/plugins/modules/vyos_config.py +++ b/plugins/modules/vyos_config.py @@ -197,21 +197,17 @@ import re from ansible.module_utils._text import to_text from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.connection import ConnectionError + from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.vyos import ( - load_config, get_config, - run_commands, -) -from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.vyos import ( get_connection, + load_config, + run_commands, ) - DEFAULT_COMMENT = "configured by vyos_config" -CONFIG_FILTERS = [ - re.compile(r"set system login user \S+ authentication encrypted-password") -] +CONFIG_FILTERS = [re.compile(r"set system login user \S+ authentication encrypted-password")] def get_candidate(module): @@ -316,8 +312,7 @@ def run(module, result): if result.get("filtered"): result["warnings"].append( - "Some configuration commands were " - "removed, please see the filtered key" + "Some configuration commands were removed, please see the filtered key" ) result["changed"] = True @@ -365,9 +360,7 @@ def main(): result["changed"] = True run_commands(module, commands=["exit"]) - if result.get("changed") and any( - (module.params["src"], module.params["lines"]) - ): + if result.get("changed") and any((module.params["src"], module.params["lines"])): msg = ( "To ensure idempotency and correct diff the input configuration lines should be" " similar to how they appear if present in" diff --git a/plugins/modules/vyos_facts.py b/plugins/modules/vyos_facts.py index 5e57821..ae7543c 100644 --- a/plugins/modules/vyos_facts.py +++ b/plugins/modules/vyos_facts.py @@ -139,12 +139,13 @@ ansible_net_gather_network_resources: """ from ansible.module_utils.basic import AnsibleModule + from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.argspec.facts.facts import ( FactsArgs, ) from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.facts import ( - Facts, FACT_RESOURCE_SUBSETS, + Facts, ) @@ -156,17 +157,13 @@ def main(): """ argument_spec = FactsArgs.argument_spec - module = AnsibleModule( - argument_spec=argument_spec, supports_check_mode=True - ) + module = AnsibleModule(argument_spec=argument_spec, supports_check_mode=True) warnings = [] ansible_facts = {} if module.params.get("available_network_resources"): - ansible_facts["available_network_resources"] = sorted( - FACT_RESOURCE_SUBSETS.keys() - ) + ansible_facts["available_network_resources"] = sorted(FACT_RESOURCE_SUBSETS.keys()) result = Facts(module).get_facts() additional_facts, additional_warnings = result ansible_facts.update(additional_facts) diff --git a/plugins/modules/vyos_firewall_global.py b/plugins/modules/vyos_firewall_global.py index 02f4f60..78db9f3 100644 --- a/plugins/modules/vyos_firewall_global.py +++ b/plugins/modules/vyos_firewall_global.py @@ -1185,6 +1185,7 @@ commands: from ansible.module_utils.basic import AnsibleModule + from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.argspec.firewall_global.firewall_global import ( Firewall_globalArgs, ) diff --git a/plugins/modules/vyos_firewall_interfaces.py b/plugins/modules/vyos_firewall_interfaces.py index 7ca936d..32ad09f 100644 --- a/plugins/modules/vyos_firewall_interfaces.py +++ b/plugins/modules/vyos_firewall_interfaces.py @@ -1251,6 +1251,7 @@ commands: from ansible.module_utils.basic import AnsibleModule + from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.argspec.firewall_interfaces.firewall_interfaces import ( Firewall_interfacesArgs, ) diff --git a/plugins/modules/vyos_firewall_rules.py b/plugins/modules/vyos_firewall_rules.py index 9730c4a..c219f54 100644 --- a/plugins/modules/vyos_firewall_rules.py +++ b/plugins/modules/vyos_firewall_rules.py @@ -1486,6 +1486,7 @@ commands: from ansible.module_utils.basic import AnsibleModule + from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.argspec.firewall_rules.firewall_rules import ( Firewall_rulesArgs, ) diff --git a/plugins/modules/vyos_hostname.py b/plugins/modules/vyos_hostname.py index da22f41..46b692a 100644 --- a/plugins/modules/vyos_hostname.py +++ b/plugins/modules/vyos_hostname.py @@ -249,6 +249,7 @@ parsed: """ from ansible.module_utils.basic import AnsibleModule + from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.argspec.hostname.hostname import ( HostnameArgs, ) diff --git a/plugins/modules/vyos_interfaces.py b/plugins/modules/vyos_interfaces.py index 4429e4b..47ff604 100644 --- a/plugins/modules/vyos_interfaces.py +++ b/plugins/modules/vyos_interfaces.py @@ -1097,6 +1097,7 @@ commands: from ansible.module_utils.basic import AnsibleModule + from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.argspec.interfaces.interfaces import ( InterfacesArgs, ) diff --git a/plugins/modules/vyos_l3_interfaces.py b/plugins/modules/vyos_l3_interfaces.py index 7ec9e2a..cdf5842 100644 --- a/plugins/modules/vyos_l3_interfaces.py +++ b/plugins/modules/vyos_l3_interfaces.py @@ -537,6 +537,7 @@ commands: from ansible.module_utils.basic import AnsibleModule + from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.argspec.l3_interfaces.l3_interfaces import ( L3_interfacesArgs, ) diff --git a/plugins/modules/vyos_lag_interfaces.py b/plugins/modules/vyos_lag_interfaces.py index a530789..fb36592 100644 --- a/plugins/modules/vyos_lag_interfaces.py +++ b/plugins/modules/vyos_lag_interfaces.py @@ -743,6 +743,7 @@ commands: from ansible.module_utils.basic import AnsibleModule + from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.argspec.lag_interfaces.lag_interfaces import ( Lag_interfacesArgs, ) diff --git a/plugins/modules/vyos_lldp_global.py b/plugins/modules/vyos_lldp_global.py index 192aa7f..f59327a 100644 --- a/plugins/modules/vyos_lldp_global.py +++ b/plugins/modules/vyos_lldp_global.py @@ -467,6 +467,7 @@ commands: from ansible.module_utils.basic import AnsibleModule + from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.argspec.lldp_global.lldp_global import ( Lldp_globalArgs, ) diff --git a/plugins/modules/vyos_lldp_interfaces.py b/plugins/modules/vyos_lldp_interfaces.py index 43ff75c..9260cb6 100644 --- a/plugins/modules/vyos_lldp_interfaces.py +++ b/plugins/modules/vyos_lldp_interfaces.py @@ -635,6 +635,7 @@ commands: from ansible.module_utils.basic import AnsibleModule + from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.argspec.lldp_interfaces.lldp_interfaces import ( Lldp_interfacesArgs, ) diff --git a/plugins/modules/vyos_logging.py b/plugins/modules/vyos_logging.py index 4b3eaaf..7e1dea7 100644 --- a/plugins/modules/vyos_logging.py +++ b/plugins/modules/vyos_logging.py @@ -153,7 +153,6 @@ commands: """ import re - from copy import deepcopy from ansible.module_utils._text import to_text @@ -162,6 +161,7 @@ from ansible.module_utils.common.validation import check_required_if from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.utils import ( remove_default_spec, ) + from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.vyos import ( get_config, load_config, @@ -189,9 +189,7 @@ def spec_to_commands(updates, module): ) else: commands.append( - "delete system syslog {0} facility {1} level {2}".format( - dest, facility, level - ) + "delete system syslog {0} facility {1} level {2}".format(dest, facility, level) ) elif state == "present" and w not in have: if w["name"]: @@ -202,9 +200,7 @@ def spec_to_commands(updates, module): ) else: commands.append( - "set system syslog {0} facility {1} level {2}".format( - dest, facility, level - ) + "set system syslog {0} facility {1} level {2}".format(dest, facility, level) ) return commands @@ -285,9 +281,7 @@ def map_params_to_obj(module, required_if=None): def main(): """main entry point for module execution""" element_spec = dict( - dest=dict( - type="str", choices=["console", "file", "global", "host", "user"] - ), + dest=dict(type="str", choices=["console", "file", "global", "host", "user"]), name=dict(type="str"), facility=dict(type="str"), level=dict(type="str"), @@ -299,9 +293,7 @@ def main(): # remove default in aggregate spec, to handle common arguments remove_default_spec(aggregate_spec) - argument_spec = dict( - aggregate=dict(type="list", elements="dict", options=aggregate_spec) - ) + argument_spec = dict(aggregate=dict(type="list", elements="dict", options=aggregate_spec)) argument_spec.update(element_spec) diff --git a/plugins/modules/vyos_logging_global.py b/plugins/modules/vyos_logging_global.py index 6a4e2dd..18248d6 100644 --- a/plugins/modules/vyos_logging_global.py +++ b/plugins/modules/vyos_logging_global.py @@ -741,6 +741,7 @@ parsed: """ from ansible.module_utils.basic import AnsibleModule + from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.argspec.logging_global.logging_global import ( Logging_globalArgs, ) diff --git a/plugins/modules/vyos_ntp_global.py b/plugins/modules/vyos_ntp_global.py index d06d878..10a2170 100644 --- a/plugins/modules/vyos_ntp_global.py +++ b/plugins/modules/vyos_ntp_global.py @@ -780,6 +780,7 @@ parsed: from ansible.module_utils.basic import AnsibleModule + from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.argspec.ntp_global.ntp_global import ( Ntp_globalArgs, ) diff --git a/plugins/modules/vyos_ospf_interfaces.py b/plugins/modules/vyos_ospf_interfaces.py index 61ef32e..9a78ebd 100644 --- a/plugins/modules/vyos_ospf_interfaces.py +++ b/plugins/modules/vyos_ospf_interfaces.py @@ -888,6 +888,7 @@ EXAMPLES = """ """ from ansible.module_utils.basic import AnsibleModule + from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.argspec.ospf_interfaces.ospf_interfaces import ( Ospf_interfacesArgs, ) diff --git a/plugins/modules/vyos_ospfv2.py b/plugins/modules/vyos_ospfv2.py index 43b0675..863bc6f 100644 --- a/plugins/modules/vyos_ospfv2.py +++ b/plugins/modules/vyos_ospfv2.py @@ -1782,6 +1782,7 @@ commands: from ansible.module_utils.basic import AnsibleModule + from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.argspec.ospfv2.ospfv2 import ( Ospfv2Args, ) diff --git a/plugins/modules/vyos_ospfv3.py b/plugins/modules/vyos_ospfv3.py index 8942cef..4ff6106 100644 --- a/plugins/modules/vyos_ospfv3.py +++ b/plugins/modules/vyos_ospfv3.py @@ -631,6 +631,7 @@ commands: from ansible.module_utils.basic import AnsibleModule + from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.argspec.ospfv3.ospfv3 import ( Ospfv3Args, ) diff --git a/plugins/modules/vyos_ping.py b/plugins/modules/vyos_ping.py index 7934583..8c0330d 100644 --- a/plugins/modules/vyos_ping.py +++ b/plugins/modules/vyos_ping.py @@ -134,12 +134,12 @@ rtt: sample: {"avg": 2, "max": 8, "min": 1, "mdev": 24} """ -from ansible.module_utils.basic import AnsibleModule -from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.vyos import ( - run_commands, -) import re +from ansible.module_utils.basic import AnsibleModule + +from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.vyos import run_commands + def main(): """main entry point for module execution""" @@ -150,9 +150,7 @@ def main(): ttl=dict(type="int"), size=dict(type="int"), interval=dict(type="int"), - state=dict( - type="str", choices=["absent", "present"], default="present" - ), + state=dict(type="str", choices=["absent", "present"], default="present"), ) module = AnsibleModule(argument_spec=argument_spec) @@ -170,9 +168,7 @@ def main(): if warnings: results["warnings"] = warnings - results["commands"] = [ - build_ping(dest, count, size, interval, source, ttl) - ] + results["commands"] = [build_ping(dest, count, size, interval, source, ttl)] ping_results = run_commands(module, commands=results["commands"]) ping_results_list = ping_results[0].split("\n") diff --git a/plugins/modules/vyos_prefix_lists.py b/plugins/modules/vyos_prefix_lists.py index 8b67caf..ed190d4 100644 --- a/plugins/modules/vyos_prefix_lists.py +++ b/plugins/modules/vyos_prefix_lists.py @@ -1294,6 +1294,7 @@ parsed: from ansible.module_utils.basic import AnsibleModule + from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.argspec.prefix_lists.prefix_lists import ( Prefix_listsArgs, ) diff --git a/plugins/modules/vyos_route_maps.py b/plugins/modules/vyos_route_maps.py index 27fac07..d49261c 100644 --- a/plugins/modules/vyos_route_maps.py +++ b/plugins/modules/vyos_route_maps.py @@ -918,6 +918,7 @@ EXAMPLES = """ """ from ansible.module_utils.basic import AnsibleModule + from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.argspec.route_maps.route_maps import ( Route_mapsArgs, ) diff --git a/plugins/modules/vyos_snmp_server.py b/plugins/modules/vyos_snmp_server.py index 1651226..74bae3f 100644 --- a/plugins/modules/vyos_snmp_server.py +++ b/plugins/modules/vyos_snmp_server.py @@ -1093,6 +1093,7 @@ parsed: """ from ansible.module_utils.basic import AnsibleModule + from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.argspec.snmp_server.snmp_server import ( Snmp_serverArgs, ) diff --git a/plugins/modules/vyos_static_routes.py b/plugins/modules/vyos_static_routes.py index 09105ef..0761599 100644 --- a/plugins/modules/vyos_static_routes.py +++ b/plugins/modules/vyos_static_routes.py @@ -900,6 +900,7 @@ commands: from ansible.module_utils.basic import AnsibleModule + from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.argspec.static_routes.static_routes import ( Static_routesArgs, ) diff --git a/plugins/modules/vyos_system.py b/plugins/modules/vyos_system.py index fd98507..66a3fd4 100644 --- a/plugins/modules/vyos_system.py +++ b/plugins/modules/vyos_system.py @@ -95,6 +95,7 @@ EXAMPLES = """ """ from ansible.module_utils.basic import AnsibleModule + from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.vyos import ( get_config, load_config, @@ -155,13 +156,9 @@ def spec_to_commands(want, have): commands.append("delete system %s" % device_key) for config in proposed: if state == "absent" and config in current: - commands.append( - "delete system %s '%s'" % (device_key, config) - ) + commands.append("delete system %s '%s'" % (device_key, config)) elif state == "present" and config not in current: - commands.append( - "set system %s '%s'" % (device_key, config) - ) + commands.append("set system %s '%s'" % (device_key, config)) else: if state == "absent" and current and proposed: commands.append("delete system %s" % device_key) @@ -186,12 +183,8 @@ def main(): host_name=dict(type="str"), domain_name=dict(type="str"), domain_search=dict(type="list", elements="str"), - name_server=dict( - type="list", aliases=["name_servers"], elements="str" - ), - state=dict( - type="str", default="present", choices=["present", "absent"] - ), + name_server=dict(type="list", aliases=["name_servers"], elements="str"), + state=dict(type="str", default="present", choices=["present", "absent"]), ) module = AnsibleModule( diff --git a/plugins/modules/vyos_user.py b/plugins/modules/vyos_user.py index b2e1acc..5494df3 100644 --- a/plugins/modules/vyos_user.py +++ b/plugins/modules/vyos_user.py @@ -181,26 +181,24 @@ commands: """ import re - from copy import deepcopy from functools import partial from ansible.module_utils.basic import AnsibleModule +from ansible.module_utils.six import iteritems from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.utils import ( remove_default_spec, ) + from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.vyos import ( get_config, load_config, ) -from ansible.module_utils.six import iteritems def validate_level(value, module): if value not in ("admin", "operator"): - module.fail_json( - msg="level must be either admin or operator, got %s" % value - ) + module.fail_json(msg="level must be either admin or operator, got %s" % value) def spec_to_commands(updates, module): @@ -231,8 +229,7 @@ def spec_to_commands(updates, module): add( commands, want, - "authentication plaintext-password %s" - % want["configured_password"], + "authentication plaintext-password %s" % want["configured_password"], ) return commands @@ -338,9 +335,7 @@ def main(): full_name=dict(), level=dict(aliases=["role"]), configured_password=dict(no_log=True), - update_password=dict( - default="always", choices=["on_create", "always"] - ), + update_password=dict(default="always", choices=["on_create", "always"]), state=dict(default="present", choices=["present", "absent"]), ) diff --git a/plugins/modules/vyos_vlan.py b/plugins/modules/vyos_vlan.py index 8325366..de20d87 100644 --- a/plugins/modules/vyos_vlan.py +++ b/plugins/modules/vyos_vlan.py @@ -164,7 +164,6 @@ commands: """ import re import time - from copy import deepcopy from ansible.module_utils._text import to_text @@ -173,6 +172,7 @@ from ansible.module_utils.common.validation import check_required_one_of from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.utils import ( remove_default_spec, ) + from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.vyos import ( load_config, run_commands, @@ -204,27 +204,17 @@ def map_obj_to_commands(updates, module): if obj_in_have: for obj in obj_in_have: for i in obj["interfaces"]: - commands.append( - "delete interfaces ethernet {0} vif {1}".format( - i, vlan_id - ) - ) + commands.append("delete interfaces ethernet {0} vif {1}".format(i, vlan_id)) elif state == "present": if not obj_in_have: if w["interfaces"] and w["vlan_id"]: for i in w["interfaces"]: - cmd = "set interfaces ethernet {0} vif {1}".format( - i, vlan_id - ) + cmd = "set interfaces ethernet {0} vif {1}".format(i, vlan_id) if w["name"]: - commands.append( - cmd + " description {0}".format(name) - ) + commands.append(cmd + " description {0}".format(name)) elif w["address"]: - commands.append( - cmd + " address {0}".format(address) - ) + commands.append(cmd + " address {0}".format(address)) else: commands.append(cmd) @@ -234,9 +224,7 @@ def map_obj_to_commands(updates, module): if not obj_in_want: for i in h["interfaces"]: commands.append( - "delete interfaces ethernet {0} vif {1}".format( - i, h["vlan_id"] - ) + "delete interfaces ethernet {0} vif {1}".format(i, h["vlan_id"]) ) return commands @@ -271,9 +259,7 @@ def map_params_to_obj(module): "address": module.params["address"], "state": module.params["state"], "interfaces": module.params["interfaces"], - "associated_interfaces": module.params[ - "associated_interfaces" - ], + "associated_interfaces": module.params["associated_interfaces"], } ) @@ -338,13 +324,9 @@ def check_declarative_intent_params(want, module, result): if w.get("associated_interfaces") is None: continue for i in w["associated_interfaces"]: - if (set(obj_interface) - set(w["associated_interfaces"])) != set( - [] - ): + if (set(obj_interface) - set(w["associated_interfaces"])) != set([]): module.fail_json( - msg="Interface {0} not configured on vlan {1}".format( - i, w["vlan_id"] - ) + msg="Interface {0} not configured on vlan {1}".format(i, w["vlan_id"]) ) diff --git a/plugins/terminal/vyos.py b/plugins/terminal/vyos.py index ef036ac..b9e84d7 100644 --- a/plugins/terminal/vyos.py +++ b/plugins/terminal/vyos.py @@ -24,9 +24,7 @@ import os import re from ansible.errors import AnsibleConnectionFailure -from ansible_collections.ansible.netcommon.plugins.plugin_utils.terminal_base import ( - TerminalBase, -) +from ansible_collections.ansible.netcommon.plugins.plugin_utils.terminal_base import TerminalBase class TerminalModule(TerminalBase): @@ -71,8 +69,6 @@ class TerminalModule(TerminalBase): try: for cmd in (b"set terminal length 0", b"set terminal width 512"): self._exec_cli_command(cmd) - self._exec_cli_command( - b"set terminal length %d" % self.terminal_length - ) + self._exec_cli_command(b"set terminal length %d" % self.terminal_length) except AnsibleConnectionFailure: raise AnsibleConnectionFailure("unable to set terminal parameters") diff --git a/pyproject.toml b/pyproject.toml index 4b00287..fa4225f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,5 +1,5 @@ [tool.black] -line-length = 79 +line-length = 100 [tool.pytest.ini_options] addopts = ["-vvv", "-n", "2", "--log-level", "WARNING", "--color", "yes"] diff --git a/requirements.txt b/requirements.txt index 8c44c98..f3152c2 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,4 @@ ansible-pylibssh paramiko==2.8.1 +# paramiko 2.8.1 depends on six but does not install it +six diff --git a/test-requirements.txt b/test-requirements.txt index f20ec70..e70d893 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -1,4 +1,4 @@ -black==22.6.0 +black==22.8.0 coverage==4.5.4 git+https://github.com/ansible-community/pytest-ansible-units.git flake8 diff --git a/tests/integration/targets/prepare_vyos_tests/tasks/main.yaml b/tests/integration/targets/prepare_vyos_tests/tasks/main.yaml index afbc291..8ada933 100644 --- a/tests/integration/targets/prepare_vyos_tests/tasks/main.yaml +++ b/tests/integration/targets/prepare_vyos_tests/tasks/main.yaml @@ -1,9 +1,10 @@ --- - name: Ensure required interfaces are present in running-config vars: - lines: "set interfaces ethernet eth0 address dhcp\nset interfaces ethernet eth0\ + lines: + "set interfaces ethernet eth0 address dhcp\nset interfaces ethernet eth0\ \ speed auto\nset interfaces ethernet eth0 duplex auto\nset interfaces ethernet\ \ eth1\nset interfaces ethernet eth2\ndelete interfaces loopback lo\n" ignore_errors: true ansible.netcommon.cli_config: - config: '{{ lines }}' + config: "{{ lines }}" diff --git a/tests/integration/targets/vyos_banner/defaults/main.yaml b/tests/integration/targets/vyos_banner/defaults/main.yaml index a845c24..9ef5ba5 100644 --- a/tests/integration/targets/vyos_banner/defaults/main.yaml +++ b/tests/integration/targets/vyos_banner/defaults/main.yaml @@ -1,3 +1,3 @@ --- -testcase: '*' +testcase: "*" test_items: [] diff --git a/tests/integration/targets/vyos_banner/tasks/cli.yaml b/tests/integration/targets/vyos_banner/tasks/cli.yaml index 8f7b62f..b2746ce 100644 --- a/tests/integration/targets/vyos_banner/tasks/cli.yaml +++ b/tests/integration/targets/vyos_banner/tasks/cli.yaml @@ -1,8 +1,8 @@ --- - name: collect all cli test cases find: - paths: '{{ role_path }}/tests/cli' - patterns: '{{ testcase }}.yaml' + paths: "{{ role_path }}/tests/cli" + patterns: "{{ testcase }}.yaml" register: test_cases delegate_to: localhost @@ -10,8 +10,8 @@ set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}" - name: run test case (connection=ansible.netcommon.network_cli) - include: '{{ test_case_to_run }} ansible_connection=ansible.netcommon.network_cli' - with_items: '{{ test_items }}' + include: "{{ test_case_to_run }} ansible_connection=ansible.netcommon.network_cli" + with_items: "{{ test_items }}" loop_control: loop_var: test_case_to_run tags: diff --git a/tests/integration/targets/vyos_banner/tests/cli/basic-no-login.yaml b/tests/integration/targets/vyos_banner/tests/cli/basic-no-login.yaml index 1ade232..d602763 100644 --- a/tests/integration/targets/vyos_banner/tests/cli/basic-no-login.yaml +++ b/tests/integration/targets/vyos_banner/tests/cli/basic-no-login.yaml @@ -15,7 +15,7 @@ state: absent - debug: - msg: '{{ result }}' + msg: "{{ result }}" - assert: that: diff --git a/tests/integration/targets/vyos_banner/tests/cli/basic-post-login.yaml b/tests/integration/targets/vyos_banner/tests/cli/basic-post-login.yaml index 17cc07d..da8adb1 100644 --- a/tests/integration/targets/vyos_banner/tests/cli/basic-post-login.yaml +++ b/tests/integration/targets/vyos_banner/tests/cli/basic-post-login.yaml @@ -15,7 +15,7 @@ state: present - debug: - msg: '{{ result }}' + msg: "{{ result }}" - assert: that: diff --git a/tests/integration/targets/vyos_banner/tests/cli/basic-pre-login.yaml b/tests/integration/targets/vyos_banner/tests/cli/basic-pre-login.yaml index 526c657..fc65c17 100644 --- a/tests/integration/targets/vyos_banner/tests/cli/basic-pre-login.yaml +++ b/tests/integration/targets/vyos_banner/tests/cli/basic-pre-login.yaml @@ -15,7 +15,7 @@ state: present - debug: - msg: '{{ result }}' + msg: "{{ result }}" - assert: that: diff --git a/tests/integration/targets/vyos_bgp_address_family/defaults/main.yaml b/tests/integration/targets/vyos_bgp_address_family/defaults/main.yaml index 852a6be..164afea 100644 --- a/tests/integration/targets/vyos_bgp_address_family/defaults/main.yaml +++ b/tests/integration/targets/vyos_bgp_address_family/defaults/main.yaml @@ -1,3 +1,3 @@ --- -testcase: '[^_].*' +testcase: "[^_].*" test_items: [] diff --git a/tests/integration/targets/vyos_bgp_address_family/tasks/cli.yaml b/tests/integration/targets/vyos_bgp_address_family/tasks/cli.yaml index 93eb2fe..83496e0 100644 --- a/tests/integration/targets/vyos_bgp_address_family/tasks/cli.yaml +++ b/tests/integration/targets/vyos_bgp_address_family/tasks/cli.yaml @@ -1,8 +1,8 @@ --- - name: Collect all cli test cases find: - paths: '{{ role_path }}/tests/cli' - patterns: '{{ testcase }}.yaml' + paths: "{{ role_path }}/tests/cli" + patterns: "{{ testcase }}.yaml" use_regex: true register: test_cases delegate_to: localhost @@ -11,9 +11,9 @@ set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}" - name: Run test case (connection=ansible.netcommon.network_cli) - include: '{{ test_case_to_run }}' + include: "{{ test_case_to_run }}" vars: ansible_connection: ansible.netcommon.network_cli - with_items: '{{ test_items }}' + with_items: "{{ test_items }}" loop_control: loop_var: test_case_to_run diff --git a/tests/integration/targets/vyos_bgp_address_family/tests/cli/deleted.yaml b/tests/integration/targets/vyos_bgp_address_family/tests/cli/deleted.yaml index 3519172..64f6f34 100644 --- a/tests/integration/targets/vyos_bgp_address_family/tests/cli/deleted.yaml +++ b/tests/integration/targets/vyos_bgp_address_family/tests/cli/deleted.yaml @@ -1,6 +1,7 @@ --- - debug: - msg: START vyos_bgp_address_family deleted integration tests on connection={{ + msg: + START vyos_bgp_address_family deleted integration tests on connection={{ ansible_connection }} - include_tasks: _remove_config.yaml @@ -8,7 +9,6 @@ - include_tasks: _populate.yaml - block: - - name: Delete the provided configuration register: result vyos.vyos.vyos_bgp_address_family: &id001 @@ -33,7 +33,8 @@ - result.commands|symmetric_difference(deleted.commands) == [] - result.after == ansible_facts['network_resources']['bgp_address_family'] - - name: Delete the existing configuration with the provided running configuration + - name: + Delete the existing configuration with the provided running configuration (IDEMPOTENT) register: result vyos.vyos.vyos_bgp_address_family: *id001 @@ -44,5 +45,4 @@ - result['changed'] == false always: - - include_tasks: _remove_config.yaml diff --git a/tests/integration/targets/vyos_bgp_address_family/tests/cli/empty_config.yaml b/tests/integration/targets/vyos_bgp_address_family/tests/cli/empty_config.yaml index 3a12be9..04a6aac 100644 --- a/tests/integration/targets/vyos_bgp_address_family/tests/cli/empty_config.yaml +++ b/tests/integration/targets/vyos_bgp_address_family/tests/cli/empty_config.yaml @@ -1,6 +1,7 @@ --- - debug: - msg: START vyos_bgp_address_family empty_config integration tests on connection={{ + msg: + START vyos_bgp_address_family empty_config integration tests on connection={{ ansible_connection }} - name: Merged with empty config should give appropriate error message diff --git a/tests/integration/targets/vyos_bgp_address_family/tests/cli/gathered.yaml b/tests/integration/targets/vyos_bgp_address_family/tests/cli/gathered.yaml index 07c9ac3..f05094f 100644 --- a/tests/integration/targets/vyos_bgp_address_family/tests/cli/gathered.yaml +++ b/tests/integration/targets/vyos_bgp_address_family/tests/cli/gathered.yaml @@ -1,6 +1,7 @@ --- - debug: - msg: START vyos_bgp_address_family gathered integration tests on connection={{ + msg: + START vyos_bgp_address_family gathered integration tests on connection={{ ansible_connection }} - include_tasks: _remove_config.yaml @@ -8,7 +9,6 @@ - include_tasks: _populate.yaml - block: - - name: Gather config from the device in structured format. register: result vyos.vyos.vyos_bgp_address_family: diff --git a/tests/integration/targets/vyos_bgp_address_family/tests/cli/overridden.yaml b/tests/integration/targets/vyos_bgp_address_family/tests/cli/overridden.yaml index 68dd47b..fdbc00b 100644 --- a/tests/integration/targets/vyos_bgp_address_family/tests/cli/overridden.yaml +++ b/tests/integration/targets/vyos_bgp_address_family/tests/cli/overridden.yaml @@ -1,6 +1,7 @@ --- - debug: - msg: START vyos_bgp_address_family overridden integration tests on connection={{ + msg: + START vyos_bgp_address_family overridden integration tests on connection={{ ansible_connection }} - include_tasks: _remove_config.yaml @@ -8,7 +9,6 @@ - include_tasks: _populate.yaml - block: - - name: Replace the existing configuration with the provided running configuration register: result vyos.vyos.vyos_bgp_address_family: &id001 @@ -42,7 +42,8 @@ - result.commands|symmetric_difference(overridden.commands) == [] - result.after == ansible_facts['network_resources']['bgp_address_family'] - - name: Replace the existing configuration with the provided running configuration + - name: + Replace the existing configuration with the provided running configuration (IDEMPOTENT) register: result vyos.vyos.vyos_bgp_address_family: *id001 @@ -53,5 +54,4 @@ - result['changed'] == false always: - - include_tasks: _remove_config.yaml diff --git a/tests/integration/targets/vyos_bgp_address_family/tests/cli/parsed.yaml b/tests/integration/targets/vyos_bgp_address_family/tests/cli/parsed.yaml index 3176797..6bd9c77 100644 --- a/tests/integration/targets/vyos_bgp_address_family/tests/cli/parsed.yaml +++ b/tests/integration/targets/vyos_bgp_address_family/tests/cli/parsed.yaml @@ -1,6 +1,7 @@ --- - debug: - msg: START vyos_bgp_address_family parsed integration tests on connection={{ ansible_connection + msg: + START vyos_bgp_address_family parsed integration tests on connection={{ ansible_connection }} - name: Provide the running configuration for parsing (config to be parsed) diff --git a/tests/integration/targets/vyos_bgp_address_family/tests/cli/rendered.yaml b/tests/integration/targets/vyos_bgp_address_family/tests/cli/rendered.yaml index 1071657..8c6ac5c 100644 --- a/tests/integration/targets/vyos_bgp_address_family/tests/cli/rendered.yaml +++ b/tests/integration/targets/vyos_bgp_address_family/tests/cli/rendered.yaml @@ -1,10 +1,10 @@ --- - debug: - msg: START vyos_bgp_address_family rendered integration tests on connection={{ + msg: + START vyos_bgp_address_family rendered integration tests on connection={{ ansible_connection }} - block: - - name: Render the given config in the form of native config. register: result vyos.vyos.vyos_bgp_address_family: &id001 diff --git a/tests/integration/targets/vyos_bgp_address_family/tests/cli/replaced.yaml b/tests/integration/targets/vyos_bgp_address_family/tests/cli/replaced.yaml index b4fe3db..d782582 100644 --- a/tests/integration/targets/vyos_bgp_address_family/tests/cli/replaced.yaml +++ b/tests/integration/targets/vyos_bgp_address_family/tests/cli/replaced.yaml @@ -1,6 +1,7 @@ --- - debug: - msg: START vyos_bgp_address_family replaced integration tests on connection={{ + msg: + START vyos_bgp_address_family replaced integration tests on connection={{ ansible_connection }} - include_tasks: _remove_config.yaml @@ -8,7 +9,6 @@ - include_tasks: _populate.yaml - block: - - name: Replace the existing configuration with the provided running configuration register: result vyos.vyos.vyos_bgp_address_family: &id001 @@ -42,7 +42,8 @@ - result.commands|symmetric_difference(replaced.commands) == [] - result.after == ansible_facts['network_resources']['bgp_address_family'] - - name: Replace the existing configuration with the provided running configuration + - name: + Replace the existing configuration with the provided running configuration (IDEMPOTENT) register: result vyos.vyos.vyos_bgp_address_family: *id001 @@ -53,5 +54,4 @@ - result['changed'] == false always: - - include_tasks: _remove_config.yaml diff --git a/tests/integration/targets/vyos_bgp_global/defaults/main.yaml b/tests/integration/targets/vyos_bgp_global/defaults/main.yaml index 852a6be..164afea 100644 --- a/tests/integration/targets/vyos_bgp_global/defaults/main.yaml +++ b/tests/integration/targets/vyos_bgp_global/defaults/main.yaml @@ -1,3 +1,3 @@ --- -testcase: '[^_].*' +testcase: "[^_].*" test_items: [] diff --git a/tests/integration/targets/vyos_bgp_global/tasks/cli.yaml b/tests/integration/targets/vyos_bgp_global/tasks/cli.yaml index 93eb2fe..83496e0 100644 --- a/tests/integration/targets/vyos_bgp_global/tasks/cli.yaml +++ b/tests/integration/targets/vyos_bgp_global/tasks/cli.yaml @@ -1,8 +1,8 @@ --- - name: Collect all cli test cases find: - paths: '{{ role_path }}/tests/cli' - patterns: '{{ testcase }}.yaml' + paths: "{{ role_path }}/tests/cli" + patterns: "{{ testcase }}.yaml" use_regex: true register: test_cases delegate_to: localhost @@ -11,9 +11,9 @@ set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}" - name: Run test case (connection=ansible.netcommon.network_cli) - include: '{{ test_case_to_run }}' + include: "{{ test_case_to_run }}" vars: ansible_connection: ansible.netcommon.network_cli - with_items: '{{ test_items }}' + with_items: "{{ test_items }}" loop_control: loop_var: test_case_to_run diff --git a/tests/integration/targets/vyos_bgp_global/tests/cli/deleted.yaml b/tests/integration/targets/vyos_bgp_global/tests/cli/deleted.yaml index 9c7400e..8df1677 100644 --- a/tests/integration/targets/vyos_bgp_global/tests/cli/deleted.yaml +++ b/tests/integration/targets/vyos_bgp_global/tests/cli/deleted.yaml @@ -8,7 +8,6 @@ - include_tasks: _populate.yaml - block: - - name: Delete the provided configuration register: result vyos.vyos.vyos_bgp_global: &id001 @@ -26,7 +25,8 @@ - result.commands|symmetric_difference(deleted.commands) == [] - result.after == ansible_facts['network_resources']['bgp_global'] - - name: Delete the existing configuration with the provided running configuration + - name: + Delete the existing configuration with the provided running configuration (IDEMPOTENT) register: result vyos.vyos.vyos_bgp_global: *id001 @@ -37,5 +37,4 @@ - result['changed'] == false always: - - include_tasks: _remove_config.yaml diff --git a/tests/integration/targets/vyos_bgp_global/tests/cli/deleted_af.yaml b/tests/integration/targets/vyos_bgp_global/tests/cli/deleted_af.yaml index 9792125..edee16b 100644 --- a/tests/integration/targets/vyos_bgp_global/tests/cli/deleted_af.yaml +++ b/tests/integration/targets/vyos_bgp_global/tests/cli/deleted_af.yaml @@ -8,7 +8,6 @@ - include_tasks: _populate_af.yaml - block: - - name: Delete the existing configuration, in presence of an af under neighbor. register: result ignore_errors: true @@ -22,5 +21,4 @@ - result.msg == 'Use the _bgp_address_family module to delete the address_family under neighbor 5001::64, before replacing/deleting the neighbor.' always: - - include_tasks: _remove_config.yaml diff --git a/tests/integration/targets/vyos_bgp_global/tests/cli/gathered.yaml b/tests/integration/targets/vyos_bgp_global/tests/cli/gathered.yaml index 2022533..742951f 100644 --- a/tests/integration/targets/vyos_bgp_global/tests/cli/gathered.yaml +++ b/tests/integration/targets/vyos_bgp_global/tests/cli/gathered.yaml @@ -8,7 +8,6 @@ - include_tasks: _populate.yaml - block: - - name: Gather config from the device in structured format. register: result vyos.vyos.vyos_bgp_global: diff --git a/tests/integration/targets/vyos_bgp_global/tests/cli/parsed.yaml b/tests/integration/targets/vyos_bgp_global/tests/cli/parsed.yaml index 7c1665f..ef8856d 100644 --- a/tests/integration/targets/vyos_bgp_global/tests/cli/parsed.yaml +++ b/tests/integration/targets/vyos_bgp_global/tests/cli/parsed.yaml @@ -1,6 +1,7 @@ --- - debug: - msg: START vyos_bgp_global parsed integration tests on connection={{ ansible_connection + msg: + START vyos_bgp_global parsed integration tests on connection={{ ansible_connection }} - name: Provide the running configuration for parsing (config to be parsed) diff --git a/tests/integration/targets/vyos_bgp_global/tests/cli/purged.yaml b/tests/integration/targets/vyos_bgp_global/tests/cli/purged.yaml index 46346c2..0af8775 100644 --- a/tests/integration/targets/vyos_bgp_global/tests/cli/purged.yaml +++ b/tests/integration/targets/vyos_bgp_global/tests/cli/purged.yaml @@ -8,7 +8,6 @@ - include_tasks: _populate.yaml - block: - - name: Purge the provided configuration register: result vyos.vyos.vyos_bgp_global: &id001 @@ -27,5 +26,4 @@ - ansible_facts.network_resources.bgp_global == [] always: - - include_tasks: _remove_config.yaml diff --git a/tests/integration/targets/vyos_bgp_global/tests/cli/rendered.yaml b/tests/integration/targets/vyos_bgp_global/tests/cli/rendered.yaml index 3a44a5e..534227f 100644 --- a/tests/integration/targets/vyos_bgp_global/tests/cli/rendered.yaml +++ b/tests/integration/targets/vyos_bgp_global/tests/cli/rendered.yaml @@ -4,7 +4,6 @@ ansible_connection }} - block: - - name: Render given bgp_global configuration register: result vyos.vyos.vyos_bgp_global: &id001 diff --git a/tests/integration/targets/vyos_bgp_global/tests/cli/replaced.yaml b/tests/integration/targets/vyos_bgp_global/tests/cli/replaced.yaml index f1b79b2..aeb4aa7 100644 --- a/tests/integration/targets/vyos_bgp_global/tests/cli/replaced.yaml +++ b/tests/integration/targets/vyos_bgp_global/tests/cli/replaced.yaml @@ -8,7 +8,6 @@ - include_tasks: _populate.yaml - block: - - name: Replace the existing configuration with the provided running configuration register: result vyos.vyos.vyos_bgp_global: &id001 @@ -56,7 +55,8 @@ - result.commands|symmetric_difference(replaced.commands) == [] - result.after == ansible_facts['network_resources']['bgp_global'] - - name: Replace the existing configuration with the provided running configuration + - name: + Replace the existing configuration with the provided running configuration (IDEMPOTENT) register: result vyos.vyos.vyos_bgp_global: *id001 @@ -67,5 +67,4 @@ - result['changed'] == false always: - - include_tasks: _remove_config.yaml diff --git a/tests/integration/targets/vyos_bgp_global/tests/cli/replaced_af.yaml b/tests/integration/targets/vyos_bgp_global/tests/cli/replaced_af.yaml index abcb177..e66aae7 100644 --- a/tests/integration/targets/vyos_bgp_global/tests/cli/replaced_af.yaml +++ b/tests/integration/targets/vyos_bgp_global/tests/cli/replaced_af.yaml @@ -8,7 +8,6 @@ - include_tasks: _populate_af.yaml - block: - - name: Replace the existing af configuration with the provided running configuration register: result ignore_errors: true @@ -52,5 +51,4 @@ - result.msg == 'Use the _bgp_address_family module to delete the address_family under neighbor 5001::64, before replacing/deleting the neighbor.' always: - - include_tasks: _remove_config.yaml diff --git a/tests/integration/targets/vyos_command/defaults/main.yaml b/tests/integration/targets/vyos_command/defaults/main.yaml index a845c24..9ef5ba5 100644 --- a/tests/integration/targets/vyos_command/defaults/main.yaml +++ b/tests/integration/targets/vyos_command/defaults/main.yaml @@ -1,3 +1,3 @@ --- -testcase: '*' +testcase: "*" test_items: [] diff --git a/tests/integration/targets/vyos_command/tasks/cli.yaml b/tests/integration/targets/vyos_command/tasks/cli.yaml index 8f7b62f..b2746ce 100644 --- a/tests/integration/targets/vyos_command/tasks/cli.yaml +++ b/tests/integration/targets/vyos_command/tasks/cli.yaml @@ -1,8 +1,8 @@ --- - name: collect all cli test cases find: - paths: '{{ role_path }}/tests/cli' - patterns: '{{ testcase }}.yaml' + paths: "{{ role_path }}/tests/cli" + patterns: "{{ testcase }}.yaml" register: test_cases delegate_to: localhost @@ -10,8 +10,8 @@ set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}" - name: run test case (connection=ansible.netcommon.network_cli) - include: '{{ test_case_to_run }} ansible_connection=ansible.netcommon.network_cli' - with_items: '{{ test_items }}' + include: "{{ test_case_to_run }} ansible_connection=ansible.netcommon.network_cli" + with_items: "{{ test_items }}" loop_control: loop_var: test_case_to_run tags: diff --git a/tests/integration/targets/vyos_command/tasks/redirection.yaml b/tests/integration/targets/vyos_command/tasks/redirection.yaml index 5564a3e..48ad53a 100644 --- a/tests/integration/targets/vyos_command/tasks/redirection.yaml +++ b/tests/integration/targets/vyos_command/tasks/redirection.yaml @@ -1,8 +1,8 @@ --- - name: collect all redirection cli test cases find: - paths: '{{ role_path }}/tests/redirection/cli' - patterns: '{{ testcase }}.yaml' + paths: "{{ role_path }}/tests/redirection/cli" + patterns: "{{ testcase }}.yaml" register: shortname_test_cases delegate_to: localhost @@ -10,7 +10,7 @@ set_fact: test_items="{{ shortname_test_cases.files | map(attribute='path') | list }}" - name: run test case (connection=ansible.netcommon.network_cli) - include: '{{ test_case_to_run }} ansible_connection=ansible.netcommon.network_cli' - with_items: '{{ test_items }}' + include: "{{ test_case_to_run }} ansible_connection=ansible.netcommon.network_cli" + with_items: "{{ test_items }}" loop_control: loop_var: test_case_to_run diff --git a/tests/integration/targets/vyos_command/tests/cli/cli_command.yaml b/tests/integration/targets/vyos_command/tests/cli/cli_command.yaml index 61ed054..2467a4f 100644 --- a/tests/integration/targets/vyos_command/tests/cli/cli_command.yaml +++ b/tests/integration/targets/vyos_command/tests/cli/cli_command.yaml @@ -3,7 +3,6 @@ msg: START cli/cli_command.yaml on connection={{ ansible_connection }} - block: - - name: get output for single command register: result ansible.netcommon.cli_command: @@ -27,7 +26,6 @@ when: ansible_connection == 'ansible.netcommon.network_cli' - block: - - name: test failure for local connection register: result ignore_errors: true diff --git a/tests/integration/targets/vyos_config/defaults/main.yaml b/tests/integration/targets/vyos_config/defaults/main.yaml index a845c24..9ef5ba5 100644 --- a/tests/integration/targets/vyos_config/defaults/main.yaml +++ b/tests/integration/targets/vyos_config/defaults/main.yaml @@ -1,3 +1,3 @@ --- -testcase: '*' +testcase: "*" test_items: [] diff --git a/tests/integration/targets/vyos_config/tasks/cli.yaml b/tests/integration/targets/vyos_config/tasks/cli.yaml index 8f7b62f..b2746ce 100644 --- a/tests/integration/targets/vyos_config/tasks/cli.yaml +++ b/tests/integration/targets/vyos_config/tasks/cli.yaml @@ -1,8 +1,8 @@ --- - name: collect all cli test cases find: - paths: '{{ role_path }}/tests/cli' - patterns: '{{ testcase }}.yaml' + paths: "{{ role_path }}/tests/cli" + patterns: "{{ testcase }}.yaml" register: test_cases delegate_to: localhost @@ -10,8 +10,8 @@ set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}" - name: run test case (connection=ansible.netcommon.network_cli) - include: '{{ test_case_to_run }} ansible_connection=ansible.netcommon.network_cli' - with_items: '{{ test_items }}' + include: "{{ test_case_to_run }} ansible_connection=ansible.netcommon.network_cli" + with_items: "{{ test_items }}" loop_control: loop_var: test_case_to_run tags: diff --git a/tests/integration/targets/vyos_config/tasks/cli_config.yaml b/tests/integration/targets/vyos_config/tasks/cli_config.yaml index 98bd1fc..8ed2874 100644 --- a/tests/integration/targets/vyos_config/tasks/cli_config.yaml +++ b/tests/integration/targets/vyos_config/tasks/cli_config.yaml @@ -1,8 +1,8 @@ --- - name: collect all cli_config test cases find: - paths: '{{ role_path }}/tests/cli_config' - patterns: '{{ testcase }}.yaml' + paths: "{{ role_path }}/tests/cli_config" + patterns: "{{ testcase }}.yaml" register: test_cases delegate_to: localhost @@ -10,7 +10,7 @@ set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}" - name: run test case (connection=ansible.netcommon.network_cli) - include: '{{ test_case_to_run }} ansible_connection=ansible.netcommon.network_cli' - with_items: '{{ test_items }}' + include: "{{ test_case_to_run }} ansible_connection=ansible.netcommon.network_cli" + with_items: "{{ test_items }}" loop_control: loop_var: test_case_to_run diff --git a/tests/integration/targets/vyos_config/tasks/redirection.yaml b/tests/integration/targets/vyos_config/tasks/redirection.yaml index 5564a3e..48ad53a 100644 --- a/tests/integration/targets/vyos_config/tasks/redirection.yaml +++ b/tests/integration/targets/vyos_config/tasks/redirection.yaml @@ -1,8 +1,8 @@ --- - name: collect all redirection cli test cases find: - paths: '{{ role_path }}/tests/redirection/cli' - patterns: '{{ testcase }}.yaml' + paths: "{{ role_path }}/tests/redirection/cli" + patterns: "{{ testcase }}.yaml" register: shortname_test_cases delegate_to: localhost @@ -10,7 +10,7 @@ set_fact: test_items="{{ shortname_test_cases.files | map(attribute='path') | list }}" - name: run test case (connection=ansible.netcommon.network_cli) - include: '{{ test_case_to_run }} ansible_connection=ansible.netcommon.network_cli' - with_items: '{{ test_items }}' + include: "{{ test_case_to_run }} ansible_connection=ansible.netcommon.network_cli" + with_items: "{{ test_items }}" loop_control: loop_var: test_case_to_run diff --git a/tests/integration/targets/vyos_config/tests/cli/backup.yaml b/tests/integration/targets/vyos_config/tests/cli/backup.yaml index 95fdd98..f414b76 100644 --- a/tests/integration/targets/vyos_config/tests/cli/backup.yaml +++ b/tests/integration/targets/vyos_config/tests/cli/backup.yaml @@ -3,16 +3,16 @@ - name: collect any backup files find: - paths: '{{ role_path }}/backup' - pattern: '{{ inventory_hostname_short }}_config*' + paths: "{{ role_path }}/backup" + pattern: "{{ inventory_hostname_short }}_config*" register: backup_files connection: local - name: delete backup files file: - path: '{{ item.path }}' + path: "{{ item.path }}" state: absent - with_items: '{{backup_files.files|default([])}}' + with_items: "{{backup_files.files|default([])}}" - name: take configure backup register: result @@ -25,8 +25,8 @@ - name: collect any backup files find: - paths: '{{ role_path }}/backup' - pattern: '{{ inventory_hostname_short }}_config*' + paths: "{{ role_path }}/backup" + pattern: "{{ inventory_hostname_short }}_config*" register: backup_files connection: local @@ -36,11 +36,11 @@ - name: delete configurable backup file path file: - path: '{{ item }}' + path: "{{ item }}" state: absent with_items: - - '{{ role_path }}/backup_test_dir/' - - '{{ role_path }}/backup/backup.cfg' + - "{{ role_path }}/backup_test_dir/" + - "{{ role_path }}/backup/backup.cfg" - name: take configuration backup in custom filename and directory path register: result @@ -48,7 +48,7 @@ backup: true backup_options: filename: backup.cfg - dir_path: '{{ role_path }}/backup_test_dir/{{ inventory_hostname_short }}' + dir_path: "{{ role_path }}/backup_test_dir/{{ inventory_hostname_short }}" - assert: that: @@ -56,7 +56,7 @@ - name: check if the backup file-1 exist find: - paths: '{{ role_path }}/backup_test_dir/{{ inventory_hostname_short }}/backup.cfg' + paths: "{{ role_path }}/backup_test_dir/{{ inventory_hostname_short }}/backup.cfg" register: backup_file connection: local @@ -77,7 +77,7 @@ - name: check if the backup file-2 exist find: - paths: '{{ role_path }}/backup/backup.cfg' + paths: "{{ role_path }}/backup/backup.cfg" register: backup_file connection: local @@ -90,7 +90,7 @@ vyos.vyos.vyos_config: backup: true backup_options: - dir_path: '{{ role_path }}/backup_test_dir/{{ inventory_hostname_short }}' + dir_path: "{{ role_path }}/backup_test_dir/{{ inventory_hostname_short }}" - assert: that: @@ -98,8 +98,8 @@ - name: check if the backup file-3 exist find: - paths: '{{ role_path }}/backup_test_dir/{{ inventory_hostname_short }}' - pattern: '{{ inventory_hostname_short }}_config*' + paths: "{{ role_path }}/backup_test_dir/{{ inventory_hostname_short }}" + pattern: "{{ inventory_hostname_short }}_config*" register: backup_file connection: local diff --git a/tests/integration/targets/vyos_config/tests/cli/check_config.yaml b/tests/integration/targets/vyos_config/tests/cli/check_config.yaml index 4300c10..2df0135 100644 --- a/tests/integration/targets/vyos_config/tests/cli/check_config.yaml +++ b/tests/integration/targets/vyos_config/tests/cli/check_config.yaml @@ -16,7 +16,7 @@ - name: Check that multiple duplicate lines collapse into a single commands assert: that: - - '{{ result.commands|length }} == 1' + - "{{ result.commands|length }} == 1" - name: Check that set is correctly prepended assert: @@ -52,6 +52,6 @@ - assert: that: - - '{{ result.filtered|length }} == 2' + - "{{ result.filtered|length }} == 2" - debug: msg="END cli/config_check.yaml on connection={{ ansible_connection }}" diff --git a/tests/integration/targets/vyos_config/tests/cli/simple.yaml b/tests/integration/targets/vyos_config/tests/cli/simple.yaml index 4e2db4e..3db5927 100644 --- a/tests/integration/targets/vyos_config/tests/cli/simple.yaml +++ b/tests/integration/targets/vyos_config/tests/cli/simple.yaml @@ -34,7 +34,7 @@ - name: Configuring when commands starts with whitespaces register: result vyos.vyos.vyos_config: - src: '{{ role_path }}/tests/cli/config.cfg' + src: "{{ role_path }}/tests/cli/config.cfg" - assert: that: diff --git a/tests/integration/targets/vyos_config/tests/cli_config/cli_backup.yaml b/tests/integration/targets/vyos_config/tests/cli_config/cli_backup.yaml index 516b835..db35410 100644 --- a/tests/integration/targets/vyos_config/tests/cli_config/cli_backup.yaml +++ b/tests/integration/targets/vyos_config/tests/cli_config/cli_backup.yaml @@ -3,24 +3,24 @@ - name: delete configurable backup file path file: - path: '{{ item }}' + path: "{{ item }}" state: absent with_items: - - '{{ role_path }}/backup_test_dir/' - - '{{ role_path }}/backup/backup.cfg' + - "{{ role_path }}/backup_test_dir/" + - "{{ role_path }}/backup/backup.cfg" - name: collect any backup files find: - paths: '{{ role_path }}/backup' - pattern: '{{ inventory_hostname_short }}_config*' + paths: "{{ role_path }}/backup" + pattern: "{{ inventory_hostname_short }}_config*" register: backup_files connection: local - name: delete backup files file: - path: '{{ item.path }}' + path: "{{ item.path }}" state: absent - with_items: '{{backup_files.files|default([])}}' + with_items: "{{backup_files.files|default([])}}" - name: take config backup register: result @@ -33,8 +33,8 @@ - name: collect any backup files find: - paths: '{{ role_path }}/backup' - pattern: '{{ inventory_hostname_short }}_config*' + paths: "{{ role_path }}/backup" + pattern: "{{ inventory_hostname_short }}_config*" register: backup_files connection: local @@ -48,7 +48,7 @@ backup: true backup_options: filename: backup.cfg - dir_path: '{{ role_path }}/backup_test_dir/{{ inventory_hostname_short }}' + dir_path: "{{ role_path }}/backup_test_dir/{{ inventory_hostname_short }}" - assert: that: @@ -56,7 +56,7 @@ - name: check if the backup file-1 exist find: - paths: '{{ role_path }}/backup_test_dir/{{ inventory_hostname_short }}/backup.cfg' + paths: "{{ role_path }}/backup_test_dir/{{ inventory_hostname_short }}/backup.cfg" register: backup_file connection: local @@ -77,7 +77,7 @@ - name: check if the backup file-2 exist find: - paths: '{{ role_path }}/backup/backup.cfg' + paths: "{{ role_path }}/backup/backup.cfg" register: backup_file connection: local @@ -90,7 +90,7 @@ ansible.netcommon.cli_config: backup: true backup_options: - dir_path: '{{ role_path }}/backup_test_dir/{{ inventory_hostname_short }}' + dir_path: "{{ role_path }}/backup_test_dir/{{ inventory_hostname_short }}" - assert: that: @@ -98,8 +98,8 @@ - name: check if the backup file-3 exist find: - paths: '{{ role_path }}/backup_test_dir/{{ inventory_hostname_short }}' - pattern: '{{ inventory_hostname_short }}_config*' + paths: "{{ role_path }}/backup_test_dir/{{ inventory_hostname_short }}" + pattern: "{{ inventory_hostname_short }}_config*" register: backup_file connection: local diff --git a/tests/integration/targets/vyos_config/tests/cli_config/cli_basic.yaml b/tests/integration/targets/vyos_config/tests/cli_config/cli_basic.yaml index 6b71144..55a96aa 100644 --- a/tests/integration/targets/vyos_config/tests/cli_config/cli_basic.yaml +++ b/tests/integration/targets/vyos_config/tests/cli_config/cli_basic.yaml @@ -1,5 +1,6 @@ --- -- debug: msg="START cli_config/cli_basic.yaml on connection={{ ansible_connection +- debug: + msg="START cli_config/cli_basic.yaml on connection={{ ansible_connection }}" - name: setup - remove interface description diff --git a/tests/integration/targets/vyos_config/tests/cli_config/cli_comment.yaml b/tests/integration/targets/vyos_config/tests/cli_config/cli_comment.yaml index 030b75d..470553f 100644 --- a/tests/integration/targets/vyos_config/tests/cli_config/cli_comment.yaml +++ b/tests/integration/targets/vyos_config/tests/cli_config/cli_comment.yaml @@ -1,5 +1,6 @@ --- -- debug: msg="START cli_config/cli_comment.yaml on connection={{ ansible_connection +- debug: + msg="START cli_config/cli_comment.yaml on connection={{ ansible_connection }}" - name: setup @@ -28,5 +29,6 @@ - name: teardown ansible.netcommon.cli_config: *id001 -- debug: msg="END cli_config/cli_comment.yaml on connection={{ ansible_connection +- debug: + msg="END cli_config/cli_comment.yaml on connection={{ ansible_connection }}" diff --git a/tests/integration/targets/vyos_config/tests/redirection/cli/shortname.yaml b/tests/integration/targets/vyos_config/tests/redirection/cli/shortname.yaml index 3f3e489..f397a27 100644 --- a/tests/integration/targets/vyos_config/tests/redirection/cli/shortname.yaml +++ b/tests/integration/targets/vyos_config/tests/redirection/cli/shortname.yaml @@ -16,7 +16,7 @@ - name: Check that multiple duplicate lines collapse into a single commands assert: that: - - '{{ result.commands|length }} == 1' + - "{{ result.commands|length }} == 1" - name: Check that set is correctly prepended assert: @@ -52,7 +52,7 @@ - assert: that: - - '{{ result.filtered|length }} == 2' + - "{{ result.filtered|length }} == 2" - name: Remove interface description and delete temp user vyos.vyos.config: &cleanup @@ -80,7 +80,7 @@ backup: true backup_options: filename: backup_with_alias.cfg - dir_path: '{{ role_path }}/backup_test_dir/{{ inventory_hostname_short }}' + dir_path: "{{ role_path }}/backup_test_dir/{{ inventory_hostname_short }}" - assert: that: @@ -88,7 +88,7 @@ - name: check if the backup file-4 exist find: - paths: '{{ role_path }}/backup_test_dir/{{ inventory_hostname_short }}/backup_with_alias.cfg' + paths: "{{ role_path }}/backup_test_dir/{{ inventory_hostname_short }}/backup_with_alias.cfg" register: backup_file connection: local diff --git a/tests/integration/targets/vyos_facts/defaults/main.yaml b/tests/integration/targets/vyos_facts/defaults/main.yaml index a845c24..9ef5ba5 100644 --- a/tests/integration/targets/vyos_facts/defaults/main.yaml +++ b/tests/integration/targets/vyos_facts/defaults/main.yaml @@ -1,3 +1,3 @@ --- -testcase: '*' +testcase: "*" test_items: [] diff --git a/tests/integration/targets/vyos_facts/tasks/cli.yaml b/tests/integration/targets/vyos_facts/tasks/cli.yaml index 8f7b62f..b2746ce 100644 --- a/tests/integration/targets/vyos_facts/tasks/cli.yaml +++ b/tests/integration/targets/vyos_facts/tasks/cli.yaml @@ -1,8 +1,8 @@ --- - name: collect all cli test cases find: - paths: '{{ role_path }}/tests/cli' - patterns: '{{ testcase }}.yaml' + paths: "{{ role_path }}/tests/cli" + patterns: "{{ testcase }}.yaml" register: test_cases delegate_to: localhost @@ -10,8 +10,8 @@ set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}" - name: run test case (connection=ansible.netcommon.network_cli) - include: '{{ test_case_to_run }} ansible_connection=ansible.netcommon.network_cli' - with_items: '{{ test_items }}' + include: "{{ test_case_to_run }} ansible_connection=ansible.netcommon.network_cli" + with_items: "{{ test_items }}" loop_control: loop_var: test_case_to_run tags: diff --git a/tests/integration/targets/vyos_facts/tasks/redirection.yaml b/tests/integration/targets/vyos_facts/tasks/redirection.yaml index 5564a3e..48ad53a 100644 --- a/tests/integration/targets/vyos_facts/tasks/redirection.yaml +++ b/tests/integration/targets/vyos_facts/tasks/redirection.yaml @@ -1,8 +1,8 @@ --- - name: collect all redirection cli test cases find: - paths: '{{ role_path }}/tests/redirection/cli' - patterns: '{{ testcase }}.yaml' + paths: "{{ role_path }}/tests/redirection/cli" + patterns: "{{ testcase }}.yaml" register: shortname_test_cases delegate_to: localhost @@ -10,7 +10,7 @@ set_fact: test_items="{{ shortname_test_cases.files | map(attribute='path') | list }}" - name: run test case (connection=ansible.netcommon.network_cli) - include: '{{ test_case_to_run }} ansible_connection=ansible.netcommon.network_cli' - with_items: '{{ test_items }}' + include: "{{ test_case_to_run }} ansible_connection=ansible.netcommon.network_cli" + with_items: "{{ test_items }}" loop_control: loop_var: test_case_to_run 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 a7c3a11..f6e8208 100644 --- a/tests/integration/targets/vyos_facts/tests/cli/basic_facts.yaml +++ b/tests/integration/targets/vyos_facts/tests/cli/basic_facts.yaml @@ -52,7 +52,7 @@ that: - result.changed == false - "{{ result['ansible_facts']['available_network_resources'] | symmetric_difference(result['ansible_facts']['ansible_net_gather_network_resources']) |length\ - \ == 0 }}" + \ == 0 }}" - name: test getting default facts register: result diff --git a/tests/integration/targets/vyos_firewall_global/defaults/main.yaml b/tests/integration/targets/vyos_firewall_global/defaults/main.yaml index 852a6be..164afea 100644 --- a/tests/integration/targets/vyos_firewall_global/defaults/main.yaml +++ b/tests/integration/targets/vyos_firewall_global/defaults/main.yaml @@ -1,3 +1,3 @@ --- -testcase: '[^_].*' +testcase: "[^_].*" test_items: [] diff --git a/tests/integration/targets/vyos_firewall_global/tasks/cli.yaml b/tests/integration/targets/vyos_firewall_global/tasks/cli.yaml index 93eb2fe..83496e0 100644 --- a/tests/integration/targets/vyos_firewall_global/tasks/cli.yaml +++ b/tests/integration/targets/vyos_firewall_global/tasks/cli.yaml @@ -1,8 +1,8 @@ --- - name: Collect all cli test cases find: - paths: '{{ role_path }}/tests/cli' - patterns: '{{ testcase }}.yaml' + paths: "{{ role_path }}/tests/cli" + patterns: "{{ testcase }}.yaml" use_regex: true register: test_cases delegate_to: localhost @@ -11,9 +11,9 @@ set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}" - name: Run test case (connection=ansible.netcommon.network_cli) - include: '{{ test_case_to_run }}' + include: "{{ test_case_to_run }}" vars: ansible_connection: ansible.netcommon.network_cli - with_items: '{{ test_items }}' + with_items: "{{ test_items }}" loop_control: loop_var: test_case_to_run diff --git a/tests/integration/targets/vyos_firewall_global/tasks/redirection.yaml b/tests/integration/targets/vyos_firewall_global/tasks/redirection.yaml index 5564a3e..48ad53a 100644 --- a/tests/integration/targets/vyos_firewall_global/tasks/redirection.yaml +++ b/tests/integration/targets/vyos_firewall_global/tasks/redirection.yaml @@ -1,8 +1,8 @@ --- - name: collect all redirection cli test cases find: - paths: '{{ role_path }}/tests/redirection/cli' - patterns: '{{ testcase }}.yaml' + paths: "{{ role_path }}/tests/redirection/cli" + patterns: "{{ testcase }}.yaml" register: shortname_test_cases delegate_to: localhost @@ -10,7 +10,7 @@ set_fact: test_items="{{ shortname_test_cases.files | map(attribute='path') | list }}" - name: run test case (connection=ansible.netcommon.network_cli) - include: '{{ test_case_to_run }} ansible_connection=ansible.netcommon.network_cli' - with_items: '{{ test_items }}' + include: "{{ test_case_to_run }} ansible_connection=ansible.netcommon.network_cli" + with_items: "{{ test_items }}" loop_control: loop_var: test_case_to_run diff --git a/tests/integration/targets/vyos_firewall_global/tests/cli/_populate.yaml b/tests/integration/targets/vyos_firewall_global/tests/cli/_populate.yaml index f79bb9a..27d1aa2 100644 --- a/tests/integration/targets/vyos_firewall_global/tests/cli/_populate.yaml +++ b/tests/integration/targets/vyos_firewall_global/tests/cli/_populate.yaml @@ -1,7 +1,8 @@ --- - name: Setup vars: - lines: "set firewall all-ping 'enable'\nset firewall broadcast-ping 'enable'\n\ + lines: + "set firewall all-ping 'enable'\nset firewall broadcast-ping 'enable'\n\ set firewall config-trap 'enable'\nset firewall group address-group MGMT-HOSTS\ \ address '192.0.1.1'\nset firewall group address-group MGMT-HOSTS address\ \ '192.0.1.3'\nset firewall group address-group MGMT-HOSTS address '192.0.1.5'\n\ @@ -15,4 +16,4 @@ \ log 'enable'\nset firewall state-policy invalid action 'reject'\nset firewall\ \ syn-cookies 'enable'\nset firewall twa-hazards-protection 'enable'\n" ansible.netcommon.cli_config: - config: '{{ lines }}' + config: "{{ lines }}" diff --git a/tests/integration/targets/vyos_firewall_global/tests/cli/_remove_config.yaml b/tests/integration/targets/vyos_firewall_global/tests/cli/_remove_config.yaml index 5c86924..60cb2d8 100644 --- a/tests/integration/targets/vyos_firewall_global/tests/cli/_remove_config.yaml +++ b/tests/integration/targets/vyos_firewall_global/tests/cli/_remove_config.yaml @@ -3,4 +3,4 @@ vars: lines: "delete firewall\n" ansible.netcommon.cli_config: - config: '{{ lines }}' + config: "{{ lines }}" diff --git a/tests/integration/targets/vyos_firewall_global/tests/cli/deleted.yaml b/tests/integration/targets/vyos_firewall_global/tests/cli/deleted.yaml index 44df47c..31620f4 100644 --- a/tests/integration/targets/vyos_firewall_global/tests/cli/deleted.yaml +++ b/tests/integration/targets/vyos_firewall_global/tests/cli/deleted.yaml @@ -1,12 +1,12 @@ --- - debug: - msg: Start vyos_firewall_global deleted integration tests ansible_connection={{ + msg: + Start vyos_firewall_global deleted integration tests ansible_connection={{ ansible_connection }} - include_tasks: _populate.yaml - block: - - name: Delete attributes of firewall. register: result vyos.vyos.vyos_firewall_global: &id001 @@ -44,5 +44,4 @@ that: - "{{ deleted['after'] == result['before'] }}" always: - - include_tasks: _remove_config.yaml diff --git a/tests/integration/targets/vyos_firewall_global/tests/cli/empty_config.yaml b/tests/integration/targets/vyos_firewall_global/tests/cli/empty_config.yaml index 3910952..643a99e 100644 --- a/tests/integration/targets/vyos_firewall_global/tests/cli/empty_config.yaml +++ b/tests/integration/targets/vyos_firewall_global/tests/cli/empty_config.yaml @@ -1,6 +1,7 @@ --- - debug: - msg: START vyos_firewall_global empty_config integration tests on connection={{ + msg: + START vyos_firewall_global empty_config integration tests on connection={{ ansible_connection }} - name: Merged with empty config should give appropriate error message diff --git a/tests/integration/targets/vyos_firewall_global/tests/cli/parsed.yaml b/tests/integration/targets/vyos_firewall_global/tests/cli/parsed.yaml index b94d95e..82b7330 100644 --- a/tests/integration/targets/vyos_firewall_global/tests/cli/parsed.yaml +++ b/tests/integration/targets/vyos_firewall_global/tests/cli/parsed.yaml @@ -1,6 +1,7 @@ --- - debug: - msg: START vyos_firewall_global parsed integration tests on connection={{ ansible_connection + msg: + START vyos_firewall_global parsed integration tests on connection={{ ansible_connection }} - include_tasks: _remove_config.yaml @@ -8,7 +9,6 @@ - include_tasks: _populate.yaml - block: - - name: Gather firewall_global facts register: firewall_global_facts vyos.vyos.vyos_facts: @@ -25,7 +25,8 @@ - name: Assert that correct parsing done assert: - that: "{{ ansible_facts['network_resources']['firewall_global'] == result['parsed']\ + that: + "{{ ansible_facts['network_resources']['firewall_global'] == result['parsed']\ \ }}" - name: Gather the existing running configuration (IDEMPOTENT) @@ -37,5 +38,4 @@ that: - result['changed'] == false always: - - include_tasks: _remove_config.yaml diff --git a/tests/integration/targets/vyos_firewall_global/tests/cli/rendered.yaml b/tests/integration/targets/vyos_firewall_global/tests/cli/rendered.yaml index 528563e..16d585e 100644 --- a/tests/integration/targets/vyos_firewall_global/tests/cli/rendered.yaml +++ b/tests/integration/targets/vyos_firewall_global/tests/cli/rendered.yaml @@ -8,7 +8,6 @@ - include_tasks: _populate.yaml - block: - - name: Structure provided configuration into device specific commands register: result vyos.vyos.vyos_firewall_global: &id001 @@ -22,7 +21,6 @@ all: true broadcast: true state_policy: - - connection_type: established action: accept log: true @@ -30,7 +28,6 @@ - connection_type: invalid action: reject route_redirects: - - afi: ipv4 ip_src_route: true icmp_redirects: @@ -38,11 +35,9 @@ receive: false group: address_group: - - name: SALES-HOSTS description: Sales office hosts address list members: - - address: 192.0.2.1 - address: 192.0.2.2 @@ -52,16 +47,13 @@ - name: ENG-HOSTS description: Sales office hosts address list members: - - address: 192.0.3.1 - address: 192.0.3.2 network_group: - - name: MGMT description: This group has the Management network addresses members: - - address: 192.0.1.0/24 state: rendered @@ -80,5 +72,4 @@ that: - result['changed'] == false always: - - include_tasks: _remove_config.yaml diff --git a/tests/integration/targets/vyos_firewall_global/tests/cli/replaced.yaml b/tests/integration/targets/vyos_firewall_global/tests/cli/replaced.yaml index 31a7644..e213bdf 100644 --- a/tests/integration/targets/vyos_firewall_global/tests/cli/replaced.yaml +++ b/tests/integration/targets/vyos_firewall_global/tests/cli/replaced.yaml @@ -8,7 +8,6 @@ - include_tasks: _populate.yaml - block: - - name: Replace device configurations of listed firewall with provided configurations register: result vyos.vyos.vyos_firewall_global: &id001 @@ -22,7 +21,6 @@ all: true broadcast: true state_policy: - - connection_type: established action: accept log: true @@ -30,7 +28,6 @@ - connection_type: invalid action: reject route_redirects: - - afi: ipv4 ip_src_route: true icmp_redirects: @@ -38,11 +35,9 @@ receive: false group: address_group: - - name: SALES-HOSTS description: Sales office hosts address list members: - - address: 192.0.2.1 - address: 192.0.2.2 @@ -52,16 +47,13 @@ - name: ENG-HOSTS description: Sales office hosts address list members: - - address: 192.0.3.1 - address: 192.0.3.2 network_group: - - name: MGMT description: This group has the Management network addresses members: - - address: 192.0.1.0/24 state: replaced @@ -81,7 +73,8 @@ that: - "{{ replaced['after'] == result['after'] }}" - - name: Replace device configurations of listed firewall with provided configurarions + - name: + Replace device configurations of listed firewall with provided configurarions (IDEMPOTENT) register: result vyos.vyos.vyos_firewall_global: *id001 @@ -96,5 +89,4 @@ that: - "{{ replaced['after'] == result['before'] }}" always: - - include_tasks: _remove_config.yaml diff --git a/tests/integration/targets/vyos_firewall_global/tests/cli/rtt.yaml b/tests/integration/targets/vyos_firewall_global/tests/cli/rtt.yaml index 00c5635..ff24402 100644 --- a/tests/integration/targets/vyos_firewall_global/tests/cli/rtt.yaml +++ b/tests/integration/targets/vyos_firewall_global/tests/cli/rtt.yaml @@ -1,12 +1,12 @@ --- - debug: - msg: START vyos_firewall_global round trip integration tests on connection={{ + msg: + START vyos_firewall_global round trip integration tests on connection={{ ansible_connection }} - include_tasks: _remove_config.yaml - block: - - name: Apply the provided configuration (base config) register: base_config vyos.vyos.vyos_firewall_global: @@ -20,7 +20,6 @@ all: true broadcast: true state_policy: - - connection_type: established action: accept log: true @@ -28,7 +27,6 @@ - connection_type: invalid action: reject route_redirects: - - afi: ipv4 ip_src_route: true icmp_redirects: @@ -36,22 +34,18 @@ receive: false group: address_group: - - name: MGMT-HOSTS description: This group has the Management hosts address list members: - - address: 192.0.1.1 - address: 192.0.1.3 - address: 192.0.1.5 network_group: - - name: MGMT description: This group has the Management network addresses members: - - address: 192.0.1.0/24 state: merged @@ -90,5 +84,4 @@ assert: that: "{{ base_config['after'] == revert['after']}}" always: - - include_tasks: _remove_config.yaml diff --git a/tests/integration/targets/vyos_firewall_global/vars/main.yaml b/tests/integration/targets/vyos_firewall_global/vars/main.yaml index faa0ff1..9ec7a6e 100644 --- a/tests/integration/targets/vyos_firewall_global/vars/main.yaml +++ b/tests/integration/targets/vyos_firewall_global/vars/main.yaml @@ -185,7 +185,7 @@ rendered: - set firewall source-validation 'strict' deleted: commands: - - 'delete firewall ' + - "delete firewall " after: [] round_trip: after: diff --git a/tests/integration/targets/vyos_firewall_interfaces/defaults/main.yaml b/tests/integration/targets/vyos_firewall_interfaces/defaults/main.yaml index 852a6be..164afea 100644 --- a/tests/integration/targets/vyos_firewall_interfaces/defaults/main.yaml +++ b/tests/integration/targets/vyos_firewall_interfaces/defaults/main.yaml @@ -1,3 +1,3 @@ --- -testcase: '[^_].*' +testcase: "[^_].*" test_items: [] diff --git a/tests/integration/targets/vyos_firewall_interfaces/tasks/cli.yaml b/tests/integration/targets/vyos_firewall_interfaces/tasks/cli.yaml index 93eb2fe..83496e0 100644 --- a/tests/integration/targets/vyos_firewall_interfaces/tasks/cli.yaml +++ b/tests/integration/targets/vyos_firewall_interfaces/tasks/cli.yaml @@ -1,8 +1,8 @@ --- - name: Collect all cli test cases find: - paths: '{{ role_path }}/tests/cli' - patterns: '{{ testcase }}.yaml' + paths: "{{ role_path }}/tests/cli" + patterns: "{{ testcase }}.yaml" use_regex: true register: test_cases delegate_to: localhost @@ -11,9 +11,9 @@ set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}" - name: Run test case (connection=ansible.netcommon.network_cli) - include: '{{ test_case_to_run }}' + include: "{{ test_case_to_run }}" vars: ansible_connection: ansible.netcommon.network_cli - with_items: '{{ test_items }}' + with_items: "{{ test_items }}" loop_control: loop_var: test_case_to_run diff --git a/tests/integration/targets/vyos_firewall_interfaces/tests/cli/_populate.yaml b/tests/integration/targets/vyos_firewall_interfaces/tests/cli/_populate.yaml index 3e60c41..8b3dacd 100644 --- a/tests/integration/targets/vyos_firewall_interfaces/tests/cli/_populate.yaml +++ b/tests/integration/targets/vyos_firewall_interfaces/tests/cli/_populate.yaml @@ -1,7 +1,8 @@ --- - name: Setup vars: - lines: "set interfaces ethernet eth1 firewall in name 'INBOUND' \nset interfaces\ + lines: + "set interfaces ethernet eth1 firewall in name 'INBOUND' \nset interfaces\ \ ethernet eth1 firewall out name 'OUTBOUND' \nset interfaces ethernet eth1\ \ firewall local name 'LOCAL' \nset interfaces ethernet eth1 firewall local\ \ ipv6-name 'V6-LOCAL'\nset interfaces ethernet eth2 firewall in name 'INBOUND'\n\ @@ -9,4 +10,4 @@ \ ethernet eth2 firewall local name 'LOCAL' \nset interfaces ethernet eth2\ \ firewall local ipv6-name 'V6-LOCAL'\n" ansible.netcommon.cli_config: - config: '{{ lines }}' + config: "{{ lines }}" diff --git a/tests/integration/targets/vyos_firewall_interfaces/tests/cli/_populate_rule_sets.yaml b/tests/integration/targets/vyos_firewall_interfaces/tests/cli/_populate_rule_sets.yaml index 40a7f4a..d2fd3ee 100644 --- a/tests/integration/targets/vyos_firewall_interfaces/tests/cli/_populate_rule_sets.yaml +++ b/tests/integration/targets/vyos_firewall_interfaces/tests/cli/_populate_rule_sets.yaml @@ -1,7 +1,8 @@ --- - name: Setup vars: - lines: "set firewall name 'INBOUND'\nset firewall name 'OUTBOUND'\nset firewall\ + lines: + "set firewall name 'INBOUND'\nset firewall name 'OUTBOUND'\nset firewall\ \ name 'LOCAL'\nset firewall ipv6-name 'V6-LOCAL'\n" ansible.netcommon.cli_config: - config: '{{ lines }}' + config: "{{ lines }}" diff --git a/tests/integration/targets/vyos_firewall_interfaces/tests/cli/_remove_config.yaml b/tests/integration/targets/vyos_firewall_interfaces/tests/cli/_remove_config.yaml index 38a1800..c95fc00 100644 --- a/tests/integration/targets/vyos_firewall_interfaces/tests/cli/_remove_config.yaml +++ b/tests/integration/targets/vyos_firewall_interfaces/tests/cli/_remove_config.yaml @@ -1,7 +1,8 @@ --- - name: Remove Config vars: - lines: "delete interfaces ethernet eth1 firewall\ndelete interfaces ethernet\ + lines: + "delete interfaces ethernet eth1 firewall\ndelete interfaces ethernet\ \ eth2 firewall\n" ansible.netcommon.cli_config: - config: '{{ lines }}' + config: "{{ lines }}" diff --git a/tests/integration/targets/vyos_firewall_interfaces/tests/cli/_remove_firewall_config.yaml b/tests/integration/targets/vyos_firewall_interfaces/tests/cli/_remove_firewall_config.yaml index 0844749..da1b02c 100644 --- a/tests/integration/targets/vyos_firewall_interfaces/tests/cli/_remove_firewall_config.yaml +++ b/tests/integration/targets/vyos_firewall_interfaces/tests/cli/_remove_firewall_config.yaml @@ -4,4 +4,4 @@ lines: "delete firewall name INBOUND\ndelete firewall name OUTBOUND\ndelete\ \ firewall name LOCAL\ndelete firewall ipv6-name V6-LOCAL\n" ansible.netcommon.cli_config: - config: '{{ lines }}' + config: "{{ lines }}" diff --git a/tests/integration/targets/vyos_firewall_interfaces/tests/cli/deleted.yaml b/tests/integration/targets/vyos_firewall_interfaces/tests/cli/deleted.yaml index 078dd89..f1a0a4d 100644 --- a/tests/integration/targets/vyos_firewall_interfaces/tests/cli/deleted.yaml +++ b/tests/integration/targets/vyos_firewall_interfaces/tests/cli/deleted.yaml @@ -1,6 +1,7 @@ --- - debug: - msg: Start vyos_firewall_interfaces deleted integration tests ansible_connection={{ + msg: + Start vyos_firewall_interfaces deleted integration tests ansible_connection={{ ansible_connection }} - include_tasks: _populate_rule_sets.yaml @@ -8,12 +9,10 @@ - include_tasks: _populate.yaml - block: - - name: Delete attributes of given firewall rules. register: result vyos.vyos.vyos_firewall_interfaces: &id001 config: - - name: eth1 - name: eth2 @@ -52,7 +51,6 @@ - "{{ deleted['after'] | symmetric_difference(result['before']) |length\ \ == 0 }}" always: - - include_tasks: _remove_config.yaml - include_tasks: _remove_firewall_config.yaml diff --git a/tests/integration/targets/vyos_firewall_interfaces/tests/cli/deleted_afi.yaml b/tests/integration/targets/vyos_firewall_interfaces/tests/cli/deleted_afi.yaml index f7db06b..b33aea8 100644 --- a/tests/integration/targets/vyos_firewall_interfaces/tests/cli/deleted_afi.yaml +++ b/tests/integration/targets/vyos_firewall_interfaces/tests/cli/deleted_afi.yaml @@ -1,6 +1,7 @@ --- - debug: - msg: Start vyos_firewall_interfaces deleted integration tests ansible_connection={{ + msg: + Start vyos_firewall_interfaces deleted integration tests ansible_connection={{ ansible_connection }} - include_tasks: _populate_rule_sets.yaml @@ -8,22 +9,18 @@ - include_tasks: _populate.yaml - block: - - name: Delete firewall interfaces based on IP address type provided. register: result vyos.vyos.vyos_firewall_interfaces: &id001 config: - - name: eth1 access_rules: - - afi: ipv4 - afi: ipv6 - name: eth2 access_rules: - - afi: ipv4 - afi: ipv6 @@ -62,7 +59,6 @@ - "{{ deleted_afi['after'] | symmetric_difference(result['before']) |length\ \ == 0 }}" always: - - include_tasks: _remove_config.yaml - include_tasks: _remove_firewall_config.yaml diff --git a/tests/integration/targets/vyos_firewall_interfaces/tests/cli/deleted_all.yaml b/tests/integration/targets/vyos_firewall_interfaces/tests/cli/deleted_all.yaml index d85654c..1293f6a 100644 --- a/tests/integration/targets/vyos_firewall_interfaces/tests/cli/deleted_all.yaml +++ b/tests/integration/targets/vyos_firewall_interfaces/tests/cli/deleted_all.yaml @@ -1,6 +1,7 @@ --- - debug: - msg: Start vyos_firewall_interfaces deleted integration tests ansible_connection={{ + msg: + Start vyos_firewall_interfaces deleted integration tests ansible_connection={{ ansible_connection }} - include_tasks: _populate_rule_sets.yaml @@ -8,7 +9,6 @@ - include_tasks: _populate.yaml - block: - - name: Delete all the firewall interfaces. register: result vyos.vyos.vyos_firewall_interfaces: &id001 @@ -48,7 +48,6 @@ - "{{ deleted['after'] | symmetric_difference(result['before']) |length\ \ == 0 }}" always: - - include_tasks: _remove_config.yaml - include_tasks: _remove_firewall_config.yaml diff --git a/tests/integration/targets/vyos_firewall_interfaces/tests/cli/deleted_single.yaml b/tests/integration/targets/vyos_firewall_interfaces/tests/cli/deleted_single.yaml index f7e91f8..eb42c02 100644 --- a/tests/integration/targets/vyos_firewall_interfaces/tests/cli/deleted_single.yaml +++ b/tests/integration/targets/vyos_firewall_interfaces/tests/cli/deleted_single.yaml @@ -1,6 +1,7 @@ --- - debug: - msg: Start vyos_firewall_interfaces deleted integration tests ansible_connection={{ + msg: + Start vyos_firewall_interfaces deleted integration tests ansible_connection={{ ansible_connection }} - include_tasks: _populate_rule_sets.yaml @@ -8,18 +9,14 @@ - include_tasks: _populate.yaml - block: - - name: Delete firewall interface. register: result vyos.vyos.vyos_firewall_interfaces: &id001 config: - - name: eth1 access_rules: - - afi: ipv4 rules: - - direction: in name: INBOUND state: deleted @@ -57,7 +54,6 @@ - "{{ deleted_single['after'] | symmetric_difference(result['before'])\ \ |length == 0 }}" always: - - include_tasks: _remove_config.yaml - include_tasks: _remove_firewall_config.yaml diff --git a/tests/integration/targets/vyos_firewall_interfaces/tests/cli/empty_config.yaml b/tests/integration/targets/vyos_firewall_interfaces/tests/cli/empty_config.yaml index 66c49bf..1b9eb34 100644 --- a/tests/integration/targets/vyos_firewall_interfaces/tests/cli/empty_config.yaml +++ b/tests/integration/targets/vyos_firewall_interfaces/tests/cli/empty_config.yaml @@ -1,6 +1,7 @@ --- - debug: - msg: START vyos_firewall_interfaces empty_config integration tests on connection={{ + msg: + START vyos_firewall_interfaces empty_config integration tests on connection={{ ansible_connection }} - name: Merged with empty config should give appropriate error message diff --git a/tests/integration/targets/vyos_firewall_interfaces/tests/cli/overridden.yaml b/tests/integration/targets/vyos_firewall_interfaces/tests/cli/overridden.yaml index 01d30b6..5776718 100644 --- a/tests/integration/targets/vyos_firewall_interfaces/tests/cli/overridden.yaml +++ b/tests/integration/targets/vyos_firewall_interfaces/tests/cli/overridden.yaml @@ -1,6 +1,7 @@ --- - debug: - msg: START vyos_firewall_interfaces overridden integration tests on connection={{ + msg: + START vyos_firewall_interfaces overridden integration tests on connection={{ ansible_connection }} - include_tasks: _remove_config.yaml @@ -12,18 +13,14 @@ - include_tasks: _populate.yaml - block: - - name: Overrides all device configuration with provided configuration register: result vyos.vyos.vyos_firewall_interfaces: &id001 config: - - name: eth2 access_rules: - - afi: ipv4 rules: - - name: INBOUND direction: out state: overridden @@ -60,7 +57,6 @@ - "{{ overridden['after'] | symmetric_difference(result['before']) |length\ \ == 0 }}" always: - - include_tasks: _remove_config.yaml - include_tasks: _remove_firewall_config.yaml diff --git a/tests/integration/targets/vyos_firewall_interfaces/tests/cli/parsed.yaml b/tests/integration/targets/vyos_firewall_interfaces/tests/cli/parsed.yaml index c7032e1..105c647 100644 --- a/tests/integration/targets/vyos_firewall_interfaces/tests/cli/parsed.yaml +++ b/tests/integration/targets/vyos_firewall_interfaces/tests/cli/parsed.yaml @@ -1,6 +1,7 @@ --- - debug: - msg: START vyos_firewall_interfaces parsed integration tests on connection={{ + msg: + START vyos_firewall_interfaces parsed integration tests on connection={{ ansible_connection }} - include_tasks: _remove_config.yaml @@ -12,7 +13,6 @@ - include_tasks: _populate.yaml - block: - - name: Gather firewall_interfaces facts register: firewall_interfaces_facts vyos.vyos.vyos_facts: @@ -29,7 +29,8 @@ - name: Assert that correct parsing done assert: - that: "{{ ansible_facts['network_resources']['firewall_interfaces'] | symmetric_difference(result['parsed'])\ + that: + "{{ ansible_facts['network_resources']['firewall_interfaces'] | symmetric_difference(result['parsed'])\ \ |length == 0 }}" - name: Gather the existing running configuration (IDEMPOTENT) @@ -41,7 +42,6 @@ that: - result['changed'] == false always: - - include_tasks: _remove_config.yaml - include_tasks: _remove_firewall_config.yaml diff --git a/tests/integration/targets/vyos_firewall_interfaces/tests/cli/rendered.yaml b/tests/integration/targets/vyos_firewall_interfaces/tests/cli/rendered.yaml index 022dd50..3283ec6 100644 --- a/tests/integration/targets/vyos_firewall_interfaces/tests/cli/rendered.yaml +++ b/tests/integration/targets/vyos_firewall_interfaces/tests/cli/rendered.yaml @@ -1,21 +1,18 @@ --- - debug: - msg: START vyos_firewall_interfaces rendered integration tests on connection={{ + msg: + START vyos_firewall_interfaces rendered integration tests on connection={{ ansible_connection }} - block: - - name: Structure provided configuration into device specific commands register: result vyos.vyos.vyos_firewall_interfaces: &id001 config: - - name: eth1 access_rules: - - afi: ipv4 rules: - - name: INBOUND direction: in @@ -27,16 +24,13 @@ - afi: ipv6 rules: - - name: V6-LOCAL direction: local - name: eth2 access_rules: - - afi: ipv4 rules: - - name: INBOUND direction: in @@ -48,7 +42,6 @@ - afi: ipv6 rules: - - name: V6-LOCAL direction: local state: rendered @@ -68,5 +61,4 @@ that: - result['changed'] == false always: - - include_tasks: _remove_config.yaml diff --git a/tests/integration/targets/vyos_firewall_interfaces/tests/cli/replaced.yaml b/tests/integration/targets/vyos_firewall_interfaces/tests/cli/replaced.yaml index b2b0067..d82a0f6 100644 --- a/tests/integration/targets/vyos_firewall_interfaces/tests/cli/replaced.yaml +++ b/tests/integration/targets/vyos_firewall_interfaces/tests/cli/replaced.yaml @@ -1,6 +1,7 @@ --- - debug: - msg: START vyos_firewall_interfaces replaced integration tests on connection={{ + msg: + START vyos_firewall_interfaces replaced integration tests on connection={{ ansible_connection }} - include_tasks: _remove_config.yaml @@ -12,34 +13,27 @@ - include_tasks: _populate.yaml - block: - - name: Replace device configurations of listed firewall rules with provided configurations register: result vyos.vyos.vyos_firewall_interfaces: &id001 config: - - name: eth1 access_rules: - - afi: ipv4 rules: - - name: OUTBOUND direction: out - afi: ipv6 rules: - - name: V6-LOCAL direction: local - name: eth2 access_rules: - - afi: ipv4 rules: - - name: INBOUND direction: in state: replaced @@ -77,7 +71,6 @@ - "{{ replaced['after'] | symmetric_difference(result['before']) |length\ \ == 0 }}" always: - - include_tasks: _remove_config.yaml - include_tasks: _remove_firewall_config.yaml diff --git a/tests/integration/targets/vyos_firewall_interfaces/tests/cli/rtt.yaml b/tests/integration/targets/vyos_firewall_interfaces/tests/cli/rtt.yaml index 9155b7c..ff3abb1 100644 --- a/tests/integration/targets/vyos_firewall_interfaces/tests/cli/rtt.yaml +++ b/tests/integration/targets/vyos_firewall_interfaces/tests/cli/rtt.yaml @@ -1,6 +1,7 @@ --- - debug: - msg: START vyos_firewall_interfaces round trip integration tests on connection={{ + msg: + START vyos_firewall_interfaces round trip integration tests on connection={{ ansible_connection }} - include_tasks: _remove_config.yaml @@ -10,18 +11,14 @@ - include_tasks: _populate_rule_sets.yaml - block: - - name: Apply the provided configuration (base config) register: base_config vyos.vyos.vyos_firewall_interfaces: config: - - name: eth1 access_rules: - - afi: ipv4 rules: - - name: INBOUND direction: in @@ -33,7 +30,6 @@ - afi: ipv6 rules: - - name: V6-LOCAL direction: local state: merged @@ -49,13 +45,10 @@ register: result vyos.vyos.vyos_firewall_interfaces: config: - - name: eth2 access_rules: - - afi: ipv4 rules: - - name: INBOUND direction: in @@ -67,14 +60,14 @@ - afi: ipv6 rules: - - name: V6-LOCAL direction: local state: merged - name: Assert that changes were applied assert: - that: "{{ round_trip['after'] | symmetric_difference(result['after']) |length\ + that: + "{{ round_trip['after'] | symmetric_difference(result['after']) |length\ \ == 0 }}" - name: Revert back to base config using facts round trip @@ -85,10 +78,10 @@ - name: Assert that config was reverted assert: - that: "{{ base_config['after'] | symmetric_difference(revert['after']) |length\ + that: + "{{ base_config['after'] | symmetric_difference(revert['after']) |length\ \ == 0 }}" always: - - include_tasks: _remove_config.yaml - include_tasks: _remove_firewall_config.yaml diff --git a/tests/integration/targets/vyos_firewall_rules/defaults/main.yaml b/tests/integration/targets/vyos_firewall_rules/defaults/main.yaml index 852a6be..164afea 100644 --- a/tests/integration/targets/vyos_firewall_rules/defaults/main.yaml +++ b/tests/integration/targets/vyos_firewall_rules/defaults/main.yaml @@ -1,3 +1,3 @@ --- -testcase: '[^_].*' +testcase: "[^_].*" test_items: [] diff --git a/tests/integration/targets/vyos_firewall_rules/tasks/cli.yaml b/tests/integration/targets/vyos_firewall_rules/tasks/cli.yaml index 93eb2fe..83496e0 100644 --- a/tests/integration/targets/vyos_firewall_rules/tasks/cli.yaml +++ b/tests/integration/targets/vyos_firewall_rules/tasks/cli.yaml @@ -1,8 +1,8 @@ --- - name: Collect all cli test cases find: - paths: '{{ role_path }}/tests/cli' - patterns: '{{ testcase }}.yaml' + paths: "{{ role_path }}/tests/cli" + patterns: "{{ testcase }}.yaml" use_regex: true register: test_cases delegate_to: localhost @@ -11,9 +11,9 @@ set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}" - name: Run test case (connection=ansible.netcommon.network_cli) - include: '{{ test_case_to_run }}' + include: "{{ test_case_to_run }}" vars: ansible_connection: ansible.netcommon.network_cli - with_items: '{{ test_items }}' + with_items: "{{ test_items }}" loop_control: loop_var: test_case_to_run diff --git a/tests/integration/targets/vyos_firewall_rules/tests/cli/_populate.yaml b/tests/integration/targets/vyos_firewall_rules/tests/cli/_populate.yaml index 551736e..12adf4f 100644 --- a/tests/integration/targets/vyos_firewall_rules/tests/cli/_populate.yaml +++ b/tests/integration/targets/vyos_firewall_rules/tests/cli/_populate.yaml @@ -1,7 +1,8 @@ --- - name: Setup vars: - lines: "set firewall group address-group 'inbound'\nset firewall ipv6-name UPLINK\ + lines: + "set firewall group address-group 'inbound'\nset firewall ipv6-name UPLINK\ \ default-action 'accept'\nset firewall ipv6-name UPLINK description 'This\ \ is ipv6 specific rule-set'\nset firewall ipv6-name UPLINK rule 1 action\ \ 'accept'\nset firewall ipv6-name UPLINK rule 1 description 'Fwipv6-Rule\ @@ -24,4 +25,4 @@ \ firewall name INBOUND rule 103 state new 'disable'\nset firewall name INBOUND\ \ rule 103 state related 'enable'\n" ansible.netcommon.cli_config: - config: '{{ lines }}' + config: "{{ lines }}" diff --git a/tests/integration/targets/vyos_firewall_rules/tests/cli/_remove_config.yaml b/tests/integration/targets/vyos_firewall_rules/tests/cli/_remove_config.yaml index acb0803..b4fc796 100644 --- a/tests/integration/targets/vyos_firewall_rules/tests/cli/_remove_config.yaml +++ b/tests/integration/targets/vyos_firewall_rules/tests/cli/_remove_config.yaml @@ -3,4 +3,4 @@ vars: lines: "delete firewall ipv6-name\ndelete firewall name\n" ansible.netcommon.cli_config: - config: '{{ lines }}' + config: "{{ lines }}" diff --git a/tests/integration/targets/vyos_firewall_rules/tests/cli/deleted.yaml b/tests/integration/targets/vyos_firewall_rules/tests/cli/deleted.yaml index 67bfd3c..6a830f9 100644 --- a/tests/integration/targets/vyos_firewall_rules/tests/cli/deleted.yaml +++ b/tests/integration/targets/vyos_firewall_rules/tests/cli/deleted.yaml @@ -1,12 +1,12 @@ --- - debug: - msg: Start vyos_firewall_rules deleted integration tests ansible_connection={{ + msg: + Start vyos_firewall_rules deleted integration tests ansible_connection={{ ansible_connection }} - include_tasks: _populate.yaml - block: - - name: Delete firewall rule set. register: result vyos.vyos.vyos_firewall_rules: &id001 @@ -52,5 +52,4 @@ - "{{ deleted_rs['after'] | symmetric_difference(result['before']) |length\ \ == 0 }}" always: - - include_tasks: _remove_config.yaml diff --git a/tests/integration/targets/vyos_firewall_rules/tests/cli/deleted_afi.yaml b/tests/integration/targets/vyos_firewall_rules/tests/cli/deleted_afi.yaml index e20670d..e104171 100644 --- a/tests/integration/targets/vyos_firewall_rules/tests/cli/deleted_afi.yaml +++ b/tests/integration/targets/vyos_firewall_rules/tests/cli/deleted_afi.yaml @@ -1,17 +1,16 @@ --- - debug: - msg: Start vyos_firewall_rules deleted integration tests ansible_connection={{ + msg: + Start vyos_firewall_rules deleted integration tests ansible_connection={{ ansible_connection }} - include_tasks: _populate.yaml - block: - - name: Delete firewall rule. register: result vyos.vyos.vyos_firewall_rules: &id001 config: - - afi: ipv6 - afi: ipv4 @@ -50,5 +49,4 @@ - "{{ deleted_afi_all['after'] | symmetric_difference(result['before'])\ \ |length == 0 }}" always: - - include_tasks: _remove_config.yaml diff --git a/tests/integration/targets/vyos_firewall_rules/tests/cli/deleted_all.yaml b/tests/integration/targets/vyos_firewall_rules/tests/cli/deleted_all.yaml index 16e563c..9df5127 100644 --- a/tests/integration/targets/vyos_firewall_rules/tests/cli/deleted_all.yaml +++ b/tests/integration/targets/vyos_firewall_rules/tests/cli/deleted_all.yaml @@ -1,12 +1,12 @@ --- - debug: - msg: Start vyos_firewall_rules deleted integration tests ansible_connection={{ + msg: + Start vyos_firewall_rules deleted integration tests ansible_connection={{ ansible_connection }} - include_tasks: _populate.yaml - block: - - name: Delete all the firewall rules. register: result vyos.vyos.vyos_firewall_rules: &id001 @@ -46,5 +46,4 @@ - "{{ deleted_afi_all['after'] | symmetric_difference(result['before'])\ \ |length == 0 }}" always: - - include_tasks: _remove_config.yaml diff --git a/tests/integration/targets/vyos_firewall_rules/tests/cli/empty_config.yaml b/tests/integration/targets/vyos_firewall_rules/tests/cli/empty_config.yaml index c30cf03..ba71e71 100644 --- a/tests/integration/targets/vyos_firewall_rules/tests/cli/empty_config.yaml +++ b/tests/integration/targets/vyos_firewall_rules/tests/cli/empty_config.yaml @@ -1,6 +1,7 @@ --- - debug: - msg: START vyos_firewall_rules empty_config integration tests on connection={{ + msg: + START vyos_firewall_rules empty_config integration tests on connection={{ ansible_connection }} - name: Merged with empty config should give appropriate error message diff --git a/tests/integration/targets/vyos_firewall_rules/tests/cli/overridden.yaml b/tests/integration/targets/vyos_firewall_rules/tests/cli/overridden.yaml index 6acc951..aac79e5 100644 --- a/tests/integration/targets/vyos_firewall_rules/tests/cli/overridden.yaml +++ b/tests/integration/targets/vyos_firewall_rules/tests/cli/overridden.yaml @@ -8,20 +8,16 @@ - include_tasks: _populate.yaml - block: - - name: Overrides all device configuration with provided configuration register: result vyos.vyos.vyos_firewall_rules: &id001 config: - - afi: ipv4 rule_sets: - - name: Downlink description: IPv4 INBOUND rule set default_action: accept rules: - - number: 501 action: accept description: Rule 501 is configured by Ansible @@ -65,5 +61,4 @@ - "{{ overridden['after'] | symmetric_difference(result['before']) |length\ \ == 0 }}" always: - - include_tasks: _remove_config.yaml diff --git a/tests/integration/targets/vyos_firewall_rules/tests/cli/parsed.yaml b/tests/integration/targets/vyos_firewall_rules/tests/cli/parsed.yaml index bc95524..3e4c972 100644 --- a/tests/integration/targets/vyos_firewall_rules/tests/cli/parsed.yaml +++ b/tests/integration/targets/vyos_firewall_rules/tests/cli/parsed.yaml @@ -1,6 +1,7 @@ --- - debug: - msg: START vyos_firewall_rules parsed integration tests on connection={{ ansible_connection + msg: + START vyos_firewall_rules parsed integration tests on connection={{ ansible_connection }} - name: Parse externally provided Firewall rules config to agnostic model diff --git a/tests/integration/targets/vyos_firewall_rules/tests/cli/rendered.yaml b/tests/integration/targets/vyos_firewall_rules/tests/cli/rendered.yaml index 6670fd7..d376744 100644 --- a/tests/integration/targets/vyos_firewall_rules/tests/cli/rendered.yaml +++ b/tests/integration/targets/vyos_firewall_rules/tests/cli/rendered.yaml @@ -1,32 +1,28 @@ --- - debug: - msg: START vyos_firewall_rules rendered integration tests on connection={{ ansible_connection + msg: + START vyos_firewall_rules rendered integration tests on connection={{ ansible_connection }} - include_tasks: _remove_config.yaml - block: - - name: Structure provided configuration into device specific commands register: result vyos.vyos.vyos_firewall_rules: config: - - afi: ipv6 rule_sets: - - name: UPLINK description: This is ipv6 specific rule-set default_action: accept - afi: ipv4 rule_sets: - - name: INBOUND description: IPv4 INBOUND rule set default_action: accept rules: - - number: 101 action: accept description: Rule 101 is configured by Ansible diff --git a/tests/integration/targets/vyos_firewall_rules/tests/cli/replaced.yaml b/tests/integration/targets/vyos_firewall_rules/tests/cli/replaced.yaml index eba1689..850aa60 100644 --- a/tests/integration/targets/vyos_firewall_rules/tests/cli/replaced.yaml +++ b/tests/integration/targets/vyos_firewall_rules/tests/cli/replaced.yaml @@ -1,6 +1,7 @@ --- - debug: - msg: START vyos_firewall_rules replaced integration tests on connection={{ ansible_connection + msg: + START vyos_firewall_rules replaced integration tests on connection={{ ansible_connection }} - include_tasks: _remove_config.yaml @@ -8,28 +9,23 @@ - include_tasks: _populate.yaml - block: - - name: Replace device configurations of listed firewall rules with provided configurations register: result vyos.vyos.vyos_firewall_rules: &id001 config: - - afi: ipv6 rule_sets: - - name: UPLINK description: This is ipv6 specific rule-set default_action: accept - afi: ipv4 rule_sets: - - name: INBOUND description: IPv4 INBOUND rule set default_action: accept rules: - - number: 101 action: accept description: Rule 101 is configured by Ansible @@ -74,5 +70,4 @@ - "{{ replaced['after'] | symmetric_difference(result['before']) |length\ \ == 0 }}" always: - - include_tasks: _remove_config.yaml diff --git a/tests/integration/targets/vyos_firewall_rules/tests/cli/rtt.yaml b/tests/integration/targets/vyos_firewall_rules/tests/cli/rtt.yaml index 762086f..f3f4252 100644 --- a/tests/integration/targets/vyos_firewall_rules/tests/cli/rtt.yaml +++ b/tests/integration/targets/vyos_firewall_rules/tests/cli/rtt.yaml @@ -6,20 +6,16 @@ - include_tasks: _remove_config.yaml - block: - - name: Apply the provided configuration (base config) register: base_config vyos.vyos.vyos_firewall_rules: config: - - afi: ipv6 rule_sets: - - name: UPLINK description: This is ipv6 specific rule-set default_action: accept rules: - - number: 1 action: accept description: Fwipv6-Rule 1 is configured by Ansible @@ -32,12 +28,10 @@ - afi: ipv4 rule_sets: - - name: INBOUND description: IPv4 INBOUND rule set default_action: accept rules: - - number: 101 action: accept description: Rule 101 is configured by Ansible @@ -60,15 +54,12 @@ register: result vyos.vyos.vyos_firewall_rules: config: - - afi: ipv4 rule_sets: - - name: INBOUND description: IPv4 INBOUND rule set default_action: accept rules: - - number: 103 action: accept description: Rule 103 is configured by Ansible @@ -83,7 +74,8 @@ - name: Assert that changes were applied assert: - that: "{{ round_trip['after'] | symmetric_difference(result['after']) |length\ + that: + "{{ round_trip['after'] | symmetric_difference(result['after']) |length\ \ == 0 }}" - name: Revert back to base config using facts round trip @@ -94,8 +86,8 @@ - name: Assert that config was reverted assert: - that: "{{ base_config['after'] | symmetric_difference(revert['after']) |length\ + that: + "{{ base_config['after'] | symmetric_difference(revert['after']) |length\ \ == 0 }}" always: - - include_tasks: _remove_config.yaml diff --git a/tests/integration/targets/vyos_hostname/defaults/main.yaml b/tests/integration/targets/vyos_hostname/defaults/main.yaml index 852a6be..164afea 100644 --- a/tests/integration/targets/vyos_hostname/defaults/main.yaml +++ b/tests/integration/targets/vyos_hostname/defaults/main.yaml @@ -1,3 +1,3 @@ --- -testcase: '[^_].*' +testcase: "[^_].*" test_items: [] diff --git a/tests/integration/targets/vyos_hostname/meta/main.yaml b/tests/integration/targets/vyos_hostname/meta/main.yaml index 91da2a7..ed97d53 100644 --- a/tests/integration/targets/vyos_hostname/meta/main.yaml +++ b/tests/integration/targets/vyos_hostname/meta/main.yaml @@ -1,2 +1 @@ --- -... diff --git a/tests/integration/targets/vyos_hostname/tasks/cli.yaml b/tests/integration/targets/vyos_hostname/tasks/cli.yaml index 93eb2fe..83496e0 100644 --- a/tests/integration/targets/vyos_hostname/tasks/cli.yaml +++ b/tests/integration/targets/vyos_hostname/tasks/cli.yaml @@ -1,8 +1,8 @@ --- - name: Collect all cli test cases find: - paths: '{{ role_path }}/tests/cli' - patterns: '{{ testcase }}.yaml' + paths: "{{ role_path }}/tests/cli" + patterns: "{{ testcase }}.yaml" use_regex: true register: test_cases delegate_to: localhost @@ -11,9 +11,9 @@ set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}" - name: Run test case (connection=ansible.netcommon.network_cli) - include: '{{ test_case_to_run }}' + include: "{{ test_case_to_run }}" vars: ansible_connection: ansible.netcommon.network_cli - with_items: '{{ test_items }}' + with_items: "{{ test_items }}" loop_control: loop_var: test_case_to_run diff --git a/tests/integration/targets/vyos_hostname/tests/cli/deleted.yaml b/tests/integration/targets/vyos_hostname/tests/cli/deleted.yaml index 5f9df51..2c052f4 100644 --- a/tests/integration/targets/vyos_hostname/tests/cli/deleted.yaml +++ b/tests/integration/targets/vyos_hostname/tests/cli/deleted.yaml @@ -7,7 +7,6 @@ - include_tasks: _populate_config.yaml - block: - - name: Delete the provided configuration register: result vyos.vyos.vyos_hostname: &id001 @@ -25,7 +24,8 @@ that: - result.after == {} - - name: Delete the existing configuration with the provided running configuration + - name: + Delete the existing configuration with the provided running configuration (IDEMPOTENT) register: result vyos.vyos.vyos_hostname: *id001 @@ -36,5 +36,4 @@ - result['changed'] == false always: - - include_tasks: _remove_config.yaml diff --git a/tests/integration/targets/vyos_hostname/tests/cli/gathered.yaml b/tests/integration/targets/vyos_hostname/tests/cli/gathered.yaml index 0509fc5..f3eacad 100644 --- a/tests/integration/targets/vyos_hostname/tests/cli/gathered.yaml +++ b/tests/integration/targets/vyos_hostname/tests/cli/gathered.yaml @@ -8,7 +8,6 @@ - include_tasks: _populate_config.yaml - block: - - name: Gather config from the device in structured format. register: result vyos.vyos.vyos_hostname: @@ -24,5 +23,4 @@ - result.gathered == ansible_facts['network_resources']['hostname'] always: - - include_tasks: _remove_config.yaml diff --git a/tests/integration/targets/vyos_hostname/tests/cli/merged.yaml b/tests/integration/targets/vyos_hostname/tests/cli/merged.yaml index f9b28c7..14ed1df 100644 --- a/tests/integration/targets/vyos_hostname/tests/cli/merged.yaml +++ b/tests/integration/targets/vyos_hostname/tests/cli/merged.yaml @@ -24,7 +24,6 @@ - result.after == ansible_facts['network_resources']['hostname'] - result.after == merged.after - - name: Assert that before dicts were correctly generated assert: that: diff --git a/tests/integration/targets/vyos_hostname/tests/cli/overridden.yaml b/tests/integration/targets/vyos_hostname/tests/cli/overridden.yaml index d9fd76d..a50ef64 100644 --- a/tests/integration/targets/vyos_hostname/tests/cli/overridden.yaml +++ b/tests/integration/targets/vyos_hostname/tests/cli/overridden.yaml @@ -26,7 +26,6 @@ - result.after == ansible_facts['network_resources']['hostname'] - result.after == merged.after - - name: override the provided configuration with the existing running configuration (IDEMPOTENT) diff --git a/tests/integration/targets/vyos_hostname/tests/cli/parsed.yaml b/tests/integration/targets/vyos_hostname/tests/cli/parsed.yaml index f6c00bb..b1aa806 100644 --- a/tests/integration/targets/vyos_hostname/tests/cli/parsed.yaml +++ b/tests/integration/targets/vyos_hostname/tests/cli/parsed.yaml @@ -1,6 +1,7 @@ --- - debug: - msg: START vyos_hostname parsed integration tests on connection={{ ansible_connection + msg: + START vyos_hostname parsed integration tests on connection={{ ansible_connection }} - name: Provide the running configuration for parsing (config to be parsed) @@ -9,7 +10,6 @@ running_config: "{{ lookup('file', '_parsed.cfg') }}" state: parsed - - name: Assert that config was correctly parsed assert: that: diff --git a/tests/integration/targets/vyos_hostname/tests/cli/rendered.yaml b/tests/integration/targets/vyos_hostname/tests/cli/rendered.yaml index 28ec797..25c81b2 100644 --- a/tests/integration/targets/vyos_hostname/tests/cli/rendered.yaml +++ b/tests/integration/targets/vyos_hostname/tests/cli/rendered.yaml @@ -10,7 +10,7 @@ register: result vyos.vyos.vyos_hostname: config: - hostname: 'vyosTest' + hostname: "vyosTest" state: rendered - assert: diff --git a/tests/integration/targets/vyos_hostname/tests/cli/replaced.yaml b/tests/integration/targets/vyos_hostname/tests/cli/replaced.yaml index 6acb993..7d9b522 100644 --- a/tests/integration/targets/vyos_hostname/tests/cli/replaced.yaml +++ b/tests/integration/targets/vyos_hostname/tests/cli/replaced.yaml @@ -26,7 +26,6 @@ - result.after == ansible_facts['network_resources']['hostname'] - result.after == merged.after - - name: Replace the provided configuration with the existing running configuration (IDEMPOTENT) diff --git a/tests/integration/targets/vyos_hostname/vars/main.yaml b/tests/integration/targets/vyos_hostname/vars/main.yaml index 615da43..ca02d03 100644 --- a/tests/integration/targets/vyos_hostname/vars/main.yaml +++ b/tests/integration/targets/vyos_hostname/vars/main.yaml @@ -4,7 +4,7 @@ merged: commands: - set system host-name vyosTest after: - hostname: 'vyosTest' + hostname: "vyosTest" deleted: commands: diff --git a/tests/integration/targets/vyos_interfaces/defaults/main.yaml b/tests/integration/targets/vyos_interfaces/defaults/main.yaml index 852a6be..164afea 100644 --- a/tests/integration/targets/vyos_interfaces/defaults/main.yaml +++ b/tests/integration/targets/vyos_interfaces/defaults/main.yaml @@ -1,3 +1,3 @@ --- -testcase: '[^_].*' +testcase: "[^_].*" test_items: [] diff --git a/tests/integration/targets/vyos_interfaces/tasks/cli.yaml b/tests/integration/targets/vyos_interfaces/tasks/cli.yaml index 93eb2fe..83496e0 100644 --- a/tests/integration/targets/vyos_interfaces/tasks/cli.yaml +++ b/tests/integration/targets/vyos_interfaces/tasks/cli.yaml @@ -1,8 +1,8 @@ --- - name: Collect all cli test cases find: - paths: '{{ role_path }}/tests/cli' - patterns: '{{ testcase }}.yaml' + paths: "{{ role_path }}/tests/cli" + patterns: "{{ testcase }}.yaml" use_regex: true register: test_cases delegate_to: localhost @@ -11,9 +11,9 @@ set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}" - name: Run test case (connection=ansible.netcommon.network_cli) - include: '{{ test_case_to_run }}' + include: "{{ test_case_to_run }}" vars: ansible_connection: ansible.netcommon.network_cli - with_items: '{{ test_items }}' + with_items: "{{ test_items }}" loop_control: loop_var: test_case_to_run diff --git a/tests/integration/targets/vyos_interfaces/tasks/redirection.yaml b/tests/integration/targets/vyos_interfaces/tasks/redirection.yaml index 5564a3e..48ad53a 100644 --- a/tests/integration/targets/vyos_interfaces/tasks/redirection.yaml +++ b/tests/integration/targets/vyos_interfaces/tasks/redirection.yaml @@ -1,8 +1,8 @@ --- - name: collect all redirection cli test cases find: - paths: '{{ role_path }}/tests/redirection/cli' - patterns: '{{ testcase }}.yaml' + paths: "{{ role_path }}/tests/redirection/cli" + patterns: "{{ testcase }}.yaml" register: shortname_test_cases delegate_to: localhost @@ -10,7 +10,7 @@ set_fact: test_items="{{ shortname_test_cases.files | map(attribute='path') | list }}" - name: run test case (connection=ansible.netcommon.network_cli) - include: '{{ test_case_to_run }} ansible_connection=ansible.netcommon.network_cli' - with_items: '{{ test_items }}' + include: "{{ test_case_to_run }} ansible_connection=ansible.netcommon.network_cli" + with_items: "{{ test_items }}" loop_control: loop_var: test_case_to_run diff --git a/tests/integration/targets/vyos_interfaces/tests/cli/_populate.yaml b/tests/integration/targets/vyos_interfaces/tests/cli/_populate.yaml index 686236f..702930c 100644 --- a/tests/integration/targets/vyos_interfaces/tests/cli/_populate.yaml +++ b/tests/integration/targets/vyos_interfaces/tests/cli/_populate.yaml @@ -1,7 +1,8 @@ --- - name: Setup vars: - lines: "set interfaces ethernet \"{{ intf }}\" description 'Configured by Ansible'\n\ + lines: + "set interfaces ethernet \"{{ intf }}\" description 'Configured by Ansible'\n\ set interfaces ethernet \"{{ intf }}\" speed 'auto'\nset interfaces ethernet\ \ \"{{ intf }}\" duplex 'auto'\nset interfaces ethernet \"{{ intf }}\" mtu\ \ '1500'\nset interfaces ethernet \"{{ intf }}\" vif 200\nset interfaces ethernet\ @@ -12,4 +13,4 @@ loop_control: loop_var: intf ansible.netcommon.cli_config: - config: '{{ lines }}' + config: "{{ lines }}" diff --git a/tests/integration/targets/vyos_interfaces/tests/cli/_remove_config.yaml b/tests/integration/targets/vyos_interfaces/tests/cli/_remove_config.yaml index 298cf5d..6353d1c 100644 --- a/tests/integration/targets/vyos_interfaces/tests/cli/_remove_config.yaml +++ b/tests/integration/targets/vyos_interfaces/tests/cli/_remove_config.yaml @@ -1,7 +1,8 @@ --- - name: Remove Config vars: - lines: "delete interfaces ethernet \"{{ intf }}\" description\ndelete interfaces\ + lines: + "delete interfaces ethernet \"{{ intf }}\" description\ndelete interfaces\ \ ethernet \"{{ intf }}\" speed\ndelete interfaces ethernet \"{{ intf }}\"\ \ duplex\ndelete interfaces ethernet \"{{ intf }}\" mtu\ndelete interfaces\ \ ethernet \"{{ intf }}\" disable\ndelete interfaces ethernet \"{{ intf }}\"\ @@ -12,4 +13,4 @@ loop_control: loop_var: intf ansible.netcommon.cli_config: - config: '{{ lines }}' + config: "{{ lines }}" diff --git a/tests/integration/targets/vyos_interfaces/tests/cli/deleted.yaml b/tests/integration/targets/vyos_interfaces/tests/cli/deleted.yaml index 56e747a..2c12ff2 100644 --- a/tests/integration/targets/vyos_interfaces/tests/cli/deleted.yaml +++ b/tests/integration/targets/vyos_interfaces/tests/cli/deleted.yaml @@ -1,17 +1,16 @@ --- - debug: - msg: Start vyos_interfaces deleted integration tests ansible_connection={{ ansible_connection + msg: + Start vyos_interfaces deleted integration tests ansible_connection={{ ansible_connection }} - include_tasks: _populate.yaml - block: - - name: Delete attributes of given interfaces register: result vyos.vyos.vyos_interfaces: &id001 config: - - name: eth1 - name: eth2 @@ -49,5 +48,4 @@ - "{{ deleted['after'] | symmetric_difference(result['before']) |length\ \ == 0 }}" always: - - include_tasks: _remove_config.yaml diff --git a/tests/integration/targets/vyos_interfaces/tests/cli/overridden.yaml b/tests/integration/targets/vyos_interfaces/tests/cli/overridden.yaml index 9921e5d..d4052c8 100644 --- a/tests/integration/targets/vyos_interfaces/tests/cli/overridden.yaml +++ b/tests/integration/targets/vyos_interfaces/tests/cli/overridden.yaml @@ -1,6 +1,7 @@ --- - debug: - msg: START vyos_interfaces overridden integration tests on connection={{ ansible_connection + msg: + START vyos_interfaces overridden integration tests on connection={{ ansible_connection }} - include_tasks: _remove_config.yaml @@ -8,12 +9,10 @@ - include_tasks: _populate.yaml - block: - - name: Overrides all device configuration with provided configuration register: result vyos.vyos.vyos_interfaces: &id001 config: - - name: eth0 speed: auto duplex: auto @@ -55,5 +54,4 @@ - "{{ overridden['after'] | symmetric_difference(result['before']) |length\ \ == 0 }}" always: - - include_tasks: _remove_config.yaml diff --git a/tests/integration/targets/vyos_interfaces/tests/cli/parsed.yaml b/tests/integration/targets/vyos_interfaces/tests/cli/parsed.yaml index a44fc2f..a22fb60 100644 --- a/tests/integration/targets/vyos_interfaces/tests/cli/parsed.yaml +++ b/tests/integration/targets/vyos_interfaces/tests/cli/parsed.yaml @@ -1,6 +1,7 @@ --- - debug: - msg: START vyos_interfaces parsed integration tests on connection={{ ansible_connection + msg: + START vyos_interfaces parsed integration tests on connection={{ ansible_connection }} - name: Parse externally provided interfaces config to agnostic model diff --git a/tests/integration/targets/vyos_interfaces/tests/cli/rendered.yaml b/tests/integration/targets/vyos_interfaces/tests/cli/rendered.yaml index 5030d71..e8f3591 100644 --- a/tests/integration/targets/vyos_interfaces/tests/cli/rendered.yaml +++ b/tests/integration/targets/vyos_interfaces/tests/cli/rendered.yaml @@ -1,6 +1,7 @@ --- - debug: - msg: START vyos_interfaces rendered integration tests on connection={{ ansible_connection + msg: + START vyos_interfaces rendered integration tests on connection={{ ansible_connection }} - include_tasks: _remove_config.yaml @@ -8,7 +9,6 @@ - include_tasks: _populate.yaml - block: - - name: Structure provided configuration into device specific commands register: result vyos.vyos.vyos_interfaces: @@ -43,5 +43,4 @@ - "{{ rendered['commands'] | symmetric_difference(result['rendered'])\ \ |length == 0 }}" always: - - include_tasks: _remove_config.yaml diff --git a/tests/integration/targets/vyos_interfaces/tests/cli/replaced.yaml b/tests/integration/targets/vyos_interfaces/tests/cli/replaced.yaml index 8b68c5a..daf8045 100644 --- a/tests/integration/targets/vyos_interfaces/tests/cli/replaced.yaml +++ b/tests/integration/targets/vyos_interfaces/tests/cli/replaced.yaml @@ -1,6 +1,7 @@ --- - debug: - msg: START vyos_interfaces replaced integration tests on connection={{ ansible_connection + msg: + START vyos_interfaces replaced integration tests on connection={{ ansible_connection }} - include_tasks: _remove_config.yaml @@ -8,16 +9,13 @@ - include_tasks: _populate.yaml - block: - - name: Replace device configurations of listed interfaces with provided configurations register: result vyos.vyos.vyos_interfaces: &id001 config: - - name: eth1 description: Replaced by Ansible vifs: - - vlan_id: 100 description: VIF 100 - Replaced by Ansible @@ -43,7 +41,8 @@ - "{{ replaced['after'] | symmetric_difference(result['after']) |length\ \ == 0 }}" - - name: Replace device configurations of listed interfaces with provided configurarions + - name: + Replace device configurations of listed interfaces with provided configurarions (IDEMPOTENT) register: result vyos.vyos.vyos_interfaces: *id001 @@ -59,5 +58,4 @@ - "{{ replaced['after'] | symmetric_difference(result['before']) |length\ \ == 0 }}" always: - - include_tasks: _remove_config.yaml diff --git a/tests/integration/targets/vyos_interfaces/tests/cli/rtt.yaml b/tests/integration/targets/vyos_interfaces/tests/cli/rtt.yaml index f003c0b..5aefbb4 100644 --- a/tests/integration/targets/vyos_interfaces/tests/cli/rtt.yaml +++ b/tests/integration/targets/vyos_interfaces/tests/cli/rtt.yaml @@ -1,17 +1,16 @@ --- - debug: - msg: START vyos_interfaces round trip integration tests on connection={{ ansible_connection + msg: + START vyos_interfaces round trip integration tests on connection={{ ansible_connection }} - include_tasks: _remove_config.yaml - block: - - name: Apply the provided configuration (base config) register: base_config vyos.vyos.vyos_interfaces: config: - - name: eth0 enabled: true duplex: auto @@ -21,7 +20,6 @@ description: Interface - 1 mtu: 1500 vifs: - - vlan_id: 100 description: Eth1 - VIF 100 mtu: 200 @@ -46,12 +44,10 @@ register: result vyos.vyos.vyos_interfaces: config: - - name: eth1 description: Interface 1 - Description (WILL BE REVERTED) mtu: 1200 vifs: - - vlan_id: 100 description: Eth1 - VIF 100 (WILL BE REVERTED) mtu: 400 @@ -68,7 +64,8 @@ - name: Assert that changes were applied assert: - that: "{{ round_trip['after'] | symmetric_difference(result['after']) |length\ + that: + "{{ round_trip['after'] | symmetric_difference(result['after']) |length\ \ == 0 }}" - name: Revert back to base config using facts round trip @@ -79,8 +76,8 @@ - name: Assert that config was reverted assert: - that: "{{ base_config['after'] | symmetric_difference(revert['after']) |length\ + that: + "{{ base_config['after'] | symmetric_difference(revert['after']) |length\ \ == 0 }}" always: - - include_tasks: _remove_config.yaml diff --git a/tests/integration/targets/vyos_l3_interfaces/defaults/main.yaml b/tests/integration/targets/vyos_l3_interfaces/defaults/main.yaml index 852a6be..164afea 100644 --- a/tests/integration/targets/vyos_l3_interfaces/defaults/main.yaml +++ b/tests/integration/targets/vyos_l3_interfaces/defaults/main.yaml @@ -1,3 +1,3 @@ --- -testcase: '[^_].*' +testcase: "[^_].*" test_items: [] diff --git a/tests/integration/targets/vyos_l3_interfaces/tasks/cli.yaml b/tests/integration/targets/vyos_l3_interfaces/tasks/cli.yaml index f622cf9..8aeb46d 100644 --- a/tests/integration/targets/vyos_l3_interfaces/tasks/cli.yaml +++ b/tests/integration/targets/vyos_l3_interfaces/tasks/cli.yaml @@ -1,8 +1,8 @@ --- - name: Collect all cli test cases find: - paths: '{{ role_path }}/tests/cli' - patterns: '{{ testcase }}.yaml' + paths: "{{ role_path }}/tests/cli" + patterns: "{{ testcase }}.yaml" use_regex: true register: test_cases delegate_to: localhost @@ -12,9 +12,9 @@ delegate_to: localhost - name: Run test case (connection=ansible.netcommon.network_cli) - include: '{{ test_case_to_run }}' + include: "{{ test_case_to_run }}" vars: ansible_connection: ansible.netcommon.network_cli - with_items: '{{ test_items }}' + with_items: "{{ test_items }}" loop_control: loop_var: test_case_to_run diff --git a/tests/integration/targets/vyos_l3_interfaces/tasks/redirection.yaml b/tests/integration/targets/vyos_l3_interfaces/tasks/redirection.yaml index 5564a3e..48ad53a 100644 --- a/tests/integration/targets/vyos_l3_interfaces/tasks/redirection.yaml +++ b/tests/integration/targets/vyos_l3_interfaces/tasks/redirection.yaml @@ -1,8 +1,8 @@ --- - name: collect all redirection cli test cases find: - paths: '{{ role_path }}/tests/redirection/cli' - patterns: '{{ testcase }}.yaml' + paths: "{{ role_path }}/tests/redirection/cli" + patterns: "{{ testcase }}.yaml" register: shortname_test_cases delegate_to: localhost @@ -10,7 +10,7 @@ set_fact: test_items="{{ shortname_test_cases.files | map(attribute='path') | list }}" - name: run test case (connection=ansible.netcommon.network_cli) - include: '{{ test_case_to_run }} ansible_connection=ansible.netcommon.network_cli' - with_items: '{{ test_items }}' + include: "{{ test_case_to_run }} ansible_connection=ansible.netcommon.network_cli" + with_items: "{{ test_items }}" loop_control: loop_var: test_case_to_run diff --git a/tests/integration/targets/vyos_l3_interfaces/tests/cli/_populate.yaml b/tests/integration/targets/vyos_l3_interfaces/tests/cli/_populate.yaml index 563b1d7..d5d8620 100644 --- a/tests/integration/targets/vyos_l3_interfaces/tests/cli/_populate.yaml +++ b/tests/integration/targets/vyos_l3_interfaces/tests/cli/_populate.yaml @@ -1,9 +1,10 @@ --- - name: Setup vars: - lines: "set interfaces ethernet eth1 address '192.0.2.14/24'\nset interfaces\ + lines: + "set interfaces ethernet eth1 address '192.0.2.14/24'\nset interfaces\ \ ethernet eth2 address '192.0.2.10/24'\nset interfaces ethernet eth2 address\ \ '192.0.2.11/24'\nset interfaces ethernet eth2 address '2001:db8::10/32'\n\ set interfaces ethernet eth2 address '2001:db8::12/32'\n" ansible.netcommon.cli_config: - config: '{{ lines }}' + config: "{{ lines }}" diff --git a/tests/integration/targets/vyos_l3_interfaces/tests/cli/_remove_config.yaml b/tests/integration/targets/vyos_l3_interfaces/tests/cli/_remove_config.yaml index 1fb0dd3..c5acac9 100644 --- a/tests/integration/targets/vyos_l3_interfaces/tests/cli/_remove_config.yaml +++ b/tests/integration/targets/vyos_l3_interfaces/tests/cli/_remove_config.yaml @@ -1,7 +1,8 @@ --- - name: Remove Config vars: - lines: "delete interfaces ethernet \"{{ intf }}\" address\ndelete interfaces\ + lines: + "delete interfaces ethernet \"{{ intf }}\" address\ndelete interfaces\ \ ethernet \"{{ intf }}\" vif\n" loop: - eth1 @@ -9,4 +10,4 @@ loop_control: loop_var: intf ansible.netcommon.cli_config: - config: '{{ lines }}' + config: "{{ lines }}" diff --git a/tests/integration/targets/vyos_l3_interfaces/tests/cli/deleted.yaml b/tests/integration/targets/vyos_l3_interfaces/tests/cli/deleted.yaml index ff4aabf..25ce28e 100644 --- a/tests/integration/targets/vyos_l3_interfaces/tests/cli/deleted.yaml +++ b/tests/integration/targets/vyos_l3_interfaces/tests/cli/deleted.yaml @@ -1,19 +1,18 @@ --- - debug: - msg: Start vyos_interfaces deleted integration tests ansible_connection={{ ansible_connection + msg: + Start vyos_interfaces deleted integration tests ansible_connection={{ ansible_connection }} - include_tasks: _remove_config.yaml - block: - - include_tasks: _populate.yaml - name: Delete attributes of given interfaces register: result vyos.vyos.vyos_l3_interfaces: &id001 config: - - name: eth1 - name: eth2 @@ -51,5 +50,4 @@ - "{{ deleted['after'] | symmetric_difference(result['before']) |length\ \ == 0 }}" always: - - include_tasks: _remove_config.yaml diff --git a/tests/integration/targets/vyos_l3_interfaces/tests/cli/empty_config.yaml b/tests/integration/targets/vyos_l3_interfaces/tests/cli/empty_config.yaml index 9929dd7..15393fb 100644 --- a/tests/integration/targets/vyos_l3_interfaces/tests/cli/empty_config.yaml +++ b/tests/integration/targets/vyos_l3_interfaces/tests/cli/empty_config.yaml @@ -1,6 +1,7 @@ --- - debug: - msg: START vyos_l3_interfaces empty_config integration tests on connection={{ + msg: + START vyos_l3_interfaces empty_config integration tests on connection={{ ansible_connection }} - name: Merged with empty config should give appropriate error message diff --git a/tests/integration/targets/vyos_l3_interfaces/tests/cli/overridden.yaml b/tests/integration/targets/vyos_l3_interfaces/tests/cli/overridden.yaml index 644fe08..dc6f0ce 100644 --- a/tests/integration/targets/vyos_l3_interfaces/tests/cli/overridden.yaml +++ b/tests/integration/targets/vyos_l3_interfaces/tests/cli/overridden.yaml @@ -1,27 +1,24 @@ --- - debug: - msg: START vyos_l3_interfaces merged integration tests on connection={{ ansible_connection + msg: + START vyos_l3_interfaces merged integration tests on connection={{ ansible_connection }} - include_tasks: _remove_config.yaml - block: - - include_tasks: _populate.yaml - name: Overrides all device configuration with provided configuration register: result vyos.vyos.vyos_l3_interfaces: &id001 config: - - name: eth0 ipv4: - - address: dhcp - name: eth1 ipv4: - - address: 192.0.2.15/24 state: overridden @@ -57,5 +54,4 @@ - "{{ overridden['after'] | symmetric_difference(result['before']) |length\ \ == 0 }}" always: - - include_tasks: _remove_config.yaml diff --git a/tests/integration/targets/vyos_l3_interfaces/tests/cli/parsed.yaml b/tests/integration/targets/vyos_l3_interfaces/tests/cli/parsed.yaml index d5ff205..6640271 100644 --- a/tests/integration/targets/vyos_l3_interfaces/tests/cli/parsed.yaml +++ b/tests/integration/targets/vyos_l3_interfaces/tests/cli/parsed.yaml @@ -1,6 +1,7 @@ --- - debug: - msg: START vyos_l3_nterfaces parsed integration tests on connection={{ ansible_connection + msg: + START vyos_l3_nterfaces parsed integration tests on connection={{ ansible_connection }} - name: Parse externally provided interfaces config to agnostic model diff --git a/tests/integration/targets/vyos_l3_interfaces/tests/cli/rendered.yaml b/tests/integration/targets/vyos_l3_interfaces/tests/cli/rendered.yaml index 02a2865..7bbf53c 100644 --- a/tests/integration/targets/vyos_l3_interfaces/tests/cli/rendered.yaml +++ b/tests/integration/targets/vyos_l3_interfaces/tests/cli/rendered.yaml @@ -1,6 +1,7 @@ --- - debug: - msg: START vyos_l3_interfaces rendered integration tests on connection={{ ansible_connection + msg: + START vyos_l3_interfaces rendered integration tests on connection={{ ansible_connection }} - include_tasks: _remove_config.yaml @@ -8,7 +9,6 @@ - include_tasks: _populate.yaml - block: - - name: Structure provided configuration into device specific commands register: result vyos.vyos.vyos_l3_interfaces: &id001 @@ -40,5 +40,4 @@ that: - result['changed'] == false always: - - include_tasks: _remove_config.yaml diff --git a/tests/integration/targets/vyos_l3_interfaces/tests/cli/replaced.yaml b/tests/integration/targets/vyos_l3_interfaces/tests/cli/replaced.yaml index 2c664bb..c102602 100644 --- a/tests/integration/targets/vyos_l3_interfaces/tests/cli/replaced.yaml +++ b/tests/integration/targets/vyos_l3_interfaces/tests/cli/replaced.yaml @@ -1,27 +1,24 @@ --- - debug: - msg: START vyos_l3_interfaces replaced integration tests on connection={{ ansible_connection + msg: + START vyos_l3_interfaces replaced integration tests on connection={{ ansible_connection }} - include_tasks: _remove_config.yaml - block: - - include_tasks: _populate.yaml - name: Replace device configurations of listed interfaces with provided configurations register: result vyos.vyos.vyos_l3_interfaces: &id001 config: - - name: eth1 ipv4: - - address: 192.0.2.19/24 - name: eth2 ipv6: - - address: 2001:db8::11/32 state: replaced @@ -42,7 +39,8 @@ - "{{ replaced['after'] | symmetric_difference(result['after']) |length\ \ == 0 }}" - - name: Replace device configurations of listed interfaces with provided configurarions + - name: + Replace device configurations of listed interfaces with provided configurarions (IDEMPOTENT) register: result vyos.vyos.vyos_l3_interfaces: *id001 @@ -58,5 +56,4 @@ - "{{ replaced['after'] | symmetric_difference(result['before']) |length\ \ == 0 }}" always: - - include_tasks: _remove_config.yaml diff --git a/tests/integration/targets/vyos_l3_interfaces/tests/redirection/cli/shortname.yaml b/tests/integration/targets/vyos_l3_interfaces/tests/redirection/cli/shortname.yaml index 33082d5..bee2a09 100644 --- a/tests/integration/targets/vyos_l3_interfaces/tests/redirection/cli/shortname.yaml +++ b/tests/integration/targets/vyos_l3_interfaces/tests/redirection/cli/shortname.yaml @@ -7,7 +7,6 @@ - include_tasks: _populate.yaml - block: - - name: Structure provided configuration into device specific commands register: result vyos.vyos.l3_interfaces: &id001 @@ -39,5 +38,4 @@ that: - result['changed'] == false always: - - include_tasks: _remove_config.yaml diff --git a/tests/integration/targets/vyos_lag_interfaces/defaults/main.yaml b/tests/integration/targets/vyos_lag_interfaces/defaults/main.yaml index 852a6be..164afea 100644 --- a/tests/integration/targets/vyos_lag_interfaces/defaults/main.yaml +++ b/tests/integration/targets/vyos_lag_interfaces/defaults/main.yaml @@ -1,3 +1,3 @@ --- -testcase: '[^_].*' +testcase: "[^_].*" test_items: [] diff --git a/tests/integration/targets/vyos_lag_interfaces/tasks/cli.yaml b/tests/integration/targets/vyos_lag_interfaces/tasks/cli.yaml index 93eb2fe..83496e0 100644 --- a/tests/integration/targets/vyos_lag_interfaces/tasks/cli.yaml +++ b/tests/integration/targets/vyos_lag_interfaces/tasks/cli.yaml @@ -1,8 +1,8 @@ --- - name: Collect all cli test cases find: - paths: '{{ role_path }}/tests/cli' - patterns: '{{ testcase }}.yaml' + paths: "{{ role_path }}/tests/cli" + patterns: "{{ testcase }}.yaml" use_regex: true register: test_cases delegate_to: localhost @@ -11,9 +11,9 @@ set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}" - name: Run test case (connection=ansible.netcommon.network_cli) - include: '{{ test_case_to_run }}' + include: "{{ test_case_to_run }}" vars: ansible_connection: ansible.netcommon.network_cli - with_items: '{{ test_items }}' + with_items: "{{ test_items }}" loop_control: loop_var: test_case_to_run diff --git a/tests/integration/targets/vyos_lag_interfaces/tasks/redirection.yaml b/tests/integration/targets/vyos_lag_interfaces/tasks/redirection.yaml index 5564a3e..48ad53a 100644 --- a/tests/integration/targets/vyos_lag_interfaces/tasks/redirection.yaml +++ b/tests/integration/targets/vyos_lag_interfaces/tasks/redirection.yaml @@ -1,8 +1,8 @@ --- - name: collect all redirection cli test cases find: - paths: '{{ role_path }}/tests/redirection/cli' - patterns: '{{ testcase }}.yaml' + paths: "{{ role_path }}/tests/redirection/cli" + patterns: "{{ testcase }}.yaml" register: shortname_test_cases delegate_to: localhost @@ -10,7 +10,7 @@ set_fact: test_items="{{ shortname_test_cases.files | map(attribute='path') | list }}" - name: run test case (connection=ansible.netcommon.network_cli) - include: '{{ test_case_to_run }} ansible_connection=ansible.netcommon.network_cli' - with_items: '{{ test_items }}' + include: "{{ test_case_to_run }} ansible_connection=ansible.netcommon.network_cli" + with_items: "{{ test_items }}" loop_control: loop_var: test_case_to_run diff --git a/tests/integration/targets/vyos_lag_interfaces/tests/cli/_add_bond.yaml b/tests/integration/targets/vyos_lag_interfaces/tests/cli/_add_bond.yaml index 927a6ce..00b7e6e 100644 --- a/tests/integration/targets/vyos_lag_interfaces/tests/cli/_add_bond.yaml +++ b/tests/integration/targets/vyos_lag_interfaces/tests/cli/_add_bond.yaml @@ -3,4 +3,4 @@ vars: lines: "set interfaces bonding bond0\nset interfaces bonding bond1\n" ansible.netcommon.cli_config: - config: '{{ lines }}' + config: "{{ lines }}" diff --git a/tests/integration/targets/vyos_lag_interfaces/tests/cli/_populate.yaml b/tests/integration/targets/vyos_lag_interfaces/tests/cli/_populate.yaml index f646742..4ad0b85 100644 --- a/tests/integration/targets/vyos_lag_interfaces/tests/cli/_populate.yaml +++ b/tests/integration/targets/vyos_lag_interfaces/tests/cli/_populate.yaml @@ -1,11 +1,12 @@ --- - name: Setup vars: - lines: "set interfaces bonding bond0\nset interfaces bonding bond0 hash-policy\ + lines: + "set interfaces bonding bond0\nset interfaces bonding bond0 hash-policy\ \ 'layer2'\nset interfaces bonding bond0 mode 'active-backup'\nset interfaces\ \ ethernet eth1 bond-group bond0\nset interfaces bonding bond1\nset interfaces\ \ bonding bond0 primary 'eth1'\nset interfaces bonding bond1 hash-policy 'layer2+3'\n\ set interfaces bonding bond1 mode 'active-backup'\nset interfaces ethernet\ \ eth2 bond-group bond1\nset interfaces bonding bond1 primary 'eth2'\n" ansible.netcommon.cli_config: - config: '{{ lines }}' + config: "{{ lines }}" diff --git a/tests/integration/targets/vyos_lag_interfaces/tests/cli/_remove_bond.yaml b/tests/integration/targets/vyos_lag_interfaces/tests/cli/_remove_bond.yaml index 6679d6a..dfc9920 100644 --- a/tests/integration/targets/vyos_lag_interfaces/tests/cli/_remove_bond.yaml +++ b/tests/integration/targets/vyos_lag_interfaces/tests/cli/_remove_bond.yaml @@ -3,4 +3,4 @@ vars: lines: "delete interfaces bonding bond0\ndelete interfaces bonding bond1\n" ansible.netcommon.cli_config: - config: '{{ lines }}' + config: "{{ lines }}" diff --git a/tests/integration/targets/vyos_lag_interfaces/tests/cli/_remove_config.yaml b/tests/integration/targets/vyos_lag_interfaces/tests/cli/_remove_config.yaml index 5469bf5..11432ea 100644 --- a/tests/integration/targets/vyos_lag_interfaces/tests/cli/_remove_config.yaml +++ b/tests/integration/targets/vyos_lag_interfaces/tests/cli/_remove_config.yaml @@ -1,10 +1,11 @@ --- - name: Remove Config vars: - lines: "delete interfaces bonding bond0 hash-policy\ndelete interfaces ethernet\ + lines: + "delete interfaces bonding bond0 hash-policy\ndelete interfaces ethernet\ \ eth1 bond-group bond0\ndelete interfaces bonding bond0 mode\ndelete interfaces\ \ bonding bond0 primary\ndelete interfaces bonding bond1 hash-policy\ndelete\ \ interfaces ethernet eth2 bond-group bond1\ndelete interfaces bonding bond1\ \ mode\ndelete interfaces bonding bond1 primary\n" ansible.netcommon.cli_config: - config: '{{ lines }}' + config: "{{ lines }}" diff --git a/tests/integration/targets/vyos_lag_interfaces/tests/cli/deleted.yaml b/tests/integration/targets/vyos_lag_interfaces/tests/cli/deleted.yaml index ac8204f..56f1ed6 100644 --- a/tests/integration/targets/vyos_lag_interfaces/tests/cli/deleted.yaml +++ b/tests/integration/targets/vyos_lag_interfaces/tests/cli/deleted.yaml @@ -1,17 +1,16 @@ --- - debug: - msg: Start vyos_lag_interfaces deleted integration tests ansible_connection={{ + msg: + Start vyos_lag_interfaces deleted integration tests ansible_connection={{ ansible_connection }} - include_tasks: _populate.yaml - block: - - name: Delete attributes of given LAG interfaces. register: result vyos.vyos.vyos_lag_interfaces: &id001 config: - - name: bond0 - name: bond1 @@ -49,5 +48,4 @@ - "{{ deleted['after'] | symmetric_difference(result['before']) |length\ \ == 0 }}" always: - - include_tasks: _remove_config.yaml diff --git a/tests/integration/targets/vyos_lag_interfaces/tests/cli/empty_config.yaml b/tests/integration/targets/vyos_lag_interfaces/tests/cli/empty_config.yaml index 6e89eae..22ac8a8 100644 --- a/tests/integration/targets/vyos_lag_interfaces/tests/cli/empty_config.yaml +++ b/tests/integration/targets/vyos_lag_interfaces/tests/cli/empty_config.yaml @@ -1,6 +1,7 @@ --- - debug: - msg: START vyos_lag_interfaces empty_config integration tests on connection={{ + msg: + START vyos_lag_interfaces empty_config integration tests on connection={{ ansible_connection }} - name: Merged with empty config should give appropriate error message diff --git a/tests/integration/targets/vyos_lag_interfaces/tests/cli/overridden.yaml b/tests/integration/targets/vyos_lag_interfaces/tests/cli/overridden.yaml index aa6e247..9682fd7 100644 --- a/tests/integration/targets/vyos_lag_interfaces/tests/cli/overridden.yaml +++ b/tests/integration/targets/vyos_lag_interfaces/tests/cli/overridden.yaml @@ -10,16 +10,13 @@ - include_tasks: _populate.yaml - block: - - name: Overrides all device configuration with provided configuration register: result vyos.vyos.vyos_lag_interfaces: &id001 config: - - name: bond1 mode: active-backup members: - - member: eth2 primary: eth2 hash_policy: layer2 @@ -57,5 +54,4 @@ - "{{ overridden['after'] | symmetric_difference(result['before']) |length\ \ == 0 }}" always: - - include_tasks: _remove_config.yaml diff --git a/tests/integration/targets/vyos_lag_interfaces/tests/cli/parsed.yaml b/tests/integration/targets/vyos_lag_interfaces/tests/cli/parsed.yaml index ed7bc61..ce2df0d 100644 --- a/tests/integration/targets/vyos_lag_interfaces/tests/cli/parsed.yaml +++ b/tests/integration/targets/vyos_lag_interfaces/tests/cli/parsed.yaml @@ -1,6 +1,7 @@ --- - debug: - msg: START vyos_lag_interfaces parsed integration tests on connection={{ ansible_connection + msg: + START vyos_lag_interfaces parsed integration tests on connection={{ ansible_connection }} - include_tasks: _remove_config.yaml @@ -8,7 +9,6 @@ - include_tasks: _populate.yaml - block: - - name: Gather lag_interfaces facts register: lag_interfaces_facts vyos.vyos.vyos_facts: @@ -25,9 +25,9 @@ - name: Assert that correct parsing done assert: - that: "{{ ansible_facts['network_resources']['lag_interfaces'] | symmetric_difference(result['parsed'])\ + that: + "{{ ansible_facts['network_resources']['lag_interfaces'] | symmetric_difference(result['parsed'])\ \ |length == 0 }}" always: - - include_tasks: _remove_config.yaml diff --git a/tests/integration/targets/vyos_lag_interfaces/tests/cli/rendered.yaml b/tests/integration/targets/vyos_lag_interfaces/tests/cli/rendered.yaml index e6d7928..781100f 100644 --- a/tests/integration/targets/vyos_lag_interfaces/tests/cli/rendered.yaml +++ b/tests/integration/targets/vyos_lag_interfaces/tests/cli/rendered.yaml @@ -1,6 +1,7 @@ --- - debug: - msg: START vyos_lag_interfaces rendered integration tests on connection={{ ansible_connection + msg: + START vyos_lag_interfaces rendered integration tests on connection={{ ansible_connection }} - include_tasks: _remove_config.yaml @@ -8,7 +9,6 @@ - include_tasks: _populate.yaml - block: - - name: Structure provided configuration into device specific commands register: result vyos.vyos.vyos_lag_interfaces: @@ -34,5 +34,4 @@ \ |length == 0 }}" always: - - include_tasks: _remove_config.yaml diff --git a/tests/integration/targets/vyos_lag_interfaces/tests/cli/replaced.yaml b/tests/integration/targets/vyos_lag_interfaces/tests/cli/replaced.yaml index c080056..c8b711b 100644 --- a/tests/integration/targets/vyos_lag_interfaces/tests/cli/replaced.yaml +++ b/tests/integration/targets/vyos_lag_interfaces/tests/cli/replaced.yaml @@ -1,6 +1,7 @@ --- - debug: - msg: START vyos_lag_interfaces replaced integration tests on connection={{ ansible_connection + msg: + START vyos_lag_interfaces replaced integration tests on connection={{ ansible_connection }} - include_tasks: _remove_config.yaml @@ -8,18 +9,15 @@ - include_tasks: _populate.yaml - block: - - name: Replace device configurations of listed LAG interfaces with provided configurations register: result vyos.vyos.vyos_lag_interfaces: &id001 config: - - name: bond1 mode: 802.3ad hash_policy: layer2 members: - - member: eth2 state: replaced @@ -56,5 +54,4 @@ - "{{ replaced['after'] | symmetric_difference(result['before']) |length\ \ == 0 }}" always: - - include_tasks: _remove_config.yaml diff --git a/tests/integration/targets/vyos_lag_interfaces/tests/cli/rtt.yaml b/tests/integration/targets/vyos_lag_interfaces/tests/cli/rtt.yaml index 55e2bbf..f5f6098 100644 --- a/tests/integration/targets/vyos_lag_interfaces/tests/cli/rtt.yaml +++ b/tests/integration/targets/vyos_lag_interfaces/tests/cli/rtt.yaml @@ -8,17 +8,14 @@ - include_tasks: _remove_bond.yaml - block: - - name: Apply the provided configuration (base config) register: base_config vyos.vyos.vyos_lag_interfaces: config: - - name: bond0 hash_policy: layer2 mode: active-backup members: - - member: eth1 primary: eth1 @@ -26,7 +23,6 @@ hash_policy: layer2+3 mode: active-backup members: - - member: eth2 primary: eth2 state: merged @@ -42,25 +38,23 @@ register: result vyos.vyos.vyos_lag_interfaces: config: - - name: bond0 hash_policy: layer2+3 mode: 802.3ad members: - - member: eth1 - name: bond1 hash_policy: layer2 mode: xor-hash members: - - member: eth2 state: merged - name: Assert that changes were applied assert: - that: "{{ round_trip['after'] | symmetric_difference(result['after']) |length\ + that: + "{{ round_trip['after'] | symmetric_difference(result['after']) |length\ \ == 0 }}" - name: Revert back to base config using facts round trip @@ -71,8 +65,8 @@ - name: Assert that config was reverted assert: - that: "{{ base_config['after'] | symmetric_difference(revert['after']) |length\ + that: + "{{ base_config['after'] | symmetric_difference(revert['after']) |length\ \ == 0 }}" always: - - include_tasks: _remove_config.yaml diff --git a/tests/integration/targets/vyos_lldp_global/defaults/main.yaml b/tests/integration/targets/vyos_lldp_global/defaults/main.yaml index 852a6be..164afea 100644 --- a/tests/integration/targets/vyos_lldp_global/defaults/main.yaml +++ b/tests/integration/targets/vyos_lldp_global/defaults/main.yaml @@ -1,3 +1,3 @@ --- -testcase: '[^_].*' +testcase: "[^_].*" test_items: [] diff --git a/tests/integration/targets/vyos_lldp_global/tasks/cli.yaml b/tests/integration/targets/vyos_lldp_global/tasks/cli.yaml index 93eb2fe..83496e0 100644 --- a/tests/integration/targets/vyos_lldp_global/tasks/cli.yaml +++ b/tests/integration/targets/vyos_lldp_global/tasks/cli.yaml @@ -1,8 +1,8 @@ --- - name: Collect all cli test cases find: - paths: '{{ role_path }}/tests/cli' - patterns: '{{ testcase }}.yaml' + paths: "{{ role_path }}/tests/cli" + patterns: "{{ testcase }}.yaml" use_regex: true register: test_cases delegate_to: localhost @@ -11,9 +11,9 @@ set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}" - name: Run test case (connection=ansible.netcommon.network_cli) - include: '{{ test_case_to_run }}' + include: "{{ test_case_to_run }}" vars: ansible_connection: ansible.netcommon.network_cli - with_items: '{{ test_items }}' + with_items: "{{ test_items }}" loop_control: loop_var: test_case_to_run diff --git a/tests/integration/targets/vyos_lldp_global/tests/cli/_populate.yaml b/tests/integration/targets/vyos_lldp_global/tests/cli/_populate.yaml index e439242..24c114d 100644 --- a/tests/integration/targets/vyos_lldp_global/tests/cli/_populate.yaml +++ b/tests/integration/targets/vyos_lldp_global/tests/cli/_populate.yaml @@ -1,7 +1,8 @@ --- - name: Setup vars: - lines: "set service lldp\nset service lldp legacy-protocols 'cdp'\nset service\ + lines: + "set service lldp\nset service lldp legacy-protocols 'cdp'\nset service\ \ lldp management-address '192.0.2.17'\n" ansible.netcommon.cli_config: - config: '{{ lines }}' + config: "{{ lines }}" diff --git a/tests/integration/targets/vyos_lldp_global/tests/cli/_remove_config.yaml b/tests/integration/targets/vyos_lldp_global/tests/cli/_remove_config.yaml index b823449..7e5b37c 100644 --- a/tests/integration/targets/vyos_lldp_global/tests/cli/_remove_config.yaml +++ b/tests/integration/targets/vyos_lldp_global/tests/cli/_remove_config.yaml @@ -1,7 +1,8 @@ --- - name: Remove Config vars: - lines: "delete service lldp legacy-protocols\ndelete service lldp management-address\n\ + lines: + "delete service lldp legacy-protocols\ndelete service lldp management-address\n\ delete service lldp\n" ansible.netcommon.cli_config: - config: '{{ lines }}' + config: "{{ lines }}" diff --git a/tests/integration/targets/vyos_lldp_global/tests/cli/deleted.yaml b/tests/integration/targets/vyos_lldp_global/tests/cli/deleted.yaml index f4c6cbc..c086e2b 100644 --- a/tests/integration/targets/vyos_lldp_global/tests/cli/deleted.yaml +++ b/tests/integration/targets/vyos_lldp_global/tests/cli/deleted.yaml @@ -6,7 +6,6 @@ - include_tasks: _populate.yaml - block: - - name: Delete attributes of LLDP service. register: result vyos.vyos.vyos_lldp_global: &id001 @@ -43,5 +42,4 @@ that: - "{{ deleted['after'] == result['before'] }}" always: - - include_tasks: _remove_config.yaml diff --git a/tests/integration/targets/vyos_lldp_global/tests/cli/parsed.yaml b/tests/integration/targets/vyos_lldp_global/tests/cli/parsed.yaml index b9c3abf..1047f30 100644 --- a/tests/integration/targets/vyos_lldp_global/tests/cli/parsed.yaml +++ b/tests/integration/targets/vyos_lldp_global/tests/cli/parsed.yaml @@ -1,6 +1,7 @@ --- - debug: - msg: START vyos_lldp_global parsed integration tests on connection={{ ansible_connection + msg: + START vyos_lldp_global parsed integration tests on connection={{ ansible_connection }} - name: Parse externally provided LLDP global config to agnostic model diff --git a/tests/integration/targets/vyos_lldp_global/tests/cli/rendered.yaml b/tests/integration/targets/vyos_lldp_global/tests/cli/rendered.yaml index 5e9f4c5..59ff032 100644 --- a/tests/integration/targets/vyos_lldp_global/tests/cli/rendered.yaml +++ b/tests/integration/targets/vyos_lldp_global/tests/cli/rendered.yaml @@ -6,7 +6,6 @@ - include_tasks: _remove_config.yaml - block: - - name: Structure provided configuration into device specific commands register: result vyos.vyos.vyos_lldp_global: @@ -24,5 +23,4 @@ \ |length == 0 }}" always: - - include_tasks: _remove_config.yaml diff --git a/tests/integration/targets/vyos_lldp_global/tests/cli/replaced.yaml b/tests/integration/targets/vyos_lldp_global/tests/cli/replaced.yaml index 9a833f5..6859dc8 100644 --- a/tests/integration/targets/vyos_lldp_global/tests/cli/replaced.yaml +++ b/tests/integration/targets/vyos_lldp_global/tests/cli/replaced.yaml @@ -1,6 +1,7 @@ --- - debug: - msg: START vyos_lldp_global replaced integration tests on connection={{ ansible_connection + msg: + START vyos_lldp_global replaced integration tests on connection={{ ansible_connection }} - include_tasks: _remove_config.yaml @@ -8,7 +9,6 @@ - include_tasks: _populate.yaml - block: - - name: Replace device configurations of LLDP service with provided configurations register: result vyos.vyos.vyos_lldp_global: &id001 @@ -36,7 +36,8 @@ that: - "{{ replaced['after'] == result['after'] }}" - - name: Replace device configurations of LLDP service with provided configurarions + - name: + Replace device configurations of LLDP service with provided configurarions (IDEMPOTENT) register: result vyos.vyos.vyos_lldp_global: *id001 @@ -51,5 +52,4 @@ that: - "{{ replaced['after'] == result['before'] }}" always: - - include_tasks: _remove_config.yaml diff --git a/tests/integration/targets/vyos_lldp_global/tests/cli/rtt.yaml b/tests/integration/targets/vyos_lldp_global/tests/cli/rtt.yaml index 2e8284f..b0bd603 100644 --- a/tests/integration/targets/vyos_lldp_global/tests/cli/rtt.yaml +++ b/tests/integration/targets/vyos_lldp_global/tests/cli/rtt.yaml @@ -1,12 +1,12 @@ --- - debug: - msg: START vyos_lldp_global round trip integration tests on connection={{ ansible_connection + msg: + START vyos_lldp_global round trip integration tests on connection={{ ansible_connection }} - include_tasks: _remove_config.yaml - block: - - name: Apply the provided configuration (base config) register: base_config vyos.vyos.vyos_lldp_global: @@ -49,5 +49,4 @@ assert: that: "{{ base_config['after'] == revert['after'] }}" always: - - include_tasks: _remove_config.yaml diff --git a/tests/integration/targets/vyos_lldp_interfaces/defaults/main.yaml b/tests/integration/targets/vyos_lldp_interfaces/defaults/main.yaml index 852a6be..164afea 100644 --- a/tests/integration/targets/vyos_lldp_interfaces/defaults/main.yaml +++ b/tests/integration/targets/vyos_lldp_interfaces/defaults/main.yaml @@ -1,3 +1,3 @@ --- -testcase: '[^_].*' +testcase: "[^_].*" test_items: [] diff --git a/tests/integration/targets/vyos_lldp_interfaces/tasks/cli.yaml b/tests/integration/targets/vyos_lldp_interfaces/tasks/cli.yaml index 93eb2fe..83496e0 100644 --- a/tests/integration/targets/vyos_lldp_interfaces/tasks/cli.yaml +++ b/tests/integration/targets/vyos_lldp_interfaces/tasks/cli.yaml @@ -1,8 +1,8 @@ --- - name: Collect all cli test cases find: - paths: '{{ role_path }}/tests/cli' - patterns: '{{ testcase }}.yaml' + paths: "{{ role_path }}/tests/cli" + patterns: "{{ testcase }}.yaml" use_regex: true register: test_cases delegate_to: localhost @@ -11,9 +11,9 @@ set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}" - name: Run test case (connection=ansible.netcommon.network_cli) - include: '{{ test_case_to_run }}' + include: "{{ test_case_to_run }}" vars: ansible_connection: ansible.netcommon.network_cli - with_items: '{{ test_items }}' + with_items: "{{ test_items }}" loop_control: loop_var: test_case_to_run diff --git a/tests/integration/targets/vyos_lldp_interfaces/tasks/redirection.yaml b/tests/integration/targets/vyos_lldp_interfaces/tasks/redirection.yaml index 5564a3e..48ad53a 100644 --- a/tests/integration/targets/vyos_lldp_interfaces/tasks/redirection.yaml +++ b/tests/integration/targets/vyos_lldp_interfaces/tasks/redirection.yaml @@ -1,8 +1,8 @@ --- - name: collect all redirection cli test cases find: - paths: '{{ role_path }}/tests/redirection/cli' - patterns: '{{ testcase }}.yaml' + paths: "{{ role_path }}/tests/redirection/cli" + patterns: "{{ testcase }}.yaml" register: shortname_test_cases delegate_to: localhost @@ -10,7 +10,7 @@ set_fact: test_items="{{ shortname_test_cases.files | map(attribute='path') | list }}" - name: run test case (connection=ansible.netcommon.network_cli) - include: '{{ test_case_to_run }} ansible_connection=ansible.netcommon.network_cli' - with_items: '{{ test_items }}' + include: "{{ test_case_to_run }} ansible_connection=ansible.netcommon.network_cli" + with_items: "{{ test_items }}" loop_control: loop_var: test_case_to_run diff --git a/tests/integration/targets/vyos_lldp_interfaces/tests/cli/_populate.yaml b/tests/integration/targets/vyos_lldp_interfaces/tests/cli/_populate.yaml index 4353cec..406d30b 100644 --- a/tests/integration/targets/vyos_lldp_interfaces/tests/cli/_populate.yaml +++ b/tests/integration/targets/vyos_lldp_interfaces/tests/cli/_populate.yaml @@ -1,7 +1,8 @@ --- - name: Setup vars: - lines: "set service lldp interface eth1\nset service lldp interface eth1 location\ + lines: + "set service lldp interface eth1\nset service lldp interface eth1 location\ \ civic-based country-code US\nset service lldp interface eth1 location civic-based\ \ ca-type 0 ca-value ENGLISH\nset service lldp interface eth2\nset service\ \ lldp interface eth2 location coordinate-based latitude 33.524449N\nset service\ @@ -9,4 +10,4 @@ \ lldp interface eth2 location coordinate-based datum WGS84\nset service lldp\ \ interface eth2 location coordinate-based longitude 222.267255W\n" ansible.netcommon.cli_config: - config: '{{ lines }}' + config: "{{ lines }}" diff --git a/tests/integration/targets/vyos_lldp_interfaces/tests/cli/_populate_intf.yaml b/tests/integration/targets/vyos_lldp_interfaces/tests/cli/_populate_intf.yaml index 11e2940..208f21e 100644 --- a/tests/integration/targets/vyos_lldp_interfaces/tests/cli/_populate_intf.yaml +++ b/tests/integration/targets/vyos_lldp_interfaces/tests/cli/_populate_intf.yaml @@ -1,8 +1,9 @@ --- - name: Setup vars: - lines: "set service lldp interface eth2\nset service lldp interface eth2 location\ + lines: + "set service lldp interface eth2\nset service lldp interface eth2 location\ \ civic-based country-code US\nset service lldp interface eth2 location civic-based\ \ ca-type 0 ca-value ENGLISH\nset service lldp interface eth2 disable\n" ansible.netcommon.cli_config: - config: '{{ lines }}' + config: "{{ lines }}" diff --git a/tests/integration/targets/vyos_lldp_interfaces/tests/cli/_remove_config.yaml b/tests/integration/targets/vyos_lldp_interfaces/tests/cli/_remove_config.yaml index a885f01..c8ab352 100644 --- a/tests/integration/targets/vyos_lldp_interfaces/tests/cli/_remove_config.yaml +++ b/tests/integration/targets/vyos_lldp_interfaces/tests/cli/_remove_config.yaml @@ -3,4 +3,4 @@ vars: lines: "delete service lldp interface\ndelete service lldp\n" ansible.netcommon.cli_config: - config: '{{ lines }}' + config: "{{ lines }}" diff --git a/tests/integration/targets/vyos_lldp_interfaces/tests/cli/deleted.yaml b/tests/integration/targets/vyos_lldp_interfaces/tests/cli/deleted.yaml index 21bf96d..c5b30af 100644 --- a/tests/integration/targets/vyos_lldp_interfaces/tests/cli/deleted.yaml +++ b/tests/integration/targets/vyos_lldp_interfaces/tests/cli/deleted.yaml @@ -1,17 +1,16 @@ --- - debug: - msg: Start vyos_lldp_interfaces deleted integration tests ansible_connection={{ + msg: + Start vyos_lldp_interfaces deleted integration tests ansible_connection={{ ansible_connection }} - include_tasks: _populate.yaml - block: - - name: Delete attributes of given LLDP interfaces. register: result vyos.vyos.vyos_lldp_interfaces: &id001 config: - - name: eth1 - name: eth2 @@ -50,5 +49,4 @@ - "{{ deleted['after'] | symmetric_difference(result['before']) |length\ \ == 0 }}" always: - - include_tasks: _remove_config.yaml diff --git a/tests/integration/targets/vyos_lldp_interfaces/tests/cli/empty_config.yaml b/tests/integration/targets/vyos_lldp_interfaces/tests/cli/empty_config.yaml index 4ef40c9..6c097e3 100644 --- a/tests/integration/targets/vyos_lldp_interfaces/tests/cli/empty_config.yaml +++ b/tests/integration/targets/vyos_lldp_interfaces/tests/cli/empty_config.yaml @@ -1,6 +1,7 @@ --- - debug: - msg: START vyos_lldp_interfaces empty_config integration tests on connection={{ + msg: + START vyos_lldp_interfaces empty_config integration tests on connection={{ ansible_connection }} - name: Merged with empty config should give appropriate error message diff --git a/tests/integration/targets/vyos_lldp_interfaces/tests/cli/overridden.yaml b/tests/integration/targets/vyos_lldp_interfaces/tests/cli/overridden.yaml index 3e6ce40..e077e01 100644 --- a/tests/integration/targets/vyos_lldp_interfaces/tests/cli/overridden.yaml +++ b/tests/integration/targets/vyos_lldp_interfaces/tests/cli/overridden.yaml @@ -1,6 +1,7 @@ --- - debug: - msg: START vyos_lldp_interfaces overridden integration tests on connection={{ + msg: + START vyos_lldp_interfaces overridden integration tests on connection={{ ansible_connection }} - include_tasks: _remove_config.yaml @@ -8,12 +9,10 @@ - include_tasks: _populate_intf.yaml - block: - - name: Overrides all device configuration with provided configuration register: result vyos.vyos.vyos_lldp_interfaces: &id001 config: - - name: eth2 location: elin: 0000000911 @@ -52,5 +51,4 @@ - "{{ overridden['after'] | symmetric_difference(result['before']) |length\ \ == 0 }}" always: - - include_tasks: _remove_config.yaml diff --git a/tests/integration/targets/vyos_lldp_interfaces/tests/cli/parsed.yaml b/tests/integration/targets/vyos_lldp_interfaces/tests/cli/parsed.yaml index 0ca52be..a32e9d5 100644 --- a/tests/integration/targets/vyos_lldp_interfaces/tests/cli/parsed.yaml +++ b/tests/integration/targets/vyos_lldp_interfaces/tests/cli/parsed.yaml @@ -1,6 +1,7 @@ --- - debug: - msg: START vyos_lldp_nterfaces parsed integration tests on connection={{ ansible_connection + msg: + START vyos_lldp_nterfaces parsed integration tests on connection={{ ansible_connection }} - name: Parse externally provided interfaces config to agnostic model diff --git a/tests/integration/targets/vyos_lldp_interfaces/tests/cli/rendered.yaml b/tests/integration/targets/vyos_lldp_interfaces/tests/cli/rendered.yaml index 342e64b..87bed90 100644 --- a/tests/integration/targets/vyos_lldp_interfaces/tests/cli/rendered.yaml +++ b/tests/integration/targets/vyos_lldp_interfaces/tests/cli/rendered.yaml @@ -1,12 +1,12 @@ --- - debug: - msg: START vyos_lldp_interfaces rendered integration tests on connection={{ ansible_connection + msg: + START vyos_lldp_interfaces rendered integration tests on connection={{ ansible_connection }} - include_tasks: _remove_config.yaml - block: - - name: Structure provided configuration into device specific commands register: result vyos.vyos.vyos_lldp_interfaces: @@ -33,5 +33,4 @@ - "{{ rendered['commands'] | symmetric_difference(result['rendered'])\ \ |length == 0 }}" always: - - include_tasks: _remove_config.yaml diff --git a/tests/integration/targets/vyos_lldp_interfaces/tests/cli/replaced.yaml b/tests/integration/targets/vyos_lldp_interfaces/tests/cli/replaced.yaml index 3218e80..e76e3b2 100644 --- a/tests/integration/targets/vyos_lldp_interfaces/tests/cli/replaced.yaml +++ b/tests/integration/targets/vyos_lldp_interfaces/tests/cli/replaced.yaml @@ -8,20 +8,18 @@ - include_tasks: _populate.yaml - block: - - - name: Replace device configurations of listed LLDP interfaces with provided + - name: + Replace device configurations of listed LLDP interfaces with provided configurations register: result vyos.vyos.vyos_lldp_interfaces: &id001 config: - - name: eth2 enable: false location: civic_based: country_code: US ca_info: - - ca_type: 0 ca_value: ENGLISH @@ -52,7 +50,8 @@ - "{{ replaced['after'] | symmetric_difference(result['after']) |length\ \ == 0 }}" - - name: Replace device configurations of listed LLDP interfaces with provided + - name: + Replace device configurations of listed LLDP interfaces with provided configurarions (IDEMPOTENT) register: result vyos.vyos.vyos_lldp_interfaces: *id001 @@ -68,5 +67,4 @@ - "{{ replaced['after'] | symmetric_difference(result['before']) |length\ \ == 0 }}" always: - - include_tasks: _remove_config.yaml diff --git a/tests/integration/targets/vyos_lldp_interfaces/tests/cli/rtt.yaml b/tests/integration/targets/vyos_lldp_interfaces/tests/cli/rtt.yaml index e6189a3..e23253b 100644 --- a/tests/integration/targets/vyos_lldp_interfaces/tests/cli/rtt.yaml +++ b/tests/integration/targets/vyos_lldp_interfaces/tests/cli/rtt.yaml @@ -1,23 +1,21 @@ --- - debug: - msg: START vyos_lldp_interfaces round trip integration tests on connection={{ + msg: + START vyos_lldp_interfaces round trip integration tests on connection={{ ansible_connection }} - include_tasks: _remove_config.yaml - block: - - name: Apply the provided configuration (base config) register: base_config vyos.vyos.vyos_lldp_interfaces: config: - - name: eth1 location: civic_based: country_code: US ca_info: - - ca_type: 0 ca_value: ENGLISH state: merged @@ -33,7 +31,6 @@ register: result vyos.vyos.vyos_lldp_interfaces: config: - - name: eth2 location: coordinate_based: @@ -45,7 +42,8 @@ - name: Assert that changes were applied assert: - that: "{{ round_trip['after'] | symmetric_difference(result['after']) |length\ + that: + "{{ round_trip['after'] | symmetric_difference(result['after']) |length\ \ == 0 }}" - name: Revert back to base config using facts round trip @@ -56,8 +54,8 @@ - name: Assert that config was reverted assert: - that: "{{ base_config['after'] | symmetric_difference(revert['after']) |length\ + that: + "{{ base_config['after'] | symmetric_difference(revert['after']) |length\ \ == 0 }}" always: - - include_tasks: _remove_config.yaml diff --git a/tests/integration/targets/vyos_lldp_interfaces/tests/redirection/cli/shortname.yaml b/tests/integration/targets/vyos_lldp_interfaces/tests/redirection/cli/shortname.yaml index f43a8e8..0b06a74 100644 --- a/tests/integration/targets/vyos_lldp_interfaces/tests/redirection/cli/shortname.yaml +++ b/tests/integration/targets/vyos_lldp_interfaces/tests/redirection/cli/shortname.yaml @@ -12,7 +12,6 @@ register: result vyos.vyos.lldp_interfaces: &id001 config: - - name: eth2 location: elin: 0000000911 diff --git a/tests/integration/targets/vyos_logging/defaults/main.yaml b/tests/integration/targets/vyos_logging/defaults/main.yaml index a845c24..9ef5ba5 100644 --- a/tests/integration/targets/vyos_logging/defaults/main.yaml +++ b/tests/integration/targets/vyos_logging/defaults/main.yaml @@ -1,3 +1,3 @@ --- -testcase: '*' +testcase: "*" test_items: [] diff --git a/tests/integration/targets/vyos_logging/tasks/cli.yaml b/tests/integration/targets/vyos_logging/tasks/cli.yaml index 8f7b62f..b2746ce 100644 --- a/tests/integration/targets/vyos_logging/tasks/cli.yaml +++ b/tests/integration/targets/vyos_logging/tasks/cli.yaml @@ -1,8 +1,8 @@ --- - name: collect all cli test cases find: - paths: '{{ role_path }}/tests/cli' - patterns: '{{ testcase }}.yaml' + paths: "{{ role_path }}/tests/cli" + patterns: "{{ testcase }}.yaml" register: test_cases delegate_to: localhost @@ -10,8 +10,8 @@ set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}" - name: run test case (connection=ansible.netcommon.network_cli) - include: '{{ test_case_to_run }} ansible_connection=ansible.netcommon.network_cli' - with_items: '{{ test_items }}' + include: "{{ test_case_to_run }} ansible_connection=ansible.netcommon.network_cli" + with_items: "{{ test_items }}" loop_control: loop_var: test_case_to_run tags: diff --git a/tests/integration/targets/vyos_logging/tests/cli/basic.yaml b/tests/integration/targets/vyos_logging/tests/cli/basic.yaml index a025047..708623e 100644 --- a/tests/integration/targets/vyos_logging/tests/cli/basic.yaml +++ b/tests/integration/targets/vyos_logging/tests/cli/basic.yaml @@ -84,7 +84,6 @@ register: result vyos.vyos.vyos_logging: aggregate: - - dest: file name: test1 facility: all @@ -106,7 +105,6 @@ register: result vyos.vyos.vyos_logging: aggregate: - - dest: console facility: all level: info @@ -132,7 +130,6 @@ register: result vyos.vyos.vyos_logging: aggregate: - - dest: console facility: all level: info diff --git a/tests/integration/targets/vyos_logging_global/defaults/main.yaml b/tests/integration/targets/vyos_logging_global/defaults/main.yaml index 852a6be..164afea 100644 --- a/tests/integration/targets/vyos_logging_global/defaults/main.yaml +++ b/tests/integration/targets/vyos_logging_global/defaults/main.yaml @@ -1,3 +1,3 @@ --- -testcase: '[^_].*' +testcase: "[^_].*" test_items: [] diff --git a/tests/integration/targets/vyos_logging_global/meta/main.yaml b/tests/integration/targets/vyos_logging_global/meta/main.yaml index 91da2a7..ed97d53 100644 --- a/tests/integration/targets/vyos_logging_global/meta/main.yaml +++ b/tests/integration/targets/vyos_logging_global/meta/main.yaml @@ -1,2 +1 @@ --- -... diff --git a/tests/integration/targets/vyos_logging_global/tasks/cli.yaml b/tests/integration/targets/vyos_logging_global/tasks/cli.yaml index 93eb2fe..83496e0 100644 --- a/tests/integration/targets/vyos_logging_global/tasks/cli.yaml +++ b/tests/integration/targets/vyos_logging_global/tasks/cli.yaml @@ -1,8 +1,8 @@ --- - name: Collect all cli test cases find: - paths: '{{ role_path }}/tests/cli' - patterns: '{{ testcase }}.yaml' + paths: "{{ role_path }}/tests/cli" + patterns: "{{ testcase }}.yaml" use_regex: true register: test_cases delegate_to: localhost @@ -11,9 +11,9 @@ set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}" - name: Run test case (connection=ansible.netcommon.network_cli) - include: '{{ test_case_to_run }}' + include: "{{ test_case_to_run }}" vars: ansible_connection: ansible.netcommon.network_cli - with_items: '{{ test_items }}' + with_items: "{{ test_items }}" loop_control: loop_var: test_case_to_run diff --git a/tests/integration/targets/vyos_logging_global/tests/cli/empty_config.yaml b/tests/integration/targets/vyos_logging_global/tests/cli/empty_config.yaml index f70fff1..2764ed6 100644 --- a/tests/integration/targets/vyos_logging_global/tests/cli/empty_config.yaml +++ b/tests/integration/targets/vyos_logging_global/tests/cli/empty_config.yaml @@ -1,6 +1,7 @@ --- - debug: - msg: START vyos_logging_global empty_config integration tests on connection={{ + msg: + START vyos_logging_global empty_config integration tests on connection={{ ansible_connection }} - name: Merged with empty config should give appropriate error message diff --git a/tests/integration/targets/vyos_logging_global/tests/cli/merged.yaml b/tests/integration/targets/vyos_logging_global/tests/cli/merged.yaml index d47d309..8d2283c 100644 --- a/tests/integration/targets/vyos_logging_global/tests/cli/merged.yaml +++ b/tests/integration/targets/vyos_logging_global/tests/cli/merged.yaml @@ -6,7 +6,8 @@ - include_tasks: _remove_config.yaml -- block: # no after state match because 1.1.8 vyos does show all commands on show command +- block: + # no after state match because 1.1.8 vyos does show all commands on show command - name: Merge the provided configuration with the existing running configuration register: result vyos.vyos.vyos_logging_global: &id001 diff --git a/tests/integration/targets/vyos_logging_global/tests/cli/overridden.yaml b/tests/integration/targets/vyos_logging_global/tests/cli/overridden.yaml index 1df1a8d..e5eea38 100644 --- a/tests/integration/targets/vyos_logging_global/tests/cli/overridden.yaml +++ b/tests/integration/targets/vyos_logging_global/tests/cli/overridden.yaml @@ -7,7 +7,8 @@ - include_tasks: _populate.yaml -- block: # no after state match because 1.1.8 vyos does show all commands on show command +- block: + # no after state match because 1.1.8 vyos does show all commands on show command - name: Overrides all device configuration with provided configuration register: result vyos.vyos.vyos_logging_global: &id001 @@ -35,5 +36,4 @@ vyos.vyos.vyos_logging_global: *id001 always: - - include_tasks: _remove_config.yaml diff --git a/tests/integration/targets/vyos_logging_global/tests/cli/rendered.yaml b/tests/integration/targets/vyos_logging_global/tests/cli/rendered.yaml index 366f889..01caca5 100644 --- a/tests/integration/targets/vyos_logging_global/tests/cli/rendered.yaml +++ b/tests/integration/targets/vyos_logging_global/tests/cli/rendered.yaml @@ -1,6 +1,7 @@ --- - debug: - msg: START vyos_logging_global rendered integration tests on connection={{ ansible_connection + msg: + START vyos_logging_global rendered integration tests on connection={{ ansible_connection }} - include_tasks: _remove_config.yaml @@ -8,7 +9,6 @@ - include_tasks: _populate.yaml - block: - - name: Structure provided configuration into device specific commands register: result vyos.vyos.vyos_logging_global: &id001 @@ -46,5 +46,4 @@ \ |length == 0 }}" always: - - include_tasks: _remove_config.yaml diff --git a/tests/integration/targets/vyos_ntp_global/defaults/main.yaml b/tests/integration/targets/vyos_ntp_global/defaults/main.yaml index 852a6be..164afea 100644 --- a/tests/integration/targets/vyos_ntp_global/defaults/main.yaml +++ b/tests/integration/targets/vyos_ntp_global/defaults/main.yaml @@ -1,3 +1,3 @@ --- -testcase: '[^_].*' +testcase: "[^_].*" test_items: [] diff --git a/tests/integration/targets/vyos_ntp_global/tasks/cli.yaml b/tests/integration/targets/vyos_ntp_global/tasks/cli.yaml index 93eb2fe..83496e0 100644 --- a/tests/integration/targets/vyos_ntp_global/tasks/cli.yaml +++ b/tests/integration/targets/vyos_ntp_global/tasks/cli.yaml @@ -1,8 +1,8 @@ --- - name: Collect all cli test cases find: - paths: '{{ role_path }}/tests/cli' - patterns: '{{ testcase }}.yaml' + paths: "{{ role_path }}/tests/cli" + patterns: "{{ testcase }}.yaml" use_regex: true register: test_cases delegate_to: localhost @@ -11,9 +11,9 @@ set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}" - name: Run test case (connection=ansible.netcommon.network_cli) - include: '{{ test_case_to_run }}' + include: "{{ test_case_to_run }}" vars: ansible_connection: ansible.netcommon.network_cli - with_items: '{{ test_items }}' + with_items: "{{ test_items }}" loop_control: loop_var: test_case_to_run diff --git a/tests/integration/targets/vyos_ntp_global/tests/cli/deleted.yaml b/tests/integration/targets/vyos_ntp_global/tests/cli/deleted.yaml index 530e2ad..81f406c 100644 --- a/tests/integration/targets/vyos_ntp_global/tests/cli/deleted.yaml +++ b/tests/integration/targets/vyos_ntp_global/tests/cli/deleted.yaml @@ -7,7 +7,6 @@ - include_tasks: _populate_config.yaml - block: - - name: Delete the provided configuration register: result vyos.vyos.vyos_ntp_global: &id001 @@ -25,7 +24,8 @@ that: - result.after == populate.config - - name: Delete the existing configuration with the provided running configuration + - name: + Delete the existing configuration with the provided running configuration (IDEMPOTENT) register: result vyos.vyos.vyos_ntp_global: *id001 @@ -36,5 +36,4 @@ - result['changed'] == false always: - - include_tasks: _remove_config.yaml diff --git a/tests/integration/targets/vyos_ntp_global/tests/cli/gathered.yaml b/tests/integration/targets/vyos_ntp_global/tests/cli/gathered.yaml index 5ac350d..3c9032b 100644 --- a/tests/integration/targets/vyos_ntp_global/tests/cli/gathered.yaml +++ b/tests/integration/targets/vyos_ntp_global/tests/cli/gathered.yaml @@ -8,7 +8,6 @@ - include_tasks: _populate_config.yaml - block: - - name: Gather config from the device in structured format. register: result vyos.vyos.vyos_ntp_global: diff --git a/tests/integration/targets/vyos_ntp_global/tests/cli/merged.yaml b/tests/integration/targets/vyos_ntp_global/tests/cli/merged.yaml index 2a22ad8..ad36012 100644 --- a/tests/integration/targets/vyos_ntp_global/tests/cli/merged.yaml +++ b/tests/integration/targets/vyos_ntp_global/tests/cli/merged.yaml @@ -37,7 +37,6 @@ - result.after == ansible_facts['network_resources']['ntp_global'] - result.after == merged.after - - name: Assert that before dicts were correctly generated assert: that: diff --git a/tests/integration/targets/vyos_ntp_global/tests/cli/overridden.yaml b/tests/integration/targets/vyos_ntp_global/tests/cli/overridden.yaml index 2269e74..43def13 100644 --- a/tests/integration/targets/vyos_ntp_global/tests/cli/overridden.yaml +++ b/tests/integration/targets/vyos_ntp_global/tests/cli/overridden.yaml @@ -8,7 +8,6 @@ - include_tasks: _populate_config.yaml - block: - - name: Override the existing configuration with the provided running configuration register: result vyos.vyos.vyos_ntp_global: &id001 @@ -38,7 +37,8 @@ - result.after == ansible_facts['network_resources']['ntp_global'] - result.after == overridden.after - - name: Override the existing configuration with the provided running configuration + - name: + Override the existing configuration with the provided running configuration (IDEMPOTENT) register: result vyos.vyos.vyos_ntp_global: *id001 @@ -49,5 +49,4 @@ - result['changed'] == false always: - - include_tasks: _remove_config.yaml diff --git a/tests/integration/targets/vyos_ntp_global/tests/cli/parsed.yaml b/tests/integration/targets/vyos_ntp_global/tests/cli/parsed.yaml index c660ac4..09524b0 100644 --- a/tests/integration/targets/vyos_ntp_global/tests/cli/parsed.yaml +++ b/tests/integration/targets/vyos_ntp_global/tests/cli/parsed.yaml @@ -1,6 +1,7 @@ --- - debug: - msg: START vyos_ntp_global parsed integration tests on connection={{ ansible_connection + msg: + START vyos_ntp_global parsed integration tests on connection={{ ansible_connection }} - name: Provide the running configuration for parsing (config to be parsed) @@ -9,7 +10,6 @@ running_config: "{{ lookup('file', '_parsed.cfg') }}" state: parsed - - name: Assert that config was correctly parsed assert: that: diff --git a/tests/integration/targets/vyos_ntp_global/tests/cli/rendered.yaml b/tests/integration/targets/vyos_ntp_global/tests/cli/rendered.yaml index 1c1edd7..8705509 100644 --- a/tests/integration/targets/vyos_ntp_global/tests/cli/rendered.yaml +++ b/tests/integration/targets/vyos_ntp_global/tests/cli/rendered.yaml @@ -6,7 +6,6 @@ - include_tasks: _remove_config.yaml - block: - - name: Structure provided configuration into device specific commands register: result vyos.vyos.vyos_ntp_global: &id001 diff --git a/tests/integration/targets/vyos_ntp_global/vars/main.yaml b/tests/integration/targets/vyos_ntp_global/vars/main.yaml index 3b4dbc4..6cd65ce 100644 --- a/tests/integration/targets/vyos_ntp_global/vars/main.yaml +++ b/tests/integration/targets/vyos_ntp_global/vars/main.yaml @@ -62,7 +62,6 @@ overridden: - set system ntp server server2 preempt - set system ntp server server_add preempt - after: servers: - server: 0.pool.ntp.org diff --git a/tests/integration/targets/vyos_ospf_interfaces/defaults/main.yaml b/tests/integration/targets/vyos_ospf_interfaces/defaults/main.yaml index 852a6be..164afea 100644 --- a/tests/integration/targets/vyos_ospf_interfaces/defaults/main.yaml +++ b/tests/integration/targets/vyos_ospf_interfaces/defaults/main.yaml @@ -1,3 +1,3 @@ --- -testcase: '[^_].*' +testcase: "[^_].*" test_items: [] diff --git a/tests/integration/targets/vyos_ospf_interfaces/tasks/cli.yaml b/tests/integration/targets/vyos_ospf_interfaces/tasks/cli.yaml index 93eb2fe..83496e0 100644 --- a/tests/integration/targets/vyos_ospf_interfaces/tasks/cli.yaml +++ b/tests/integration/targets/vyos_ospf_interfaces/tasks/cli.yaml @@ -1,8 +1,8 @@ --- - name: Collect all cli test cases find: - paths: '{{ role_path }}/tests/cli' - patterns: '{{ testcase }}.yaml' + paths: "{{ role_path }}/tests/cli" + patterns: "{{ testcase }}.yaml" use_regex: true register: test_cases delegate_to: localhost @@ -11,9 +11,9 @@ set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}" - name: Run test case (connection=ansible.netcommon.network_cli) - include: '{{ test_case_to_run }}' + include: "{{ test_case_to_run }}" vars: ansible_connection: ansible.netcommon.network_cli - with_items: '{{ test_items }}' + with_items: "{{ test_items }}" loop_control: loop_var: test_case_to_run diff --git a/tests/integration/targets/vyos_ospf_interfaces/tests/cli/deleted.yaml b/tests/integration/targets/vyos_ospf_interfaces/tests/cli/deleted.yaml index 58cd9ff..4efca68 100644 --- a/tests/integration/targets/vyos_ospf_interfaces/tests/cli/deleted.yaml +++ b/tests/integration/targets/vyos_ospf_interfaces/tests/cli/deleted.yaml @@ -8,7 +8,6 @@ - include_tasks: _populate.yaml - block: - - name: Delete the provided configuration register: result vyos.vyos.vyos_ospf_interfaces: &id001 @@ -26,7 +25,8 @@ - result.commands|symmetric_difference(deleted.commands) == [] - result.after|symmetric_difference(ansible_facts['network_resources']['ospf_interfaces']) == [] - - name: Delete the existing configuration with the provided running configuration + - name: + Delete the existing configuration with the provided running configuration (IDEMPOTENT) register: result vyos.vyos.vyos_ospf_interfaces: *id001 @@ -37,5 +37,4 @@ - result['changed'] == false always: - - include_tasks: _remove_config.yaml diff --git a/tests/integration/targets/vyos_ospf_interfaces/tests/cli/empty_config.yaml b/tests/integration/targets/vyos_ospf_interfaces/tests/cli/empty_config.yaml index aff0f66..f99b8fe 100644 --- a/tests/integration/targets/vyos_ospf_interfaces/tests/cli/empty_config.yaml +++ b/tests/integration/targets/vyos_ospf_interfaces/tests/cli/empty_config.yaml @@ -1,6 +1,7 @@ --- - debug: - msg: START vyos_ospf_interfaces empty_config integration tests on connection={{ + msg: + START vyos_ospf_interfaces empty_config integration tests on connection={{ ansible_connection }} - name: Merged with empty config should give appropriate error message diff --git a/tests/integration/targets/vyos_ospf_interfaces/tests/cli/gathered.yaml b/tests/integration/targets/vyos_ospf_interfaces/tests/cli/gathered.yaml index 85a7cf2..21b6e5a 100644 --- a/tests/integration/targets/vyos_ospf_interfaces/tests/cli/gathered.yaml +++ b/tests/integration/targets/vyos_ospf_interfaces/tests/cli/gathered.yaml @@ -8,7 +8,6 @@ - include_tasks: _populate.yaml - block: - - name: Gather config from the device in structured format. register: result vyos.vyos.vyos_ospf_interfaces: diff --git a/tests/integration/targets/vyos_ospf_interfaces/tests/cli/overridden.yaml b/tests/integration/targets/vyos_ospf_interfaces/tests/cli/overridden.yaml index 0db10d2..dae9a6e 100644 --- a/tests/integration/targets/vyos_ospf_interfaces/tests/cli/overridden.yaml +++ b/tests/integration/targets/vyos_ospf_interfaces/tests/cli/overridden.yaml @@ -1,6 +1,7 @@ --- - debug: - msg: START vyos_ospf_interfaces overridden integration tests on connection={{ + msg: + START vyos_ospf_interfaces overridden integration tests on connection={{ ansible_connection }} - include_tasks: _remove_config.yaml @@ -8,7 +9,6 @@ - include_tasks: _populate.yaml - block: - - name: Override the existing configuration with the provided running configuration register: result vyos.vyos.vyos_ospf_interfaces: &id001 @@ -33,7 +33,8 @@ - result.commands|symmetric_difference(overridden.commands) == [] - result.after|symmetric_difference(ansible_facts['network_resources']['ospf_interfaces']) == [] - - name: Override the existing configuration with the provided running configuration + - name: + Override the existing configuration with the provided running configuration (IDEMPOTENT) register: result vyos.vyos.vyos_ospf_interfaces: *id001 @@ -44,5 +45,4 @@ - result['changed'] == false always: - - include_tasks: _remove_config.yaml diff --git a/tests/integration/targets/vyos_ospf_interfaces/tests/cli/parsed.yaml b/tests/integration/targets/vyos_ospf_interfaces/tests/cli/parsed.yaml index 4e327e1..c260ec4 100644 --- a/tests/integration/targets/vyos_ospf_interfaces/tests/cli/parsed.yaml +++ b/tests/integration/targets/vyos_ospf_interfaces/tests/cli/parsed.yaml @@ -1,6 +1,7 @@ --- - debug: - msg: START vyos_ospfv3_interfaces parsed integration tests on connection={{ ansible_connection + msg: + START vyos_ospfv3_interfaces parsed integration tests on connection={{ ansible_connection }} - name: Provide the running configuration for parsing (config to be parsed) diff --git a/tests/integration/targets/vyos_ospf_interfaces/tests/cli/rendered.yaml b/tests/integration/targets/vyos_ospf_interfaces/tests/cli/rendered.yaml index 328406b..2c27672 100644 --- a/tests/integration/targets/vyos_ospf_interfaces/tests/cli/rendered.yaml +++ b/tests/integration/targets/vyos_ospf_interfaces/tests/cli/rendered.yaml @@ -6,7 +6,6 @@ - include_tasks: _remove_config.yaml - block: - - name: Structure provided configuration into device specific commands register: result vyos.vyos.vyos_ospf_interfaces: diff --git a/tests/integration/targets/vyos_ospf_interfaces/tests/cli/replaced.yaml b/tests/integration/targets/vyos_ospf_interfaces/tests/cli/replaced.yaml index a98b616..89c8c76 100644 --- a/tests/integration/targets/vyos_ospf_interfaces/tests/cli/replaced.yaml +++ b/tests/integration/targets/vyos_ospf_interfaces/tests/cli/replaced.yaml @@ -8,7 +8,6 @@ - include_tasks: _populate.yaml - block: - - name: Replace the existing configuration with the provided running configuration register: result vyos.vyos.vyos_ospf_interfaces: &id001 @@ -44,7 +43,8 @@ - result.commands|symmetric_difference(replaced.commands) == [] - result.after|symmetric_difference(ansible_facts['network_resources']['ospf_interfaces']) == [] - - name: Replace the existing configuration with the provided running configuration + - name: + Replace the existing configuration with the provided running configuration (IDEMPOTENT) register: result vyos.vyos.vyos_ospf_interfaces: *id001 @@ -55,5 +55,4 @@ - result['changed'] == false always: - - include_tasks: _remove_config.yaml diff --git a/tests/integration/targets/vyos_ospfv2/defaults/main.yaml b/tests/integration/targets/vyos_ospfv2/defaults/main.yaml index 852a6be..164afea 100644 --- a/tests/integration/targets/vyos_ospfv2/defaults/main.yaml +++ b/tests/integration/targets/vyos_ospfv2/defaults/main.yaml @@ -1,3 +1,3 @@ --- -testcase: '[^_].*' +testcase: "[^_].*" test_items: [] diff --git a/tests/integration/targets/vyos_ospfv2/tasks/cli.yaml b/tests/integration/targets/vyos_ospfv2/tasks/cli.yaml index 93eb2fe..83496e0 100644 --- a/tests/integration/targets/vyos_ospfv2/tasks/cli.yaml +++ b/tests/integration/targets/vyos_ospfv2/tasks/cli.yaml @@ -1,8 +1,8 @@ --- - name: Collect all cli test cases find: - paths: '{{ role_path }}/tests/cli' - patterns: '{{ testcase }}.yaml' + paths: "{{ role_path }}/tests/cli" + patterns: "{{ testcase }}.yaml" use_regex: true register: test_cases delegate_to: localhost @@ -11,9 +11,9 @@ set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}" - name: Run test case (connection=ansible.netcommon.network_cli) - include: '{{ test_case_to_run }}' + include: "{{ test_case_to_run }}" vars: ansible_connection: ansible.netcommon.network_cli - with_items: '{{ test_items }}' + with_items: "{{ test_items }}" loop_control: loop_var: test_case_to_run diff --git a/tests/integration/targets/vyos_ospfv2/tasks/redirection.yaml b/tests/integration/targets/vyos_ospfv2/tasks/redirection.yaml index 5564a3e..48ad53a 100644 --- a/tests/integration/targets/vyos_ospfv2/tasks/redirection.yaml +++ b/tests/integration/targets/vyos_ospfv2/tasks/redirection.yaml @@ -1,8 +1,8 @@ --- - name: collect all redirection cli test cases find: - paths: '{{ role_path }}/tests/redirection/cli' - patterns: '{{ testcase }}.yaml' + paths: "{{ role_path }}/tests/redirection/cli" + patterns: "{{ testcase }}.yaml" register: shortname_test_cases delegate_to: localhost @@ -10,7 +10,7 @@ set_fact: test_items="{{ shortname_test_cases.files | map(attribute='path') | list }}" - name: run test case (connection=ansible.netcommon.network_cli) - include: '{{ test_case_to_run }} ansible_connection=ansible.netcommon.network_cli' - with_items: '{{ test_items }}' + include: "{{ test_case_to_run }} ansible_connection=ansible.netcommon.network_cli" + with_items: "{{ test_items }}" loop_control: loop_var: test_case_to_run diff --git a/tests/integration/targets/vyos_ospfv2/tests/cli/_populate.yaml b/tests/integration/targets/vyos_ospfv2/tests/cli/_populate.yaml index 9f358d5..a445375 100644 --- a/tests/integration/targets/vyos_ospfv2/tests/cli/_populate.yaml +++ b/tests/integration/targets/vyos_ospfv2/tests/cli/_populate.yaml @@ -2,34 +2,34 @@ - name: Setup vars: lines: "set protocols ospf mpls-te 'enable' \n - set protocols ospf mpls-te router-address '192.0.11.11' \n - set protocols ospf redistribute bgp metric-type '2' \n - set protocols ospf redistribute bgp metric '10'\n - set protocols ospf default-information originate metric-type '2' \n - set protocols ospf default-information originate 'always' \n - set protocols ospf default-information originate metric '10' \n - set protocols ospf default-information originate route-map 'ingress' \n - set protocols ospf auto-cost reference-bandwidth '2' \n - set protocols ospf parameters router-id '192.0.1.1' \n - set protocols ospf parameters 'opaque-lsa' \n - set protocols ospf parameters abr-type 'cisco' \n - set protocols ospf parameters 'rfc1583-compatibility' \n - set protocols ospf passive-interface 'eth1' \n - set protocols ospf passive-interface 'eth2' \n - set protocols ospf max-metric router-lsa on-shutdown '10' \n - set protocols ospf max-metric router-lsa 'administrative' \n - set protocols ospf max-metric router-lsa on-startup '10' \n - set protocols ospf log-adjacency-changes 'detail' \n - set protocols ospf neighbor 192.0.11.12 priority '2' \n - set protocols ospf neighbor 192.0.11.12 poll-interval '10' \n - set protocols ospf area 2 authentication 'plaintext-password' \n - set protocols ospf area 2 shortcut 'enable' \n - set protocols ospf area 2 area-type 'normal' \n - set protocols ospf area 3 area-type 'nssa' \n - set protocols ospf area 4 range 192.0.3.0/24 cost '10' \n - set protocols ospf area 4 range 192.0.4.0/24 cost '12' \n - set protocols ospf area 4 area-type stub default-cost '20' \n - set protocols ospf area 4 network '192.0.2.0/24'" + set protocols ospf mpls-te router-address '192.0.11.11' \n + set protocols ospf redistribute bgp metric-type '2' \n + set protocols ospf redistribute bgp metric '10'\n + set protocols ospf default-information originate metric-type '2' \n + set protocols ospf default-information originate 'always' \n + set protocols ospf default-information originate metric '10' \n + set protocols ospf default-information originate route-map 'ingress' \n + set protocols ospf auto-cost reference-bandwidth '2' \n + set protocols ospf parameters router-id '192.0.1.1' \n + set protocols ospf parameters 'opaque-lsa' \n + set protocols ospf parameters abr-type 'cisco' \n + set protocols ospf parameters 'rfc1583-compatibility' \n + set protocols ospf passive-interface 'eth1' \n + set protocols ospf passive-interface 'eth2' \n + set protocols ospf max-metric router-lsa on-shutdown '10' \n + set protocols ospf max-metric router-lsa 'administrative' \n + set protocols ospf max-metric router-lsa on-startup '10' \n + set protocols ospf log-adjacency-changes 'detail' \n + set protocols ospf neighbor 192.0.11.12 priority '2' \n + set protocols ospf neighbor 192.0.11.12 poll-interval '10' \n + set protocols ospf area 2 authentication 'plaintext-password' \n + set protocols ospf area 2 shortcut 'enable' \n + set protocols ospf area 2 area-type 'normal' \n + set protocols ospf area 3 area-type 'nssa' \n + set protocols ospf area 4 range 192.0.3.0/24 cost '10' \n + set protocols ospf area 4 range 192.0.4.0/24 cost '12' \n + set protocols ospf area 4 area-type stub default-cost '20' \n + set protocols ospf area 4 network '192.0.2.0/24'" ansible.netcommon.cli_config: - config: '{{ lines }}' + config: "{{ lines }}" diff --git a/tests/integration/targets/vyos_ospfv2/tests/cli/_remove_config.yaml b/tests/integration/targets/vyos_ospfv2/tests/cli/_remove_config.yaml index 7360870..9c963bc 100644 --- a/tests/integration/targets/vyos_ospfv2/tests/cli/_remove_config.yaml +++ b/tests/integration/targets/vyos_ospfv2/tests/cli/_remove_config.yaml @@ -3,4 +3,4 @@ vars: lines: "delete protocols ospf\n" ansible.netcommon.cli_config: - config: '{{ lines }}' + config: "{{ lines }}" diff --git a/tests/integration/targets/vyos_ospfv2/tests/cli/deleted.yaml b/tests/integration/targets/vyos_ospfv2/tests/cli/deleted.yaml index a61f5a7..9fc0d70 100644 --- a/tests/integration/targets/vyos_ospfv2/tests/cli/deleted.yaml +++ b/tests/integration/targets/vyos_ospfv2/tests/cli/deleted.yaml @@ -6,7 +6,6 @@ - include_tasks: _populate.yaml - block: - - name: Delete attributes of ospfv2. register: result vyos.vyos.vyos_ospfv2: &id001 @@ -44,5 +43,4 @@ that: - "{{ deleted['after'] == result['before'] }}" always: - - include_tasks: _remove_config.yaml diff --git a/tests/integration/targets/vyos_ospfv2/tests/cli/parsed.yaml b/tests/integration/targets/vyos_ospfv2/tests/cli/parsed.yaml index cfa29f9..ac5c203 100644 --- a/tests/integration/targets/vyos_ospfv2/tests/cli/parsed.yaml +++ b/tests/integration/targets/vyos_ospfv2/tests/cli/parsed.yaml @@ -1,6 +1,7 @@ --- - debug: - msg: START vyos_ospfv2 parsed integration tests on connection={{ ansible_connection + msg: + START vyos_ospfv2 parsed integration tests on connection={{ ansible_connection }} - name: Parse externally provided ospfv2 config to agnostic model diff --git a/tests/integration/targets/vyos_ospfv2/tests/cli/rendered.yaml b/tests/integration/targets/vyos_ospfv2/tests/cli/rendered.yaml index 8a805a6..e11aa6a 100644 --- a/tests/integration/targets/vyos_ospfv2/tests/cli/rendered.yaml +++ b/tests/integration/targets/vyos_ospfv2/tests/cli/rendered.yaml @@ -6,12 +6,11 @@ - include_tasks: _remove_config.yaml - block: - - name: Structure provided configuration into device specific commands register: result vyos.vyos.vyos_ospfv2: config: - log_adjacency_changes: 'detail' + log_adjacency_changes: "detail" max_metric: router_lsa: administrative: true @@ -22,48 +21,48 @@ always: true metric: 10 metric_type: 2 - route_map: 'ingress' + route_map: "ingress" mpls_te: enabled: true - router_address: '192.0.11.11' + router_address: "192.0.11.11" auto_cost: reference_bandwidth: 2 neighbor: - - neighbor_id: '192.0.11.12' + - neighbor_id: "192.0.11.12" poll_interval: 10 priority: 2 redistribute: - - route_type: 'bgp' + - route_type: "bgp" metric: 10 metric_type: 2 passive_interface: - - 'eth1' - - 'eth2' + - "eth1" + - "eth2" parameters: - router_id: '192.0.1.1' + router_id: "192.0.1.1" opaque_lsa: true rfc1583_compatibility: true - abr_type: 'cisco' + abr_type: "cisco" areas: - - area_id: '2' + - area_id: "2" area_type: normal: true authentication: "plaintext-password" - shortcut: 'enable' - - area_id: '3' + shortcut: "enable" + - area_id: "3" area_type: nssa: set: true - - area_id: '4' + - area_id: "4" area_type: stub: default_cost: 20 network: - - address: '192.0.2.0/24' + - address: "192.0.2.0/24" range: - - address: '192.0.3.0/24' + - address: "192.0.3.0/24" cost: 10 - - address: '192.0.4.0/24' + - address: "192.0.4.0/24" cost: 12 state: rendered diff --git a/tests/integration/targets/vyos_ospfv2/tests/cli/replaced.yaml b/tests/integration/targets/vyos_ospfv2/tests/cli/replaced.yaml index 07606f9..e1fc389 100644 --- a/tests/integration/targets/vyos_ospfv2/tests/cli/replaced.yaml +++ b/tests/integration/targets/vyos_ospfv2/tests/cli/replaced.yaml @@ -8,12 +8,11 @@ - include_tasks: _populate.yaml - block: - - name: Replace device configurations of listed ospfv2 routes with provided configurations register: result vyos.vyos.vyos_ospfv2: &id001 config: - log_adjacency_changes: 'detail' + log_adjacency_changes: "detail" max_metric: router_lsa: administrative: true @@ -24,44 +23,44 @@ always: true metric: 10 metric_type: 2 - route_map: 'ingress' + route_map: "ingress" mpls_te: enabled: true - router_address: '192.0.22.22' + router_address: "192.0.22.22" auto_cost: reference_bandwidth: 2 neighbor: - - neighbor_id: '192.0.11.12' + - neighbor_id: "192.0.11.12" poll_interval: 10 priority: 2 redistribute: - - route_type: 'bgp' + - route_type: "bgp" metric: 10 metric_type: 2 passive_interface: - - 'eth1' + - "eth1" parameters: - router_id: '192.0.1.1' + router_id: "192.0.1.1" opaque_lsa: true rfc1583_compatibility: true - abr_type: 'cisco' + abr_type: "cisco" areas: - - area_id: '2' + - area_id: "2" area_type: normal: true authentication: "plaintext-password" - shortcut: 'enable' - - area_id: '4' + shortcut: "enable" + - area_id: "4" area_type: stub: default_cost: 20 network: - - address: '192.0.2.0/24' - - address: '192.0.12.0/24' - - address: '192.0.22.0/24' - - address: '192.0.32.0/24' + - address: "192.0.2.0/24" + - address: "192.0.12.0/24" + - address: "192.0.22.0/24" + - address: "192.0.32.0/24" range: - - address: '1.1.2.0/24' + - address: "1.1.2.0/24" cost: 10 state: replaced @@ -81,7 +80,8 @@ that: - "{{ replaced['after'] == result['after'] }}" - - name: Replace device configurations of listed ospfv2 routes with provided configurarions + - name: + Replace device configurations of listed ospfv2 routes with provided configurarions (IDEMPOTENT) register: result vyos.vyos.vyos_ospfv2: *id001 @@ -96,5 +96,4 @@ that: - "{{ replaced['after'] == result['before'] }}" always: - - include_tasks: _remove_config.yaml diff --git a/tests/integration/targets/vyos_ospfv2/tests/cli/rtt.yaml b/tests/integration/targets/vyos_ospfv2/tests/cli/rtt.yaml index 7efc2a7..9407ffa 100644 --- a/tests/integration/targets/vyos_ospfv2/tests/cli/rtt.yaml +++ b/tests/integration/targets/vyos_ospfv2/tests/cli/rtt.yaml @@ -6,12 +6,11 @@ - include_tasks: _remove_config.yaml - block: - - name: Apply the provided configuration (base config) register: base_config vyos.vyos.vyos_ospfv2: config: - log_adjacency_changes: 'detail' + log_adjacency_changes: "detail" max_metric: router_lsa: administrative: true @@ -22,48 +21,48 @@ always: true metric: 10 metric_type: 2 - route_map: 'ingress' + route_map: "ingress" mpls_te: enabled: true - router_address: '192.0.11.11' + router_address: "192.0.11.11" auto_cost: reference_bandwidth: 2 neighbor: - - neighbor_id: '192.0.11.12' + - neighbor_id: "192.0.11.12" poll_interval: 10 priority: 2 redistribute: - - route_type: 'bgp' + - route_type: "bgp" metric: 10 metric_type: 2 passive_interface: - - 'eth1' - - 'eth2' + - "eth1" + - "eth2" parameters: - router_id: '192.0.1.1' + router_id: "192.0.1.1" opaque_lsa: true rfc1583_compatibility: true - abr_type: 'cisco' + abr_type: "cisco" areas: - - area_id: '2' + - area_id: "2" area_type: normal: true authentication: "plaintext-password" - shortcut: 'enable' - - area_id: '3' + shortcut: "enable" + - area_id: "3" area_type: nssa: set: true - - area_id: '4' + - area_id: "4" area_type: stub: default_cost: 20 network: - - address: '192.0.2.0/24' + - address: "192.0.2.0/24" range: - - address: '192.0.3.0/24' + - address: "192.0.3.0/24" cost: 10 - - address: '192.0.4.0/24' + - address: "192.0.4.0/24" cost: 12 state: merged @@ -79,23 +78,23 @@ vyos.vyos.vyos_ospfv2: config: areas: - - area_id: '2' + - area_id: "2" area_type: normal: true authentication: "plaintext-password" - shortcut: 'enable' - - area_id: '4' + shortcut: "enable" + - area_id: "4" area_type: stub: default_cost: 20 set: true network: - - address: '192.0.12.0/24' - - address: '192.0.2.0/24' - - address: '192.0.22.0/24' - - address: '192.0.32.0/24' + - address: "192.0.12.0/24" + - address: "192.0.2.0/24" + - address: "192.0.22.0/24" + - address: "192.0.32.0/24" range: - - address: '1.1.2.0/24' + - address: "1.1.2.0/24" cost: 10 auto_cost: reference_bandwidth: 2 @@ -104,8 +103,8 @@ always: true metric: 10 metric_type: 2 - route_map: 'ingress' - log_adjacency_changes: 'detail' + route_map: "ingress" + log_adjacency_changes: "detail" max_metric: router_lsa: administrative: true @@ -113,22 +112,22 @@ on_startup: 10 mpls_te: enabled: true - router_address: '192.0.22.22' + router_address: "192.0.22.22" neighbor: - - neighbor_id: '192.0.11.12' + - neighbor_id: "192.0.11.12" poll_interval: 10 priority: 2 parameters: - abr_type: 'cisco' + abr_type: "cisco" opaque_lsa: true rfc1583_compatibility: true - router_id: '192.0.1.1' + router_id: "192.0.1.1" passive_interface: - - 'eth1' + - "eth1" redistribute: - metric: 10 metric_type: 2 - route_type: 'bgp' + route_type: "bgp" state: replaced - name: Assert that changes were applied @@ -145,5 +144,4 @@ assert: that: "{{ base_config['after'] == revert['after']}}" always: - - include_tasks: _remove_config.yaml diff --git a/tests/integration/targets/vyos_ospfv2/vars/main.yaml b/tests/integration/targets/vyos_ospfv2/vars/main.yaml index e55da20..da81c19 100644 --- a/tests/integration/targets/vyos_ospfv2/vars/main.yaml +++ b/tests/integration/targets/vyos_ospfv2/vars/main.yaml @@ -40,26 +40,26 @@ merged: - set protocols ospf area 4 network 192.0.2.0/24 after: areas: - - area_id: '2' + - area_id: "2" area_type: normal: true authentication: "plaintext-password" - shortcut: 'enable' - - area_id: '3' + shortcut: "enable" + - area_id: "3" area_type: nssa: set: true - - area_id: '4' + - area_id: "4" area_type: stub: default_cost: 20 set: true network: - - address: '192.0.2.0/24' + - address: "192.0.2.0/24" range: - - address: '192.0.3.0/24' + - address: "192.0.3.0/24" cost: 10 - - address: '192.0.4.0/24' + - address: "192.0.4.0/24" cost: 12 auto_cost: reference_bandwidth: 2 @@ -68,8 +68,8 @@ merged: always: true metric: 10 metric_type: 2 - route_map: 'ingress' - log_adjacency_changes: 'detail' + route_map: "ingress" + log_adjacency_changes: "detail" max_metric: router_lsa: administrative: true @@ -77,46 +77,46 @@ merged: on_startup: 10 mpls_te: enabled: true - router_address: '192.0.11.11' + router_address: "192.0.11.11" neighbor: - - neighbor_id: '192.0.11.12' + - neighbor_id: "192.0.11.12" poll_interval: 10 priority: 2 parameters: - abr_type: 'cisco' + abr_type: "cisco" opaque_lsa: true rfc1583_compatibility: true - router_id: '192.0.1.1' + router_id: "192.0.1.1" passive_interface: - - 'eth1' - - 'eth2' + - "eth1" + - "eth2" redistribute: - metric: 10 metric_type: 2 - route_type: 'bgp' + route_type: "bgp" merged_update: before: areas: - - area_id: '2' + - area_id: "2" area_type: normal: true authentication: "plaintext-password" - shortcut: 'enable' - - area_id: '3' + shortcut: "enable" + - area_id: "3" area_type: nssa: set: true - - area_id: '4' + - area_id: "4" area_type: stub: default_cost: 20 set: true network: - - address: '192.0.2.0/24' + - address: "192.0.2.0/24" range: - - address: '192.0.3.0/24' + - address: "192.0.3.0/24" cost: 10 - - address: '192.0.4.0/24' + - address: "192.0.4.0/24" cost: 12 auto_cost: reference_bandwidth: 2 @@ -125,8 +125,8 @@ merged_update: always: true metric: 10 metric_type: 2 - route_map: 'ingress' - log_adjacency_changes: 'detail' + route_map: "ingress" + log_adjacency_changes: "detail" max_metric: router_lsa: administrative: true @@ -134,43 +134,43 @@ merged_update: on_startup: 10 mpls_te: enabled: true - router_address: '192.0.11.11' + router_address: "192.0.11.11" neighbor: - - neighbor_id: '192.0.11.12' + - neighbor_id: "192.0.11.12" poll_interval: 10 priority: 2 parameters: - abr_type: 'cisco' + abr_type: "cisco" opaque_lsa: true rfc1583_compatibility: true - router_id: '192.0.1.1' + router_id: "192.0.1.1" passive_interface: - - 'eth1' - - 'eth2' + - "eth1" + - "eth2" redistribute: - metric: 10 metric_type: 2 - route_type: 'bgp' + route_type: "bgp" after: areas: - - area_id: '2' + - area_id: "2" area_type: normal: true authentication: "plaintext-password" - shortcut: 'enable' - - area_id: '3' + shortcut: "enable" + - area_id: "3" area_type: nssa: set: true - - area_id: '4' + - area_id: "4" network: - - address: '192.0.2.0/24' - - address: '192.0.22.0/24' - - address: '192.0.32.0/24' + - address: "192.0.2.0/24" + - address: "192.0.22.0/24" + - address: "192.0.32.0/24" range: - - address: '192.0.3.0/24' + - address: "192.0.3.0/24" cost: 10 - - address: '192.0.4.0/24' + - address: "192.0.4.0/24" cost: 12 auto_cost: reference_bandwidth: 2 @@ -179,8 +179,8 @@ merged_update: always: true metric: 10 metric_type: 2 - route_map: 'ingress' - log_adjacency_changes: 'detail' + route_map: "ingress" + log_adjacency_changes: "detail" max_metric: router_lsa: administrative: true @@ -188,49 +188,49 @@ merged_update: on_startup: 10 mpls_te: enabled: true - router_address: '192.0.11.11' + router_address: "192.0.11.11" neighbor: - - neighbor_id: '192.0.11.12' + - neighbor_id: "192.0.11.12" poll_interval: 10 priority: 2 parameters: - abr_type: 'cisco' + abr_type: "cisco" opaque_lsa: true rfc1583_compatibility: true - router_id: '192.0.1.1' + router_id: "192.0.1.1" passive_interface: - - 'eth1' - - 'eth2' + - "eth1" + - "eth2" redistribute: - metric: 10 metric_type: 2 - route_type: 'bgp' + route_type: "bgp" commands: - delete protocols ospf area 4 area-type stub - set protocols ospf area 4 network 192.0.22.0/24 - set protocols ospf area 4 network 192.0.32.0/24 populate: areas: - - area_id: '2' + - area_id: "2" area_type: normal: true authentication: "plaintext-password" - shortcut: 'enable' - - area_id: '3' + shortcut: "enable" + - area_id: "3" area_type: nssa: set: true - - area_id: '4' + - area_id: "4" area_type: stub: default_cost: 20 set: true network: - - address: '192.0.2.0/24' + - address: "192.0.2.0/24" range: - - address: '192.0.3.0/24' + - address: "192.0.3.0/24" cost: 10 - - address: '192.0.4.0/24' + - address: "192.0.4.0/24" cost: 12 auto_cost: reference_bandwidth: 2 @@ -239,8 +239,8 @@ populate: always: true metric: 10 metric_type: 2 - route_map: 'ingress' - log_adjacency_changes: 'detail' + route_map: "ingress" + log_adjacency_changes: "detail" max_metric: router_lsa: administrative: true @@ -248,23 +248,23 @@ populate: on_startup: 10 mpls_te: enabled: true - router_address: '192.0.11.11' + router_address: "192.0.11.11" neighbor: - - neighbor_id: '192.0.11.12' + - neighbor_id: "192.0.11.12" poll_interval: 10 priority: 2 parameters: - abr_type: 'cisco' + abr_type: "cisco" opaque_lsa: true rfc1583_compatibility: true - router_id: '192.0.1.1' + router_id: "192.0.1.1" passive_interface: - - 'eth1' - - 'eth2' + - "eth1" + - "eth2" redistribute: - metric: 10 metric_type: 2 - route_type: 'bgp' + route_type: "bgp" replaced: commands: - delete protocols ospf passive-interface eth2 @@ -281,23 +281,23 @@ replaced: - set protocols ospf area 4 network 192.0.32.0/24 after: areas: - - area_id: '2' + - area_id: "2" area_type: normal: true authentication: "plaintext-password" - shortcut: 'enable' - - area_id: '4' + shortcut: "enable" + - area_id: "4" area_type: stub: default_cost: 20 set: true network: - - address: '192.0.12.0/24' - - address: '192.0.2.0/24' - - address: '192.0.22.0/24' - - address: '192.0.32.0/24' + - address: "192.0.12.0/24" + - address: "192.0.2.0/24" + - address: "192.0.22.0/24" + - address: "192.0.32.0/24" range: - - address: '1.1.2.0/24' + - address: "1.1.2.0/24" cost: 10 auto_cost: reference_bandwidth: 2 @@ -306,8 +306,8 @@ replaced: always: true metric: 10 metric_type: 2 - route_map: 'ingress' - log_adjacency_changes: 'detail' + route_map: "ingress" + log_adjacency_changes: "detail" max_metric: router_lsa: administrative: true @@ -315,22 +315,22 @@ replaced: on_startup: 10 mpls_te: enabled: true - router_address: '192.0.22.22' + router_address: "192.0.22.22" neighbor: - - neighbor_id: '192.0.11.12' + - neighbor_id: "192.0.11.12" poll_interval: 10 priority: 2 parameters: - abr_type: 'cisco' + abr_type: "cisco" opaque_lsa: true rfc1583_compatibility: true - router_id: '192.0.1.1' + router_id: "192.0.1.1" passive_interface: - - 'eth1' + - "eth1" redistribute: - metric: 10 metric_type: 2 - route_type: 'bgp' + route_type: "bgp" rendered: commands: - set protocols ospf mpls-te enable @@ -372,26 +372,26 @@ rendered: parsed: after: areas: - - area_id: '2' + - area_id: "2" area_type: normal: true authentication: "plaintext-password" - shortcut: 'enable' - - area_id: '3' + shortcut: "enable" + - area_id: "3" area_type: nssa: set: true - - area_id: '4' + - area_id: "4" area_type: stub: default_cost: 20 set: true network: - - address: '192.0.2.0/24' + - address: "192.0.2.0/24" range: - - address: '192.0.3.0/24' + - address: "192.0.3.0/24" cost: 10 - - address: '192.0.4.0/24' + - address: "192.0.4.0/24" cost: 12 auto_cost: reference_bandwidth: 2 @@ -400,8 +400,8 @@ parsed: always: true metric: 10 metric_type: 2 - route_map: 'ingress' - log_adjacency_changes: 'detail' + route_map: "ingress" + log_adjacency_changes: "detail" max_metric: router_lsa: administrative: true @@ -409,47 +409,47 @@ parsed: on_startup: 10 mpls_te: enabled: true - router_address: '192.0.11.11' + router_address: "192.0.11.11" neighbor: - - neighbor_id: '192.0.11.12' + - neighbor_id: "192.0.11.12" poll_interval: 10 priority: 2 parameters: - abr_type: 'cisco' + abr_type: "cisco" opaque_lsa: true rfc1583_compatibility: true - router_id: '192.0.1.1' + router_id: "192.0.1.1" passive_interface: - - 'eth1' - - 'eth2' + - "eth1" + - "eth2" redistribute: - metric: 10 metric_type: 2 - route_type: 'bgp' + route_type: "bgp" deleted: commands: - - 'delete protocols ospf' + - "delete protocols ospf" after: {} round_trip: after: areas: - - area_id: '2' + - area_id: "2" area_type: normal: true authentication: "plaintext-password" - shortcut: 'enable' - - area_id: '4' + shortcut: "enable" + - area_id: "4" area_type: stub: default_cost: 20 set: true network: - - address: '192.0.12.0/24' - - address: '192.0.2.0/24' - - address: '192.0.22.0/24' - - address: '192.0.32.0/24' + - address: "192.0.12.0/24" + - address: "192.0.2.0/24" + - address: "192.0.22.0/24" + - address: "192.0.32.0/24" range: - - address: '1.1.2.0/24' + - address: "1.1.2.0/24" cost: 10 auto_cost: reference_bandwidth: 2 @@ -458,8 +458,8 @@ round_trip: always: true metric: 10 metric_type: 2 - route_map: 'ingress' - log_adjacency_changes: 'detail' + route_map: "ingress" + log_adjacency_changes: "detail" max_metric: router_lsa: administrative: true @@ -467,19 +467,19 @@ round_trip: on_startup: 10 mpls_te: enabled: true - router_address: '192.0.22.22' + router_address: "192.0.22.22" neighbor: - - neighbor_id: '192.0.11.12' + - neighbor_id: "192.0.11.12" poll_interval: 10 priority: 2 parameters: - abr_type: 'cisco' + abr_type: "cisco" opaque_lsa: true rfc1583_compatibility: true - router_id: '192.0.1.1' + router_id: "192.0.1.1" passive_interface: - - 'eth1' + - "eth1" redistribute: - metric: 10 metric_type: 2 - route_type: 'bgp' + route_type: "bgp" diff --git a/tests/integration/targets/vyos_ospfv3/defaults/main.yaml b/tests/integration/targets/vyos_ospfv3/defaults/main.yaml index 852a6be..164afea 100644 --- a/tests/integration/targets/vyos_ospfv3/defaults/main.yaml +++ b/tests/integration/targets/vyos_ospfv3/defaults/main.yaml @@ -1,3 +1,3 @@ --- -testcase: '[^_].*' +testcase: "[^_].*" test_items: [] diff --git a/tests/integration/targets/vyos_ospfv3/tasks/cli.yaml b/tests/integration/targets/vyos_ospfv3/tasks/cli.yaml index 93eb2fe..83496e0 100644 --- a/tests/integration/targets/vyos_ospfv3/tasks/cli.yaml +++ b/tests/integration/targets/vyos_ospfv3/tasks/cli.yaml @@ -1,8 +1,8 @@ --- - name: Collect all cli test cases find: - paths: '{{ role_path }}/tests/cli' - patterns: '{{ testcase }}.yaml' + paths: "{{ role_path }}/tests/cli" + patterns: "{{ testcase }}.yaml" use_regex: true register: test_cases delegate_to: localhost @@ -11,9 +11,9 @@ set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}" - name: Run test case (connection=ansible.netcommon.network_cli) - include: '{{ test_case_to_run }}' + include: "{{ test_case_to_run }}" vars: ansible_connection: ansible.netcommon.network_cli - with_items: '{{ test_items }}' + with_items: "{{ test_items }}" loop_control: loop_var: test_case_to_run diff --git a/tests/integration/targets/vyos_ospfv3/tasks/redirection.yaml b/tests/integration/targets/vyos_ospfv3/tasks/redirection.yaml index 5564a3e..48ad53a 100644 --- a/tests/integration/targets/vyos_ospfv3/tasks/redirection.yaml +++ b/tests/integration/targets/vyos_ospfv3/tasks/redirection.yaml @@ -1,8 +1,8 @@ --- - name: collect all redirection cli test cases find: - paths: '{{ role_path }}/tests/redirection/cli' - patterns: '{{ testcase }}.yaml' + paths: "{{ role_path }}/tests/redirection/cli" + patterns: "{{ testcase }}.yaml" register: shortname_test_cases delegate_to: localhost @@ -10,7 +10,7 @@ set_fact: test_items="{{ shortname_test_cases.files | map(attribute='path') | list }}" - name: run test case (connection=ansible.netcommon.network_cli) - include: '{{ test_case_to_run }} ansible_connection=ansible.netcommon.network_cli' - with_items: '{{ test_items }}' + include: "{{ test_case_to_run }} ansible_connection=ansible.netcommon.network_cli" + with_items: "{{ test_items }}" loop_control: loop_var: test_case_to_run diff --git a/tests/integration/targets/vyos_ospfv3/tests/cli/_populate.yaml b/tests/integration/targets/vyos_ospfv3/tests/cli/_populate.yaml index fb66d0a..31f90ef 100644 --- a/tests/integration/targets/vyos_ospfv3/tests/cli/_populate.yaml +++ b/tests/integration/targets/vyos_ospfv3/tests/cli/_populate.yaml @@ -2,12 +2,12 @@ - name: Setup vars: lines: "set protocols ospfv3 area 2 export-list 'export1' \n - set protocols ospfv3 area 2 import-list 'import1' \n - set protocols ospfv3 area 2 range '2001:db10::/32' \n - set protocols ospfv3 area 2 range '2001:db20::/32' \n - set protocols ospfv3 area 2 range '2001:db30::/32' \n - set protocols ospfv3 area 3 range '2001:db40::/32' \n - set protocols ospfv3 parameters router-id '192.0.2.10' \n - set protocols ospfv3 redistribute 'bgp'" + set protocols ospfv3 area 2 import-list 'import1' \n + set protocols ospfv3 area 2 range '2001:db10::/32' \n + set protocols ospfv3 area 2 range '2001:db20::/32' \n + set protocols ospfv3 area 2 range '2001:db30::/32' \n + set protocols ospfv3 area 3 range '2001:db40::/32' \n + set protocols ospfv3 parameters router-id '192.0.2.10' \n + set protocols ospfv3 redistribute 'bgp'" ansible.netcommon.cli_config: - config: '{{ lines }}' + config: "{{ lines }}" diff --git a/tests/integration/targets/vyos_ospfv3/tests/cli/_remove_config.yaml b/tests/integration/targets/vyos_ospfv3/tests/cli/_remove_config.yaml index 2a47505..ca4537e 100644 --- a/tests/integration/targets/vyos_ospfv3/tests/cli/_remove_config.yaml +++ b/tests/integration/targets/vyos_ospfv3/tests/cli/_remove_config.yaml @@ -3,4 +3,4 @@ vars: lines: "delete protocols ospfv3\n" ansible.netcommon.cli_config: - config: '{{ lines }}' + config: "{{ lines }}" diff --git a/tests/integration/targets/vyos_ospfv3/tests/cli/deleted.yaml b/tests/integration/targets/vyos_ospfv3/tests/cli/deleted.yaml index 55bec18..e0be4c3 100644 --- a/tests/integration/targets/vyos_ospfv3/tests/cli/deleted.yaml +++ b/tests/integration/targets/vyos_ospfv3/tests/cli/deleted.yaml @@ -6,7 +6,6 @@ - include_tasks: _populate.yaml - block: - - name: Delete ospfv3 routes register: result vyos.vyos.vyos_ospfv3: &id001 @@ -44,5 +43,4 @@ that: - "{{ deleted['after'] == result['before'] }}" always: - - include_tasks: _remove_config.yaml diff --git a/tests/integration/targets/vyos_ospfv3/tests/cli/parsed.yaml b/tests/integration/targets/vyos_ospfv3/tests/cli/parsed.yaml index 6287083..1bec41a 100644 --- a/tests/integration/targets/vyos_ospfv3/tests/cli/parsed.yaml +++ b/tests/integration/targets/vyos_ospfv3/tests/cli/parsed.yaml @@ -1,6 +1,7 @@ --- - debug: - msg: START vyos_ospfv3 parsed integration tests on connection={{ ansible_connection + msg: + START vyos_ospfv3 parsed integration tests on connection={{ ansible_connection }} - name: Parse externally provided ospfv3 config to agnostic model diff --git a/tests/integration/targets/vyos_ospfv3/tests/cli/rendered.yaml b/tests/integration/targets/vyos_ospfv3/tests/cli/rendered.yaml index 3f714ce..b921bda 100644 --- a/tests/integration/targets/vyos_ospfv3/tests/cli/rendered.yaml +++ b/tests/integration/targets/vyos_ospfv3/tests/cli/rendered.yaml @@ -6,26 +6,25 @@ - include_tasks: _remove_config.yaml - block: - - name: Structure provided configuration into device specific commands register: result vyos.vyos.vyos_ospfv3: config: redistribute: - - route_type: 'bgp' + - route_type: "bgp" parameters: - router_id: '192.0.2.10' + router_id: "192.0.2.10" areas: - - area_id: '2' - export_list: 'export1' - import_list: 'import1' + - area_id: "2" + export_list: "export1" + import_list: "import1" range: - - address: '2001:db10::/32' - - address: '2001:db20::/32' - - address: '2001:db30::/32' - - area_id: '3' + - address: "2001:db10::/32" + - address: "2001:db20::/32" + - address: "2001:db30::/32" + - area_id: "3" range: - - address: '2001:db40::/32' + - address: "2001:db40::/32" state: rendered - name: Assert that correct set of commands were generated diff --git a/tests/integration/targets/vyos_ospfv3/tests/cli/replaced.yaml b/tests/integration/targets/vyos_ospfv3/tests/cli/replaced.yaml index 74d25db..08291ba 100644 --- a/tests/integration/targets/vyos_ospfv3/tests/cli/replaced.yaml +++ b/tests/integration/targets/vyos_ospfv3/tests/cli/replaced.yaml @@ -8,27 +8,26 @@ - include_tasks: _populate.yaml - block: - - name: Replace device configurations of listed ospfv3 routes with provided configurations register: result vyos.vyos.vyos_ospfv3: &id001 config: redistribute: - - route_type: 'bgp' + - route_type: "bgp" parameters: - router_id: '192.0.2.10' + router_id: "192.0.2.10" areas: - - area_id: '2' - export_list: 'export1' - import_list: 'import1' + - area_id: "2" + export_list: "export1" + import_list: "import1" range: - - address: '2001:db10::/32' - - address: '2001:db30::/32' - - address: '2001:db50::/32' - - area_id: '4' + - address: "2001:db10::/32" + - address: "2001:db30::/32" + - address: "2001:db50::/32" + - area_id: "4" range: - - address: '2001:db60::/32' + - address: "2001:db60::/32" state: replaced - name: Assert that correct set of commands were generated @@ -47,7 +46,8 @@ that: - "{{ replaced['after'] == result['after'] }}" - - name: Replace device configurations of listed ospfv3 routes with provided configurarions + - name: + Replace device configurations of listed ospfv3 routes with provided configurarions (IDEMPOTENT) register: result vyos.vyos.vyos_ospfv3: *id001 @@ -62,5 +62,4 @@ that: - "{{ replaced['after'] == result['before'] }}" always: - - include_tasks: _remove_config.yaml diff --git a/tests/integration/targets/vyos_ospfv3/tests/cli/rtt.yaml b/tests/integration/targets/vyos_ospfv3/tests/cli/rtt.yaml index d817554..2142aad 100644 --- a/tests/integration/targets/vyos_ospfv3/tests/cli/rtt.yaml +++ b/tests/integration/targets/vyos_ospfv3/tests/cli/rtt.yaml @@ -6,26 +6,25 @@ - include_tasks: _remove_config.yaml - block: - - name: Apply the provided configuration (base config) register: base_config vyos.vyos.vyos_ospfv3: config: areas: - - area_id: '2' - export_list: 'export1' - import_list: 'import1' + - area_id: "2" + export_list: "export1" + import_list: "import1" range: - - address: '2001:db10::/32' - - address: '2001:db20::/32' - - address: '2001:db30::/32' - - area_id: '3' + - address: "2001:db10::/32" + - address: "2001:db20::/32" + - address: "2001:db30::/32" + - area_id: "3" range: - - address: '2001:db40::/32' + - address: "2001:db40::/32" parameters: - router_id: '192.0.2.10' + router_id: "192.0.2.10" redistribute: - - route_type: 'bgp' + - route_type: "bgp" state: merged - name: Gather ospfv3 facts @@ -40,21 +39,21 @@ vyos.vyos.vyos_ospfv3: config: redistribute: - - route_type: 'bgp' + - route_type: "bgp" parameters: - router_id: '192.0.2.10' + router_id: "192.0.2.10" areas: - - area_id: '2' - export_list: 'export1' - import_list: 'import1' + - area_id: "2" + export_list: "export1" + import_list: "import1" range: - - address: '2001:db10::/32' - - address: '2001:db30::/32' - - address: '2001:db50::/32' - - area_id: '4' + - address: "2001:db10::/32" + - address: "2001:db30::/32" + - address: "2001:db50::/32" + - area_id: "4" range: - - address: '2001:db60::/32' + - address: "2001:db60::/32" state: replaced - name: Assert that changes were applied @@ -71,5 +70,4 @@ assert: that: "{{ base_config['after'] == revert['after']}}" always: - - include_tasks: _remove_config.yaml diff --git a/tests/integration/targets/vyos_ospfv3/vars/main.yaml b/tests/integration/targets/vyos_ospfv3/vars/main.yaml index 6ded89a..3793760 100644 --- a/tests/integration/targets/vyos_ospfv3/vars/main.yaml +++ b/tests/integration/targets/vyos_ospfv3/vars/main.yaml @@ -14,59 +14,58 @@ merged: - set protocols ospfv3 area 3 range 2001:db40::/32 after: areas: - - area_id: '2' - export_list: 'export1' - import_list: 'import1' + - area_id: "2" + export_list: "export1" + import_list: "import1" range: - - address: '2001:db10::/32' - - address: '2001:db20::/32' - - address: '2001:db30::/32' - - area_id: '3' + - address: "2001:db10::/32" + - address: "2001:db20::/32" + - address: "2001:db30::/32" + - area_id: "3" range: - - address: '2001:db40::/32' + - address: "2001:db40::/32" parameters: - router_id: '192.0.2.10' + router_id: "192.0.2.10" redistribute: - - route_type: 'bgp' - + - route_type: "bgp" merged_update: commands: - set protocols ospfv3 area 3 range 2001:db70::/32 after: areas: - - area_id: '2' - export_list: 'export1' - import_list: 'import1' + - area_id: "2" + export_list: "export1" + import_list: "import1" range: - - address: '2001:db10::/32' - - address: '2001:db20::/32' - - address: '2001:db30::/32' - - area_id: '3' + - address: "2001:db10::/32" + - address: "2001:db20::/32" + - address: "2001:db30::/32" + - area_id: "3" range: - - address: '2001:db40::/32' - - address: '2001:db70::/32' + - address: "2001:db40::/32" + - address: "2001:db70::/32" parameters: - router_id: '192.0.2.10' + router_id: "192.0.2.10" redistribute: - - route_type: 'bgp' + - route_type: "bgp" populate: areas: - - area_id: '2' - export_list: 'export1' - import_list: 'import1' + - area_id: "2" + export_list: "export1" + import_list: "import1" range: - - address: '2001:db10::/32' - - address: '2001:db20::/32' - - address: '2001:db30::/32' - - area_id: '3' + - address: "2001:db10::/32" + - address: "2001:db20::/32" + - address: "2001:db30::/32" + - area_id: "3" range: - - address: '2001:db40::/32' + - address: "2001:db40::/32" parameters: - router_id: '192.0.2.10' + router_id: "192.0.2.10" redistribute: - - route_type: 'bgp' + - route_type: "bgp" replaced: commands: - delete protocols ospfv3 area 2 range 2001:db20::/32 @@ -76,20 +75,20 @@ replaced: - set protocols ospfv3 area 4 range 2001:db60::/32 after: areas: - - area_id: '2' - export_list: 'export1' - import_list: 'import1' + - area_id: "2" + export_list: "export1" + import_list: "import1" range: - - address: '2001:db10::/32' - - address: '2001:db30::/32' - - address: '2001:db50::/32' - - area_id: '4' + - address: "2001:db10::/32" + - address: "2001:db30::/32" + - address: "2001:db50::/32" + - area_id: "4" range: - - address: '2001:db60::/32' + - address: "2001:db60::/32" parameters: - router_id: '192.0.2.10' + router_id: "192.0.2.10" redistribute: - - route_type: 'bgp' + - route_type: "bgp" rendered: commands: - set protocols ospfv3 redistribute bgp @@ -105,38 +104,38 @@ rendered: parsed: after: areas: - - area_id: '2' - export_list: 'export1' - import_list: 'import1' + - area_id: "2" + export_list: "export1" + import_list: "import1" range: - - address: '2001:db10::/32' - - address: '2001:db20::/32' - - address: '2001:db30::/32' - - area_id: '3' + - address: "2001:db10::/32" + - address: "2001:db20::/32" + - address: "2001:db30::/32" + - area_id: "3" range: - - address: '2001:db40::/32' + - address: "2001:db40::/32" parameters: - router_id: '192.0.2.10' + router_id: "192.0.2.10" redistribute: - - route_type: 'bgp' + - route_type: "bgp" deleted: commands: - - 'delete protocols ospfv3' + - "delete protocols ospfv3" after: {} round_trip: after: areas: - - area_id: '2' - export_list: 'export1' - import_list: 'import1' + - area_id: "2" + export_list: "export1" + import_list: "import1" range: - - address: '2001:db10::/32' - - address: '2001:db30::/32' - - address: '2001:db50::/32' - - area_id: '4' + - address: "2001:db10::/32" + - address: "2001:db30::/32" + - address: "2001:db50::/32" + - area_id: "4" range: - - address: '2001:db60::/32' + - address: "2001:db60::/32" parameters: - router_id: '192.0.2.10' + router_id: "192.0.2.10" redistribute: - - route_type: 'bgp' + - route_type: "bgp" diff --git a/tests/integration/targets/vyos_prefix_lists/tasks/cli.yaml b/tests/integration/targets/vyos_prefix_lists/tasks/cli.yaml index 93eb2fe..83496e0 100644 --- a/tests/integration/targets/vyos_prefix_lists/tasks/cli.yaml +++ b/tests/integration/targets/vyos_prefix_lists/tasks/cli.yaml @@ -1,8 +1,8 @@ --- - name: Collect all cli test cases find: - paths: '{{ role_path }}/tests/cli' - patterns: '{{ testcase }}.yaml' + paths: "{{ role_path }}/tests/cli" + patterns: "{{ testcase }}.yaml" use_regex: true register: test_cases delegate_to: localhost @@ -11,9 +11,9 @@ set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}" - name: Run test case (connection=ansible.netcommon.network_cli) - include: '{{ test_case_to_run }}' + include: "{{ test_case_to_run }}" vars: ansible_connection: ansible.netcommon.network_cli - with_items: '{{ test_items }}' + with_items: "{{ test_items }}" loop_control: loop_var: test_case_to_run diff --git a/tests/integration/targets/vyos_route_maps/defaults/main.yaml b/tests/integration/targets/vyos_route_maps/defaults/main.yaml index 852a6be..164afea 100644 --- a/tests/integration/targets/vyos_route_maps/defaults/main.yaml +++ b/tests/integration/targets/vyos_route_maps/defaults/main.yaml @@ -1,3 +1,3 @@ --- -testcase: '[^_].*' +testcase: "[^_].*" test_items: [] diff --git a/tests/integration/targets/vyos_route_maps/tasks/cli.yaml b/tests/integration/targets/vyos_route_maps/tasks/cli.yaml index 93eb2fe..83496e0 100644 --- a/tests/integration/targets/vyos_route_maps/tasks/cli.yaml +++ b/tests/integration/targets/vyos_route_maps/tasks/cli.yaml @@ -1,8 +1,8 @@ --- - name: Collect all cli test cases find: - paths: '{{ role_path }}/tests/cli' - patterns: '{{ testcase }}.yaml' + paths: "{{ role_path }}/tests/cli" + patterns: "{{ testcase }}.yaml" use_regex: true register: test_cases delegate_to: localhost @@ -11,9 +11,9 @@ set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}" - name: Run test case (connection=ansible.netcommon.network_cli) - include: '{{ test_case_to_run }}' + include: "{{ test_case_to_run }}" vars: ansible_connection: ansible.netcommon.network_cli - with_items: '{{ test_items }}' + with_items: "{{ test_items }}" loop_control: loop_var: test_case_to_run diff --git a/tests/integration/targets/vyos_route_maps/tests/cli/deleted.yaml b/tests/integration/targets/vyos_route_maps/tests/cli/deleted.yaml index 2999d63..fe68d56 100644 --- a/tests/integration/targets/vyos_route_maps/tests/cli/deleted.yaml +++ b/tests/integration/targets/vyos_route_maps/tests/cli/deleted.yaml @@ -8,7 +8,6 @@ - include_tasks: _populate.yaml - block: - - name: Delete the provided configuration register: result vyos.vyos.vyos_route_maps: &id001 @@ -27,7 +26,8 @@ - "{{ deleted['after'] | symmetric_difference(result['after']) |length\ \ == 0 }}" - - name: Delete the existing configuration with the provided running configuration + - name: + Delete the existing configuration with the provided running configuration (IDEMPOTENT) register: result vyos.vyos.vyos_route_maps: *id001 @@ -38,5 +38,4 @@ - result['changed'] == false always: - - include_tasks: _remove_config.yaml diff --git a/tests/integration/targets/vyos_route_maps/tests/cli/gathered.yaml b/tests/integration/targets/vyos_route_maps/tests/cli/gathered.yaml index 356e975..430b9d5 100644 --- a/tests/integration/targets/vyos_route_maps/tests/cli/gathered.yaml +++ b/tests/integration/targets/vyos_route_maps/tests/cli/gathered.yaml @@ -8,7 +8,6 @@ - include_tasks: _populate.yaml - block: - - name: Gather config from the device in structured format. register: result vyos.vyos.vyos_route_maps: diff --git a/tests/integration/targets/vyos_route_maps/tests/cli/overridden.yaml b/tests/integration/targets/vyos_route_maps/tests/cli/overridden.yaml index 76971d6..168ef17 100644 --- a/tests/integration/targets/vyos_route_maps/tests/cli/overridden.yaml +++ b/tests/integration/targets/vyos_route_maps/tests/cli/overridden.yaml @@ -8,7 +8,6 @@ - include_tasks: _populate.yaml - block: - - name: Override the existing configuration with the provided running configuration register: result vyos.vyos.vyos_route_maps: &id001 @@ -40,7 +39,8 @@ - result.commands|symmetric_difference(overridden.commands) == [] - result.after|symmetric_difference(ansible_facts['network_resources']['route_maps']) == [] - - name: Override the existing configuration with the provided running configuration + - name: + Override the existing configuration with the provided running configuration (IDEMPOTENT) register: result vyos.vyos.vyos_route_maps: *id001 @@ -51,5 +51,4 @@ - result['changed'] == false always: - - include_tasks: _remove_config.yaml diff --git a/tests/integration/targets/vyos_route_maps/tests/cli/parsed.yaml b/tests/integration/targets/vyos_route_maps/tests/cli/parsed.yaml index ee76852..f098347 100644 --- a/tests/integration/targets/vyos_route_maps/tests/cli/parsed.yaml +++ b/tests/integration/targets/vyos_route_maps/tests/cli/parsed.yaml @@ -1,6 +1,7 @@ --- - debug: - msg: START vyos_route_maps parsed integration tests on connection={{ ansible_connection + msg: + START vyos_route_maps parsed integration tests on connection={{ ansible_connection }} - name: Provide the running configuration for parsing (config to be parsed) diff --git a/tests/integration/targets/vyos_route_maps/tests/cli/rendered.yaml b/tests/integration/targets/vyos_route_maps/tests/cli/rendered.yaml index 7d194d9..f9e599f 100644 --- a/tests/integration/targets/vyos_route_maps/tests/cli/rendered.yaml +++ b/tests/integration/targets/vyos_route_maps/tests/cli/rendered.yaml @@ -6,7 +6,6 @@ - include_tasks: _remove_config.yaml - block: - - name: Structure provided configuration into device specific commands register: result vyos.vyos.vyos_route_maps: &id001 diff --git a/tests/integration/targets/vyos_smoke/defaults/main.yaml b/tests/integration/targets/vyos_smoke/defaults/main.yaml index a845c24..9ef5ba5 100644 --- a/tests/integration/targets/vyos_smoke/defaults/main.yaml +++ b/tests/integration/targets/vyos_smoke/defaults/main.yaml @@ -1,3 +1,3 @@ --- -testcase: '*' +testcase: "*" test_items: [] diff --git a/tests/integration/targets/vyos_smoke/tasks/cli.yaml b/tests/integration/targets/vyos_smoke/tasks/cli.yaml index cc5f7df..d9c9ed7 100644 --- a/tests/integration/targets/vyos_smoke/tasks/cli.yaml +++ b/tests/integration/targets/vyos_smoke/tasks/cli.yaml @@ -1,8 +1,8 @@ --- - name: collect all cli test cases find: - paths: '{{ role_path }}/tests/cli' - patterns: '{{ testcase }}.yaml' + paths: "{{ role_path }}/tests/cli" + patterns: "{{ testcase }}.yaml" register: test_cases delegate_to: localhost @@ -10,8 +10,8 @@ set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}" - name: run test case with single_user_mode (connection=ansible.netcommon.network_cli) - include: '{{ test_case_to_run }} ansible_connection=ansible.netcommon.network_cli ansible_network_single_user_mode=True' - with_items: '{{ test_items }}' + include: "{{ test_case_to_run }} ansible_connection=ansible.netcommon.network_cli ansible_network_single_user_mode=True" + with_items: "{{ test_items }}" loop_control: loop_var: test_case_to_run tags: diff --git a/tests/integration/targets/vyos_smoke/tests/cli/caching.yaml b/tests/integration/targets/vyos_smoke/tests/cli/caching.yaml index 87b93c8..9afea2e 100644 --- a/tests/integration/targets/vyos_smoke/tests/cli/caching.yaml +++ b/tests/integration/targets/vyos_smoke/tests/cli/caching.yaml @@ -1,84 +1,84 @@ --- - block: - - debug: msg="START connection={{ ansible_connection }} cli/caching.yaml" + - debug: msg="START connection={{ ansible_connection }} cli/caching.yaml" - - set_fact: - interface_cmds: - - set interfaces ethernet eth1 description 'Configured by Ansible - Interface 1' - - set interfaces ethernet eth1 mtu '1500' - - set interfaces ethernet eth1 duplex 'auto' - - set interfaces ethernet eth1 speed 'auto' - - set interfaces ethernet eth1 vif 101 description 'Eth1 - VIF 101' - - set interfaces ethernet eth2 description 'Configured by Ansible - Interface 2 (ADMIN DOWN)' - - set interfaces ethernet eth2 mtu '600' - l3_interface_cmds: - - set interfaces ethernet eth1 address '192.0.2.10/24' - - set interfaces ethernet eth1 address '2001:db8::10/32' - - set interfaces ethernet eth2 address '198.51.100.10/24' + - set_fact: + interface_cmds: + - set interfaces ethernet eth1 description 'Configured by Ansible - Interface 1' + - set interfaces ethernet eth1 mtu '1500' + - set interfaces ethernet eth1 duplex 'auto' + - set interfaces ethernet eth1 speed 'auto' + - set interfaces ethernet eth1 vif 101 description 'Eth1 - VIF 101' + - set interfaces ethernet eth2 description 'Configured by Ansible - Interface 2 (ADMIN DOWN)' + - set interfaces ethernet eth2 mtu '600' + l3_interface_cmds: + - set interfaces ethernet eth1 address '192.0.2.10/24' + - set interfaces ethernet eth1 address '2001:db8::10/32' + - set interfaces ethernet eth2 address '198.51.100.10/24' - - name: Remove interfaces from config before actual testing - ignore_errors: true - vyos.vyos.vyos_config: &rem - lines: - - delete interfaces ethernet eth1 - - delete interfaces ethernet eth2 - match: none + - name: Remove interfaces from config before actual testing + ignore_errors: true + vyos.vyos.vyos_config: &rem + lines: + - delete interfaces ethernet eth1 + - delete interfaces ethernet eth2 + match: none - - name: Merge base interfaces configuration - register: result - vyos.vyos.vyos_interfaces: &merged - config: - - name: eth1 - description: Configured by Ansible - Interface 1 - mtu: 1500 - speed: auto - duplex: auto - vifs: - - vlan_id: 101 - description: Eth1 - VIF 101 + - name: Merge base interfaces configuration + register: result + vyos.vyos.vyos_interfaces: &merged + config: + - name: eth1 + description: Configured by Ansible - Interface 1 + mtu: 1500 + speed: auto + duplex: auto + vifs: + - vlan_id: 101 + description: Eth1 - VIF 101 - - name: eth2 - description: Configured by Ansible - Interface 2 (ADMIN DOWN) - mtu: 600 - state: merged + - name: eth2 + description: Configured by Ansible - Interface 2 (ADMIN DOWN) + mtu: 600 + state: merged - - assert: - that: - - "{{ interface_cmds | symmetric_difference(result['commands']) |length == 0 }}" + - assert: + that: + - "{{ interface_cmds | symmetric_difference(result['commands']) |length == 0 }}" - - name: Merge base interfaces configuration (IDEMPOTENT) - register: result - vyos.vyos.vyos_interfaces: *merged + - name: Merge base interfaces configuration (IDEMPOTENT) + register: result + vyos.vyos.vyos_interfaces: *merged - - assert: - that: - - result.changed == False + - assert: + that: + - result.changed == False - - name: Merge L3 interfaces configuration - register: result - vyos.vyos.vyos_l3_interfaces: &mergedl3 - config: - - name: eth1 - ipv4: - - address: 192.0.2.10/24 - ipv6: - - address: 2001:db8::10/32 - - name: eth2 - ipv4: - - address: 198.51.100.10/24 - state: merged + - name: Merge L3 interfaces configuration + register: result + vyos.vyos.vyos_l3_interfaces: &mergedl3 + config: + - name: eth1 + ipv4: + - address: 192.0.2.10/24 + ipv6: + - address: 2001:db8::10/32 + - name: eth2 + ipv4: + - address: 198.51.100.10/24 + state: merged - - assert: - that: - - "{{ l3_interface_cmds | symmetric_difference(result['commands']) |length == 0 }}" + - assert: + that: + - "{{ l3_interface_cmds | symmetric_difference(result['commands']) |length == 0 }}" - - name: Merge L3 interfaces configuration (IDEMPOTENT) - register: result - vyos.vyos.vyos_l3_interfaces: *mergedl3 + - name: Merge L3 interfaces configuration (IDEMPOTENT) + register: result + vyos.vyos.vyos_l3_interfaces: *mergedl3 - - assert: - that: - - result.changed == False + - assert: + that: + - result.changed == False always: - name: cleanup vyos.vyos.vyos_config: *rem diff --git a/tests/integration/targets/vyos_snmp_server/defaults/main.yaml b/tests/integration/targets/vyos_snmp_server/defaults/main.yaml index 852a6be..164afea 100644 --- a/tests/integration/targets/vyos_snmp_server/defaults/main.yaml +++ b/tests/integration/targets/vyos_snmp_server/defaults/main.yaml @@ -1,3 +1,3 @@ --- -testcase: '[^_].*' +testcase: "[^_].*" test_items: [] diff --git a/tests/integration/targets/vyos_snmp_server/meta/main.yaml b/tests/integration/targets/vyos_snmp_server/meta/main.yaml index 91da2a7..ed97d53 100644 --- a/tests/integration/targets/vyos_snmp_server/meta/main.yaml +++ b/tests/integration/targets/vyos_snmp_server/meta/main.yaml @@ -1,2 +1 @@ --- -... diff --git a/tests/integration/targets/vyos_snmp_server/tasks/cli.yaml b/tests/integration/targets/vyos_snmp_server/tasks/cli.yaml index 93eb2fe..83496e0 100644 --- a/tests/integration/targets/vyos_snmp_server/tasks/cli.yaml +++ b/tests/integration/targets/vyos_snmp_server/tasks/cli.yaml @@ -1,8 +1,8 @@ --- - name: Collect all cli test cases find: - paths: '{{ role_path }}/tests/cli' - patterns: '{{ testcase }}.yaml' + paths: "{{ role_path }}/tests/cli" + patterns: "{{ testcase }}.yaml" use_regex: true register: test_cases delegate_to: localhost @@ -11,9 +11,9 @@ set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}" - name: Run test case (connection=ansible.netcommon.network_cli) - include: '{{ test_case_to_run }}' + include: "{{ test_case_to_run }}" vars: ansible_connection: ansible.netcommon.network_cli - with_items: '{{ test_items }}' + with_items: "{{ test_items }}" loop_control: loop_var: test_case_to_run diff --git a/tests/integration/targets/vyos_snmp_server/tests/cli/deleted.yaml b/tests/integration/targets/vyos_snmp_server/tests/cli/deleted.yaml index 1fa32c5..8cd2c8a 100644 --- a/tests/integration/targets/vyos_snmp_server/tests/cli/deleted.yaml +++ b/tests/integration/targets/vyos_snmp_server/tests/cli/deleted.yaml @@ -7,7 +7,6 @@ - include_tasks: _populate_config.yaml - block: - - name: Delete the provided configuration register: result vyos.vyos.vyos_snmp_server: &id001 @@ -25,7 +24,8 @@ that: - result.after == {} - - name: Delete the existing configuration with the provided running configuration + - name: + Delete the existing configuration with the provided running configuration (IDEMPOTENT) register: result vyos.vyos.vyos_snmp_server: *id001 @@ -36,5 +36,4 @@ - result['changed'] == false always: - - include_tasks: _remove_config.yaml diff --git a/tests/integration/targets/vyos_snmp_server/tests/cli/gathered.yaml b/tests/integration/targets/vyos_snmp_server/tests/cli/gathered.yaml index 184faa5..7cdf3c4 100644 --- a/tests/integration/targets/vyos_snmp_server/tests/cli/gathered.yaml +++ b/tests/integration/targets/vyos_snmp_server/tests/cli/gathered.yaml @@ -8,7 +8,6 @@ - include_tasks: _populate_config.yaml - block: - - name: Gather config from the device in structured format. register: result vyos.vyos.vyos_snmp_server: diff --git a/tests/integration/targets/vyos_snmp_server/tests/cli/merged.yaml b/tests/integration/targets/vyos_snmp_server/tests/cli/merged.yaml index e372166..06627b0 100644 --- a/tests/integration/targets/vyos_snmp_server/tests/cli/merged.yaml +++ b/tests/integration/targets/vyos_snmp_server/tests/cli/merged.yaml @@ -42,7 +42,6 @@ - result.after == ansible_facts['network_resources']['snmp_server'] - result.after == merged.after - - name: Assert that before dicts were correctly generated assert: that: diff --git a/tests/integration/targets/vyos_snmp_server/tests/cli/overridden.yaml b/tests/integration/targets/vyos_snmp_server/tests/cli/overridden.yaml index 5f3d9c9..b1d6565 100644 --- a/tests/integration/targets/vyos_snmp_server/tests/cli/overridden.yaml +++ b/tests/integration/targets/vyos_snmp_server/tests/cli/overridden.yaml @@ -8,7 +8,6 @@ - include_tasks: _populate_config.yaml - block: - - name: Override the existing configuration with the provided running configuration register: result vyos.vyos.vyos_snmp_server: &id001 @@ -51,8 +50,8 @@ - result.after == ansible_facts['network_resources']['snmp_server'] - result.commands|length == 13 - - - name: Override the existing configuration with the provided running configuration + - name: + Override the existing configuration with the provided running configuration (IDEMPOTENT) register: result vyos.vyos.vyos_snmp_server: *id001 @@ -63,5 +62,4 @@ - result['changed'] == false always: - - include_tasks: _remove_config.yaml diff --git a/tests/integration/targets/vyos_snmp_server/tests/cli/parsed.yaml b/tests/integration/targets/vyos_snmp_server/tests/cli/parsed.yaml index e189134..4ecc1ac 100644 --- a/tests/integration/targets/vyos_snmp_server/tests/cli/parsed.yaml +++ b/tests/integration/targets/vyos_snmp_server/tests/cli/parsed.yaml @@ -1,6 +1,7 @@ --- - debug: - msg: START vyos_snmp_server parsed integration tests on connection={{ ansible_connection + msg: + START vyos_snmp_server parsed integration tests on connection={{ ansible_connection }} - name: Provide the running configuration for parsing (config to be parsed) @@ -9,7 +10,6 @@ running_config: "{{ lookup('file', '_parsed.cfg') }}" state: parsed - - name: Assert that config was correctly parsed assert: that: diff --git a/tests/integration/targets/vyos_snmp_server/tests/cli/replaced.yaml b/tests/integration/targets/vyos_snmp_server/tests/cli/replaced.yaml index 0b5a564..2bfcaf6 100644 --- a/tests/integration/targets/vyos_snmp_server/tests/cli/replaced.yaml +++ b/tests/integration/targets/vyos_snmp_server/tests/cli/replaced.yaml @@ -8,7 +8,6 @@ - include_tasks: _populate_config.yaml - block: - - name: Replace the existing configuration with the provided running configuration register: result vyos.vyos.vyos_snmp_server: &id001 @@ -51,8 +50,8 @@ - result.after == ansible_facts['network_resources']['snmp_server'] - result.commands|length == 13 - - - name: Replace the existing configuration with the provided running configuration + - name: + Replace the existing configuration with the provided running configuration (IDEMPOTENT) register: result vyos.vyos.vyos_snmp_server: *id001 @@ -63,5 +62,4 @@ - result['changed'] == false always: - - include_tasks: _remove_config.yaml diff --git a/tests/integration/targets/vyos_static_routes/defaults/main.yaml b/tests/integration/targets/vyos_static_routes/defaults/main.yaml index 852a6be..164afea 100644 --- a/tests/integration/targets/vyos_static_routes/defaults/main.yaml +++ b/tests/integration/targets/vyos_static_routes/defaults/main.yaml @@ -1,3 +1,3 @@ --- -testcase: '[^_].*' +testcase: "[^_].*" test_items: [] diff --git a/tests/integration/targets/vyos_static_routes/meta/main.yaml b/tests/integration/targets/vyos_static_routes/meta/main.yaml index 91da2a7..ed97d53 100644 --- a/tests/integration/targets/vyos_static_routes/meta/main.yaml +++ b/tests/integration/targets/vyos_static_routes/meta/main.yaml @@ -1,2 +1 @@ --- -... diff --git a/tests/integration/targets/vyos_static_routes/tasks/cli.yaml b/tests/integration/targets/vyos_static_routes/tasks/cli.yaml index 93eb2fe..83496e0 100644 --- a/tests/integration/targets/vyos_static_routes/tasks/cli.yaml +++ b/tests/integration/targets/vyos_static_routes/tasks/cli.yaml @@ -1,8 +1,8 @@ --- - name: Collect all cli test cases find: - paths: '{{ role_path }}/tests/cli' - patterns: '{{ testcase }}.yaml' + paths: "{{ role_path }}/tests/cli" + patterns: "{{ testcase }}.yaml" use_regex: true register: test_cases delegate_to: localhost @@ -11,9 +11,9 @@ set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}" - name: Run test case (connection=ansible.netcommon.network_cli) - include: '{{ test_case_to_run }}' + include: "{{ test_case_to_run }}" vars: ansible_connection: ansible.netcommon.network_cli - with_items: '{{ test_items }}' + with_items: "{{ test_items }}" loop_control: loop_var: test_case_to_run diff --git a/tests/integration/targets/vyos_static_routes/tasks/redirection.yaml b/tests/integration/targets/vyos_static_routes/tasks/redirection.yaml index 5564a3e..48ad53a 100644 --- a/tests/integration/targets/vyos_static_routes/tasks/redirection.yaml +++ b/tests/integration/targets/vyos_static_routes/tasks/redirection.yaml @@ -1,8 +1,8 @@ --- - name: collect all redirection cli test cases find: - paths: '{{ role_path }}/tests/redirection/cli' - patterns: '{{ testcase }}.yaml' + paths: "{{ role_path }}/tests/redirection/cli" + patterns: "{{ testcase }}.yaml" register: shortname_test_cases delegate_to: localhost @@ -10,7 +10,7 @@ set_fact: test_items="{{ shortname_test_cases.files | map(attribute='path') | list }}" - name: run test case (connection=ansible.netcommon.network_cli) - include: '{{ test_case_to_run }} ansible_connection=ansible.netcommon.network_cli' - with_items: '{{ test_items }}' + include: "{{ test_case_to_run }} ansible_connection=ansible.netcommon.network_cli" + with_items: "{{ test_items }}" loop_control: loop_var: test_case_to_run diff --git a/tests/integration/targets/vyos_static_routes/tests/cli/_populate.yaml b/tests/integration/targets/vyos_static_routes/tests/cli/_populate.yaml index f292e5d..4c54ef6 100644 --- a/tests/integration/targets/vyos_static_routes/tests/cli/_populate.yaml +++ b/tests/integration/targets/vyos_static_routes/tests/cli/_populate.yaml @@ -9,4 +9,4 @@ set protocols static route6 2001:db8:1000::/36 blackhole distance '2'\nset\ \ protocols static route6 2001:db8:1000::/36\n" ansible.netcommon.cli_config: - config: '{{ lines }}' + config: "{{ lines }}" diff --git a/tests/integration/targets/vyos_static_routes/tests/cli/_remove_config.yaml b/tests/integration/targets/vyos_static_routes/tests/cli/_remove_config.yaml index 5a5cccb..5608d22 100644 --- a/tests/integration/targets/vyos_static_routes/tests/cli/_remove_config.yaml +++ b/tests/integration/targets/vyos_static_routes/tests/cli/_remove_config.yaml @@ -3,4 +3,4 @@ vars: lines: "delete protocols static route\ndelete protocols static route6\n" ansible.netcommon.cli_config: - config: '{{ lines }}' + config: "{{ lines }}" diff --git a/tests/integration/targets/vyos_static_routes/tests/cli/deleted_afi.yaml b/tests/integration/targets/vyos_static_routes/tests/cli/deleted_afi.yaml index 221f1b5..491f9c3 100644 --- a/tests/integration/targets/vyos_static_routes/tests/cli/deleted_afi.yaml +++ b/tests/integration/targets/vyos_static_routes/tests/cli/deleted_afi.yaml @@ -1,19 +1,17 @@ --- - debug: - msg: Start vyos_static_routes deleted integration tests ansible_connection={{ + msg: + Start vyos_static_routes deleted integration tests ansible_connection={{ ansible_connection }} - include_tasks: _populate.yaml - block: - - name: Delete static route based on afi. register: result vyos.vyos.vyos_static_routes: &id001 config: - - address_families: - - afi: ipv4 - afi: ipv6 @@ -52,5 +50,4 @@ - "{{ deleted_afi_all['after'] | symmetric_difference(result['before'])\ \ |length == 0 }}" always: - - include_tasks: _remove_config.yaml diff --git a/tests/integration/targets/vyos_static_routes/tests/cli/deleted_all.yaml b/tests/integration/targets/vyos_static_routes/tests/cli/deleted_all.yaml index e10f1bc..bddb528 100644 --- a/tests/integration/targets/vyos_static_routes/tests/cli/deleted_all.yaml +++ b/tests/integration/targets/vyos_static_routes/tests/cli/deleted_all.yaml @@ -1,12 +1,12 @@ --- - debug: - msg: Start vyos_static_routes deleted integration tests ansible_connection={{ + msg: + Start vyos_static_routes deleted integration tests ansible_connection={{ ansible_connection }} - include_tasks: _populate.yaml - block: - - name: Delete all the static routes. register: result vyos.vyos.vyos_static_routes: &id001 @@ -46,5 +46,4 @@ - "{{ deleted_afi_all['after'] | symmetric_difference(result['before'])\ \ |length == 0 }}" always: - - include_tasks: _remove_config.yaml diff --git a/tests/integration/targets/vyos_static_routes/tests/cli/empty_config.yaml b/tests/integration/targets/vyos_static_routes/tests/cli/empty_config.yaml index f58ef39..6fded87 100644 --- a/tests/integration/targets/vyos_static_routes/tests/cli/empty_config.yaml +++ b/tests/integration/targets/vyos_static_routes/tests/cli/empty_config.yaml @@ -1,6 +1,7 @@ --- - debug: - msg: START vyos_static_routes empty_config integration tests on connection={{ + msg: + START vyos_static_routes empty_config integration tests on connection={{ ansible_connection }} - name: Merged with empty config should give appropriate error message diff --git a/tests/integration/targets/vyos_static_routes/tests/cli/overridden.yaml b/tests/integration/targets/vyos_static_routes/tests/cli/overridden.yaml index a9112a5..d1bedc8 100644 --- a/tests/integration/targets/vyos_static_routes/tests/cli/overridden.yaml +++ b/tests/integration/targets/vyos_static_routes/tests/cli/overridden.yaml @@ -8,20 +8,15 @@ - include_tasks: _populate.yaml - block: - - name: Overrides all device configuration with provided configuration register: result vyos.vyos.vyos_static_routes: &id001 config: - - address_families: - - afi: ipv4 routes: - - dest: 198.0.2.48/28 next_hops: - - forward_router_address: 192.0.2.18 state: overridden @@ -57,5 +52,4 @@ - "{{ overridden['after'] | symmetric_difference(result['before']) |length\ \ == 0 }}" always: - - include_tasks: _remove_config.yaml diff --git a/tests/integration/targets/vyos_static_routes/tests/cli/parsed.yaml b/tests/integration/targets/vyos_static_routes/tests/cli/parsed.yaml index 4b6e434..06cad97 100644 --- a/tests/integration/targets/vyos_static_routes/tests/cli/parsed.yaml +++ b/tests/integration/targets/vyos_static_routes/tests/cli/parsed.yaml @@ -1,6 +1,7 @@ --- - debug: - msg: START vyos_static_routes parsed integration tests on connection={{ ansible_connection + msg: + START vyos_static_routes parsed integration tests on connection={{ ansible_connection }} - include_tasks: _remove_config.yaml @@ -8,7 +9,6 @@ - include_tasks: _populate.yaml - block: - - name: Gather static_routes facts register: static_routes_facts vyos.vyos.vyos_facts: @@ -25,7 +25,8 @@ - name: Assert that correct parsing done assert: - that: "{{ ansible_facts['network_resources']['static_routes'] | symmetric_difference(result['parsed'])\ + that: + "{{ ansible_facts['network_resources']['static_routes'] | symmetric_difference(result['parsed'])\ \ |length == 0 }}" - name: Gather the existing running configuration (IDEMPOTENT) @@ -37,5 +38,4 @@ that: - result['changed'] == false always: - - include_tasks: _remove_config.yaml diff --git a/tests/integration/targets/vyos_static_routes/tests/cli/rendered.yaml b/tests/integration/targets/vyos_static_routes/tests/cli/rendered.yaml index ff18523..81e7259 100644 --- a/tests/integration/targets/vyos_static_routes/tests/cli/rendered.yaml +++ b/tests/integration/targets/vyos_static_routes/tests/cli/rendered.yaml @@ -1,6 +1,7 @@ --- - debug: - msg: START vyos_static_routes rendered integration tests on connection={{ ansible_connection + msg: + START vyos_static_routes rendered integration tests on connection={{ ansible_connection }} - include_tasks: _remove_config.yaml @@ -8,36 +9,28 @@ - include_tasks: _populate.yaml - block: - - name: Structure provided configuration into device specific commands register: result vyos.vyos.vyos_static_routes: &id001 config: - - address_families: - - afi: ipv4 routes: - - dest: 192.0.2.32/28 blackhole_config: type: blackhole next_hops: - - forward_router_address: 192.0.2.10 - forward_router_address: 192.0.2.9 - address_families: - - afi: ipv6 routes: - - dest: 2001:db8:1000::/36 blackhole_config: distance: 2 next_hops: - - forward_router_address: 2001:db8:2000:2::1 - forward_router_address: 2001:db8:2000:2::2 @@ -58,5 +51,4 @@ that: - result['changed'] == false always: - - include_tasks: _remove_config.yaml diff --git a/tests/integration/targets/vyos_static_routes/tests/cli/replaced.yaml b/tests/integration/targets/vyos_static_routes/tests/cli/replaced.yaml index 80ed801..50af5ed 100644 --- a/tests/integration/targets/vyos_static_routes/tests/cli/replaced.yaml +++ b/tests/integration/targets/vyos_static_routes/tests/cli/replaced.yaml @@ -1,6 +1,7 @@ --- - debug: - msg: START vyos_static_routes replaced integration tests on connection={{ ansible_connection + msg: + START vyos_static_routes replaced integration tests on connection={{ ansible_connection }} - include_tasks: _remove_config.yaml @@ -8,23 +9,18 @@ - include_tasks: _populate.yaml - block: - - name: Replace device configurations of listed static routes with provided configurations register: result vyos.vyos.vyos_static_routes: &id001 config: - - address_families: - - afi: ipv4 routes: - - dest: 192.0.2.32/28 blackhole_config: distance: 2 next_hops: - - forward_router_address: 192.0.2.7 - forward_router_address: 192.0.2.8 @@ -65,5 +61,4 @@ - "{{ replaced['after'] | symmetric_difference(result['before']) |length\ \ == 0 }}" always: - - include_tasks: _remove_config.yaml diff --git a/tests/integration/targets/vyos_static_routes/tests/cli/rtt.yaml b/tests/integration/targets/vyos_static_routes/tests/cli/rtt.yaml index 340fde9..64e8044 100644 --- a/tests/integration/targets/vyos_static_routes/tests/cli/rtt.yaml +++ b/tests/integration/targets/vyos_static_routes/tests/cli/rtt.yaml @@ -6,36 +6,28 @@ - include_tasks: _remove_config.yaml - block: - - name: Apply the provided configuration (base config) register: base_config vyos.vyos.vyos_static_routes: config: - - address_families: - - afi: ipv4 routes: - - dest: 192.0.2.32/28 blackhole_config: type: blackhole next_hops: - - forward_router_address: 192.0.2.10 - forward_router_address: 192.0.2.9 - address_families: - - afi: ipv6 routes: - - dest: 2001:db8:1000::/36 blackhole_config: distance: 2 next_hops: - - forward_router_address: 2001:db8:2000:2::1 - forward_router_address: 2001:db8:2000:2::2 @@ -52,17 +44,13 @@ register: result vyos.vyos.vyos_static_routes: config: - - address_families: - - afi: ipv4 routes: - - dest: 192.0.2.32/28 blackhole_config: distance: 2 next_hops: - - forward_router_address: 192.0.2.7 - forward_router_address: 192.0.2.8 @@ -72,7 +60,8 @@ - name: Assert that changes were applied assert: - that: "{{ round_trip['after'] | symmetric_difference(result['after']) |length\ + that: + "{{ round_trip['after'] | symmetric_difference(result['after']) |length\ \ == 0 }}" - name: Revert back to base config using facts round trip @@ -83,8 +72,8 @@ - name: Assert that config was reverted assert: - that: "{{ base_config['after'] | symmetric_difference(revert['after']) |length\ + that: + "{{ base_config['after'] | symmetric_difference(revert['after']) |length\ \ == 0 }}" always: - - include_tasks: _remove_config.yaml diff --git a/tests/integration/targets/vyos_system/defaults/main.yaml b/tests/integration/targets/vyos_system/defaults/main.yaml index a845c24..9ef5ba5 100644 --- a/tests/integration/targets/vyos_system/defaults/main.yaml +++ b/tests/integration/targets/vyos_system/defaults/main.yaml @@ -1,3 +1,3 @@ --- -testcase: '*' +testcase: "*" test_items: [] diff --git a/tests/integration/targets/vyos_system/tasks/cli.yaml b/tests/integration/targets/vyos_system/tasks/cli.yaml index 8f7b62f..b2746ce 100644 --- a/tests/integration/targets/vyos_system/tasks/cli.yaml +++ b/tests/integration/targets/vyos_system/tasks/cli.yaml @@ -1,8 +1,8 @@ --- - name: collect all cli test cases find: - paths: '{{ role_path }}/tests/cli' - patterns: '{{ testcase }}.yaml' + paths: "{{ role_path }}/tests/cli" + patterns: "{{ testcase }}.yaml" register: test_cases delegate_to: localhost @@ -10,8 +10,8 @@ set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}" - name: run test case (connection=ansible.netcommon.network_cli) - include: '{{ test_case_to_run }} ansible_connection=ansible.netcommon.network_cli' - with_items: '{{ test_items }}' + include: "{{ test_case_to_run }} ansible_connection=ansible.netcommon.network_cli" + with_items: "{{ test_items }}" loop_control: loop_var: test_case_to_run tags: diff --git a/tests/integration/targets/vyos_user/defaults/main.yaml b/tests/integration/targets/vyos_user/defaults/main.yaml index a845c24..9ef5ba5 100644 --- a/tests/integration/targets/vyos_user/defaults/main.yaml +++ b/tests/integration/targets/vyos_user/defaults/main.yaml @@ -1,3 +1,3 @@ --- -testcase: '*' +testcase: "*" test_items: [] diff --git a/tests/integration/targets/vyos_user/tasks/cli.yaml b/tests/integration/targets/vyos_user/tasks/cli.yaml index 8f7b62f..b2746ce 100644 --- a/tests/integration/targets/vyos_user/tasks/cli.yaml +++ b/tests/integration/targets/vyos_user/tasks/cli.yaml @@ -1,8 +1,8 @@ --- - name: collect all cli test cases find: - paths: '{{ role_path }}/tests/cli' - patterns: '{{ testcase }}.yaml' + paths: "{{ role_path }}/tests/cli" + patterns: "{{ testcase }}.yaml" register: test_cases delegate_to: localhost @@ -10,8 +10,8 @@ set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}" - name: run test case (connection=ansible.netcommon.network_cli) - include: '{{ test_case_to_run }} ansible_connection=ansible.netcommon.network_cli' - with_items: '{{ test_items }}' + include: "{{ test_case_to_run }} ansible_connection=ansible.netcommon.network_cli" + with_items: "{{ test_items }}" loop_control: loop_var: test_case_to_run tags: diff --git a/tests/integration/targets/vyos_user/tests/cli/auth.yaml b/tests/integration/targets/vyos_user/tests/cli/auth.yaml index bc4e788..87eaba6 100644 --- a/tests/integration/targets/vyos_user/tests/cli/auth.yaml +++ b/tests/integration/targets/vyos_user/tests/cli/auth.yaml @@ -1,6 +1,5 @@ --- - block: - - name: Create user with password vyos.vyos.vyos_user: name: auth_user @@ -10,7 +9,8 @@ - name: test login via ssh with new user expect: - command: ssh auth_user@{{ ansible_ssh_host }} -p {{ ansible_port | default(22) + command: + ssh auth_user@{{ ansible_ssh_host }} -p {{ ansible_port | default(22) }} -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no '/opt/vyatta/sbin/vyatta-cfg-cmd-wrapper show version' responses: @@ -18,7 +18,8 @@ - name: test login via ssh with invalid password (should fail) expect: - command: ssh auth_user@{{ ansible_ssh_host }} -p {{ ansible_port | default(22) + command: + ssh auth_user@{{ ansible_ssh_host }} -p {{ ansible_port | default(22) }} -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no '/opt/vyatta/sbin/vyatta-cfg-cmd-wrapper show version' responses: @@ -31,7 +32,6 @@ that: - results.failed always: - - name: delete user register: result vyos.vyos.vyos_user: diff --git a/tests/integration/targets/vyos_user/tests/cli/basic.yaml b/tests/integration/targets/vyos_user/tests/cli/basic.yaml index 00a7a26..edd3b5c 100644 --- a/tests/integration/targets/vyos_user/tests/cli/basic.yaml +++ b/tests/integration/targets/vyos_user/tests/cli/basic.yaml @@ -25,7 +25,6 @@ register: result vyos.vyos.vyos_user: aggregate: - - name: ansibletest2 - name: ansibletest3 @@ -55,7 +54,6 @@ register: result vyos.vyos.vyos_user: aggregate: - - name: ansibletest2 - name: ansibletest3 @@ -71,7 +69,6 @@ register: result vyos.vyos.vyos_user: users: - - name: ansibletest1 - name: ansibletest2 diff --git a/tests/integration/targets/vyos_vlan/defaults/main.yaml b/tests/integration/targets/vyos_vlan/defaults/main.yaml index a845c24..9ef5ba5 100644 --- a/tests/integration/targets/vyos_vlan/defaults/main.yaml +++ b/tests/integration/targets/vyos_vlan/defaults/main.yaml @@ -1,3 +1,3 @@ --- -testcase: '*' +testcase: "*" test_items: [] diff --git a/tests/integration/targets/vyos_vlan/tasks/cli.yaml b/tests/integration/targets/vyos_vlan/tasks/cli.yaml index 8f7b62f..b2746ce 100644 --- a/tests/integration/targets/vyos_vlan/tasks/cli.yaml +++ b/tests/integration/targets/vyos_vlan/tasks/cli.yaml @@ -1,8 +1,8 @@ --- - name: collect all cli test cases find: - paths: '{{ role_path }}/tests/cli' - patterns: '{{ testcase }}.yaml' + paths: "{{ role_path }}/tests/cli" + patterns: "{{ testcase }}.yaml" register: test_cases delegate_to: localhost @@ -10,8 +10,8 @@ set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}" - name: run test case (connection=ansible.netcommon.network_cli) - include: '{{ test_case_to_run }} ansible_connection=ansible.netcommon.network_cli' - with_items: '{{ test_items }}' + include: "{{ test_case_to_run }} ansible_connection=ansible.netcommon.network_cli" + with_items: "{{ test_items }}" loop_control: loop_var: test_case_to_run tags: diff --git a/tests/integration/targets/vyos_vlan/tests/cli/basic.yaml b/tests/integration/targets/vyos_vlan/tests/cli/basic.yaml index eade5a4..2dfa1ec 100644 --- a/tests/integration/targets/vyos_vlan/tests/cli/basic.yaml +++ b/tests/integration/targets/vyos_vlan/tests/cli/basic.yaml @@ -74,7 +74,6 @@ register: result vyos.vyos.vyos_vlan: &id004 aggregate: - - vlan_id: 101 name: voice interfaces: eth0 diff --git a/tests/unit/compat/mock.py b/tests/unit/compat/mock.py index b7df24f..4bef4c2 100644 --- a/tests/unit/compat/mock.py +++ b/tests/unit/compat/mock.py @@ -24,6 +24,7 @@ __metaclass__ = type Compat module for Python3.x's unittest.mock module """ import sys + import _io # Python 2.7 @@ -102,9 +103,7 @@ if sys.version_info >= (3,) and sys.version_info < (3, 4, 4): global file_spec if file_spec is None: - file_spec = list( - set(dir(_io.TextIOWrapper)).union(set(dir(_io.BytesIO))) - ) + file_spec = list(set(dir(_io.TextIOWrapper)).union(set(dir(_io.BytesIO)))) if mock is None: mock = MagicMock(name="open", spec=open) diff --git a/tests/unit/mock/loader.py b/tests/unit/mock/loader.py index aea5df5..258dccd 100644 --- a/tests/unit/mock/loader.py +++ b/tests/unit/mock/loader.py @@ -23,8 +23,8 @@ __metaclass__ = type import os from ansible.errors import AnsibleParserError -from ansible.parsing.dataloader import DataLoader from ansible.module_utils._text import to_bytes, to_text +from ansible.parsing.dataloader import DataLoader class DictDataLoader(DataLoader): diff --git a/tests/unit/mock/path.py b/tests/unit/mock/path.py index 74b02be..3962f24 100644 --- a/tests/unit/mock/path.py +++ b/tests/unit/mock/path.py @@ -1,10 +1,8 @@ from __future__ import absolute_import, division, print_function __metaclass__ = type -from ansible_collections.vyos.vyos.tests.unit.compat.mock import MagicMock from ansible.utils.path import unfrackpath +from ansible_collections.vyos.vyos.tests.unit.compat.mock import MagicMock -mock_unfrackpath_noop = MagicMock( - spec_set=unfrackpath, side_effect=lambda x, *args, **kwargs: x -) +mock_unfrackpath_noop = MagicMock(spec_set=unfrackpath, side_effect=lambda x, *args, **kwargs: x) diff --git a/tests/unit/mock/procenv.py b/tests/unit/mock/procenv.py index 1587949..06987e3 100644 --- a/tests/unit/mock/procenv.py +++ b/tests/unit/mock/procenv.py @@ -21,14 +21,15 @@ from __future__ import absolute_import, division, print_function __metaclass__ = type -import sys import json - +import sys from contextlib import contextmanager from io import BytesIO, StringIO -from ansible_collections.vyos.vyos.tests.unit.compat import unittest -from ansible.module_utils.six import PY3 + from ansible.module_utils._text import to_bytes +from ansible.module_utils.six import PY3 + +from ansible_collections.vyos.vyos.tests.unit.compat import unittest @contextmanager diff --git a/tests/unit/mock/vault_helper.py b/tests/unit/mock/vault_helper.py index b34ae13..4c6c890 100644 --- a/tests/unit/mock/vault_helper.py +++ b/tests/unit/mock/vault_helper.py @@ -17,7 +17,6 @@ from __future__ import absolute_import, division, print_function __metaclass__ = type from ansible.module_utils._text import to_bytes - from ansible.parsing.vault import VaultSecret @@ -37,6 +36,4 @@ class TextVaultSecret(VaultSecret): @property def bytes(self): """The text encoded with encoding, unless we specifically set _bytes.""" - return self._bytes or to_bytes( - self.text, encoding=self.encoding, errors=self.errors - ) + return self._bytes or to_bytes(self.text, encoding=self.encoding, errors=self.errors) diff --git a/tests/unit/mock/yaml_helper.py b/tests/unit/mock/yaml_helper.py index 5df30aa..540055d 100644 --- a/tests/unit/mock/yaml_helper.py +++ b/tests/unit/mock/yaml_helper.py @@ -2,11 +2,11 @@ from __future__ import absolute_import, division, print_function __metaclass__ = type import io -import yaml +import yaml from ansible.module_utils.six import PY3 -from ansible.parsing.yaml.loader import AnsibleLoader from ansible.parsing.yaml.dumper import AnsibleDumper +from ansible.parsing.yaml.loader import AnsibleLoader class YamlTestUtils(object): @@ -44,9 +44,7 @@ class YamlTestUtils(object): obj_2 = loader.get_data() # dump the gen 2 objects directory to strings - string_from_object_dump_2 = self._dump_string( - obj_2, dumper=AnsibleDumper - ) + string_from_object_dump_2 = self._dump_string(obj_2, dumper=AnsibleDumper) # The gen 1 and gen 2 yaml strings self.assertEqual(string_from_object_dump, string_from_object_dump_2) @@ -58,9 +56,7 @@ class YamlTestUtils(object): loader_3 = self._loader(stream_3) obj_3 = loader_3.get_data() - string_from_object_dump_3 = self._dump_string( - obj_3, dumper=AnsibleDumper - ) + string_from_object_dump_3 = self._dump_string(obj_3, dumper=AnsibleDumper) self.assertEqual(obj, obj_3) # should be transitive, but... @@ -92,12 +88,8 @@ class YamlTestUtils(object): stream_obj_from_string = io.StringIO() if PY3: - yaml.dump( - obj_from_stream, stream_obj_from_stream, Dumper=AnsibleDumper - ) - yaml.dump( - obj_from_stream, stream_obj_from_string, Dumper=AnsibleDumper - ) + yaml.dump(obj_from_stream, stream_obj_from_stream, Dumper=AnsibleDumper) + yaml.dump(obj_from_stream, stream_obj_from_string, Dumper=AnsibleDumper) else: yaml.dump( obj_from_stream, @@ -119,12 +111,8 @@ class YamlTestUtils(object): stream_obj_from_string.seek(0) if PY3: - yaml_string_obj_from_stream = yaml.dump( - obj_from_stream, Dumper=AnsibleDumper - ) - yaml_string_obj_from_string = yaml.dump( - obj_from_string, Dumper=AnsibleDumper - ) + yaml_string_obj_from_stream = yaml.dump(obj_from_stream, Dumper=AnsibleDumper) + yaml_string_obj_from_string = yaml.dump(obj_from_string, Dumper=AnsibleDumper) else: yaml_string_obj_from_stream = yaml.dump( obj_from_stream, Dumper=AnsibleDumper, encoding=None @@ -134,11 +122,7 @@ class YamlTestUtils(object): ) assert yaml_string == yaml_string_obj_from_stream - assert ( - yaml_string - == yaml_string_obj_from_stream - == yaml_string_obj_from_string - ) + assert yaml_string == yaml_string_obj_from_stream == yaml_string_obj_from_string assert ( yaml_string == yaml_string_obj_from_stream diff --git a/tests/unit/modules/conftest.py b/tests/unit/modules/conftest.py index e19a1e0..013d198 100644 --- a/tests/unit/modules/conftest.py +++ b/tests/unit/modules/conftest.py @@ -7,10 +7,9 @@ __metaclass__ = type import json import pytest - -from ansible.module_utils.six import string_types from ansible.module_utils._text import to_bytes from ansible.module_utils.common._collections_compat import MutableMapping +from ansible.module_utils.six import string_types @pytest.fixture @@ -21,20 +20,11 @@ def patch_ansible_module(request, mocker): if "ANSIBLE_MODULE_ARGS" not in request.param: request.param = {"ANSIBLE_MODULE_ARGS": request.param} if "_ansible_remote_tmp" not in request.param["ANSIBLE_MODULE_ARGS"]: - request.param["ANSIBLE_MODULE_ARGS"][ - "_ansible_remote_tmp" - ] = "/tmp" - if ( - "_ansible_keep_remote_files" - not in request.param["ANSIBLE_MODULE_ARGS"] - ): - request.param["ANSIBLE_MODULE_ARGS"][ - "_ansible_keep_remote_files" - ] = False + request.param["ANSIBLE_MODULE_ARGS"]["_ansible_remote_tmp"] = "/tmp" + if "_ansible_keep_remote_files" not in request.param["ANSIBLE_MODULE_ARGS"]: + request.param["ANSIBLE_MODULE_ARGS"]["_ansible_keep_remote_files"] = False args = json.dumps(request.param) else: - raise Exception( - "Malformed data to the patch_ansible_module pytest fixture" - ) + raise Exception("Malformed data to the patch_ansible_module pytest fixture") mocker.patch("ansible.module_utils.basic._ANSIBLE_ARGS", to_bytes(args)) diff --git a/tests/unit/modules/network/vyos/test_vyos_banner.py b/tests/unit/modules/network/vyos/test_vyos_banner.py index 4281cba..08d4424 100644 --- a/tests/unit/modules/network/vyos/test_vyos_banner.py +++ b/tests/unit/modules/network/vyos/test_vyos_banner.py @@ -18,11 +18,10 @@ from __future__ import absolute_import, division, print_function __metaclass__ = type -from ansible_collections.vyos.vyos.tests.unit.compat.mock import patch from ansible_collections.vyos.vyos.plugins.modules import vyos_banner -from ansible_collections.vyos.vyos.tests.unit.modules.utils import ( - set_module_args, -) +from ansible_collections.vyos.vyos.tests.unit.compat.mock import patch +from ansible_collections.vyos.vyos.tests.unit.modules.utils import set_module_args + from .vyos_module import TestVyosModule @@ -53,9 +52,7 @@ class TestVyosBannerModule(TestVyosModule): def test_vyos_banner_create(self): set_module_args(dict(banner="pre-login", text="test\nbanner\nstring")) - commands = [ - "set system login banner pre-login 'test\\nbanner\\nstring'" - ] + commands = ["set system login banner pre-login 'test\\nbanner\\nstring'"] self.execute_module(changed=True, commands=commands) def test_vyos_banner_remove(self): diff --git a/tests/unit/modules/network/vyos/test_vyos_bgp_address_family.py b/tests/unit/modules/network/vyos/test_vyos_bgp_address_family.py index db39466..a9f0ef1 100644 --- a/tests/unit/modules/network/vyos/test_vyos_bgp_address_family.py +++ b/tests/unit/modules/network/vyos/test_vyos_bgp_address_family.py @@ -20,13 +20,10 @@ from __future__ import absolute_import, division, print_function __metaclass__ = type +from ansible_collections.vyos.vyos.plugins.modules import vyos_bgp_address_family from ansible_collections.vyos.vyos.tests.unit.compat.mock import patch -from ansible_collections.vyos.vyos.plugins.modules import ( - vyos_bgp_address_family, -) -from ansible_collections.vyos.vyos.tests.unit.modules.utils import ( - set_module_args, -) +from ansible_collections.vyos.vyos.tests.unit.modules.utils import set_module_args + from .vyos_module import TestVyosModule, load_fixture @@ -39,9 +36,7 @@ class TestVyosBgpafModule(TestVyosModule): self.mock_get_resource_connection_config = patch( "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.rm_base.resource_module_base.get_resource_connection" ) - self.get_resource_connection_config = ( - self.mock_get_resource_connection_config.start() - ) + self.get_resource_connection_config = self.mock_get_resource_connection_config.start() self.mock_execute_show_command = patch( "ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts." @@ -72,13 +67,9 @@ class TestVyosBgpafModule(TestVyosModule): address_family=[ dict( afi="ipv4", - aggregate_address=[ - dict(prefix="192.0.2.0/24", as_set=True) - ], + aggregate_address=[dict(prefix="192.0.2.0/24", as_set=True)], networks=[ - dict( - prefix="192.1.13.0/24", route_map="map01" - ), + dict(prefix="192.1.13.0/24", route_map="map01"), dict(prefix="192.2.13.0/24", backdoor=True), ], ), @@ -93,11 +84,7 @@ class TestVyosBgpafModule(TestVyosModule): address_family=[ dict( afi="ipv4", - route_map=[ - dict( - action="export", route_map="map01" - ) - ], + route_map=[dict(action="export", route_map="map01")], soft_reconfiguration=True, ), ], @@ -125,13 +112,9 @@ class TestVyosBgpafModule(TestVyosModule): address_family=[ dict( afi="ipv4", - aggregate_address=[ - dict(prefix="192.0.2.0/24", summary_only=True) - ], + aggregate_address=[dict(prefix="192.0.2.0/24", summary_only=True)], networks=[ - dict( - prefix="192.1.13.0/24", route_map="map01" - ), + dict(prefix="192.1.13.0/24", route_map="map01"), ], ), dict( @@ -145,9 +128,7 @@ class TestVyosBgpafModule(TestVyosModule): address_family=[ dict( afi="ipv6", - distribute_list=[ - dict(action="export", acl=10) - ], + distribute_list=[dict(action="export", acl=10)], route_server_client=True, ), ], @@ -158,9 +139,7 @@ class TestVyosBgpafModule(TestVyosModule): dict( afi="ipv4", filter_list=[ - dict( - action="export", path_list="list01" - ), + dict(action="export", path_list="list01"), ], capability=dict(orf="send"), ) @@ -189,13 +168,9 @@ class TestVyosBgpafModule(TestVyosModule): address_family=[ dict( afi="ipv4", - aggregate_address=[ - dict(prefix="192.0.2.0/24", as_set=True) - ], + aggregate_address=[dict(prefix="192.0.2.0/24", as_set=True)], networks=[ - dict( - prefix="192.1.13.0/24", route_map="map01" - ), + dict(prefix="192.1.13.0/24", route_map="map01"), dict(prefix="192.2.13.0/24", backdoor=True), ], ), @@ -210,11 +185,7 @@ class TestVyosBgpafModule(TestVyosModule): address_family=[ dict( afi="ipv4", - route_map=[ - dict( - action="export", route_map="map01" - ) - ], + route_map=[dict(action="export", route_map="map01")], soft_reconfiguration=True, ), ], @@ -243,13 +214,9 @@ class TestVyosBgpafModule(TestVyosModule): address_family=[ dict( afi="ipv4", - aggregate_address=[ - dict(prefix="192.0.2.0/24", summary_only=True) - ], + aggregate_address=[dict(prefix="192.0.2.0/24", summary_only=True)], networks=[ - dict( - prefix="192.1.13.0/24", route_map="map01" - ), + dict(prefix="192.1.13.0/24", route_map="map01"), ], ), dict( @@ -263,17 +230,11 @@ class TestVyosBgpafModule(TestVyosModule): address_family=[ dict( afi="ipv4", - route_map=[ - dict( - action="import", route_map="map01" - ) - ], + route_map=[dict(action="import", route_map="map01")], ), dict( afi="ipv6", - distribute_list=[ - dict(action="export", acl=10) - ], + distribute_list=[dict(action="export", acl=10)], route_server_client=True, ), ], @@ -283,11 +244,7 @@ class TestVyosBgpafModule(TestVyosModule): address_family=[ dict( afi="ipv4", - route_map=[ - dict( - action="export", route_map="map01" - ) - ], + route_map=[dict(action="export", route_map="map01")], ), ], ), @@ -297,9 +254,7 @@ class TestVyosBgpafModule(TestVyosModule): dict( afi="ipv4", filter_list=[ - dict( - action="export", path_list="list01" - ), + dict(action="export", path_list="list01"), ], capability=dict(orf="send"), ) @@ -333,13 +288,9 @@ class TestVyosBgpafModule(TestVyosModule): address_family=[ dict( afi="ipv4", - aggregate_address=[ - dict(prefix="192.0.2.0/24", as_set=True) - ], + aggregate_address=[dict(prefix="192.0.2.0/24", as_set=True)], networks=[ - dict( - prefix="192.1.13.0/24", route_map="map01" - ), + dict(prefix="192.1.13.0/24", route_map="map01"), dict(prefix="192.2.13.0/24", backdoor=True), ], ), @@ -354,11 +305,7 @@ class TestVyosBgpafModule(TestVyosModule): address_family=[ dict( afi="ipv4", - route_map=[ - dict( - action="export", route_map="map01" - ) - ], + route_map=[dict(action="export", route_map="map01")], soft_reconfiguration=True, ), ], @@ -388,9 +335,7 @@ class TestVyosBgpafModule(TestVyosModule): dict( afi="ipv4", networks=[ - dict( - prefix="192.1.13.0/24", route_map="map01" - ), + dict(prefix="192.1.13.0/24", route_map="map01"), ], ), dict( @@ -404,17 +349,11 @@ class TestVyosBgpafModule(TestVyosModule): address_family=[ dict( afi="ipv4", - route_map=[ - dict( - action="import", route_map="map01" - ) - ], + route_map=[dict(action="import", route_map="map01")], ), dict( afi="ipv6", - distribute_list=[ - dict(action="export", acl=10) - ], + distribute_list=[dict(action="export", acl=10)], route_server_client=True, ), ], @@ -481,9 +420,7 @@ class TestVyosBgpafModule(TestVyosModule): dict( afi="ipv4", networks=[ - dict( - prefix="192.1.13.0/24", route_map="map01" - ), + dict(prefix="192.1.13.0/24", route_map="map01"), ], ), dict( @@ -497,17 +434,11 @@ class TestVyosBgpafModule(TestVyosModule): address_family=[ dict( afi="ipv4", - route_map=[ - dict( - action="import", route_map="map01" - ) - ], + route_map=[dict(action="import", route_map="map01")], ), dict( afi="ipv6", - distribute_list=[ - dict(action="export", acl=10) - ], + distribute_list=[dict(action="export", acl=10)], route_server_client=True, ), ], @@ -517,9 +448,7 @@ class TestVyosBgpafModule(TestVyosModule): ) ) result = self.execute_module(failed=True) - self.assertIn( - "Only one bgp instance is allowed per device", result["msg"] - ) + self.assertIn("Only one bgp instance is allowed per device", result["msg"]) def test_vyos_bgp_address_family_rendered(self): set_module_args( @@ -530,13 +459,9 @@ class TestVyosBgpafModule(TestVyosModule): address_family=[ dict( afi="ipv4", - aggregate_address=[ - dict(prefix="192.0.2.0/24", as_set=True) - ], + aggregate_address=[dict(prefix="192.0.2.0/24", as_set=True)], networks=[ - dict( - prefix="192.1.13.0/24", route_map="map01" - ), + dict(prefix="192.1.13.0/24", route_map="map01"), dict(prefix="192.2.13.0/24", backdoor=True), ], ), @@ -551,11 +476,7 @@ class TestVyosBgpafModule(TestVyosModule): address_family=[ dict( afi="ipv4", - route_map=[ - dict( - action="export", route_map="map01" - ) - ], + route_map=[dict(action="export", route_map="map01")], soft_reconfiguration=True, ), ], @@ -613,9 +534,7 @@ class TestVyosBgpafModule(TestVyosModule): {"prefix": "192.1.13.0/24", "route_map": "map01"}, {"prefix": "192.2.13.0/24", "backdoor": True}, ], - "aggregate_address": [ - {"prefix": "192.0.2.0/24", "as_set": True} - ], + "aggregate_address": [{"prefix": "192.0.2.0/24", "as_set": True}], }, { "afi": "ipv6", @@ -654,9 +573,7 @@ class TestVyosBgpafModule(TestVyosModule): {"prefix": "192.1.13.0/24", "route_map": "map01"}, {"prefix": "192.2.13.0/24", "backdoor": True}, ], - "aggregate_address": [ - {"prefix": "192.0.2.0/24", "as_set": True} - ], + "aggregate_address": [{"prefix": "192.0.2.0/24", "as_set": True}], }, { "afi": "ipv6", diff --git a/tests/unit/modules/network/vyos/test_vyos_bgp_global.py b/tests/unit/modules/network/vyos/test_vyos_bgp_global.py index 465b249..23f2e6a 100644 --- a/tests/unit/modules/network/vyos/test_vyos_bgp_global.py +++ b/tests/unit/modules/network/vyos/test_vyos_bgp_global.py @@ -20,11 +20,10 @@ from __future__ import absolute_import, division, print_function __metaclass__ = type -from ansible_collections.vyos.vyos.tests.unit.compat.mock import patch from ansible_collections.vyos.vyos.plugins.modules import vyos_bgp_global -from ansible_collections.vyos.vyos.tests.unit.modules.utils import ( - set_module_args, -) +from ansible_collections.vyos.vyos.tests.unit.compat.mock import patch +from ansible_collections.vyos.vyos.tests.unit.modules.utils import set_module_args + from .vyos_module import TestVyosModule, load_fixture @@ -38,23 +37,17 @@ class TestVyosBgpglobalModule(TestVyosModule): self.mock_get_resource_connection_config = patch( "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.rm_base.resource_module_base.get_resource_connection" ) - self.get_resource_connection_config = ( - self.mock_get_resource_connection_config.start() - ) + self.get_resource_connection_config = self.mock_get_resource_connection_config.start() self.mock_execute_show_command_config = patch( "ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.config.bgp_global.bgp_global.Bgp_global._get_config" ) - self.execute_show_command_config = ( - self.mock_execute_show_command_config.start() - ) + self.execute_show_command_config = self.mock_execute_show_command_config.start() self.mock_get_resource_connection_facts = patch( "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.facts.facts.get_resource_connection" ) - self.get_resource_connection_facts = ( - self.mock_get_resource_connection_facts.start() - ) + self.get_resource_connection_facts = self.mock_get_resource_connection_facts.start() self.mock_execute_show_command = patch( "ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.bgp_global.bgp_global.Bgp_globalFacts.get_device_data" @@ -318,9 +311,7 @@ class TestVyosBgpglobalModule(TestVyosModule): ) ) result = self.execute_module(failed=True) - self.assertIn( - "Only one bgp instance is allowed per device", result["msg"] - ) + self.assertIn("Only one bgp instance is allowed per device", result["msg"]) def test_vyos_bgp_global_replaced_af(self): set_module_args( @@ -356,9 +347,7 @@ class TestVyosBgpglobalModule(TestVyosModule): state="replaced", ) ) - result = self.execute_module( - failed=True, filename="vyos_bgp_global_af_config.cfg" - ) + result = self.execute_module(failed=True, filename="vyos_bgp_global_af_config.cfg") self.assertIn( "Use the _bgp_address_family module to delete the address_family under neighbor 5001::64, before replacing/deleting the neighbor.", result["msg"], diff --git a/tests/unit/modules/network/vyos/test_vyos_command.py b/tests/unit/modules/network/vyos/test_vyos_command.py index a8a3569..7ed049b 100644 --- a/tests/unit/modules/network/vyos/test_vyos_command.py +++ b/tests/unit/modules/network/vyos/test_vyos_command.py @@ -20,11 +20,10 @@ from __future__ import absolute_import, division, print_function __metaclass__ = type -from ansible_collections.vyos.vyos.tests.unit.compat.mock import patch from ansible_collections.vyos.vyos.plugins.modules import vyos_command -from ansible_collections.vyos.vyos.tests.unit.modules.utils import ( - set_module_args, -) +from ansible_collections.vyos.vyos.tests.unit.compat.mock import patch +from ansible_collections.vyos.vyos.tests.unit.modules.utils import set_module_args + from .vyos_module import TestVyosModule, load_fixture @@ -84,9 +83,7 @@ class TestVyosCommandModule(TestVyosModule): def test_vyos_command_retries(self): wait_for = 'result[0] contains "test string"' - set_module_args( - dict(commands=["show version"], wait_for=wait_for, retries=2) - ) + set_module_args(dict(commands=["show version"], wait_for=wait_for, retries=2)) self.execute_module(failed=True) self.assertEqual(self.run_commands.call_count, 2) @@ -95,9 +92,7 @@ class TestVyosCommandModule(TestVyosModule): 'result[0] contains "VyOS maintainers"', 'result[0] contains "test string"', ] - set_module_args( - dict(commands=["show version"], wait_for=wait_for, match="any") - ) + set_module_args(dict(commands=["show version"], wait_for=wait_for, match="any")) self.execute_module() def test_vyos_command_match_all(self): @@ -105,9 +100,7 @@ class TestVyosCommandModule(TestVyosModule): 'result[0] contains "VyOS maintainers"', 'result[0] contains "maintainers@vyos.net"', ] - set_module_args( - dict(commands=["show version"], wait_for=wait_for, match="all") - ) + set_module_args(dict(commands=["show version"], wait_for=wait_for, match="all")) self.execute_module() def test_vyos_command_match_all_failure(self): @@ -116,7 +109,5 @@ class TestVyosCommandModule(TestVyosModule): 'result[0] contains "test string"', ] commands = ["show version", "show version"] - set_module_args( - dict(commands=commands, wait_for=wait_for, match="all") - ) + set_module_args(dict(commands=commands, wait_for=wait_for, match="all")) self.execute_module(failed=True) diff --git a/tests/unit/modules/network/vyos/test_vyos_config.py b/tests/unit/modules/network/vyos/test_vyos_config.py index c282c71..def567a 100644 --- a/tests/unit/modules/network/vyos/test_vyos_config.py +++ b/tests/unit/modules/network/vyos/test_vyos_config.py @@ -21,15 +21,11 @@ from __future__ import absolute_import, division, print_function __metaclass__ = type -from ansible_collections.vyos.vyos.tests.unit.compat.mock import ( - patch, - MagicMock, -) -from ansible_collections.vyos.vyos.plugins.modules import vyos_config from ansible_collections.vyos.vyos.plugins.cliconf.vyos import Cliconf -from ansible_collections.vyos.vyos.tests.unit.modules.utils import ( - set_module_args, -) +from ansible_collections.vyos.vyos.plugins.modules import vyos_config +from ansible_collections.vyos.vyos.tests.unit.compat.mock import MagicMock, patch +from ansible_collections.vyos.vyos.tests.unit.modules.utils import set_module_args + from .vyos_module import TestVyosModule, load_fixture @@ -82,9 +78,7 @@ class TestVyosConfigModule(TestVyosModule): def test_vyos_config_unchanged(self): src = load_fixture("vyos_config_config.cfg") - self.conn.get_diff = MagicMock( - return_value=self.cliconf_obj.get_diff(src, src) - ) + self.conn.get_diff = MagicMock(return_value=self.cliconf_obj.get_diff(src, src)) set_module_args(dict(src=src)) self.execute_module() @@ -97,9 +91,7 @@ class TestVyosConfigModule(TestVyosModule): "delete interfaces ethernet eth0 address", ] self.conn.get_diff = MagicMock( - return_value=self.cliconf_obj.get_diff( - candidate, self.running_config - ) + return_value=self.cliconf_obj.get_diff(candidate, self.running_config) ) self.execute_module(changed=True, commands=commands) @@ -124,9 +116,7 @@ class TestVyosConfigModule(TestVyosModule): set_module_args(dict(lines=commands)) candidate = "\n".join(commands) self.conn.get_diff = MagicMock( - return_value=self.cliconf_obj.get_diff( - candidate, self.running_config - ) + return_value=self.cliconf_obj.get_diff(candidate, self.running_config) ) self.execute_module(changed=True, commands=commands) @@ -135,9 +125,7 @@ class TestVyosConfigModule(TestVyosModule): new_config = ["set system host-name router"] set_module_args(dict(lines=new_config, config=config)) candidate = "\n".join(new_config) - self.conn.get_diff = MagicMock( - return_value=self.cliconf_obj.get_diff(candidate, config) - ) + self.conn.get_diff = MagicMock(return_value=self.cliconf_obj.get_diff(candidate, config)) self.execute_module(changed=True, commands=new_config) def test_vyos_config_match_none(self): @@ -148,8 +136,6 @@ class TestVyosConfigModule(TestVyosModule): set_module_args(dict(lines=lines, match="none")) candidate = "\n".join(lines) self.conn.get_diff = MagicMock( - return_value=self.cliconf_obj.get_diff( - candidate, None, diff_match="none" - ) + return_value=self.cliconf_obj.get_diff(candidate, None, diff_match="none") ) self.execute_module(changed=True, commands=lines, sort=False) diff --git a/tests/unit/modules/network/vyos/test_vyos_facts.py b/tests/unit/modules/network/vyos/test_vyos_facts.py index c0ef686..727f69b 100644 --- a/tests/unit/modules/network/vyos/test_vyos_facts.py +++ b/tests/unit/modules/network/vyos/test_vyos_facts.py @@ -19,11 +19,11 @@ from __future__ import absolute_import, division, print_function __metaclass__ = type import json -from ansible_collections.vyos.vyos.tests.unit.compat.mock import patch + from ansible_collections.vyos.vyos.plugins.modules import vyos_facts -from ansible_collections.vyos.vyos.tests.unit.modules.utils import ( - set_module_args, -) +from ansible_collections.vyos.vyos.tests.unit.compat.mock import patch +from ansible_collections.vyos.vyos.tests.unit.modules.utils import set_module_args + from .vyos_module import TestVyosModule, load_fixture @@ -40,9 +40,7 @@ class TestVyosFactsModule(TestVyosModule): self.mock_get_resource_connection = patch( "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.facts.facts.get_resource_connection" ) - self.get_resource_connection = ( - self.mock_get_resource_connection.start() - ) + self.get_resource_connection = self.mock_get_resource_connection.start() self.mock_get_capabilities = patch( "ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.legacy.base.get_capabilities" diff --git a/tests/unit/modules/network/vyos/test_vyos_firewall_global.py b/tests/unit/modules/network/vyos/test_vyos_firewall_global.py index c691f09..367da22 100644 --- a/tests/unit/modules/network/vyos/test_vyos_firewall_global.py +++ b/tests/unit/modules/network/vyos/test_vyos_firewall_global.py @@ -20,11 +20,10 @@ from __future__ import absolute_import, division, print_function __metaclass__ = type -from ansible_collections.vyos.vyos.tests.unit.compat.mock import patch from ansible_collections.vyos.vyos.plugins.modules import vyos_firewall_global -from ansible_collections.vyos.vyos.tests.unit.modules.utils import ( - set_module_args, -) +from ansible_collections.vyos.vyos.tests.unit.compat.mock import patch +from ansible_collections.vyos.vyos.tests.unit.modules.utils import set_module_args + from .vyos_module import TestVyosModule, load_fixture @@ -47,16 +46,12 @@ class TestVyosFirewallRulesModule(TestVyosModule): self.mock_get_resource_connection_config = patch( "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.cfg.base.get_resource_connection" ) - self.get_resource_connection_config = ( - self.mock_get_resource_connection_config.start() - ) + self.get_resource_connection_config = self.mock_get_resource_connection_config.start() self.mock_get_resource_connection_facts = patch( "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.facts.facts.get_resource_connection" ) - self.get_resource_connection_facts = ( - self.mock_get_resource_connection_facts.start() - ) + self.get_resource_connection_facts = self.mock_get_resource_connection_facts.start() self.mock_execute_show_command = patch( "ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.firewall_global.firewall_global.Firewall_globalFacts.get_device_data" diff --git a/tests/unit/modules/network/vyos/test_vyos_firewall_interfaces.py b/tests/unit/modules/network/vyos/test_vyos_firewall_interfaces.py index 186edaa..fe64659 100644 --- a/tests/unit/modules/network/vyos/test_vyos_firewall_interfaces.py +++ b/tests/unit/modules/network/vyos/test_vyos_firewall_interfaces.py @@ -20,13 +20,10 @@ from __future__ import absolute_import, division, print_function __metaclass__ = type +from ansible_collections.vyos.vyos.plugins.modules import vyos_firewall_interfaces from ansible_collections.vyos.vyos.tests.unit.compat.mock import patch -from ansible_collections.vyos.vyos.plugins.modules import ( - vyos_firewall_interfaces, -) -from ansible_collections.vyos.vyos.tests.unit.modules.utils import ( - set_module_args, -) +from ansible_collections.vyos.vyos.tests.unit.modules.utils import set_module_args + from .vyos_module import TestVyosModule, load_fixture @@ -49,16 +46,12 @@ class TestVyosFirewallInterfacesModule(TestVyosModule): self.mock_get_resource_connection_config = patch( "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.cfg.base.get_resource_connection" ) - self.get_resource_connection_config = ( - self.mock_get_resource_connection_config.start() - ) + self.get_resource_connection_config = self.mock_get_resource_connection_config.start() self.mock_get_resource_connection_facts = patch( "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.facts.facts.get_resource_connection" ) - self.get_resource_connection_facts = ( - self.mock_get_resource_connection_facts.start() - ) + self.get_resource_connection_facts = self.mock_get_resource_connection_facts.start() self.mock_execute_show_command = patch( "ansible_collections.vyos.vyos.plugins.module_utils.network.vyos." @@ -97,9 +90,7 @@ class TestVyosFirewallInterfacesModule(TestVyosModule): ), dict( afi="ipv6", - rules=[ - dict(name="V6-LOCAL", direction="local") - ], + rules=[dict(name="V6-LOCAL", direction="local")], ), ], ), @@ -116,9 +107,7 @@ class TestVyosFirewallInterfacesModule(TestVyosModule): ), dict( afi="ipv6", - rules=[ - dict(name="V6-LOCAL", direction="local") - ], + rules=[dict(name="V6-LOCAL", direction="local")], ), ], ), @@ -155,9 +144,7 @@ class TestVyosFirewallInterfacesModule(TestVyosModule): ), dict( afi="ipv6", - rules=[ - dict(name="V6-LOCAL", direction="local") - ], + rules=[dict(name="V6-LOCAL", direction="local")], ), ], ), @@ -174,9 +161,7 @@ class TestVyosFirewallInterfacesModule(TestVyosModule): ), dict( afi="ipv6", - rules=[ - dict(name="V6-LOCAL", direction="local") - ], + rules=[dict(name="V6-LOCAL", direction="local")], ), ], ), @@ -207,11 +192,7 @@ class TestVyosFirewallInterfacesModule(TestVyosModule): self.execute_module(changed=True, commands=commands) def test_vyos_firewall_rule_set_03_deleted_per_interface(self): - set_module_args( - dict( - config=[dict(name="eth0"), dict(name="eth2")], state="deleted" - ) - ) + set_module_args(dict(config=[dict(name="eth0"), dict(name="eth2")], state="deleted")) commands = [ "delete interfaces ethernet eth0 firewall", "delete interfaces ethernet eth2 firewall", @@ -227,11 +208,7 @@ class TestVyosFirewallInterfacesModule(TestVyosModule): self.execute_module(changed=True, commands=commands) def test_vyos_firewall_rule_set_03_deleted(self): - set_module_args( - dict( - config=[dict(name="eth0"), dict(name="eth2")], state="deleted" - ) - ) + set_module_args(dict(config=[dict(name="eth0"), dict(name="eth2")], state="deleted")) commands = [ "delete interfaces ethernet eth0 firewall", "delete interfaces ethernet eth2 firewall", @@ -239,11 +216,7 @@ class TestVyosFirewallInterfacesModule(TestVyosModule): self.execute_module(changed=True, commands=commands) def test_vyos_firewall_rule_set_04_deleted_interface_idem(self): - set_module_args( - dict( - config=[dict(name="eth1"), dict(name="eth3")], state="deleted" - ) - ) + set_module_args(dict(config=[dict(name="eth1"), dict(name="eth3")], state="deleted")) self.execute_module(changed=False, commands=[]) def test_vyos_firewall_rule_set_02_replaced_idem(self): @@ -263,9 +236,7 @@ class TestVyosFirewallInterfacesModule(TestVyosModule): ), dict( afi="ipv6", - rules=[ - dict(name="V6-LOCAL", direction="local") - ], + rules=[dict(name="V6-LOCAL", direction="local")], ), ], ), @@ -282,9 +253,7 @@ class TestVyosFirewallInterfacesModule(TestVyosModule): ), dict( afi="ipv6", - rules=[ - dict(name="V6-LOCAL", direction="local") - ], + rules=[dict(name="V6-LOCAL", direction="local")], ), ], ), @@ -307,9 +276,7 @@ class TestVyosFirewallInterfacesModule(TestVyosModule): ), dict( afi="ipv6", - rules=[ - dict(name="V6-LOCAL", direction="local") - ], + rules=[dict(name="V6-LOCAL", direction="local")], ), ], ), @@ -322,9 +289,7 @@ class TestVyosFirewallInterfacesModule(TestVyosModule): ), dict( afi="ipv6", - rules=[ - dict(name="V6-LOCAL", direction="local") - ], + rules=[dict(name="V6-LOCAL", direction="local")], ), ], ), @@ -337,9 +302,7 @@ class TestVyosFirewallInterfacesModule(TestVyosModule): ), dict( afi="ipv6", - rules=[ - dict(name="V6-LOCAL", direction="local") - ], + rules=[dict(name="V6-LOCAL", direction="local")], ), ], ), @@ -398,9 +361,7 @@ class TestVyosFirewallInterfacesModule(TestVyosModule): ), dict( afi="ipv6", - rules=[ - dict(name="V6-LOCAL", direction="local") - ], + rules=[dict(name="V6-LOCAL", direction="local")], ), ], ), @@ -417,9 +378,7 @@ class TestVyosFirewallInterfacesModule(TestVyosModule): ), dict( afi="ipv6", - rules=[ - dict(name="V6-LOCAL", direction="local") - ], + rules=[dict(name="V6-LOCAL", direction="local")], ), ], ), diff --git a/tests/unit/modules/network/vyos/test_vyos_firewall_rules.py b/tests/unit/modules/network/vyos/test_vyos_firewall_rules.py index c82ffc6..623ab1e 100644 --- a/tests/unit/modules/network/vyos/test_vyos_firewall_rules.py +++ b/tests/unit/modules/network/vyos/test_vyos_firewall_rules.py @@ -20,11 +20,10 @@ from __future__ import absolute_import, division, print_function __metaclass__ = type -from ansible_collections.vyos.vyos.tests.unit.compat.mock import patch from ansible_collections.vyos.vyos.plugins.modules import vyos_firewall_rules -from ansible_collections.vyos.vyos.tests.unit.modules.utils import ( - set_module_args, -) +from ansible_collections.vyos.vyos.tests.unit.compat.mock import patch +from ansible_collections.vyos.vyos.tests.unit.modules.utils import set_module_args + from .vyos_module import TestVyosModule, load_fixture @@ -47,16 +46,12 @@ class TestVyosFirewallRulesModule(TestVyosModule): self.mock_get_resource_connection_config = patch( "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.cfg.base.get_resource_connection" ) - self.get_resource_connection_config = ( - self.mock_get_resource_connection_config.start() - ) + self.get_resource_connection_config = self.mock_get_resource_connection_config.start() self.mock_get_resource_connection_facts = patch( "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.facts.facts.get_resource_connection" ) - self.get_resource_connection_facts = ( - self.mock_get_resource_connection_facts.start() - ) + self.get_resource_connection_facts = self.mock_get_resource_connection_facts.start() self.mock_execute_show_command = patch( "ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.static_routes.static_routes.Static_routesFacts.get_device_data" ) @@ -271,14 +266,10 @@ class TestVyosFirewallRulesModule(TestVyosModule): mac_address="38:00:25:19:76:0c", port=2127, ), - destination=dict( - address="192.0.1.0", port=2124 - ), + destination=dict(address="192.0.1.0", port=2124), limit=dict( burst=10, - rate=dict( - number=20, unit="second" - ), + rate=dict(number=20, unit="second"), ), recent=dict(count=10, time=20), state=dict( @@ -467,14 +458,10 @@ class TestVyosFirewallRulesModule(TestVyosModule): mac_address="38:00:25:19:76:0c", port=2127, ), - destination=dict( - address="2001:db8::11", port=2124 - ), + destination=dict(address="2001:db8::11", port=2124), limit=dict( burst=10, - rate=dict( - number=20, unit="second" - ), + rate=dict(number=20, unit="second"), ), recent=dict(count=10, time=20), state=dict( @@ -614,9 +601,7 @@ class TestVyosFirewallRulesModule(TestVyosModule): dict( number="101", protocol="icmp", - icmp=dict( - type_name="port-unreachable" - ), + icmp=dict(type_name="port-unreachable"), ) ], ), diff --git a/tests/unit/modules/network/vyos/test_vyos_hostname.py b/tests/unit/modules/network/vyos/test_vyos_hostname.py index 54377da..13d4e32 100644 --- a/tests/unit/modules/network/vyos/test_vyos_hostname.py +++ b/tests/unit/modules/network/vyos/test_vyos_hostname.py @@ -20,11 +20,10 @@ from __future__ import absolute_import, division, print_function __metaclass__ = type -from ansible_collections.vyos.vyos.tests.unit.compat.mock import patch from ansible_collections.vyos.vyos.plugins.modules import vyos_hostname -from ansible_collections.vyos.vyos.tests.unit.modules.utils import ( - set_module_args, -) +from ansible_collections.vyos.vyos.tests.unit.compat.mock import patch +from ansible_collections.vyos.vyos.tests.unit.modules.utils import set_module_args + from .vyos_module import TestVyosModule, load_fixture @@ -38,16 +37,12 @@ class TestVyosHostnameModule(TestVyosModule): self.mock_get_resource_connection_config = patch( "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.rm_base.resource_module_base.get_resource_connection" ) - self.get_resource_connection_config = ( - self.mock_get_resource_connection_config.start() - ) + self.get_resource_connection_config = self.mock_get_resource_connection_config.start() self.mock_get_resource_connection_facts = patch( "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.facts.facts.get_resource_connection" ) - self.get_resource_connection_facts = ( - self.mock_get_resource_connection_facts.start() - ) + self.get_resource_connection_facts = self.mock_get_resource_connection_facts.start() self.mock_execute_show_command = patch( "ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.hostname.hostname.HostnameFacts.get_config" @@ -76,43 +71,31 @@ class TestVyosHostnameModule(TestVyosModule): self.execute_module(changed=False, commands=[]) def test_vyos_hostname_replaced_idempotent(self): - set_module_args( - dict(config=dict(hostname="vyos_test"), state="replaced") - ) + set_module_args(dict(config=dict(hostname="vyos_test"), state="replaced")) self.execute_module(changed=False, commands=[]) def test_vyos_hostname_overridden_idempotent(self): - set_module_args( - dict(config=dict(hostname="vyos_test"), state="overridden") - ) + set_module_args(dict(config=dict(hostname="vyos_test"), state="overridden")) self.execute_module(changed=False, commands=[]) def test_vyos_hostname_merged(self): set_module_args(dict(config=dict(hostname="vyos"))) - self.execute_module( - changed=True, commands=["set system host-name vyos"] - ) + self.execute_module(changed=True, commands=["set system host-name vyos"]) def test_vyos_hostname_replaced(self): set_module_args(dict(config=dict(hostname="vyos"), state="replaced")) - self.execute_module( - changed=True, commands=["set system host-name vyos"] - ) + self.execute_module(changed=True, commands=["set system host-name vyos"]) def test_vyos_hostname_overridden(self): set_module_args(dict(config=dict(hostname="vyos"), state="overridden")) def test_vyos_hostname_deleted(self): set_module_args(dict(state="deleted")) - self.execute_module( - changed=True, commands=["delete system host-name vyos_test"] - ) + self.execute_module(changed=True, commands=["delete system host-name vyos_test"]) def test_vyos_hostname_gathered(self): set_module_args(dict(state="gathered")) - result = self.execute_module( - changed=False, filename="vyos_hostname_config.cfg" - ) + result = self.execute_module(changed=False, filename="vyos_hostname_config.cfg") gathered_list = {"hostname": "vyos_test"} self.assertEqual(sorted(gathered_list), sorted(result["gathered"])) @@ -124,11 +107,7 @@ class TestVyosHostnameModule(TestVyosModule): self.assertEqual(sorted(parsed_list), sorted(result["parsed"])) def test_vyos_hostname_rendered(self): - set_module_args( - dict(state="rendered", config=dict(hostname="vyos_test")) - ) + set_module_args(dict(state="rendered", config=dict(hostname="vyos_test"))) commands = ["set system host-name vyos_test"] result = self.execute_module(changed=False) - self.assertEqual( - sorted(result["rendered"]), sorted(commands), result["rendered"] - ) + self.assertEqual(sorted(result["rendered"]), sorted(commands), result["rendered"]) diff --git a/tests/unit/modules/network/vyos/test_vyos_interfaces.py b/tests/unit/modules/network/vyos/test_vyos_interfaces.py index c796145..1595040 100644 --- a/tests/unit/modules/network/vyos/test_vyos_interfaces.py +++ b/tests/unit/modules/network/vyos/test_vyos_interfaces.py @@ -20,13 +20,10 @@ from __future__ import absolute_import, division, print_function __metaclass__ = type +from ansible_collections.vyos.vyos.plugins.modules import vyos_interfaces from ansible_collections.vyos.vyos.tests.unit.compat.mock import patch -from ansible_collections.vyos.vyos.plugins.modules import ( - vyos_interfaces, -) -from ansible_collections.vyos.vyos.tests.unit.modules.utils import ( - set_module_args, -) +from ansible_collections.vyos.vyos.tests.unit.modules.utils import set_module_args + from .vyos_module import TestVyosModule, load_fixture @@ -49,16 +46,12 @@ class TestVyosFirewallInterfacesModule(TestVyosModule): self.mock_get_resource_connection_config = patch( "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.cfg.base.get_resource_connection" ) - self.get_resource_connection_config = ( - self.mock_get_resource_connection_config.start() - ) + self.get_resource_connection_config = self.mock_get_resource_connection_config.start() self.mock_get_resource_connection_facts = patch( "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.facts.facts.get_resource_connection" ) - self.get_resource_connection_facts = ( - self.mock_get_resource_connection_facts.start() - ) + self.get_resource_connection_facts = self.mock_get_resource_connection_facts.start() self.mock_execute_show_command = patch( "ansible_collections.vyos.vyos.plugins.module_utils.network.vyos." diff --git a/tests/unit/modules/network/vyos/test_vyos_logging_global.py b/tests/unit/modules/network/vyos/test_vyos_logging_global.py index 0f72aeb..12da571 100644 --- a/tests/unit/modules/network/vyos/test_vyos_logging_global.py +++ b/tests/unit/modules/network/vyos/test_vyos_logging_global.py @@ -8,11 +8,11 @@ from __future__ import absolute_import, division, print_function __metaclass__ = type from textwrap import dedent -from ansible_collections.vyos.vyos.tests.unit.compat.mock import patch + from ansible_collections.vyos.vyos.plugins.modules import vyos_logging_global -from ansible_collections.vyos.vyos.tests.unit.modules.utils import ( - set_module_args, -) +from ansible_collections.vyos.vyos.tests.unit.compat.mock import patch +from ansible_collections.vyos.vyos.tests.unit.modules.utils import set_module_args + from .vyos_module import TestVyosModule @@ -26,16 +26,12 @@ class TestVyosLoggingGlobalModule(TestVyosModule): self.mock_get_resource_connection_config = patch( "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.rm_base.resource_module_base.get_resource_connection" ) - self.get_resource_connection_config = ( - self.mock_get_resource_connection_config.start() - ) + self.get_resource_connection_config = self.mock_get_resource_connection_config.start() self.mock_get_resource_connection_facts = patch( "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.facts.facts.get_resource_connection" ) - self.get_resource_connection_facts = ( - self.mock_get_resource_connection_facts.start() - ) + self.get_resource_connection_facts = self.mock_get_resource_connection_facts.start() self.mock_execute_show_command = patch( "ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.logging_global.logging_global.Logging_globalFacts.get_logging_data" @@ -300,9 +296,7 @@ class TestVyosLoggingGlobalModule(TestVyosModule): ) playbook = dict( config=dict( - console=dict( - facilities=[dict(facility="local7", severity="emerg")] - ), + console=dict(facilities=[dict(facility="local7", severity="emerg")]), files=[ dict( path="abc", @@ -353,9 +347,7 @@ class TestVyosLoggingGlobalModule(TestVyosModule): set system syslog console facility local6 """ ) - playbook = dict( - config=dict(console=dict(facilities=[dict(facility="local6")])) - ) + playbook = dict(config=dict(console=dict(facilities=[dict(facility="local6")]))) compare_cmds = [] playbook["state"] = "replaced" set_module_args(playbook) @@ -372,9 +364,7 @@ class TestVyosLoggingGlobalModule(TestVyosModule): ) playbook = dict( config=dict( - console=dict( - facilities=[dict(facility="local7", severity="emerg")] - ), + console=dict(facilities=[dict(facility="local7", severity="emerg")]), files=[ dict( path="abc", @@ -412,9 +402,7 @@ class TestVyosLoggingGlobalModule(TestVyosModule): ], users=[ dict(username="vyos"), - dict( - username="paul", facilities=[dict(facility="local7")] - ), + dict(username="paul", facilities=[dict(facility="local7")]), ], ) ) diff --git a/tests/unit/modules/network/vyos/test_vyos_ntp_global.py b/tests/unit/modules/network/vyos/test_vyos_ntp_global.py index 1db6c9b..0a6119b 100644 --- a/tests/unit/modules/network/vyos/test_vyos_ntp_global.py +++ b/tests/unit/modules/network/vyos/test_vyos_ntp_global.py @@ -20,11 +20,10 @@ from __future__ import absolute_import, division, print_function __metaclass__ = type -from ansible_collections.vyos.vyos.tests.unit.compat.mock import patch from ansible_collections.vyos.vyos.plugins.modules import vyos_ntp_global -from ansible_collections.vyos.vyos.tests.unit.modules.utils import ( - set_module_args, -) +from ansible_collections.vyos.vyos.tests.unit.compat.mock import patch +from ansible_collections.vyos.vyos.tests.unit.modules.utils import set_module_args + from .vyos_module import TestVyosModule, load_fixture @@ -38,16 +37,12 @@ class TestVyosNTPModule(TestVyosModule): self.mock_get_resource_connection_config = patch( "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.rm_base.resource_module_base.get_resource_connection" ) - self.get_resource_connection_config = ( - self.mock_get_resource_connection_config.start() - ) + self.get_resource_connection_config = self.mock_get_resource_connection_config.start() self.mock_get_resource_connection_facts = patch( "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.facts.facts.get_resource_connection" ) - self.get_resource_connection_facts = ( - self.mock_get_resource_connection_facts.start() - ) + self.get_resource_connection_facts = self.mock_get_resource_connection_facts.start() self.mock_execute_show_command = patch( "ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.ntp_global.ntp_global.Ntp_globalFacts.get_config" @@ -79,9 +74,7 @@ class TestVyosNTPModule(TestVyosModule): listen_addresses=["10.2.3.1", "10.4.3.1"], servers=[ dict(server="server1"), - dict( - server="server3", options=["noselect", "dynamic"] - ), + dict(server="server3", options=["noselect", "dynamic"]), dict(server="time1.vyos.net"), dict(server="time2.vyos.net"), dict(server="time3.vyos.net"), @@ -183,9 +176,7 @@ class TestVyosNTPModule(TestVyosModule): listen_addresses=["10.2.3.1", "10.4.3.1"], servers=[ dict(server="server1"), - dict( - server="server3", options=["noselect", "dynamic"] - ), + dict(server="server3", options=["noselect", "dynamic"]), dict(server="time1.vyos.net"), dict(server="time2.vyos.net"), dict(server="time3.vyos.net"), @@ -204,9 +195,7 @@ class TestVyosNTPModule(TestVyosModule): listen_addresses=["10.9.9.1"], servers=[ dict(server="server9"), - dict( - server="server6", options=["noselect", "dynamic"] - ), + dict(server="server6", options=["noselect", "dynamic"]), dict(server="time1.vyos.net"), dict(server="time2.vyos.net"), dict(server="time3.vyos.net"), @@ -238,9 +227,7 @@ class TestVyosNTPModule(TestVyosModule): listen_addresses=["10.2.3.1", "10.4.3.1"], servers=[ dict(server="server1"), - dict( - server="server3", options=["noselect", "dynamic"] - ), + dict(server="server3", options=["noselect", "dynamic"]), dict(server="time1.vyos.net"), dict(server="time2.vyos.net"), dict(server="time3.vyos.net"), @@ -259,9 +246,7 @@ class TestVyosNTPModule(TestVyosModule): listen_addresses=["10.7.9.1"], servers=[ dict(server="server79"), - dict( - server="server46", options=["noselect", "dynamic"] - ), + dict(server="server46", options=["noselect", "dynamic"]), dict(server="time1.vyos.net"), dict(server="time2.vyos.net"), dict(server="time3.vyos.net"), diff --git a/tests/unit/modules/network/vyos/test_vyos_ospf_interfaces.py b/tests/unit/modules/network/vyos/test_vyos_ospf_interfaces.py index 20b896d..e8c3241 100644 --- a/tests/unit/modules/network/vyos/test_vyos_ospf_interfaces.py +++ b/tests/unit/modules/network/vyos/test_vyos_ospf_interfaces.py @@ -20,11 +20,10 @@ from __future__ import absolute_import, division, print_function __metaclass__ = type -from ansible_collections.vyos.vyos.tests.unit.compat.mock import patch from ansible_collections.vyos.vyos.plugins.modules import vyos_ospf_interfaces -from ansible_collections.vyos.vyos.tests.unit.modules.utils import ( - set_module_args, -) +from ansible_collections.vyos.vyos.tests.unit.compat.mock import patch +from ansible_collections.vyos.vyos.tests.unit.modules.utils import set_module_args + from .vyos_module import TestVyosModule, load_fixture @@ -37,9 +36,7 @@ class TestVyosOspfInterfacesModule(TestVyosModule): self.mock_get_resource_connection_config = patch( "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.rm_base.resource_module_base.get_resource_connection" ) - self.get_resource_connection_config = ( - self.mock_get_resource_connection_config.start() - ) + self.get_resource_connection_config = self.mock_get_resource_connection_config.start() self.mock_execute_show_command = patch( "ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.ospf_interfaces.ospf_interfaces.Ospf_interfacesFacts.get_device_data" @@ -76,9 +73,7 @@ class TestVyosOspfInterfacesModule(TestVyosModule): dict( afi="ipv4", cost=100, - authentication=dict( - plaintext_password="abcdefg!" - ), + authentication=dict(plaintext_password="abcdefg!"), priority=55, ), dict(afi="ipv6", mtu_ignore=True, instance=20), @@ -173,9 +168,7 @@ class TestVyosOspfInterfacesModule(TestVyosModule): dict( afi="ipv4", cost=100, - authentication=dict( - plaintext_password="abcdefg!" - ), + authentication=dict(plaintext_password="abcdefg!"), priority=55, ), ], @@ -241,9 +234,7 @@ class TestVyosOspfInterfacesModule(TestVyosModule): dict( afi="ipv4", cost=100, - authentication=dict( - plaintext_password="abcdefg!" - ), + authentication=dict(plaintext_password="abcdefg!"), priority=55, ), ], @@ -338,9 +329,7 @@ class TestVyosOspfInterfacesModule(TestVyosModule): dict( afi="ipv4", cost=100, - authentication=dict( - plaintext_password="abcdefg!" - ), + authentication=dict(plaintext_password="abcdefg!"), priority=55, ), dict(afi="ipv6", mtu_ignore=True, instance=20), @@ -370,9 +359,7 @@ class TestVyosOspfInterfacesModule(TestVyosModule): "set interfaces bonding bond2 ipv6 ospfv3 passive", ] result = self.execute_module(changed=False) - self.assertEqual( - sorted(result["rendered"]), sorted(commands), result["rendered"] - ) + self.assertEqual(sorted(result["rendered"]), sorted(commands), result["rendered"]) def test_vyos_ospf_interfaces_parsed(self): commands = [ @@ -437,14 +424,10 @@ class TestVyosOspfInterfacesModule(TestVyosModule): def test_vyos_ospf_interfaces_gathered(self): set_module_args(dict(state="gathered")) - result = self.execute_module( - changed=False, filename="vyos_ospf_interfaces_config.cfg" - ) + result = self.execute_module(changed=False, filename="vyos_ospf_interfaces_config.cfg") gathered_list = [ { - "address_family": [ - {"afi": "ipv6", "instance": "33", "mtu_ignore": True} - ], + "address_family": [{"afi": "ipv6", "instance": "33", "mtu_ignore": True}], "name": "eth0", }, { diff --git a/tests/unit/modules/network/vyos/test_vyos_ospfv2.py b/tests/unit/modules/network/vyos/test_vyos_ospfv2.py index c3631d9..e036f68 100644 --- a/tests/unit/modules/network/vyos/test_vyos_ospfv2.py +++ b/tests/unit/modules/network/vyos/test_vyos_ospfv2.py @@ -20,11 +20,10 @@ from __future__ import absolute_import, division, print_function __metaclass__ = type -from ansible_collections.vyos.vyos.tests.unit.compat.mock import patch from ansible_collections.vyos.vyos.plugins.modules import vyos_ospfv2 -from ansible_collections.vyos.vyos.tests.unit.modules.utils import ( - set_module_args, -) +from ansible_collections.vyos.vyos.tests.unit.compat.mock import patch +from ansible_collections.vyos.vyos.tests.unit.modules.utils import set_module_args + from .vyos_module import TestVyosModule, load_fixture @@ -47,16 +46,12 @@ class TestVyosOspfv2Module(TestVyosModule): self.mock_get_resource_connection_config = patch( "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.cfg.base.get_resource_connection" ) - self.get_resource_connection_config = ( - self.mock_get_resource_connection_config.start() - ) + self.get_resource_connection_config = self.mock_get_resource_connection_config.start() self.mock_get_resource_connection_facts = patch( "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.facts.facts.get_resource_connection" ) - self.get_resource_connection_facts = ( - self.mock_get_resource_connection_facts.start() - ) + self.get_resource_connection_facts = self.mock_get_resource_connection_facts.start() self.mock_execute_show_command = patch( "ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.ospfv2.ospfv2.Ospfv2Facts.get_device_data" @@ -271,9 +266,7 @@ class TestVyosOspfv2Module(TestVyosModule): def test_vyos_ospfv2_gathered(self): set_module_args(dict(state="gathered")) - result = self.execute_module( - changed=False, filename="vyos_ospfv2_config.cfg" - ) + result = self.execute_module(changed=False, filename="vyos_ospfv2_config.cfg") gather_dict = { "areas": [ { @@ -378,9 +371,7 @@ set protocols ospf redistribute bgp metric-type '2'""" "router_id": "192.0.1.1", }, "passive_interface": ["eth2", "eth1"], - "redistribute": [ - {"metric": 10, "metric_type": 2, "route_type": "bgp"} - ], + "redistribute": [{"metric": 10, "metric_type": 2, "route_type": "bgp"}], } self.assertEqual(sorted(parsed_list), sorted(result["parsed"])) @@ -430,6 +421,4 @@ set protocols ospf redistribute bgp metric-type '2'""" "set protocols ospf area 4 network 192.0.2.0/24", ] result = self.execute_module(changed=False) - self.assertEqual( - sorted(result["rendered"]), sorted(commands), result["rendered"] - ) + self.assertEqual(sorted(result["rendered"]), sorted(commands), result["rendered"]) diff --git a/tests/unit/modules/network/vyos/test_vyos_ospfv3.py b/tests/unit/modules/network/vyos/test_vyos_ospfv3.py index ec47461..d04b7f7 100644 --- a/tests/unit/modules/network/vyos/test_vyos_ospfv3.py +++ b/tests/unit/modules/network/vyos/test_vyos_ospfv3.py @@ -20,11 +20,10 @@ from __future__ import absolute_import, division, print_function __metaclass__ = type -from ansible_collections.vyos.vyos.tests.unit.compat.mock import patch from ansible_collections.vyos.vyos.plugins.modules import vyos_ospfv3 -from ansible_collections.vyos.vyos.tests.unit.modules.utils import ( - set_module_args, -) +from ansible_collections.vyos.vyos.tests.unit.compat.mock import patch +from ansible_collections.vyos.vyos.tests.unit.modules.utils import set_module_args + from .vyos_module import TestVyosModule, load_fixture @@ -47,16 +46,12 @@ class TestVyosOspfv3Module(TestVyosModule): self.mock_get_resource_connection_config = patch( "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.cfg.base.get_resource_connection" ) - self.get_resource_connection_config = ( - self.mock_get_resource_connection_config.start() - ) + self.get_resource_connection_config = self.mock_get_resource_connection_config.start() self.mock_get_resource_connection_facts = patch( "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.facts.facts.get_resource_connection" ) - self.get_resource_connection_facts = ( - self.mock_get_resource_connection_facts.start() - ) + self.get_resource_connection_facts = self.mock_get_resource_connection_facts.start() self.mock_execute_show_command = patch( "ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.ospfv3.ospfv3.Ospfv3Facts.get_device_data" @@ -254,9 +249,7 @@ class TestVyosOspfv3Module(TestVyosModule): def test_vyos_ospfv3_gathered(self): set_module_args(dict(state="gathered")) - result = self.execute_module( - changed=False, filename="vyos_ospfv3_config.cfg" - ) + result = self.execute_module(changed=False, filename="vyos_ospfv3_config.cfg") gather_dict = { "areas": [ { @@ -343,6 +336,4 @@ set protocols ospfv3 redistribute 'bgp'""" "set protocols ospfv3 area 3 range 2001:db40::/32", ] result = self.execute_module(changed=False) - self.assertEqual( - sorted(result["rendered"]), sorted(commands), result["rendered"] - ) + self.assertEqual(sorted(result["rendered"]), sorted(commands), result["rendered"]) diff --git a/tests/unit/modules/network/vyos/test_vyos_ping.py b/tests/unit/modules/network/vyos/test_vyos_ping.py index 9b79ce6..ea8d259 100644 --- a/tests/unit/modules/network/vyos/test_vyos_ping.py +++ b/tests/unit/modules/network/vyos/test_vyos_ping.py @@ -20,11 +20,10 @@ from __future__ import absolute_import, division, print_function __metaclass__ = type -from ansible_collections.vyos.vyos.tests.unit.compat.mock import patch from ansible_collections.vyos.vyos.plugins.modules import vyos_ping -from ansible_collections.vyos.vyos.tests.unit.modules.utils import ( - set_module_args, -) +from ansible_collections.vyos.vyos.tests.unit.compat.mock import patch +from ansible_collections.vyos.vyos.tests.unit.modules.utils import set_module_args + from .vyos_module import TestVyosModule, load_fixture diff --git a/tests/unit/modules/network/vyos/test_vyos_prefix_lists.py b/tests/unit/modules/network/vyos/test_vyos_prefix_lists.py index d1e1a8c..e8d044d 100644 --- a/tests/unit/modules/network/vyos/test_vyos_prefix_lists.py +++ b/tests/unit/modules/network/vyos/test_vyos_prefix_lists.py @@ -21,11 +21,11 @@ from __future__ import absolute_import, division, print_function __metaclass__ = type from textwrap import dedent -from ansible_collections.vyos.vyos.tests.unit.compat.mock import patch + from ansible_collections.vyos.vyos.plugins.modules import vyos_prefix_lists -from ansible_collections.vyos.vyos.tests.unit.modules.utils import ( - set_module_args, -) +from ansible_collections.vyos.vyos.tests.unit.compat.mock import patch +from ansible_collections.vyos.vyos.tests.unit.modules.utils import set_module_args + from .vyos_module import TestVyosModule @@ -50,9 +50,7 @@ class TestVyosPrefixListsModule(TestVyosModule): self.mock_get_resource_connection = patch( "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.rm_base.resource_module_base.get_resource_connection" ) - self.get_resource_connection = ( - self.mock_get_resource_connection.start() - ) + self.get_resource_connection = self.mock_get_resource_connection.start() self.mock_get_config = patch( "ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.prefix_lists.prefix_lists.Prefix_listsFacts.get_config" diff --git a/tests/unit/modules/network/vyos/test_vyos_route_maps.py b/tests/unit/modules/network/vyos/test_vyos_route_maps.py index d11e5ab..6b50ad5 100644 --- a/tests/unit/modules/network/vyos/test_vyos_route_maps.py +++ b/tests/unit/modules/network/vyos/test_vyos_route_maps.py @@ -20,11 +20,10 @@ from __future__ import absolute_import, division, print_function __metaclass__ = type -from ansible_collections.vyos.vyos.tests.unit.compat.mock import patch from ansible_collections.vyos.vyos.plugins.modules import vyos_route_maps -from ansible_collections.vyos.vyos.tests.unit.modules.utils import ( - set_module_args, -) +from ansible_collections.vyos.vyos.tests.unit.compat.mock import patch +from ansible_collections.vyos.vyos.tests.unit.modules.utils import set_module_args + from .vyos_module import TestVyosModule, load_fixture @@ -38,16 +37,12 @@ class TestVyosRouteMapsModule(TestVyosModule): self.mock_get_resource_connection_config = patch( "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.rm_base.resource_module_base.get_resource_connection" ) - self.get_resource_connection_config = ( - self.mock_get_resource_connection_config.start() - ) + self.get_resource_connection_config = self.mock_get_resource_connection_config.start() self.mock_get_resource_connection_facts = patch( "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.facts.facts.get_resource_connection" ) - self.get_resource_connection_facts = ( - self.mock_get_resource_connection_facts.start() - ) + self.get_resource_connection_facts = self.mock_get_resource_connection_facts.start() self.mock_execute_show_command = patch( "ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.route_maps.route_maps.Route_mapsFacts.get_config" diff --git a/tests/unit/modules/network/vyos/test_vyos_snmp_server.py b/tests/unit/modules/network/vyos/test_vyos_snmp_server.py index 6cac77d..60a0746 100644 --- a/tests/unit/modules/network/vyos/test_vyos_snmp_server.py +++ b/tests/unit/modules/network/vyos/test_vyos_snmp_server.py @@ -20,11 +20,10 @@ from __future__ import absolute_import, division, print_function __metaclass__ = type -from ansible_collections.vyos.vyos.tests.unit.compat.mock import patch from ansible_collections.vyos.vyos.plugins.modules import vyos_snmp_server -from ansible_collections.vyos.vyos.tests.unit.modules.utils import ( - set_module_args, -) +from ansible_collections.vyos.vyos.tests.unit.compat.mock import patch +from ansible_collections.vyos.vyos.tests.unit.modules.utils import set_module_args + from .vyos_module import TestVyosModule, load_fixture @@ -38,16 +37,12 @@ class TestVyosSnmpServerModule(TestVyosModule): self.mock_get_resource_connection_config = patch( "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.rm_base.resource_module_base.get_resource_connection" ) - self.get_resource_connection_config = ( - self.mock_get_resource_connection_config.start() - ) + self.get_resource_connection_config = self.mock_get_resource_connection_config.start() self.mock_get_resource_connection_facts = patch( "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.facts.facts.get_resource_connection" ) - self.get_resource_connection_facts = ( - self.mock_get_resource_connection_facts.start() - ) + self.get_resource_connection_facts = self.mock_get_resource_connection_facts.start() self.mock_execute_show_command = patch( "ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.snmp_server.snmp_server.Snmp_serverFacts.get_config" @@ -89,21 +84,13 @@ class TestVyosSnmpServerModule(TestVyosModule): users=[ dict( user="admin_user", - authentication=dict( - type="sha", plaintext_key="abc1234567" - ), - privacy=dict( - type="aes", plaintext_key="abc1234567" - ), + authentication=dict(type="sha", plaintext_key="abc1234567"), + privacy=dict(type="aes", plaintext_key="abc1234567"), ), dict( user="guest_user", - authentication=dict( - type="sha", plaintext_key="opq1234567" - ), - privacy=dict( - type="aes", plaintext_key="opq1234567" - ), + authentication=dict(type="sha", plaintext_key="opq1234567"), + privacy=dict(type="aes", plaintext_key="opq1234567"), ), ] ), @@ -131,21 +118,13 @@ class TestVyosSnmpServerModule(TestVyosModule): users=[ dict( user="admin_user", - authentication=dict( - type="sha", plaintext_key="abc1234567" - ), - privacy=dict( - type="aes", plaintext_key="abc1234567" - ), + authentication=dict(type="sha", plaintext_key="abc1234567"), + privacy=dict(type="aes", plaintext_key="abc1234567"), ), dict( user="guest_user", - authentication=dict( - type="sha", plaintext_key="opq1234567" - ), - privacy=dict( - type="aes", plaintext_key="opq1234567" - ), + authentication=dict(type="sha", plaintext_key="opq1234567"), + privacy=dict(type="aes", plaintext_key="opq1234567"), ), ] ), @@ -173,21 +152,13 @@ class TestVyosSnmpServerModule(TestVyosModule): users=[ dict( user="admin_user", - authentication=dict( - type="sha", plaintext_key="abc1234567" - ), - privacy=dict( - type="aes", plaintext_key="abc1234567" - ), + authentication=dict(type="sha", plaintext_key="abc1234567"), + privacy=dict(type="aes", plaintext_key="abc1234567"), ), dict( user="guest_user", - authentication=dict( - type="sha", plaintext_key="opq1234567" - ), - privacy=dict( - type="aes", plaintext_key="opq1234567" - ), + authentication=dict(type="sha", plaintext_key="opq1234567"), + privacy=dict(type="aes", plaintext_key="opq1234567"), ), ] ), @@ -213,9 +184,7 @@ class TestVyosSnmpServerModule(TestVyosModule): description="snmp_config", smux_peer="peer1", trap_source="1.1.1.1", - trap_target=dict( - address="10.10.1.1", community="switches", port="80" - ), + trap_target=dict(address="10.10.1.1", community="switches", port="80"), snmp_v3=dict( engine_id="34", groups=[ @@ -229,12 +198,8 @@ class TestVyosSnmpServerModule(TestVyosModule): trap_targets=[ dict( address="20.12.1.1", - authentication=dict( - type="sha", plaintext_key="abc1234567" - ), - privacy=dict( - type="aes", plaintext_key="abc1234567" - ), + authentication=dict(type="sha", plaintext_key="abc1234567"), + privacy=dict(type="aes", plaintext_key="abc1234567"), ), ], ), @@ -275,9 +240,7 @@ class TestVyosSnmpServerModule(TestVyosModule): description="snmp_config", smux_peer="peer1", trap_source="1.1.1.1", - trap_target=dict( - address="10.10.1.1", community="switches", port="80" - ), + trap_target=dict(address="10.10.1.1", community="switches", port="80"), snmp_v3=dict( engine_id="34", groups=[ @@ -291,12 +254,8 @@ class TestVyosSnmpServerModule(TestVyosModule): trap_targets=[ dict( address="20.12.1.1", - authentication=dict( - type="sha", plaintext_key="abc1234567" - ), - privacy=dict( - type="aes", plaintext_key="abc1234567" - ), + authentication=dict(type="sha", plaintext_key="abc1234567"), + privacy=dict(type="aes", plaintext_key="abc1234567"), ), ], ), @@ -350,9 +309,7 @@ class TestVyosSnmpServerModule(TestVyosModule): description="snmp_config", smux_peer="peer1", trap_source="1.1.1.1", - trap_target=dict( - address="10.10.1.1", community="switches", port="80" - ), + trap_target=dict(address="10.10.1.1", community="switches", port="80"), snmp_v3=dict( engine_id="34", groups=[ @@ -366,12 +323,8 @@ class TestVyosSnmpServerModule(TestVyosModule): trap_targets=[ dict( address="20.12.1.1", - authentication=dict( - type="sha", plaintext_key="abc1234567" - ), - privacy=dict( - type="aes", plaintext_key="abc1234567" - ), + authentication=dict(type="sha", plaintext_key="abc1234567"), + privacy=dict(type="aes", plaintext_key="abc1234567"), ), ], ), @@ -434,9 +387,7 @@ class TestVyosSnmpServerModule(TestVyosModule): description="snmp_config", smux_peer="peer1", trap_source="1.1.1.1", - trap_target=dict( - address="10.10.1.1", community="switches", port="80" - ), + trap_target=dict(address="10.10.1.1", community="switches", port="80"), snmp_v3=dict( engine_id="34", groups=[ @@ -450,12 +401,8 @@ class TestVyosSnmpServerModule(TestVyosModule): trap_targets=[ dict( address="20.12.1.1", - authentication=dict( - type="sha", plaintext_key="abc1234567" - ), - privacy=dict( - type="aes", plaintext_key="abc1234567" - ), + authentication=dict(type="sha", plaintext_key="abc1234567"), + privacy=dict(type="aes", plaintext_key="abc1234567"), ), ], ), diff --git a/tests/unit/modules/network/vyos/test_vyos_static_routes.py b/tests/unit/modules/network/vyos/test_vyos_static_routes.py index 5577d9c..df25992 100644 --- a/tests/unit/modules/network/vyos/test_vyos_static_routes.py +++ b/tests/unit/modules/network/vyos/test_vyos_static_routes.py @@ -20,11 +20,10 @@ from __future__ import absolute_import, division, print_function __metaclass__ = type -from ansible_collections.vyos.vyos.tests.unit.compat.mock import patch from ansible_collections.vyos.vyos.plugins.modules import vyos_static_routes -from ansible_collections.vyos.vyos.tests.unit.modules.utils import ( - set_module_args, -) +from ansible_collections.vyos.vyos.tests.unit.compat.mock import patch +from ansible_collections.vyos.vyos.tests.unit.modules.utils import set_module_args + from .vyos_module import TestVyosModule, load_fixture @@ -47,16 +46,12 @@ class TestVyosStaticRoutesModule(TestVyosModule): self.mock_get_resource_connection_config = patch( "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.cfg.base.get_resource_connection" ) - self.get_resource_connection_config = ( - self.mock_get_resource_connection_config.start() - ) + self.get_resource_connection_config = self.mock_get_resource_connection_config.start() self.mock_get_resource_connection_facts = patch( "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.facts.facts.get_resource_connection" ) - self.get_resource_connection_facts = ( - self.mock_get_resource_connection_facts.start() - ) + self.get_resource_connection_facts = self.mock_get_resource_connection_facts.start() self.mock_execute_show_command = patch( "ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.static_routes.static_routes.Static_routesFacts.get_device_data" @@ -128,12 +123,8 @@ class TestVyosStaticRoutesModule(TestVyosModule): dict( dest="192.0.2.32/28", next_hops=[ - dict( - forward_router_address="192.0.2.9" - ), - dict( - forward_router_address="192.0.2.10" - ), + dict(forward_router_address="192.0.2.9"), + dict(forward_router_address="192.0.2.10"), ], ) ], @@ -197,12 +188,8 @@ class TestVyosStaticRoutesModule(TestVyosModule): dict( dest="192.0.2.32/28", next_hops=[ - dict( - forward_router_address="192.0.2.9" - ), - dict( - forward_router_address="192.0.2.10" - ), + dict(forward_router_address="192.0.2.9"), + dict(forward_router_address="192.0.2.10"), ], ) ], @@ -228,12 +215,8 @@ class TestVyosStaticRoutesModule(TestVyosModule): dict( dest="192.0.2.48/28", next_hops=[ - dict( - forward_router_address="192.0.2.9" - ), - dict( - forward_router_address="192.0.2.10" - ), + dict(forward_router_address="192.0.2.9"), + dict(forward_router_address="192.0.2.10"), ], ) ], @@ -264,12 +247,8 @@ class TestVyosStaticRoutesModule(TestVyosModule): dict( dest="192.0.2.32/28", next_hops=[ - dict( - forward_router_address="192.0.2.9" - ), - dict( - forward_router_address="192.0.2.10" - ), + dict(forward_router_address="192.0.2.9"), + dict(forward_router_address="192.0.2.10"), ], ) ], diff --git a/tests/unit/modules/network/vyos/test_vyos_system.py b/tests/unit/modules/network/vyos/test_vyos_system.py index b763d9c..3665720 100644 --- a/tests/unit/modules/network/vyos/test_vyos_system.py +++ b/tests/unit/modules/network/vyos/test_vyos_system.py @@ -20,11 +20,10 @@ from __future__ import absolute_import, division, print_function __metaclass__ = type -from ansible_collections.vyos.vyos.tests.unit.compat.mock import patch from ansible_collections.vyos.vyos.plugins.modules import vyos_system -from ansible_collections.vyos.vyos.tests.unit.modules.utils import ( - set_module_args, -) +from ansible_collections.vyos.vyos.tests.unit.compat.mock import patch +from ansible_collections.vyos.vyos.tests.unit.modules.utils import set_module_args + from .vyos_module import TestVyosModule, load_fixture @@ -80,9 +79,7 @@ class TestVyosSystemModule(TestVyosModule): self.execute_module(changed=True, commands=commands) def test_vyos_system_domain_search(self): - set_module_args( - dict(domain_search=["foo.example.com", "bar.example.com"]) - ) + set_module_args(dict(domain_search=["foo.example.com", "bar.example.com"])) commands = [ "set system domain-search domain 'foo.example.com'", "set system domain-search domain 'bar.example.com'", diff --git a/tests/unit/modules/network/vyos/test_vyos_user.py b/tests/unit/modules/network/vyos/test_vyos_user.py index 427036b..5a1f69f 100644 --- a/tests/unit/modules/network/vyos/test_vyos_user.py +++ b/tests/unit/modules/network/vyos/test_vyos_user.py @@ -20,11 +20,10 @@ from __future__ import absolute_import, division, print_function __metaclass__ = type -from ansible_collections.vyos.vyos.tests.unit.compat.mock import patch from ansible_collections.vyos.vyos.plugins.modules import vyos_user -from ansible_collections.vyos.vyos.tests.unit.modules.utils import ( - set_module_args, -) +from ansible_collections.vyos.vyos.tests.unit.compat.mock import patch +from ansible_collections.vyos.vyos.tests.unit.modules.utils import set_module_args + from .vyos_module import TestVyosModule, load_fixture @@ -59,17 +58,13 @@ class TestVyosUserModule(TestVyosModule): result = self.execute_module(changed=True) self.assertEqual( result["commands"], - [ - "set system login user ansible authentication plaintext-password test" - ], + ["set system login user ansible authentication plaintext-password test"], ) def test_vyos_user_delete(self): set_module_args(dict(name="ansible", state="absent")) result = self.execute_module(changed=True) - self.assertEqual( - result["commands"], ["delete system login user ansible"] - ) + self.assertEqual(result["commands"], ["delete system login user ansible"]) def test_vyos_user_level(self): set_module_args(dict(name="ansible", level="operator")) @@ -107,9 +102,7 @@ class TestVyosUserModule(TestVyosModule): result = self.execute_module(changed=True) self.assertEqual( result["commands"], - [ - "set system login user test authentication plaintext-password test" - ], + ["set system login user test authentication plaintext-password test"], ) def test_vyos_user_update_password_on_create_ok(self): @@ -133,7 +126,5 @@ class TestVyosUserModule(TestVyosModule): result = self.execute_module(changed=True) self.assertEqual( result["commands"], - [ - "set system login user ansible authentication plaintext-password test" - ], + ["set system login user ansible authentication plaintext-password test"], ) diff --git a/tests/unit/modules/network/vyos/vyos_module.py b/tests/unit/modules/network/vyos/vyos_module.py index cb7874f..98a422d 100644 --- a/tests/unit/modules/network/vyos/vyos_module.py +++ b/tests/unit/modules/network/vyos/vyos_module.py @@ -20,8 +20,8 @@ from __future__ import absolute_import, division, print_function __metaclass__ = type -import os import json +import os from ansible_collections.vyos.vyos.tests.unit.modules.utils import ( AnsibleExitJson, @@ -29,7 +29,6 @@ from ansible_collections.vyos.vyos.tests.unit.modules.utils import ( ModuleTestCase, ) - fixture_path = os.path.join(os.path.dirname(__file__), "fixtures") fixture_data = {} @@ -83,9 +82,7 @@ class TestVyosModule(ModuleTestCase): result["commands"], ) else: - self.assertEqual( - commands, result["commands"], result["commands"] - ) + self.assertEqual(commands, result["commands"], result["commands"]) return result diff --git a/tests/unit/modules/utils.py b/tests/unit/modules/utils.py index 90023ce..779c68f 100644 --- a/tests/unit/modules/utils.py +++ b/tests/unit/modules/utils.py @@ -3,11 +3,12 @@ from __future__ import absolute_import, division, print_function __metaclass__ = type import json -from ansible_collections.vyos.vyos.tests.unit.compat import unittest -from ansible_collections.vyos.vyos.tests.unit.compat.mock import patch from ansible.module_utils import basic from ansible.module_utils._text import to_bytes +from ansible_collections.vyos.vyos.tests.unit.compat import unittest +from ansible_collections.vyos.vyos.tests.unit.compat.mock import patch + def set_module_args(args): if "_ansible_remote_tmp" not in args: |