. "$KOLA_EXT_DATA/commonlib.sh"
ntp_test_setup() {
ntp_host_ip=$1
ip netns add container
ip link add veth-host type veth peer name veth-container
ip link set veth-container netns container
ip netns exec container ip address add 172.16.0.1/24 dev veth-container
ip netns exec container ip link set veth-container up
pushd "$(mktemp -d)"
container=$(get_fedora_container_ref)
cat <<EOF >Dockerfile
FROM $container
RUN rm -f /etc/yum.repos.d/*.repo \
&& curl -L https://raw.githubusercontent.com/coreos/fedora-coreos-config/testing-devel/fedora-archive.repo -o /etc/yum.repos.d/fedora-archive.repo
RUN dnf -y install systemd dnsmasq iproute iputils \
&& dnf clean all \
&& systemctl enable dnsmasq
RUN echo -e 'dhcp-range=172.16.0.10,172.16.0.20,12h\nbind-interfaces\ninterface=veth-container\ndhcp-option=option:ntp-server,$ntp_host_ip' > /etc/dnsmasq.d/dhcp
CMD [ "/sbin/init" ]
EOF
podman build -t dnsmasq .
popd
podman run -d --rm --name dnsmasq --privileged --network ns:/var/run/netns/container dnsmasq
nmcli dev set veth-host managed yes
ip link set veth-host up
}
check_for_ntp_server() {
ntp_host_ip=$1
ntp_sources_cmd=$2
ntp_server=""
retries=300
while [[ $retries -gt 0 ]]; do
ntp_sources=$($ntp_sources_cmd)
[[ "$ntp_sources" =~ "$ntp_host_ip" ]] && break
echo "waiting for ntp server to appear"
sleep 1
retries=$((retries - 1))
done
if [ $retries -eq 0 ]; then
fatal "propagation of ntp server information via dhcp failed"
fi
}