-
Notifications
You must be signed in to change notification settings - Fork 30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(anta.tests): Added testcase to verify domain name to IP address translation #534
Changes from 1 commit
f6ecd52
52975b9
b52b47f
d732d53
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,48 @@ | ||||||
# 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. | ||||||
""" | ||||||
Test functions related to the EOS various service settings | ||||||
""" | ||||||
from __future__ import annotations | ||||||
|
||||||
from typing import List | ||||||
|
||||||
from anta.models import AntaCommand, AntaTemplate, AntaTest | ||||||
|
||||||
# Mypy does not understand AntaTest.Input typing | ||||||
# mypy: disable-error-code=attr-defined | ||||||
|
||||||
|
||||||
class VerifyDNSLookup(AntaTest): | ||||||
""" | ||||||
This class verifies the DNS(Domain name service) name to IP address translation. | ||||||
|
||||||
Expected Results: | ||||||
* success: The test will pass if a domain name is resolved to an IP address. | ||||||
* failure: The test will fail if a domain name does not resolve to an IP address. | ||||||
* error: This test will error out if a domain name is not correct. | ||||||
carl-baillargeon marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
""" | ||||||
|
||||||
name = "VerifyDNSLookup" | ||||||
description = "Verifies the DNS(Domain name service) name to IP address translation." | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
categories = ["services"] | ||||||
commands = [AntaTemplate(template="bash timeout 10 nslookup {domain}")] | ||||||
|
||||||
class Input(AntaTest.Input): | ||||||
"""Inputs for the VerifyDNSLookup test.""" | ||||||
|
||||||
domain_names: List[str] | ||||||
"""List of domain names""" | ||||||
|
||||||
def render(self, template: AntaTemplate) -> list[AntaCommand]: | ||||||
return [template.render(domain=domain_name) for domain_name in self.inputs.domain_names] | ||||||
|
||||||
@AntaTest.anta_test | ||||||
def test(self) -> None: | ||||||
self.result.is_success() | ||||||
for command in self.instance_commands: | ||||||
domain = command.params["domain"] | ||||||
output = command.json_output["messages"][0] | ||||||
if f"Can't find {domain}: No answer" in output: | ||||||
carl-baillargeon marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
self.result.is_failure(f"Domain {domain} is not resolved to an IP address.") | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you add the failed domains in a list or set and have a single failure message like: The following domain(s) are not resolved to an IP address: google.ca, arista.com |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,46 @@ | ||||||
# 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. | ||||||
""" | ||||||
Tests for anta.tests.security.py | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
""" | ||||||
from __future__ import annotations | ||||||
|
||||||
from typing import Any | ||||||
|
||||||
from anta.tests.services import VerifyDNSLookup | ||||||
from tests.lib.anta import test # noqa: F401; pylint: disable=W0611 | ||||||
|
||||||
DATA: list[dict[str, Any]] = [ | ||||||
{ | ||||||
"name": "success", | ||||||
"test": VerifyDNSLookup, | ||||||
"eos_data": [ | ||||||
{ | ||||||
"messages": [ | ||||||
"Server:\t\t127.0.0.1\nAddress:\t127.0.0.1#53\n\nNon-authoritative answer:\nName:\tarista.com\nAddress: 151.101.130.132\nName:\tarista.com\n" | ||||||
"Address: 151.101.2.132\nName:\tarista.com\nAddress: 151.101.194.132\nName:\tarista.com\nAddress: 151.101.66.132\n\n" | ||||||
] | ||||||
}, | ||||||
{"messages": ["Server:\t\t127.0.0.1\nAddress:\t127.0.0.1#53\n\nNon-authoritative answer:\nName:\twww.google.com\nAddress: 172.217.12.100\n\n"]}, | ||||||
], | ||||||
"inputs": {"domain_names": ["arista.com", "www.google.com"]}, | ||||||
"expected": {"result": "success"}, | ||||||
}, | ||||||
{ | ||||||
"name": "failure", | ||||||
"test": VerifyDNSLookup, | ||||||
"eos_data": [ | ||||||
{ | ||||||
"messages": [ | ||||||
"Server:\t\t127.0.0.1\nAddress:\t127.0.0.1#53\n\nNon-authoritative answer:\nName:\tarista.com\nAddress: 151.101.130.132\nName:\tarista.com\n" | ||||||
"Address: 151.101.2.132\nName:\tarista.com\nAddress: 151.101.194.132\nName:\tarista.com\nAddress: 151.101.66.132\n\n" | ||||||
] | ||||||
}, | ||||||
{"messages": ["Server:\t\t127.0.0.1\nAddress:\t127.0.0.1#53\n\nNon-authoritative answer:\nName:\twww.google.com\nAddress: 172.217.12.100\n\n"]}, | ||||||
{"messages": ["Server:\t\t127.0.0.1\nAddress:\t127.0.0.1#53\n\nNon-authoritative answer:\n*** Can't find khatri.com: No answer\n\n"]}, | ||||||
], | ||||||
"inputs": {"domain_names": ["arista.com", "www.google.com", "khatri.com"]}, | ||||||
"expected": {"result": "failure", "messages": ["Domain khatri.com is not resolved to an IP address."]}, | ||||||
}, | ||||||
] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.