From 6e3fdd41056aa104a49b172de16d0d770afe556c Mon Sep 17 00:00:00 2001 From: Gaige B Paulsen Date: Wed, 12 Feb 2025 17:48:57 -0500 Subject: T7153: remove logging module (#393) --- changelogs/fragments/T7153-remove-logging.yaml | 3 + docs/vyos.vyos.vyos_logging_module.rst | 348 -------------------- meta/runtime.yml | 13 +- plugins/action/logging.py | 1 - plugins/modules/vyos_logging.py | 365 --------------------- tests/integration/targets/vyos_logging/aliases | 1 - .../targets/vyos_logging/defaults/main.yaml | 3 - .../targets/vyos_logging/tasks/cli.yaml | 21 -- .../targets/vyos_logging/tasks/main.yaml | 3 - .../targets/vyos_logging/tests/cli/basic.yaml | 152 --------- 10 files changed, 9 insertions(+), 901 deletions(-) create mode 100644 changelogs/fragments/T7153-remove-logging.yaml delete mode 100644 docs/vyos.vyos.vyos_logging_module.rst delete mode 120000 plugins/action/logging.py delete mode 100644 plugins/modules/vyos_logging.py delete mode 100644 tests/integration/targets/vyos_logging/aliases delete mode 100644 tests/integration/targets/vyos_logging/defaults/main.yaml delete mode 100644 tests/integration/targets/vyos_logging/tasks/cli.yaml delete mode 100644 tests/integration/targets/vyos_logging/tasks/main.yaml delete mode 100644 tests/integration/targets/vyos_logging/tests/cli/basic.yaml 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 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
ParameterChoices/DefaultsComments
-
- aggregate - -
- list - / elements=dictionary -
-
- -
List of logging definitions.
-
-
- dest - -
- string -
-
-
    Choices: -
  • console
  • -
  • file
  • -
  • global
  • -
  • host
  • -
  • user
  • -
-
-
Destination of the logs.
-
-
- facility - -
- string -
-
- -
Set logging facility.
-
-
- level - -
- string -
-
- -
Set logging severity levels.
-
-
- name - -
- string -
-
- -
If value of dest is file it indicates file-name, for user it indicates username and for host indicates the host name to be notified.
-
-
- state - -
- string -
-
-
    Choices: -
  • present
  • -
  • absent
  • -
-
-
State of the logging configuration.
-
-
- dest - -
- string -
-
-
    Choices: -
  • console
  • -
  • file
  • -
  • global
  • -
  • host
  • -
  • user
  • -
-
-
Destination of the logs.
-
-
- facility - -
- string -
-
- -
Set logging facility.
-
-
- level - -
- string -
-
- -
Set logging severity levels.
-
-
- name - -
- string -
-
- -
If value of dest is file it indicates file-name, for user it indicates username and for host indicates the host name to be notified.
-
-
- state - -
- string -
-
-
    Choices: -
  • present ←
  • -
  • absent
  • -
-
-
State of the logging configuration.
-
-
- - -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 ` - - - -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 `_, the following are the fields unique to this module: - -.. raw:: html - - - - - - - - - - - - -
KeyReturnedDescription
-
- commands - -
- list -
-
always -
The list of configuration mode commands to send to the device
-
-
Sample:
-
['set system syslog global facility all level notice']
-
-

- - -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 . -# - - -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' -- cgit v1.2.3