diff options
author | Gaige B Paulsen <gaige@cluetrust.com> | 2025-02-12 17:48:57 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-02-12 22:48:57 +0000 |
commit | 6e3fdd41056aa104a49b172de16d0d770afe556c (patch) | |
tree | cda0a964d2ffbce116f8667291cf5489b36e4519 | |
parent | 7a276a73b554a8b107944c6f2a593d49fc9e4389 (diff) | |
download | vyos.vyos-6e3fdd41056aa104a49b172de16d0d770afe556c.tar.gz vyos.vyos-6e3fdd41056aa104a49b172de16d0d770afe556c.zip |
T7153: remove logging module (#393)
-rw-r--r-- | changelogs/fragments/T7153-remove-logging.yaml | 3 | ||||
-rw-r--r-- | docs/vyos.vyos.vyos_logging_module.rst | 348 | ||||
-rw-r--r-- | meta/runtime.yml | 13 | ||||
l--------- | plugins/action/logging.py | 1 | ||||
-rw-r--r-- | plugins/modules/vyos_logging.py | 365 | ||||
-rw-r--r-- | tests/integration/targets/vyos_logging/aliases | 1 | ||||
-rw-r--r-- | tests/integration/targets/vyos_logging/defaults/main.yaml | 3 | ||||
-rw-r--r-- | tests/integration/targets/vyos_logging/tasks/cli.yaml | 21 | ||||
-rw-r--r-- | tests/integration/targets/vyos_logging/tasks/main.yaml | 3 | ||||
-rw-r--r-- | tests/integration/targets/vyos_logging/tests/cli/basic.yaml | 152 |
10 files changed, 9 insertions, 901 deletions
diff --git a/changelogs/fragments/T7153-remove-logging.yaml b/changelogs/fragments/T7153-remove-logging.yaml new file mode 100644 index 00000000..92f5b099 --- /dev/null +++ b/changelogs/fragments/T7153-remove-logging.yaml @@ -0,0 +1,3 @@ +--- +breaking_changes: + - Removed `vyos_logging`. Use `vyos_logging_global` instead. diff --git a/docs/vyos.vyos.vyos_logging_module.rst b/docs/vyos.vyos.vyos_logging_module.rst deleted file mode 100644 index b29b0649..00000000 --- a/docs/vyos.vyos.vyos_logging_module.rst +++ /dev/null @@ -1,348 +0,0 @@ -.. _vyos.vyos.vyos_logging_module: - - -********************** -vyos.vyos.vyos_logging -********************** - -**Manage logging on network devices** - - -Version added: 1.0.0 - -.. contents:: - :local: - :depth: 1 - -DEPRECATED ----------- -:Removed in collection release after 2023-08-01 -:Why: Updated module released with more functionality. -:Alternative: vyos_logging_global - - - -Synopsis --------- -- This module provides declarative management of logging on Vyatta Vyos devices. - - - - -Parameters ----------- - -.. raw:: html - - <table border=0 cellpadding=0 class="documentation-table"> - <tr> - <th colspan="2">Parameter</th> - <th>Choices/<font color="blue">Defaults</font></th> - <th width="100%">Comments</th> - </tr> - <tr> - <td colspan="2"> - <div class="ansibleOptionAnchor" id="parameter-"></div> - <b>aggregate</b> - <a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a> - <div style="font-size: small"> - <span style="color: purple">list</span> - / <span style="color: purple">elements=dictionary</span> - </div> - </td> - <td> - </td> - <td> - <div>List of logging definitions.</div> - </td> - </tr> - <tr> - <td class="elbow-placeholder"></td> - <td colspan="1"> - <div class="ansibleOptionAnchor" id="parameter-"></div> - <b>dest</b> - <a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a> - <div style="font-size: small"> - <span style="color: purple">string</span> - </div> - </td> - <td> - <ul style="margin: 0; padding: 0"><b>Choices:</b> - <li>console</li> - <li>file</li> - <li>global</li> - <li>host</li> - <li>user</li> - </ul> - </td> - <td> - <div>Destination of the logs.</div> - </td> - </tr> - <tr> - <td class="elbow-placeholder"></td> - <td colspan="1"> - <div class="ansibleOptionAnchor" id="parameter-"></div> - <b>facility</b> - <a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a> - <div style="font-size: small"> - <span style="color: purple">string</span> - </div> - </td> - <td> - </td> - <td> - <div>Set logging facility.</div> - </td> - </tr> - <tr> - <td class="elbow-placeholder"></td> - <td colspan="1"> - <div class="ansibleOptionAnchor" id="parameter-"></div> - <b>level</b> - <a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a> - <div style="font-size: small"> - <span style="color: purple">string</span> - </div> - </td> - <td> - </td> - <td> - <div>Set logging severity levels.</div> - </td> - </tr> - <tr> - <td class="elbow-placeholder"></td> - <td colspan="1"> - <div class="ansibleOptionAnchor" id="parameter-"></div> - <b>name</b> - <a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a> - <div style="font-size: small"> - <span style="color: purple">string</span> - </div> - </td> - <td> - </td> - <td> - <div>If value of <code>dest</code> is <em>file</em> it indicates file-name, for <em>user</em> it indicates username and for <em>host</em> indicates the host name to be notified.</div> - </td> - </tr> - <tr> - <td class="elbow-placeholder"></td> - <td colspan="1"> - <div class="ansibleOptionAnchor" id="parameter-"></div> - <b>state</b> - <a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a> - <div style="font-size: small"> - <span style="color: purple">string</span> - </div> - </td> - <td> - <ul style="margin: 0; padding: 0"><b>Choices:</b> - <li>present</li> - <li>absent</li> - </ul> - </td> - <td> - <div>State of the logging configuration.</div> - </td> - </tr> - - <tr> - <td colspan="2"> - <div class="ansibleOptionAnchor" id="parameter-"></div> - <b>dest</b> - <a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a> - <div style="font-size: small"> - <span style="color: purple">string</span> - </div> - </td> - <td> - <ul style="margin: 0; padding: 0"><b>Choices:</b> - <li>console</li> - <li>file</li> - <li>global</li> - <li>host</li> - <li>user</li> - </ul> - </td> - <td> - <div>Destination of the logs.</div> - </td> - </tr> - <tr> - <td colspan="2"> - <div class="ansibleOptionAnchor" id="parameter-"></div> - <b>facility</b> - <a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a> - <div style="font-size: small"> - <span style="color: purple">string</span> - </div> - </td> - <td> - </td> - <td> - <div>Set logging facility.</div> - </td> - </tr> - <tr> - <td colspan="2"> - <div class="ansibleOptionAnchor" id="parameter-"></div> - <b>level</b> - <a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a> - <div style="font-size: small"> - <span style="color: purple">string</span> - </div> - </td> - <td> - </td> - <td> - <div>Set logging severity levels.</div> - </td> - </tr> - <tr> - <td colspan="2"> - <div class="ansibleOptionAnchor" id="parameter-"></div> - <b>name</b> - <a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a> - <div style="font-size: small"> - <span style="color: purple">string</span> - </div> - </td> - <td> - </td> - <td> - <div>If value of <code>dest</code> is <em>file</em> it indicates file-name, for <em>user</em> it indicates username and for <em>host</em> indicates the host name to be notified.</div> - </td> - </tr> - <tr> - <td colspan="2"> - <div class="ansibleOptionAnchor" id="parameter-"></div> - <b>state</b> - <a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a> - <div style="font-size: small"> - <span style="color: purple">string</span> - </div> - </td> - <td> - <ul style="margin: 0; padding: 0"><b>Choices:</b> - <li><div style="color: blue"><b>present</b> ←</div></li> - <li>absent</li> - </ul> - </td> - <td> - <div>State of the logging configuration.</div> - </td> - </tr> - </table> - <br/> - - -Notes ------ - -.. note:: - - Tested against VyOS 1.1.8 (helium). - - This module works with connection ``ansible.netcommon.network_cli``. See `the VyOS OS Platform Options <../network/user_guide/platform_vyos.html>`_. - - For more information on using Ansible to manage network devices see the :ref:`Ansible Network Guide <network_guide>` - - - -Examples --------- - -.. code-block:: yaml - - - name: configure console logging - vyos.vyos.vyos_logging: - dest: console - facility: all - level: crit - - - name: remove console logging configuration - vyos.vyos.vyos_logging: - dest: console - state: absent - - - name: configure file logging - vyos.vyos.vyos_logging: - dest: file - name: test - facility: local3 - level: err - - - name: Add logging aggregate - vyos.vyos.vyos_logging: - aggregate: - - dest: file - name: test1 - facility: all - level: info - - dest: file - name: test2 - facility: news - level: debug - state: present - - - name: Remove logging aggregate - vyos.vyos.vyos_logging: - aggregate: - - dest: console - facility: all - level: info - - dest: console - facility: daemon - level: warning - - dest: file - name: test2 - facility: news - level: debug - state: absent - - - -Return Values -------------- -Common return values are documented `here <https://docs.ansible.com/ansible/latest/reference_appendices/common_return_values.html#common-return-values>`_, the following are the fields unique to this module: - -.. raw:: html - - <table border=0 cellpadding=0 class="documentation-table"> - <tr> - <th colspan="1">Key</th> - <th>Returned</th> - <th width="100%">Description</th> - </tr> - <tr> - <td colspan="1"> - <div class="ansibleOptionAnchor" id="return-"></div> - <b>commands</b> - <a class="ansibleOptionLink" href="#return-" title="Permalink to this return value"></a> - <div style="font-size: small"> - <span style="color: purple">list</span> - </div> - </td> - <td>always</td> - <td> - <div>The list of configuration mode commands to send to the device</div> - <br/> - <div style="font-size: smaller"><b>Sample:</b></div> - <div style="font-size: smaller; color: blue; word-wrap: break-word; word-break: break-all;">['set system syslog global facility all level notice']</div> - </td> - </tr> - </table> - <br/><br/> - - -Status ------- - - -- This module will be removed in a release after 2023-08-01. *[deprecated]* -- For more information see `DEPRECATED`_. - - -Authors -~~~~~~~ - -- Trishna Guha (@trishnaguha) diff --git a/meta/runtime.yml b/meta/runtime.yml index 1ee4fef2..58899674 100644 --- a/meta/runtime.yml +++ b/meta/runtime.yml @@ -33,14 +33,13 @@ plugin_routing: lldp_interfaces: redirect: vyos.vyos.vyos_lldp_interfaces logging: - redirect: vyos.vyos.vyos_logging - deprecation: - removal_date: "2023-08-01" - warning_text: See the plugin documentation for more details + tombstone: + removal_version: 6.0.0 + warning_text: use vyos_logging_global instead vyos_logging: - deprecation: - removal_date: "2023-08-01" - warning_text: See the plugin documentation for more details + tombstone: + removal_version: 6.0.0 + warning_text: use vyos_logging_global instead logging_global: redirect: vyos.vyos.vyos_logging_global ntp_global: diff --git a/plugins/action/logging.py b/plugins/action/logging.py deleted file mode 120000 index 331a791f..00000000 --- a/plugins/action/logging.py +++ /dev/null @@ -1 +0,0 @@ -vyos.py
\ No newline at end of file diff --git a/plugins/modules/vyos_logging.py b/plugins/modules/vyos_logging.py deleted file mode 100644 index 204e4f91..00000000 --- a/plugins/modules/vyos_logging.py +++ /dev/null @@ -1,365 +0,0 @@ -#!/usr/bin/python -# -*- coding: utf-8 -*- -from __future__ import absolute_import, division, print_function - - -__metaclass__ = type - -# (c) 2017, Ansible by Red Hat, inc -# -# This file is part of Ansible by Red Hat -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Ansible is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with Ansible. If not, see <http://www.gnu.org/licenses/>. -# - - -DOCUMENTATION = """ -module: vyos_logging -author: Trishna Guha (@trishnaguha) -short_description: Manage logging on network devices -description: -- This module provides declarative management of logging on Vyatta Vyos devices. -version_added: 1.0.0 -deprecated: - alternative: vyos_logging_global - why: Updated module released with more functionality. - removed_at_date: '2023-08-01' -notes: -- Tested against VyOS 1.1.8 (helium). -- This module works with connection C(ansible.netcommon.network_cli). See L(the VyOS OS Platform Options,../network/user_guide/platform_vyos.html). -options: - dest: - description: - - Destination of the logs. - type: str - choices: - - console - - file - - global - - host - - user - name: - description: - - If value of C(dest) is I(file) it indicates file-name, for I(user) it indicates - username and for I(host) indicates the host name to be notified. - type: str - facility: - description: - - Set logging facility. - type: str - level: - description: - - Set logging severity levels. - type: str - aggregate: - description: List of logging definitions. - type: list - elements: dict - suboptions: - dest: - description: - - Destination of the logs. - type: str - choices: - - console - - file - - global - - host - - user - name: - description: - - If value of C(dest) is I(file) it indicates file-name, for I(user) it indicates - username and for I(host) indicates the host name to be notified. - type: str - facility: - description: - - Set logging facility. - type: str - level: - description: - - Set logging severity levels. - type: str - state: - description: - - State of the logging configuration. - type: str - choices: - - present - - absent - state: - description: - - State of the logging configuration. - type: str - default: present - choices: - - present - - absent -extends_documentation_fragment: -- vyos.vyos.vyos -""" - -EXAMPLES = """ -- name: configure console logging - vyos.vyos.vyos_logging: - dest: console - facility: all - level: crit - -- name: remove console logging configuration - vyos.vyos.vyos_logging: - dest: console - state: absent - -- name: configure file logging - vyos.vyos.vyos_logging: - dest: file - name: test - facility: local3 - level: err - -- name: Add logging aggregate - vyos.vyos.vyos_logging: - aggregate: - - dest: file - name: test1 - facility: all - level: info - - dest: file - name: test2 - facility: news - level: debug - state: present - -- name: Remove logging aggregate - vyos.vyos.vyos_logging: - aggregate: - - dest: console - facility: all - level: info - - dest: console - facility: daemon - level: warning - - dest: file - name: test2 - facility: news - level: debug - state: absent -""" - -RETURN = """ -commands: - description: The list of configuration mode commands to send to the device - returned: always - type: list - sample: - - set system syslog global facility all level notice -""" - -import re - -from copy import deepcopy - -from ansible.module_utils._text import to_text -from ansible.module_utils.basic import AnsibleModule -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, -) - - -def spec_to_commands(updates, module): - commands = list() - want, have = updates - - for w in want: - dest = w["dest"] - name = w["name"] - facility = w["facility"] - level = w["level"] - state = w["state"] - del w["state"] - - if state == "absent" and w in have: - if w["name"]: - commands.append( - "delete system syslog {0} {1} facility {2} level {3}".format( - dest, - name, - facility, - level, - ), - ) - else: - commands.append( - "delete system syslog {0} facility {1} level {2}".format( - dest, - facility, - level, - ), - ) - elif state == "present" and w not in have: - if w["name"]: - commands.append( - "set system syslog {0} {1} facility {2} level {3}".format( - dest, - name, - facility, - level, - ), - ) - else: - commands.append( - "set system syslog {0} facility {1} level {2}".format( - dest, - facility, - level, - ), - ) - - return commands - - -def config_to_dict(module): - data = get_config(module) - obj = [] - - for line in data.split("\n"): - if line.startswith("set system syslog"): - match = re.search(r"set system syslog (\S+)", line, re.M) - dest = match.group(1) - if dest == "host": - match = re.search(r"host (\S+)", line, re.M) - name = match.group(1) - elif dest == "file": - match = re.search(r"file (\S+)", line, re.M) - name = match.group(1) - elif dest == "user": - match = re.search(r"user (\S+)", line, re.M) - name = match.group(1) - else: - name = None - - if "facility" in line: - match = re.search(r"facility (\S+)", line, re.M) - facility = match.group(1) - if "level" in line: - match = re.search(r"level (\S+)", line, re.M) - level = match.group(1).strip("'") - - obj.append( - { - "dest": dest, - "name": name, - "facility": facility, - "level": level, - }, - ) - - return obj - - -def map_params_to_obj(module, required_if=None): - obj = [] - - aggregate = module.params.get("aggregate") - if aggregate: - for item in aggregate: - for key in item: - if item.get(key) is None: - item[key] = module.params[key] - - try: - check_required_if(required_if, item) - except TypeError as exc: - module.fail_json(to_text(exc)) - obj.append(item.copy()) - - else: - if module.params["dest"] not in ("host", "file", "user"): - module.params["name"] = None - - obj.append( - { - "dest": module.params["dest"], - "name": module.params["name"], - "facility": module.params["facility"], - "level": module.params["level"], - "state": module.params["state"], - }, - ) - - return obj - - -def main(): - """main entry point for module execution""" - element_spec = dict( - dest=dict(type="str", choices=["console", "file", "global", "host", "user"]), - name=dict(type="str"), - facility=dict(type="str"), - level=dict(type="str"), - state=dict(default="present", choices=["present", "absent"]), - ) - - aggregate_spec = deepcopy(element_spec) - - # 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.update(element_spec) - - required_if = [ - ("dest", "host", ["name", "facility", "level"]), - ("dest", "file", ["name", "facility", "level"]), - ("dest", "user", ["name", "facility", "level"]), - ("dest", "console", ["facility", "level"]), - ("dest", "global", ["facility", "level"]), - ] - - module = AnsibleModule( - argument_spec=argument_spec, - required_if=required_if, - supports_check_mode=True, - ) - - warnings = list() - - result = {"changed": False} - if warnings: - result["warnings"] = warnings - want = map_params_to_obj(module, required_if=required_if) - have = config_to_dict(module) - - commands = spec_to_commands((want, have), module) - result["commands"] = commands - - if commands: - commit = not module.check_mode - load_config(module, commands, commit=commit) - result["changed"] = True - - module.exit_json(**result) - - -if __name__ == "__main__": - main() diff --git a/tests/integration/targets/vyos_logging/aliases b/tests/integration/targets/vyos_logging/aliases deleted file mode 100644 index 8071e1f7..00000000 --- a/tests/integration/targets/vyos_logging/aliases +++ /dev/null @@ -1 +0,0 @@ -shippable/vyos/group1 diff --git a/tests/integration/targets/vyos_logging/defaults/main.yaml b/tests/integration/targets/vyos_logging/defaults/main.yaml deleted file mode 100644 index 9ef5ba51..00000000 --- a/tests/integration/targets/vyos_logging/defaults/main.yaml +++ /dev/null @@ -1,3 +0,0 @@ ---- -testcase: "*" -test_items: [] diff --git a/tests/integration/targets/vyos_logging/tasks/cli.yaml b/tests/integration/targets/vyos_logging/tasks/cli.yaml deleted file mode 100644 index 35c23769..00000000 --- a/tests/integration/targets/vyos_logging/tasks/cli.yaml +++ /dev/null @@ -1,21 +0,0 @@ ---- -- name: Collect all cli test cases - ansible.builtin.find: - paths: "{{ role_path }}/tests/cli" - patterns: "{{ testcase }}.yaml" - register: test_cases - delegate_to: localhost - -- name: Set test_items - ansible.builtin.set_fact: - test_items: "{{ test_cases.files | map(attribute='path') | list }}" - -- name: Run test case (connection=ansible.netcommon.network_cli) - ansible.builtin.include_tasks: "{{ test_case_to_run }}" - vars: - ansible_connection: ansible.netcommon.network_cli - with_items: "{{ test_items }}" - loop_control: - loop_var: test_case_to_run - tags: - - network_cli diff --git a/tests/integration/targets/vyos_logging/tasks/main.yaml b/tests/integration/targets/vyos_logging/tasks/main.yaml deleted file mode 100644 index 9201bd65..00000000 --- a/tests/integration/targets/vyos_logging/tasks/main.yaml +++ /dev/null @@ -1,3 +0,0 @@ ---- -- name: Run CLI tests - ansible.builtin.include_tasks: cli.yaml diff --git a/tests/integration/targets/vyos_logging/tests/cli/basic.yaml b/tests/integration/targets/vyos_logging/tests/cli/basic.yaml deleted file mode 100644 index 708623e7..00000000 --- a/tests/integration/targets/vyos_logging/tests/cli/basic.yaml +++ /dev/null @@ -1,152 +0,0 @@ ---- -- debug: msg="START cli/basic.yaml on connection={{ ansible_connection }}" - -- name: set-up logging - register: result - vyos.vyos.vyos_logging: - dest: console - facility: all - level: info - state: present - -- assert: - that: - - result.changed == true - - '"set system syslog console facility all level info" in result.commands' - -- name: set-up logging again (idempotent) - register: result - vyos.vyos.vyos_logging: - dest: console - facility: all - level: info - state: present - -- assert: - that: - - result.changed == false - -- name: file logging - register: result - vyos.vyos.vyos_logging: - dest: file - name: test - facility: all - level: notice - state: present - -- assert: - that: - - result.changed == true - - '"set system syslog file test facility all level notice" in result.commands' - -- name: file logging again (idempotent) - register: result - vyos.vyos.vyos_logging: - dest: file - name: test - facility: all - level: notice - state: present - -- assert: - that: - - result.changed == false - -- name: delete logging - register: result - vyos.vyos.vyos_logging: - dest: file - name: test - facility: all - level: notice - state: absent - -- assert: - that: - - result.changed == true - - '"delete system syslog file test facility all level notice" in result.commands' - -- name: delete logging again (idempotent) - register: result - vyos.vyos.vyos_logging: - dest: file - name: test - facility: all - level: notice - state: absent - -- assert: - that: - - result.changed == false - -- name: Add logging collections - register: result - vyos.vyos.vyos_logging: - aggregate: - - dest: file - name: test1 - facility: all - level: info - - - dest: file - name: test2 - facility: news - level: debug - state: present - -- assert: - that: - - result.changed == true - - '"set system syslog file test1 facility all level info" in result.commands' - - '"set system syslog file test2 facility news level debug" in result.commands' - -- name: Add and remove logging collections with overrides - register: result - vyos.vyos.vyos_logging: - aggregate: - - dest: console - facility: all - level: info - - - dest: file - name: test1 - facility: all - level: info - state: absent - - - dest: console - facility: daemon - level: warning - state: present - -- assert: - that: - - result.changed == true - - '"delete system syslog file test1 facility all level info" in result.commands' - - '"set system syslog console facility daemon level warning" in result.commands' - -- name: Remove logging collections - register: result - vyos.vyos.vyos_logging: - aggregate: - - dest: console - facility: all - level: info - - - dest: console - facility: daemon - level: warning - - - dest: file - name: test2 - facility: news - level: debug - state: absent - -- assert: - that: - - result.changed == true - - '"delete system syslog console facility all level info" in result.commands' - - '"delete system syslog console facility daemon level warning" in result.commands' - - '"delete system syslog file test2 facility news level debug" in result.commands' |