Skip to content

Commit b3f15f5

Browse files
author
anon
committed
remove dead code around args.wait
1 parent 277b5fe commit b3f15f5

1 file changed

Lines changed: 17 additions & 19 deletions

File tree

qubesadmin/tools/qvm_shutdown.py

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -71,33 +71,32 @@ def main(args=None, app=None): # pylint: disable=missing-docstring
7171

7272
loop = asyncio.new_event_loop()
7373
asyncio.set_event_loop(loop)
74-
remaining_domains = args.domains
74+
remaining_domains = set(args.domains)
7575
for _ in range(len(args.domains)):
76-
this_round_domains = set(remaining_domains)
77-
if not this_round_domains:
76+
if not remaining_domains:
7877
break
79-
remaining_domains = set()
78+
shutdown_failed = set()
8079
if not args.dry_run:
81-
for vm in this_round_domains:
80+
for vm in remaining_domains:
8281
try:
8382
vm.shutdown(force=force)
8483
except qubesadmin.exc.QubesVMNotStartedError:
8584
pass
8685
except qubesadmin.exc.QubesException as e:
8786
if not args.wait:
8887
vm.log.error('Shutdown error: {}'.format(e))
89-
else:
90-
remaining_domains.add(vm)
88+
shutdown_failed.add(vm)
9189
if not args.wait:
9290
if shutdown_failed:
9391
parser.error_runtime(
9492
'Failed to shut down: ' +
9593
', '.join(vm.name for vm in shutdown_failed),
9694
len(shutdown_failed))
9795
return
98-
this_round_domains.difference_update(remaining_domains)
99-
if not this_round_domains:
100-
# no VM shutdown request succeed, no sense to try again
96+
awaiting = remaining_domains - shutdown_failed
97+
remaining_domains = shutdown_failed
98+
if not awaiting:
99+
# no VM shutdown request succeeded, no sense to try again
101100
break
102101

103102
try:
@@ -107,7 +106,7 @@ def main(args=None, app=None): # pylint: disable=missing-docstring
107106
awaiting), args.timeout))
108107
except (TimeoutError, asyncio.TimeoutError):
109108
if not args.dry_run:
110-
current_vms = failed_domains(this_round_domains)
109+
current_vms = failed_domains(awaiting)
111110
if current_vms:
112111
args.app.log.info(
113112
'Killing remaining qubes: {}'
@@ -121,14 +120,13 @@ def main(args=None, app=None): # pylint: disable=missing-docstring
121120
except qubesadmin.exc.QubesException as e:
122121
parser.error_runtime(e)
123122

124-
if args.wait:
125-
loop.close()
126-
failed = failed_domains(args.domains)
127-
if failed:
128-
parser.error_runtime(
129-
'Failed to shut down: ' +
130-
', '.join(vm.name for vm in failed),
131-
len(failed))
123+
loop.close()
124+
failed = failed_domains(args.domains)
125+
if failed:
126+
parser.error_runtime(
127+
'Failed to shut down: ' +
128+
', '.join(vm.name for vm in failed),
129+
len(failed))
132130

133131

134132
if __name__ == '__main__':

0 commit comments

Comments
 (0)