diff options
Diffstat (limited to 'tests')
20 files changed, 924 insertions, 0 deletions
diff --git a/tests/integration/targets/vyos_logging_global/defaults/main.yaml b/tests/integration/targets/vyos_logging_global/defaults/main.yaml new file mode 100644 index 0000000..852a6be --- /dev/null +++ b/tests/integration/targets/vyos_logging_global/defaults/main.yaml @@ -0,0 +1,3 @@ +--- +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 new file mode 100644 index 0000000..91da2a7 --- /dev/null +++ b/tests/integration/targets/vyos_logging_global/meta/main.yaml @@ -0,0 +1,2 @@ +--- +... diff --git a/tests/integration/targets/vyos_logging_global/tasks/cli.yaml b/tests/integration/targets/vyos_logging_global/tasks/cli.yaml new file mode 100644 index 0000000..93eb2fe --- /dev/null +++ b/tests/integration/targets/vyos_logging_global/tasks/cli.yaml @@ -0,0 +1,19 @@ +--- +- name: Collect all cli test cases + find: + paths: '{{ role_path }}/tests/cli' + patterns: '{{ testcase }}.yaml' + use_regex: true + register: test_cases + delegate_to: localhost + +- name: Set test_items + 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 }}' + vars: + 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_logging_global/tasks/main.yaml b/tests/integration/targets/vyos_logging_global/tasks/main.yaml new file mode 100644 index 0000000..b957d2f --- /dev/null +++ b/tests/integration/targets/vyos_logging_global/tasks/main.yaml @@ -0,0 +1,4 @@ +--- +- include: cli.yaml + tags: + - network_cli diff --git a/tests/integration/targets/vyos_logging_global/tests/cli/_parsed.cfg b/tests/integration/targets/vyos_logging_global/tests/cli/_parsed.cfg new file mode 100644 index 0000000..fb2c3dc --- /dev/null +++ b/tests/integration/targets/vyos_logging_global/tests/cli/_parsed.cfg @@ -0,0 +1,3 @@ +set system syslog console facility news level 'debug' +set system syslog file def facility local7 level 'emerg' +set system syslog global facility local7 level 'debug' diff --git a/tests/integration/targets/vyos_logging_global/tests/cli/_populate.yaml b/tests/integration/targets/vyos_logging_global/tests/cli/_populate.yaml new file mode 100644 index 0000000..2f3828f --- /dev/null +++ b/tests/integration/targets/vyos_logging_global/tests/cli/_populate.yaml @@ -0,0 +1,53 @@ +--- +- name: POPULATE Apply the provided configuration + register: result + vyos.vyos.vyos_logging_global: + config: + console: + facilities: + - facility: all + - facility: local7 + severity: err + - facility: news + severity: debug + files: + - path: def + archive: + file_num: 2 + facilities: + - facility: local6 + severity: emerg + - facility: local7 + severity: emerg + hosts: + - hostname: 172.16.2.15 + facilities: + - facility: all + severity: all + - facility: all + protocol: udp + - hostname: 172.16.2.12 + facilities: + - facility: all + protocol: udp + users: + - username: vyos + facilities: + - facility: local7 + severity: debug + - facility: local6 + severity: alert + - username: paul + facilities: + - facility: local7 + severity: err + global_params: + archive: + file_num: 2 + size: 111 + facilities: + - facility: cron + severity: debug + - facility: local7 + severity: debug + state: merged diff --git a/tests/integration/targets/vyos_logging_global/tests/cli/_remove_config.yaml b/tests/integration/targets/vyos_logging_global/tests/cli/_remove_config.yaml new file mode 100644 index 0000000..1c2187b --- /dev/null +++ b/tests/integration/targets/vyos_logging_global/tests/cli/_remove_config.yaml @@ -0,0 +1,4 @@ +--- +- name: delete the provided configuration + vyos.vyos.vyos_logging_global: + state: deleted diff --git a/tests/integration/targets/vyos_logging_global/tests/cli/deleted.yaml b/tests/integration/targets/vyos_logging_global/tests/cli/deleted.yaml new file mode 100644 index 0000000..2a0a355 --- /dev/null +++ b/tests/integration/targets/vyos_logging_global/tests/cli/deleted.yaml @@ -0,0 +1,22 @@ +--- +- debug: + msg: Start Deleted integration state for vyos_logging ansible_connection={{ + ansible_connection }} + +- include_tasks: _remove_config.yaml +- include_tasks: _populate.yaml + +- block: + - name: TEST - [deleted] Remove all configuration + vyos.vyos.vyos_logging_global: + state: deleted + register: result + + - name: TEST - [deleted] Assert that correct set of commands were generated + assert: + that: + - "{{ deleted['commands'] | symmetric_difference(result['commands']) |\ + \ length == 0 }}" + + always: + - include_tasks: _remove_config.yaml 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 new file mode 100644 index 0000000..f70fff1 --- /dev/null +++ b/tests/integration/targets/vyos_logging_global/tests/cli/empty_config.yaml @@ -0,0 +1,60 @@ +--- +- debug: + msg: START vyos_logging_global empty_config integration tests on connection={{ + ansible_connection }} + +- name: Merged with empty config should give appropriate error message + register: result + ignore_errors: true + vyos.vyos.vyos_logging_global: + config: + state: merged + +- assert: + that: + - result.msg == 'value of config parameter must not be empty for state merged' + +- name: Replaced with empty config should give appropriate error message + register: result + ignore_errors: true + vyos.vyos.vyos_logging_global: + config: + state: replaced + +- assert: + that: + - result.msg == 'value of config parameter must not be empty for state replaced' + +- name: Overridden with empty config should give appropriate error message + register: result + ignore_errors: true + vyos.vyos.vyos_logging_global: + config: + state: overridden + +- assert: + that: + - result.msg == 'value of config parameter must not be empty for state overridden' + +- name: Parsed with empty running_config should give appropriate error message + register: result + ignore_errors: true + vyos.vyos.vyos_logging_global: + running_config: + state: parsed + +- assert: + that: + - result.msg == 'value of running_config parameter must not be empty for state + parsed' + +- name: Rendered with empty config should give appropriate error message + register: result + ignore_errors: true + vyos.vyos.vyos_logging_global: + config: + state: rendered + +- assert: + that: + - result.msg == 'value of config parameter must not be empty for state rendered' diff --git a/tests/integration/targets/vyos_logging_global/tests/cli/gathered.yaml b/tests/integration/targets/vyos_logging_global/tests/cli/gathered.yaml new file mode 100644 index 0000000..af1fa52 --- /dev/null +++ b/tests/integration/targets/vyos_logging_global/tests/cli/gathered.yaml @@ -0,0 +1,22 @@ +--- +- debug: + msg: START vyos_logging_global gathered integration tests on connection={{ + ansible_connection }} + +- include_tasks: _remove_config.yaml + +- include_tasks: _populate.yaml + +- block: + - name: TEST - [gathered] Gather the provided configuration with the existing running configuration + register: result + vyos.vyos.vyos_logging_global: + config: + state: gathered + + - name: TEST - [gathered] Assert + assert: + that: + - result.changed == false + always: + - include_tasks: _remove_config.yaml diff --git a/tests/integration/targets/vyos_logging_global/tests/cli/merged.yaml b/tests/integration/targets/vyos_logging_global/tests/cli/merged.yaml new file mode 100644 index 0000000..d47d309 --- /dev/null +++ b/tests/integration/targets/vyos_logging_global/tests/cli/merged.yaml @@ -0,0 +1,56 @@ +--- +- debug: + msg: + START vyos_logging_global merged integration tests on connection={{ ansible_connection + }} + +- include_tasks: _remove_config.yaml + +- 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 + config: + console: + facilities: + - facility: all + files: + - path: def + archive: + file_num: 2 + facilities: + - facility: local6 + severity: emerg + hosts: + - hostname: 172.16.2.15 + facilities: + - facility: all + severity: all + users: + - username: vyos + facilities: + - facility: local7 + severity: debug + global_params: + archive: + file_num: 2 + size: 111 + facilities: + - facility: cron + severity: debug + state: merged + + - name: Assert that correct set of commands were generated + assert: + that: + - "{{ merged['commands'] | symmetric_difference(result['commands']) |length\ + \ == 0 }}" + + - name: + Merge the provided configuration with the existing running configuration + (IDEMPOTENT) + register: result + vyos.vyos.vyos_logging_global: *id001 + + always: + - include_tasks: _remove_config.yaml diff --git a/tests/integration/targets/vyos_logging_global/tests/cli/overridden.yaml b/tests/integration/targets/vyos_logging_global/tests/cli/overridden.yaml new file mode 100644 index 0000000..1df1a8d --- /dev/null +++ b/tests/integration/targets/vyos_logging_global/tests/cli/overridden.yaml @@ -0,0 +1,39 @@ +--- +- debug: + msg: START vyos_logging_global overridden integration tests on connection={{ + ansible_connection }} + +- include_tasks: _remove_config.yaml + +- include_tasks: _populate.yaml + +- 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 + config: + console: + facilities: + - facility: all + - facility: local7 + severity: err + - facility: news + severity: debug + global_params: + archive: + file_num: 2 + state: overridden + + - name: Assert that correct commands were generated + assert: + that: + - "{{ overridden['commands'] | symmetric_difference(result['commands'])\ + \ |length == 0 }}" + + - name: Overrides all device configuration with provided configurations (IDEMPOTENT) + register: result + vyos.vyos.vyos_logging_global: *id001 + + always: + + - include_tasks: _remove_config.yaml diff --git a/tests/integration/targets/vyos_logging_global/tests/cli/parsed.yaml b/tests/integration/targets/vyos_logging_global/tests/cli/parsed.yaml new file mode 100644 index 0000000..40a14f6 --- /dev/null +++ b/tests/integration/targets/vyos_logging_global/tests/cli/parsed.yaml @@ -0,0 +1,14 @@ +--- +- debug: + msg: START vyos_logging_global parsed integration tests on connection={{ ansible_connection }} + +- name: TEST - [parsed] Parse the commands for provided configuration + register: result + vyos.vyos.vyos_logging_global: + running_config: "{{ lookup('file', '_parsed.cfg') }}" + state: parsed + +- assert: + that: + - result.changed == false + - parsed['after'] == result.parsed diff --git a/tests/integration/targets/vyos_logging_global/tests/cli/rendered.yaml b/tests/integration/targets/vyos_logging_global/tests/cli/rendered.yaml new file mode 100644 index 0000000..366f889 --- /dev/null +++ b/tests/integration/targets/vyos_logging_global/tests/cli/rendered.yaml @@ -0,0 +1,50 @@ +--- +- debug: + msg: START vyos_logging_global rendered integration tests on connection={{ ansible_connection + }} + +- include_tasks: _remove_config.yaml + +- include_tasks: _populate.yaml + +- block: + + - name: Structure provided configuration into device specific commands + register: result + vyos.vyos.vyos_logging_global: &id001 + config: + console: + facilities: + - facility: all + files: + - path: abc + archive: + size: 125 + hosts: + - hostname: 172.16.2.15 + facilities: + - facility: all + severity: all + users: + - username: vyos + facilities: + - facility: local7 + severity: debug + global_params: + archive: + file_num: 2 + size: 111 + facilities: + - facility: cron + severity: debug + state: rendered + + - name: Assert that correct set of commands were generated + assert: + that: + - "{{ rendered['commands'] | symmetric_difference(result['rendered'])\ + \ |length == 0 }}" + + always: + + - include_tasks: _remove_config.yaml diff --git a/tests/integration/targets/vyos_logging_global/vars/main.yaml b/tests/integration/targets/vyos_logging_global/vars/main.yaml new file mode 100644 index 0000000..ae8b853 --- /dev/null +++ b/tests/integration/targets/vyos_logging_global/vars/main.yaml @@ -0,0 +1,95 @@ +--- +merged: + before: {} + commands: + - set system syslog host 172.16.2.15 facility all level all + - set system syslog console facility all + - set system syslog user vyos facility local7 level debug + - set system syslog global facility cron level debug + - set system syslog global archive file 2 + - set system syslog global archive size 111 + - set system syslog file def archive file 2 + - set system syslog file def facility local6 level emerg + after: + console: + facilities: + - facility: all + files: + - path: def + facilities: + - facility: local6 + severity: emerg + hosts: + - hostname: 172.16.2.15 + facilities: + - facility: all + severity: all + users: + - username: vyos + facilities: + - facility: local7 + severity: debug + global_params: + archive: + size: 111 + facilities: + - facility: cron + severity: debug + +overridden: + commands: + - delete system syslog file def + - delete system syslog global facility cron + - delete system syslog global facility local7 + - delete system syslog host 172.16.2.12 + - delete system syslog host 172.16.2.15 + - delete system syslog user paul + - delete system syslog user vyos + - set system syslog console facility all + - set system syslog global archive file 2 + - delete system syslog global archive size 111 + + after: + console: + facilities: + - facility: all + - facility: local7 + severity: err + - facility: news + severity: debug + files: + - path: Myfile + global_params: + archive: + file_num: 2 + +rendered: + commands: + - set system syslog console facility all + - set system syslog file abc archive size 125 + - set system syslog host 172.16.2.15 facility all level all + - set system syslog user vyos facility local7 level debug + - set system syslog global facility cron level debug + - set system syslog global archive file 2 + - set system syslog global archive size 111 + +deleted: + commands: + - delete system syslog + after: {} + +parsed: + after: + console: + facilities: + - facility: news + severity: debug + files: + - path: def + facilities: + - facility: local7 + severity: emerg + global_params: + facilities: + - facility: local7 + severity: debug diff --git a/tests/sanity/ignore-2.10.txt b/tests/sanity/ignore-2.10.txt index 967e336..d753480 100644 --- a/tests/sanity/ignore-2.10.txt +++ b/tests/sanity/ignore-2.10.txt @@ -7,3 +7,6 @@ plugins/modules/vyos_route_maps.py import-2.6!skip plugins/modules/vyos_prefix_lists.py import-2.6!skip plugins/module_utils/network/vyos/config/prefix_lists/prefix_lists.py import-2.6!skip plugins/module_utils/network/vyos/config/prefix_lists/prefix_lists.py compile-2.6!skip +plugins/modules/vyos_logging_global.py import-2.6!skip +plugins/module_utils/network/vyos/config/logging_global/logging_global.py import-2.6!skip +plugins/module_utils/network/vyos/config/logging_global/logging_global.py compile-2.6!skip
\ No newline at end of file diff --git a/tests/sanity/ignore-2.11.txt b/tests/sanity/ignore-2.11.txt index 967e336..d753480 100644 --- a/tests/sanity/ignore-2.11.txt +++ b/tests/sanity/ignore-2.11.txt @@ -7,3 +7,6 @@ plugins/modules/vyos_route_maps.py import-2.6!skip plugins/modules/vyos_prefix_lists.py import-2.6!skip plugins/module_utils/network/vyos/config/prefix_lists/prefix_lists.py import-2.6!skip plugins/module_utils/network/vyos/config/prefix_lists/prefix_lists.py compile-2.6!skip +plugins/modules/vyos_logging_global.py import-2.6!skip +plugins/module_utils/network/vyos/config/logging_global/logging_global.py import-2.6!skip +plugins/module_utils/network/vyos/config/logging_global/logging_global.py compile-2.6!skip
\ No newline at end of file diff --git a/tests/sanity/ignore-2.12.txt b/tests/sanity/ignore-2.12.txt index 967e336..d753480 100644 --- a/tests/sanity/ignore-2.12.txt +++ b/tests/sanity/ignore-2.12.txt @@ -7,3 +7,6 @@ plugins/modules/vyos_route_maps.py import-2.6!skip plugins/modules/vyos_prefix_lists.py import-2.6!skip plugins/module_utils/network/vyos/config/prefix_lists/prefix_lists.py import-2.6!skip plugins/module_utils/network/vyos/config/prefix_lists/prefix_lists.py compile-2.6!skip +plugins/modules/vyos_logging_global.py import-2.6!skip +plugins/module_utils/network/vyos/config/logging_global/logging_global.py import-2.6!skip +plugins/module_utils/network/vyos/config/logging_global/logging_global.py compile-2.6!skip
\ No newline at end of file diff --git a/tests/sanity/ignore-2.9.txt b/tests/sanity/ignore-2.9.txt index aa3ef3f..83e9150 100644 --- a/tests/sanity/ignore-2.9.txt +++ b/tests/sanity/ignore-2.9.txt @@ -10,6 +10,8 @@ plugins/modules/vyos_lldp.py validate-modules:deprecation-mismatch # 2.9 expects plugins/modules/vyos_lldp.py validate-modules:invalid-documentation # removed_at_date not supported in `deprecated` dict plugins/modules/vyos_lldp_interface.py validate-modules:deprecation-mismatch # 2.9 expects METADATA plugins/modules/vyos_lldp_interface.py validate-modules:invalid-documentation # removed_at_date not supported in `deprecated` dict +plugins/modules/vyos_logging.py validate-modules:deprecation-mismatch # 2.9 expects METADATA +plugins/modules/vyos_logging.py validate-modules:invalid-documentation # removed_at_date not supported in `deprecated` dict plugins/action/vyos.py action-plugin-docs # base class for deprecated network platform modules using `connection: local` plugins/module_utils/network/vyos/config/ospf_interfaces/ospf_interfaces.py compile-2.6!skip plugins/module_utils/network/vyos/config/ospf_interfaces/ospf_interfaces.py import-2.6!skip @@ -19,3 +21,6 @@ plugins/modules/vyos_route_maps.py import-2.6!skip plugins/modules/vyos_prefix_lists.py import-2.6!skip plugins/module_utils/network/vyos/config/prefix_lists/prefix_lists.py import-2.6!skip plugins/module_utils/network/vyos/config/prefix_lists/prefix_lists.py compile-2.6!skip +plugins/modules/vyos_logging_global.py import-2.6!skip +plugins/module_utils/network/vyos/config/logging_global/logging_global.py import-2.6!skip +plugins/module_utils/network/vyos/config/logging_global/logging_global.py compile-2.6!skip
\ No newline at end of file diff --git a/tests/unit/modules/network/vyos/test_vyos_logging_global.py b/tests/unit/modules/network/vyos/test_vyos_logging_global.py new file mode 100644 index 0000000..0f72aeb --- /dev/null +++ b/tests/unit/modules/network/vyos/test_vyos_logging_global.py @@ -0,0 +1,464 @@ +# +# (c) 2021, Ansible by Red Hat, inc +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) +# + +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 .vyos_module import TestVyosModule + + +class TestVyosLoggingGlobalModule(TestVyosModule): + + module = vyos_logging_global + + def setUp(self): + super(TestVyosLoggingGlobalModule, self).setUp() + + 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.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.mock_execute_show_command = patch( + "ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.logging_global.logging_global.Logging_globalFacts.get_logging_data" + ) + + self.execute_show_command = self.mock_execute_show_command.start() + + def tearDown(self): + super(TestVyosLoggingGlobalModule, self).tearDown() + self.mock_get_resource_connection_config.stop() + self.mock_get_resource_connection_facts.stop() + self.mock_execute_show_command.stop() + + def test_vyos_logging_global_merged_idempotent(self): + self.execute_show_command.return_value = dedent( + """\ + set system syslog console facility all + set system syslog console facility local7 level 'err' + set system syslog console facility news level 'debug' + set system syslog file xyz + set system syslog file abc archive size '125' + set system syslog file def archive file '2' + set system syslog file def facility local6 level 'emerg' + set system syslog file def facility local7 level 'emerg' + set system syslog global archive file '2' + set system syslog global archive size '111' + set system syslog global facility cron level 'debug' + set system syslog global facility local7 level 'debug' + set system syslog global marker interval '111' + set system syslog global preserve-fqdn + set system syslog host 10.0.2.12 facility all protocol 'udp' + set system syslog host 10.0.2.15 facility all level 'all' + set system syslog host 10.0.2.15 facility all protocol 'udp' + set system syslog host 10.0.2.15 port '122' + set system syslog user paul facility local7 level 'err' + set system syslog user vyos facility local6 level 'alert' + set system syslog user vyos facility local7 level 'debug' + """ + ) + playbook = dict( + config=dict( + console=dict( + facilities=[ + dict(facility="all"), + dict(facility="local7", severity="err"), + dict(facility="news", severity="debug"), + ] + ), + files=[ + dict(path="xyz"), + dict(path="abc", archive=dict(size=125)), + dict( + path="def", + archive=dict(file_num=2), + facilities=[ + dict(facility="local6", severity="emerg"), + dict(facility="local7", severity="emerg"), + ], + ), + ], + hosts=[ + dict( + hostname="10.0.2.15", + port=122, + facilities=[ + dict(facility="all", severity="all"), + dict(facility="all", protocol="udp"), + ], + ), + dict( + hostname="10.0.2.12", + facilities=[dict(facility="all", protocol="udp")], + ), + ], + users=[ + dict( + username="vyos", + facilities=[ + dict(facility="local7", severity="debug"), + dict(facility="local6", severity="alert"), + ], + ), + dict( + username="paul", + facilities=[dict(facility="local7", severity="err")], + ), + ], + global_params=dict( + archive=dict(size=111, file_num=2), + marker_interval=111, + preserve_fqdn="True", + facilities=[ + dict(facility="cron", severity="debug"), + dict(facility="local7", severity="debug"), + ], + ), + ) + ) + compare_cmds = [] + playbook["state"] = "merged" + set_module_args(playbook) + result = self.execute_module() + + self.maxDiff = None + self.assertEqual(sorted(result["commands"]), sorted(compare_cmds)) + + def test_vyos_logging_global_merged(self): + self.execute_show_command.return_value = dedent( + """\ + """ + ) + playbook = dict( + config=dict( + console=dict( + facilities=[ + dict(facility="all"), + dict(facility="local7", severity="err"), + dict(facility="news", severity="debug"), + ] + ), + files=[ + dict(path="xyz"), + dict(path="abc", archive=dict(size=125)), + dict( + path="def", + archive=dict(file_num=2), + facilities=[ + dict(facility="local6", severity="emerg"), + dict(facility="local7", severity="emerg"), + ], + ), + ], + hosts=[ + dict( + hostname="10.0.2.15", + port=122, + facilities=[ + dict(facility="all", severity="all"), + dict(facility="all", protocol="udp"), + ], + ), + dict( + hostname="10.0.2.12", + facilities=[dict(facility="all", protocol="udp")], + ), + ], + users=[ + dict( + username="vyos", + facilities=[ + dict(facility="local7", severity="debug"), + dict(facility="local6", severity="alert"), + ], + ), + dict( + username="paul", + facilities=[dict(facility="local7", severity="err")], + ), + ], + global_params=dict( + archive=dict(size=111, file_num=2), + marker_interval=111, + preserve_fqdn="True", + facilities=[ + dict(facility="cron", severity="debug"), + dict(facility="local7", severity="debug"), + ], + ), + ) + ) + compare_cmds = [ + "set system syslog user paul facility local7 level err", + "set system syslog host 10.0.2.15 facility all protocol udp", + "set system syslog global marker interval 111", + "set system syslog file def archive file 2", + "set system syslog file abc archive size 125", + "set system syslog console facility local7 level err", + "set system syslog host 10.0.2.12 facility all protocol udp", + "set system syslog global facility local7 level debug", + "set system syslog host 10.0.2.15 facility all level all", + "set system syslog global preserve-fqdn", + "set system syslog global archive file 2", + "set system syslog console facility all", + "set system syslog file xyz", + "set system syslog file def facility local7 level emerg", + "set system syslog console facility news level debug", + "set system syslog user vyos facility local6 level alert", + "set system syslog global facility cron level debug", + "set system syslog file def facility local6 level emerg", + "set system syslog global archive size 111", + "set system syslog host 10.0.2.15 port 122", + "set system syslog user vyos facility local7 level debug", + ] + playbook["state"] = "merged" + set_module_args(playbook) + result = self.execute_module(changed=True) + self.maxDiff = None + self.assertEqual(sorted(result["commands"]), sorted(compare_cmds)) + + def test_vyos_logging_global_deleted(self): + self.execute_show_command.return_value = dedent( + """\ + set system syslog console facility all + set system syslog console facility local7 level 'err' + set system syslog console facility news level 'debug' + set system syslog file xyz + set system syslog file abc archive size '125' + set system syslog file def archive file '2' + set system syslog file def facility local6 level 'emerg' + set system syslog file def facility local7 level 'emerg' + set system syslog global archive file '2' + set system syslog global archive size '111' + set system syslog global facility cron level 'debug' + set system syslog global facility local7 level 'debug' + set system syslog global marker interval '111' + set system syslog global preserve-fqdn + set system syslog host 10.0.2.12 facility all protocol 'udp' + set system syslog host 10.0.2.15 facility all level 'all' + set system syslog host 10.0.2.15 facility all protocol 'udp' + set system syslog host 10.0.2.15 port '122' + set system syslog user paul facility local7 level 'err' + set system syslog user vyos facility local6 level 'alert' + set system syslog user vyos facility local7 level 'debug' + """ + ) + playbook = dict(config=dict()) + compare_cmds = ["delete system syslog"] + playbook["state"] = "deleted" + set_module_args(playbook) + result = self.execute_module(changed=True) + self.maxDiff = None + self.assertEqual(sorted(result["commands"]), sorted(compare_cmds)) + + def test_vyos_logging_global_replaced(self): + """ + passing all commands as have and expecting [] commands + """ + self.execute_show_command.return_value = dedent( + """\ + set system syslog console facility all + set system syslog console facility local7 level 'err' + set system syslog console facility news level 'debug' + set system syslog file xyz + set system syslog file abc archive size '125' + set system syslog file def archive file '2' + set system syslog file def facility local6 level 'emerg' + set system syslog file def facility local7 level 'emerg' + set system syslog global archive file '2' + set system syslog global archive size '111' + set system syslog global facility cron level 'debug' + set system syslog global facility local7 level 'debug' + set system syslog global marker interval '111' + set system syslog global preserve-fqdn + set system syslog host 10.0.2.12 facility all protocol 'udp' + set system syslog host 10.0.2.15 facility all level 'all' + set system syslog host 10.0.2.15 facility all protocol 'udp' + set system syslog host 10.0.2.15 port '122' + set system syslog user paul facility local7 level 'err' + set system syslog user vyos facility local6 level 'alert' + set system syslog user vyos facility local7 level 'debug' + """ + ) + playbook = dict( + config=dict( + console=dict( + facilities=[dict(facility="local7", severity="emerg")] + ), + files=[ + dict( + path="abc", + archive=dict(file_num=2), + facilities=[ + dict(facility="local6", severity="err"), + dict(facility="local7", severity="emerg"), + ], + ) + ], + ) + ) + compare_cmds = [ + "delete system syslog console facility all", + "delete system syslog console facility local7", + "delete system syslog console facility news", + "delete system syslog file def", + "delete system syslog file xyz", + "delete system syslog global facility cron", + "delete system syslog global facility local7", + "delete system syslog global archive file 2", + "delete system syslog global archive size 111", + "delete system syslog global marker", + "delete system syslog global preserve-fqdn", + "delete system syslog host 10.0.2.12", + "delete system syslog host 10.0.2.15", + "delete system syslog user paul", + "delete system syslog user vyos", + "set system syslog console facility local7 level emerg", + "set system syslog file abc facility local6 level err", + "set system syslog file abc facility local7 level emerg", + "delete system syslog file abc archive size 125", + "set system syslog file abc archive file 2", + ] + + playbook["state"] = "replaced" + set_module_args(playbook) + result = self.execute_module(changed=True) + self.maxDiff = None + self.assertEqual(sorted(result["commands"]), sorted(compare_cmds)) + + def test_vyos_logging_global_replaced_idempotent(self): + """ + passing all commands as have and expecting [] commands + """ + self.execute_show_command.return_value = dedent( + """\ + set system syslog console facility local6 + """ + ) + playbook = dict( + config=dict(console=dict(facilities=[dict(facility="local6")])) + ) + compare_cmds = [] + playbook["state"] = "replaced" + set_module_args(playbook) + result = self.execute_module(changed=False) + self.maxDiff = None + self.assertEqual(sorted(result["commands"]), sorted(compare_cmds)) + + def test_vyos_logging_global_overridden(self): + self.execute_show_command.return_value = dedent( + """\ + set system syslog console + set system syslog global + """ + ) + playbook = dict( + config=dict( + console=dict( + facilities=[dict(facility="local7", severity="emerg")] + ), + files=[ + dict( + path="abc", + archive=dict(file_num=2), + facilities=[ + dict(facility="local6", severity="err"), + dict(facility="local7", severity="emerg"), + ], + ) + ], + ) + ) + compare_cmds = [ + "set system syslog console facility local7 level emerg", + "set system syslog file abc facility local6 level err", + "set system syslog file abc facility local7 level emerg", + "set system syslog file abc archive file 2", + ] + playbook["state"] = "overridden" + set_module_args(playbook) + result = self.execute_module(changed=True) + print(result["commands"]) + self.maxDiff = None + self.assertEqual(sorted(result["commands"]), sorted(compare_cmds)) + + def test_vyos_logging_global_rendered(self): + playbook = dict( + config=dict( + console=dict(facilities=[dict(facility="all")]), + hosts=[ + dict( + hostname="10.0.2.16", + facilities=[dict(facility="local6")], + ) + ], + users=[ + dict(username="vyos"), + dict( + username="paul", facilities=[dict(facility="local7")] + ), + ], + ) + ) + compare_cmds = [ + "set system syslog console facility all", + "set system syslog host 10.0.2.16 facility local6", + "set system syslog user vyos", + "set system syslog user paul facility local7", + ] + playbook["state"] = "rendered" + set_module_args(playbook) + result = self.execute_module() + self.maxDiff = None + self.assertEqual(sorted(result["rendered"]), sorted(compare_cmds)) + + def test_vyos_logging_global_parsed(self): + set_module_args( + dict( + running_config=dedent( + """\ + set system syslog console facility all + set system syslog file xyz + """ + ), + state="parsed", + ) + ) + parsed = dict( + console=dict(facilities=[dict(facility="all")]), + files=[dict(path="xyz")], + ) + result = self.execute_module(changed=False) + self.maxDiff = None + self.assertEqual(sorted(result["parsed"]), sorted(parsed)) + + def test_vyos_logging_global_gathered(self): + self.execute_show_command.return_value = dedent( + """\ + set system syslog console facility all + """ + ) + set_module_args(dict(state="gathered")) + gathered = dict(console=dict(facilities=[dict(facility="all")])) + result = self.execute_module(changed=False) + + self.maxDiff = None + self.assertEqual(sorted(result["gathered"]), sorted(gathered)) |