From nobody Sat Apr 20 13:10:16 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1553400153274496.29386984969835; Sat, 23 Mar 2019 21:02:33 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id EE3E33082AF4; Sun, 24 Mar 2019 04:02:31 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C4DB01001DD4; Sun, 24 Mar 2019 04:02:31 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 8918D180338A; Sun, 24 Mar 2019 04:02:31 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x2O427LX010960 for ; Sun, 24 Mar 2019 00:02:07 -0400 Received: by smtp.corp.redhat.com (Postfix) id 9F4635C26D; Sun, 24 Mar 2019 04:02:07 +0000 (UTC) Received: from blue.redhat.com (ovpn-116-59.phx2.redhat.com [10.3.116.59]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3F87D5C280; Sun, 24 Mar 2019 04:02:07 +0000 (UTC) From: Eric Blake To: libvir-list@redhat.com Date: Sat, 23 Mar 2019 23:01:59 -0500 Message-Id: <20190324040203.24304-2-eblake@redhat.com> In-Reply-To: <20190324040203.24304-1-eblake@redhat.com> References: <20190324040203.24304-1-eblake@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com Cc: mprivozn@redhat.com Subject: [libvirt] [PATCH 1/5] snapshot: Avoid infloop during REDEFINE X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.45]); Sun, 24 Mar 2019 04:02:32 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Commit 55c2ab3e accidentally introduced an infinite loop while checking whether a redefined snapshot would cause an infinite loop in chasing its parents back to a root. Alas, 'make check' did not catch it, so my next patch will be a testsuite improvement that would have hung and prevented the bug from being checked in to begin with. Signed-off-by: Eric Blake --- src/conf/snapshot_conf.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/conf/snapshot_conf.c b/src/conf/snapshot_conf.c index 52abafab0f..cc3f71ab6f 100644 --- a/src/conf/snapshot_conf.c +++ b/src/conf/snapshot_conf.c @@ -962,6 +962,7 @@ virDomainSnapshotRedefinePrep(virDomainPtr domain, vm->def->name); break; } + otherdef =3D virDomainSnapshotObjGetDef(other); } } --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sat Apr 20 13:10:16 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1553400136472698.2644680496841; Sat, 23 Mar 2019 21:02:16 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 8414B30821E0; Sun, 24 Mar 2019 04:02:14 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 186375D9CC; Sun, 24 Mar 2019 04:02:14 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id CA41241F3F; Sun, 24 Mar 2019 04:02:11 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x2O42AD7010973 for ; Sun, 24 Mar 2019 00:02:10 -0400 Received: by smtp.corp.redhat.com (Postfix) id 378C15C28F; Sun, 24 Mar 2019 04:02:10 +0000 (UTC) Received: from blue.redhat.com (ovpn-116-59.phx2.redhat.com [10.3.116.59]) by smtp.corp.redhat.com (Postfix) with ESMTP id C33985E1A2; Sun, 24 Mar 2019 04:02:07 +0000 (UTC) From: Eric Blake To: libvir-list@redhat.com Date: Sat, 23 Mar 2019 23:02:00 -0500 Message-Id: <20190324040203.24304-3-eblake@redhat.com> In-Reply-To: <20190324040203.24304-1-eblake@redhat.com> References: <20190324040203.24304-1-eblake@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com Cc: mprivozn@redhat.com Subject: [libvirt] [PATCH 2/5] virsh: Parse # comments in batch mode X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.47]); Sun, 24 Mar 2019 04:02:15 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Continuing from what I did in commit 4817dec0, now I want to write a sequence that is self-documenting. So I need comments :) Now I can do something like: $ virsh -c test:///default ' # setup snapshot-create-as test s1 snapshot-create-as test s2 # check snapshot-list test --name ' Note that this does NOT accept comments in argv mode, another patch will tackle that. (If I'm not careful, I might turn virsh into a full-fledged 'sh' replacement? Here's hoping I don't go that far...) Signed-off-by: Eric Blake --- tests/virshtest.c | 6 ++++++ tools/virsh.pod | 3 ++- tools/virt-admin.pod | 3 ++- tools/vsh.c | 8 +++++++- 4 files changed, 17 insertions(+), 3 deletions(-) diff --git a/tests/virshtest.c b/tests/virshtest.c index 7e59ad7da6..5408db1387 100644 --- a/tests/virshtest.c +++ b/tests/virshtest.c @@ -417,6 +417,12 @@ mymain(void) DO_TEST(38, "a\nb\n", "ec\\\nho a\n echo \\\n b;"); DO_TEST(39, "a\n b\n", "\"ec\\\nho\" a\n echo \"\\\n b\";"); DO_TEST(40, "a\n\\\n b\n", "ec\\\nho a\n echo '\\\n b';"); + DO_TEST(41, "a\n", "echo a # b"); + DO_TEST(42, "a\nc\n", "echo a #b\necho c"); + DO_TEST(43, "a\nc\n", "echo a # b\\\necho c"); + DO_TEST(44, "a # b\n", "echo a '#' b"); + DO_TEST(45, "a # b\n", "echo a \\# b"); + DO_TEST(46, "a\n", "#unbalanced 'quotes\"\necho a # b"); # undef DO_TEST diff --git a/tools/virsh.pod b/tools/virsh.pod index db72343159..05adb568db 100644 --- a/tools/virsh.pod +++ b/tools/virsh.pod @@ -44,7 +44,8 @@ and their arguments joined with whitespace and separated = by semicolons or newlines between commands, where unquoted backslash-newline pairs are elided. Within I, virsh understands the same single, double, and backslash escapes as the shell, although you must -add another layer of shell escaping in creating the single shell argument. +add another layer of shell escaping in creating the single shell argument, +and any word starting with unquoted I<#> begins a comment that ends at new= line. If no command is given in the command line, B will then start a min= imal interpreter waiting for your commands, and the B command will then e= xit the program. diff --git a/tools/virt-admin.pod b/tools/virt-admin.pod index 9bbff42846..8489325ca9 100644 --- a/tools/virt-admin.pod +++ b/tools/virt-admin.pod @@ -27,7 +27,8 @@ and their arguments joined with whitespace and separated = by semicolons or newlines between commands, where unquoted backslash-newline pairs are elided. Within I, virt-admin understands the same single, double, and backslash escapes as the shell, although you must -add another layer of shell escaping in creating the single shell argument. +add another layer of shell escaping in creating the single shell argument, +and any word starting with unquoted I<#> begins a comment that ends at new= line. If no command is given in the command line, B will then start = a minimal interpreter waiting for your commands, and the B command will then e= xit the program. diff --git a/tools/vsh.c b/tools/vsh.c index 5903f129c1..9a88ee29b7 100644 --- a/tools/vsh.c +++ b/tools/vsh.c @@ -1,7 +1,7 @@ /* * vsh.c: common data to be used by clients to exercise the libvirt API * - * Copyright (C) 2005, 2007-2015 Red Hat, Inc. + * Copyright (C) 2005-2019 Red Hat, Inc. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -1693,6 +1693,12 @@ vshCommandStringGetArg(vshControl *ctl, vshCommandPa= rser *parser, char **res, parser->pos =3D ++p; /* =3D \0 or begin of next comman= d */ return VSH_TK_SUBCMD_END; } + if (*p =3D=3D '#') { /* Argument starting with # is comment to end of = line */ + while (*p && *p !=3D '\n') + p++; + parser->pos =3D p + !!*p; + return VSH_TK_SUBCMD_END; + } while (*p) { /* end of token is blank space or ';' */ --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sat Apr 20 13:10:16 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1553400136129596.6516001174351; Sat, 23 Mar 2019 21:02:16 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 801E130821C2; Sun, 24 Mar 2019 04:02:14 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 15E805D9CA; Sun, 24 Mar 2019 04:02:14 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 364A741F3E; Sun, 24 Mar 2019 04:02:11 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x2O42AM7010980 for ; Sun, 24 Mar 2019 00:02:10 -0400 Received: by smtp.corp.redhat.com (Postfix) id B8DD95C280; Sun, 24 Mar 2019 04:02:10 +0000 (UTC) Received: from blue.redhat.com (ovpn-116-59.phx2.redhat.com [10.3.116.59]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5A8D55E1A2; Sun, 24 Mar 2019 04:02:10 +0000 (UTC) From: Eric Blake To: libvir-list@redhat.com Date: Sat, 23 Mar 2019 23:02:01 -0500 Message-Id: <20190324040203.24304-4-eblake@redhat.com> In-Reply-To: <20190324040203.24304-1-eblake@redhat.com> References: <20190324040203.24304-1-eblake@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com Cc: mprivozn@redhat.com Subject: [libvirt] [PATCH 3/5] virsh: Treat any command name starting with # as comment X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.47]); Sun, 24 Mar 2019 04:02:15 +0000 (UTC) Content-Type: text/plain; charset="utf-8" As the previous commit mentioned, argv mode (such as when you feed virsh via stdin with <<\EOF instead of via a single shell argument) didn't permit comments. Do this by treating any command name token that starts with # as a comment which silently eats all remaining arguments to the next newline or semicolon. Note that batch mode recognizes unquoted # at the start of any word as a command as part of the tokenizer, while this patch only treats # at the start of the command word as a comment (any other # remaining by the time vshCommandParse() is processing things was already quoted during the tokenzier, and as such was probably intended as the actual argument to the command word earlier in the line). Now I can do something like: $ virsh -c test:///default < --- tests/virshtest.c | 1 + tools/virsh.pod | 3 ++- tools/virt-admin.pod | 4 +++- tools/vsh.c | 11 +++++++++-- 4 files changed, 15 insertions(+), 4 deletions(-) diff --git a/tests/virshtest.c b/tests/virshtest.c index 5408db1387..3560e240a4 100644 --- a/tests/virshtest.c +++ b/tests/virshtest.c @@ -423,6 +423,7 @@ mymain(void) DO_TEST(44, "a # b\n", "echo a '#' b"); DO_TEST(45, "a # b\n", "echo a \\# b"); DO_TEST(46, "a\n", "#unbalanced 'quotes\"\necho a # b"); + DO_TEST(47, "a\n", "\\# ignored;echo a\n'#also' ignored"); # undef DO_TEST diff --git a/tools/virsh.pod b/tools/virsh.pod index 05adb568db..95cab7b57d 100644 --- a/tools/virsh.pod +++ b/tools/virsh.pod @@ -35,7 +35,8 @@ will be clear for each of those commands. Note: it is pe= rmissible to give numeric names to domains, however, doing so will result in a domain that can only be identified by domain id. In other words, if a numeric value is supplied it will be interpreted as a domain id, not -as a name. +as a name. Any I starting with B<#> is treated as a comment +and silently ignored, all other unrecognized Is are diagnosed. The B program can be used either to run one I by giving the command and its arguments on the shell command line, or a I diff --git a/tools/virt-admin.pod b/tools/virt-admin.pod index 8489325ca9..f06ee9247a 100644 --- a/tools/virt-admin.pod +++ b/tools/virt-admin.pod @@ -18,7 +18,9 @@ The basic structure of most virt-admin usage is: virt-admin [OPTION]... [ARG]... -Where I is one of the commands listed below. +Where I is one of the commands listed below. Any I +starting with B<#> is treated as a comment and silently ignored, all +other unrecognized Is are diagnosed. The B program can be used either to run one I by givi= ng the command and its arguments on the shell command line, or a I diff --git a/tools/vsh.c b/tools/vsh.c index 9a88ee29b7..d90ce8d102 100644 --- a/tools/vsh.c +++ b/tools/vsh.c @@ -1437,8 +1437,15 @@ vshCommandParse(vshControl *ctl, vshCommandParser *p= arser, vshCmd **partial) } if (cmd =3D=3D NULL) { - /* first token must be command name */ - if (!(cmd =3D vshCmddefSearch(tkdata))) { + /* first token must be command name or comment */ + if (*tkdata =3D=3D '#') { + do { + VIR_FREE(tkdata); + tk =3D parser->getNextArg(ctl, parser, &tkdata, fa= lse); + } while (tk =3D=3D VSH_TK_ARG); + VIR_FREE(tkdata); + break; + } else if (!(cmd =3D vshCmddefSearch(tkdata))) { if (!partial) vshError(ctl, _("unknown command: '%s'"), tkdata); goto syntaxError; /* ... or ignore this command only= ? */ --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sat Apr 20 13:10:16 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1553400153141717.9262794459827; Sat, 23 Mar 2019 21:02:33 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 110D53084215; Sun, 24 Mar 2019 04:02:32 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id DF5BB5C26D; Sun, 24 Mar 2019 04:02:31 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 9E4823FB30; Sun, 24 Mar 2019 04:02:31 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x2O42BBd010985 for ; Sun, 24 Mar 2019 00:02:11 -0400 Received: by smtp.corp.redhat.com (Postfix) id 475BC5C28F; Sun, 24 Mar 2019 04:02:11 +0000 (UTC) Received: from blue.redhat.com (ovpn-116-59.phx2.redhat.com [10.3.116.59]) by smtp.corp.redhat.com (Postfix) with ESMTP id DC2B05C280; Sun, 24 Mar 2019 04:02:10 +0000 (UTC) From: Eric Blake To: libvir-list@redhat.com Date: Sat, 23 Mar 2019 23:02:02 -0500 Message-Id: <20190324040203.24304-5-eblake@redhat.com> In-Reply-To: <20190324040203.24304-1-eblake@redhat.com> References: <20190324040203.24304-1-eblake@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com Cc: mprivozn@redhat.com Subject: [libvirt] [PATCH 4/5] virsh: Add 'echo --err' option X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.40]); Sun, 24 Mar 2019 04:02:32 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Since test:///default resets state on every connection, writing a test that covers a sequence of commands must be done from a single session. But if the test wants to exercise particular failure modes as well as successes, it can be nice to leave witnesses in the stderr stream immediately before and after the spot where the expected error should be, to ensure the rest of the script is not causing errors. Do this by adding an --err option. Signed-off-by: Eric Blake --- tools/virsh.pod | 4 +++- tools/vsh.c | 15 +++++++++++++-- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/tools/virsh.pod b/tools/virsh.pod index 95cab7b57d..c4ff0c745a 100644 --- a/tools/virsh.pod +++ b/tools/virsh.pod @@ -623,12 +623,14 @@ the usable CPU models are only limited by the hypervi= sor. This command will print that all CPU models are accepted for these architectures and the act= ual list of supported CPU models can be checked in the domain capabilities XML. -=3Ditem B [I<--shell>] [I<--xml>] [I...] +=3Ditem B [I<--shell>] [I<--xml>] [I...] [I...] Echo back each I, separated by space. If I<--shell> is specified, then the output will be single-quoted where needed, so that it is suitable for reuse in a shell context. If I<--xml> is specified, then the output will be escaped for use in XML. +If I<--err> is specified, prefix B<"error: "> and output to stderr +instead of stdout. =3Ditem B I [I] [I] [I] [I] [I<--error>] diff --git a/tools/vsh.c b/tools/vsh.c index d90ce8d102..65b96f87d5 100644 --- a/tools/vsh.c +++ b/tools/vsh.c @@ -3296,6 +3296,10 @@ const vshCmdOptDef opts_echo[] =3D { .type =3D VSH_OT_BOOL, .help =3D N_("escape for XML use") }, + {.name =3D "err", + .type =3D VSH_OT_BOOL, + .help =3D N_("output to stderr"), + }, {.name =3D "str", .type =3D VSH_OT_ALIAS, .help =3D "string" @@ -3329,6 +3333,7 @@ cmdEcho(vshControl *ctl, const vshCmd *cmd) { bool shell =3D false; bool xml =3D false; + bool err =3D false; int count =3D 0; const vshCmdOpt *opt =3D NULL; char *arg; @@ -3338,6 +3343,8 @@ cmdEcho(vshControl *ctl, const vshCmd *cmd) shell =3D true; if (vshCommandOptBool(cmd, "xml")) xml =3D true; + if (vshCommandOptBool(cmd, "err")) + err =3D true; while ((opt =3D vshCommandOptArgv(ctl, cmd, opt))) { char *str; @@ -3372,8 +3379,12 @@ cmdEcho(vshControl *ctl, const vshCmd *cmd) return false; } arg =3D virBufferContentAndReset(&buf); - if (arg) - vshPrint(ctl, "%s", arg); + if (arg) { + if (err) + vshError(ctl, "%s", arg); + else + vshPrint(ctl, "%s", arg); + } VIR_FREE(arg); return true; } --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sat Apr 20 13:10:16 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 155340015987856.520115381005326; Sat, 23 Mar 2019 21:02:39 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 809C6307CDE3; Sun, 24 Mar 2019 04:02:38 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 4776C600D4; Sun, 24 Mar 2019 04:02:38 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 10B563FAF5; Sun, 24 Mar 2019 04:02:38 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x2O42Dwu011000 for ; Sun, 24 Mar 2019 00:02:13 -0400 Received: by smtp.corp.redhat.com (Postfix) id AE3FA5C280; Sun, 24 Mar 2019 04:02:13 +0000 (UTC) Received: from blue.redhat.com (ovpn-116-59.phx2.redhat.com [10.3.116.59]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6A36F5C26D; Sun, 24 Mar 2019 04:02:11 +0000 (UTC) From: Eric Blake To: libvir-list@redhat.com Date: Sat, 23 Mar 2019 23:02:03 -0500 Message-Id: <20190324040203.24304-6-eblake@redhat.com> In-Reply-To: <20190324040203.24304-1-eblake@redhat.com> References: <20190324040203.24304-1-eblake@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com Cc: mprivozn@redhat.com Subject: [libvirt] [PATCH 5/5] snapshot: Add tests of virsh -c test:///default snapshot* X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.49]); Sun, 24 Mar 2019 04:02:39 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Had this been in place earlier, I would have avoided the bugs in commit 0baf6945 and 55c2ab3e. Writing the test required me to extend the power of virsh - creating enough snapshots to cause fanout requires enough input in a single session that adding comments and markers makes it easier to check that output is correct. It's still a bit odd that with test:///default, reverting to a snapshot changes the domain from running to paused (possibly a bug in how the test driver copied from the qemu driver) - but the important part is that the test is reproducible, and any future tweaks we make to snapshot code have less chance of breaking successful command sequences. Signed-off-by: Eric Blake --- tests/Makefile.am | 3 +- tests/virsh-snapshot | 212 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 214 insertions(+), 1 deletion(-) create mode 100755 tests/virsh-snapshot diff --git a/tests/Makefile.am b/tests/Makefile.am index 29f1fe2d2a..d3cdbff8bb 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -1,6 +1,6 @@ ## Process this file with automake to produce Makefile.in -## Copyright (C) 2005-2015 Red Hat, Inc. +## Copyright (C) 2005-2019 Red Hat, Inc. ## ## This library is free software; you can redistribute it and/or ## modify it under the terms of the GNU Lesser General Public @@ -410,6 +410,7 @@ libvirtd_test_scripts =3D \ virsh-schedinfo \ virsh-self-test \ virt-admin-self-test \ + virsh-snapshot \ virsh-start \ virsh-undefine \ virsh-uriprecedence \ diff --git a/tests/virsh-snapshot b/tests/virsh-snapshot new file mode 100755 index 0000000000..3e6ff39f5f --- /dev/null +++ b/tests/virsh-snapshot @@ -0,0 +1,212 @@ +#!/bin/sh +# simple testing of snapshot APIs on test driver + +# Copyright (C) 2019 Red Hat, Inc. + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 2 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program. If not, see +# . + +. "$(dirname $0)/test-lib.sh" + +if test "$VERBOSE" =3D yes; then + set -x + $abs_top_builddir/tools/virsh --version +fi + +fail=3D0 + +# The test driver loses states between restarts, so we perform a script +# with some convenient markers for later post-processing of output. +$abs_top_builddir/tools/virsh --connect test:///default >out 2>err ' + # Create a series of snapshots, with names that intentionally sort + # differently by topology than by name. Use revert to create fanout. + snapshot-create-as test s1 + snapshot-create-as test s3 + snapshot-create-as test s2 + snapshot-revert test s3 + snapshot-create-as test s6 + snapshot-create-as test s5 + snapshot-revert test s6 + snapshot-create-as test s4 + snapshot-revert test s1 + snapshot-create-as test s7 + snapshot-create-as test s8 + # Checking tree view (siblings sorted alphabetically) + snapshot-list test --tree + # Current was last one created, but we can change that + snapshot-current test --name + snapshot-current test s1 + snapshot-current test --name + # Deleting current root leads to multiple roots, demonstrate list filter= ing + snapshot-delete test --current + echo --err marker + snapshot-current test --name + echo --err marker + snapshot-list test --roots + snapshot-list test --leaves + snapshot-list test --parent --no-leaves + snapshot-list test --from s3 + snapshot-list test --from s3 --descendants --name + # More fun with delete flags, current node moves up to remaining parent + snapshot-current test s4 + snapshot-delete test --children-only s6 + snapshot-current test --name + snapshot-delete test --children s7 + snapshot-current test --name + snapshot-delete test s6 + snapshot-current test --name + # Now the tree is linear, so we have an unambiguous topological order + snapshot-list test --name + snapshot-list test --name --topological + # Capture some XML for later redefine + echo "" + snapshot-dumpxml test s3 + echo "" + snapshot-dumpxml test s2 + echo "" + # All done +' || fail=3D1 + +# First part is expected output, --tree results in trailing spaces, +# and --list produces timestamps +sed 's/ *$//; s/[0-9-]\{10\} [0-9:.]* .[0-9]\{4\}/TIMESTAMP/; + /MarkerA/,/MarkerC/d' < out > out.cooked || fail=3D1 +# Second part holds domain XMLs +sed -n '/MarkerA/,/MarkerB/p' < out > s3.xml || fail=3D1 +sed -n '/MarkerB/,/MarkerC/p' < out > s2.xml || fail=3D1 + +cat <<\EOF > exp || fail=3D1 +Domain snapshot s1 created +Domain snapshot s3 created +Domain snapshot s2 created + +Domain snapshot s6 created +Domain snapshot s5 created + +Domain snapshot s4 created + +Domain snapshot s7 created +Domain snapshot s8 created +s1 + | + +- s3 + | | + | +- s2 + | +- s6 + | | + | +- s4 + | +- s5 + | + +- s7 + | + +- s8 + + +s8 +Snapshot s1 set as current +s1 +Domain snapshot s1 deleted + + + + + Name Creation Time State +--------------------------------------------- + s3 TIMESTAMP running + s7 TIMESTAMP paused + + Name Creation Time State +--------------------------------------------- + s2 TIMESTAMP running + s4 TIMESTAMP paused + s5 TIMESTAMP paused + s8 TIMESTAMP paused + + Name Creation Time State Parent +------------------------------------------------------ + s3 TIMESTAMP running + s6 TIMESTAMP paused s3 + s7 TIMESTAMP paused + + Name Creation Time State +--------------------------------------------- + s2 TIMESTAMP running + s6 TIMESTAMP paused + +s2 +s4 +s5 +s6 + +Snapshot s4 set as current +Domain snapshot s6 children deleted + +s6 +Domain snapshot s7 deleted + +s6 +Domain snapshot s6 deleted + +s3 +s2 +s3 + +s3 +s2 + +EOF +compare exp out.cooked || fail=3D1 + +cat < exp || fail=3D1 +error: marker +error: domain 'test' has no current snapshot +error: marker +EOF +compare exp err || fail=3D1 + +# Restore state with redefine +$abs_top_builddir/tools/virsh -c test:///default >out 2>err < exp || fail=3D1 + + +Domain snapshot s3 created from 's3.xml' +Domain snapshot s2 created from 's2.xml' +Name: s2 +Domain: test +Current: yes +State: running +Location: internal +Parent: s3 +Children: 0 +Descendants: 0 +Metadata: yes + +EOF + +cat < exp || fail=3D1 +error: invalid argument: parent s3 for snapshot s2 not found +error: marker +EOF +compare exp err || fail=3D1 + +(exit $fail); exit $fail --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list