public inbox for kdevops@lists.linux.dev
 help / color / mirror / Atom feed
From: Daniel Gomez <da.gomez@kernel.org>
To: kdevops@lists.linux.dev, Luis Chamberlain <mcgrof@kernel.org>,
	 Daniel Gomez <da.gomez@samsung.com>
Cc: Daniel Gomez <da.gomez@kernel.org>
Subject: [PATCH v2 1/4] guestfs: bringup: check if domain exists
Date: Mon, 12 May 2025 15:36:02 +0200	[thread overview]
Message-ID: <20250512-bringup-guestfs-debug-v2-1-bd5691108448@samsung.com> (raw)
In-Reply-To: <20250512-bringup-guestfs-debug-v2-0-bd5691108448@samsung.com>

From: Daniel Gomez <da.gomez@samsung.com>

virsh domstate fails (exit 1) if domain checked does not exist. This
conflicts when debugging the script with set -euxo pipefile. Replace the
command with virsh list --all and search for the domain in the list.
Also, capture the state to avoid trying to start a domain that is
already running.

Signed-off-by: Daniel Gomez <da.gomez@samsung.com>
---
 scripts/bringup_guestfs.sh | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/scripts/bringup_guestfs.sh b/scripts/bringup_guestfs.sh
index 7cafa7ffafb058b31cca4baa7228b7fd4c0b9119..1d377faf387888a4523a838fd292654e5deddd82 100755
--- a/scripts/bringup_guestfs.sh
+++ b/scripts/bringup_guestfs.sh
@@ -316,10 +316,12 @@ do
 	# If the guest is already defined, then just stop what we're doing
 	# and plead to the developer to clean things up.
 	#
-	virsh domstate $name 1>/dev/null 2>&1
-	if [ $? -eq 0 ]; then
-		echo "Domain $name is already defined."
-		virsh start $name
+	if virsh list --all | grep --quiet --word-regexp "$name"; then
+		output_domstate=$(virsh domstate $name 2>/dev/null)
+		echo "Domain $name is already defined. (state: $output_domstate)"
+		if [ "$output_domstate" != "running" ]; then
+			virsh start $name
+		fi
 		exit 0
 	fi
 

-- 
2.49.0


  reply	other threads:[~2025-05-12 13:36 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-05-12 13:36 [PATCH v2 0/4] guestfs: bringup: add debug mode Daniel Gomez
2025-05-12 13:36 ` Daniel Gomez [this message]
2025-05-12 13:36 ` [PATCH v2 2/4] guestfs: bringup: fix unbound variable when debug Daniel Gomez
2025-05-12 13:36 ` [PATCH v2 3/4] guestfs: bringup: fix user check " Daniel Gomez
2025-05-12 13:36 ` [PATCH v2 4/4] guestfs: bringup: add debug mode Daniel Gomez
2025-05-12 15:43 ` [PATCH v2 0/4] " Chuck Lever
2025-05-13  5:49   ` Daniel Gomez
2025-05-14 18:28 ` Luis Chamberlain

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250512-bringup-guestfs-debug-v2-1-bd5691108448@samsung.com \
    --to=da.gomez@kernel.org \
    --cc=da.gomez@samsung.com \
    --cc=kdevops@lists.linux.dev \
    --cc=mcgrof@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox