1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
|
"""Live VyOS smoke tests for pyvyos.
These are intentionally a small, opinionated subset of the SDK:
just enough to prove that payloads round-trip against a real VyOS
HTTPS API. Destructive operations (reboot/poweroff/image-add/
image-delete/reset/config-file-load) live in a separate file when
they exist; not in scope for v0.4.x.
"""
from __future__ import annotations
import random
from pyvyos import ApiResponse, VyDevice
def _ok(response: ApiResponse) -> None:
assert response.status == 200, f"status={response.status} error={response.error!r}"
assert not response.error, f"unexpected error: {response.error!r}"
def _dummy_name() -> str:
"""VyOS requires dummy interfaces to match `dumN`.
Pick a high random N to avoid collision with anything an operator
may have created manually.
"""
return f"dum{random.randint(900, 9999)}"
def test_show_system_image(device: VyDevice) -> None:
response = device.show(path=["system", "image"])
_ok(response)
assert response.result is not None
def test_retrieve_show_config_system(device: VyDevice) -> None:
response = device.retrieve_show_config(path=["system"])
_ok(response)
assert isinstance(response.result, dict)
def test_configure_set_read_delete_dummy_iface(device: VyDevice) -> None:
name = _dummy_name()
address = "192.0.2.10/32"
iface_path = ["interfaces", "dummy", name]
try:
set_response = device.configure_set(path=iface_path + ["address", address])
_ok(set_response)
read_response = device.retrieve_return_values(path=iface_path + ["address"])
_ok(read_response)
# retrieve_return_values returns a list of stringified values.
assert address in str(read_response.result), read_response.result
finally:
cleanup = device.configure_delete(path=iface_path)
_ok(cleanup)
def test_configure_multiple_op_batch(device: VyDevice) -> None:
name = _dummy_name()
iface_path = ["interfaces", "dummy", name]
response = device.configure_multiple_op(
op_path=[
{"op": "set", "path": iface_path + ["address", "192.0.2.11/32"]},
{"op": "delete", "path": iface_path},
]
)
_ok(response)
|