-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d6508a7
commit 5edf95e
Showing
10 changed files
with
254 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,3 +16,6 @@ | |
|
||
- name: ssh_key_authentication | ||
case: ssh_key_authentication/test.py | ||
|
||
- name: ntp_client | ||
case: ntp_client/test.py |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
=== Simple NTP client test | ||
==== Description | ||
Verify NTP client to multiple NTP servers and verify that one get selected | ||
|
||
==== Topology | ||
ifdef::topdoc[] | ||
image::../../test/case/ietf_system/ntp_client/topology.svg[Simple NTP client test topology] | ||
endif::topdoc[] | ||
ifndef::topdoc[] | ||
ifdef::testgroup[] | ||
image::ntp_client/topology.svg[Simple NTP client test topology] | ||
endif::testgroup[] | ||
ifndef::testgroup[] | ||
image::topology.svg[Simple NTP client test topology] | ||
endif::testgroup[] | ||
endif::topdoc[] | ||
==== Test sequence | ||
. Set up topology and attach to target DUT | ||
. Configure NTP client on 'target' | ||
. Verify one source is in 'selected' state on 'target' | ||
|
||
|
||
<<< | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
#!/usr/bin/env python3 | ||
""" | ||
Simple NTP client test | ||
Verify NTP client to multiple NTP servers and verify that one get selected | ||
""" | ||
|
||
import infamy | ||
import infamy.ntp_server as ntp_server | ||
import infamy.ntp as ntp | ||
import infamy.util as util | ||
def config_target(dut, data1, data2, data3): | ||
dut.put_config_dicts({ | ||
"ietf-interfaces": { | ||
"interfaces": { | ||
"interface": [ | ||
{ | ||
"name": data1, | ||
"enabled": True, | ||
"ipv4": { | ||
"address": [{ | ||
"ip": "192.168.1.2", | ||
"prefix-length": 24 | ||
}] | ||
} | ||
}, | ||
{ | ||
"name": data2, | ||
"enabled": True, | ||
"ipv4": { | ||
"address": [{ | ||
"ip": "192.168.2.2", | ||
"prefix-length": 24 | ||
}] | ||
} | ||
}, | ||
{ | ||
"name": data3, | ||
"enabled": True, | ||
"ipv4": { | ||
"address": [{ | ||
|
||
"ip": "192.168.3.2", | ||
"prefix-length": 24 | ||
}] | ||
} | ||
}] | ||
} | ||
}, | ||
"ietf-system": { | ||
"system": { | ||
"ntp": { | ||
"enabled": True, | ||
"server": [{ | ||
"name": "Server1", | ||
"udp": { | ||
"address": "192.168.1.1" | ||
}, | ||
"iburst": True | ||
},{ | ||
"name": "Server2", | ||
"udp": { | ||
"address": "192.168.2.1" | ||
}, | ||
"iburst": True | ||
},{ | ||
"name": "Server3", | ||
"udp": { | ||
"address": "192.168.3.1" | ||
}, | ||
"iburst": True | ||
}] | ||
} | ||
} | ||
} | ||
}) | ||
|
||
with infamy.Test() as test: | ||
with test.step("Set up topology and attach to target DUT"): | ||
env = infamy.Env() | ||
target = env.attach("target", "mgmt") | ||
|
||
with test.step("Configure NTP client on 'target'"): | ||
_, data1 = env.ltop.xlate("target", "data1") | ||
_, data2 = env.ltop.xlate("target", "data2") | ||
_, data3 = env.ltop.xlate("target", "data3") | ||
|
||
config_target(target, data1, data2, data3) | ||
|
||
_, hport1 = env.ltop.xlate("host", "data1") | ||
_, hport2 = env.ltop.xlate("host", "data2") | ||
_, hport3 = env.ltop.xlate("host", "data3") | ||
|
||
with infamy.IsolatedMacVlan(hport1) as ns1, \ | ||
infamy.IsolatedMacVlan(hport2) as ns2, \ | ||
infamy.IsolatedMacVlan(hport3) as ns3: | ||
ns1.addip("192.168.1.1") | ||
ns2.addip("192.168.2.1") | ||
ns3.addip("192.168.3.1") | ||
|
||
with ntp_server.Server(ns1) as ntp1, \ | ||
ntp_server.Server(ns2) as ntp2, \ | ||
ntp_server.Server(ns3) as ntp3: | ||
with test.step("Verify one source is in 'selected' state on 'target'"): | ||
util.until(lambda: ntp.any_source_selected(target), attempts=200) | ||
|
||
test.succeed() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../../infamy/topologies/1x4.dot |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
""" | ||
NTP client helper | ||
""" | ||
def _get_ntp(target): | ||
xpath="/ietf-system:system-state/infix-system:ntp" | ||
data=target.get_data(xpath) | ||
|
||
if data is None: | ||
return None | ||
|
||
return data["system-state"].get("infix-system:ntp", None) or data["system-state"].get("ntp", None) | ||
|
||
def _get_ntp_sources(target): | ||
ntp=_get_ntp(target) | ||
|
||
if ntp is None: | ||
return [] | ||
|
||
return ntp["sources"]["source"] | ||
|
||
def any_source_selected(target): | ||
sources=_get_ntp_sources(target) | ||
|
||
for source in sources: | ||
if source["source-state"] == "selected": | ||
return True | ||
|
||
return False |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
"""Start NTP server in the background""" | ||
import subprocess | ||
|
||
class Server: | ||
def __init__(self, netns, iface="iface"): | ||
self.iface = iface | ||
self.process = None | ||
self.netns = netns | ||
|
||
def __enter__(self): | ||
self.start() | ||
|
||
def __exit__(self, _, __, ___): | ||
self.stop() | ||
|
||
def start(self): | ||
cmd=f"ntpd -w -n -l -I {self.iface}" | ||
self.process = self.netns.popen(cmd.split(" "),stderr=subprocess.DEVNULL) | ||
|
||
def stop(self): | ||
if self.process: | ||
self.process.terminate() | ||
self.process.wait() | ||
self.process = None |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters