networkxml2conftest: Allow regenerating hosts file

Inside of testCompareXMLToConfFiles() the
networkDnsmasqConfContents() is called. This may also produce
contents of corresponding hosts file. This is then compared to
expected contents stored on disk as ${testname}.hostsfile. But
due to additional checks virTestCompareToFile() might not even be
called. Problem with that is when there's actual content but the
file doesn't exist the compare helper is not called and thus
VIR_TEST_REGENERATE_OUTPUT trick doesn't work. Let's call the
helper more often as it is perfectly capable of handling this
edge case. What it is not capable of handling is when the file
shouldn't exist at all. So handling of that case is kept.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
Michal Privoznik committed 2026-01-29 13:38:55 +01:00
1 parent 319bbb5c84
commit 30baa49454
1 file changed
+8 -10
+8 -10
View File
@@ -75,18 +75,16 @@ testCompareXMLToConfFiles(const char *inxml, const char *outconf,
if (virTestCompareToFile(confactual, outconf) < 0)
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) {
if (hostsfileactual) {
if (virTestCompareToFile(hostsfileactual, outhostsfile) < 0) {
goto fail;
}
} else {
if (virFileExists(outhostsfile)) {
VIR_TEST_DEBUG("%s: hostsfile exists but the configuration did not specify any host",
outhostsfile);
goto fail;
}
} else if (hostsfileactual) {
VIR_TEST_DEBUG("%s: file does not exist but actual data was expected",
outhostsfile);
goto fail;
}
ret = 0;