mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-10 05:17:59 +03:00
conf: fix title and description for virDomainSetMetadata API
If we pass XML to virDomainDefineXML API with these two elements: ... <title></title> <description></description> ... libvirt correctly ignores these two elements and they will not appear in the parsed XML. However, if we use virDomainSetMetadata API and with "" as value for title or description we will end up with the parsed XML that contains these empty elements. Let's fix the behavior of this API to behave the same as virDomainDefineXML. Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1518042 Reviewed-by: John Ferlan <jferlan@redhat.com> Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
This commit is contained in:
parent
d38d512f4e
commit
e387afeb9a
@ -29678,7 +29678,7 @@ virDomainDefSetMetadata(virDomainDefPtr def,
|
|||||||
xmlDocPtr doc = NULL;
|
xmlDocPtr doc = NULL;
|
||||||
xmlNodePtr old;
|
xmlNodePtr old;
|
||||||
xmlNodePtr new = NULL;
|
xmlNodePtr new = NULL;
|
||||||
char *tmp;
|
char *tmp = NULL;
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
|
|
||||||
if (type >= VIR_DOMAIN_METADATA_LAST) {
|
if (type >= VIR_DOMAIN_METADATA_LAST) {
|
||||||
@ -29689,7 +29689,7 @@ virDomainDefSetMetadata(virDomainDefPtr def,
|
|||||||
|
|
||||||
switch ((virDomainMetadataType) type) {
|
switch ((virDomainMetadataType) type) {
|
||||||
case VIR_DOMAIN_METADATA_DESCRIPTION:
|
case VIR_DOMAIN_METADATA_DESCRIPTION:
|
||||||
if (VIR_STRDUP(tmp, metadata) < 0)
|
if (STRNEQ_NULLABLE(metadata, "") && VIR_STRDUP(tmp, metadata) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
VIR_FREE(def->description);
|
VIR_FREE(def->description);
|
||||||
@ -29697,7 +29697,7 @@ virDomainDefSetMetadata(virDomainDefPtr def,
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case VIR_DOMAIN_METADATA_TITLE:
|
case VIR_DOMAIN_METADATA_TITLE:
|
||||||
if (VIR_STRDUP(tmp, metadata) < 0)
|
if (STRNEQ_NULLABLE(metadata, "") && VIR_STRDUP(tmp, metadata) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
VIR_FREE(def->title);
|
VIR_FREE(def->title);
|
||||||
|
@ -167,6 +167,7 @@ struct metadataTest {
|
|||||||
virDomainPtr dom;
|
virDomainPtr dom;
|
||||||
|
|
||||||
const char *data;
|
const char *data;
|
||||||
|
const char *expect;
|
||||||
int type;
|
int type;
|
||||||
bool fail;
|
bool fail;
|
||||||
};
|
};
|
||||||
@ -232,7 +233,7 @@ testTextMetadata(const void *data)
|
|||||||
|
|
||||||
actual = virDomainGetMetadata(test->dom, test->type, NULL, 0);
|
actual = virDomainGetMetadata(test->dom, test->type, NULL, 0);
|
||||||
|
|
||||||
if (STRNEQ_NULLABLE(test->data, actual)) {
|
if (STRNEQ_NULLABLE(test->expect, actual)) {
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||||
"expected metadata doesn't match actual: "
|
"expected metadata doesn't match actual: "
|
||||||
"expected:'%s'\ngot: '%s'",
|
"expected:'%s'\ngot: '%s'",
|
||||||
@ -248,10 +249,11 @@ testTextMetadata(const void *data)
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define TEST_TEXT_METADATA(INDEX, TYPE, DATA, FAIL) \
|
#define TEST_TEXT_METADATA(INDEX, TYPE, DATA, EXPECT, FAIL) \
|
||||||
do { \
|
do { \
|
||||||
test.type = VIR_DOMAIN_METADATA_ ## TYPE; \
|
test.type = VIR_DOMAIN_METADATA_ ## TYPE; \
|
||||||
test.data = DATA; \
|
test.data = DATA; \
|
||||||
|
test.expect = EXPECT; \
|
||||||
test.fail = FAIL; \
|
test.fail = FAIL; \
|
||||||
\
|
\
|
||||||
if (virTestRun("text metadata: " #TYPE " " INDEX " ", \
|
if (virTestRun("text metadata: " #TYPE " " INDEX " ", \
|
||||||
@ -259,9 +261,16 @@ testTextMetadata(const void *data)
|
|||||||
ret = EXIT_FAILURE; \
|
ret = EXIT_FAILURE; \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
#define TEST_TITLE(INDEX, DATA) TEST_TEXT_METADATA(INDEX, TITLE, DATA, false)
|
#define TEST_TITLE(INDEX, DATA) \
|
||||||
#define TEST_TITLE_FAIL(INDEX, DATA) TEST_TEXT_METADATA(INDEX, TITLE, DATA, true)
|
TEST_TEXT_METADATA(INDEX, TITLE, DATA, DATA, false)
|
||||||
#define TEST_DESCR(INDEX, DATA) TEST_TEXT_METADATA(INDEX, DESCRIPTION, DATA, false)
|
#define TEST_TITLE_EXPECT(INDEX, DATA, EXPECT) \
|
||||||
|
TEST_TEXT_METADATA(INDEX, TITLE, DATA, EXPECT, false)
|
||||||
|
#define TEST_TITLE_FAIL(INDEX, DATA) \
|
||||||
|
TEST_TEXT_METADATA(INDEX, TITLE, DATA, DATA, true)
|
||||||
|
#define TEST_DESCR(INDEX, DATA) \
|
||||||
|
TEST_TEXT_METADATA(INDEX, DESCRIPTION, DATA, DATA, false)
|
||||||
|
#define TEST_DESCR_EXPECT(INDEX, DATA, EXPECT) \
|
||||||
|
TEST_TEXT_METADATA(INDEX, DESCRIPTION, DATA, EXPECT, false)
|
||||||
|
|
||||||
static int
|
static int
|
||||||
mymain(void)
|
mymain(void)
|
||||||
@ -290,7 +299,7 @@ mymain(void)
|
|||||||
TEST_TITLE("2", NULL);
|
TEST_TITLE("2", NULL);
|
||||||
TEST_TITLE("3", "blah");
|
TEST_TITLE("3", "blah");
|
||||||
TEST_TITLE_FAIL("4", "qwe\nrt");
|
TEST_TITLE_FAIL("4", "qwe\nrt");
|
||||||
TEST_TITLE("5", "");
|
TEST_TITLE_EXPECT("5", "", NULL);
|
||||||
TEST_TITLE_FAIL("6", "qwert\n");
|
TEST_TITLE_FAIL("6", "qwert\n");
|
||||||
TEST_TITLE_FAIL("7", "\n");
|
TEST_TITLE_FAIL("7", "\n");
|
||||||
|
|
||||||
@ -298,7 +307,7 @@ mymain(void)
|
|||||||
TEST_DESCR("2", NULL);
|
TEST_DESCR("2", NULL);
|
||||||
TEST_DESCR("3", "qwert");
|
TEST_DESCR("3", "qwert");
|
||||||
TEST_DESCR("4", "\n");
|
TEST_DESCR("4", "\n");
|
||||||
TEST_DESCR("5", "");
|
TEST_DESCR_EXPECT("5", "", NULL);
|
||||||
|
|
||||||
virDomainFree(test.dom);
|
virDomainFree(test.dom);
|
||||||
virConnectClose(test.conn);
|
virConnectClose(test.conn);
|
||||||
|
Loading…
Reference in New Issue
Block a user