From 188b3285668b7dad173ca8aa12ba01e129194c78 Mon Sep 17 00:00:00 2001
From: Mark Goddard <mark@stackhpc.com>
Date: Wed, 30 Mar 2022 12:29:09 +0100
Subject: [PATCH] libvirt: Fix nova-libvirt-cleanup command

This change addresses an issue in the nova-libvirt-cleanup command,
added in I46854ed7eaf1d5b5e3ccd8531c963427848bdc99.

Check for rc=1 pgrep command, since a lack of matches is a pass.

Also, use bash for set -o pipefail.

Change-Id: Iffda0dfffce8768324ffec55e629134c70e2e996
---
 ansible/roles/nova-cell/tasks/libvirt-cleanup.yml | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/ansible/roles/nova-cell/tasks/libvirt-cleanup.yml b/ansible/roles/nova-cell/tasks/libvirt-cleanup.yml
index 4ec206f44e..1e9c24cde2 100644
--- a/ansible/roles/nova-cell/tasks/libvirt-cleanup.yml
+++ b/ansible/roles/nova-cell/tasks/libvirt-cleanup.yml
@@ -14,12 +14,14 @@
   register: container_facts
 
 - block:
+    # NOTE(mgoddard): pgrep exit status 1 means no match.
     - name: Check if there are any running VMs
       become: true
       shell:
         cmd: >
           set -o pipefail &&
-          pgrep -l qemu | awk '!/qemu-ga/  && !/qemu-img/ {print $1}'
+          { pgrep -l qemu || test $? = 1; } | awk '!/qemu-ga/  && !/qemu-img/ {print $1}'
+        executable: /bin/bash
       register: running_vms
 
     - name: Fail if there are any running VMs