tests: Add tests for <lease/> to cover dnsmasq settings

New tests are required to cover some new XML syntax entry for
<lease/> option. This includes schema testing and other features
like unit attribute and lease value. This commit includes hostsfile
checks adding new files for each test case that is manipulating <host/>
tag.

Signed-off-by: Julio Faracco <jcfaracco@gmail.com>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
Julio Faracco 2020-04-22 17:05:58 -03:00 committed by Michal Privoznik
parent 97a0aa2467
commit 7e5a40fd0f
32 changed files with 225 additions and 2 deletions

View File

@ -0,0 +1,7 @@
00:16:3e:77:e2:ed,192.168.122.10,a.example.com
00:16:3e:3e:a9:1a,192.168.122.11,b.example.com
id:0:4:7e:7d:f0:7d:a8:bc:c5:d2:13:32:11:ed:16:ea:84:63,[2001:db8:ac10:fd01::1:20]
paul,[2001:db8:ac10:fd01::1:21]
id:0:3:0:1:0:16:3e:11:22:33,peter.xyz,[2001:db8:ac10:fd01::1:22]
id:0:3:0:1:0:16:3e:44:55:33,[2001:db8:ac10:fd01::1:23]
id:0:1:0:1:18:aa:62:fe:0:16:3e:44:55:66,badbob,[2001:db8:ac10:fd01::1:24]

View File

@ -0,0 +1,5 @@
id:0:4:7e:7d:f0:7d:a8:bc:c5:d2:13:32:11:ed:16:ea:84:63,[2001:db8:ac10:fd01::1:20]
paul,[2001:db8:ac10:fd01::1:21]
id:0:3:0:1:0:16:3e:11:22:33,peter.xyz,[2001:db8:ac10:fd01::1:22]
id:0:3:0:1:0:16:3e:44:55:33,[2001:db8:ac10:fd01::1:23]
id:0:1:0:1:18:aa:62:fe:0:16:3e:44:55:66,badbob,[2001:db8:ac10:fd01::1:24]

View File

@ -0,0 +1,7 @@
00:16:3e:77:e2:ed,192.168.122.10,a.example.com
00:16:3e:3e:a9:1a,192.168.122.11,b.example.com
id:0:4:7e:7d:f0:7d:a8:bc:c5:d2:13:32:11:ed:16:ea:84:63,[2001:db8:ac10:fd01::1:20]
paul,[2001:db8:ac10:fd01::1:21]
id:0:3:0:1:0:16:3e:11:22:33,peter.xyz,[2001:db8:ac10:fd01::1:22]
id:0:3:0:1:0:16:3e:44:55:33,[2001:db8:ac10:fd01::1:23]
id:0:1:0:1:18:aa:62:fe:0:16:3e:44:55:66,badbob,[2001:db8:ac10:fd01::1:24]

View File

@ -0,0 +1,16 @@
##WARNING: THIS IS AN AUTO-GENERATED FILE. CHANGES TO IT ARE LIKELY TO BE
##OVERWRITTEN AND LOST. Changes to this configuration should be made using:
## virsh net-edit default
## or other application using the libvirt API.
##
## dnsmasq conf file created by libvirt
strict-order
except-interface=lo
bind-dynamic
interface=virbr0
dhcp-range=192.168.122.2,192.168.122.254,255.255.255.0,1h
dhcp-no-override
dhcp-authoritative
dhcp-lease-max=253
dhcp-hostsfile=/var/lib/libvirt/dnsmasq/default.hostsfile
addn-hosts=/var/lib/libvirt/dnsmasq/default.addnhosts

View File

@ -0,0 +1,2 @@
00:16:3e:77:e2:ed,192.168.122.10,a.example.com,2h
00:16:3e:3e:a9:1a,192.168.122.11,b.example.com,3h

View File

@ -0,0 +1,21 @@
<network>
<name>default</name>
<uuid>81ff0d90-c91e-6742-64da-4a736edb9a9b</uuid>
<forward dev='eth1' mode='nat'>
<interface dev='eth1'/>
</forward>
<bridge name='virbr0' stp='on' delay='0'/>
<ip address='192.168.122.1' netmask='255.255.255.0'>
<dhcp>
<range start='192.168.122.2' end='192.168.122.254'>
<lease expiry='1' unit='hours'/>
</range>
<host mac='00:16:3e:77:e2:ed' name='a.example.com' ip='192.168.122.10'>
<lease expiry='2' unit='hours'/>
</host>
<host mac='00:16:3e:3e:a9:1a' name='b.example.com' ip='192.168.122.11'>
<lease expiry='3' unit='hours'/>
</host>
</dhcp>
</ip>
</network>

View File

@ -0,0 +1,16 @@
##WARNING: THIS IS AN AUTO-GENERATED FILE. CHANGES TO IT ARE LIKELY TO BE
##OVERWRITTEN AND LOST. Changes to this configuration should be made using:
## virsh net-edit default
## or other application using the libvirt API.
##
## dnsmasq conf file created by libvirt
strict-order
except-interface=lo
bind-dynamic
interface=virbr0
dhcp-range=192.168.122.2,192.168.122.254,255.255.255.0,infinite
dhcp-no-override
dhcp-authoritative
dhcp-lease-max=253
dhcp-hostsfile=/var/lib/libvirt/dnsmasq/default.hostsfile
addn-hosts=/var/lib/libvirt/dnsmasq/default.addnhosts

View File

@ -0,0 +1,2 @@
00:16:3e:77:e2:ed,192.168.122.10,a.example.com,infinite
00:16:3e:3e:a9:1a,192.168.122.11,b.example.com,infinite

View File

@ -0,0 +1,21 @@
<network>
<name>default</name>
<uuid>81ff0d90-c91e-6742-64da-4a736edb9a9b</uuid>
<forward dev='eth1' mode='nat'>
<interface dev='eth1'/>
</forward>
<bridge name='virbr0' stp='on' delay='0'/>
<ip address='192.168.122.1' netmask='255.255.255.0'>
<dhcp>
<range start='192.168.122.2' end='192.168.122.254'>
<lease expiry='0'/>
</range>
<host mac='00:16:3e:77:e2:ed' name='a.example.com' ip='192.168.122.10'>
<lease expiry='0'/>
</host>
<host mac='00:16:3e:3e:a9:1a' name='b.example.com' ip='192.168.122.11'>
<lease expiry='0'/>
</host>
</dhcp>
</ip>
</network>

View File

@ -0,0 +1,16 @@
##WARNING: THIS IS AN AUTO-GENERATED FILE. CHANGES TO IT ARE LIKELY TO BE
##OVERWRITTEN AND LOST. Changes to this configuration should be made using:
## virsh net-edit default
## or other application using the libvirt API.
##
## dnsmasq conf file created by libvirt
strict-order
except-interface=lo
bind-dynamic
interface=virbr0
dhcp-range=192.168.122.2,192.168.122.254,255.255.255.0,10m
dhcp-no-override
dhcp-authoritative
dhcp-lease-max=253
dhcp-hostsfile=/var/lib/libvirt/dnsmasq/default.hostsfile
addn-hosts=/var/lib/libvirt/dnsmasq/default.addnhosts

View File

@ -0,0 +1,2 @@
00:16:3e:77:e2:ed,192.168.122.10,a.example.com,20m
00:16:3e:3e:a9:1a,192.168.122.11,b.example.com,30m

View File

@ -0,0 +1,21 @@
<network>
<name>default</name>
<uuid>81ff0d90-c91e-6742-64da-4a736edb9a9b</uuid>
<forward dev='eth1' mode='nat'>
<interface dev='eth1'/>
</forward>
<bridge name='virbr0' stp='on' delay='0'/>
<ip address='192.168.122.1' netmask='255.255.255.0'>
<dhcp>
<range start='192.168.122.2' end='192.168.122.254'>
<lease expiry='10' unit='minutes'/>
</range>
<host mac='00:16:3e:77:e2:ed' name='a.example.com' ip='192.168.122.10'>
<lease expiry='20' unit='minutes'/>
</host>
<host mac='00:16:3e:3e:a9:1a' name='b.example.com' ip='192.168.122.11'>
<lease expiry='30' unit='minutes'/>
</host>
</dhcp>
</ip>
</network>

View File

@ -0,0 +1,16 @@
##WARNING: THIS IS AN AUTO-GENERATED FILE. CHANGES TO IT ARE LIKELY TO BE
##OVERWRITTEN AND LOST. Changes to this configuration should be made using:
## virsh net-edit default
## or other application using the libvirt API.
##
## dnsmasq conf file created by libvirt
strict-order
except-interface=lo
bind-dynamic
interface=virbr0
dhcp-range=192.168.122.2,192.168.122.254,255.255.255.0,200s
dhcp-no-override
dhcp-authoritative
dhcp-lease-max=253
dhcp-hostsfile=/var/lib/libvirt/dnsmasq/default.hostsfile
addn-hosts=/var/lib/libvirt/dnsmasq/default.addnhosts

View File

@ -0,0 +1,2 @@
00:16:3e:77:e2:ed,192.168.122.10,a.example.com,300s
00:16:3e:3e:a9:1a,192.168.122.11,b.example.com,400s

View File

@ -0,0 +1,21 @@
<network>
<name>default</name>
<uuid>81ff0d90-c91e-6742-64da-4a736edb9a9b</uuid>
<forward dev='eth1' mode='nat'>
<interface dev='eth1'/>
</forward>
<bridge name='virbr0' stp='on' delay='0'/>
<ip address='192.168.122.1' netmask='255.255.255.0'>
<dhcp>
<range start='192.168.122.2' end='192.168.122.254'>
<lease expiry='200' unit='seconds'/>
</range>
<host mac='00:16:3e:77:e2:ed' name='a.example.com' ip='192.168.122.10'>
<lease expiry='300' unit='seconds'/>
</host>
<host mac='00:16:3e:3e:a9:1a' name='b.example.com' ip='192.168.122.11'>
<lease expiry='400' unit='seconds'/>
</host>
</dhcp>
</ip>
</network>

View File

@ -0,0 +1,2 @@
00:16:3e:77:e2:ed,192.168.122.10,a.example.com
00:16:3e:3e:a9:1a,192.168.122.11,b.example.com

View File

@ -0,0 +1,2 @@
00:16:3e:77:e2:ed,192.168.122.10,a.example.com
00:16:3e:3e:a9:1a,192.168.122.11,b.example.com

View File

@ -0,0 +1,2 @@
00:16:3e:77:e2:ed,192.168.122.10,a.example.com
00:16:3e:3e:a9:1a,192.168.122.11,b.example.com

View File

@ -0,0 +1,2 @@
00:16:3e:77:e2:ed,192.168.122.10,a.example.com
00:16:3e:3e:a9:1a,192.168.122.11,b.example.com

View File

@ -0,0 +1,2 @@
00:16:3e:77:e2:ed,192.168.122.10,a.example.com
00:16:3e:3e:a9:1a,192.168.122.11,b.example.com

View File

@ -0,0 +1,2 @@
00:16:3e:77:e2:ed,192.168.122.10,a.example.com
00:16:3e:3e:a9:1a,192.168.122.11,b.example.com

View File

@ -0,0 +1,2 @@
00:16:3e:77:e2:ed,192.168.122.10,a.example.com
00:16:3e:3e:a9:1a,192.168.122.11,b.example.com

View File

@ -16,7 +16,8 @@
#define VIR_FROM_THIS VIR_FROM_NONE #define VIR_FROM_THIS VIR_FROM_NONE
static int static int
testCompareXMLToConfFiles(const char *inxml, const char *outconf, dnsmasqCapsPtr caps) testCompareXMLToConfFiles(const char *inxml, const char *outconf,
char *outhostsfile, dnsmasqCapsPtr caps)
{ {
char *confactual = NULL; char *confactual = NULL;
char *hostsfileactual = NULL; char *hostsfileactual = NULL;
@ -63,6 +64,20 @@ testCompareXMLToConfFiles(const char *inxml, const char *outconf, dnsmasqCapsPtr
if (virTestCompareToFile(confactual, outconf) < 0) if (virTestCompareToFile(confactual, outconf) < 0)
goto fail; goto fail;
if (virFileExists(outhostsfile)) {
if (!hostsfileactual) {
VIR_TEST_DEBUG("%s: hostsfile exists but the configuration did "
"not specify any host", outhostsfile);
goto fail;
} else if (virTestCompareToFile(hostsfileactual, outhostsfile) < 0) {
goto fail;
}
} else if (hostsfileactual) {
VIR_TEST_DEBUG("%s: file does not exist but actual data was expected",
outhostsfile);
goto fail;
}
ret = 0; ret = 0;
fail: fail:
@ -88,14 +103,17 @@ testCompareXMLToConfHelper(const void *data)
const testInfo *info = data; const testInfo *info = data;
char *inxml = NULL; char *inxml = NULL;
char *outconf = NULL; char *outconf = NULL;
char *outhostsfile = NULL;
inxml = g_strdup_printf("%s/networkxml2confdata/%s.xml", abs_srcdir, info->name); inxml = g_strdup_printf("%s/networkxml2confdata/%s.xml", abs_srcdir, info->name);
outconf = g_strdup_printf("%s/networkxml2confdata/%s.conf", abs_srcdir, info->name); outconf = g_strdup_printf("%s/networkxml2confdata/%s.conf", abs_srcdir, info->name);
outhostsfile = g_strdup_printf("%s/networkxml2confdata/%s.hostsfile", abs_srcdir, info->name);
result = testCompareXMLToConfFiles(inxml, outconf, info->caps); result = testCompareXMLToConfFiles(inxml, outconf, outhostsfile, info->caps);
VIR_FREE(inxml); VIR_FREE(inxml);
VIR_FREE(outconf); VIR_FREE(outconf);
VIR_FREE(outhostsfile);
return result; return result;
} }
@ -145,6 +163,10 @@ mymain(void)
DO_TEST("dhcp6host-routed-network", dhcpv6); DO_TEST("dhcp6host-routed-network", dhcpv6);
DO_TEST("ptr-domains-auto", dhcpv6); DO_TEST("ptr-domains-auto", dhcpv6);
DO_TEST("dnsmasq-options", dhcpv6); DO_TEST("dnsmasq-options", dhcpv6);
DO_TEST("leasetime-seconds", full);
DO_TEST("leasetime-minutes", full);
DO_TEST("leasetime-hours", full);
DO_TEST("leasetime-infinite", full);
virObjectUnref(dhcpv6); virObjectUnref(dhcpv6);
virObjectUnref(full); virObjectUnref(full);

View File

@ -0,0 +1 @@
../networkxml2confdata/leasetime-hours.xml

View File

@ -0,0 +1 @@
../networkxml2confdata/leasetime-infinite.xml

View File

@ -0,0 +1 @@
../networkxml2confdata/leasetime-minutes.xml

View File

@ -0,0 +1 @@
../networkxml2confdata/leasetime-seconds.xml

View File

@ -0,0 +1 @@
../networkxml2xmlin/leasetime-hours.xml

View File

@ -0,0 +1 @@
../networkxml2xmlin/leasetime-infinite.xml

View File

@ -0,0 +1 @@
../networkxml2xmlin/leasetime-minutes.xml

View File

@ -0,0 +1 @@
../networkxml2xmlin/leasetime-seconds.xml

View File

@ -160,6 +160,10 @@ mymain(void)
DO_TEST("metadata"); DO_TEST("metadata");
DO_TEST("set-mtu"); DO_TEST("set-mtu");
DO_TEST("dnsmasq-options"); DO_TEST("dnsmasq-options");
DO_TEST("leasetime-seconds");
DO_TEST("leasetime-minutes");
DO_TEST("leasetime-hours");
DO_TEST("leasetime-infinite");
DO_TEST("isolated-ports"); DO_TEST("isolated-ports");
return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE; return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;