summaryrefslogtreecommitdiffstats
path: root/tests/units/anta_tests/test_logging.py
blob: d46c86581fd9eab68af7df19fc102b899577cdd3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
# Copyright (c) 2023-2024 Arista Networks, Inc.
# Use of this source code is governed by the Apache License 2.0
# that can be found in the LICENSE file.
"""Data for testing anta.tests.logging."""

from __future__ import annotations

from typing import Any

from anta.tests.logging import (
    VerifyLoggingAccounting,
    VerifyLoggingErrors,
    VerifyLoggingHostname,
    VerifyLoggingHosts,
    VerifyLoggingLogsGeneration,
    VerifyLoggingPersistent,
    VerifyLoggingSourceIntf,
    VerifyLoggingTimestamp,
)
from tests.lib.anta import test  # noqa: F401; pylint: disable=W0611

DATA: list[dict[str, Any]] = [
    {
        "name": "success",
        "test": VerifyLoggingPersistent,
        "eos_data": [
            "Persistent logging: level debugging\n",
            """Directory of flash:/persist/messages

                   -rw-        9948           May 10 13:54  messages

            33214693376 bytes total (10081136640 bytes free)

            """,
        ],
        "inputs": None,
        "expected": {"result": "success"},
    },
    {
        "name": "failure-disabled",
        "test": VerifyLoggingPersistent,
        "eos_data": [
            "Persistent logging: disabled\n",
            """Directory of flash:/persist/messages

                   -rw-           0           Apr 13 16:29  messages

            33214693376 bytes total (10082168832 bytes free)

            """,
        ],
        "inputs": None,
        "expected": {"result": "failure", "messages": ["Persistent logging is disabled"]},
    },
    {
        "name": "failure-not-saved",
        "test": VerifyLoggingPersistent,
        "eos_data": [
            "Persistent logging: level debugging\n",
            """Directory of flash:/persist/messages

                   -rw-           0           Apr 13 16:29  messages

            33214693376 bytes total (10082168832 bytes free)

            """,
        ],
        "inputs": None,
        "expected": {"result": "failure", "messages": ["No persistent logs are saved in flash"]},
    },
    {
        "name": "success",
        "test": VerifyLoggingSourceIntf,
        "eos_data": [
            """Trap logging: level informational
                Logging source-interface 'Management0', IP Address 172.20.20.12 in VRF MGMT
                Logging to '10.22.10.92' port 514 in VRF MGMT via udp
                Logging to '10.22.10.93' port 514 in VRF MGMT via tcp
                Logging to '10.22.10.94' port 911 in VRF MGMT via udp

                """,
        ],
        "inputs": {"interface": "Management0", "vrf": "MGMT"},
        "expected": {"result": "success"},
    },
    {
        "name": "failure-intf",
        "test": VerifyLoggingSourceIntf,
        "eos_data": [
            """Trap logging: level informational
                Logging source-interface 'Management1', IP Address 172.20.20.12 in VRF MGMT
                Logging to '10.22.10.92' port 514 in VRF MGMT via udp
                Logging to '10.22.10.93' port 514 in VRF MGMT via tcp
                Logging to '10.22.10.94' port 911 in VRF MGMT via udp

                """,
        ],
        "inputs": {"interface": "Management0", "vrf": "MGMT"},
        "expected": {"result": "failure", "messages": ["Source-interface 'Management0' is not configured in VRF MGMT"]},
    },
    {
        "name": "failure-vrf",
        "test": VerifyLoggingSourceIntf,
        "eos_data": [
            """Trap logging: level informational
                Logging source-interface 'Management0', IP Address 172.20.20.12 in VRF default
                Logging to '10.22.10.92' port 514 in VRF MGMT via udp
                Logging to '10.22.10.93' port 514 in VRF MGMT via tcp
                Logging to '10.22.10.94' port 911 in VRF MGMT via udp

                """,
        ],
        "inputs": {"interface": "Management0", "vrf": "MGMT"},
        "expected": {"result": "failure", "messages": ["Source-interface 'Management0' is not configured in VRF MGMT"]},
    },
    {
        "name": "success",
        "test": VerifyLoggingHosts,
        "eos_data": [
            """Trap logging: level informational
                Logging source-interface 'Management0', IP Address 172.20.20.12 in VRF MGMT
                Logging to '10.22.10.92' port 514 in VRF MGMT via udp
                Logging to '10.22.10.93' port 514 in VRF MGMT via tcp
                Logging to '10.22.10.94' port 911 in VRF MGMT via udp

                """,
        ],
        "inputs": {"hosts": ["10.22.10.92", "10.22.10.93", "10.22.10.94"], "vrf": "MGMT"},
        "expected": {"result": "success"},
    },
    {
        "name": "failure-hosts",
        "test": VerifyLoggingHosts,
        "eos_data": [
            """Trap logging: level informational
                Logging source-interface 'Management1', IP Address 172.20.20.12 in VRF MGMT
                Logging to '10.22.10.92' port 514 in VRF MGMT via udp
                Logging to '10.22.10.103' port 514 in VRF MGMT via tcp
                Logging to '10.22.10.104' port 911 in VRF MGMT via udp

                """,
        ],
        "inputs": {"hosts": ["10.22.10.92", "10.22.10.93", "10.22.10.94"], "vrf": "MGMT"},
        "expected": {"result": "failure", "messages": ["Syslog servers ['10.22.10.93', '10.22.10.94'] are not configured in VRF MGMT"]},
    },
    {
        "name": "failure-vrf",
        "test": VerifyLoggingHosts,
        "eos_data": [
            """Trap logging: level informational
                Logging source-interface 'Management0', IP Address 172.20.20.12 in VRF MGMT
                Logging to '10.22.10.92' port 514 in VRF MGMT via udp
                Logging to '10.22.10.93' port 514 in VRF default via tcp
                Logging to '10.22.10.94' port 911 in VRF default via udp

                """,
        ],
        "inputs": {"hosts": ["10.22.10.92", "10.22.10.93", "10.22.10.94"], "vrf": "MGMT"},
        "expected": {"result": "failure", "messages": ["Syslog servers ['10.22.10.93', '10.22.10.94'] are not configured in VRF MGMT"]},
    },
    {
        "name": "success",
        "test": VerifyLoggingLogsGeneration,
        "eos_data": [
            "",
            "2023-05-10T13:54:21.463497-05:00 NW-CORE.example.org ConfigAgent: %SYS-6-LOGMSG_INFO: "
            "Message from arista on command-api (10.22.1.107): ANTA VerifyLoggingLogsGeneration validation\n",
        ],
        "inputs": None,
        "expected": {"result": "success"},
    },
    {
        "name": "failure",
        "test": VerifyLoggingLogsGeneration,
        "eos_data": ["", "Log Buffer:\n"],
        "inputs": None,
        "expected": {"result": "failure", "messages": ["Logs are not generated"]},
    },
    {
        "name": "success",
        "test": VerifyLoggingHostname,
        "eos_data": [
            {"hostname": "NW-CORE", "fqdn": "NW-CORE.example.org"},
            "",
            "2023-05-10T15:41:44.701810-05:00 NW-CORE.example.org ConfigAgent: %SYS-6-LOGMSG_INFO: "
            "Message from arista on command-api (10.22.1.107): ANTA VerifyLoggingHostname validation\n",
        ],
        "inputs": None,
        "expected": {"result": "success"},
    },
    {
        "name": "failure",
        "test": VerifyLoggingHostname,
        "eos_data": [
            {"hostname": "NW-CORE", "fqdn": "NW-CORE.example.org"},
            "",
            "2023-05-10T13:54:21.463497-05:00 NW-CORE ConfigAgent: %SYS-6-LOGMSG_INFO: "
            "Message from arista on command-api (10.22.1.107): ANTA VerifyLoggingLogsHostname validation\n",
        ],
        "inputs": None,
        "expected": {"result": "failure", "messages": ["Logs are not generated with the device FQDN"]},
    },
    {
        "name": "success",
        "test": VerifyLoggingTimestamp,
        "eos_data": [
            "",
            "2023-05-10T15:41:44.680813-05:00 NW-CORE.example.org ConfigAgent: %SYS-6-LOGMSG_INFO: "
            "Message from arista on command-api (10.22.1.107): ANTA VerifyLoggingTimestamp validation\n"
            "2023-05-10T15:42:44.680813-05:00 NW-CORE.example.org ConfigAgent: %SYS-6-LOGMSG_INFO: "
            "Other log\n",
        ],
        "inputs": None,
        "expected": {"result": "success"},
    },
    {
        "name": "failure",
        "test": VerifyLoggingTimestamp,
        "eos_data": [
            "",
            "May 10 13:54:22 NE-CORE.example.org ConfigAgent: %SYS-6-LOGMSG_INFO: "
            "Message from arista on command-api (10.22.1.107): ANTA VerifyLoggingTimestamp validation\n",
        ],
        "inputs": None,
        "expected": {"result": "failure", "messages": ["Logs are not generated with the appropriate timestamp format"]},
    },
    {
        "name": "failure-no-matching-log",
        "test": VerifyLoggingTimestamp,
        "eos_data": [
            "",
            "May 10 13:54:22 NE-CORE.example.org ConfigAgent: %SYS-6-LOGMSG_INFO: Message from arista on command-api (10.22.1.107): BLAH\n",
        ],
        "inputs": None,
        "expected": {"result": "failure", "messages": ["Logs are not generated with the appropriate timestamp format"]},
    },
    {
        "name": "success",
        "test": VerifyLoggingAccounting,
        "eos_data": ["2023 May 10 15:50:31 arista   command-api 10.22.1.107     stop   service=shell priv-lvl=15 cmd=show aaa accounting logs | tail\n"],
        "inputs": None,
        "expected": {"result": "success"},
    },
    {
        "name": "failure",
        "test": VerifyLoggingAccounting,
        "eos_data": ["2023 May 10 15:52:26 arista   vty14       10.22.1.107     stop   service=shell priv-lvl=15 cmd=show bgp summary\n"],
        "inputs": None,
        "expected": {"result": "failure", "messages": ["AAA accounting logs are not generated"]},
    },
    {
        "name": "success",
        "test": VerifyLoggingErrors,
        "eos_data": [""],
        "inputs": None,
        "expected": {"result": "success"},
    },
    {
        "name": "failure",
        "test": VerifyLoggingErrors,
        "eos_data": [
            "Aug  2 19:57:42 DC1-LEAF1A Mlag: %FWK-3-SOCKET_CLOSE_REMOTE: Connection to Mlag (pid:27200) at tbt://192.168.0.1:4432/+n closed by peer (EOF)",
        ],
        "inputs": None,
        "expected": {"result": "failure", "messages": ["Device has reported syslog messages with a severity of ERRORS or higher"]},
    },
]