Created
November 12, 2019 09:06
-
-
Save dzerrenner/fb5a0517018105fb6ef308c4b0973b67 to your computer and use it in GitHub Desktop.
Test NTP connection with pytest
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
import ntplib | |
import pytest | |
from time import ctime | |
class Test_ntp(object): | |
@pytest.mark.report_section("NTP") | |
def test_ntp(self, ipsec, ntpserver): | |
""" | |
NTP-Request via ipsec from different environments. | |
""" | |
print("ipsec return code: " ipsec.ipsec_exit_status) | |
print("ipsec client ip: " ipsec.client_ip) | |
if ipsec.connection_status != "established": | |
pytest.xfail("Failing because of ipsec connection could not be established") | |
print(f"sending NTP request to {ntpserver}") | |
_, target = ntpserver | |
client = ntplib.NTPClient() | |
# An exceptions is raised if an error would occur from ntplib.NTPException | |
res = client.request(str(target)) | |
time = ctime(res.tx_time) | |
print = (f"NTP response; Stratum: {res.stratum}, time: {time}") | |
assert(res.stratum > 0) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment