Skip to content

Commit 86f702b

Browse files
committed
test: add new tests for NTP
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
1 parent 0617445 commit 86f702b

File tree

32 files changed

+1235
-1
lines changed

32 files changed

+1235
-1
lines changed

test/case/all.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@
3232
- name: "Interfaces"
3333
suite: interfaces/all.yaml
3434

35+
- name: "NTP Server"
36+
suite: ntp/all.yaml
37+
3538
- name: "Routing"
3639
suite: routing/all.yaml
3740

test/case/ntp/Readme.adoc

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
:testgroup:
2+
== NTP Server Tests
3+
4+
Tests for NTP server functionality across different operational modes:
5+
6+
- Standalone mode: local reference clock only
7+
- Server mode: sync from upstream while serving clients
8+
- Peer mode: bidirectional synchronization between peers
9+
- Server and client interoperability
10+
- Makestep configuration for initial sync
11+
12+
include::server_mode_standalone/Readme.adoc[]
13+
14+
<<<
15+
16+
include::server_mode_server/Readme.adoc[]
17+
18+
<<<
19+
20+
include::server_mode_peer/Readme.adoc[]
21+
22+
<<<
23+
24+
include::server_client/Readme.adoc[]
25+
26+
<<<
27+
28+
include::server_makestep/Readme.adoc[]

test/case/ntp/all.yaml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
---
2+
- name: NTP server standalone mode
3+
case: server_mode_standalone/test.py
4+
5+
- name: NTP server mode
6+
case: server_mode_server/test.py
7+
8+
- name: NTP peer mode
9+
case: server_mode_peer/test.py
10+
11+
- name: NTP server and client interoperability
12+
case: server_client/test.py
13+
14+
- name: NTP server makestep configuration
15+
case: server_makestep/test.py

test/case/ntp/ntp.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
name: ntp
2+
description: NTP server and client tests
3+
tests:
4+
- server_basic
5+
- server_mutual_exclusion
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
test.adoc
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
=== NTP server and client interoperability
2+
3+
ifdef::topdoc[:imagesdir: {topdoc}../../test/case/ntp/server_client]
4+
5+
==== Description
6+
7+
Verify NTP server (ietf-ntp) and client (ietf-system:ntp) work together.
8+
9+
This test verifies:
10+
1. Server uses ietf-ntp YANG model with refclock-master
11+
2. Client uses ietf-system:ntp YANG model
12+
3. Client successfully synchronizes from server
13+
4. Server shows packet statistics
14+
5. Mutual exclusion prevents both modes on same device
15+
16+
==== Topology
17+
18+
image::topology.svg[NTP server and client interoperability topology, align=center, scaledwidth=75%]
19+
20+
==== Sequence
21+
22+
. Set up topology and attach to devices
23+
. Configure NTP server using ietf-ntp model
24+
. Configure NTP client using ietf-system:ntp model
25+
. Verify NTP server has received packets
26+
. Verify NTP client has synchronized
27+
28+
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
#!/usr/bin/env python3
2+
"""NTP server and client interoperability test
3+
4+
Verify NTP server (ietf-ntp) and client (ietf-system:ntp) work together.
5+
6+
This test verifies:
7+
1. Server uses ietf-ntp YANG model with refclock-master
8+
2. Client uses ietf-system:ntp YANG model
9+
3. Client successfully synchronizes from server
10+
4. Server shows packet statistics
11+
5. Mutual exclusion prevents both modes on same device
12+
"""
13+
14+
import infamy
15+
from infamy import until
16+
import infamy.ntp as ntp
17+
18+
19+
with infamy.Test() as test:
20+
with test.step("Set up topology and attach to devices"):
21+
env = infamy.Env()
22+
server = env.attach("server", "mgmt")
23+
client = env.attach("client", "mgmt")
24+
25+
_, server_data = env.ltop.xlate("server", "data")
26+
_, client_data = env.ltop.xlate("client", "data")
27+
28+
with test.step("Configure NTP server using ietf-ntp model"):
29+
server.put_config_dicts({
30+
"ietf-interfaces": {
31+
"interfaces": {
32+
"interface": [{
33+
"name": server_data,
34+
"enabled": True,
35+
"ipv4": {
36+
"address": [{
37+
"ip": "192.168.3.1",
38+
"prefix-length": 24
39+
}]
40+
}
41+
}]
42+
}
43+
},
44+
"ietf-ntp": {
45+
"ntp": {
46+
"refclock-master": {
47+
"master-stratum": 8
48+
},
49+
"interfaces": {
50+
"interface": [
51+
{"name": server_data}
52+
]
53+
}
54+
}
55+
}
56+
})
57+
58+
with test.step("Configure NTP client using ietf-system:ntp model"):
59+
client.put_config_dicts({
60+
"ietf-interfaces": {
61+
"interfaces": {
62+
"interface": [{
63+
"name": client_data,
64+
"enabled": True,
65+
"ipv4": {
66+
"address": [{
67+
"ip": "192.168.3.2",
68+
"prefix-length": 24
69+
}]
70+
}
71+
}]
72+
}
73+
},
74+
"ietf-system": {
75+
"system": {
76+
"ntp": {
77+
"enabled": True,
78+
"server": [{
79+
"name": "ntp-server",
80+
"udp": {
81+
"address": "192.168.3.1"
82+
},
83+
"iburst": True
84+
}]
85+
}
86+
}
87+
}
88+
})
89+
90+
with test.step("Verify NTP server has received packets"):
91+
until(lambda: ntp.server_has_received_packets(server), attempts=30)
92+
93+
with test.step("Verify NTP client has synchronized"):
94+
until(lambda: ntp.any_source_selected(client), attempts=30)
95+
96+
test.succeed()
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
graph "ntp-server-client-interop" {
2+
layout="neato";
3+
overlap="false";
4+
esep="+22";
5+
6+
node [shape=record, fontname="DejaVu Sans Mono, Book"];
7+
edge [color="cornflowerblue", penwidth="2", fontname="DejaVu Serif, Book"];
8+
9+
host [
10+
label="{ <mgmt1> mgmt1 | <host> \n\nhost\n\n\n | <mgmt2> mgmt2 }",
11+
pos="0,15!",
12+
requires="controller",
13+
];
14+
15+
server [
16+
label="{ <mgmt> mgmt | <data> data } | { server }",
17+
pos="2,15.25!",
18+
fontsize=12,
19+
requires="infix",
20+
];
21+
22+
client [
23+
label="{ <data> data | <mgmt> mgmt } | { client }",
24+
pos="2,14.75!",
25+
fontsize=12,
26+
requires="infix",
27+
];
28+
29+
host:mgmt1 -- server:mgmt [requires="mgmt", color="lightgray"]
30+
host:mgmt2 -- client:mgmt [requires="mgmt" color="lightgrey"]
31+
32+
server:data -- client:data [label="\n\n192.168.3.0/24 "]
33+
}
Lines changed: 58 additions & 0 deletions
Loading
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
test.adoc

0 commit comments

Comments
 (0)