Device API¶
The device module provides device abstraction classes for different types of network devices and hosts.
Device Management Module.
This module provides device abstraction classes that represent different types of network devices and hosts. Each device class encapsulates device-specific information such as credentials, hostnames, and device type characteristics.
The module implements a device hierarchy with an abstract base class and concrete implementations for different device types:
- Device (ABC): Abstract base class defining the device interface
- LinuxDevice: Represents Linux-based network devices and hosts
- OneOS6Device: Represents OneOS6 router/switch devices
- RADIUSServer: Specialized Linux device for RADIUS authentication
- HostDevice: Utility class for executing commands on the local host
Classes:
| Name | Description |
|---|---|
Device |
Abstract base class for all device types |
LinuxDevice |
Linux/Unix-based device implementation |
OneOS6Device |
OneOS6 network device implementation |
RADIUSServer |
RADIUS server device (extends LinuxDevice) |
HostDevice |
Local host command execution utility |
Example
Basic device usage:
from router_test_kit.device import LinuxDevice, OneOS6Device
# Create different device types
linux_vm = LinuxDevice(username="admin", password="secret")
router = OneOS6Device(username="admin", password="admin")
# Device types are automatically set
print(linux_vm.type) # "linux"
print(router.type) # "oneos"
Note
Device objects store connection credentials but do not manage connections themselves. Connections are handled by the Connection classes which use Device objects to obtain authentication information.
Classes¶
Device ¶
Bases: ABC
Abstract base class for network devices and hosts.
This class provides a common interface for all device types, storing essential information such as credentials, hostname, and device type. Device objects are used by Connection classes to obtain authentication information and device-specific characteristics.
Each device subclass defines default values for username, password, and prompt symbols that are appropriate for that device type. These defaults can be overridden during instantiation.
Attributes:
| Name | Type | Description |
|---|---|---|
username |
Optional[str]
|
Authentication username for the device |
password |
Optional[str]
|
Authentication password for the device |
hostname |
Optional[str]
|
Network hostname or identifier |
type |
str
|
Device type identifier (read-only property) |
Class Attributes
DEFAULT_USERNAME (str): Default username for this device type DEFAULT_PASSWORD (str): Default password for this device type DEFAULT_PROMPT_SYMBOL (str): Default command prompt symbol
Example
This is an abstract class and cannot be instantiated directly:
Note
Device objects are passive containers for device information. They do not establish or manage network connections. Use Connection classes for actual network communication.
Source code in src/router_test_kit/device.py
Attributes¶
type
property
¶
Get the device type identifier.
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
Device type string (e.g., "linux", "oneos") |
Functions¶
__init__ ¶
Initialize a new device instance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
username
|
Optional[str]
|
Authentication username. Uses class default if None. |
None
|
password
|
Optional[str]
|
Authentication password. Uses class default if None. |
None
|
Note
This is an abstract class and should not be instantiated directly. Use concrete implementations like LinuxDevice or OneOS6Device.
Source code in src/router_test_kit/device.py
LinuxDevice ¶
Bases: Device
Linux/Unix-based device implementation.
Represents Linux, Unix, or other POSIX-compatible devices and virtual machines. This class is commonly used for Linux-based network appliances, virtual machines, and general-purpose Linux hosts.
The class provides appropriate defaults for Linux systems:
- Default username: "user"
- Default password: "user"
- Default prompt: "$" (changes to "#" for root)
Attributes:
| Name | Type | Description |
|---|---|---|
All |
attributes inherited from Device class, plus
|
|
hostname |
str
|
Auto-generated hostname in format "linux-{username}" |
Example
Source code in src/router_test_kit/device.py
Attributes¶
type
property
¶
Get the device type identifier.
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
Device type string (e.g., "linux", "oneos") |
Functions¶
__init__ ¶
Initialize a Linux device.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
username
|
Optional[str]
|
Linux username. Defaults to "user" if None. |
None
|
password
|
Optional[str]
|
Linux password. Defaults to "user" if None. |
None
|
Source code in src/router_test_kit/device.py
RADIUSServer ¶
Bases: LinuxDevice
RADIUS authentication server device.
Specialized Linux device for RADIUS (Remote Authentication Dial-In User Service) servers. Inherits all Linux device functionality but uses a specific hostname identifier for RADIUS services.
This class is typically used in network testing scenarios that require authentication services for devices like routers and switches.
Example
Source code in src/router_test_kit/device.py
Attributes¶
type
property
¶
Get the device type identifier.
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
Device type string (e.g., "linux", "oneos") |
Functions¶
__init__ ¶
Initialize a RADIUS server device.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
username
|
Optional[str]
|
RADIUS server admin username. Defaults to "user" if None. |
None
|
password
|
Optional[str]
|
RADIUS server admin password. Defaults to "user" if None. |
None
|
Source code in src/router_test_kit/device.py
OneOS6Device ¶
Bases: Device
OneOS6 network device implementation.
Represents OneOS6-based routers and switches. OneOS6 is a network operating system commonly used in enterprise routing and switching equipment.
The class provides appropriate defaults for OneOS6 devices: - Default username: "admin" - Default password: "admin" - Default prompt: "#" (privileged mode)
Attributes:
| Name | Type | Description |
|---|---|---|
All |
attributes inherited from Device class, plus
|
|
PHYSICAL_INTERFACES_LIST |
List[str]
|
Supported interface types |
Class Attributes
PHYSICAL_INTERFACES_LIST: List of supported physical interface types that can be extended based on specific device models
Example
Note
The PHYSICAL_INTERFACES_LIST can be extended in subclasses to support additional interface types for specific OneOS6 device models.
Source code in src/router_test_kit/device.py
Attributes¶
type
property
¶
Get the device type identifier.
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
Device type string (e.g., "linux", "oneos") |
Functions¶
__init__ ¶
Initialize a OneOS6 device.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
username
|
Optional[str]
|
OneOS6 admin username. Defaults to "admin" if None. |
None
|
password
|
Optional[str]
|
OneOS6 admin password. Defaults to "admin" if None. |
None
|
Source code in src/router_test_kit/device.py
HostDevice ¶
Local host command execution utility.
This class provides static methods for executing shell commands on the local host system. It's designed for scenarios where tests need to run commands on the host machine running the test suite.
The class uses the modern subprocess.run API with proper error handling, timeout support, and flexible output management.
Example
# Basic command execution
result = HostDevice.write_command("echo 'Hello World'")
print(result) # "Hello World"
# With error handling
result = HostDevice.write_command("nonexistent_command", quiet=True)
print(result) # None (command failed)
# With logging
result = HostDevice.write_command("ls -la", print_response=True)
# Logs command execution details
Note
All methods are static since this class doesn't maintain state. Commands are executed with a 30-second timeout by default.
Source code in src/router_test_kit/device.py
255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 | |
Functions¶
write_command
staticmethod
¶
Execute a shell command on the local host system.
Executes the specified command using subprocess.run with proper error handling and timeout support. Returns combined stdout/stderr output or None if the command fails.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
command
|
str
|
Shell command to execute |
required |
print_response
|
bool
|
Whether to log successful command execution details |
False
|
quiet
|
bool
|
Whether to suppress error logging for failed commands |
False
|
Returns:
| Type | Description |
|---|---|
Optional[str]
|
Combined command output (stdout + stderr) if successful, None if failed |
Raises:
| Type | Description |
|---|---|
None
|
All exceptions are caught and handled internally |
Example
Note
Commands are executed with shell=True, so shell features like pipes and redirects are supported. A 30-second timeout is enforced.