Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion board/common/qemu/ddi/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,11 @@ q_add_disk()
q_sect_device_usb()
{
if [ -z "$usb_bus_added" ]; then
q sect usb
case "$IX_QEMU_MACHINE" in
q35*|pc*)
q sect device piix3-usb-uhci
;;
esac
q sect device usb-ehci
q param id ehci
usb_bus_added=YES
Expand Down
15 changes: 12 additions & 3 deletions src/yangerd/internal/collector/ntp.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,8 +245,7 @@ func addAssociations(ntp map[string]interface{}, srcs []ntpSource) {
for _, src := range srcs {
d := src.data

// Skip reference clocks — they have refids, not addresses
if d.Mode == chrony.SourceModeRef {
if !resolved(d) {
continue
}

Expand Down Expand Up @@ -320,6 +319,16 @@ var sourceModeMap = map[chrony.ModeType]string{
chrony.SourceModeRef: "local-clock",
}

// resolved reports whether a chrony source has an IP address: refclocks
// carry a refid instead, and a server named by hostname has only a
// placeholder ID until DNS answers.
func resolved(d *chrony.ReplySourceData) bool {
if d.Mode == chrony.SourceModeRef || d.IPAddr == nil {
return false
}
return d.IPAddr.Family == chrony.IPAddrInet4 || d.IPAddr.Family == chrony.IPAddrInet6
}

// addSources builds the infix-system:ntp/sources/source list.
// Reference clocks and sources with invalid stratum are skipped,
// matching the Python yanger ietf_system.py add_ntp() behaviour.
Expand All @@ -328,7 +337,7 @@ func addSources(srcs []ntpSource) map[string]interface{} {
for _, src := range srcs {
d := src.data

if d.Mode == chrony.SourceModeRef {
if !resolved(d) {
continue
}
if d.Stratum > 16 {
Expand Down
30 changes: 30 additions & 0 deletions src/yangerd/internal/collector/ntp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,16 @@ func fullFakeChrony() *fakeChrony {
}
}

// unresolvedSource is a server configured by hostname that chronyd has
// not resolved yet; cmdmon reports it with an ID placeholder address.
func unresolvedSource() *chrony.ReplySourceData {
d := sourceData(nil, chrony.SourceModeClient, chrony.SourceStateUnreach,
0, 6, 0, 0, 0, 0)
d.IPAddr.Family = chrony.IPAddrID
d.IPAddr.IP[3] = 1
return d
}

func unsyncFakeChrony() *fakeChrony {
return &fakeChrony{
tracking: &chrony.ReplyTracking{
Expand Down Expand Up @@ -398,6 +408,26 @@ func ntpSourceCount(t *testing.T, tr *tree.Tree) int {
return len(ntp.Sources.Source)
}

func TestNTPUnresolvedSourceSkipped(t *testing.T) {
fake := fullFakeChrony()
fake.data = append(fake.data, unresolvedSource())
fake.stats = append(fake.stats, nil)

out, tr := ntpCollect(t, fake)
assocs := out["associations"].(map[string]interface{})["association"].([]interface{})
if len(assocs) != 3 {
t.Fatalf("expected 3 associations, got %d", len(assocs))
}
for _, a := range assocs {
if addr := a.(map[string]interface{})["address"].(string); addr == "ID#0000000001" {
t.Fatal("unresolved source leaked into associations")
}
}
if n := ntpSourceCount(t, tr); n != 4 {
t.Fatalf("expected 4 NTP sources, got %d", n)
}
}

func TestNTPSourcesEmpty(t *testing.T) {
fake := &fakeChrony{tracking: fullFakeChrony().tracking}

Expand Down
2 changes: 1 addition & 1 deletion test/templates/inc/infix-usb.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ if [ -n "{{qn_usb}}" ]; then
dd if=/dev/zero of={{qn_usb}} bs=8M count=1 >/dev/null 2>&1
mkfs.vfat {{qn_usb}} >/dev/null 2>&1
fi
usb_cmd=" -drive if=none,id=usbstick,format=raw,file={{qn_usb}} -usb -device usb-ehci,id=ehci -device usb-storage,bus=ehci.0,drive=usbstick "
usb_cmd=" -drive if=none,id=usbstick,format=raw,file={{qn_usb}} -device piix3-usb-uhci,id=uhci -device usb-ehci,id=ehci -device usb-storage,bus=ehci.0,drive=usbstick "
fi
Loading