[PATCH 0/3] virsh: Fix regression in script-friendly output of 'virsh list --uuid'

Peter Krempa (3): virsh: cmdList: Revert to script-friendly output for 'virsh list --uuid' NEWS: Mention breakage of scrip-friendly virsh output virshtest: Add test case for script friendly options NEWS.rst | 11 +++++++ tests/virshtest.c | 2 ++ .../virshtestdata/script-friendly-options.in | 11 +++++++ .../virshtestdata/script-friendly-options.out | 33 +++++++++++++++++++ tools/virsh-domain-monitor.c | 2 +- 5 files changed, 58 insertions(+), 1 deletion(-) create mode 100644 tests/virshtestdata/script-friendly-options.in create mode 100644 tests/virshtestdata/script-friendly-options.out -- 2.46.0

Commit 271940223c2914bf63cbec00930ce46d6eef30ba which strived to add support to use '--uuid' in the table output of 'virsh list' went too far and also allowed the default table view to be enabled when just '--uuid' is specified. This broke the script-friendly output which previously had this format: $ virsh list --uuid b6d03c07-86f8-4a57-8719-172a5d0359bb to this script-unfriendly output: $ virsh list --uuid Id Name State UUID ------------------------------------------------------------- 1 ha running b6d03c07-86f8-4a57-8719-172a5d0359bb Using the human friendly output will still be possible by using: $ virsh list --table --uuid Fixes: 271940223c2914bf63cbec00930ce46d6eef30ba Closes: https://gitlab.com/libvirt/libvirt/-/issues/666 Signed-off-by: Peter Krempa <pkrempa@redhat.com> --- tools/virsh-domain-monitor.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/virsh-domain-monitor.c b/tools/virsh-domain-monitor.c index 87efd86a69..9ee9090c11 100644 --- a/tools/virsh-domain-monitor.c +++ b/tools/virsh-domain-monitor.c @@ -1857,7 +1857,7 @@ cmdList(vshControl *ctl, const vshCmd *cmd) VSH_EXCLUSIVE_OPTIONS("table", "name"); VSH_EXCLUSIVE_OPTIONS("table", "id"); - if (!optName && !optID) + if (!optUUID && !optName && !optID) optTable = true; if (!(list = virshDomainListCollect(ctl, flags))) -- 2.46.0

Signed-off-by: Peter Krempa <pkrempa@redhat.com> --- NEWS.rst | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/NEWS.rst b/NEWS.rst index 8b89a7c9ee..beea8221e1 100644 --- a/NEWS.rst +++ b/NEWS.rst @@ -21,6 +21,17 @@ v10.8.0 (unreleased) * **Bug fixes** + * virsh: Fix script-friedly output of ``virsh list --uuid`` + + The script-friendly output of just 1 UUID per line was mistakenly replaced + by the full human-targetted table view full of redundant information + and very hard to parse. Users who wish to see the UUIDs in the tabular + output need to use ``virsh list --table --uuid`` as old behaviour was + reverted. + + Note that this also broke the ``libvirt-guests`` script. The bug was + introduced in `v10.7.0 (2024-09-02)`_. + v10.7.0 (2024-09-02) ==================== -- 2.46.0

Add a bunch of tests verifying that script-friendly options of certain commands are not changed incompatibly thus potentially breaking user scripts. Signed-off-by: Peter Krempa <pkrempa@redhat.com> --- This sample represents what 'libvirt-guests' uses and what I thought off. Feel free to suggest more. tests/virshtest.c | 2 ++ .../virshtestdata/script-friendly-options.in | 11 +++++++ .../virshtestdata/script-friendly-options.out | 33 +++++++++++++++++++ 3 files changed, 46 insertions(+) create mode 100644 tests/virshtestdata/script-friendly-options.in create mode 100644 tests/virshtestdata/script-friendly-options.out diff --git a/tests/virshtest.c b/tests/virshtest.c index b86c39285a..a7f62df563 100644 --- a/tests/virshtest.c +++ b/tests/virshtest.c @@ -352,6 +352,8 @@ mymain(void) "checkpoint-create test --redefine checkpoint-c2.xml ;" "checkpoint-info test c2"); + DO_TEST_SCRIPT("script-friendly-options", NULL, VIRSH_CUSTOM); + /* completion doesn't work on non-readline builds */ need_readline = true; diff --git a/tests/virshtestdata/script-friendly-options.in b/tests/virshtestdata/script-friendly-options.in new file mode 100644 index 0000000000..08d2a87474 --- /dev/null +++ b/tests/virshtestdata/script-friendly-options.in @@ -0,0 +1,11 @@ +echo "Following script-friendly outputs of commands must not change" +list --uuid; +list --uuid --all; +list --name; +list --name --all; +list --uuid --name --all; +domstate fv0 +domstate fv0 --reason +domname ef861801-45b9-11cb-88e3-afbfe5370493 +domid fv0 +domstats fv0 diff --git a/tests/virshtestdata/script-friendly-options.out b/tests/virshtestdata/script-friendly-options.out new file mode 100644 index 0000000000..2ab1ba0e71 --- /dev/null +++ b/tests/virshtestdata/script-friendly-options.out @@ -0,0 +1,33 @@ +Following script-friendly outputs of commands must not change +4dea22b3-1d52-d8f3-2516-782e98ab3fa0 +ef861801-45b9-11cb-88e3-afbfe5370493 +08721f99-3d1d-4aec-96eb-97803297bb36 + +4dea22b3-1d52-d8f3-2516-782e98ab3fa0 +ef861801-45b9-11cb-88e3-afbfe5370493 +08721f99-3d1d-4aec-96eb-97803297bb36 + +fv0 +fc4 +fc5 + +fv0 +fc4 +fc5 + +4dea22b3-1d52-d8f3-2516-782e98ab3fa0 fv0 +ef861801-45b9-11cb-88e3-afbfe5370493 fc4 +08721f99-3d1d-4aec-96eb-97803297bb36 fc5 + +running + +running (unknown) + +fc4 + +1 + +Domain: 'fv0' + state.state=1 + state.reason=0 + -- 2.46.0

On Thu, Sep 05, 2024 at 14:43:54 +0200, Peter Krempa wrote:
Peter Krempa (3): virsh: cmdList: Revert to script-friendly output for 'virsh list --uuid' NEWS: Mention breakage of scrip-friendly virsh output virshtest: Add test case for script friendly options
NEWS.rst | 11 +++++++ tests/virshtest.c | 2 ++ .../virshtestdata/script-friendly-options.in | 11 +++++++ .../virshtestdata/script-friendly-options.out | 33 +++++++++++++++++++ tools/virsh-domain-monitor.c | 2 +- 5 files changed, 58 insertions(+), 1 deletion(-) create mode 100644 tests/virshtestdata/script-friendly-options.in create mode 100644 tests/virshtestdata/script-friendly-options.out
Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
participants (2)
-
Jiri Denemark
-
Peter Krempa