Skip to content

Commit

Permalink
Improve qvm-check mechanism on invalid domains
Browse files Browse the repository at this point in the history
  • Loading branch information
alimirjamali committed Jul 10, 2024
1 parent 1334d7a commit 06bfde3
Showing 1 changed file with 28 additions and 4 deletions.
32 changes: 28 additions & 4 deletions qubesadmin/tools/qvm_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,33 @@
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#
""" Exits sucessfull if the provided domains exists, else returns failure """
""" Exits sucessfull if the provided domain(s) exist, else returns failure """

import sys

import qubesadmin.tools
import qubesadmin.vm

parser = qubesadmin.tools.QubesArgumentParser(description=__doc__,
vmname_nargs='+')
class QvmCheckArgumentParser(qubesadmin.tools.QubesArgumentParser):
"""Collecting error message(s) on invalid domain(s) instead of aborting"""
def __init__(self, description, vmname_nargs):
super().__init__(description=description, vmname_nargs=vmname_nargs)
self._invalid_domains = []

def error(self, message):
if message.startswith('no such domain: '):
self._invalid_domains.append(message[17:])

Check warning on line 38 in qubesadmin/tools/qvm_check.py

View check run for this annotation

Codecov / codecov/patch

qubesadmin/tools/qvm_check.py#L37-L38

Added lines #L37 - L38 were not covered by tests
else:
super().error(message)

Check warning on line 40 in qubesadmin/tools/qvm_check.py

View check run for this annotation

Codecov / codecov/patch

qubesadmin/tools/qvm_check.py#L40

Added line #L40 was not covered by tests

def parse_args(self, *args, **kwargs):
parse_args = super().parse_args(*args, **kwargs)
self._invalid_domains.sort()
parse_args.invalid_domains = self._invalid_domains
return parse_args


parser = QvmCheckArgumentParser(description=__doc__, vmname_nargs='+')
parser.add_argument("--running", action="store_true", dest="running",
default=False,
help="Determine if (any of given) VM is running")
Expand All @@ -44,7 +62,7 @@


def print_msg(log, domains, status):
"""Print message in appropriate form about given domain(s)"""
"""Print message in appropriate form about given valid domain(s)"""
if not domains:
log.info("None of qubes: {!s}".format(', '.join(status)))
else:
Expand Down Expand Up @@ -103,6 +121,12 @@ def main(args=None, app=None):
elif args.verbose:
print_msg(log, domains, ["exists"])

if args.invalid_domains:
if args.verbose:
for vm in args.invalid_domains:
log.warning("{!s}: {!s}".format(vm, 'non-existent!'))
return_code = 1

Check warning on line 128 in qubesadmin/tools/qvm_check.py

View check run for this annotation

Codecov / codecov/patch

qubesadmin/tools/qvm_check.py#L125-L128

Added lines #L125 - L128 were not covered by tests

return return_code


Expand Down

0 comments on commit 06bfde3

Please sign in to comment.