Skip to content

Commit

Permalink
kola/tests/misc: add test to verify the DHCP propagation of NTP servers
Browse files Browse the repository at this point in the history
Writing this test to verify coreos/fedora-coreos-config#412
to enable the DHCP propagation of NTP servers. We don't need this test once the
upstream/downstream patch merges.
upstream patch: https://listengine.tuxfamily.org/chrony.tuxfamily.org/chrony-dev/2020/05/msg00023.html
downstream patch: https://src.fedoraproject.org/rpms/chrony/pull-request/3
  • Loading branch information
sohankunkerkar committed Aug 19, 2020
1 parent 99ea017 commit 0698e0a
Showing 1 changed file with 80 additions and 0 deletions.
80 changes: 80 additions & 0 deletions mantle/kola/tests/misc/chronydhcp.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
// Copyright 2020 Red Hat
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package misc

import (
"strings"
"time"

"github.com/coreos/mantle/kola"
"github.com/coreos/mantle/kola/cluster"
"github.com/coreos/mantle/kola/register"
"github.com/coreos/mantle/platform/conf"
"github.com/coreos/mantle/util"
)

func init() {
register.RegisterTest(&register.Test{
Name: "coreos.chrony.dhcp.verify",
Run: verifyDHCPPropagationOfNTPServers,
ClusterSize: 1,
Tags: []string{"chrony", "dhcp", "ntp", kola.NeedsInternetTag},
UserDataV3: conf.Ignition(`{
"ignition": {"version": "3.0.0"},
"storage": {
"files": [
{
"group": {},
"path": "/usr/local/bin/setup.sh",
"user": {},
"contents": {
"source": "data:,%23!%2Fbin%2Fbash%0A%0A%23%20This%20script%20creates%20two%20veth%20interfaces%20i.e.%20one%20for%20the%20host%20machine%20%0A%23%20and%20other%20for%20the%20container(dnsmasq%20server).%20This%20setup%20will%20be%20helpful%0A%23%20to%20verify%20the%20DHCP%20propagation%20of%20NTP%20servers%0A%23%20https%3A%2F%2Fgithub.com%2Fcoreos%2Ffedora-coreos-config%2Fpull%2F412%0A%0A%23%20This%20is%20needed%20to%20run%20a%20container%20with%20systemd%0Asetsebool%20container_manage_cgroup%201%0A%0A%23%20create%20a%20network%20namespace%0Aip%20netns%20add%20container%0A%0A%23%20create%20veth%20pair%20and%20assign%20a%20namespace%20to%20veth-container%0Aip%20link%20add%20veth-host%20type%20veth%20peer%20name%20veth-container%0Aip%20link%20set%20veth-container%20netns%20container%0A%0A%23%20assign%20an%20IP%20address%20to%20the%20%60veth-container%60%20interface%20and%20bring%20it%20up%0Aip%20netns%20exec%20container%20ip%20address%20add%20172.16.0.1%2F24%20dev%20veth-container%0Aip%20netns%20exec%20container%20ip%20link%20set%20veth-container%20up%0A%0A%23%20create%20a%20static%20ethernet%20connection%20for%20the%20%60veth-host%60%0Anmcli%20dev%20set%20veth-host%20managed%20yes%0Aip%20link%20set%20veth-host%20up%0A%0A%23%20run%20podman%20commands%20to%20set%20up%20dnsmasq%20server%0Apodman%20run%20-d%20--rm%20--name%20dnsmasq%20--privileged%20--network%20ns%3A%2Fvar%2Frun%2Fnetns%2Fcontainer%20quay.io%2Fsohankunkerkar%2Fdnsmasq%0Apodman%20exec%20-it%20dnsmasq%20%2Fbin%2Fbash%20-c%20%22echo%20-e%20'dhcp-range%3D172.16.0.10%2C172.16.0.20%2C12h%5Cnbind-interfaces%5Cninterface%3Dveth-container%5Cndhcp-option%3Doption%3Antp-server%2C129.6.15.30'%20%3E%3E%20%2Fetc%2Fdnsmasq.d%2Fdhcp%3B%20sudo%20systemctl%20restart%20dnsmasq.service%22",
"verification": {}
},
"mode": 493
}
]
},
"systemd": {
"units": [
{
"contents": "[Unit]\nDescription=verify chrony using NTP settings from DHCP\n[Service]\nType=oneshot\nExecStart=/usr/local/bin/setup.sh\nRestart=on-failure\nRemainAfterExit=yes\n[Install]\nWantedBy=multi-user.target\n",
"name": "chrony-dhcp.service"
}
]
}
}`),
})
}

func verifyDHCPPropagationOfNTPServers(c cluster.TestCluster) {
m := c.Machines()[0]
// Wait a little bit for the chrony-dhcp.service to start
if err := util.WaitUntilReady(10*time.Minute, 5*time.Second, func() (bool, error) {
_, _, err := m.SSH("sudo systemctl start chrony-dhcp.service")
if err != nil {
return false, err
}
return true, nil
}); err != nil {
c.Fatal("failed to start chrony-dhcp.service: %v", err)
}

out := c.MustSSH(m, "chronyc sources")
// Name: time-c-g.nist.gov IP address: 129.6.15.30
if !strings.Contains(string(out), "time-c-g.nist.gov") {
c.Fatalf("propagation of ntp server information via dhcp failed")
}
}

0 comments on commit 0698e0a

Please sign in to comment.