|
| 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() |
0 commit comments