nac-test-pyats-common 0.1.1__tar.gz → 0.2.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (36) hide show
  1. {nac_test_pyats_common-0.1.1 → nac_test_pyats_common-0.2.0}/PKG-INFO +1 -1
  2. {nac_test_pyats_common-0.1.1 → nac_test_pyats_common-0.2.0}/pyproject.toml +1 -1
  3. {nac_test_pyats_common-0.1.1 → nac_test_pyats_common-0.2.0}/src/nac_test_pyats_common/__init__.py +8 -1
  4. nac_test_pyats_common-0.2.0/src/nac_test_pyats_common/catc/__init__.py +56 -0
  5. nac_test_pyats_common-0.2.0/src/nac_test_pyats_common/catc/device_resolver.py +164 -0
  6. nac_test_pyats_common-0.2.0/src/nac_test_pyats_common/catc/ssh_test_base.py +115 -0
  7. {nac_test_pyats_common-0.1.1 → nac_test_pyats_common-0.2.0}/src/nac_test_pyats_common/common/base_device_resolver.py +78 -180
  8. {nac_test_pyats_common-0.1.1 → nac_test_pyats_common-0.2.0}/src/nac_test_pyats_common/iosxe/test_base.py +6 -0
  9. {nac_test_pyats_common-0.1.1 → nac_test_pyats_common-0.2.0}/src/nac_test_pyats_common/sdwan/device_resolver.py +53 -21
  10. {nac_test_pyats_common-0.1.1 → nac_test_pyats_common-0.2.0}/src/nac_test_pyats_common/sdwan/ssh_test_base.py +11 -9
  11. nac_test_pyats_common-0.2.0/tests/unit/catc/__init__.py +4 -0
  12. nac_test_pyats_common-0.2.0/tests/unit/catc/test_auth.py +344 -0
  13. nac_test_pyats_common-0.2.0/tests/unit/catc/test_device_resolver.py +533 -0
  14. {nac_test_pyats_common-0.1.1 → nac_test_pyats_common-0.2.0}/tests/unit/test_base_device_resolver.py +601 -431
  15. nac_test_pyats_common-0.1.1/src/nac_test_pyats_common/catc/__init__.py +0 -38
  16. nac_test_pyats_common-0.1.1/src/nac_test_pyats_common/iosxe/catc_resolver.py +0 -67
  17. {nac_test_pyats_common-0.1.1 → nac_test_pyats_common-0.2.0}/.gitignore +0 -0
  18. {nac_test_pyats_common-0.1.1 → nac_test_pyats_common-0.2.0}/LICENSE +0 -0
  19. {nac_test_pyats_common-0.1.1 → nac_test_pyats_common-0.2.0}/README.md +0 -0
  20. {nac_test_pyats_common-0.1.1 → nac_test_pyats_common-0.2.0}/src/nac_test_pyats_common/aci/__init__.py +0 -0
  21. {nac_test_pyats_common-0.1.1 → nac_test_pyats_common-0.2.0}/src/nac_test_pyats_common/aci/auth.py +0 -0
  22. {nac_test_pyats_common-0.1.1 → nac_test_pyats_common-0.2.0}/src/nac_test_pyats_common/aci/test_base.py +0 -0
  23. /nac_test_pyats_common-0.1.1/src/nac_test_pyats_common/catc/test_base.py → /nac_test_pyats_common-0.2.0/src/nac_test_pyats_common/catc/api_test_base.py +0 -0
  24. {nac_test_pyats_common-0.1.1 → nac_test_pyats_common-0.2.0}/src/nac_test_pyats_common/catc/auth.py +0 -0
  25. {nac_test_pyats_common-0.1.1 → nac_test_pyats_common-0.2.0}/src/nac_test_pyats_common/common/__init__.py +0 -0
  26. {nac_test_pyats_common-0.1.1 → nac_test_pyats_common-0.2.0}/src/nac_test_pyats_common/iosxe/__init__.py +0 -0
  27. {nac_test_pyats_common-0.1.1 → nac_test_pyats_common-0.2.0}/src/nac_test_pyats_common/iosxe/iosxe_resolver.py +0 -0
  28. {nac_test_pyats_common-0.1.1 → nac_test_pyats_common-0.2.0}/src/nac_test_pyats_common/iosxe/registry.py +0 -0
  29. {nac_test_pyats_common-0.1.1 → nac_test_pyats_common-0.2.0}/src/nac_test_pyats_common/py.typed +0 -0
  30. {nac_test_pyats_common-0.1.1 → nac_test_pyats_common-0.2.0}/src/nac_test_pyats_common/sdwan/__init__.py +0 -0
  31. {nac_test_pyats_common-0.1.1 → nac_test_pyats_common-0.2.0}/src/nac_test_pyats_common/sdwan/api_test_base.py +0 -0
  32. {nac_test_pyats_common-0.1.1 → nac_test_pyats_common-0.2.0}/src/nac_test_pyats_common/sdwan/auth.py +0 -0
  33. {nac_test_pyats_common-0.1.1 → nac_test_pyats_common-0.2.0}/tests/__init__.py +0 -0
  34. {nac_test_pyats_common-0.1.1 → nac_test_pyats_common-0.2.0}/tests/unit/__init__.py +0 -0
  35. {nac_test_pyats_common-0.1.1 → nac_test_pyats_common-0.2.0}/tests/unit/iosxe/__init__.py +0 -0
  36. {nac_test_pyats_common-0.1.1 → nac_test_pyats_common-0.2.0}/tests/unit/iosxe/test_registry.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: nac-test-pyats-common
3
- Version: 0.1.1
3
+ Version: 0.2.0
4
4
  Summary: Architecture adapters for Network as Code (NaC) PyATS testing - auth classes, test base classes, and device resolvers
5
5
  Project-URL: Homepage, https://github.com/netascode/nac-test-pyats-common
6
6
  Project-URL: Documentation, https://github.com/netascode/nac-test-pyats-common
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "nac-test-pyats-common"
3
- version = "0.1.1"
3
+ version = "0.2.0"
4
4
  description = "Architecture adapters for Network as Code (NaC) PyATS testing - auth classes, test base classes, and device resolvers"
5
5
  readme = "README.md"
6
6
  requires-python = ">=3.10"
@@ -29,7 +29,12 @@ __version__ = "1.0.0"
29
29
 
30
30
  # Public API - Import from subpackages
31
31
  from nac_test_pyats_common.aci import APICAuth, APICTestBase
32
- from nac_test_pyats_common.catc import CatalystCenterAuth, CatalystCenterTestBase
32
+ from nac_test_pyats_common.catc import (
33
+ CatalystCenterAuth,
34
+ CatalystCenterDeviceResolver,
35
+ CatalystCenterSSHTestBase,
36
+ CatalystCenterTestBase,
37
+ )
33
38
  from nac_test_pyats_common.sdwan import (
34
39
  SDWANDeviceResolver,
35
40
  SDWANManagerAuth,
@@ -49,4 +54,6 @@ __all__ = [
49
54
  # Catalyst Center
50
55
  "CatalystCenterAuth",
51
56
  "CatalystCenterTestBase",
57
+ "CatalystCenterSSHTestBase",
58
+ "CatalystCenterDeviceResolver",
52
59
  ]
@@ -0,0 +1,56 @@
1
+ # SPDX-License-Identifier: MPL-2.0
2
+ # Copyright (c) 2025 Daniel Schmidt
3
+
4
+ """Catalyst Center adapter module for NAC PyATS testing.
5
+
6
+ This module provides Catalyst Center-specific authentication, test base classes, and
7
+ device resolver implementations for use with the nac-test framework. It includes support
8
+ for both Catalyst Center API testing and SSH-based device-to-device (D2D) testing.
9
+
10
+ Classes:
11
+ CatalystCenterAuth: Token-based authentication with automatic endpoint
12
+ detection.
13
+ CatalystCenterTestBase: Base class for Catalyst Center API tests with
14
+ tracking.
15
+ CatalystCenterSSHTestBase: Base class for Catalyst Center SSH/D2D tests
16
+ with device inventory.
17
+ CatalystCenterDeviceResolver: Resolves device information from the
18
+ Catalyst Center data model.
19
+
20
+ Example:
21
+ For Catalyst Center API testing:
22
+
23
+ >>> from nac_test_pyats_common.catc import CatalystCenterTestBase
24
+ >>>
25
+ >>> class VerifyNetworkDevices(CatalystCenterTestBase):
26
+ ... async def get_items_to_verify(self):
27
+ ... return ['device-uuid-1', 'device-uuid-2']
28
+ ...
29
+ ... async def verify_item(self, item):
30
+ ... response = await self.client.get(
31
+ ... f"/dna/intent/api/v1/network-device/{item}"
32
+ ... )
33
+ ... return response.status_code == 200
34
+
35
+ For SSH/D2D testing:
36
+
37
+ >>> from nac_test_pyats_common.catc import CatalystCenterSSHTestBase
38
+ >>>
39
+ >>> class VerifyInterfaceStatus(CatalystCenterSSHTestBase):
40
+ ... @aetest.test
41
+ ... def verify_interfaces(self, steps, device):
42
+ ... # SSH-based verification
43
+ ... pass
44
+ """
45
+
46
+ from .api_test_base import CatalystCenterTestBase
47
+ from .auth import CatalystCenterAuth
48
+ from .device_resolver import CatalystCenterDeviceResolver
49
+ from .ssh_test_base import CatalystCenterSSHTestBase
50
+
51
+ __all__ = [
52
+ "CatalystCenterAuth",
53
+ "CatalystCenterTestBase",
54
+ "CatalystCenterSSHTestBase",
55
+ "CatalystCenterDeviceResolver",
56
+ ]
@@ -0,0 +1,164 @@
1
+ # SPDX-License-Identifier: MPL-2.0
2
+ # Copyright (c) 2025 Daniel Schmidt
3
+
4
+ """Catalyst Center-specific device resolver for parsing the NAC data model.
5
+
6
+ This module provides the CatalystCenterDeviceResolver class, which extends
7
+ BaseDeviceResolver to implement Catalyst Center schema navigation for D2D testing.
8
+ """
9
+
10
+ import logging
11
+ from typing import Any
12
+
13
+ from nac_test_pyats_common.common import BaseDeviceResolver
14
+ from nac_test_pyats_common.iosxe.registry import register_iosxe_resolver
15
+
16
+ logger = logging.getLogger(__name__)
17
+
18
+
19
+ @register_iosxe_resolver("CC")
20
+ class CatalystCenterDeviceResolver(BaseDeviceResolver):
21
+ """Catalyst Center device resolver for D2D testing.
22
+
23
+ Navigates the Catalyst Center NAC schema (catalyst_center.inventory.devices[])
24
+ to extract device information for SSH testing.
25
+
26
+ Schema structure:
27
+ catalyst_center:
28
+ inventory:
29
+ devices:
30
+ - name: P3-BN1
31
+ fqdn_name: P3-BN1.cisco.eu
32
+ device_ip: 192.168.38.1
33
+ pid: C9300-24P
34
+ state: PROVISION
35
+ device_role: ACCESS
36
+ site: Global/MAX_AREA/MAX_BUILDING
37
+
38
+ Credentials:
39
+ Uses IOSXE_USERNAME and IOSXE_PASSWORD environment variables
40
+ for SSH access to managed IOS-XE devices.
41
+
42
+ Example:
43
+ >>> resolver = CatalystCenterDeviceResolver(data_model)
44
+ >>> devices = resolver.get_resolved_inventory()
45
+ >>> for device in devices:
46
+ ... print(f"{device['hostname']}: {device['host']}")
47
+ """
48
+
49
+ def get_architecture_name(self) -> str:
50
+ """Return 'catalyst_center' as the architecture identifier.
51
+
52
+ Returns:
53
+ Architecture name used in logging and error messages.
54
+ """
55
+ return "catalyst_center"
56
+
57
+ def get_schema_root_key(self) -> str:
58
+ """Return 'catalyst_center' as the root key in the data model.
59
+
60
+ Returns:
61
+ Root key used when navigating the schema.
62
+ """
63
+ return "catalyst_center"
64
+
65
+ def navigate_to_devices(self) -> list[dict[str, Any]]:
66
+ """Navigate Catalyst Center schema: catalyst_center.inventory.devices[].
67
+
68
+ Traverses the Catalyst Center data model structure to find all
69
+ managed devices in the inventory.
70
+
71
+ Returns:
72
+ List of device dictionaries from the inventory.
73
+ """
74
+ devices: list[dict[str, Any]] = []
75
+ cc_data = self.data_model.get("catalyst_center", {})
76
+ inventory = cc_data.get("inventory", {})
77
+ devices.extend(inventory.get("devices", []))
78
+ return devices
79
+
80
+ def validate_device_data(self, device_data: dict[str, Any]) -> None:
81
+ """Validate device state before extraction.
82
+
83
+ Skip devices with INIT or PNP states as they are not fully provisioned.
84
+
85
+ Args:
86
+ device_data: Device data dictionary from the data model.
87
+
88
+ Raises:
89
+ ValueError: If the device has an unsupported state (INIT, PNP).
90
+ """
91
+ state = device_data.get("state", "").upper()
92
+ if state in ("INIT", "PNP"):
93
+ raise ValueError(
94
+ f"Device has unsupported state '{state}' "
95
+ "(devices in INIT or PNP state are not fully provisioned)"
96
+ )
97
+
98
+ def extract_hostname(self, device_data: dict[str, Any]) -> str:
99
+ """Extract hostname from the 'name' field.
100
+
101
+ Uses the device name as the hostname for SSH connections.
102
+
103
+ Args:
104
+ device_data: Device data dictionary from the data model.
105
+
106
+ Returns:
107
+ Device hostname string.
108
+ """
109
+ name = device_data.get("name")
110
+ if not name:
111
+ raise ValueError("Device missing 'name' field")
112
+ return str(name)
113
+
114
+ def extract_host_ip(self, device_data: dict[str, Any]) -> str:
115
+ """Extract management IP from device_ip field.
116
+
117
+ Reads the device_ip field directly from the device data.
118
+ Handles CIDR notation if present (e.g., "10.1.1.100/32" -> "10.1.1.100").
119
+
120
+ Args:
121
+ device_data: Device data dictionary from the data model.
122
+
123
+ Returns:
124
+ IP address string without CIDR notation (e.g., "192.168.38.1").
125
+
126
+ Raises:
127
+ ValueError: If device_ip field is not found.
128
+ """
129
+ device_ip = device_data.get("device_ip")
130
+ if not device_ip:
131
+ raise ValueError(
132
+ "Device missing 'device_ip' field. "
133
+ "Ensure device_ip is configured in the inventory."
134
+ )
135
+
136
+ ip_value = str(device_ip)
137
+
138
+ # Strip CIDR notation if present
139
+ if "/" in ip_value:
140
+ ip_value = ip_value.split("/")[0]
141
+
142
+ return ip_value
143
+
144
+ def extract_os_type(self, device_data: dict[str, Any]) -> str:
145
+ """Return 'iosxe' as all managed devices are IOS-XE based.
146
+
147
+ Args:
148
+ device_data: Device data dictionary (unused, OS is hardcoded).
149
+
150
+ Returns:
151
+ Always returns 'iosxe'.
152
+ """
153
+ return "iosxe"
154
+
155
+ def get_credential_env_vars(self) -> tuple[str, str]:
156
+ """Return IOS-XE credential env vars for managed devices.
157
+
158
+ Catalyst Center D2D tests connect to IOS-XE devices,
159
+ NOT the Catalyst Center controller.
160
+
161
+ Returns:
162
+ Tuple of (username_env_var, password_env_var).
163
+ """
164
+ return ("IOSXE_USERNAME", "IOSXE_PASSWORD")
@@ -0,0 +1,115 @@
1
+ # SPDX-License-Identifier: MPL-2.0
2
+ # Copyright (c) 2025 Daniel Schmidt
3
+
4
+ """Catalyst Center specific base test class for SSH/Direct-to-Device testing.
5
+
6
+ This module provides the CatalystCenterSSHTestBase class, which extends the generic
7
+ SSHTestBase to add Catalyst Center-specific functionality for device-to-device (D2D)
8
+ testing.
9
+
10
+ The class delegates device inventory resolution to CatalystCenterDeviceResolver, which
11
+ handles all Catalyst Center schema navigation and credential injection.
12
+
13
+ Credentials:
14
+ Catalyst Center D2D tests connect to IOS-XE devices managed by Catalyst Center,
15
+ NOT the Catalyst Center controller. Set these environment variables:
16
+ - IOSXE_USERNAME: SSH username for managed devices
17
+ - IOSXE_PASSWORD: SSH password for managed devices
18
+ """
19
+
20
+ import logging
21
+ import os
22
+ from typing import Any
23
+
24
+ from nac_test.pyats_core.common.ssh_base_test import (
25
+ SSHTestBase, # type: ignore[import-untyped]
26
+ )
27
+
28
+ from .device_resolver import CatalystCenterDeviceResolver
29
+
30
+ logger = logging.getLogger(__name__)
31
+
32
+
33
+ class CatalystCenterSSHTestBase(SSHTestBase): # type: ignore[misc]
34
+ """Catalyst Center-specific base test class for SSH/D2D testing.
35
+
36
+ This class extends SSHTestBase and implements the contract required by
37
+ nac-test's SSH execution engine. Device inventory resolution is fully
38
+ delegated to CatalystCenterDeviceResolver.
39
+
40
+ Credentials:
41
+ Catalyst Center D2D tests require IOSXE_USERNAME and IOSXE_PASSWORD
42
+ environment variables (NOT CC_* which are for the controller).
43
+
44
+ Example:
45
+ class MyCatalystCenterSSHTest(CatalystCenterSSHTestBase):
46
+ @aetest.test
47
+ def verify_device_connectivity(self, steps, device):
48
+ # SSH-based verification logic here
49
+ pass
50
+ """
51
+
52
+ # Class-level storage for the last resolver instance
53
+ # This allows nac-test to access skipped_devices after calling
54
+ # get_ssh_device_inventory()
55
+ _last_resolver: "CatalystCenterDeviceResolver | None" = None
56
+
57
+ @classmethod
58
+ def get_ssh_device_inventory(
59
+ cls, data_model: dict[str, Any]
60
+ ) -> list[dict[str, Any]]:
61
+ """Parse the Catalyst Center data model to retrieve the device inventory.
62
+
63
+ This method is the entry point called by nac-test's orchestrator.
64
+ All device inventory resolution is delegated to CatalystCenterDeviceResolver,
65
+ which handles:
66
+ - Schema navigation (catalyst_center.inventory.devices[])
67
+ - Device metadata extraction (name, device_ip, etc.)
68
+ - Credential injection (IOSXE_USERNAME, IOSXE_PASSWORD)
69
+
70
+ After calling this method, access cls._last_resolver.skipped_devices
71
+ to get information about devices that failed resolution.
72
+
73
+ Args:
74
+ data_model: The merged data model from nac-test containing all
75
+ configuration data with resolved variables.
76
+
77
+ Returns:
78
+ List of device dictionaries, each containing:
79
+ - hostname (str): Device hostname
80
+ - host (str): Management IP address for SSH connection
81
+ - os (str): Operating system type (e.g., "iosxe")
82
+ - username (str): SSH username from IOSXE_USERNAME
83
+ - password (str): SSH password from IOSXE_PASSWORD
84
+ - device_id (str): Device identifier (name)
85
+
86
+ Raises:
87
+ ValueError: If IOSXE_USERNAME or IOSXE_PASSWORD env vars are not set.
88
+ """
89
+ logger.info(
90
+ "CatalystCenterSSHTestBase: Resolving device inventory via "
91
+ "CatalystCenterDeviceResolver"
92
+ )
93
+
94
+ cls._last_resolver = CatalystCenterDeviceResolver(data_model)
95
+ return cls._last_resolver.get_resolved_inventory()
96
+
97
+ def get_device_credentials(self, device: dict[str, Any]) -> dict[str, str | None]:
98
+ """Get Catalyst Center managed device SSH credentials from env vars.
99
+
100
+ Catalyst Center D2D tests connect to IOS-XE devices managed by
101
+ Catalyst Center, NOT the Catalyst Center controller. Use IOSXE_*
102
+ environment variables.
103
+
104
+ Args:
105
+ device: Device dictionary (not used - all devices share credentials).
106
+
107
+ Returns:
108
+ Dictionary containing:
109
+ - username (str | None): SSH username from IOSXE_USERNAME
110
+ - password (str | None): SSH password from IOSXE_PASSWORD
111
+ """
112
+ return {
113
+ "username": os.environ.get("IOSXE_USERNAME"),
114
+ "password": os.environ.get("IOSXE_PASSWORD"),
115
+ }