From 1fd6a618b60d7168fd8f37585d5d39d22d775afd Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Thu, 28 Mar 2024 07:11:39 +0100 Subject: Adding upstream version 0.13.0. Signed-off-by: Daniel Baumann --- tests/data/__init__.py | 3 + tests/data/ansible_inventory.yml | 47 ++++ tests/data/empty | 0 tests/data/empty_ansible_inventory.yml | 1 + tests/data/expected_anta_inventory.yml | 16 ++ tests/data/json_data.py | 258 +++++++++++++++++++++ tests/data/syntax_error.py | 7 + tests/data/template.j2 | 3 + tests/data/test_catalog.yml | 5 + tests/data/test_catalog_not_a_list.yml | 2 + ...test_catalog_test_definition_multiple_dicts.yml | 9 + .../test_catalog_test_definition_not_a_dict.yml | 3 + .../data/test_catalog_with_syntax_error_module.yml | 2 + tests/data/test_catalog_with_tags.yml | 28 +++ tests/data/test_catalog_with_undefined_module.yml | 3 + .../test_catalog_with_undefined_module_nested.yml | 4 + tests/data/test_catalog_with_undefined_tests.yml | 3 + tests/data/test_catalog_wrong_type.yml | 1 + tests/data/test_empty_catalog.yml | 0 tests/data/test_inventory.yml | 12 + tests/data/test_snapshot_commands.yml | 8 + tests/data/toto.yml | 16 ++ 22 files changed, 431 insertions(+) create mode 100644 tests/data/__init__.py create mode 100644 tests/data/ansible_inventory.yml create mode 100644 tests/data/empty create mode 100644 tests/data/empty_ansible_inventory.yml create mode 100644 tests/data/expected_anta_inventory.yml create mode 100644 tests/data/json_data.py create mode 100644 tests/data/syntax_error.py create mode 100644 tests/data/template.j2 create mode 100644 tests/data/test_catalog.yml create mode 100644 tests/data/test_catalog_not_a_list.yml create mode 100644 tests/data/test_catalog_test_definition_multiple_dicts.yml create mode 100644 tests/data/test_catalog_test_definition_not_a_dict.yml create mode 100644 tests/data/test_catalog_with_syntax_error_module.yml create mode 100644 tests/data/test_catalog_with_tags.yml create mode 100644 tests/data/test_catalog_with_undefined_module.yml create mode 100644 tests/data/test_catalog_with_undefined_module_nested.yml create mode 100644 tests/data/test_catalog_with_undefined_tests.yml create mode 100644 tests/data/test_catalog_wrong_type.yml create mode 100644 tests/data/test_empty_catalog.yml create mode 100644 tests/data/test_inventory.yml create mode 100644 tests/data/test_snapshot_commands.yml create mode 100644 tests/data/toto.yml (limited to 'tests/data') diff --git a/tests/data/__init__.py b/tests/data/__init__.py new file mode 100644 index 0000000..e772bee --- /dev/null +++ b/tests/data/__init__.py @@ -0,0 +1,3 @@ +# 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. diff --git a/tests/data/ansible_inventory.yml b/tests/data/ansible_inventory.yml new file mode 100644 index 0000000..a958505 --- /dev/null +++ b/tests/data/ansible_inventory.yml @@ -0,0 +1,47 @@ +--- +all: + children: + cv_servers: + hosts: + cv_atd1: + ansible_host: 10.73.1.238 + ansible_user: tom + ansible_password: arista123 + cv_collection: v3 + ATD_LAB: + vars: + ansible_user: arista + ansible_ssh_pass: arista + children: + ATD_FABRIC: + children: + ATD_SPINES: + vars: + type: spine + hosts: + spine1: + ansible_host: 192.168.0.10 + spine2: + ansible_host: 192.168.0.11 + ATD_LEAFS: + vars: + type: l3leaf + children: + pod1: + hosts: + leaf1: + ansible_host: 192.168.0.12 + leaf2: + ansible_host: 192.168.0.13 + pod2: + hosts: + leaf3: + ansible_host: 192.168.0.14 + leaf4: + ansible_host: 192.168.0.15 + ATD_TENANTS_NETWORKS: + children: + ATD_LEAFS: + ATD_SERVERS: + children: + ATD_LEAFS: diff --git a/tests/data/empty b/tests/data/empty new file mode 100644 index 0000000..e69de29 diff --git a/tests/data/empty_ansible_inventory.yml b/tests/data/empty_ansible_inventory.yml new file mode 100644 index 0000000..ed97d53 --- /dev/null +++ b/tests/data/empty_ansible_inventory.yml @@ -0,0 +1 @@ +--- diff --git a/tests/data/expected_anta_inventory.yml b/tests/data/expected_anta_inventory.yml new file mode 100644 index 0000000..c0f92cb --- /dev/null +++ b/tests/data/expected_anta_inventory.yml @@ -0,0 +1,16 @@ +anta_inventory: + hosts: + - host: 10.73.1.238 + name: cv_atd1 + - host: 192.168.0.10 + name: spine1 + - host: 192.168.0.11 + name: spine2 + - host: 192.168.0.12 + name: leaf1 + - host: 192.168.0.13 + name: leaf2 + - host: 192.168.0.14 + name: leaf3 + - host: 192.168.0.15 + name: leaf4 diff --git a/tests/data/json_data.py b/tests/data/json_data.py new file mode 100644 index 0000000..ad2c9ed --- /dev/null +++ b/tests/data/json_data.py @@ -0,0 +1,258 @@ +# 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. +# pylint: skip-file + +INVENTORY_MODEL_HOST_VALID = [ + {"name": "validIPv4", "input": "1.1.1.1", "expected_result": "valid"}, + { + "name": "validIPv6", + "input": "fe80::cc62:a9ff:feef:932a", + }, +] + +INVENTORY_MODEL_HOST_INVALID = [ + { + "name": "invalidIPv4_with_netmask", + "input": "1.1.1.1/32", + }, + { + "name": "invalidIPv6_with_netmask", + "input": "fe80::cc62:a9ff:feef:932a/128", + }, + {"name": "invalidHost_format", "input": "@", "expected_result": "invalid"}, + { + "name": "invalidIPv6_format", + "input": "fe80::cc62:a9ff:feef:", + }, +] + +INVENTORY_MODEL_HOST_CACHE = [ + {"name": "Host cache default", "input": {"host": "1.1.1.1"}, "expected_result": False}, + {"name": "Host cache enabled", "input": {"host": "1.1.1.1", "disable_cache": False}, "expected_result": False}, + {"name": "Host cache disabled", "input": {"host": "1.1.1.1", "disable_cache": True}, "expected_result": True}, +] + +INVENTORY_MODEL_NETWORK_VALID = [ + {"name": "ValidIPv4_Subnet", "input": "1.1.1.0/24", "expected_result": "valid"}, + {"name": "ValidIPv6_Subnet", "input": "2001:db8::/32", "expected_result": "valid"}, +] + +INVENTORY_MODEL_NETWORK_INVALID = [ + {"name": "ValidIPv4_Subnet", "input": "1.1.1.0/17", "expected_result": "invalid"}, + { + "name": "InvalidIPv6_Subnet", + "input": "2001:db8::/16", + "expected_result": "invalid", + }, +] + +INVENTORY_MODEL_NETWORK_CACHE = [ + {"name": "Network cache default", "input": {"network": "1.1.1.0/24"}, "expected_result": False}, + {"name": "Network cache enabled", "input": {"network": "1.1.1.0/24", "disable_cache": False}, "expected_result": False}, + {"name": "Network cache disabled", "input": {"network": "1.1.1.0/24", "disable_cache": True}, "expected_result": True}, +] + +INVENTORY_MODEL_RANGE_VALID = [ + { + "name": "ValidIPv4_Range", + "input": {"start": "10.1.0.1", "end": "10.1.0.10"}, + "expected_result": "valid", + }, +] + +INVENTORY_MODEL_RANGE_INVALID = [ + { + "name": "InvalidIPv4_Range_name", + "input": {"start": "toto", "end": "10.1.0.1"}, + "expected_result": "invalid", + }, +] + +INVENTORY_MODEL_RANGE_CACHE = [ + {"name": "Range cache default", "input": {"start": "1.1.1.1", "end": "1.1.1.10"}, "expected_result": False}, + {"name": "Range cache enabled", "input": {"start": "1.1.1.1", "end": "1.1.1.10", "disable_cache": False}, "expected_result": False}, + {"name": "Range cache disabled", "input": {"start": "1.1.1.1", "end": "1.1.1.10", "disable_cache": True}, "expected_result": True}, +] + +INVENTORY_MODEL_VALID = [ + { + "name": "Valid_Host_Only", + "input": {"hosts": [{"host": "192.168.0.17"}, {"host": "192.168.0.2"}]}, + "expected_result": "valid", + }, + { + "name": "Valid_Networks_Only", + "input": {"networks": [{"network": "192.168.0.0/16"}, {"network": "192.168.1.0/24"}]}, + "expected_result": "valid", + }, + { + "name": "Valid_Ranges_Only", + "input": { + "ranges": [ + {"start": "10.1.0.1", "end": "10.1.0.10"}, + {"start": "10.2.0.1", "end": "10.2.1.10"}, + ] + }, + "expected_result": "valid", + }, +] + +INVENTORY_MODEL_INVALID = [ + { + "name": "Host_with_Invalid_entry", + "input": {"hosts": [{"host": "192.168.0.17"}, {"host": "192.168.0.2/32"}]}, + "expected_result": "invalid", + }, +] + +INVENTORY_DEVICE_MODEL_VALID = [ + { + "name": "Valid_Inventory", + "input": [{"host": "1.1.1.1", "username": "arista", "password": "arista123!"}, {"host": "1.1.1.2", "username": "arista", "password": "arista123!"}], + "expected_result": "valid", + }, +] + +INVENTORY_DEVICE_MODEL_INVALID = [ + { + "name": "Invalid_Inventory", + "input": [{"host": "1.1.1.1", "password": "arista123!"}, {"host": "1.1.1.1", "username": "arista"}], + "expected_result": "invalid", + }, +] + +ANTA_INVENTORY_TESTS_VALID = [ + { + "name": "ValidInventory_with_host_only", + "input": {"anta_inventory": {"hosts": [{"host": "192.168.0.17"}, {"host": "192.168.0.2"}, {"host": "my.awesome.host.com"}]}}, + "expected_result": "valid", + "parameters": { + "ipaddress_in_scope": "192.168.0.17", + "ipaddress_out_of_scope": "192.168.1.1", + "nb_hosts": 2, + }, + }, + { + "name": "ValidInventory_with_networks_only", + "input": {"anta_inventory": {"networks": [{"network": "192.168.0.0/24"}]}}, + "expected_result": "valid", + "parameters": { + "ipaddress_in_scope": "192.168.0.1", + "ipaddress_out_of_scope": "192.168.1.1", + "nb_hosts": 256, + }, + }, + { + "name": "ValidInventory_with_ranges_only", + "input": { + "anta_inventory": { + "ranges": [ + {"start": "10.0.0.1", "end": "10.0.0.11"}, + {"start": "10.0.0.101", "end": "10.0.0.111"}, + ] + } + }, + "expected_result": "valid", + "parameters": { + "ipaddress_in_scope": "10.0.0.10", + "ipaddress_out_of_scope": "192.168.1.1", + "nb_hosts": 22, + }, + }, + { + "name": "ValidInventory_with_host_port", + "input": {"anta_inventory": {"hosts": [{"host": "192.168.0.17", "port": 443}, {"host": "192.168.0.2", "port": 80}]}}, + "expected_result": "valid", + "parameters": { + "ipaddress_in_scope": "192.168.0.17", + "ipaddress_out_of_scope": "192.168.1.1", + "nb_hosts": 2, + }, + }, + { + "name": "ValidInventory_with_host_tags", + "input": {"anta_inventory": {"hosts": [{"host": "192.168.0.17", "tags": ["leaf"]}, {"host": "192.168.0.2", "tags": ["spine"]}]}}, + "expected_result": "valid", + "parameters": { + "ipaddress_in_scope": "192.168.0.17", + "ipaddress_out_of_scope": "192.168.1.1", + "nb_hosts": 2, + }, + }, + { + "name": "ValidInventory_with_networks_tags", + "input": {"anta_inventory": {"networks": [{"network": "192.168.0.0/24", "tags": ["leaf"]}]}}, + "expected_result": "valid", + "parameters": { + "ipaddress_in_scope": "192.168.0.1", + "ipaddress_out_of_scope": "192.168.1.1", + "nb_hosts": 256, + }, + }, + { + "name": "ValidInventory_with_ranges_tags", + "input": { + "anta_inventory": { + "ranges": [ + {"start": "10.0.0.1", "end": "10.0.0.11", "tags": ["leaf"]}, + {"start": "10.0.0.101", "end": "10.0.0.111", "tags": ["spine"]}, + ] + } + }, + "expected_result": "valid", + "parameters": { + "ipaddress_in_scope": "10.0.0.10", + "ipaddress_out_of_scope": "192.168.1.1", + "nb_hosts": 22, + }, + }, +] + +ANTA_INVENTORY_TESTS_INVALID = [ + { + "name": "InvalidInventory_with_host_only", + "input": {"anta_inventory": {"hosts": [{"host": "192.168.0.17/32"}, {"host": "192.168.0.2"}]}}, + "expected_result": "invalid", + }, + { + "name": "InvalidInventory_wrong_network_bits", + "input": {"anta_inventory": {"networks": [{"network": "192.168.42.0/8"}]}}, + "expected_result": "invalid", + }, + { + "name": "InvalidInventory_wrong_network", + "input": {"anta_inventory": {"networks": [{"network": "toto"}]}}, + "expected_result": "invalid", + }, + { + "name": "InvalidInventory_wrong_range", + "input": {"anta_inventory": {"ranges": [{"start": "toto", "end": "192.168.42.42"}]}}, + "expected_result": "invalid", + }, + { + "name": "InvalidInventory_wrong_range_type_mismatch", + "input": {"anta_inventory": {"ranges": [{"start": "fe80::cafe", "end": "192.168.42.42"}]}}, + "expected_result": "invalid", + }, + { + "name": "Invalid_Root_Key", + "input": { + "inventory": { + "ranges": [ + {"start": "10.0.0.1", "end": "10.0.0.11"}, + {"start": "10.0.0.100", "end": "10.0.0.111"}, + ] + } + }, + "expected_result": "invalid", + }, +] + +TEST_RESULT_SET_STATUS = [ + {"name": "set_success", "target": "success", "message": "success"}, + {"name": "set_error", "target": "error", "message": "error"}, + {"name": "set_failure", "target": "failure", "message": "failure"}, + {"name": "set_skipped", "target": "skipped", "message": "skipped"}, + {"name": "set_unset", "target": "unset", "message": "unset"}, +] diff --git a/tests/data/syntax_error.py b/tests/data/syntax_error.py new file mode 100644 index 0000000..051ef33 --- /dev/null +++ b/tests/data/syntax_error.py @@ -0,0 +1,7 @@ +# 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. +# pylint: skip-file +# flake8: noqa +# type: ignore +typo diff --git a/tests/data/template.j2 b/tests/data/template.j2 new file mode 100644 index 0000000..e8820fe --- /dev/null +++ b/tests/data/template.j2 @@ -0,0 +1,3 @@ +{% for d in data %} +* {{ d.test }} is [green]{{ d.result | upper}}[/green] for {{ d.name }} +{% endfor %} diff --git a/tests/data/test_catalog.yml b/tests/data/test_catalog.yml new file mode 100644 index 0000000..c5b55b0 --- /dev/null +++ b/tests/data/test_catalog.yml @@ -0,0 +1,5 @@ +--- +anta.tests.software: + - VerifyEOSVersion: + versions: + - 4.31.1F diff --git a/tests/data/test_catalog_not_a_list.yml b/tests/data/test_catalog_not_a_list.yml new file mode 100644 index 0000000..d8c4297 --- /dev/null +++ b/tests/data/test_catalog_not_a_list.yml @@ -0,0 +1,2 @@ +--- +anta.tests.configuration: true diff --git a/tests/data/test_catalog_test_definition_multiple_dicts.yml b/tests/data/test_catalog_test_definition_multiple_dicts.yml new file mode 100644 index 0000000..9287ee6 --- /dev/null +++ b/tests/data/test_catalog_test_definition_multiple_dicts.yml @@ -0,0 +1,9 @@ +--- +anta.tests.software: + - VerifyEOSVersion: + versions: + - 4.25.4M + - 4.26.1F + VerifyTerminAttrVersion: + versions: + - 4.25.4M diff --git a/tests/data/test_catalog_test_definition_not_a_dict.yml b/tests/data/test_catalog_test_definition_not_a_dict.yml new file mode 100644 index 0000000..052ad26 --- /dev/null +++ b/tests/data/test_catalog_test_definition_not_a_dict.yml @@ -0,0 +1,3 @@ +--- +anta.tests.software: + - VerifyEOSVersion diff --git a/tests/data/test_catalog_with_syntax_error_module.yml b/tests/data/test_catalog_with_syntax_error_module.yml new file mode 100644 index 0000000..8b3e00a --- /dev/null +++ b/tests/data/test_catalog_with_syntax_error_module.yml @@ -0,0 +1,2 @@ +--- +tests.data.syntax_error: diff --git a/tests/data/test_catalog_with_tags.yml b/tests/data/test_catalog_with_tags.yml new file mode 100644 index 0000000..0c8f5f6 --- /dev/null +++ b/tests/data/test_catalog_with_tags.yml @@ -0,0 +1,28 @@ +--- +anta.tests.system: + - VerifyUptime: + minimum: 10 + filters: + tags: ['fabric'] + - VerifyReloadCause: + filters: + tags: ['leaf', 'spine'] + - VerifyCoredump: + - VerifyAgentLogs: + - VerifyCPUUtilization: + filters: + tags: ['leaf'] + - VerifyMemoryUtilization: + filters: + tags: ['testdevice'] + - VerifyFileSystemUtilization: + - VerifyNTP: + +anta.tests.mlag: + - VerifyMlagStatus: + +anta.tests.interfaces: + - VerifyL3MTU: + mtu: 1500 + filters: + tags: ['demo'] diff --git a/tests/data/test_catalog_with_undefined_module.yml b/tests/data/test_catalog_with_undefined_module.yml new file mode 100644 index 0000000..f2e116b --- /dev/null +++ b/tests/data/test_catalog_with_undefined_module.yml @@ -0,0 +1,3 @@ +--- +anta.tests.undefined: + - MyTest: diff --git a/tests/data/test_catalog_with_undefined_module_nested.yml b/tests/data/test_catalog_with_undefined_module_nested.yml new file mode 100644 index 0000000..cf0f393 --- /dev/null +++ b/tests/data/test_catalog_with_undefined_module_nested.yml @@ -0,0 +1,4 @@ +--- +anta.tests: + undefined: + - MyTest: diff --git a/tests/data/test_catalog_with_undefined_tests.yml b/tests/data/test_catalog_with_undefined_tests.yml new file mode 100644 index 0000000..8282714 --- /dev/null +++ b/tests/data/test_catalog_with_undefined_tests.yml @@ -0,0 +1,3 @@ +--- +anta.tests.software: + - FakeTest: diff --git a/tests/data/test_catalog_wrong_type.yml b/tests/data/test_catalog_wrong_type.yml new file mode 100644 index 0000000..3f8f043 --- /dev/null +++ b/tests/data/test_catalog_wrong_type.yml @@ -0,0 +1 @@ +"Not a string" diff --git a/tests/data/test_empty_catalog.yml b/tests/data/test_empty_catalog.yml new file mode 100644 index 0000000..e69de29 diff --git a/tests/data/test_inventory.yml b/tests/data/test_inventory.yml new file mode 100644 index 0000000..d0ca457 --- /dev/null +++ b/tests/data/test_inventory.yml @@ -0,0 +1,12 @@ +--- +anta_inventory: + hosts: + - name: dummy + host: dummy.anta.ninja + tags: ["leaf"] + - name: dummy2 + host: dummy2.anta.ninja + tags: ["leaf"] + - name: dummy3 + host: dummy3.anta.ninja + tags: ["spine"] diff --git a/tests/data/test_snapshot_commands.yml b/tests/data/test_snapshot_commands.yml new file mode 100644 index 0000000..d2ee8dc --- /dev/null +++ b/tests/data/test_snapshot_commands.yml @@ -0,0 +1,8 @@ +--- +# list of EOS commands to collect in JSON format +json_format: + - show version + +# list of EOS commands to collect in text format +text_format: + - show version diff --git a/tests/data/toto.yml b/tests/data/toto.yml new file mode 100644 index 0000000..c0f92cb --- /dev/null +++ b/tests/data/toto.yml @@ -0,0 +1,16 @@ +anta_inventory: + hosts: + - host: 10.73.1.238 + name: cv_atd1 + - host: 192.168.0.10 + name: spine1 + - host: 192.168.0.11 + name: spine2 + - host: 192.168.0.12 + name: leaf1 + - host: 192.168.0.13 + name: leaf2 + - host: 192.168.0.14 + name: leaf3 + - host: 192.168.0.15 + name: leaf4 -- cgit v1.2.3