On 7/9/24 17:23, Adam Julis wrote:
> The "modify" command allows to replace an existing record (its
> text value). The primary key is the name of the record. If
> duplicity or missing record detected, throw error.
>
> Tests in networkxml2xmlupdatetest.c contain replacements of an
> existing DNS-text record and failure due to non-existing record.
>
> Resolves: https://gitlab.com/libvirt/libvirt/-/issues/639
> Signed-off-by: Adam Julis <[email protected]>
> ---
> src/conf/network_conf.c | 18 ++++++++-----
> .../dns-txt-record-modify-fail.xml | 1 +
> .../dns-txt-record-modify-success.xml | 1 +
> .../nat-network-dns-txt-modify-ok.xml | 26 +++++++++++++++++++
> tests/networkxml2xmlupdatetest.c | 9 +++++++
> 5 files changed, 49 insertions(+), 6 deletions(-)
> create mode 100644
> tests/networkxml2xmlupdatein/dns-txt-record-modify-fail.xml
> create mode 100644
> tests/networkxml2xmlupdatein/dns-txt-record-modify-success.xml
> create mode 100644
> tests/networkxml2xmlupdateout/nat-network-dns-txt-modify-ok.xml
>
> diff --git a/src/conf/network_conf.c b/src/conf/network_conf.c
> index fc387f9566..dd362b6ab2 100644
> --- a/src/conf/network_conf.c
> +++ b/src/conf/network_conf.c
> @@ -3351,12 +3351,6 @@ virNetworkDefUpdateDNSTxt(virNetworkDef *def,
> bool isAdd = (command == VIR_NETWORK_UPDATE_COMMAND_ADD_FIRST ||
> command == VIR_NETWORK_UPDATE_COMMAND_ADD_LAST);
>
> - if (command == VIR_NETWORK_UPDATE_COMMAND_MODIFY) {
> - virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s",
> - _("DNS TXT records cannot be modified, only added or
> deleted"));
> - goto cleanup;
> - }
> -
> if (virNetworkDefUpdateCheckElementName(def, ctxt->node, "txt") < 0)
> goto cleanup;
>
> @@ -3395,6 +3389,18 @@ virNetworkDefUpdateDNSTxt(virNetworkDef *def,
> virNetworkDNSTxtDefClear(&dns->txts[foundIdx]);
> VIR_DELETE_ELEMENT(dns->txts, foundIdx, dns->ntxts);
>
> + } else if (command == VIR_NETWORK_UPDATE_COMMAND_MODIFY) {
> +
> + if (foundIdx == dns->ntxts) {
> + virReportError(VIR_ERR_OPERATION_INVALID,
> + _("couldn't locate a matching DNS TXT record in
> network %1$s"),
> + def->name);
> + goto cleanup;
> + }
> +
> + VIR_FREE(dns->txts[foundIdx].value);
> + dns->txts[foundIdx].value = g_strdup(txt.value);
Instead of strdup()-ing the string, you may as well g_steal_pointer() it.
> +
> } else {
> virNetworkDefUpdateUnknownCommand(command);
> goto cleanup;
Reviewed-by: Michal Privoznik <[email protected]>
Michal