From 0af70dc0533dc062eaa47bfeb66e4ff5e3cc5f67 Mon Sep 17 00:00:00 2001 From: Austin Whaley Date: Tue, 12 Nov 2024 18:12:16 -0500 Subject: [PATCH 01/14] Adding ability to delete a logging server's attribute without removing the whole server --- .../network/sonic/config/logging/logging.py | 26 ++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/plugins/module_utils/network/sonic/config/logging/logging.py b/plugins/module_utils/network/sonic/config/logging/logging.py index 0538c7395..931e70c12 100644 --- a/plugins/module_utils/network/sonic/config/logging/logging.py +++ b/plugins/module_utils/network/sonic/config/logging/logging.py @@ -453,9 +453,29 @@ def get_delete_servers_requests(self, configs): for config in configs: server_host = config['host'] url = 'data/openconfig-system:system/logging/remote-servers/remote-server={0}'.format(server_host) - request = {"path": url, "method": method} - requests.append(request) - + if not (config.get("vrf") or config.get("source_interface") or config.get("message_type") or + config.get("remote_port") or config.get("protocol") or config.get("severity")): + request = {"path": url, "method": method} + requests.append(request) + else: + if config.get('source_interface'): + request = {"path": "{}/config/openconfig-system-ext:source-interface".format(url), "method": method} + requests.append(request) + if config.get("message_type"): + request = {"path": "{}/config/openconfig-system-ext:message-type".format(url), "method": method} + requests.append(request) + if config.get("vrf"): + request = {"path": "{}/config/openconfig-system-ext:vrf-name".format(url), "method": method} + requests.append(request) + if config.get("remote_port"): + request = {"path": "{}/config/remote-port".format(url), "method": method} + requests.append(request) + if config.get("protocol"): + request = {"path": "{}/config/openconfig-system-ext:protocol".format(url), "method": method} + requests.append(request) + if config.get("severity"): + request = {"path": "{}/config/openconfig-system-ext:severity".format(url), "method": method} + requests.append(request) return requests def get_delete_all_servers_requests(self): From 65f940cee2cbf65012e0c5f628f930bca8319d43 Mon Sep 17 00:00:00 2001 From: Austin Whaley Date: Wed, 13 Nov 2024 19:32:14 -0500 Subject: [PATCH 02/14] Removing unused validate_want function from logging config file --- .../network/sonic/config/logging/logging.py | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/plugins/module_utils/network/sonic/config/logging/logging.py b/plugins/module_utils/network/sonic/config/logging/logging.py index 931e70c12..73a44d65b 100644 --- a/plugins/module_utils/network/sonic/config/logging/logging.py +++ b/plugins/module_utils/network/sonic/config/logging/logging.py @@ -156,7 +156,6 @@ def set_state(self, want, have): """ state = self._module.params['state'] - self.validate_want(want, state) self.preprocess_want(want, state) if state == 'deleted': @@ -328,22 +327,6 @@ def get_replaced_config(self, have, want): replaced_config['remote_servers'] = replaced_servers return replaced_config - def validate_want(self, want, state): - - if state == 'deleted': - - if 'remote_servers' in want and want['remote_servers'] is not None: - for server in want['remote_servers']: - source_interface_config = server.get('source_interface', None) - remote_port_config = server.get('remote_port', None) - protocol_config = server.get('protocol', None) - severity_config = server.get('severity', None) - message_type_config = server.get('message_type', None) - vrf_config = server.get('vrf', None) - if source_interface_config or remote_port_config or \ - message_type_config or vrf_config or protocol_config or severity_config: - err_msg = "Logging remote_server parameter(s) can not be deleted." - self._module.fail_json(msg=err_msg, code=405) def preprocess_want(self, want, state): From 5f6dd1d575ac172b72e114b4169e67eff2e9f3c5 Mon Sep 17 00:00:00 2001 From: Austin Whaley Date: Wed, 13 Nov 2024 19:33:02 -0500 Subject: [PATCH 03/14] Removing outdated message about not deleting attributes and adding attribute deletion example --- plugins/modules/sonic_logging.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/plugins/modules/sonic_logging.py b/plugins/modules/sonic_logging.py index 0d6358e96..6f613ccf2 100644 --- a/plugins/modules/sonic_logging.py +++ b/plugins/modules/sonic_logging.py @@ -61,17 +61,14 @@ type: int description: - Destination port number for logging messages sent to the server. - - remote_port can not be deleted. source_interface: type: str description: - Source interface used as source ip for sending logging packets. - - source_interface can not be deleted. message_type: type: str description: - Type of messages that remote server receives. - - message_type can not be deleted. choices: - log - event @@ -134,6 +131,10 @@ remote_servers: - host: 10.11.0.2 - host: log1.dell.com + - host: 10.11.1.1 + message_type: log + protocol: tcp + source_interface: Ethernet8 state: deleted # After state: @@ -143,8 +144,8 @@ #--------------------------------------------------------------------------------------- #HOST PORT SOURCE-INTERFACE VRF MESSAGE-TYPE PROTOCOL #--------------------------------------------------------------------------------------- -#10.11.1.1 616 Ethernet8 - log tcp -#10.11.1.2 116 Ethernet6 - log tls +#10.11.1.1 616 - - log udp +#10.11.1.2 116 Ethernet6 - log tls # # # Using merged From 2e62897b16f63127d3f192ac25366583cae695e4 Mon Sep 17 00:00:00 2001 From: Austin Whaley Date: Mon, 18 Nov 2024 12:23:04 -0500 Subject: [PATCH 04/14] Adding severity output to the logging module documentation and adding default values to logging server parameters --- plugins/modules/sonic_logging.py | 163 ++++++++++++++++--------------- 1 file changed, 84 insertions(+), 79 deletions(-) diff --git a/plugins/modules/sonic_logging.py b/plugins/modules/sonic_logging.py index 6f613ccf2..94fc8ae53 100644 --- a/plugins/modules/sonic_logging.py +++ b/plugins/modules/sonic_logging.py @@ -46,6 +46,42 @@ - Specifies logging related configurations. type: dict suboptions: + message_type: + type: str + description: + - Type of messages that remote server receives. + choices: + - log + - event + - audit + severity: + version_added: 3.1.0 + type: str + description: + - The log severity filter for remote syslog server. + choices: + - debug + - info + - notice + - warning + - error + - critical + - alert + - emergency + default: notice + protocol: + type: str + description: + - Type of the protocol for sending the messages. + choices: + - TCP + - TLS + - UDP + default: UDP + vrf: + type: str + description: + - VRF name used by remote logging server. remote_servers: type: list elements: dict @@ -65,40 +101,6 @@ type: str description: - Source interface used as source ip for sending logging packets. - message_type: - type: str - description: - - Type of messages that remote server receives. - choices: - - log - - event - - audit - severity: - version_added: 3.1.0 - type: str - description: - - The log severity filter for remote syslog server. - choices: - - debug - - info - - notice - - warning - - error - - critical - - alert - - emergency - protocol: - type: str - description: - - Type of the protocol for sending the messages. - choices: - - TCP - - TLS - - UDP - vrf: - type: str - description: - - VRF name used by remote logging server. state: description: - The state of the configuration after module completion. @@ -117,13 +119,13 @@ # ------------- # #sonic# show logging servers -#--------------------------------------------------------------------------------------- -#HOST PORT SOURCE-INTERFACE VRF MESSAGE-TYPE PROTOCOL -#--------------------------------------------------------------------------------------- -#10.11.0.2 5 Ethernet24 - event udp -#10.11.1.1 616 Ethernet8 - log tcp -#log1.dell.com 6 Ethernet28 - audit udp -#10.11.1.2 116 Ethernet6 - log tls +#---------------------------------------------------------------------------------------------------------- +#HOST PORT SOURCE-INTERFACE VRF MESSAGE-TYPE SEVERITY PROTOCOL +#---------------------------------------------------------------------------------------------------------- +#10.11.0.2 5 Ethernet24 - event notice udp +#10.11.1.1 616 Ethernet8 - log alert tcp +#log1.dell.com 6 Ethernet28 - audit notice udp +#10.11.1.2 116 Ethernet6 - log notice tls # - name: Delete logging server configuration sonic_logging: @@ -135,17 +137,18 @@ message_type: log protocol: tcp source_interface: Ethernet8 + severity: alert state: deleted # After state: # ------------ # #sonic# show logging servers -#--------------------------------------------------------------------------------------- -#HOST PORT SOURCE-INTERFACE VRF MESSAGE-TYPE PROTOCOL -#--------------------------------------------------------------------------------------- -#10.11.1.1 616 - - log udp -#10.11.1.2 116 Ethernet6 - log tls +#---------------------------------------------------------------------------------------------------------- +#HOST PORT SOURCE-INTERFACE VRF MESSAGE-TYPE SEVERITY PROTOCOL +#---------------------------------------------------------------------------------------------------------- +#10.11.1.1 616 - - log notice udp +#10.11.1.2 116 Ethernet6 - log notice tls # # # Using merged @@ -154,10 +157,10 @@ # ------------- # #sonic# show logging servers -#-------------------------------------------------------------------------------------- -#HOST PORT SOURCE-INTERFACE VRF MESSAGE-TYPE PROTOCOL -#-------------------------------------------------------------------------------------- -#10.11.1.1 616 Ethernet8 - log tcp +#---------------------------------------------------------------------------------------------------------- +#HOST PORT SOURCE-INTERFACE VRF MESSAGE-TYPE SEVERITY PROTOCOL +#---------------------------------------------------------------------------------------------------------- +#10.11.1.1 616 Ethernet8 - log notice tcp # - name: Merge logging server configuration sonic_logging: @@ -172,6 +175,8 @@ remote_port: 4 protocol: TLS source_interface: Ethernet2 + - host: 10.11.1.1 + severity: error - host: log1.dell.com remote_port: 6 protocol: udp @@ -181,15 +186,14 @@ # After state: # ------------ -# #sonic# show logging servers -#------------------------------------------------------------------------------------- -#HOST PORT SOURCE-INTERFACE VRF MESSAGE-TYPE PROTOCOL -#------------------------------------------------------------------------------------- -#10.11.0.2 5 Ethernet24 - event udp -#10.11.0.1 4 Ethernet2 - log tls -#10.11.1.1 616 Ethernet8 - log tcp -#log1.dell.com 6 Ethernet28 - audit udp +#---------------------------------------------------------------------------------------------------------- +#HOST PORT SOURCE-INTERFACE VRF MESSAGE-TYPE SEVERITY PROTOCOL +#---------------------------------------------------------------------------------------------------------- +#10.11.0.2 5 Ethernet24 - event notice udp +#10.11.0.1 4 Ethernet2 - log notice tls +#10.11.1.1 616 Ethernet8 - log error tcp +#log1.dell.com 6 Ethernet28 - audit notice udp # # # Using overridden @@ -198,12 +202,12 @@ # ------------- # #sonic# show logging servers -#-------------------------------------------------------------------------------------- -#HOST PORT SOURCE-INTERFACE VRF MESSAGE-TYPE PROTOCOL -#-------------------------------------------------------------------------------------- -#10.11.1.1 616 Ethernet8 - log tcp -#10.11.1.2 626 Ethernet16 - event udp -#10.11.1.3 626 Ethernet14 - log tls +#---------------------------------------------------------------------------------------------------------- +#HOST PORT SOURCE-INTERFACE VRF MESSAGE-TYPE SEVERITY PROTOCOL +#---------------------------------------------------------------------------------------------------------- +#10.11.1.1 616 Ethernet8 - log notice tcp +#10.11.1.2 626 Ethernet16 - event emergency udp +#10.11.1.3 626 Ethernet14 - log notice tls # - name: Override logging server configuration sonic_logging: @@ -214,16 +218,16 @@ protocol: TCP source_interface: Ethernet24 message_type: audit + severity: alert state: overridden # # After state: # ------------ -# #sonic# show logging servers -#-------------------------------------------------------------------------------------- -#HOST PORT SOURCE-INTERFACE VRF MESSAGE-TYPE PROTOCOL -#-------------------------------------------------------------------------------------- -#10.11.1.2 622 Ethernet24 - audit tcp +#---------------------------------------------------------------------------------------------------------- +#HOST PORT SOURCE-INTERFACE VRF MESSAGE-TYPE SEVERITY PROTOCOL +#---------------------------------------------------------------------------------------------------------- +#10.11.1.2 622 Ethernet24 - audit alert tcp # # Using replaced # @@ -231,11 +235,11 @@ # ------------- # #sonic# show logging servers -#-------------------------------------------------------------------------------------- -#HOST PORT SOURCE-INTERFACE VRF MESSAGE-TYPE PROTOCOL -#-------------------------------------------------------------------------------------- -#10.11.1.1 616 Ethernet8 - log tcp -#10.11.1.2 626 Ethernet16 - event udp +#---------------------------------------------------------------------------------------------------------- +#HOST PORT SOURCE-INTERFACE VRF MESSAGE-TYPE SEVERITY PROTOCOL +#---------------------------------------------------------------------------------------------------------- +#10.11.1.1 616 Ethernet8 - log notice tcp +#10.11.1.2 626 Ethernet16 - event notice udp # - name: Replace logging server configuration sonic_logging: @@ -245,6 +249,7 @@ remote_port: 622 protocol: UDP message_type: audit + severity: debug state: replaced # # After state: @@ -253,11 +258,11 @@ # "MESSAGE-TYPE" has default value of "log" # #sonic# show logging servers -#-------------------------------------------------------------------------------------- -#HOST PORT SOURCE-INTERFACE VRF MESSAGE-TYPE PROTOCOL -#-------------------------------------------------------------------------------------- -#10.11.1.1 616 Ethernet8 - log tcp -#10.11.1.2 622 - - audit udp +#---------------------------------------------------------------------------------------------------------- +#HOST PORT SOURCE-INTERFACE VRF MESSAGE-TYPE SEVERITY PROTOCOL +#---------------------------------------------------------------------------------------------------------- +#10.11.1.1 616 Ethernet8 - log notice tcp +#10.11.1.2 622 - - audit debug udp # """ RETURN = """ From 6c3fc70677d930248431f2ace320d7c629ae6088 Mon Sep 17 00:00:00 2001 From: Austin Whaley Date: Mon, 25 Nov 2024 19:48:20 -0500 Subject: [PATCH 05/14] Updating regression test to include deleting a specific attribute and overriding a single logging server. --- .../roles/sonic_logging/defaults/main.yml | 64 ++++++++++++------- 1 file changed, 42 insertions(+), 22 deletions(-) diff --git a/tests/regression/roles/sonic_logging/defaults/main.yml b/tests/regression/roles/sonic_logging/defaults/main.yml index 97dbb894f..7d9e3c730 100644 --- a/tests/regression/roles/sonic_logging/defaults/main.yml +++ b/tests/regression/roles/sonic_logging/defaults/main.yml @@ -19,20 +19,20 @@ logging_host_server: logging.dell.com tests: - name: test_case_01 - description: Create a logging remote server + description: Create a single logging remote server state: merged input: remote_servers: - host: "{{ logging_ip_server_1 }}" source_interface: "{{ interface1 }}" remote_port: 616 - protocol: UDP + protocol: TCP severity: debug message_type: event vrf: Vrf_logging_1 - name: test_case_02 - description: Create several logging remote servers + description: Create several logging remote servers state: merged input: remote_servers: @@ -44,7 +44,7 @@ tests: source_interface: "{{ vlan1 }}" remote_port: 818 protocol: TCP - message_type: auditd-system + message_type: event vrf: Vrf_logging_2 - host: "{{ logging_ip_server_7 }}" severity: debug @@ -65,7 +65,7 @@ tests: vrf: Vrf_logging_1 - name: test_case_03 - description: Replace logging remote server + description: Replace a single logging remote server state: replaced input: remote_servers: @@ -74,18 +74,13 @@ tests: source_interface: "{{ interface2 }}" remote_port: 838 protocol: UDP + message_type: event - name: test_case_04 - description: Replace logging remote servers + description: Replace several logging remote servers state: replaced input: remote_servers: - - host: "{{ logging_ip_server_3 }}" - severity: alert - source_interface: "{{ interface3 }}" - remote_port: 838 - protocol: UDP - message_type: event - host: "{{ logging_ip_server_4 }}" severity: critical source_interface: "{{ interface4 }}" @@ -100,10 +95,22 @@ tests: source_interface: "{{ interface5 }}" remote_port: 818 protocol: TLS - message_type: auditd-system + message_type: event - name: test_case_05 - description: Overridden logging remote servers + description: Override a single logging remote server + state: overridden + input: + remote_servers: + - host: "{{ logging_ip_server_1 }}" + severity: info + source_interface: "{{ interface1 }}" + remote_port: 777 + protocol: UDP + message_type: log + + - name: test_case_06 + description: Override several logging remote servers state: overridden input: remote_servers: @@ -117,8 +124,8 @@ tests: protocol: TCP message_type: event - - name: test_case_06 - description: Modify several created logging remote servers to change or add suboptions + - name: test_case_07 + description: Modify several created logging remote servers to change or add attributes state: merged input: remote_servers: @@ -127,29 +134,42 @@ tests: source_interface: "{{ interface1 }}" remote_port: 111 protocol: TCP - message_type: log + message_type: event vrf: Vrf_logging_1 - host: "{{ logging_ip_server_3 }}" severity: emergency source_interface: "{{ vlan1 }}" remote_port: 313 protocol: UDP - message_type: auditd-system + message_type: audit vrf: Vrf_logging_2 - host: "{{ logging_host_server }}" severity: warning source_interface: "{{ lo1 }}" + message_type: log + vrf: Vrf_logging_1 + + - name: test_case_08 + description: Delete a single logging remote server's attributes + state: deleted + input: + remote_servers: + - host: "{{ logging_ip_server_1 }}" + source_interface: "{{ interface1 }}" + remote_port: 616 + protocol: TCP message_type: event vrf: Vrf_logging_1 + severity: debug - - name: test_case_07 + - name: test_case_09 description: Delete a logging remote server state: deleted input: remote_servers: - host: "{{ logging_ip_server_1 }}" - - name: test_case_08 + - name: test_case_10 description: Delete several logging remote servers state: deleted input: @@ -159,7 +179,7 @@ tests: - host: "{{ logging_ip_server_7 }}" - host: "{{ logging_host_server }}" - - name: test_case_09 + - name: test_case_11 description: Delete all logging configurations state: deleted - input: {} + input: {} \ No newline at end of file From 812481cd0ffc706d4bf4720d88b782917f65fa63 Mon Sep 17 00:00:00 2001 From: Austin Whaley Date: Mon, 25 Nov 2024 19:57:41 -0500 Subject: [PATCH 06/14] Adding fragment file for the PR --- changelogs/fragments/486-delete-attribute-logging-server.yaml | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 changelogs/fragments/486-delete-attribute-logging-server.yaml diff --git a/changelogs/fragments/486-delete-attribute-logging-server.yaml b/changelogs/fragments/486-delete-attribute-logging-server.yaml new file mode 100644 index 000000000..625146b2e --- /dev/null +++ b/changelogs/fragments/486-delete-attribute-logging-server.yaml @@ -0,0 +1,3 @@ +--- +minor_changes: + - sonic_logging - Adding the ability to delete a specific attribute of a logging server into the logging module (https://github.com/ansible-collections/dellemc.enterprise_sonic/pull/486). \ No newline at end of file From 77c4922116e7716a6588a79a56352c9227f87728 Mon Sep 17 00:00:00 2001 From: Austin Whaley Date: Wed, 4 Dec 2024 19:37:32 -0500 Subject: [PATCH 07/14] Adding newline to the end of the logging regression tests --- plugins/modules/sonic_logging.py | 40 +++----------------------------- 1 file changed, 3 insertions(+), 37 deletions(-) diff --git a/plugins/modules/sonic_logging.py b/plugins/modules/sonic_logging.py index 3bbd56ee1..a86345bf9 100644 --- a/plugins/modules/sonic_logging.py +++ b/plugins/modules/sonic_logging.py @@ -46,42 +46,6 @@ - Specifies logging related configurations. type: dict suboptions: - message_type: - type: str - description: - - Type of messages that remote server receives. - choices: - - log - - event - - audit - severity: - version_added: 3.1.0 - type: str - description: - - The log severity filter for remote syslog server. - choices: - - debug - - info - - notice - - warning - - error - - critical - - alert - - emergency - default: notice - protocol: - type: str - description: - - Type of the protocol for sending the messages. - choices: - - TCP - - TLS - - UDP - default: UDP - vrf: - type: str - description: - - VRF name used by remote logging server. remote_servers: type: list elements: dict @@ -105,12 +69,12 @@ type: str description: - Type of messages that remote server receives. - - message_type can not be deleted. choices: - log - event - audit - auditd-system + default: log severity: version_added: 3.1.0 type: str @@ -125,6 +89,7 @@ - critical - alert - emergency + default: notice protocol: type: str description: @@ -133,6 +98,7 @@ - TCP - TLS - UDP + default: UDP vrf: type: str description: From 79b18479152ed1685d676dd7f133095849926e24 Mon Sep 17 00:00:00 2001 From: Austin Whaley Date: Wed, 4 Dec 2024 20:28:25 -0500 Subject: [PATCH 08/14] Adding default value for logging servers severity attribute --- plugins/module_utils/network/sonic/config/logging/logging.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/plugins/module_utils/network/sonic/config/logging/logging.py b/plugins/module_utils/network/sonic/config/logging/logging.py index 73a44d65b..aeb512176 100644 --- a/plugins/module_utils/network/sonic/config/logging/logging.py +++ b/plugins/module_utils/network/sonic/config/logging/logging.py @@ -43,6 +43,7 @@ DEFAULT_REMOTE_PORT = 514 DEFAULT_LOG_TYPE = 'log' DEFAULT_PROTOCOL = 'UDP' +DEFAULT_SEVERITY = 'notice' TEST_KEYS = [ { @@ -363,6 +364,8 @@ def preprocess_want(self, want, state): server['message_type'] = DEFAULT_LOG_TYPE if 'protocol' in server and not server['protocol']: server['protocol'] = DEFAULT_PROTOCOL + if 'severity' in server and not server['severity']: + server['severity'] = DEFAULT_SEVERITY def get_merge_requests(self, configs, have): From c36e2b7a6ae2cced0e242f22378414cac91a983f Mon Sep 17 00:00:00 2001 From: Austin Whaley Date: Wed, 4 Dec 2024 20:29:13 -0500 Subject: [PATCH 09/14] Adding newline to end of loggings regression playbook --- tests/regression/roles/sonic_logging/defaults/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/regression/roles/sonic_logging/defaults/main.yml b/tests/regression/roles/sonic_logging/defaults/main.yml index 7d9e3c730..8a6372421 100644 --- a/tests/regression/roles/sonic_logging/defaults/main.yml +++ b/tests/regression/roles/sonic_logging/defaults/main.yml @@ -182,4 +182,4 @@ tests: - name: test_case_11 description: Delete all logging configurations state: deleted - input: {} \ No newline at end of file + input: {} From bc846460ea43a70ecc75960a7a01810f8e024193 Mon Sep 17 00:00:00 2001 From: Austin Whaley Date: Wed, 4 Dec 2024 20:56:33 -0500 Subject: [PATCH 10/14] Adding new delete attributes test case and fixing bug where existing config attributes were missing openconfig-system preface --- .../network/sonic/fixtures/sonic_logging.yaml | 122 +++++++++++++----- 1 file changed, 90 insertions(+), 32 deletions(-) diff --git a/tests/unit/modules/network/sonic/fixtures/sonic_logging.yaml b/tests/unit/modules/network/sonic/fixtures/sonic_logging.yaml index 5d421e0c7..54ef87f05 100644 --- a/tests/unit/modules/network/sonic/fixtures/sonic_logging.yaml +++ b/tests/unit/modules/network/sonic/fixtures/sonic_logging.yaml @@ -34,25 +34,25 @@ merged_01: - host: 10.11.0.2 config: host: 10.11.0.2 + remote-port: 5 source-interface: Eth1/24 message-type: event - remote-port: 5 protocol: TCP severity: INFORMATIONAL - host: 10.11.0.3 config: host: 10.11.0.3 + remote-port: 4 source-interface: Eth1/22 message-type: log - remote-port: 4 protocol: TLS severity: NOTICE - host: log1.dell.com config: host: log1.dell.com + remote-port: 6 source-interface: Eth1/28 message-type: audit - remote-port: 6 protocol: UDP severity: ERROR @@ -70,18 +70,18 @@ deleted_01: - host: 10.11.0.2 config: host: 10.11.0.2 - source-interface: Eth1/24 - message-type: event remote-port: 5 - protocol: TCP - severity: debug + openconfig-system-ext:source-interface: Eth1/24 + openconfig-system-ext:message-type: event + openconfig-system-ext:protocol: TCP + openconfig-system-ext:severity: debug - host: log1.dell.com config: host: log1.dell.com - source-interface: Eth1/28 remote-port: 6 - protocol: UDP - severity: error + openconfig-system-ext:source-interface: Eth1/28 + openconfig-system-ext:protocol: UDP + openconfig-system-ext:severity: error expected_config_requests: - path: "data/openconfig-system:system/logging/remote-servers" method: "delete" @@ -104,23 +104,69 @@ deleted_02: - host: 10.11.0.2 config: host: 10.11.0.2 - source-interface: Eth1/24 - message-type: event remote-port: 5 - protocol: TCP - severity: debug + openconfig-system-ext:source-interface: Eth1/24 + openconfig-system-ext:message-type: event + openconfig-system-ext:protocol: TCP + openconfig-system-ext:severity: debug - host: log1.dell.com config: host: log1.dell.com - source-interface: Eth1/28 remote-port: 6 - protocol: UDP - severity: error + openconfig-system-ext:source-interface: Eth1/28 + openconfig-system-ext:protocol: UDP + openconfig-system-ext:severity: error expected_config_requests: - path: "data/openconfig-system:system/logging/remote-servers/remote-server=10.11.0.2" method: "delete" data: + +deleted_03: + module_args: + state: deleted + config: + remote_servers: + - host: 10.11.0.2 + remote_port: 5 + protocol: TCP + severity: error + source_interface: Eth1/24 + message_type: event + existing_logging_config: + - path: "data/openconfig-system:system/logging" + response: + code: 200 + value: + openconfig-system:logging: + remote-servers: + remote-server: + - host: 10.11.0.2 + config: + host: 10.11.0.2 + remote-port: 5 + openconfig-system-ext:protocol: TCP + openconfig-system-ext:severity: error + openconfig-system-ext:source-interface: Eth1/24 + openconfig-system-ext:message-type: event + expected_config_requests: + - path: "data/openconfig-system:system/logging/remote-servers/remote-server=10.11.0.2/config/openconfig-system-ext:source-interface" + method: "delete" + data: + - path: "data/openconfig-system:system/logging/remote-servers/remote-server=10.11.0.2/config/openconfig-system-ext:message-type" + method: "delete" + data: + - path: "data/openconfig-system:system/logging/remote-servers/remote-server=10.11.0.2/config/remote-port" + method: "delete" + data: + - path: "data/openconfig-system:system/logging/remote-servers/remote-server=10.11.0.2/config/openconfig-system-ext:protocol" + method: "delete" + data: + - path: "data/openconfig-system:system/logging/remote-servers/remote-server=10.11.0.2/config/openconfig-system-ext:severity" + method: "delete" + data: + + replaced_01: module_args: state: replaced @@ -149,20 +195,32 @@ replaced_01: - host: 10.11.0.2 config: host: 10.11.0.2 - source-interface: Eth1/24 - message-type: event remote-port: 5 - protocol: TCP - severity: emergency + openconfig-system-ext:protocol: TCP + openconfig-system-ext:severity: emergency + openconfig-system-ext:source-interface: Eth1/24 + openconfig-system-ext:message-type: event - host: log1.dell.com config: host: log1.dell.com - source-interface: Eth1/28 remote-port: 6 - protocol: UDP - severity: debug + openconfig-system-ext:protocol: UDP + openconfig-system-ext:severity: debug + openconfig-system-ext:source-interface: Eth1/28 expected_config_requests: - - path: "data/openconfig-system:system/logging/remote-servers/remote-server=10.11.0.2" + - path: "data/openconfig-system:system/logging/remote-servers/remote-server=10.11.0.2/config/remote-port" + method: "delete" + data: + - path: "data/openconfig-system:system/logging/remote-servers/remote-server=10.11.0.2/config/openconfig-system-ext:source-interface" + method: "delete" + data: + - path: "data/openconfig-system:system/logging/remote-servers/remote-server=10.11.0.2/config/openconfig-system-ext:protocol" + method: "delete" + data: + - path: "data/openconfig-system:system/logging/remote-servers/remote-server=10.11.0.2/config/openconfig-system-ext:severity" + method: "delete" + data: + - path: "data/openconfig-system:system/logging/remote-servers/remote-server=10.11.0.2/config/openconfig-system-ext:message-type" method: "delete" data: - path: "data/openconfig-system:system/logging/remote-servers" @@ -211,18 +269,18 @@ overridden_01: - host: 10.11.0.2 config: host: 10.11.0.2 - source-interface: Eth1/24 - message-type: event remote-port: 5 - protocol: TCP - severity: error + openconfig-system-ext:source-interface: Eth1/24 + openconfig-system-ext:message-type: event + openconfig-system-ext:protocol: TCP + openconfig-system-ext:severity: error - host: log1.dell.com config: host: log1.dell.com - source-interface: Eth1/28 remote-port: 6 - protocol: UDP - severity: debug + openconfig-system-ext:source-interface: Eth1/28 + openconfig-system-ext:protocol: UDP + openconfig-system-ext:severity: debug expected_config_requests: - path: "data/openconfig-system:system/logging/remote-servers" method: "delete" From 4f25205d2a0b79033a25b0841f0d7eb8b948e44b Mon Sep 17 00:00:00 2001 From: Austin Whaley Date: Wed, 4 Dec 2024 21:07:57 -0500 Subject: [PATCH 11/14] Adding default values for attributes "severity", "protocol", and "message-type" to reflect the SONIC 4.4.0/4.5.0 behavior. --- .../network/sonic/argspec/logging/logging.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/plugins/module_utils/network/sonic/argspec/logging/logging.py b/plugins/module_utils/network/sonic/argspec/logging/logging.py index c34ee11f6..d36f57a84 100644 --- a/plugins/module_utils/network/sonic/argspec/logging/logging.py +++ b/plugins/module_utils/network/sonic/argspec/logging/logging.py @@ -45,15 +45,18 @@ def __init__(self, **kwargs): 'options': { 'host': {'required': True, 'type': 'str'}, + 'remote_port': {'type': 'int'}, 'message_type': {'choices': ['log', 'event', 'audit', 'auditd-system'], + 'default': 'log', 'type': 'str'}, 'severity': {'choices': ['debug', 'info', 'notice', 'warning', 'error', 'critical', 'alert', 'emergency'], + 'default': 'notice', 'type': 'str'}, - 'remote_port': {'type': 'int'}, - 'source_interface': {'type': 'str'}, - 'vrf': {'type': 'str'}, 'protocol': {'choices': ['TCP', 'UDP', 'TLS'], + 'default': 'UDP', 'type': 'str'}, + 'source_interface': {'type': 'str'}, + 'vrf': {'type': 'str'} }, 'type': 'list' } From 483eaf92a54d872045fc40e14ddf854657cbfb46 Mon Sep 17 00:00:00 2001 From: Austin Whaley Date: Wed, 4 Dec 2024 21:26:55 -0500 Subject: [PATCH 12/14] Fixing pylint/pep8 style issues with whitespaces --- plugins/module_utils/network/sonic/config/logging/logging.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/plugins/module_utils/network/sonic/config/logging/logging.py b/plugins/module_utils/network/sonic/config/logging/logging.py index aeb512176..659a335c3 100644 --- a/plugins/module_utils/network/sonic/config/logging/logging.py +++ b/plugins/module_utils/network/sonic/config/logging/logging.py @@ -328,7 +328,6 @@ def get_replaced_config(self, have, want): replaced_config['remote_servers'] = replaced_servers return replaced_config - def preprocess_want(self, want, state): if state == 'merged': @@ -439,7 +438,7 @@ def get_delete_servers_requests(self, configs): for config in configs: server_host = config['host'] url = 'data/openconfig-system:system/logging/remote-servers/remote-server={0}'.format(server_host) - if not (config.get("vrf") or config.get("source_interface") or config.get("message_type") or + if not (config.get("vrf") or config.get("source_interface") or config.get("message_type") or config.get("remote_port") or config.get("protocol") or config.get("severity")): request = {"path": url, "method": method} requests.append(request) From 3abbd14d3dbedd9c7df51c11fdf84bf70bd4fdd9 Mon Sep 17 00:00:00 2001 From: Austin Whaley Date: Wed, 4 Dec 2024 22:09:02 -0500 Subject: [PATCH 13/14] Removing explicit default value definitions in argspec and module. Adding that breaks delete single remote server functionality for the module. Don't want to introduce any breaking changes in this push. Noted the default values in the description instead. --- .../network/sonic/argspec/logging/logging.py | 3 --- plugins/modules/sonic_logging.py | 9 +++------ 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/plugins/module_utils/network/sonic/argspec/logging/logging.py b/plugins/module_utils/network/sonic/argspec/logging/logging.py index d36f57a84..305d8ebdc 100644 --- a/plugins/module_utils/network/sonic/argspec/logging/logging.py +++ b/plugins/module_utils/network/sonic/argspec/logging/logging.py @@ -47,13 +47,10 @@ def __init__(self, **kwargs): 'type': 'str'}, 'remote_port': {'type': 'int'}, 'message_type': {'choices': ['log', 'event', 'audit', 'auditd-system'], - 'default': 'log', 'type': 'str'}, 'severity': {'choices': ['debug', 'info', 'notice', 'warning', 'error', 'critical', 'alert', 'emergency'], - 'default': 'notice', 'type': 'str'}, 'protocol': {'choices': ['TCP', 'UDP', 'TLS'], - 'default': 'UDP', 'type': 'str'}, 'source_interface': {'type': 'str'}, 'vrf': {'type': 'str'} diff --git a/plugins/modules/sonic_logging.py b/plugins/modules/sonic_logging.py index a86345bf9..335be185a 100644 --- a/plugins/modules/sonic_logging.py +++ b/plugins/modules/sonic_logging.py @@ -68,18 +68,17 @@ message_type: type: str description: - - Type of messages that remote server receives. + - Type of messages that remote server receives. Defaults to "log" value. choices: - log - event - audit - auditd-system - default: log severity: version_added: 3.1.0 type: str description: - - The log severity filter for remote syslog server. + - The log severity filter for remote syslog server. Defaults to "notice" value. choices: - debug - info @@ -89,16 +88,14 @@ - critical - alert - emergency - default: notice protocol: type: str description: - - Type of the protocol for sending the messages. + - Type of the protocol for sending the messages. Defaults to "UDP" value. choices: - TCP - TLS - UDP - default: UDP vrf: type: str description: From 6df421fa2b2148e117b09c4c9fa6842676518a8f Mon Sep 17 00:00:00 2001 From: Austin Whaley Date: Wed, 4 Dec 2024 22:11:12 -0500 Subject: [PATCH 14/14] Adding unit test call for deleted_03 in logging. Made lines between regression tests standard at 1 line. --- .../unit/modules/network/sonic/fixtures/sonic_logging.yaml | 2 -- tests/unit/modules/network/sonic/test_sonic_logging.py | 7 +++++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/tests/unit/modules/network/sonic/fixtures/sonic_logging.yaml b/tests/unit/modules/network/sonic/fixtures/sonic_logging.yaml index 54ef87f05..4d348c679 100644 --- a/tests/unit/modules/network/sonic/fixtures/sonic_logging.yaml +++ b/tests/unit/modules/network/sonic/fixtures/sonic_logging.yaml @@ -121,7 +121,6 @@ deleted_02: method: "delete" data: - deleted_03: module_args: state: deleted @@ -166,7 +165,6 @@ deleted_03: method: "delete" data: - replaced_01: module_args: state: replaced diff --git a/tests/unit/modules/network/sonic/test_sonic_logging.py b/tests/unit/modules/network/sonic/test_sonic_logging.py index eb744d0f1..22d9bddd1 100644 --- a/tests/unit/modules/network/sonic/test_sonic_logging.py +++ b/tests/unit/modules/network/sonic/test_sonic_logging.py @@ -72,6 +72,13 @@ def test_sonic_logging_deleted_02(self): result = self.execute_module(changed=True) self.validate_config_requests() + def test_sonic_logging_deleted_03(self): + set_module_args(self.fixture_data['deleted_03']['module_args']) + self.initialize_facts_get_requests(self.fixture_data['deleted_03']['existing_logging_config']) + self.initialize_config_requests(self.fixture_data['deleted_03']['expected_config_requests']) + result = self.execute_module(changed=True) + self.validate_config_requests() + def test_sonic_logging_replaced_01(self): set_module_args(self.fixture_data['replaced_01']['module_args']) self.initialize_facts_get_requests(self.fixture_data['replaced_01']['existing_logging_config'])