Merge remote-tracking branch 'qubesos/pr/44'

* qubesos/pr/44:
  Fix style else-return
  tests: update qvm-template-process and qvm-remove tests
  Add --force to manpage.
  Avoid cloning installed_by_rpm
  Print vm list before prompt
  Use --force instead of --yes
  Toggle installed_by_rpm in template tool
  Fix error message grammar
  Add --yes option and confirm prompt.
This commit is contained in:
Marek Marczykowski-Górecki 2018-01-06 14:54:32 +01:00
commit 51a89a9e77
No known key found for this signature in database
GPG Key ID: 063938BA42CFA724
6 changed files with 42 additions and 8 deletions

View File

@ -14,7 +14,7 @@
Synopsis
--------
:command:`qvm-remove` [-h] [--verbose] [--quiet] [--force-root] [--all] [--exclude *EXCLUDE*] [--just-db] [*VMNAME* [*VMNAME* ...]]
:command:`qvm-remove` [-h] [--verbose] [--quiet] [--force] [--force-root] [--all] [--exclude *EXCLUDE*] [--just-db] [*VMNAME* [*VMNAME* ...]]
Options
-------
@ -28,6 +28,10 @@ Options
Exclude the qube from :option:`--all`.
.. option:: --force, -f
Do not prompt for confirmation; assume 'yes'.
.. option:: --help, -h
Show this help message and exit

View File

@ -334,7 +334,8 @@ class QubesBase(qubesadmin.base.PropertyHolder):
assert isinstance(dst_vm, qubesadmin.vm.QubesVM)
for prop in src_vm.property_list():
# handled by admin.vm.Create call
if prop in ('name', 'qid', 'template', 'label', 'uuid'):
if prop in ('name', 'qid', 'template', 'label', 'uuid', \
'installed_by_rpm'):
continue
if src_vm.property_is_default(prop):
continue

View File

@ -31,5 +31,5 @@ class TC_00_qvm_remove(qubesadmin.tests.QubesTestCase):
self.app.expected_calls[
('some-vm', 'admin.vm.Remove', None, None)] = \
b'0\x00\n'
qubesadmin.tools.qvm_remove.main(['some-vm'], app=self.app)
qubesadmin.tools.qvm_remove.main(['-f', 'some-vm'], app=self.app)
self.assertAllCalled()

View File

@ -240,6 +240,9 @@ class TC_00_qvm_template_postprocess(qubesadmin.tests.QubesTestCase):
self.app.expected_calls[
('test-vm', 'admin.vm.property.Set', 'netvm', b'')] = b'0\0'
self.app.expected_calls[
('test-vm', 'admin.vm.property.Set', 'installed_by_rpm', b'True')] \
= b'0\0'
self.app.expected_calls[
('test-vm', 'admin.vm.property.Reset', 'netvm', None)] = b'0\0'
self.app.expected_calls[
@ -290,6 +293,9 @@ class TC_00_qvm_template_postprocess(qubesadmin.tests.QubesTestCase):
self.app.expected_calls[
('test-vm', 'admin.vm.property.Set', 'netvm', b'')] = b'0\0'
self.app.expected_calls[
('test-vm', 'admin.vm.property.Set', 'installed_by_rpm', b'True')] \
= b'0\0'
self.app.expected_calls[
('test-vm', 'admin.vm.property.Reset', 'netvm', None)] = b'0\0'
self.app.expected_calls[
@ -335,6 +341,9 @@ class TC_00_qvm_template_postprocess(qubesadmin.tests.QubesTestCase):
mock_import_appmenus):
self.app.expected_calls[('dom0', 'admin.vm.List', None, None)] = \
b'0\0test-vm class=TemplateVM state=Halted\n'
self.app.expected_calls[
('test-vm', 'admin.vm.property.Set', 'installed_by_rpm', b'True')] \
= b'0\0'
self.app.add_new_vm = mock.Mock()
if qubesadmin.tools.qvm_template_postprocess.have_events:
@ -365,6 +374,9 @@ class TC_00_qvm_template_postprocess(qubesadmin.tests.QubesTestCase):
b'0\0test-vm class=TemplateVM state=Halted\n'
self.app.expected_calls[('test-vm', 'admin.vm.Remove', None, None)] = \
b'0\0'
self.app.expected_calls[
('test-vm', 'admin.vm.property.Set', 'installed_by_rpm', b'False')]\
= b'0\0'
self.app.expected_calls[
('test-vm', 'admin.vm.property.Get', 'template', None)] = \
b'2\0QubesNoSuchPropertyError\0\0invalid property \'template\' of ' \

View File

@ -28,14 +28,29 @@ from qubesadmin.tools import QubesArgumentParser
parser = QubesArgumentParser(description=__doc__,
want_app=True,
vmname_nargs='+')
parser.add_argument("--force", "-f", action="store_true", dest="no_confirm",
default=False, help="Do not prompt for confirmation")
def main(args=None, app=None): # pylint: disable=missing-docstring
args = parser.parse_args(args, app=app)
for vm in args.domains:
del args.app.domains[vm.name]
go_ahead = ""
if not args.no_confirm:
print("This will completely remove the selected VM(s)...")
for vm in args.domains:
print(" ", vm.name)
go_ahead = input("Are you sure? [y/N] ").upper()
if args.no_confirm or go_ahead == "Y":
for vm in args.domains:
del args.app.domains[vm.name]
retcode = 0
else:
print("Remove cancelled.")
retcode = 1
return retcode
return 0
if __name__ == '__main__':

View File

@ -205,6 +205,7 @@ def post_install(args):
# if data import fails, remove half-created VM
del app.domains[vm.name]
raise
vm.installed_by_rpm = True
import_appmenus(vm, args.dir)
if not args.skip_start:
@ -222,10 +223,11 @@ def pre_remove(args):
try:
tpl = app.domains[args.name]
except KeyError:
parser.error('Qube with this name do not exist')
parser.error('No Qube with this name exists')
for appvm in tpl.appvms:
parser.error('Qube {} use this template'.format(appvm.name))
parser.error('Qube {} uses this template'.format(appvm.name))
tpl.installed_by_rpm = False
del app.domains[args.name]
return 0