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

* qubesos/pr/65:
  Add 'make clean' target, use it for Debian build
  doc: adjust example in qvm-pool man page
  tools/qvm-pool: add --set to modify pool properties
  tools: fix error reporing on unknown storage pool
This commit is contained in:
Marek Marczykowski-Górecki 2018-04-14 22:15:26 +02:00
commit f46afecfe4
No known key found for this signature in database
GPG Key ID: 063938BA42CFA724
7 changed files with 73 additions and 2 deletions

1
.gitignore vendored
View File

@ -3,3 +3,4 @@
build/
pkgs/
.coverage
__pycache__

View File

@ -12,3 +12,9 @@ install:
$(PYTHON) setup.py install -O1 $(PYTHON_PREFIX_ARG) --root $(DESTDIR)
install -d $(DESTDIR)/etc/xdg/autostart
install -m 0644 etc/qvm-start-gui.desktop $(DESTDIR)/etc/xdg/autostart/
clean:
rm -rf test-packages/__pycache__ qubesadmin/__pycache__
rm -rf qubesadmin/*/__pycache__ qubesadmin/tests/*/__pycache__
rm -rf test-packages/*.egg-info
rm -f .coverage

4
debian/rules vendored
View File

@ -37,6 +37,10 @@ override_dh_auto_install:
install -m 0644 build/man/* \
debian/qubes-core-admin-client/usr/share/man/man1/
override_dh_clean:
dh_clean -O--buildsystem=pybuild
make clean
# debmake generated override targets
# This is example for Cmake (See http://bugs.debian.org/641051 )
#override_dh_auto_configure:

View File

@ -51,14 +51,19 @@ Options
qubes.xml, but does not delete any content (FIXME: is it really true for
all pool drivers?).
.. option:: --set NAME, -s NAME
Modify a pool. This set options of a pool. Use ``--o`` to specify actual modifications.
Examples
--------
Create a pool backed by the default `xen` driver.
Create a pool backed by the `file` driver.
::
qvm-pool -o dir_path=/mnt/foo -a foo xen
qvm-pool -o dir_path=/mnt/foo -a foo file
Authors
-------

View File

@ -92,3 +92,25 @@ class TC_00_qvm_pool(qubesadmin.tests.QubesTestCase):
'volume_group qubes_dom0\n'
)
self.assertAllCalled()
def test_050_set(self):
self.app.expected_calls[('dom0', 'admin.pool.List', None, None)] = \
b'0\x00pool-file\npool-lvm\n'
self.app.expected_calls[
('dom0', 'admin.pool.Set.revisions_to_keep', 'pool-lvm', b'2')] = \
b'0\x00'
self.assertEqual(0,
qubesadmin.tools.qvm_pool.main(['-s', 'pool-lvm', '-o',
'revisions_to_keep=2'],
app=self.app))
self.assertAllCalled()
def test_051_set_invalid(self):
self.app.expected_calls[('dom0', 'admin.pool.List', None, None)] = \
b'0\x00pool-file\npool-lvm\n'
with self.assertRaises(SystemExit) as e:
qubesadmin.tools.qvm_pool.main(
['-s', 'pool-lvm', '-o', 'prop=1'],
app=self.app)
self.assertEqual(e.exception.code, 2)
self.assertAllCalled()

View File

@ -314,6 +314,9 @@ class PoolsAction(QubesAction):
except qubesadmin.exc.QubesException as e:
parser.error(str(e))
sys.exit(2)
except KeyError:
parser.error('No such pools: %s' % pool_names)
sys.exit(2)
class QubesArgumentParser(argparse.ArgumentParser):

View File

@ -92,6 +92,23 @@ class _Add(argparse.Action):
setattr(namespace, 'driver', driver)
class _Set(qubesadmin.tools.PoolsAction):
''' Action for argument parser that sets pool options. '''
def __init__(self, option_strings, dest=None, default=None, metavar=None):
super(_Set, self).__init__(option_strings=option_strings,
dest=dest,
metavar=metavar,
default=default,
help='modify pool (use -o to specify '
'modifications)')
def __call__(self, parser, namespace, name, option_string=None):
print('dupa')
setattr(namespace, 'command', 'set')
super(_Set, self).__call__(parser, namespace, name, option_string)
class _Options(argparse.Action):
''' Action for argument parser that parsers options. '''
@ -127,6 +144,8 @@ def get_parser():
dest='command',
metavar=('NAME', 'DRIVER'))
group.add_argument('-r', '--remove', metavar='NAME', action=_Remove)
group.add_argument('-s', '--set', metavar='POOLNAME', dest='pool',
action=_Set, default=[])
group.add_argument('--help-drivers',
dest='command',
const='list-drivers',
@ -173,6 +192,17 @@ def main(args=None, app=None):
elif args.command == 'info':
for pool in args.pools:
pool_info(pool)
elif args.command == 'set':
pool = args.pool[0]
for opt, value in args.options.items():
if not hasattr(type(pool), opt):
parser.error('setting pool option %s is not supported' % (
pool.name))
try:
setattr(pool, opt, value)
except qubesadmin.exc.QubesException as e:
parser.error('failed to set pool %s option %s: %s\n' % (
pool.name, opt, str(e)))
return 0