#!/bin/sh

set -e

. ./helpers

ME=$(basename $0)

# With an empty DHCP_HTTP_BOOT_URL, no HTTP Boot match must be
# emitted at all, for either daemon: this is what configuration files
# predating that option keep getting.

setup_sandbox
sed -i -e 's/^DHCP_HTTP_BOOT_URL=.*/DHCP_HTTP_BOOT_URL=/' "${SANDBOX}/etc/ikvswitch.conf"

run_setup start
assert_eq "ikvswitch-setup start rc (dnsmasq)" "${SETUP_RC}" "0"

DNQ=${SANDBOX}/out/leaf1/etc/dnsmasq.d/ikvswitch.conf
assert_file_contains "dnsmasq config" "${DNQ}" "dhcp-boot=tag:ipxe,http://192.168.100.2/oci/ipxe.php"
assert_file_not_contains "dnsmasq config" "${DNQ}" "httpboot"
assert_file_not_contains "dnsmasq config" "${DNQ}" "openstack-cluster-installer"

sed -i -e 's/^DHCP_SERVER_DAEMON=.*/DHCP_SERVER_DAEMON=isc-dhcp/' "${SANDBOX}/etc/ikvswitch.conf"

run_setup start
assert_eq "ikvswitch-setup start rc (isc-dhcp)" "${SETUP_RC}" "0"

DHCPD=${SANDBOX}/out/leaf1/etc/dhcp/dhcpd.conf
assert_file_contains "dhcpd.conf" "${DHCPD}" "if option pxe-system-type = 00:09 {"
assert_file_not_contains "dhcpd.conf" "${DHCPD}" "00:10"
assert_file_not_contains "dhcpd.conf" "${DHCPD}" "openstack-cluster-installer"

# An empty value is legitimate, so start must not complain.
assert_not_contains "ikvswitch-setup start output" "${OUT}" "Please set"
assert_not_contains "ikvswitch-setup start output" "${OUT}" "must start with"

exit 0
