virsh: Fix net-desc --config output

Fixes the following bug:
Command:          `net-desc --config [--title] my_network`
Expected Output:  Title/Description of persistent config
Output:           Title/Description of live config

This was caused due to the usage of a single `flags` variable in
`virshGetNetworkDescription()` which ended up in a wrong enum being
passed to `virNetworkGetMetadata()` (enum being that of LIVE instead of
CONFIG).

Although the domain object has the same code, this didn't cause a problem
there because the enum values of `VIR_DOMAIN_INACTIVE_XML` and
`VIR_DOMAIN_METADATA_CONFIG` turn out to be the same (1 << 1), whereas
they are not for network equivalent ones (1 << 0, 1 << 1).

Signed-off-by: K Shiva Kiran <shiva_kr@riseup.net>
Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
This commit is contained in:
K Shiva Kiran 2023-08-31 23:46:57 +05:30 committed by Jiri Denemark
parent 0873d63b09
commit 30be60dd76

View File

@ -366,7 +366,8 @@ static const vshCmdOptDef opts_network_desc[] = {
/* extract description or title from network xml */
static char *
virshGetNetworkDescription(vshControl *ctl, virNetworkPtr net,
bool title, unsigned int flags)
bool title, unsigned int flags,
unsigned int queryflags)
{
char *desc = NULL;
g_autoptr(xmlDoc) doc = NULL;
@ -394,7 +395,7 @@ virshGetNetworkDescription(vshControl *ctl, virNetworkPtr net,
}
/* fall back to xml */
if (virshNetworkGetXMLFromNet(ctl, net, flags, &doc, &ctxt) < 0)
if (virshNetworkGetXMLFromNet(ctl, net, queryflags, &doc, &ctxt) < 0)
return NULL;
if (title)
@ -454,7 +455,7 @@ cmdNetworkDesc(vshControl *ctl, const vshCmd *cmd)
g_autofree char *descNet = NULL;
g_autofree char *descNew = NULL;
if (!(descNet = virshGetNetworkDescription(ctl, net, title, queryflags)))
if (!(descNet = virshGetNetworkDescription(ctl, net, title, flags, queryflags)))
return false;
if (!descArg)
@ -515,7 +516,7 @@ cmdNetworkDesc(vshControl *ctl, const vshCmd *cmd)
vshPrintExtra(ctl, "%s", _("Network description updated successfully"));
} else {
g_autofree char *desc = virshGetNetworkDescription(ctl, net, title, queryflags);
g_autofree char *desc = virshGetNetworkDescription(ctl, net, title, flags, queryflags);
if (!desc)
return false;
@ -1128,7 +1129,7 @@ cmdNetworkList(vshControl *ctl, const vshCmd *cmd G_GNUC_UNUSED)
if (optTitle) {
g_autofree char *title = NULL;
if (!(title = virshGetNetworkDescription(ctl, network, true, 0)))
if (!(title = virshGetNetworkDescription(ctl, network, true, 0, 0)))
goto cleanup;
if (vshTableRowAppend(table,
virNetworkGetName(network),