{"id":9465,"library":"anta","title":"Arista Network Test Automation (ANTA) Framework","description":"The Arista Network Test Automation (ANTA) Framework is a Python library designed for automating network device testing, specifically targeting Arista EOS devices. It provides a structured way to define, execute, and report on various network tests, supporting both CLI and programmatic workflows. As of this entry, the current version is 1.8.0, with active development and regular feature and maintenance releases.","status":"active","version":"1.8.0","language":"en","source_language":"en","source_url":"https://github.com/aristanetworks/anta","tags":["network automation","arista","testing","eos"],"install":[{"cmd":"pip install anta anta-lib-tests","lang":"bash","label":"Install core ANTA and official test library"}],"dependencies":[{"reason":"Provides the official suite of built-in ANTA tests. Many quickstart examples and common use-cases rely on these tests.","package":"anta-lib-tests","optional":false}],"imports":[{"symbol":"AntaInventory","correct":"from anta.inventory import AntaInventory"},{"note":"The core models were moved from `anta_models` to `models` in ANTA v1.0.0.","wrong":"from anta.anta_models import AntaTest","symbol":"AntaTest","correct":"from anta.models import AntaTest"},{"symbol":"ResultManager","correct":"from anta.result_manager import ResultManager"},{"note":"Requires the `anta-lib-tests` package to be installed alongside `anta`.","symbol":"VerifyReachability","correct":"from anta.tests.connectivity import VerifyReachability"},{"note":"The `main` function from `anta.runner` is designed for CLI execution and parsing `argparse` arguments. Direct programmatic execution usually involves calling test methods manually on device objects.","wrong":"import anta.runner","symbol":"main (CLI runner)","correct":"from anta.runner import main"}],"quickstart":{"code":"import os\nfrom anta.inventory import AntaInventory\nfrom anta.models import AntaTest\nfrom anta.tests.connectivity import VerifyReachability # Requires anta-lib-tests\nfrom anta.result_manager import ResultManager\n\n# 1. Define your inventory programmatically or load from a file\n# This example uses a simple in-memory inventory for a single device.\n# Replace '127.0.0.1' with your actual device's IP/hostname.\ninventory_data = {\n    \"lab\": {\n        \"hosts\": {\n            \"veos-01\": {\n                \"host\": \"127.0.0.1\",\n                \"port\": 8443,\n                \"username\": os.environ.get('ANTA_USERNAME', 'admin'),\n                \"password\": os.environ.get('ANTA_PASSWORD', 'arista'),\n                \"protocol\": \"https_vfy\"\n            }\n        }\n    }\n}\ninventory = AntaInventory(inventory_data=inventory_data)\n\n# 2. Define your tests using AntaTest objects\n# This uses a built-in test from anta-lib-tests. Adjust 'hosts' for your network.\n# Note: '1.1.1.1' and '2.2.2.2' are example unreachable hosts for a quick fail result.\n# If you have real devices, replace with actual reachable/unreachable IPs.\ntests_to_run = [\n    AntaTest(test=VerifyReachability, args={\"hosts\": [\"1.1.1.1\", \"2.2.2.2\"]})\n]\n\n# 3. Instantiate a ResultManager to collect test outcomes\nresult_manager = ResultManager()\n\n# 4. Iterate over inventory devices and execute tests\nprint(\"--- Starting ANTA tests ---\")\nfor device_name, device in inventory.get_devices().items():\n    print(f\"\\nRunning tests on device: {device_name} ({device.host})\")\n    try:\n        device.connect() # Establish connection to the device\n        for anta_test in tests_to_run:\n            # Execute each test and record its result\n            print(f\"  Executing test: {anta_test.test.__name__}...\")\n            anta_test.test(device=device, result_manager=result_manager) # Pass device and result_manager\n        device.close() # Close connection after tests\n    except Exception as e:\n        # Handle connection errors or general exceptions during test execution\n        print(f\"  ERROR during tests on {device_name}: {e}\")\n        # Add a skipped/failed result for the first test if connection failed\n        if tests_to_run:\n            result_manager.add_failure(device=device, test=tests_to_run[0].test, result=\"SKIPPED\", messages=[f\"Could not connect or run tests: {e}\"])\n        else:\n            print(f\"  No tests defined for {device_name}, but connection failed: {e}\")\n\n# 5. Print the aggregated test results\nprint(\"\\n--- ANTA Test Results Summary ---\")\nfor result in result_manager.get_results():\n    print(f\"Device: {result.name}, Test: {result.test}, Result: {result.result}\")\n    if result.messages:\n        for message in result.messages:\n            print(f\"  - {message}\")\n","lang":"python","description":"This quickstart demonstrates how to programmatically define an ANTA inventory, specify tests, execute them against a device (mocked or real), and process the results. It assumes you have `anta` and `anta-lib-tests` installed. Credentials are loaded from environment variables `ANTA_USERNAME` and `ANTA_PASSWORD`, defaulting to 'admin' and 'arista' respectively. Replace '127.0.0.1' and test host IPs with your actual environment details."},"warnings":[{"fix":"Review the official ANTA v1.0.0 migration guide and update import paths, inventory formats, and test definitions. Specifically, `AntaTest` and `AntaDevice` are now imported from `anta.models`.","message":"ANTA v1.0.0 introduced significant API changes and refactoring. Key modules like `anta.anta_models` were renamed to `anta.models`, and the overall test execution flow was redesigned.","severity":"breaking","affected_versions":"<1.0.0"},{"fix":"Ensure you install both `anta` and `anta-lib-tests`: `pip install anta anta-lib-tests`. If you omit `anta-lib-tests`, you will encounter `ModuleNotFoundError` when trying to import common tests.","message":"Built-in ANTA tests (e.g., `VerifyReachability`) are no longer part of the core `anta` package. They have been moved to a separate package, `anta-lib-tests`.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"For programmatic execution, directly instantiate `AntaInventory`, `ResultManager`, and `AntaTest` objects. Then, iterate through your inventory, connect to devices, execute `anta_test.test(device=device, result_manager=result_manager)`, and collect results from the `ResultManager`.","message":"ANTA's programmatic runner (`anta.runner.main`) is primarily designed for internal CLI use with `argparse`. Direct programmatic execution requires a more manual loop over inventory devices and tests.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Consult the latest ANTA documentation for the correct inventory YAML structure. Ensure connection parameters like `protocol` (`https_vfy` vs `https`) are correctly specified.","message":"The inventory format, especially for device connection parameters, has evolved. Older YAML inventory files might require updates, particularly for protocol specification (`https_vfy` for verified HTTPS).","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-17T00:00:00.000Z","next_check":"2026-07-16T00:00:00.000Z","problems":[{"fix":"Update your imports to `from anta.models import ...`.","cause":"Attempting to import models from the old `anta.anta_models` path, which was deprecated in v1.0.0.","error":"ModuleNotFoundError: No module named 'anta.anta_models'"},{"fix":"Install the `anta-lib-tests` package: `pip install anta-lib-tests`.","cause":"The `anta-lib-tests` package, which contains common built-in tests like `VerifyReachability`, is not installed.","error":"ModuleNotFoundError: No module named 'anta.tests.connectivity'"},{"fix":"Ensure your test execution loop calls `anta_test.test(device=device, result_manager=result_manager)`.","cause":"When running tests programmatically, you must explicitly pass the `device` object and `result_manager` to the test's `test` method.","error":"TypeError: AntaTest.test() missing 1 required positional argument: 'device'"},{"fix":"For lab environments, you can often disable certificate verification by setting `protocol: https` (without `_vfy`) in your inventory, or properly configure certificate trust. Always understand security implications before disabling verification.","cause":"The device's certificate hostname does not match the hostname used for connection, or a self-signed certificate is not trusted.","error":"Failed to establish connection to ...: SSLError('hostname '...' doesn't match '...'), (certificate verify failed: Hostname mismatch)"}]}