From 4ceff0f8c07d9046435dc026b4a56d2690c47e83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Marczykowski-G=C3=B3recki?= Date: Thu, 11 May 2017 23:21:04 +0200 Subject: [PATCH] Rename qubesmgmt to qubesadmin module QubesOS/qubes-issues#853 --- .travis.yml | 2 +- Makefile.builder | 2 +- README.md | 2 +- ci/coveragerc | 4 +- doc/conf.py | 4 +- doc/skel-manpage.py | 6 +- {qubesmgmt => qubesadmin}/__init__.py | 14 +- {qubesmgmt => qubesadmin}/app.py | 48 ++--- {qubesmgmt => qubesadmin}/base.py | 36 ++-- {qubesmgmt => qubesadmin}/config.py | 0 {qubesmgmt => qubesadmin}/devices.py | 0 {qubesmgmt => qubesadmin}/events/__init__.py | 12 +- {qubesmgmt => qubesadmin}/exc.py | 0 {qubesmgmt => qubesadmin}/features.py | 0 {qubesmgmt => qubesadmin}/firewall.py | 0 {qubesmgmt => qubesadmin}/label.py | 6 +- {qubesmgmt => qubesadmin}/log.py | 0 {qubesmgmt => qubesadmin}/storage.py | 0 {qubesmgmt => qubesadmin}/tests/__init__.py | 6 +- {qubesmgmt => qubesadmin}/tests/app.py | 32 ++-- {qubesmgmt => qubesadmin}/tests/devices.py | 44 ++--- {qubesmgmt => qubesadmin}/tests/errors.py | 14 +- {qubesmgmt => qubesadmin}/tests/events.py | 14 +- {qubesmgmt => qubesadmin}/tests/firewall.py | 174 +++++++++--------- {qubesmgmt => qubesadmin}/tests/label.py | 6 +- {qubesmgmt => qubesadmin}/tests/storage.py | 18 +- .../tests/tools/__init__.py | 0 {qubesmgmt => qubesadmin}/tests/tools/init.py | 34 ++-- .../tests/tools/qubes_prefs.py | 22 +-- .../tests/tools/qvm_check.py | 50 ++--- .../tests/tools/qvm_clone.py | 18 +- .../tests/tools/qvm_create.py | 22 +-- .../tests/tools/qvm_device.py | 44 ++--- .../tests/tools/qvm_features.py | 52 +++--- .../tests/tools/qvm_firewall.py | 54 +++--- .../tests/tools/qvm_kill.py | 20 +- .../tests/tools/qvm_ls.py | 40 ++-- .../tests/tools/qvm_pause.py | 22 +-- .../tests/tools/qvm_pool.py | 24 +-- .../tests/tools/qvm_prefs.py | 26 +-- .../tests/tools/qvm_remove.py | 10 +- .../tests/tools/qvm_run.py | 20 +- .../tests/tools/qvm_shutdown.py | 20 +- .../tests/tools/qvm_start.py | 20 +- .../tests/tools/qvm_start_gui.py | 18 +- .../tests/tools/qvm_unpause.py | 20 +- .../tests/tools/qvm_volume.py | 34 ++-- .../tests/vm/__init__.py | 4 +- {qubesmgmt => qubesadmin}/tests/vm/actions.py | 4 +- .../tests/vm/properties.py | 10 +- {qubesmgmt => qubesadmin}/tests/vm/storage.py | 4 +- {qubesmgmt => qubesadmin}/tools/__init__.py | 18 +- {qubesmgmt => qubesadmin}/tools/dochelpers.py | 8 +- .../tools/qubes_prefs.py | 8 +- {qubesmgmt => qubesadmin}/tools/qvm_check.py | 8 +- {qubesmgmt => qubesadmin}/tools/qvm_clone.py | 2 +- {qubesmgmt => qubesadmin}/tools/qvm_create.py | 18 +- {qubesmgmt => qubesadmin}/tools/qvm_device.py | 34 ++-- .../tools/qvm_features.py | 8 +- .../tools/qvm_firewall.py | 14 +- {qubesmgmt => qubesadmin}/tools/qvm_kill.py | 8 +- {qubesmgmt => qubesadmin}/tools/qvm_ls.py | 26 +-- {qubesmgmt => qubesadmin}/tools/qvm_pause.py | 6 +- {qubesmgmt => qubesadmin}/tools/qvm_pool.py | 22 +-- {qubesmgmt => qubesadmin}/tools/qvm_prefs.py | 10 +- {qubesmgmt => qubesadmin}/tools/qvm_remove.py | 2 +- {qubesmgmt => qubesadmin}/tools/qvm_run.py | 8 +- .../tools/qvm_shutdown.py | 8 +- {qubesmgmt => qubesadmin}/tools/qvm_start.py | 8 +- .../tools/qvm_start_gui.py | 20 +- .../tools/qvm_unpause.py | 6 +- {qubesmgmt => qubesadmin}/tools/qvm_volume.py | 30 +-- {qubesmgmt => qubesadmin}/utils.py | 4 +- {qubesmgmt => qubesadmin}/vm/__init__.py | 24 +-- ...ient.spec => qubes-core-admin-client.spec} | 34 ++-- run-tests | 2 +- setup.py | 18 +- test-packages/.gitignore | 2 +- 78 files changed, 696 insertions(+), 696 deletions(-) rename {qubesmgmt => qubesadmin}/__init__.py (79%) rename {qubesmgmt => qubesadmin}/app.py (92%) rename {qubesmgmt => qubesadmin}/base.py (89%) rename {qubesmgmt => qubesadmin}/config.py (100%) rename {qubesmgmt => qubesadmin}/devices.py (100%) rename {qubesmgmt => qubesadmin}/events/__init__.py (95%) rename {qubesmgmt => qubesadmin}/exc.py (100%) rename {qubesmgmt => qubesadmin}/features.py (100%) rename {qubesmgmt => qubesadmin}/firewall.py (100%) rename {qubesmgmt => qubesadmin}/label.py (94%) rename {qubesmgmt => qubesadmin}/log.py (100%) rename {qubesmgmt => qubesadmin}/storage.py (100%) rename {qubesmgmt => qubesadmin}/tests/__init__.py (98%) rename {qubesmgmt => qubesadmin}/tests/app.py (94%) rename {qubesmgmt => qubesadmin}/tests/devices.py (88%) rename {qubesmgmt => qubesadmin}/tests/errors.py (84%) rename {qubesmgmt => qubesadmin}/tests/events.py (95%) rename {qubesmgmt => qubesadmin}/tests/firewall.py (72%) rename {qubesmgmt => qubesadmin}/tests/label.py (95%) rename {qubesmgmt => qubesadmin}/tests/storage.py (95%) rename {qubesmgmt => qubesadmin}/tests/tools/__init__.py (100%) rename {qubesmgmt => qubesadmin}/tests/tools/init.py (84%) rename {qubesmgmt => qubesadmin}/tests/tools/qubes_prefs.py (81%) rename {qubesmgmt => qubesadmin}/tests/tools/qvm_check.py (84%) rename {qubesmgmt => qubesadmin}/tests/tools/qvm_clone.py (81%) rename {qubesmgmt => qubesadmin}/tests/tools/qvm_create.py (85%) rename {qubesmgmt => qubesadmin}/tests/tools/qvm_device.py (87%) rename {qubesmgmt => qubesadmin}/tests/tools/qvm_features.py (84%) rename {qubesmgmt => qubesadmin}/tests/tools/qvm_firewall.py (84%) rename {qubesmgmt => qubesadmin}/tests/tools/qvm_kill.py (79%) rename {qubesmgmt => qubesadmin}/tests/tools/qvm_ls.py (82%) rename {qubesmgmt => qubesadmin}/tests/tools/qvm_pause.py (81%) rename {qubesmgmt => qubesadmin}/tests/tools/qvm_pool.py (83%) rename {qubesmgmt => qubesadmin}/tests/tools/qvm_prefs.py (83%) rename {qubesmgmt => qubesadmin}/tests/tools/qvm_remove.py (84%) rename {qubesmgmt => qubesadmin}/tests/tools/qvm_run.py (94%) rename {qubesmgmt => qubesadmin}/tests/tools/qvm_shutdown.py (80%) rename {qubesmgmt => qubesadmin}/tests/tools/qvm_start.py (79%) rename {qubesmgmt => qubesadmin}/tests/tools/qvm_start_gui.py (96%) rename {qubesmgmt => qubesadmin}/tests/tools/qvm_unpause.py (81%) rename {qubesmgmt => qubesadmin}/tests/tools/qvm_volume.py (87%) rename {qubesmgmt => qubesadmin}/tests/vm/__init__.py (93%) rename {qubesmgmt => qubesadmin}/tests/vm/actions.py (96%) rename {qubesmgmt => qubesadmin}/tests/vm/properties.py (96%) rename {qubesmgmt => qubesadmin}/tests/vm/storage.py (95%) rename {qubesmgmt => qubesadmin}/tools/__init__.py (98%) rename {qubesmgmt => qubesadmin}/tools/dochelpers.py (97%) rename {qubesmgmt => qubesadmin}/tools/qubes_prefs.py (87%) rename {qubesmgmt => qubesadmin}/tools/qvm_check.py (94%) rename {qubesmgmt => qubesadmin}/tools/qvm_clone.py (98%) rename {qubesmgmt => qubesadmin}/tools/qvm_create.py (92%) rename {qubesmgmt => qubesadmin}/tools/qvm_device.py (90%) rename {qubesmgmt => qubesadmin}/tools/qvm_features.py (94%) rename {qubesmgmt => qubesadmin}/tools/qvm_firewall.py (95%) rename {qubesmgmt => qubesadmin}/tools/qvm_kill.py (89%) rename {qubesmgmt => qubesadmin}/tools/qvm_ls.py (96%) rename {qubesmgmt => qubesadmin}/tools/qvm_pause.py (90%) rename {qubesmgmt => qubesadmin}/tools/qvm_pool.py (93%) rename {qubesmgmt => qubesadmin}/tools/qvm_prefs.py (97%) rename {qubesmgmt => qubesadmin}/tools/qvm_remove.py (96%) rename {qubesmgmt => qubesadmin}/tools/qvm_run.py (97%) rename {qubesmgmt => qubesadmin}/tools/qvm_shutdown.py (94%) rename {qubesmgmt => qubesadmin}/tools/qvm_start.py (90%) rename {qubesmgmt => qubesadmin}/tools/qvm_start_gui.py (97%) rename {qubesmgmt => qubesadmin}/tools/qvm_unpause.py (91%) rename {qubesmgmt => qubesadmin}/tools/qvm_volume.py (90%) rename {qubesmgmt => qubesadmin}/utils.py (97%) rename {qubesmgmt => qubesadmin}/vm/__init__.py (94%) rename rpm_spec/{qubes-core-mgmt-client.spec => qubes-core-admin-client.spec} (64%) diff --git a/.travis.yml b/.travis.yml index 5a264e4..e152421 100644 --- a/.travis.yml +++ b/.travis.yml @@ -10,7 +10,7 @@ install: - git clone https://github.com/"${TRAVIS_REPO_SLUG%%/*}"/qubes-builder ~/qubes-builder script: - test -z "$TESTS_ONLY" || python setup.py build - - test -z "$TESTS_ONLY" || { cd build/lib; PYTHONPATH=../../test-packages pylint --rcfile=../../ci/pylintrc qubesmgmt; } + - test -z "$TESTS_ONLY" || { cd build/lib; PYTHONPATH=../../test-packages pylint --rcfile=../../ci/pylintrc qubesadmin; } - test -z "$TESTS_ONLY" || { cd build/lib; ROOTDIR=../.. ../../run-tests; } - test -n "$TESTS_ONLY" || ~/qubes-builder/scripts/travis-build env: diff --git a/Makefile.builder b/Makefile.builder index 930d3fa..14495f2 100644 --- a/Makefile.builder +++ b/Makefile.builder @@ -1,2 +1,2 @@ -RPM_SPEC_FILES := rpm_spec/qubes-core-mgmt-client.spec +RPM_SPEC_FILES := rpm_spec/qubes-core-admin-client.spec diff --git a/README.md b/README.md index f61ff3e..af39777 100644 --- a/README.md +++ b/README.md @@ -9,6 +9,6 @@ Compatibility Most of the API modules are compatible with Python >= 2.7. Very few parts require Python >= 3.4: - tools (`qvm-*`) - - qubesmgmt.events module (for asyncio module) + - qubesadmin.events module (for asyncio module) Parts not compatible with Python < 3.4, are not installed in such environment. diff --git a/ci/coveragerc b/ci/coveragerc index a8b51cd..37b61cc 100644 --- a/ci/coveragerc +++ b/ci/coveragerc @@ -1,3 +1,3 @@ [run] -source = qubesmgmt -omit = qubesmgmt/tests/* +source = qubesadmin +omit = qubesadmin/tests/* diff --git a/doc/conf.py b/doc/conf.py index de874e5..5be96ef 100644 --- a/doc/conf.py +++ b/doc/conf.py @@ -41,8 +41,8 @@ extensions = [ ] try: - import qubesmgmt.tools.dochelpers - extensions.append('qubesmgmt.tools.dochelpers') + import qubesadmin.tools.dochelpers + extensions.append('qubesadmin.tools.dochelpers') except ImportError: pass diff --git a/doc/skel-manpage.py b/doc/skel-manpage.py index 37d8d85..8bb75ad 100755 --- a/doc/skel-manpage.py +++ b/doc/skel-manpage.py @@ -5,16 +5,16 @@ import sys sys.path.insert(0, os.path.abspath('../')) import argparse -import qubesmgmt.dochelpers +import qubesadmin.dochelpers parser = argparse.ArgumentParser(description='prepare new manpage for command') parser.add_argument('command', metavar='COMMAND', help='program\'s command name; this should translate to ' - 'qubesmgmt.tools.') + 'qubesadmin.tools.') def main(): args = parser.parse_args() - sys.stdout.write(qubesmgmt.dochelpers.prepare_manpage(args.command)) + sys.stdout.write(qubesadmin.dochelpers.prepare_manpage(args.command)) if __name__ == '__main__': main() diff --git a/qubesmgmt/__init__.py b/qubesadmin/__init__.py similarity index 79% rename from qubesmgmt/__init__.py rename to qubesadmin/__init__.py index d7d438f..2a9b1fc 100644 --- a/qubesmgmt/__init__.py +++ b/qubesadmin/__init__.py @@ -22,13 +22,13 @@ import os -import qubesmgmt.config -import qubesmgmt.base -import qubesmgmt.app +import qubesadmin.config +import qubesadmin.base +import qubesadmin.app -DEFAULT = qubesmgmt.base.DEFAULT +DEFAULT = qubesadmin.base.DEFAULT -if os.path.exists(qubesmgmt.config.QUBESD_SOCKET): - Qubes = qubesmgmt.app.QubesLocal +if os.path.exists(qubesadmin.config.QUBESD_SOCKET): + Qubes = qubesadmin.app.QubesLocal else: - Qubes = qubesmgmt.app.QubesRemote + Qubes = qubesadmin.app.QubesRemote diff --git a/qubesmgmt/app.py b/qubesadmin/app.py similarity index 92% rename from qubesmgmt/app.py rename to qubesadmin/app.py index 5789844..aa55ce0 100644 --- a/qubesmgmt/app.py +++ b/qubesadmin/app.py @@ -28,16 +28,16 @@ import subprocess import logging -import qubesmgmt.base -import qubesmgmt.exc -import qubesmgmt.label -import qubesmgmt.storage -import qubesmgmt.utils -import qubesmgmt.vm -import qubesmgmt.config +import qubesadmin.base +import qubesadmin.exc +import qubesadmin.label +import qubesadmin.storage +import qubesadmin.utils +import qubesadmin.vm +import qubesadmin.config BUF_SIZE = 4096 -VM_ENTRY_POINT = 'qubesmgmt.vm' +VM_ENTRY_POINT = 'qubesadmin.vm' class VMCollection(object): '''Collection of VMs objects''' @@ -85,7 +85,7 @@ class VMCollection(object): if item not in self: raise KeyError(item) if item not in self._vm_objects: - cls = qubesmgmt.utils.get_entry_point_one(VM_ENTRY_POINT, + cls = qubesadmin.utils.get_entry_point_one(VM_ENTRY_POINT, self._vm_list[item]['class']) self._vm_objects[item] = cls(self.app, item) return self._vm_objects[item] @@ -109,7 +109,7 @@ class VMCollection(object): return self._vm_list.keys() -class QubesBase(qubesmgmt.base.PropertyHolder): +class QubesBase(qubesadmin.base.PropertyHolder): '''Main Qubes application''' #: domains (VMs) collection @@ -126,10 +126,10 @@ class QubesBase(qubesmgmt.base.PropertyHolder): def __init__(self): super(QubesBase, self).__init__(self, 'mgmt.property.', 'dom0') self.domains = VMCollection(self) - self.labels = qubesmgmt.base.WrapperObjectsCollection( - self, 'mgmt.label.List', qubesmgmt.label.Label) - self.pools = qubesmgmt.base.WrapperObjectsCollection( - self, 'mgmt.pool.List', qubesmgmt.storage.Pool) + self.labels = qubesadmin.base.WrapperObjectsCollection( + self, 'mgmt.label.List', qubesadmin.label.Label) + self.pools = qubesadmin.base.WrapperObjectsCollection( + self, 'mgmt.pool.List', qubesadmin.storage.Pool) #: cache for available storage pool drivers and options to create them self._pool_drivers = None self.log = logging.getLogger('app') @@ -215,10 +215,10 @@ class QubesBase(qubesmgmt.base.PropertyHolder): ''' try: - return qubesmgmt.utils.get_entry_point_one( + return qubesadmin.utils.get_entry_point_one( VM_ENTRY_POINT, clsname) except KeyError: - raise qubesmgmt.exc.QubesException( + raise qubesadmin.exc.QubesException( 'no such VM class: {!r}'.format(clsname)) # don't catch TypeError @@ -228,7 +228,7 @@ class QubesBase(qubesmgmt.base.PropertyHolder): Example usage with custom storage pools: - >>> app = qubesmgmt.Qubes() + >>> app = qubesadmin.Qubes() >>> pools = {'private': 'external'} >>> vm = app.add_new_vm('AppVM', 'my-new-vm', 'red', >>> 'my-template', pools=pools) @@ -273,7 +273,7 @@ class QubesBase(qubesmgmt.base.PropertyHolder): Example usage with custom storage pools: - >>> app = qubesmgmt.Qubes() + >>> app = qubesadmin.Qubes() >>> pools = {'private': 'external'} >>> src_vm = app.domains['personal'] >>> vm = app.clone_vm(src_vm, 'my-new-vm', pools=pools) @@ -338,7 +338,7 @@ class QubesLocal(QubesBase): def qubesd_call(self, dest, method, arg=None, payload=None): try: client_socket = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) - client_socket.connect(qubesmgmt.config.QUBESD_SOCKET) + client_socket.connect(qubesadmin.config.QUBESD_SOCKET) except IOError: # TODO: raise @@ -375,7 +375,7 @@ class QubesLocal(QubesBase): raise ValueError('Empty destination name allowed only from a VM') try: self.qubesd_call(dest, 'mgmt.vm.Start') - except qubesmgmt.exc.QubesVMNotHaltedError: + except qubesadmin.exc.QubesVMNotHaltedError: pass qrexec_opts = ['-d', dest] if filter_esc: @@ -387,7 +387,7 @@ class QubesLocal(QubesBase): kwargs.setdefault('stdin', subprocess.PIPE) kwargs.setdefault('stdout', subprocess.PIPE) kwargs.setdefault('stderr', subprocess.PIPE) - proc = subprocess.Popen([qubesmgmt.config.QREXEC_CLIENT] + + proc = subprocess.Popen([qubesadmin.config.QREXEC_CLIENT] + qrexec_opts + ['{}:QUBESRPC {} dom0'.format(user, service)], **kwargs) return proc @@ -405,14 +405,14 @@ class QubesRemote(QubesBase): service_name = method if arg is not None: service_name += '+' + arg - p = subprocess.Popen([qubesmgmt.config.QREXEC_CLIENT_VM, + p = subprocess.Popen([qubesadmin.config.QREXEC_CLIENT_VM, dest, service_name], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE) (stdout, stderr) = p.communicate(payload) if p.returncode != 0: # TODO: use dedicated exception - raise qubesmgmt.exc.QubesException('Service call error: %s', + raise qubesadmin.exc.QubesException('Service call error: %s', stderr.decode()) return self._parse_qubesd_response(stdout) @@ -439,7 +439,7 @@ class QubesRemote(QubesBase): kwargs.setdefault('stdin', subprocess.PIPE) kwargs.setdefault('stdout', subprocess.PIPE) kwargs.setdefault('stderr', subprocess.PIPE) - proc = subprocess.Popen([qubesmgmt.config.QREXEC_CLIENT_VM, + proc = subprocess.Popen([qubesadmin.config.QREXEC_CLIENT_VM, dest or '', service] + (shlex.split(localcmd) if localcmd else []), **kwargs) return proc diff --git a/qubesmgmt/base.py b/qubesadmin/base.py similarity index 89% rename from qubesmgmt/base.py rename to qubesadmin/base.py index 5cec02c..f1e2d39 100644 --- a/qubesmgmt/base.py +++ b/qubesadmin/base.py @@ -21,7 +21,7 @@ '''Base classes for managed objects''' import ast -import qubesmgmt.exc +import qubesadmin.exc DEFAULT = object() @@ -73,7 +73,7 @@ class PropertyHolder(object): ''' if response_data == b'': - raise qubesmgmt.exc.QubesDaemonNoResponseError( + raise qubesadmin.exc.QubesDaemonNoResponseError( 'Got empty response from qubesd') if response_data[0:2] == b'\x30\x00': @@ -86,17 +86,17 @@ class PropertyHolder(object): format_string = format_string.decode('utf-8') exc_type = exc_type.decode('ascii') try: - exc_class = getattr(qubesmgmt.exc, exc_type) + exc_class = getattr(qubesadmin.exc, exc_type) except AttributeError: if exc_type.endswith('Error'): exc_class = __builtins__.get(exc_type, - qubesmgmt.exc.QubesException) + qubesadmin.exc.QubesException) else: - exc_class = qubesmgmt.exc.QubesException + exc_class = qubesadmin.exc.QubesException # TODO: handle traceback if given raise exc_class(format_string, *args) else: - raise qubesmgmt.exc.QubesDaemonCommunicationError( + raise qubesadmin.exc.QubesDaemonCommunicationError( 'Invalid response format') def property_list(self): @@ -159,12 +159,12 @@ class PropertyHolder(object): self._method_prefix + 'Get', item, None) - except qubesmgmt.exc.QubesDaemonNoResponseError: - raise qubesmgmt.exc.QubesPropertyAccessError(item) + except qubesadmin.exc.QubesDaemonNoResponseError: + raise qubesadmin.exc.QubesPropertyAccessError(item) (_default, prop_type, value) = property_str.split(b' ', 2) prop_type = prop_type.decode('ascii') if not prop_type.startswith('type='): - raise qubesmgmt.exc.QubesDaemonCommunicationError( + raise qubesadmin.exc.QubesDaemonCommunicationError( 'Invalid type prefix received: {}'.format(prop_type)) (_, prop_type) = prop_type.split('=', 1) value = value.decode() @@ -188,23 +188,23 @@ class PropertyHolder(object): # TODO return self.app.labels[value] else: - raise qubesmgmt.exc.QubesDaemonCommunicationError( + raise qubesadmin.exc.QubesDaemonCommunicationError( 'Received invalid value type: {}'.format(prop_type)) def __setattr__(self, key, value): if key.startswith('_') or key in dir(self): return super(PropertyHolder, self).__setattr__(key, value) - if value is qubesmgmt.DEFAULT: + if value is qubesadmin.DEFAULT: try: self.qubesd_call( self._method_dest, self._method_prefix + 'Reset', key, None) - except qubesmgmt.exc.QubesDaemonNoResponseError: - raise qubesmgmt.exc.QubesPropertyAccessError(key) + except qubesadmin.exc.QubesDaemonNoResponseError: + raise qubesadmin.exc.QubesPropertyAccessError(key) else: - if isinstance(value, qubesmgmt.vm.QubesVM): + if isinstance(value, qubesadmin.vm.QubesVM): value = value.name try: self.qubesd_call( @@ -212,8 +212,8 @@ class PropertyHolder(object): self._method_prefix + 'Set', key, str(value).encode('utf-8')) - except qubesmgmt.exc.QubesDaemonNoResponseError: - raise qubesmgmt.exc.QubesPropertyAccessError(key) + except qubesadmin.exc.QubesDaemonNoResponseError: + raise qubesadmin.exc.QubesPropertyAccessError(key) def __delattr__(self, name): if name.startswith('_') or name in dir(self): @@ -224,8 +224,8 @@ class PropertyHolder(object): self._method_prefix + 'Reset', name ) - except qubesmgmt.exc.QubesDaemonNoResponseError: - raise qubesmgmt.exc.QubesPropertyAccessError(name) + except qubesadmin.exc.QubesDaemonNoResponseError: + raise qubesadmin.exc.QubesPropertyAccessError(name) class WrapperObjectsCollection(object): diff --git a/qubesmgmt/config.py b/qubesadmin/config.py similarity index 100% rename from qubesmgmt/config.py rename to qubesadmin/config.py diff --git a/qubesmgmt/devices.py b/qubesadmin/devices.py similarity index 100% rename from qubesmgmt/devices.py rename to qubesadmin/devices.py diff --git a/qubesmgmt/events/__init__.py b/qubesadmin/events/__init__.py similarity index 95% rename from qubesmgmt/events/__init__.py rename to qubesadmin/events/__init__.py index 5b805c7..e3f11e0 100644 --- a/qubesmgmt/events/__init__.py +++ b/qubesadmin/events/__init__.py @@ -23,8 +23,8 @@ import asyncio import subprocess -import qubesmgmt.config -import qubesmgmt.exc +import qubesadmin.config +import qubesadmin.exc class EventsDispatcher(object): @@ -75,7 +75,7 @@ class EventsDispatcher(object): if self.app.qubesd_connection_type == 'socket': reader, writer = yield from asyncio.open_unix_connection( - qubesmgmt.config.QUBESD_SOCKET) + qubesadmin.config.QUBESD_SOCKET) writer.write(b'dom0\0') # source writer.write(b'mgmt.Events\0') # method writer.write(dest.encode('ascii') + b'\0') # dest @@ -124,9 +124,9 @@ class EventsDispatcher(object): break self.app.log.warning( 'Connection to qubesd terminated, reconnecting in {} ' - 'seconds'.format(qubesmgmt.config.QUBESD_RECONNECT_DELAY)) + 'seconds'.format(qubesadmin.config.QUBESD_RECONNECT_DELAY)) # avoid busy-loop if qubesd is dead - yield from asyncio.sleep(qubesmgmt.config.QUBESD_RECONNECT_DELAY) + yield from asyncio.sleep(qubesadmin.config.QUBESD_RECONNECT_DELAY) @asyncio.coroutine def _listen_for_events(self, vm=None): @@ -159,7 +159,7 @@ class EventsDispatcher(object): raise if not event_data.startswith(b'1\0'): - raise qubesmgmt.exc.QubesDaemonCommunicationError( + raise qubesadmin.exc.QubesDaemonCommunicationError( 'Non-event received on events connection: ' + repr(event_data)) event_data = event_data.decode('utf-8') diff --git a/qubesmgmt/exc.py b/qubesadmin/exc.py similarity index 100% rename from qubesmgmt/exc.py rename to qubesadmin/exc.py diff --git a/qubesmgmt/features.py b/qubesadmin/features.py similarity index 100% rename from qubesmgmt/features.py rename to qubesadmin/features.py diff --git a/qubesmgmt/firewall.py b/qubesadmin/firewall.py similarity index 100% rename from qubesmgmt/firewall.py rename to qubesadmin/firewall.py diff --git a/qubesmgmt/label.py b/qubesadmin/label.py similarity index 94% rename from qubesmgmt/label.py rename to qubesadmin/label.py index 275f6cb..a01d15c 100644 --- a/qubesmgmt/label.py +++ b/qubesadmin/label.py @@ -20,7 +20,7 @@ '''VM Labels''' -import qubesmgmt.exc +import qubesadmin.exc class Label(object): @@ -45,7 +45,7 @@ class Label(object): try: qubesd_response = self.app.qubesd_call( 'dom0', 'mgmt.label.Get', self._name, None) - except qubesmgmt.exc.QubesDaemonNoResponseError: + except qubesadmin.exc.QubesDaemonNoResponseError: raise AttributeError self._color = qubesd_response.decode() return self._color @@ -68,7 +68,7 @@ class Label(object): try: qubesd_response = self.app.qubesd_call( 'dom0', 'mgmt.label.Index', self._name, None) - except qubesmgmt.exc.QubesDaemonNoResponseError: + except qubesadmin.exc.QubesDaemonNoResponseError: raise AttributeError self._index = int(qubesd_response.decode()) return self._index diff --git a/qubesmgmt/log.py b/qubesadmin/log.py similarity index 100% rename from qubesmgmt/log.py rename to qubesadmin/log.py diff --git a/qubesmgmt/storage.py b/qubesadmin/storage.py similarity index 100% rename from qubesmgmt/storage.py rename to qubesadmin/storage.py diff --git a/qubesmgmt/tests/__init__.py b/qubesadmin/tests/__init__.py similarity index 98% rename from qubesmgmt/tests/__init__.py rename to qubesadmin/tests/__init__.py index b9a535a..d56fcf6 100644 --- a/qubesmgmt/tests/__init__.py +++ b/qubesadmin/tests/__init__.py @@ -22,8 +22,8 @@ import unittest import io -import qubesmgmt -import qubesmgmt.app +import qubesadmin +import qubesadmin.app class TestVM(object): @@ -107,7 +107,7 @@ class _AssertNotRaisesContext(object): return False -class QubesTest(qubesmgmt.app.QubesBase): +class QubesTest(qubesadmin.app.QubesBase): expected_calls = None actual_calls = None service_calls = None diff --git a/qubesmgmt/tests/app.py b/qubesadmin/tests/app.py similarity index 94% rename from qubesmgmt/tests/app.py rename to qubesadmin/tests/app.py index 9662284..6b8cfbe 100644 --- a/qubesmgmt/tests/app.py +++ b/qubesadmin/tests/app.py @@ -31,10 +31,10 @@ try: except ImportError: import mock -import qubesmgmt.tests +import qubesadmin.tests -class TC_00_VMCollection(qubesmgmt.tests.QubesTestCase): +class TC_00_VMCollection(qubesadmin.tests.QubesTestCase): def test_000_list(self): self.app.expected_calls[('dom0', 'mgmt.vm.List', None, None)] = \ b'0\x00test-vm class=AppVM state=Running\n' @@ -79,7 +79,7 @@ class TC_00_VMCollection(qubesmgmt.tests.QubesTestCase): self.assertAllCalled() -class TC_10_QubesBase(qubesmgmt.tests.QubesTestCase): +class TC_10_QubesBase(qubesadmin.tests.QubesTestCase): def test_010_new_simple(self): self.app.expected_calls[('dom0', 'mgmt.vm.Create.AppVM', None, b'name=new-vm label=red')] = b'0\x00' @@ -200,10 +200,10 @@ class TC_20_QubesLocal(unittest.TestCase): def setUp(self): super(TC_20_QubesLocal, self).setUp() self.socket_dir = tempfile.mkdtemp() - self.orig_sock = qubesmgmt.config.QUBESD_SOCKET - qubesmgmt.config.QUBESD_SOCKET = os.path.join(self.socket_dir, 'sock') + self.orig_sock = qubesadmin.config.QUBESD_SOCKET + qubesadmin.config.QUBESD_SOCKET = os.path.join(self.socket_dir, 'sock') self.proc = None - self.app = qubesmgmt.app.QubesLocal() + self.app = qubesadmin.app.QubesLocal() def listen_and_send(self, send_data): '''Listen on socket and send data in response. @@ -230,7 +230,7 @@ class TC_20_QubesLocal(unittest.TestCase): return self.socket_pipe.recv() def tearDown(self): - qubesmgmt.config.QUBESD_SOCKET = self.orig_sock + qubesadmin.config.QUBESD_SOCKET = self.orig_sock if self.proc is not None: try: self.proc.terminate() @@ -262,7 +262,7 @@ class TC_20_QubesLocal(unittest.TestCase): with mock.patch('subprocess.Popen') as mock_proc: p = self.app.run_service('some-vm', 'service.name') mock_proc.assert_called_once_with([ - qubesmgmt.config.QREXEC_CLIENT, + qubesadmin.config.QREXEC_CLIENT, '-d', 'some-vm', 'DEFAULT:QUBESRPC service.name dom0'], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE) @@ -275,7 +275,7 @@ class TC_20_QubesLocal(unittest.TestCase): with mock.patch('subprocess.Popen') as mock_proc: p = self.app.run_service('some-vm', 'service.name', filter_esc=True) mock_proc.assert_called_once_with([ - qubesmgmt.config.QREXEC_CLIENT, + qubesadmin.config.QREXEC_CLIENT, '-d', 'some-vm', '-t', '-T', 'DEFAULT:QUBESRPC service.name dom0'], stdin=subprocess.PIPE, stdout=subprocess.PIPE, @@ -289,7 +289,7 @@ class TC_20_QubesLocal(unittest.TestCase): with mock.patch('subprocess.Popen') as mock_proc: p = self.app.run_service('some-vm', 'service.name', user='user') mock_proc.assert_called_once_with([ - qubesmgmt.config.QREXEC_CLIENT, + qubesadmin.config.QREXEC_CLIENT, '-d', 'some-vm', 'user:QUBESRPC service.name dom0'], stdin=subprocess.PIPE, stdout=subprocess.PIPE, @@ -312,7 +312,7 @@ class TC_30_QubesRemote(unittest.TestCase): }) self.proc_patch = mock.patch('subprocess.Popen', self.proc_mock) self.proc_patch.start() - self.app = qubesmgmt.app.QubesRemote() + self.app = qubesadmin.app.QubesRemote() def set_proc_stdout(self, send_data): self.proc_mock.configure_mock(**{ @@ -327,7 +327,7 @@ class TC_30_QubesRemote(unittest.TestCase): self.set_proc_stdout(b'0\0') self.app.qubesd_call('test-vm', 'some.method', 'arg1', b'payload') self.assertEqual(self.proc_mock.mock_calls, [ - mock.call([qubesmgmt.config.QREXEC_CLIENT_VM, 'test-vm', + mock.call([qubesadmin.config.QREXEC_CLIENT_VM, 'test-vm', 'some.method+arg1'], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE), @@ -338,7 +338,7 @@ class TC_30_QubesRemote(unittest.TestCase): self.set_proc_stdout(b'0\0') self.app.qubesd_call('test-vm', 'some.method', None, b'payload') self.assertEqual(self.proc_mock.mock_calls, [ - mock.call([qubesmgmt.config.QREXEC_CLIENT_VM, 'test-vm', + mock.call([qubesadmin.config.QREXEC_CLIENT_VM, 'test-vm', 'some.method'], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE), @@ -349,7 +349,7 @@ class TC_30_QubesRemote(unittest.TestCase): self.set_proc_stdout(b'0\0') self.app.qubesd_call('test-vm', 'some.method', None, None) self.assertEqual(self.proc_mock.mock_calls, [ - mock.call([qubesmgmt.config.QREXEC_CLIENT_VM, 'test-vm', + mock.call([qubesadmin.config.QREXEC_CLIENT_VM, 'test-vm', 'some.method'], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE), @@ -359,7 +359,7 @@ class TC_30_QubesRemote(unittest.TestCase): def test_010_run_service(self): self.app.run_service('some-vm', 'service.name') self.proc_mock.assert_called_once_with([ - qubesmgmt.config.QREXEC_CLIENT_VM, + qubesadmin.config.QREXEC_CLIENT_VM, 'some-vm', 'service.name'], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE) @@ -375,7 +375,7 @@ class TC_30_QubesRemote(unittest.TestCase): def test_013_run_service_default_target(self): self.app.run_service('', 'service.name') self.proc_mock.assert_called_once_with([ - qubesmgmt.config.QREXEC_CLIENT_VM, + qubesadmin.config.QREXEC_CLIENT_VM, '', 'service.name'], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE) diff --git a/qubesmgmt/tests/devices.py b/qubesadmin/tests/devices.py similarity index 88% rename from qubesmgmt/tests/devices.py rename to qubesadmin/tests/devices.py index 8c4313f..347f122 100644 --- a/qubesmgmt/tests/devices.py +++ b/qubesadmin/tests/devices.py @@ -18,11 +18,11 @@ # You should have received a copy of the GNU Lesser General Public License along # with this program; if not, see . -import qubesmgmt.tests -import qubesmgmt.devices +import qubesadmin.tests +import qubesadmin.devices -class TC_00_DeviceCollection(qubesmgmt.tests.QubesTestCase): +class TC_00_DeviceCollection(qubesadmin.tests.QubesTestCase): def setUp(self): super(TC_00_DeviceCollection, self).setUp() self.app.expected_calls[('dom0', 'mgmt.vm.List', None, None)] = \ @@ -38,7 +38,7 @@ class TC_00_DeviceCollection(qubesmgmt.tests.QubesTestCase): devices = list(self.vm.devices['test'].available()) self.assertEqual(len(devices), 1) dev = devices[0] - self.assertIsInstance(dev, qubesmgmt.devices.DeviceInfo) + self.assertIsInstance(dev, qubesadmin.devices.DeviceInfo) self.assertEqual(dev.backend_domain, self.vm) self.assertEqual(dev.ident, 'dev1') self.assertEqual(dev.description, '') @@ -54,7 +54,7 @@ class TC_00_DeviceCollection(qubesmgmt.tests.QubesTestCase): devices = list(self.vm.devices['test'].available()) self.assertEqual(len(devices), 1) dev = devices[0] - self.assertIsInstance(dev, qubesmgmt.devices.DeviceInfo) + self.assertIsInstance(dev, qubesadmin.devices.DeviceInfo) self.assertEqual(dev.backend_domain, self.vm) self.assertEqual(dev.ident, 'dev1') self.assertEqual(dev.description, 'This is description') @@ -69,7 +69,7 @@ class TC_00_DeviceCollection(qubesmgmt.tests.QubesTestCase): devices = list(self.vm.devices['test'].available()) self.assertEqual(len(devices), 1) dev = devices[0] - self.assertIsInstance(dev, qubesmgmt.devices.DeviceInfo) + self.assertIsInstance(dev, qubesadmin.devices.DeviceInfo) self.assertEqual(dev.backend_domain, self.vm) self.assertEqual(dev.ident, 'dev1') self.assertEqual(dev.description, 'This is description') @@ -83,7 +83,7 @@ class TC_00_DeviceCollection(qubesmgmt.tests.QubesTestCase): ('test-vm', 'mgmt.vm.device.test.Available', None, None)] = \ b'0\0dev1 description=This is description\n' dev = self.vm.devices['test']['dev1'] - self.assertIsInstance(dev, qubesmgmt.devices.DeviceInfo) + self.assertIsInstance(dev, qubesadmin.devices.DeviceInfo) self.assertEqual(dev.backend_domain, self.vm) self.assertEqual(dev.ident, 'dev1') self.assertEqual(dev.description, 'This is description') @@ -97,7 +97,7 @@ class TC_00_DeviceCollection(qubesmgmt.tests.QubesTestCase): ('test-vm', 'mgmt.vm.device.test.Available', None, None)] = \ b'0\0dev1 description=This is description\n' dev = self.vm.devices['test']['dev2'] - self.assertIsInstance(dev, qubesmgmt.devices.UnknownDevice) + self.assertIsInstance(dev, qubesadmin.devices.UnknownDevice) self.assertEqual(dev.backend_domain, self.vm) self.assertEqual(dev.ident, 'dev2') self.assertEqual(dev.description, 'Unknown device') @@ -110,7 +110,7 @@ class TC_00_DeviceCollection(qubesmgmt.tests.QubesTestCase): self.app.expected_calls[ ('test-vm', 'mgmt.vm.device.test.Attach', 'test-vm2+dev1', b'')] = \ b'0\0' - assign = qubesmgmt.devices.DeviceAssignment( + assign = qubesadmin.devices.DeviceAssignment( self.app.domains['test-vm2'], 'dev1') self.vm.devices['test'].attach(assign) self.assertAllCalled() @@ -119,7 +119,7 @@ class TC_00_DeviceCollection(qubesmgmt.tests.QubesTestCase): self.app.expected_calls[ ('test-vm', 'mgmt.vm.device.test.Attach', 'test-vm2+dev1', b'ro=True something=value')] = b'0\0' - assign = qubesmgmt.devices.DeviceAssignment( + assign = qubesadmin.devices.DeviceAssignment( self.app.domains['test-vm2'], 'dev1') assign.options['ro'] = True assign.options['something'] = 'value' @@ -130,7 +130,7 @@ class TC_00_DeviceCollection(qubesmgmt.tests.QubesTestCase): self.app.expected_calls[ ('test-vm', 'mgmt.vm.device.test.Attach', 'test-vm2+dev1', b'persistent=yes')] = b'0\0' - assign = qubesmgmt.devices.DeviceAssignment( + assign = qubesadmin.devices.DeviceAssignment( self.app.domains['test-vm2'], 'dev1') assign.persistent = True self.vm.devices['test'].attach(assign) @@ -140,7 +140,7 @@ class TC_00_DeviceCollection(qubesmgmt.tests.QubesTestCase): self.app.expected_calls[ ('test-vm', 'mgmt.vm.device.test.Attach', 'test-vm2+dev1', b'persistent=yes ro=True')] = b'0\0' - assign = qubesmgmt.devices.DeviceAssignment( + assign = qubesadmin.devices.DeviceAssignment( self.app.domains['test-vm2'], 'dev1') assign.persistent = True assign.options['ro'] = True @@ -151,7 +151,7 @@ class TC_00_DeviceCollection(qubesmgmt.tests.QubesTestCase): self.app.expected_calls[ ('test-vm', 'mgmt.vm.device.test.Detach', 'test-vm2+dev1', None)] = b'0\0' - assign = qubesmgmt.devices.DeviceAssignment( + assign = qubesadmin.devices.DeviceAssignment( self.app.domains['test-vm2'], 'dev1') self.vm.devices['test'].detach(assign) self.assertAllCalled() @@ -163,7 +163,7 @@ class TC_00_DeviceCollection(qubesmgmt.tests.QubesTestCase): b'test-vm3+dev2\n' assigns = list(self.vm.devices['test'].assignments()) self.assertEqual(len(assigns), 2) - self.assertIsInstance(assigns[0], qubesmgmt.devices.DeviceAssignment) + self.assertIsInstance(assigns[0], qubesadmin.devices.DeviceAssignment) self.assertEqual(assigns[0].backend_domain, self.app.domains['test-vm2']) self.assertEqual(assigns[0].ident, 'dev1') @@ -171,7 +171,7 @@ class TC_00_DeviceCollection(qubesmgmt.tests.QubesTestCase): self.app.domains['test-vm']) self.assertEqual(assigns[0].options, {}) - self.assertIsInstance(assigns[1], qubesmgmt.devices.DeviceAssignment) + self.assertIsInstance(assigns[1], qubesadmin.devices.DeviceAssignment) self.assertEqual(assigns[1].backend_domain, self.app.domains['test-vm3']) self.assertEqual(assigns[1].ident, 'dev2') @@ -188,7 +188,7 @@ class TC_00_DeviceCollection(qubesmgmt.tests.QubesTestCase): b'test-vm3+dev2 ro=False persistent=True\n' assigns = list(self.vm.devices['test'].assignments()) self.assertEqual(len(assigns), 2) - self.assertIsInstance(assigns[0], qubesmgmt.devices.DeviceAssignment) + self.assertIsInstance(assigns[0], qubesadmin.devices.DeviceAssignment) self.assertEqual(assigns[0].backend_domain, self.app.domains['test-vm2']) self.assertEqual(assigns[0].ident, 'dev1') @@ -197,7 +197,7 @@ class TC_00_DeviceCollection(qubesmgmt.tests.QubesTestCase): self.assertEqual(assigns[0].options, {'ro': 'True'}) self.assertEqual(assigns[0].persistent, False) - self.assertIsInstance(assigns[1], qubesmgmt.devices.DeviceAssignment) + self.assertIsInstance(assigns[1], qubesadmin.devices.DeviceAssignment) self.assertEqual(assigns[1].backend_domain, self.app.domains['test-vm3']) self.assertEqual(assigns[1].ident, 'dev2') @@ -215,7 +215,7 @@ class TC_00_DeviceCollection(qubesmgmt.tests.QubesTestCase): b'test-vm3+dev2 persistent=True\n' assigns = list(self.vm.devices['test'].assignments(True)) self.assertEqual(len(assigns), 1) - self.assertIsInstance(assigns[0], qubesmgmt.devices.DeviceAssignment) + self.assertIsInstance(assigns[0], qubesadmin.devices.DeviceAssignment) self.assertEqual(assigns[0].backend_domain, self.app.domains['test-vm3']) self.assertEqual(assigns[0].ident, 'dev2') @@ -232,7 +232,7 @@ class TC_00_DeviceCollection(qubesmgmt.tests.QubesTestCase): b'test-vm3+dev2 persistent=True\n' assigns = list(self.vm.devices['test'].assignments(False)) self.assertEqual(len(assigns), 1) - self.assertIsInstance(assigns[0], qubesmgmt.devices.DeviceAssignment) + self.assertIsInstance(assigns[0], qubesadmin.devices.DeviceAssignment) self.assertEqual(assigns[0].backend_domain, self.app.domains['test-vm2']) self.assertEqual(assigns[0].ident, 'dev1') @@ -252,7 +252,7 @@ class TC_00_DeviceCollection(qubesmgmt.tests.QubesTestCase): b'0\0dev2\n' devs = list(self.vm.devices['test'].persistent()) self.assertEqual(len(devs), 1) - self.assertIsInstance(devs[0], qubesmgmt.devices.DeviceInfo) + self.assertIsInstance(devs[0], qubesadmin.devices.DeviceInfo) self.assertEqual(devs[0].backend_domain, self.app.domains['test-vm3']) self.assertEqual(devs[0].ident, 'dev2') self.assertAllCalled() @@ -270,10 +270,10 @@ class TC_00_DeviceCollection(qubesmgmt.tests.QubesTestCase): b'0\0dev2\n' devs = list(self.vm.devices['test'].attached()) self.assertEqual(len(devs), 2) - self.assertIsInstance(devs[0], qubesmgmt.devices.DeviceInfo) + self.assertIsInstance(devs[0], qubesadmin.devices.DeviceInfo) self.assertEqual(devs[0].backend_domain, self.app.domains['test-vm2']) self.assertEqual(devs[0].ident, 'dev1') - self.assertIsInstance(devs[1], qubesmgmt.devices.DeviceInfo) + self.assertIsInstance(devs[1], qubesadmin.devices.DeviceInfo) self.assertEqual(devs[1].backend_domain, self.app.domains['test-vm3']) self.assertEqual(devs[1].ident, 'dev2') self.assertAllCalled() diff --git a/qubesmgmt/tests/errors.py b/qubesadmin/tests/errors.py similarity index 84% rename from qubesmgmt/tests/errors.py rename to qubesadmin/tests/errors.py index aed5828..012e4c0 100644 --- a/qubesmgmt/tests/errors.py +++ b/qubesadmin/tests/errors.py @@ -18,15 +18,15 @@ # You should have received a copy of the GNU Lesser General Public License along # with this program; if not, see . -import qubesmgmt.exc -import qubesmgmt.tests +import qubesadmin.exc +import qubesadmin.tests import unittest -class TC_00_Errors(qubesmgmt.tests.QubesTestCase): +class TC_00_Errors(qubesadmin.tests.QubesTestCase): def test_000_exception(self): self.app.expected_calls[('dom0', 'mgmt.vm.List', None, None)] = \ b'2\x00QubesException\x00\x00An error occurred\x00' - with self.assertRaises(qubesmgmt.exc.QubesException) as context: + with self.assertRaises(qubesadmin.exc.QubesException) as context: vms = list(self.app.domains) self.assertEqual(str(context.exception), 'An error occurred') @@ -34,7 +34,7 @@ class TC_00_Errors(qubesmgmt.tests.QubesTestCase): self.app.expected_calls[('dom0', 'mgmt.vm.List', None, None)] = \ b'2\x00QubesException\x00\x00' \ b'An error occurred: %s, %s\x00string\x00other\x00' - with self.assertRaises(qubesmgmt.exc.QubesException) as context: + with self.assertRaises(qubesadmin.exc.QubesException) as context: vms = list(self.app.domains) self.assertEqual(str(context.exception), 'An error occurred: string, other') @@ -44,7 +44,7 @@ class TC_00_Errors(qubesmgmt.tests.QubesTestCase): b'2\x00QubesException\x00\x00' \ b'An error occurred: %d, %d\x001\x002\x00' try: - with self.assertRaises(qubesmgmt.exc.QubesException) as context: + with self.assertRaises(qubesadmin.exc.QubesException) as context: vms = list(self.app.domains) except TypeError as e: self.fail('TypeError: {!s}'.format(e)) @@ -52,7 +52,7 @@ class TC_00_Errors(qubesmgmt.tests.QubesTestCase): def test_010_empty(self): self.app.expected_calls[('dom0', 'mgmt.vm.List', None, None)] = b'' - with self.assertRaises(qubesmgmt.exc.QubesDaemonNoResponseError) \ + with self.assertRaises(qubesadmin.exc.QubesDaemonNoResponseError) \ as context: vms = list(self.app.domains) self.assertEqual(str(context.exception), diff --git a/qubesmgmt/tests/events.py b/qubesadmin/tests/events.py similarity index 95% rename from qubesmgmt/tests/events.py rename to qubesadmin/tests/events.py index 4dfccb2..081655b 100644 --- a/qubesmgmt/tests/events.py +++ b/qubesadmin/tests/events.py @@ -22,13 +22,13 @@ import socket import subprocess -import qubesmgmt.tests +import qubesadmin.tests import unittest try: - # qubesmgmt.events require python3, so this tests can also use python3 features + # qubesadmin.events require python3, so this tests can also use python3 features import asyncio import unittest.mock - import qubesmgmt.events + import qubesadmin.events except ImportError: # don't run any tests on python2 def load_tests(loader, tests, pattern): @@ -40,11 +40,11 @@ except ImportError: return f -class TC_00_Events(qubesmgmt.tests.QubesTestCase): +class TC_00_Events(qubesadmin.tests.QubesTestCase): def setUp(self): super().setUp() self.app = unittest.mock.MagicMock() - self.dispatcher = qubesmgmt.events.EventsDispatcher(self.app) + self.dispatcher = qubesadmin.events.EventsDispatcher(self.app) def test_000_handler_specific(self): handler = unittest.mock.Mock() @@ -139,7 +139,7 @@ class TC_00_Events(qubesmgmt.tests.QubesTestCase): sock1, sock2 = socket.socketpair() with unittest.mock.patch('asyncio.open_unix_connection', lambda path: self.mock_open_unix_connection( - qubesmgmt.config.QUBESD_SOCKET, sock1, path)): + qubesadmin.config.QUBESD_SOCKET, sock1, path)): task = asyncio.ensure_future(self.dispatcher._get_events_reader()) reader = asyncio.ensure_future(loop.run_in_executor(None, self.read_all, sock2)) @@ -165,7 +165,7 @@ class TC_00_Events(qubesmgmt.tests.QubesTestCase): vm.name = 'test-vm' with unittest.mock.patch('asyncio.open_unix_connection', lambda path: self.mock_open_unix_connection( - qubesmgmt.config.QUBESD_SOCKET, sock1, path)): + qubesadmin.config.QUBESD_SOCKET, sock1, path)): task = asyncio.ensure_future(self.dispatcher._get_events_reader(vm)) reader = asyncio.ensure_future(loop.run_in_executor(None, self.read_all, sock2)) diff --git a/qubesmgmt/tests/firewall.py b/qubesadmin/tests/firewall.py similarity index 72% rename from qubesmgmt/tests/firewall.py rename to qubesadmin/tests/firewall.py index ddb5f68..00bff87 100644 --- a/qubesmgmt/tests/firewall.py +++ b/qubesadmin/tests/firewall.py @@ -22,18 +22,18 @@ '''Tests for firewall API. This is mostly copy from core-admin''' import datetime import unittest -import qubesmgmt.firewall -import qubesmgmt.tests +import qubesadmin.firewall +import qubesadmin.tests -class TestOption(qubesmgmt.firewall.RuleChoice): +class TestOption(qubesadmin.firewall.RuleChoice): opt1 = 'opt1' opt2 = 'opt2' another = 'another' # noinspection PyPep8Naming -class TC_00_RuleChoice(qubesmgmt.tests.QubesTestCase): +class TC_00_RuleChoice(qubesadmin.tests.QubesTestCase): def test_000_accept_allowed(self): with self.assertNotRaises(ValueError): TestOption('opt1') @@ -49,41 +49,41 @@ class TC_00_RuleChoice(qubesmgmt.tests.QubesTestCase): self.assertRaises(ValueError, lambda: TestOption('invalid')) -class TC_01_Action(qubesmgmt.tests.QubesTestCase): +class TC_01_Action(qubesadmin.tests.QubesTestCase): def test_000_allowed_values(self): with self.assertNotRaises(ValueError): - instance = qubesmgmt.firewall.Action('accept') + instance = qubesadmin.firewall.Action('accept') self.assertEqual( set(instance.allowed_values), {'accept', 'drop'}) def test_001_rule(self): - instance = qubesmgmt.firewall.Action('accept') + instance = qubesadmin.firewall.Action('accept') self.assertEqual(instance.rule, 'action=accept') # noinspection PyPep8Naming -class TC_02_Proto(qubesmgmt.tests.QubesTestCase): +class TC_02_Proto(qubesadmin.tests.QubesTestCase): def test_000_allowed_values(self): with self.assertNotRaises(ValueError): - instance = qubesmgmt.firewall.Proto('tcp') + instance = qubesadmin.firewall.Proto('tcp') self.assertEqual( set(instance.allowed_values), {'tcp', 'udp', 'icmp'}) def test_001_rule(self): - instance = qubesmgmt.firewall.Proto('tcp') + instance = qubesadmin.firewall.Proto('tcp') self.assertEqual(instance.rule, 'proto=tcp') # noinspection PyPep8Naming -class TC_02_DstHost(qubesmgmt.tests.QubesTestCase): +class TC_02_DstHost(qubesadmin.tests.QubesTestCase): def test_000_hostname(self): with self.assertNotRaises(ValueError): - instance = qubesmgmt.firewall.DstHost('qubes-os.org') + instance = qubesadmin.firewall.DstHost('qubes-os.org') self.assertEqual(instance.type, 'dsthost') def test_001_ipv4(self): with self.assertNotRaises(ValueError): - instance = qubesmgmt.firewall.DstHost('127.0.0.1') + instance = qubesadmin.firewall.DstHost('127.0.0.1') self.assertEqual(instance.type, 'dst4') self.assertEqual(instance.prefixlen, 32) self.assertEqual(str(instance), '127.0.0.1/32') @@ -91,7 +91,7 @@ class TC_02_DstHost(qubesmgmt.tests.QubesTestCase): def test_002_ipv4_prefixlen(self): with self.assertNotRaises(ValueError): - instance = qubesmgmt.firewall.DstHost('127.0.0.0', 8) + instance = qubesadmin.firewall.DstHost('127.0.0.0', 8) self.assertEqual(instance.type, 'dst4') self.assertEqual(instance.prefixlen, 8) self.assertEqual(str(instance), '127.0.0.0/8') @@ -99,7 +99,7 @@ class TC_02_DstHost(qubesmgmt.tests.QubesTestCase): def test_003_ipv4_parse_prefixlen(self): with self.assertNotRaises(ValueError): - instance = qubesmgmt.firewall.DstHost('127.0.0.0/8') + instance = qubesadmin.firewall.DstHost('127.0.0.0/8') self.assertEqual(instance.type, 'dst4') self.assertEqual(instance.prefixlen, 8) self.assertEqual(str(instance), '127.0.0.0/8') @@ -107,31 +107,31 @@ class TC_02_DstHost(qubesmgmt.tests.QubesTestCase): def test_004_ipv4_invalid_prefix(self): with self.assertRaises(ValueError): - qubesmgmt.firewall.DstHost('127.0.0.0/33') + qubesadmin.firewall.DstHost('127.0.0.0/33') with self.assertRaises(ValueError): - qubesmgmt.firewall.DstHost('127.0.0.0', 33) + qubesadmin.firewall.DstHost('127.0.0.0', 33) with self.assertRaises(ValueError): - qubesmgmt.firewall.DstHost('127.0.0.0/-1') + qubesadmin.firewall.DstHost('127.0.0.0/-1') def test_005_ipv4_reject_shortened(self): # not strictly required, but ppl are used to it with self.assertRaises(ValueError): - qubesmgmt.firewall.DstHost('127/8') + qubesadmin.firewall.DstHost('127/8') def test_006_ipv4_invalid_addr(self): with self.assertRaises(ValueError): - qubesmgmt.firewall.DstHost('137.327.0.0/16') + qubesadmin.firewall.DstHost('137.327.0.0/16') with self.assertRaises(ValueError): - qubesmgmt.firewall.DstHost('1.2.3.4.5/32') + qubesadmin.firewall.DstHost('1.2.3.4.5/32') @unittest.expectedFailure def test_007_ipv4_invalid_network(self): with self.assertRaises(ValueError): - qubesmgmt.firewall.DstHost('127.0.0.1/32') + qubesadmin.firewall.DstHost('127.0.0.1/32') def test_010_ipv6(self): with self.assertNotRaises(ValueError): - instance = qubesmgmt.firewall.DstHost('2001:abcd:efab::3') + instance = qubesadmin.firewall.DstHost('2001:abcd:efab::3') self.assertEqual(instance.type, 'dst6') self.assertEqual(instance.prefixlen, 128) self.assertEqual(str(instance), '2001:abcd:efab::3/128') @@ -139,7 +139,7 @@ class TC_02_DstHost(qubesmgmt.tests.QubesTestCase): def test_011_ipv6_prefixlen(self): with self.assertNotRaises(ValueError): - instance = qubesmgmt.firewall.DstHost('2001:abcd:efab::', 64) + instance = qubesadmin.firewall.DstHost('2001:abcd:efab::', 64) self.assertEqual(instance.type, 'dst6') self.assertEqual(instance.prefixlen, 64) self.assertEqual(str(instance), '2001:abcd:efab::/64') @@ -147,7 +147,7 @@ class TC_02_DstHost(qubesmgmt.tests.QubesTestCase): def test_012_ipv6_parse_prefixlen(self): with self.assertNotRaises(ValueError): - instance = qubesmgmt.firewall.DstHost('2001:abcd:efab::/64') + instance = qubesadmin.firewall.DstHost('2001:abcd:efab::/64') self.assertEqual(instance.type, 'dst6') self.assertEqual(instance.prefixlen, 64) self.assertEqual(str(instance), '2001:abcd:efab::/64') @@ -155,120 +155,120 @@ class TC_02_DstHost(qubesmgmt.tests.QubesTestCase): def test_013_ipv6_invalid_prefix(self): with self.assertRaises(ValueError): - qubesmgmt.firewall.DstHost('2001:abcd:efab::3/129') + qubesadmin.firewall.DstHost('2001:abcd:efab::3/129') with self.assertRaises(ValueError): - qubesmgmt.firewall.DstHost('2001:abcd:efab::3', 129) + qubesadmin.firewall.DstHost('2001:abcd:efab::3', 129) with self.assertRaises(ValueError): - qubesmgmt.firewall.DstHost('2001:abcd:efab::3/-1') + qubesadmin.firewall.DstHost('2001:abcd:efab::3/-1') def test_014_ipv6_invalid_addr(self): with self.assertRaises(ValueError): - qubesmgmt.firewall.DstHost('2001:abcd:efab0123::3/128') + qubesadmin.firewall.DstHost('2001:abcd:efab0123::3/128') with self.assertRaises(ValueError): - qubesmgmt.firewall.DstHost('2001:abcd:efab:3/128') + qubesadmin.firewall.DstHost('2001:abcd:efab:3/128') with self.assertRaises(ValueError): - qubesmgmt.firewall.DstHost('2001:abcd:efab:a:a:a:a:a:a:3/128') + qubesadmin.firewall.DstHost('2001:abcd:efab:a:a:a:a:a:a:3/128') with self.assertRaises(ValueError): - qubesmgmt.firewall.DstHost('2001:abcd:efgh::3/128') + qubesadmin.firewall.DstHost('2001:abcd:efgh::3/128') @unittest.expectedFailure def test_015_ipv6_invalid_network(self): with self.assertRaises(ValueError): - qubesmgmt.firewall.DstHost('2001:abcd:efab::3/64') + qubesadmin.firewall.DstHost('2001:abcd:efab::3/64') @unittest.expectedFailure def test_020_invalid_hostname(self): with self.assertRaises(ValueError): - qubesmgmt.firewall.DstHost('www qubes-os.org') + qubesadmin.firewall.DstHost('www qubes-os.org') with self.assertRaises(ValueError): - qubesmgmt.firewall.DstHost('https://qubes-os.org') + qubesadmin.firewall.DstHost('https://qubes-os.org') -class TC_03_DstPorts(qubesmgmt.tests.QubesTestCase): +class TC_03_DstPorts(qubesadmin.tests.QubesTestCase): def test_000_single_str(self): with self.assertNotRaises(ValueError): - instance = qubesmgmt.firewall.DstPorts('80') + instance = qubesadmin.firewall.DstPorts('80') self.assertEqual(str(instance), '80') self.assertEqual(instance.range, [80, 80]) self.assertEqual(instance.rule, 'dstports=80-80') def test_001_single_int(self): with self.assertNotRaises(ValueError): - instance = qubesmgmt.firewall.DstPorts(80) + instance = qubesadmin.firewall.DstPorts(80) self.assertEqual(str(instance), '80') self.assertEqual(instance.range, [80, 80]) self.assertEqual(instance.rule, 'dstports=80-80') def test_002_range(self): with self.assertNotRaises(ValueError): - instance = qubesmgmt.firewall.DstPorts('80-90') + instance = qubesadmin.firewall.DstPorts('80-90') self.assertEqual(str(instance), '80-90') self.assertEqual(instance.range, [80, 90]) self.assertEqual(instance.rule, 'dstports=80-90') def test_003_invalid(self): with self.assertRaises(ValueError): - qubesmgmt.firewall.DstPorts('80-90-100') + qubesadmin.firewall.DstPorts('80-90-100') with self.assertRaises(ValueError): - qubesmgmt.firewall.DstPorts('abcdef') + qubesadmin.firewall.DstPorts('abcdef') with self.assertRaises(ValueError): - qubesmgmt.firewall.DstPorts('80 90') + qubesadmin.firewall.DstPorts('80 90') with self.assertRaises(ValueError): - qubesmgmt.firewall.DstPorts('') + qubesadmin.firewall.DstPorts('') def test_004_reversed_range(self): with self.assertRaises(ValueError): - qubesmgmt.firewall.DstPorts('100-20') + qubesadmin.firewall.DstPorts('100-20') def test_005_out_of_range(self): with self.assertRaises(ValueError): - qubesmgmt.firewall.DstPorts('1000000000000') + qubesadmin.firewall.DstPorts('1000000000000') with self.assertRaises(ValueError): - qubesmgmt.firewall.DstPorts(1000000000000) + qubesadmin.firewall.DstPorts(1000000000000) with self.assertRaises(ValueError): - qubesmgmt.firewall.DstPorts('1-1000000000000') + qubesadmin.firewall.DstPorts('1-1000000000000') -class TC_04_IcmpType(qubesmgmt.tests.QubesTestCase): +class TC_04_IcmpType(qubesadmin.tests.QubesTestCase): def test_000_number(self): with self.assertNotRaises(ValueError): - instance = qubesmgmt.firewall.IcmpType(8) + instance = qubesadmin.firewall.IcmpType(8) self.assertEqual(str(instance), '8') self.assertEqual(instance.rule, 'icmptype=8') def test_001_str(self): with self.assertNotRaises(ValueError): - instance = qubesmgmt.firewall.IcmpType('8') + instance = qubesadmin.firewall.IcmpType('8') self.assertEqual(str(instance), '8') self.assertEqual(instance.rule, 'icmptype=8') def test_002_invalid(self): with self.assertRaises(ValueError): - qubesmgmt.firewall.IcmpType(600) + qubesadmin.firewall.IcmpType(600) with self.assertRaises(ValueError): - qubesmgmt.firewall.IcmpType(-1) + qubesadmin.firewall.IcmpType(-1) with self.assertRaises(ValueError): - qubesmgmt.firewall.IcmpType('abcde') + qubesadmin.firewall.IcmpType('abcde') with self.assertRaises(ValueError): - qubesmgmt.firewall.IcmpType('') + qubesadmin.firewall.IcmpType('') -class TC_05_SpecialTarget(qubesmgmt.tests.QubesTestCase): +class TC_05_SpecialTarget(qubesadmin.tests.QubesTestCase): def test_000_allowed_values(self): with self.assertNotRaises(ValueError): - instance = qubesmgmt.firewall.SpecialTarget('dns') + instance = qubesadmin.firewall.SpecialTarget('dns') self.assertEqual( set(instance.allowed_values), {'dns'}) def test_001_rule(self): - instance = qubesmgmt.firewall.SpecialTarget('dns') + instance = qubesadmin.firewall.SpecialTarget('dns') self.assertEqual(instance.rule, 'specialtarget=dns') -class TC_06_Expire(qubesmgmt.tests.QubesTestCase): +class TC_06_Expire(qubesadmin.tests.QubesTestCase): def test_000_number(self): with self.assertNotRaises(ValueError): - instance = qubesmgmt.firewall.Expire(1463292452) + instance = qubesadmin.firewall.Expire(1463292452) self.assertEqual(str(instance), '1463292452') self.assertEqual(instance.datetime, datetime.datetime(2016, 5, 15, 6, 7, 32)) @@ -276,7 +276,7 @@ class TC_06_Expire(qubesmgmt.tests.QubesTestCase): def test_001_str(self): with self.assertNotRaises(ValueError): - instance = qubesmgmt.firewall.Expire('1463292452') + instance = qubesadmin.firewall.Expire('1463292452') self.assertEqual(str(instance), '1463292452') self.assertEqual(instance.datetime, datetime.datetime(2016, 5, 15, 6, 7, 32)) @@ -284,31 +284,31 @@ class TC_06_Expire(qubesmgmt.tests.QubesTestCase): def test_002_invalid(self): with self.assertRaises(ValueError): - qubesmgmt.firewall.Expire('abcdef') + qubesadmin.firewall.Expire('abcdef') with self.assertRaises(ValueError): - qubesmgmt.firewall.Expire('') + qubesadmin.firewall.Expire('') def test_003_expired(self): with self.assertNotRaises(ValueError): - instance = qubesmgmt.firewall.Expire('1463292452') + instance = qubesadmin.firewall.Expire('1463292452') self.assertTrue(instance.expired) with self.assertNotRaises(ValueError): - instance = qubesmgmt.firewall.Expire('1583292452') + instance = qubesadmin.firewall.Expire('1583292452') self.assertFalse(instance.expired) -class TC_07_Comment(qubesmgmt.tests.QubesTestCase): +class TC_07_Comment(qubesadmin.tests.QubesTestCase): def test_000_str(self): with self.assertNotRaises(ValueError): - instance = qubesmgmt.firewall.Comment('Some comment') + instance = qubesadmin.firewall.Comment('Some comment') self.assertEqual(str(instance), 'Some comment') self.assertEqual(instance.rule, 'comment=Some comment') -class TC_10_Rule(qubesmgmt.tests.QubesTestCase): +class TC_10_Rule(qubesadmin.tests.QubesTestCase): def test_000_simple(self): with self.assertNotRaises(ValueError): - rule = qubesmgmt.firewall.Rule(None, action='accept', proto='icmp') + rule = qubesadmin.firewall.Rule(None, action='accept', proto='icmp') self.assertEqual(rule.rule, 'action=accept proto=icmp') self.assertIsNone(rule.dsthost) self.assertIsNone(rule.dstports) @@ -320,7 +320,7 @@ class TC_10_Rule(qubesmgmt.tests.QubesTestCase): def test_001_expire(self): with self.assertNotRaises(ValueError): - rule = qubesmgmt.firewall.Rule(None, action='accept', proto='icmp', + rule = qubesadmin.firewall.Rule(None, action='accept', proto='icmp', expire='1463292452') self.assertEqual(rule.rule, 'action=accept proto=icmp expire=1463292452') @@ -328,40 +328,40 @@ class TC_10_Rule(qubesmgmt.tests.QubesTestCase): def test_002_dstports(self): with self.assertNotRaises(ValueError): - rule = qubesmgmt.firewall.Rule(None, action='accept', proto='tcp', + rule = qubesadmin.firewall.Rule(None, action='accept', proto='tcp', dstports=80) self.assertEqual(str(rule.dstports), '80') def test_003_reject_invalid(self): with self.assertRaises((ValueError, AssertionError)): # missing action - qubesmgmt.firewall.Rule(None, proto='icmp') + qubesadmin.firewall.Rule(None, proto='icmp') with self.assertRaises(ValueError): # not proto=tcp or proto=udp for dstports - qubesmgmt.firewall.Rule(None, action='accept', proto='icmp', + qubesadmin.firewall.Rule(None, action='accept', proto='icmp', dstports=80) with self.assertRaises(ValueError): # not proto=tcp or proto=udp for dstports - qubesmgmt.firewall.Rule(None, action='accept', dstports=80) + qubesadmin.firewall.Rule(None, action='accept', dstports=80) with self.assertRaises(ValueError): # not proto=icmp for icmptype - qubesmgmt.firewall.Rule(None, action='accept', proto='tcp', + qubesadmin.firewall.Rule(None, action='accept', proto='tcp', icmptype=8) with self.assertRaises(ValueError): # not proto=icmp for icmptype - qubesmgmt.firewall.Rule(None, action='accept', icmptype=8) + qubesadmin.firewall.Rule(None, action='accept', icmptype=8) def test_004_proto_change(self): - rule = qubesmgmt.firewall.Rule(None, action='accept', proto='tcp') + rule = qubesadmin.firewall.Rule(None, action='accept', proto='tcp') with self.assertNotRaises(ValueError): rule.proto = 'udp' self.assertEqual(rule.rule, 'action=accept proto=udp') - rule = qubesmgmt.firewall.Rule(None, action='accept', proto='tcp', + rule = qubesadmin.firewall.Rule(None, action='accept', proto='tcp', dstports=80) with self.assertNotRaises(ValueError): rule.proto = 'udp' self.assertEqual(rule.rule, 'action=accept proto=udp dstports=80-80') - rule = qubesmgmt.firewall.Rule(None, action='accept') + rule = qubesadmin.firewall.Rule(None, action='accept') with self.assertNotRaises(ValueError): rule.proto = 'udp' self.assertEqual(rule.rule, 'action=accept proto=udp') @@ -383,7 +383,7 @@ class TC_10_Rule(qubesmgmt.tests.QubesTestCase): rule_txt = \ 'action=accept dst4=192.168.0.0/24 proto=tcp dstports=443' with self.assertNotRaises(ValueError): - rule = qubesmgmt.firewall.Rule(rule_txt) + rule = qubesadmin.firewall.Rule(rule_txt) self.assertEqual(rule.dsthost, '192.168.0.0/24') self.assertEqual(rule.proto, 'tcp') self.assertEqual(rule.dstports, '443') @@ -394,7 +394,7 @@ class TC_10_Rule(qubesmgmt.tests.QubesTestCase): rule_txt = \ 'action=accept dsthost=qubes-os.org comment=Some comment' with self.assertNotRaises(ValueError): - rule = qubesmgmt.firewall.Rule(rule_txt) + rule = qubesadmin.firewall.Rule(rule_txt) self.assertEqual(rule.dsthost, 'qubes-os.org') self.assertIsNone(rule.proto) self.assertIsNone(rule.dstports) @@ -402,7 +402,7 @@ class TC_10_Rule(qubesmgmt.tests.QubesTestCase): self.assertEqual(rule.comment, 'Some comment') -class TC_11_Firewall(qubesmgmt.tests.QubesTestCase): +class TC_11_Firewall(qubesadmin.tests.QubesTestCase): def setUp(self): super(TC_11_Firewall, self).setUp() self.app.expected_calls[('dom0', 'mgmt.vm.List', None, None)] = \ @@ -414,7 +414,7 @@ class TC_11_Firewall(qubesmgmt.tests.QubesTestCase): None, None)] = b'0\0accept' policy = self.vm.firewall.policy self.assertEqual(policy, 'accept') - self.assertEqual(policy, qubesmgmt.firewall.Action('accept')) + self.assertEqual(policy, qubesadmin.firewall.Action('accept')) self.assertAllCalled() def test_001_policy_set(self): @@ -426,7 +426,7 @@ class TC_11_Firewall(qubesmgmt.tests.QubesTestCase): def test_002_policy_set2(self): self.app.expected_calls[('test-vm', 'mgmt.vm.firewall.SetPolicy', None, b'drop')] = b'0\0' - self.vm.firewall.policy = qubesmgmt.firewall.Action('drop') + self.vm.firewall.policy = qubesadmin.firewall.Action('drop') self.assertAllCalled() def test_010_load_rules(self): @@ -436,8 +436,8 @@ class TC_11_Firewall(qubesmgmt.tests.QubesTestCase): b'action=drop proto=icmp\n' rules = self.vm.firewall.rules self.assertListEqual(rules, [ - qubesmgmt.firewall.Rule('action=accept dsthost=qubes-os.org'), - qubesmgmt.firewall.Rule('action=drop proto=icmp'), + qubesadmin.firewall.Rule('action=accept dsthost=qubes-os.org'), + qubesadmin.firewall.Rule('action=drop proto=icmp'), ]) # check caching del self.app.expected_calls[('test-vm', 'mgmt.vm.firewall.Get', @@ -451,7 +451,7 @@ class TC_11_Firewall(qubesmgmt.tests.QubesTestCase): self.vm.firewall.load_rules() rules3 = self.vm.firewall.rules self.assertListEqual(rules3, [ - qubesmgmt.firewall.Rule( + qubesadmin.firewall.Rule( 'action=accept dsthost=qubes-os.org proto=tcp dstports=443')]) self.assertAllCalled() @@ -460,7 +460,7 @@ class TC_11_Firewall(qubesmgmt.tests.QubesTestCase): 'action=accept proto=tcp dsthost=qubes-os.org dstports=443-443', 'action=accept dsthost=example.com', ) - rules = [qubesmgmt.firewall.Rule(rule) for rule in rules_txt] + rules = [qubesadmin.firewall.Rule(rule) for rule in rules_txt] self.app.expected_calls[('test-vm', 'mgmt.vm.firewall.Set', None, ''.join(rule + '\n' for rule in rules_txt).encode('ascii'))] = b'0\0' self.vm.firewall.rules = rules diff --git a/qubesmgmt/tests/label.py b/qubesadmin/tests/label.py similarity index 95% rename from qubesmgmt/tests/label.py rename to qubesadmin/tests/label.py index 6dd8016..ea99422 100644 --- a/qubesmgmt/tests/label.py +++ b/qubesadmin/tests/label.py @@ -18,11 +18,11 @@ # You should have received a copy of the GNU Lesser General Public License along # with this program; if not, see . -import qubesmgmt.tests -from qubesmgmt.label import Label +import qubesadmin.tests +from qubesadmin.label import Label -class TC_00_Label(qubesmgmt.tests.QubesTestCase): +class TC_00_Label(qubesadmin.tests.QubesTestCase): def test_000_list(self): self.app.expected_calls[ ('dom0', 'mgmt.label.List', None, None)] = \ diff --git a/qubesmgmt/tests/storage.py b/qubesadmin/tests/storage.py similarity index 95% rename from qubesmgmt/tests/storage.py rename to qubesadmin/tests/storage.py index 5ada843..9e05413 100644 --- a/qubesmgmt/tests/storage.py +++ b/qubesadmin/tests/storage.py @@ -18,16 +18,16 @@ # You should have received a copy of the GNU Lesser General Public License along # with this program; if not, see . -import qubesmgmt.tests -import qubesmgmt.storage +import qubesadmin.tests +import qubesadmin.storage -class TestVMVolume(qubesmgmt.tests.QubesTestCase): +class TestVMVolume(qubesadmin.tests.QubesTestCase): def setUp(self): super(TestVMVolume, self).setUp() - self.vol = qubesmgmt.storage.Volume(self.app, vm='test-vm', + self.vol = qubesadmin.storage.Volume(self.app, vm='test-vm', vm_name='volname') - self.pool_vol = qubesmgmt.storage.Volume(self.app, pool='test-pool', + self.pool_vol = qubesadmin.storage.Volume(self.app, pool='test-pool', vid='some-id') def expect_info(self): @@ -154,7 +154,7 @@ class TestVMVolume(qubesmgmt.tests.QubesTestCase): class TestPoolVolume(TestVMVolume): def setUp(self): super(TestPoolVolume, self).setUp() - self.vol = qubesmgmt.storage.Volume(self.app, pool='test-pool', + self.vol = qubesadmin.storage.Volume(self.app, pool='test-pool', vid='some-id') def test_000_qubesd_call(self): @@ -234,13 +234,13 @@ class TestPoolVolume(TestVMVolume): self.assertAllCalled() -class TestPool(qubesmgmt.tests.QubesTestCase): +class TestPool(qubesadmin.tests.QubesTestCase): def test_000_list(self): self.app.expected_calls[('dom0', 'mgmt.pool.List', None, None)] = \ b'0\x00file\nlvm\n' seen = set() for pool in self.app.pools: - self.assertIsInstance(pool, qubesmgmt.storage.Pool) + self.assertIsInstance(pool, qubesadmin.storage.Pool) self.assertIn(pool.name, ('file', 'lvm')) self.assertNotIn(pool.name, seen) seen.add(pool.name) @@ -275,7 +275,7 @@ class TestPool(qubesmgmt.tests.QubesTestCase): pool = self.app.pools['file'] seen = set() for volume in pool.volumes: - self.assertIsInstance(volume, qubesmgmt.storage.Volume) + self.assertIsInstance(volume, qubesadmin.storage.Volume) self.assertIn(volume.vid, ('vol1', 'vol2')) self.assertEqual(volume.pool, 'file') self.assertNotIn(volume.vid, seen) diff --git a/qubesmgmt/tests/tools/__init__.py b/qubesadmin/tests/tools/__init__.py similarity index 100% rename from qubesmgmt/tests/tools/__init__.py rename to qubesadmin/tests/tools/__init__.py diff --git a/qubesmgmt/tests/tools/init.py b/qubesadmin/tests/tools/init.py similarity index 84% rename from qubesmgmt/tests/tools/init.py rename to qubesadmin/tests/tools/init.py index 659267d..1a0b45d 100644 --- a/qubesmgmt/tests/tools/init.py +++ b/qubesadmin/tests/tools/init.py @@ -19,16 +19,16 @@ import argparse -import qubesmgmt -import qubesmgmt.tools +import qubesadmin +import qubesadmin.tools -import qubesmgmt.tests +import qubesadmin.tests -class TC_00_PropertyAction(qubesmgmt.tests.QubesTestCase): +class TC_00_PropertyAction(qubesadmin.tests.QubesTestCase): def test_000_default(self): parser = argparse.ArgumentParser() parser.add_argument('--property', '-p', - action=qubesmgmt.tools.PropertyAction) + action=qubesadmin.tools.PropertyAction) parser.set_defaults(properties={'defaultprop': 'defaultvalue'}) args = parser.parse_args([]) @@ -38,7 +38,7 @@ class TC_00_PropertyAction(qubesmgmt.tests.QubesTestCase): def test_001_set_prop(self): parser = argparse.ArgumentParser() parser.add_argument('--property', '-p', - action=qubesmgmt.tools.PropertyAction) + action=qubesadmin.tools.PropertyAction) args = parser.parse_args(['-p', 'testprop=testvalue']) self.assertDictContainsSubset( @@ -47,7 +47,7 @@ class TC_00_PropertyAction(qubesmgmt.tests.QubesTestCase): def test_002_set_prop_2(self): parser = argparse.ArgumentParser() parser.add_argument('--property', '-p', - action=qubesmgmt.tools.PropertyAction) + action=qubesadmin.tools.PropertyAction) parser.set_defaults(properties={'defaultprop': 'defaultvalue'}) args = parser.parse_args( @@ -59,7 +59,7 @@ class TC_00_PropertyAction(qubesmgmt.tests.QubesTestCase): def test_003_set_prop_with_default(self): parser = argparse.ArgumentParser() parser.add_argument('--property', '-p', - action=qubesmgmt.tools.PropertyAction) + action=qubesadmin.tools.PropertyAction) parser.set_defaults(properties={'defaultprop': 'defaultvalue'}) args = parser.parse_args(['-p', 'testprop=testvalue']) @@ -71,7 +71,7 @@ class TC_00_PropertyAction(qubesmgmt.tests.QubesTestCase): # pylint: disable=invalid-name parser = argparse.ArgumentParser() parser.add_argument('--property', '-p', - action=qubesmgmt.tools.PropertyAction) + action=qubesadmin.tools.PropertyAction) parser.set_defaults(properties={'testprop': 'defaultvalue'}) args = parser.parse_args(['-p', 'testprop=testvalue']) @@ -80,24 +80,24 @@ class TC_00_PropertyAction(qubesmgmt.tests.QubesTestCase): args.properties) -class TC_01_SinglePropertyAction(qubesmgmt.tests.QubesTestCase): +class TC_01_SinglePropertyAction(qubesadmin.tests.QubesTestCase): def test_000_help(self): parser = argparse.ArgumentParser() action = parser.add_argument('--testprop', '-T', - action=qubesmgmt.tools.SinglePropertyAction) + action=qubesadmin.tools.SinglePropertyAction) self.assertIn('testprop', action.help) def test_001_help_const(self): parser = argparse.ArgumentParser() action = parser.add_argument('--testprop', '-T', - action=qubesmgmt.tools.SinglePropertyAction, + action=qubesadmin.tools.SinglePropertyAction, const='testvalue') self.assertIn('testvalue', action.help) def test_100_default(self): parser = argparse.ArgumentParser() parser.add_argument('--testprop', '-T', - action=qubesmgmt.tools.SinglePropertyAction) + action=qubesadmin.tools.SinglePropertyAction) parser.set_defaults(properties={'testprop': 'defaultvalue'}) args = parser.parse_args([]) @@ -107,7 +107,7 @@ class TC_01_SinglePropertyAction(qubesmgmt.tests.QubesTestCase): def test_101_set_prop(self): parser = argparse.ArgumentParser() parser.add_argument('--testprop', '-T', - action=qubesmgmt.tools.SinglePropertyAction) + action=qubesadmin.tools.SinglePropertyAction) args = parser.parse_args(['-T', 'testvalue']) self.assertDictContainsSubset( {'testprop': 'testvalue'}, args.properties) @@ -115,7 +115,7 @@ class TC_01_SinglePropertyAction(qubesmgmt.tests.QubesTestCase): def test_102_set_prop_dest(self): parser = argparse.ArgumentParser() parser.add_argument('--testprop', '-T', dest='otherprop', - action=qubesmgmt.tools.SinglePropertyAction) + action=qubesadmin.tools.SinglePropertyAction) args = parser.parse_args(['-T', 'testvalue']) self.assertDictContainsSubset( {'otherprop': 'testvalue'}, args.properties) @@ -123,7 +123,7 @@ class TC_01_SinglePropertyAction(qubesmgmt.tests.QubesTestCase): def test_103_set_prop_const(self): parser = argparse.ArgumentParser() parser.add_argument('--testprop', '-T', - action=qubesmgmt.tools.SinglePropertyAction, + action=qubesadmin.tools.SinglePropertyAction, const='testvalue') args = parser.parse_args(['-T']) self.assertDictContainsSubset( @@ -132,7 +132,7 @@ class TC_01_SinglePropertyAction(qubesmgmt.tests.QubesTestCase): def test_104_set_prop_positional(self): parser = argparse.ArgumentParser() parser.add_argument('testprop', - action=qubesmgmt.tools.SinglePropertyAction) + action=qubesadmin.tools.SinglePropertyAction) args = parser.parse_args(['testvalue']) self.assertDictContainsSubset( {'testprop': 'testvalue'}, args.properties) diff --git a/qubesmgmt/tests/tools/qubes_prefs.py b/qubesadmin/tests/tools/qubes_prefs.py similarity index 81% rename from qubesmgmt/tests/tools/qubes_prefs.py rename to qubesadmin/tests/tools/qubes_prefs.py index cda5066..1efa22f 100644 --- a/qubesmgmt/tests/tools/qubes_prefs.py +++ b/qubesadmin/tests/tools/qubes_prefs.py @@ -18,12 +18,12 @@ # You should have received a copy of the GNU Lesser General Public License along # with this program; if not, see . -import qubesmgmt.tests -import qubesmgmt.tests.tools -import qubesmgmt.tools.qubes_prefs +import qubesadmin.tests +import qubesadmin.tests.tools +import qubesadmin.tools.qubes_prefs -class TC_00_qubes_prefs(qubesmgmt.tests.QubesTestCase): +class TC_00_qubes_prefs(qubesadmin.tests.QubesTestCase): def test_000_list(self): self.app.expected_calls[ ('dom0', 'mgmt.property.List', None, None)] = \ @@ -34,8 +34,8 @@ class TC_00_qubes_prefs(qubesmgmt.tests.QubesTestCase): self.app.expected_calls[ ('dom0', 'mgmt.property.Get', 'prop2', None)] = \ b'0\x00default=False type=str value2' - with qubesmgmt.tests.tools.StdoutBuffer() as stdout: - self.assertEqual(0, qubesmgmt.tools.qubes_prefs.main([], app=self.app)) + with qubesadmin.tests.tools.StdoutBuffer() as stdout: + self.assertEqual(0, qubesadmin.tools.qubes_prefs.main([], app=self.app)) self.assertEqual(stdout.getvalue(), 'prop1 D value1\n' 'prop2 - value2\n') @@ -45,7 +45,7 @@ class TC_00_qubes_prefs(qubesmgmt.tests.QubesTestCase): self.app.expected_calls[ ('dom0', 'mgmt.property.Set', 'default_user', b'testuser')]\ = b'0\x00' - self.assertEqual(0, qubesmgmt.tools.qubes_prefs.main([ + self.assertEqual(0, qubesadmin.tools.qubes_prefs.main([ 'default_user', 'testuser'], app=self.app)) self.assertAllCalled() @@ -54,8 +54,8 @@ class TC_00_qubes_prefs(qubesmgmt.tests.QubesTestCase): ('dom0', 'mgmt.property.Get', 'no_such_property', None)] = \ b'2\x00AttributeError\x00\x00no_such_property\x00' with self.assertRaises(SystemExit): - with qubesmgmt.tests.tools.StderrBuffer() as stderr: - qubesmgmt.tools.qubes_prefs.main([ + with qubesadmin.tests.tools.StderrBuffer() as stderr: + qubesadmin.tools.qubes_prefs.main([ 'no_such_property'], app=self.app) self.assertIn('no such property: \'no_such_property\'', stderr.getvalue()) @@ -66,8 +66,8 @@ class TC_00_qubes_prefs(qubesmgmt.tests.QubesTestCase): ('dom0', 'mgmt.property.Set', 'no_such_property', b'value')]\ = b'2\x00AttributeError\x00\x00no_such_property\x00' with self.assertRaises(SystemExit): - with qubesmgmt.tests.tools.StderrBuffer() as stderr: - qubesmgmt.tools.qubes_prefs.main([ + with qubesadmin.tests.tools.StderrBuffer() as stderr: + qubesadmin.tools.qubes_prefs.main([ 'no_such_property', 'value'], app=self.app) self.assertIn('no such property: \'no_such_property\'', stderr.getvalue()) diff --git a/qubesmgmt/tests/tools/qvm_check.py b/qubesadmin/tests/tools/qvm_check.py similarity index 84% rename from qubesmgmt/tests/tools/qvm_check.py rename to qubesadmin/tests/tools/qvm_check.py index 1398f1f..16f743e 100644 --- a/qubesmgmt/tests/tools/qvm_check.py +++ b/qubesadmin/tests/tools/qvm_check.py @@ -18,16 +18,16 @@ # You should have received a copy of the GNU Lesser General Public License along # with this program; if not, see . -import qubesmgmt.tests -import qubesmgmt.tools.qvm_check +import qubesadmin.tests +import qubesadmin.tools.qvm_check -class TC_00_qvm_check(qubesmgmt.tests.QubesTestCase): +class TC_00_qvm_check(qubesadmin.tests.QubesTestCase): def test_000_exists(self): self.app.expected_calls[ ('dom0', 'mgmt.vm.List', None, None)] = \ b'0\x00some-vm class=AppVM state=Running\n' self.assertEqual( - qubesmgmt.tools.qvm_check.main(['some-vm'], app=self.app), + qubesadmin.tools.qvm_check.main(['some-vm'], app=self.app), 0) self.assertAllCalled() @@ -37,7 +37,7 @@ class TC_00_qvm_check(qubesmgmt.tests.QubesTestCase): b'0\x00some-vm class=AppVM state=Running\n' \ b'other-vm class=AppVM state=Running\n' self.assertEqual( - qubesmgmt.tools.qvm_check.main(['some-vm', 'other-vm'], + qubesadmin.tools.qvm_check.main(['some-vm', 'other-vm'], app=self.app), 0) self.assertAllCalled() @@ -46,9 +46,9 @@ class TC_00_qvm_check(qubesmgmt.tests.QubesTestCase): self.app.expected_calls[ ('dom0', 'mgmt.vm.List', None, None)] = \ b'0\x00some-vm class=AppVM state=Running\n' - with qubesmgmt.tests.tools.StdoutBuffer() as stdout: + with qubesadmin.tests.tools.StdoutBuffer() as stdout: self.assertEqual( - qubesmgmt.tools.qvm_check.main(['some-vm'], app=self.app), + qubesadmin.tools.qvm_check.main(['some-vm'], app=self.app), 0) self.assertEqual(stdout.getvalue(), 'VM some-vm exists\n') @@ -59,9 +59,9 @@ class TC_00_qvm_check(qubesmgmt.tests.QubesTestCase): ('dom0', 'mgmt.vm.List', None, None)] = \ b'0\x00some-vm class=AppVM state=Running\n' \ b'other-vm class=AppVM state=Running\n' - with qubesmgmt.tests.tools.StdoutBuffer() as stdout: + with qubesadmin.tests.tools.StdoutBuffer() as stdout: self.assertEqual( - qubesmgmt.tools.qvm_check.main(['some-vm', 'other-vm'], + qubesadmin.tools.qvm_check.main(['some-vm', 'other-vm'], app=self.app), 0) self.assertEqual(stdout.getvalue(), @@ -77,9 +77,9 @@ class TC_00_qvm_check(qubesmgmt.tests.QubesTestCase): self.app.expected_calls[ ('some-vm', 'mgmt.vm.List', None, None)] = \ b'0\x00some-vm class=AppVM state=Running\n' - with qubesmgmt.tests.tools.StdoutBuffer() as stdout: + with qubesadmin.tests.tools.StdoutBuffer() as stdout: self.assertEqual( - qubesmgmt.tools.qvm_check.main(['--running', + qubesadmin.tools.qvm_check.main(['--running', 'some-vm'], app=self.app), 0) self.assertEqual(stdout.getvalue(), @@ -98,9 +98,9 @@ class TC_00_qvm_check(qubesmgmt.tests.QubesTestCase): self.app.expected_calls[ ('some-vm2', 'mgmt.vm.List', None, None)] = \ b'0\x00some-vm2 class=AppVM state=Running\n' - with qubesmgmt.tests.tools.StdoutBuffer() as stdout: + with qubesadmin.tests.tools.StdoutBuffer() as stdout: self.assertEqual( - qubesmgmt.tools.qvm_check.main(['--running', + qubesadmin.tools.qvm_check.main(['--running', 'some-vm', 'some-vm2'], app=self.app), 0) @@ -123,9 +123,9 @@ class TC_00_qvm_check(qubesmgmt.tests.QubesTestCase): self.app.expected_calls[ ('some-vm3', 'mgmt.vm.List', None, None)] = \ b'0\x00some-vm3 class=AppVM state=Halted\n' - with qubesmgmt.tests.tools.StdoutBuffer() as stdout: + with qubesadmin.tests.tools.StdoutBuffer() as stdout: self.assertEqual( - qubesmgmt.tools.qvm_check.main(['--running', + qubesadmin.tools.qvm_check.main(['--running', '--all'], app=self.app), 0) @@ -142,9 +142,9 @@ class TC_00_qvm_check(qubesmgmt.tests.QubesTestCase): self.app.expected_calls[ ('some-vm3', 'mgmt.vm.List', None, None)] = \ b'0\x00some-vm3 class=AppVM state=Halted\n' - with qubesmgmt.tests.tools.StdoutBuffer() as stdout: + with qubesadmin.tests.tools.StdoutBuffer() as stdout: self.assertEqual( - qubesmgmt.tools.qvm_check.main(['--running', + qubesadmin.tools.qvm_check.main(['--running', 'some-vm3'], app=self.app), 1) @@ -161,9 +161,9 @@ class TC_00_qvm_check(qubesmgmt.tests.QubesTestCase): self.app.expected_calls[ ('some-vm2', 'mgmt.vm.List', None, None)] = \ b'0\x00some-vm2 class=AppVM state=Paused\n' - with qubesmgmt.tests.tools.StdoutBuffer() as stdout: + with qubesadmin.tests.tools.StdoutBuffer() as stdout: self.assertEqual( - qubesmgmt.tools.qvm_check.main(['--paused', + qubesadmin.tools.qvm_check.main(['--paused', 'some-vm2'], app=self.app), 0) @@ -183,9 +183,9 @@ class TC_00_qvm_check(qubesmgmt.tests.QubesTestCase): self.app.expected_calls[ ('some-vm', 'mgmt.vm.List', None, None)] = \ b'0\x00some-vm class=AppVM state=Running\n' - with qubesmgmt.tests.tools.StdoutBuffer() as stdout: + with qubesadmin.tests.tools.StdoutBuffer() as stdout: self.assertEqual( - qubesmgmt.tools.qvm_check.main(['--paused', + qubesadmin.tools.qvm_check.main(['--paused', 'some-vm2', 'some-vm'], app=self.app), 0) @@ -200,9 +200,9 @@ class TC_00_qvm_check(qubesmgmt.tests.QubesTestCase): b'0\x00some-vm class=AppVM state=Running\n' \ b'some-vm2 class=AppVM state=Paused\n' \ b'some-vm3 class=TemplateVM state=Halted\n' - with qubesmgmt.tests.tools.StdoutBuffer() as stdout: + with qubesadmin.tests.tools.StdoutBuffer() as stdout: self.assertEqual( - qubesmgmt.tools.qvm_check.main(['--template', + qubesadmin.tools.qvm_check.main(['--template', 'some-vm3'], app=self.app), 0) @@ -216,9 +216,9 @@ class TC_00_qvm_check(qubesmgmt.tests.QubesTestCase): b'0\x00some-vm class=AppVM state=Running\n' \ b'some-vm2 class=AppVM state=Paused\n' \ b'some-vm3 class=TemplateVM state=Halted\n' - with qubesmgmt.tests.tools.StdoutBuffer() as stdout: + with qubesadmin.tests.tools.StdoutBuffer() as stdout: self.assertEqual( - qubesmgmt.tools.qvm_check.main(['--template', + qubesadmin.tools.qvm_check.main(['--template', 'some-vm2', 'some-vm3'], app=self.app), 0) diff --git a/qubesmgmt/tests/tools/qvm_clone.py b/qubesadmin/tests/tools/qvm_clone.py similarity index 81% rename from qubesmgmt/tests/tools/qvm_clone.py rename to qubesadmin/tests/tools/qvm_clone.py index 0211ea1..d531684 100644 --- a/qubesmgmt/tests/tools/qvm_clone.py +++ b/qubesadmin/tests/tools/qvm_clone.py @@ -17,25 +17,25 @@ # # You should have received a copy of the GNU Lesser General Public License along # with this program; if not, see . -import qubesmgmt.tests -import qubesmgmt.tests.tools -import qubesmgmt.tools.qvm_clone +import qubesadmin.tests +import qubesadmin.tests.tools +import qubesadmin.tools.qvm_clone -class TC_00_qvm_clone(qubesmgmt.tests.QubesTestCase): +class TC_00_qvm_clone(qubesadmin.tests.QubesTestCase): def test_000_simple(self): self.app.expected_calls[('test-vm', 'mgmt.vm.Clone', None, b'name=new-vm')] = b'0\x00' self.app.expected_calls[('dom0', 'mgmt.vm.List', None, None)] = \ b'0\x00new-vm class=AppVM state=Halted\n' \ b'test-vm class=AppVM state=Halted\n' - qubesmgmt.tools.qvm_clone.main(['test-vm', 'new-vm'], app=self.app) + qubesadmin.tools.qvm_clone.main(['test-vm', 'new-vm'], app=self.app) self.assertAllCalled() def test_001_missing_vm(self): with self.assertRaises(SystemExit): - with qubesmgmt.tests.tools.StderrBuffer() as stderr: - qubesmgmt.tools.qvm_clone.main(['test-vm'], app=self.app) + with qubesadmin.tests.tools.StderrBuffer() as stderr: + qubesadmin.tools.qvm_clone.main(['test-vm'], app=self.app) self.assertIn('NAME', stderr.getvalue()) self.assertAllCalled() @@ -45,7 +45,7 @@ class TC_00_qvm_clone(qubesmgmt.tests.QubesTestCase): self.app.expected_calls[('dom0', 'mgmt.vm.List', None, None)] = \ b'0\x00new-vm class=AppVM state=Halted\n' \ b'test-vm class=AppVM state=Halted\n' - qubesmgmt.tools.qvm_clone.main(['-P', 'some-pool', 'test-vm', 'new-vm'], + qubesadmin.tools.qvm_clone.main(['-P', 'some-pool', 'test-vm', 'new-vm'], app=self.app) self.assertAllCalled() @@ -56,7 +56,7 @@ class TC_00_qvm_clone(qubesmgmt.tests.QubesTestCase): self.app.expected_calls[('dom0', 'mgmt.vm.List', None, None)] = \ b'0\x00new-vm class=AppVM state=Halted\n' \ b'test-vm class=AppVM state=Halted\n' - qubesmgmt.tools.qvm_clone.main(['--pool', 'private=some-pool', + qubesadmin.tools.qvm_clone.main(['--pool', 'private=some-pool', '--pool', 'volatile=other-pool', 'test-vm', 'new-vm'], app=self.app) self.assertAllCalled() diff --git a/qubesmgmt/tests/tools/qvm_create.py b/qubesadmin/tests/tools/qvm_create.py similarity index 85% rename from qubesmgmt/tests/tools/qvm_create.py rename to qubesadmin/tests/tools/qvm_create.py index e0d2863..b934b37 100644 --- a/qubesmgmt/tests/tools/qvm_create.py +++ b/qubesadmin/tests/tools/qvm_create.py @@ -17,12 +17,12 @@ # # You should have received a copy of the GNU Lesser General Public License along # with this program; if not, see . -import qubesmgmt.tests -import qubesmgmt.tests.tools -import qubesmgmt.tools.qvm_create +import qubesadmin.tests +import qubesadmin.tests.tools +import qubesadmin.tools.qvm_create -class TC_00_qvm_create(qubesmgmt.tests.QubesTestCase): +class TC_00_qvm_create(qubesadmin.tests.QubesTestCase): def test_000_just_appvm(self): self.app.expected_calls[('dom0', 'mgmt.vm.Create.AppVM', None, b'name=new-vm label=red')] = b'0\x00' @@ -30,13 +30,13 @@ class TC_00_qvm_create(qubesmgmt.tests.QubesTestCase): b'0\x00red\nblue\n' self.app.expected_calls[('dom0', 'mgmt.vm.List', None, None)] = \ b'0\x00new-vm class=AppVM state=Halted\n' - qubesmgmt.tools.qvm_create.main(['-l', 'red', 'new-vm'], app=self.app) + qubesadmin.tools.qvm_create.main(['-l', 'red', 'new-vm'], app=self.app) self.assertAllCalled() def test_001_missing_vm(self): with self.assertRaises(SystemExit): - with qubesmgmt.tests.tools.StderrBuffer() as stderr: - qubesmgmt.tools.qvm_create.main(['-l', 'red'], app=self.app) + with qubesadmin.tests.tools.StderrBuffer() as stderr: + qubesadmin.tools.qvm_create.main(['-l', 'red'], app=self.app) self.assertIn('NAME', stderr.getvalue()) self.assertAllCalled() @@ -47,7 +47,7 @@ class TC_00_qvm_create(qubesmgmt.tests.QubesTestCase): b'0\x00red\nblue\n' self.app.expected_calls[('dom0', 'mgmt.vm.List', None, None)] = \ b'0\x00new-vm class=AppVM state=Halted\n' - qubesmgmt.tools.qvm_create.main(['-l', 'red', '-t', + qubesadmin.tools.qvm_create.main(['-l', 'red', '-t', 'some-template', 'new-vm'], app=self.app) self.assertAllCalled() @@ -60,7 +60,7 @@ class TC_00_qvm_create(qubesmgmt.tests.QubesTestCase): b'0\x00new-vm class=AppVM state=Halted\n' self.app.expected_calls[('new-vm', 'mgmt.vm.property.Set', 'netvm', b'sys-whonix')] = b'0\x00' - qubesmgmt.tools.qvm_create.main(['-l', 'red', '--prop', + qubesadmin.tools.qvm_create.main(['-l', 'red', '--prop', 'netvm=sys-whonix', 'new-vm'], app=self.app) self.assertAllCalled() @@ -72,7 +72,7 @@ class TC_00_qvm_create(qubesmgmt.tests.QubesTestCase): b'0\x00red\nblue\n' self.app.expected_calls[('dom0', 'mgmt.vm.List', None, None)] = \ b'0\x00new-vm class=AppVM state=Halted\n' - qubesmgmt.tools.qvm_create.main(['-l', 'red', '-P', 'some-pool', + qubesadmin.tools.qvm_create.main(['-l', 'red', '-P', 'some-pool', 'new-vm'], app=self.app) self.assertAllCalled() @@ -85,7 +85,7 @@ class TC_00_qvm_create(qubesmgmt.tests.QubesTestCase): b'0\x00red\nblue\n' self.app.expected_calls[('dom0', 'mgmt.vm.List', None, None)] = \ b'0\x00new-vm class=AppVM state=Halted\n' - qubesmgmt.tools.qvm_create.main(['-l', 'red', '--pool', + qubesadmin.tools.qvm_create.main(['-l', 'red', '--pool', 'private=some-pool', '--pool', 'volatile=other-pool', 'new-vm'], app=self.app) self.assertAllCalled() diff --git a/qubesmgmt/tests/tools/qvm_device.py b/qubesadmin/tests/tools/qvm_device.py similarity index 87% rename from qubesmgmt/tests/tools/qvm_device.py rename to qubesadmin/tests/tools/qvm_device.py index d12139c..54a895a 100644 --- a/qubesmgmt/tests/tools/qvm_device.py +++ b/qubesadmin/tests/tools/qvm_device.py @@ -24,13 +24,13 @@ ''' Tests for the `qvm-device` tool. ''' import unittest.mock as mock -import qubesmgmt.tests -import qubesmgmt.tests.tools -import qubesmgmt.devices -import qubesmgmt.tools.qvm_device +import qubesadmin.tests +import qubesadmin.tests.tools +import qubesadmin.devices +import qubesadmin.tools.qvm_device -class TC_00_qvm_device(qubesmgmt.tests.QubesTestCase): +class TC_00_qvm_device(qubesadmin.tests.QubesTestCase): ''' Tests the output logic of the qvm-device tool ''' def setUp(self): super(TC_00_qvm_device, self).setUp() @@ -63,8 +63,8 @@ class TC_00_qvm_device(qubesmgmt.tests.QubesTestCase): self.app.expected_calls[('test-vm3', 'mgmt.vm.device.test.List', None, None)] = b'0\0' - with qubesmgmt.tests.tools.StdoutBuffer() as buf: - qubesmgmt.tools.qvm_device.main( + with qubesadmin.tests.tools.StdoutBuffer() as buf: + qubesadmin.tools.qvm_device.main( ['test', 'list'], app=self.app) self.assertEqual( [x.rstrip() for x in buf.getvalue().splitlines()], @@ -89,8 +89,8 @@ class TC_00_qvm_device(qubesmgmt.tests.QubesTestCase): None, None)] = \ b'0\0test-vm1+dev1 persistent=yes\n' - with qubesmgmt.tests.tools.StdoutBuffer() as buf: - qubesmgmt.tools.qvm_device.main( + with qubesadmin.tests.tools.StdoutBuffer() as buf: + qubesadmin.tools.qvm_device.main( ['test', 'list', 'test-vm3'], app=self.app) self.assertEqual( buf.getvalue(), @@ -116,8 +116,8 @@ class TC_00_qvm_device(qubesmgmt.tests.QubesTestCase): None, None)] = \ b'0\0test-vm1+dev1\n' - with qubesmgmt.tests.tools.StdoutBuffer() as buf: - qubesmgmt.tools.qvm_device.main( + with qubesadmin.tests.tools.StdoutBuffer() as buf: + qubesadmin.tools.qvm_device.main( ['test', 'list', 'test-vm3'], app=self.app) self.assertEqual( buf.getvalue(), @@ -128,7 +128,7 @@ class TC_00_qvm_device(qubesmgmt.tests.QubesTestCase): ''' Test attach action ''' self.app.expected_calls[('test-vm2', 'mgmt.vm.device.test.Attach', 'test-vm1+dev1', b'')] = b'0\0' - qubesmgmt.tools.qvm_device.main( + qubesadmin.tools.qvm_device.main( ['test', 'attach', 'test-vm2', 'test-vm1:dev1'], app=self.app) self.assertAllCalled() @@ -136,7 +136,7 @@ class TC_00_qvm_device(qubesmgmt.tests.QubesTestCase): ''' Test attach action ''' self.app.expected_calls[('test-vm2', 'mgmt.vm.device.test.Attach', 'test-vm1+dev1', b'ro=True')] = b'0\0' - qubesmgmt.tools.qvm_device.main( + qubesadmin.tools.qvm_device.main( ['test', 'attach', '-o', 'ro=True', 'test-vm2', 'test-vm1:dev1'], app=self.app) self.assertAllCalled() @@ -145,16 +145,16 @@ class TC_00_qvm_device(qubesmgmt.tests.QubesTestCase): ''' Test attach action ''' self.app.expected_calls[('test-vm2', 'mgmt.vm.device.test.Attach', 'test-vm1+dev1', b'persistent=yes')] = b'0\0' - qubesmgmt.tools.qvm_device.main( + qubesadmin.tools.qvm_device.main( ['test', 'attach', '-p', 'test-vm2', 'test-vm1:dev1'], app=self.app) self.assertAllCalled() def test_012_attach_invalid(self): ''' Test attach action ''' - with qubesmgmt.tests.tools.StderrBuffer() as stderr: + with qubesadmin.tests.tools.StderrBuffer() as stderr: with self.assertRaises(SystemExit): - qubesmgmt.tools.qvm_device.main( + qubesadmin.tools.qvm_device.main( ['test', 'attach', '-p', 'test-vm2', 'dev1'], app=self.app) self.assertIn('expected a backend vm & device id', @@ -163,9 +163,9 @@ class TC_00_qvm_device(qubesmgmt.tests.QubesTestCase): def test_013_attach_invalid2(self): ''' Test attach action ''' - with qubesmgmt.tests.tools.StderrBuffer() as stderr: + with qubesadmin.tests.tools.StderrBuffer() as stderr: with self.assertRaises(SystemExit): - qubesmgmt.tools.qvm_device.main( + qubesadmin.tools.qvm_device.main( ['test', 'attach', '-p', 'test-vm2', 'test-vm1:invalid'], app=self.app) self.assertIn('doesn\'t expose device', @@ -174,9 +174,9 @@ class TC_00_qvm_device(qubesmgmt.tests.QubesTestCase): def test_014_attach_invalid3(self): ''' Test attach action ''' - with qubesmgmt.tests.tools.StderrBuffer() as stderr: + with qubesadmin.tests.tools.StderrBuffer() as stderr: with self.assertRaises(SystemExit): - qubesmgmt.tools.qvm_device.main( + qubesadmin.tools.qvm_device.main( ['test', 'attach', '-p', 'test-vm2', 'no-such-vm:dev3'], app=self.app) self.assertIn('no backend vm', @@ -187,7 +187,7 @@ class TC_00_qvm_device(qubesmgmt.tests.QubesTestCase): ''' Test detach action ''' self.app.expected_calls[('test-vm2', 'mgmt.vm.device.test.Detach', 'test-vm1+dev1', None)] = b'0\0' - qubesmgmt.tools.qvm_device.main( + qubesadmin.tools.qvm_device.main( ['test', 'detach', 'test-vm2', 'test-vm1:dev1'], app=self.app) self.assertAllCalled() @@ -195,7 +195,7 @@ class TC_00_qvm_device(qubesmgmt.tests.QubesTestCase): ''' Test detach action ''' self.app.expected_calls[('test-vm2', 'mgmt.vm.device.test.Detach', 'test-vm1+dev7', None)] = b'0\0' - qubesmgmt.tools.qvm_device.main( + qubesadmin.tools.qvm_device.main( ['test', 'detach', 'test-vm2', 'test-vm1:dev7'], app=self.app) self.assertAllCalled() diff --git a/qubesmgmt/tests/tools/qvm_features.py b/qubesadmin/tests/tools/qvm_features.py similarity index 84% rename from qubesmgmt/tests/tools/qvm_features.py rename to qubesadmin/tests/tools/qvm_features.py index 2961f80..70ff92b 100644 --- a/qubesmgmt/tests/tools/qvm_features.py +++ b/qubesadmin/tests/tools/qvm_features.py @@ -18,11 +18,11 @@ # You should have received a copy of the GNU Lesser General Public License along # with this program; if not, see . -import qubesmgmt.tests -import qubesmgmt.tools.qvm_features +import qubesadmin.tests +import qubesadmin.tools.qvm_features -class TC_00_qvm_features(qubesmgmt.tests.QubesTestCase): +class TC_00_qvm_features(qubesadmin.tests.QubesTestCase): def test_000_list(self): self.app.expected_calls[ ('dom0', 'mgmt.vm.List', None, None)] = \ @@ -36,9 +36,9 @@ class TC_00_qvm_features(qubesmgmt.tests.QubesTestCase): self.app.expected_calls[ ('some-vm', 'mgmt.vm.feature.Get', 'feature2', None)] = \ b'0\x00value2 with spaces' - with qubesmgmt.tests.tools.StdoutBuffer() as stdout: + with qubesadmin.tests.tools.StdoutBuffer() as stdout: self.assertEqual( - qubesmgmt.tools.qvm_features.main(['some-vm'], app=self.app), + qubesadmin.tools.qvm_features.main(['some-vm'], app=self.app), 0) self.assertEqual(stdout.getvalue(), 'feature1 value1\n' @@ -53,7 +53,7 @@ class TC_00_qvm_features(qubesmgmt.tests.QubesTestCase): ('some-vm', 'mgmt.vm.feature.Set', 'feature3', 'value of feature')] = b'0\x00' self.assertEqual( - qubesmgmt.tools.qvm_features.main(['some-vm', 'feature3', + qubesadmin.tools.qvm_features.main(['some-vm', 'feature3', 'value of feature'], app=self.app), 0) @@ -66,9 +66,9 @@ class TC_00_qvm_features(qubesmgmt.tests.QubesTestCase): self.app.expected_calls[ ('some-vm', 'mgmt.vm.feature.Get', 'feature3', None)] = \ b'0\x00value2 with spaces' - with qubesmgmt.tests.tools.StdoutBuffer() as stdout: + with qubesadmin.tests.tools.StdoutBuffer() as stdout: self.assertEqual( - qubesmgmt.tools.qvm_features.main(['some-vm', 'feature3'], + qubesadmin.tools.qvm_features.main(['some-vm', 'feature3'], app=self.app), 0) self.assertEqual(stdout.getvalue(), @@ -82,9 +82,9 @@ class TC_00_qvm_features(qubesmgmt.tests.QubesTestCase): self.app.expected_calls[ ('some-vm', 'mgmt.vm.feature.Remove', 'feature4', None)] = \ b'0\x00' - with qubesmgmt.tests.tools.StdoutBuffer() as stdout: + with qubesadmin.tests.tools.StdoutBuffer() as stdout: self.assertEqual( - qubesmgmt.tools.qvm_features.main(['--unset', 'some-vm', + qubesadmin.tools.qvm_features.main(['--unset', 'some-vm', 'feature4'], app=self.app), 0) @@ -101,9 +101,9 @@ class TC_00_qvm_features(qubesmgmt.tests.QubesTestCase): self.app.expected_calls[ ('some-vm', 'mgmt.vm.List', None, None)] = \ b'0\x00some-vm class=AppVM state=Running\n' - with qubesmgmt.tests.tools.StdoutBuffer() as stdout: + with qubesadmin.tests.tools.StdoutBuffer() as stdout: self.assertEqual( - qubesmgmt.tools.qvm_check.main(['--running', + qubesadmin.tools.qvm_check.main(['--running', 'some-vm'], app=self.app), 0) self.assertEqual(stdout.getvalue(), @@ -122,9 +122,9 @@ class TC_00_qvm_features(qubesmgmt.tests.QubesTestCase): self.app.expected_calls[ ('some-vm2', 'mgmt.vm.List', None, None)] = \ b'0\x00some-vm2 class=AppVM state=Running\n' - with qubesmgmt.tests.tools.StdoutBuffer() as stdout: + with qubesadmin.tests.tools.StdoutBuffer() as stdout: self.assertEqual( - qubesmgmt.tools.qvm_check.main(['--running', + qubesadmin.tools.qvm_check.main(['--running', 'some-vm', 'some-vm2'], app=self.app), 0) @@ -147,9 +147,9 @@ class TC_00_qvm_features(qubesmgmt.tests.QubesTestCase): self.app.expected_calls[ ('some-vm3', 'mgmt.vm.List', None, None)] = \ b'0\x00some-vm3 class=AppVM state=Halted\n' - with qubesmgmt.tests.tools.StdoutBuffer() as stdout: + with qubesadmin.tests.tools.StdoutBuffer() as stdout: self.assertEqual( - qubesmgmt.tools.qvm_check.main(['--running', + qubesadmin.tools.qvm_check.main(['--running', '--all'], app=self.app), 0) @@ -166,9 +166,9 @@ class TC_00_qvm_features(qubesmgmt.tests.QubesTestCase): self.app.expected_calls[ ('some-vm3', 'mgmt.vm.List', None, None)] = \ b'0\x00some-vm3 class=AppVM state=Halted\n' - with qubesmgmt.tests.tools.StdoutBuffer() as stdout: + with qubesadmin.tests.tools.StdoutBuffer() as stdout: self.assertEqual( - qubesmgmt.tools.qvm_check.main(['--running', + qubesadmin.tools.qvm_check.main(['--running', 'some-vm3'], app=self.app), 1) @@ -185,9 +185,9 @@ class TC_00_qvm_features(qubesmgmt.tests.QubesTestCase): self.app.expected_calls[ ('some-vm2', 'mgmt.vm.List', None, None)] = \ b'0\x00some-vm2 class=AppVM state=Paused\n' - with qubesmgmt.tests.tools.StdoutBuffer() as stdout: + with qubesadmin.tests.tools.StdoutBuffer() as stdout: self.assertEqual( - qubesmgmt.tools.qvm_check.main(['--paused', + qubesadmin.tools.qvm_check.main(['--paused', 'some-vm2'], app=self.app), 0) @@ -207,9 +207,9 @@ class TC_00_qvm_features(qubesmgmt.tests.QubesTestCase): self.app.expected_calls[ ('some-vm', 'mgmt.vm.List', None, None)] = \ b'0\x00some-vm class=AppVM state=Running\n' - with qubesmgmt.tests.tools.StdoutBuffer() as stdout: + with qubesadmin.tests.tools.StdoutBuffer() as stdout: self.assertEqual( - qubesmgmt.tools.qvm_check.main(['--paused', + qubesadmin.tools.qvm_check.main(['--paused', 'some-vm2', 'some-vm'], app=self.app), 0) @@ -224,9 +224,9 @@ class TC_00_qvm_features(qubesmgmt.tests.QubesTestCase): b'0\x00some-vm class=AppVM state=Running\n' \ b'some-vm2 class=AppVM state=Paused\n' \ b'some-vm3 class=TemplateVM state=Halted\n' - with qubesmgmt.tests.tools.StdoutBuffer() as stdout: + with qubesadmin.tests.tools.StdoutBuffer() as stdout: self.assertEqual( - qubesmgmt.tools.qvm_check.main(['--template', + qubesadmin.tools.qvm_check.main(['--template', 'some-vm3'], app=self.app), 0) @@ -240,9 +240,9 @@ class TC_00_qvm_features(qubesmgmt.tests.QubesTestCase): b'0\x00some-vm class=AppVM state=Running\n' \ b'some-vm2 class=AppVM state=Paused\n' \ b'some-vm3 class=TemplateVM state=Halted\n' - with qubesmgmt.tests.tools.StdoutBuffer() as stdout: + with qubesadmin.tests.tools.StdoutBuffer() as stdout: self.assertEqual( - qubesmgmt.tools.qvm_check.main(['--template', + qubesadmin.tools.qvm_check.main(['--template', 'some-vm2', 'some-vm3'], app=self.app), 0) diff --git a/qubesmgmt/tests/tools/qvm_firewall.py b/qubesadmin/tests/tools/qvm_firewall.py similarity index 84% rename from qubesmgmt/tests/tools/qvm_firewall.py rename to qubesadmin/tests/tools/qvm_firewall.py index bcd6aa4..30353c1 100644 --- a/qubesmgmt/tests/tools/qvm_firewall.py +++ b/qubesadmin/tests/tools/qvm_firewall.py @@ -22,30 +22,30 @@ import argparse -import qubesmgmt.firewall -import qubesmgmt.tests -import qubesmgmt.tests.tools -import qubesmgmt.tools.qvm_firewall +import qubesadmin.firewall +import qubesadmin.tests +import qubesadmin.tests.tools +import qubesadmin.tools.qvm_firewall -class TC_00_RuleAction(qubesmgmt.tests.QubesTestCase): +class TC_00_RuleAction(qubesadmin.tests.QubesTestCase): def setUp(self): super(TC_00_RuleAction, self).setUp() - self.action = qubesmgmt.tools.qvm_firewall.RuleAction( + self.action = qubesadmin.tools.qvm_firewall.RuleAction( None, dest='rule') def test_000_named_opts(self): ns = argparse.Namespace() self.action(None, ns, ['dsthost=127.0.0.1', 'action=accept']) self.assertEqual(ns.rule, - qubesmgmt.firewall.Rule( + qubesadmin.firewall.Rule( None, action='accept', dsthost='127.0.0.1/32')) def test_001_unnamed_opts(self): ns = argparse.Namespace() self.action(None, ns, ['accept', '127.0.0.1', 'tcp', '80']) self.assertEqual(ns.rule, - qubesmgmt.firewall.Rule( + qubesadmin.firewall.Rule( None, action='accept', dsthost='127.0.0.1/32', proto='tcp', dstports=80)) @@ -53,7 +53,7 @@ class TC_00_RuleAction(qubesmgmt.tests.QubesTestCase): ns = argparse.Namespace() self.action(None, ns, ['accept', '127.0.0.1', 'icmp', '8']) self.assertEqual(ns.rule, - qubesmgmt.firewall.Rule( + qubesadmin.firewall.Rule( None, action='accept', dsthost='127.0.0.1/32', proto='icmp', icmptype=8)) @@ -62,12 +62,12 @@ class TC_00_RuleAction(qubesmgmt.tests.QubesTestCase): self.action(None, ns, ['dsthost=127.0.0.1', 'accept', 'dstports=443', 'tcp']) self.assertEqual(ns.rule, - qubesmgmt.firewall.Rule( + qubesadmin.firewall.Rule( None, action='accept', dsthost='127.0.0.1/32', proto='tcp', dstports=443)) -class TC_10_qvm_firewall(qubesmgmt.tests.QubesTestCase): +class TC_10_qvm_firewall(qubesadmin.tests.QubesTestCase): def setUp(self): super(TC_10_qvm_firewall, self).setUp() self.app.expected_calls[('dom0', 'mgmt.vm.List', None, None)] = \ @@ -78,8 +78,8 @@ class TC_10_qvm_firewall(qubesmgmt.tests.QubesTestCase): None, None)] = \ b'0\0action=accept dsthost=qubes-os.org\n' \ b'action=drop proto=icmp\n' - with qubesmgmt.tests.tools.StdoutBuffer() as stdout: - qubesmgmt.tools.qvm_firewall.main(['test-vm', 'list'], app=self.app) + with qubesadmin.tests.tools.StdoutBuffer() as stdout: + qubesadmin.tools.qvm_firewall.main(['test-vm', 'list'], app=self.app) self.assertEqual( [l.strip() for l in stdout.getvalue().splitlines()], ['NO ACTION HOST PROTOCOL PORT(S) SPECIAL ' @@ -97,8 +97,8 @@ class TC_10_qvm_firewall(qubesmgmt.tests.QubesTestCase): b'dstports=443-443\n' \ b'action=drop proto=icmp icmptype=8\n' \ b'action=accept specialtarget=dns comment=Allow DNS\n' - with qubesmgmt.tests.tools.StdoutBuffer() as stdout: - qubesmgmt.tools.qvm_firewall.main(['test-vm', 'list'], app=self.app) + with qubesadmin.tests.tools.StdoutBuffer() as stdout: + qubesadmin.tools.qvm_firewall.main(['test-vm', 'list'], app=self.app) self.assertEqual( [l.strip() for l in stdout.getvalue().splitlines()], ['NO ACTION HOST PROTOCOL PORT(S) SPECIAL ' @@ -116,8 +116,8 @@ class TC_10_qvm_firewall(qubesmgmt.tests.QubesTestCase): None, None)] = \ b'0\0action=accept dsthost=qubes-os.org\n' \ b'action=drop proto=icmp\n' - with qubesmgmt.tests.tools.StdoutBuffer() as stdout: - qubesmgmt.tools.qvm_firewall.main(['test-vm', '--raw', 'list'], + with qubesadmin.tests.tools.StdoutBuffer() as stdout: + qubesadmin.tools.qvm_firewall.main(['test-vm', '--raw', 'list'], app=self.app) self.assertEqual( [l.strip() for l in stdout.getvalue().splitlines()], @@ -132,8 +132,8 @@ class TC_10_qvm_firewall(qubesmgmt.tests.QubesTestCase): b'action=drop proto=icmp\n' self.app.expected_calls[('test-vm', 'mgmt.vm.firewall.Reload', None, None)] = b'0\0' - with qubesmgmt.tests.tools.StdoutBuffer() as stdout: - qubesmgmt.tools.qvm_firewall.main( + with qubesadmin.tests.tools.StdoutBuffer() as stdout: + qubesadmin.tools.qvm_firewall.main( ['test-vm', '--raw', '--reload', 'list'], app=self.app) self.assertEqual( @@ -152,7 +152,7 @@ class TC_10_qvm_firewall(qubesmgmt.tests.QubesTestCase): b'action=drop proto=icmp\n' b'action=accept dst4=192.168.0.0/24 comment=Allow LAN\n')] = \ b'0\0' - qubesmgmt.tools.qvm_firewall.main( + qubesadmin.tools.qvm_firewall.main( ['test-vm', 'add', 'accept', '192.168.0.0/24', 'comment=Allow LAN'], app=self.app ) @@ -166,7 +166,7 @@ class TC_10_qvm_firewall(qubesmgmt.tests.QubesTestCase): b'action=accept dsthost=qubes-os.org\n' b'action=accept dst4=192.168.0.0/24 comment=Allow LAN\n' b'action=drop proto=icmp\n')] = b'0\0' - qubesmgmt.tools.qvm_firewall.main( + qubesadmin.tools.qvm_firewall.main( ['test-vm', 'add', '--before', '1', 'accept', '192.168.0.0/24', 'comment=Allow LAN'], app=self.app @@ -179,7 +179,7 @@ class TC_10_qvm_firewall(qubesmgmt.tests.QubesTestCase): b'action=drop proto=icmp\n' self.app.expected_calls[('test-vm', 'mgmt.vm.firewall.Set', None, b'action=accept dsthost=qubes-os.org\n')] = b'0\0' - qubesmgmt.tools.qvm_firewall.main( + qubesadmin.tools.qvm_firewall.main( ['test-vm', 'del', '--rule-no', '1'], app=self.app ) @@ -191,7 +191,7 @@ class TC_10_qvm_firewall(qubesmgmt.tests.QubesTestCase): b'action=drop proto=icmp\n' self.app.expected_calls[('test-vm', 'mgmt.vm.firewall.Set', None, b'action=accept dsthost=qubes-os.org\n')] = b'0\0' - qubesmgmt.tools.qvm_firewall.main( + qubesadmin.tools.qvm_firewall.main( ['test-vm', 'del', 'drop', 'proto=icmp'], app=self.app ) @@ -199,8 +199,8 @@ class TC_10_qvm_firewall(qubesmgmt.tests.QubesTestCase): def test_030_policy_get(self): self.app.expected_calls[('test-vm', 'mgmt.vm.firewall.GetPolicy', None, None)] = b'0\0accept' - with qubesmgmt.tests.tools.StdoutBuffer() as stdout: - qubesmgmt.tools.qvm_firewall.main( + with qubesadmin.tests.tools.StdoutBuffer() as stdout: + qubesadmin.tools.qvm_firewall.main( ['test-vm', 'policy'], app=self.app ) @@ -209,8 +209,8 @@ class TC_10_qvm_firewall(qubesmgmt.tests.QubesTestCase): def test_031_policy_set(self): self.app.expected_calls[('test-vm', 'mgmt.vm.firewall.SetPolicy', None, b'accept')] = b'0\0' - with qubesmgmt.tests.tools.StdoutBuffer() as stdout: - qubesmgmt.tools.qvm_firewall.main( + with qubesadmin.tests.tools.StdoutBuffer() as stdout: + qubesadmin.tools.qvm_firewall.main( ['test-vm', 'policy', 'accept'], app=self.app ) diff --git a/qubesmgmt/tests/tools/qvm_kill.py b/qubesadmin/tests/tools/qvm_kill.py similarity index 79% rename from qubesmgmt/tests/tools/qvm_kill.py rename to qubesadmin/tests/tools/qvm_kill.py index 5e03ecd..c7bd5d5 100644 --- a/qubesmgmt/tests/tools/qvm_kill.py +++ b/qubesadmin/tests/tools/qvm_kill.py @@ -18,25 +18,25 @@ # You should have received a copy of the GNU Lesser General Public License along # with this program; if not, see . -import qubesmgmt.tests -import qubesmgmt.tests.tools -import qubesmgmt.tools.qvm_kill +import qubesadmin.tests +import qubesadmin.tests.tools +import qubesadmin.tools.qvm_kill -class TC_00_qvm_kill(qubesmgmt.tests.QubesTestCase): +class TC_00_qvm_kill(qubesadmin.tests.QubesTestCase): def test_000_with_vm(self): self.app.expected_calls[ ('dom0', 'mgmt.vm.List', None, None)] = \ b'0\x00some-vm class=AppVM state=Running\n' self.app.expected_calls[ ('some-vm', 'mgmt.vm.Kill', None, None)] = b'0\x00' - qubesmgmt.tools.qvm_kill.main(['some-vm'], app=self.app) + qubesadmin.tools.qvm_kill.main(['some-vm'], app=self.app) self.assertAllCalled() def test_001_missing_vm(self): with self.assertRaises(SystemExit): - with qubesmgmt.tests.tools.StderrBuffer() as stderr: - qubesmgmt.tools.qvm_kill.main([], app=self.app) + with qubesadmin.tests.tools.StderrBuffer() as stderr: + qubesadmin.tools.qvm_kill.main([], app=self.app) self.assertIn('one of the arguments --all VMNAME is required', stderr.getvalue()) self.assertAllCalled() @@ -46,8 +46,8 @@ class TC_00_qvm_kill(qubesmgmt.tests.QubesTestCase): ('dom0', 'mgmt.vm.List', None, None)] = \ b'0\x00some-vm class=AppVM state=Running\n' with self.assertRaises(SystemExit): - with qubesmgmt.tests.tools.StderrBuffer() as stderr: - qubesmgmt.tools.qvm_kill.main(['no-such-vm'], app=self.app) + with qubesadmin.tests.tools.StderrBuffer() as stderr: + qubesadmin.tools.qvm_kill.main(['no-such-vm'], app=self.app) self.assertIn('no such domain', stderr.getvalue()) self.assertAllCalled() @@ -61,7 +61,7 @@ class TC_00_qvm_kill(qubesmgmt.tests.QubesTestCase): ('dom0', 'mgmt.vm.List', None, None)] = \ b'0\x00some-vm class=AppVM state=Halted\n' self.assertEqual( - qubesmgmt.tools.qvm_kill.main(['some-vm'], app=self.app), + qubesadmin.tools.qvm_kill.main(['some-vm'], app=self.app), 1) self.assertAllCalled() diff --git a/qubesmgmt/tests/tools/qvm_ls.py b/qubesadmin/tests/tools/qvm_ls.py similarity index 82% rename from qubesmgmt/tests/tools/qvm_ls.py rename to qubesadmin/tests/tools/qvm_ls.py index 2e2ab52..42a24da 100644 --- a/qubesmgmt/tests/tools/qvm_ls.py +++ b/qubesadmin/tests/tools/qvm_ls.py @@ -20,14 +20,14 @@ # with this program; if not, see . import unittest -import qubesmgmt -import qubesmgmt.vm -import qubesmgmt.tools.qvm_ls +import qubesadmin +import qubesadmin.vm +import qubesadmin.tools.qvm_ls -import qubesmgmt.tests -import qubesmgmt.tests.tools +import qubesadmin.tests +import qubesadmin.tests.tools -from qubesmgmt.tests import TestVM, TestVMCollection +from qubesadmin.tests import TestVM, TestVMCollection class TestApp(object): @@ -39,21 +39,21 @@ class TestApp(object): ] ) -class TC_00_Column(qubesmgmt.tests.QubesTestCase): +class TC_00_Column(qubesadmin.tests.QubesTestCase): def test_100_init(self): try: - testcolumn = qubesmgmt.tools.qvm_ls.Column('TESTCOLUMN') + testcolumn = qubesadmin.tools.qvm_ls.Column('TESTCOLUMN') self.assertEqual(testcolumn.ls_head, 'TESTCOLUMN') finally: try: - qubesmgmt.tools.qvm_ls.Column.columns['TESTCOLUMN'] + qubesadmin.tools.qvm_ls.Column.columns['TESTCOLUMN'] except KeyError: pass -class TC_10_globals(qubesmgmt.tests.QubesTestCase): +class TC_10_globals(qubesadmin.tests.QubesTestCase): def test_100_simple_flag(self): - flag = qubesmgmt.tools.qvm_ls.simple_flag(1, 'T', 'internal') + flag = qubesadmin.tools.qvm_ls.simple_flag(1, 'T', 'internal') # TODO after serious testing of QubesVM and Qubes app, this should be # using normal components @@ -65,12 +65,12 @@ class TC_10_globals(qubesmgmt.tests.QubesTestCase): @unittest.skip('column list generated dynamically') def test_900_formats_columns(self): - for fmt in qubesmgmt.tools.qvm_ls.formats: - for col in qubesmgmt.tools.qvm_ls.formats[fmt]: - self.assertIn(col.upper(), qubesmgmt.tools.qvm_ls.Column.columns) + for fmt in qubesadmin.tools.qvm_ls.formats: + for col in qubesadmin.tools.qvm_ls.formats[fmt]: + self.assertIn(col.upper(), qubesadmin.tools.qvm_ls.Column.columns) -class TC_50_List(qubesmgmt.tests.QubesTestCase): +class TC_50_List(qubesadmin.tests.QubesTestCase): def test_100_list_with_status(self): app = TestApp() app.domains['test-vm'].internal = False @@ -79,15 +79,15 @@ class TC_50_List(qubesmgmt.tests.QubesTestCase): app.domains['test-vm'].netvm = TestVM('sys-net') app.domains['test-vm'].label = 'green' app.domains['dom0'].label = 'black' - with qubesmgmt.tests.tools.StdoutBuffer() as stdout: - qubesmgmt.tools.qvm_ls.main([], app=app) + with qubesadmin.tests.tools.StdoutBuffer() as stdout: + qubesadmin.tools.qvm_ls.main([], app=app) self.assertEqual(stdout.getvalue(), 'NAME STATUS LABEL TEMPLATE NETVM\n' 'dom0 -r------ black - -\n' 'test-vm -r------ green template sys-net\n') -class TC_90_List_with_qubesd_calls(qubesmgmt.tests.QubesTestCase): +class TC_90_List_with_qubesd_calls(qubesadmin.tests.QubesTestCase): def test_100_list_with_status(self): self.app.expected_calls[ ('dom0', 'mgmt.vm.List', None, None)] = \ @@ -143,8 +143,8 @@ class TC_90_List_with_qubesd_calls(qubesmgmt.tests.QubesTestCase): ('sys-net', 'mgmt.vm.property.Get', key, None)] = \ b'0\x00default=True ' + value - with qubesmgmt.tests.tools.StdoutBuffer() as stdout: - qubesmgmt.tools.qvm_ls.main([], app=self.app) + with qubesadmin.tests.tools.StdoutBuffer() as stdout: + qubesadmin.tools.qvm_ls.main([], app=self.app) self.assertEqual(stdout.getvalue(), 'NAME STATUS LABEL TEMPLATE NETVM\n' 'sys-net ar-N---- red template1 sys-net\n' diff --git a/qubesmgmt/tests/tools/qvm_pause.py b/qubesadmin/tests/tools/qvm_pause.py similarity index 81% rename from qubesmgmt/tests/tools/qvm_pause.py rename to qubesadmin/tests/tools/qvm_pause.py index 25f3ec2..006a4fb 100644 --- a/qubesmgmt/tests/tools/qvm_pause.py +++ b/qubesadmin/tests/tools/qvm_pause.py @@ -18,25 +18,25 @@ # You should have received a copy of the GNU Lesser General Public License along # with this program; if not, see . -import qubesmgmt.tests -import qubesmgmt.tests.tools -import qubesmgmt.tools.qvm_pause +import qubesadmin.tests +import qubesadmin.tests.tools +import qubesadmin.tools.qvm_pause -class TC_00_qvm_pause(qubesmgmt.tests.QubesTestCase): +class TC_00_qvm_pause(qubesadmin.tests.QubesTestCase): def test_000_with_vm(self): self.app.expected_calls[ ('dom0', 'mgmt.vm.List', None, None)] = \ b'0\x00some-vm class=AppVM state=Running\n' self.app.expected_calls[ ('some-vm', 'mgmt.vm.Pause', None, None)] = b'0\x00' - qubesmgmt.tools.qvm_pause.main(['some-vm'], app=self.app) + qubesadmin.tools.qvm_pause.main(['some-vm'], app=self.app) self.assertAllCalled() def test_001_missing_vm(self): with self.assertRaises(SystemExit): - with qubesmgmt.tests.tools.StderrBuffer() as stderr: - qubesmgmt.tools.qvm_pause.main([], app=self.app) + with qubesadmin.tests.tools.StderrBuffer() as stderr: + qubesadmin.tools.qvm_pause.main([], app=self.app) self.assertIn('one of the arguments --all VMNAME is required', stderr.getvalue()) self.assertAllCalled() @@ -46,8 +46,8 @@ class TC_00_qvm_pause(qubesmgmt.tests.QubesTestCase): ('dom0', 'mgmt.vm.List', None, None)] = \ b'0\x00some-vm class=AppVM state=Running\n' with self.assertRaises(SystemExit): - with qubesmgmt.tests.tools.StderrBuffer() as stderr: - qubesmgmt.tools.qvm_pause.main(['no-such-vm'], app=self.app) + with qubesadmin.tests.tools.StderrBuffer() as stderr: + qubesadmin.tools.qvm_pause.main(['no-such-vm'], app=self.app) self.assertIn('no such domain', stderr.getvalue()) self.assertAllCalled() @@ -61,7 +61,7 @@ class TC_00_qvm_pause(qubesmgmt.tests.QubesTestCase): ('dom0', 'mgmt.vm.List', None, None)] = \ b'0\x00some-vm class=AppVM state=Halted\n' self.assertEqual( - qubesmgmt.tools.qvm_pause.main(['some-vm'], app=self.app), + qubesadmin.tools.qvm_pause.main(['some-vm'], app=self.app), 1) self.assertAllCalled() @@ -77,7 +77,7 @@ class TC_00_qvm_pause(qubesmgmt.tests.QubesTestCase): b'0\x00some-vm class=AppVM state=Running\n' \ b'other-vm class=AppVM state=Running\n' self.assertEqual( - qubesmgmt.tools.qvm_pause.main(['some-vm', 'other-vm'], + qubesadmin.tools.qvm_pause.main(['some-vm', 'other-vm'], app=self.app), 0) self.assertAllCalled() diff --git a/qubesmgmt/tests/tools/qvm_pool.py b/qubesadmin/tests/tools/qvm_pool.py similarity index 83% rename from qubesmgmt/tests/tools/qvm_pool.py rename to qubesadmin/tests/tools/qvm_pool.py index d29bf55..4fc9291 100644 --- a/qubesmgmt/tests/tools/qvm_pool.py +++ b/qubesadmin/tests/tools/qvm_pool.py @@ -18,12 +18,12 @@ # You should have received a copy of the GNU Lesser General Public License along # with this program; if not, see . -import qubesmgmt.tests -import qubesmgmt.tests.tools -import qubesmgmt.tools.qvm_pool +import qubesadmin.tests +import qubesadmin.tests.tools +import qubesadmin.tools.qvm_pool -class TC_00_qvm_pool(qubesmgmt.tests.QubesTestCase): +class TC_00_qvm_pool(qubesadmin.tests.QubesTestCase): def test_000_list(self): self.app.expected_calls[('dom0', 'mgmt.pool.List', None, None)] = \ b'0\x00pool-file\npool-lvm\n' @@ -33,9 +33,9 @@ class TC_00_qvm_pool(qubesmgmt.tests.QubesTestCase): self.app.expected_calls[ ('dom0', 'mgmt.pool.Info', 'pool-lvm', None)] = \ b'0\x00driver=lvm\nvolume_group=qubes_dom0\nthin_pool=pool00\n' - with qubesmgmt.tests.tools.StdoutBuffer() as stdout: + with qubesadmin.tests.tools.StdoutBuffer() as stdout: self.assertEqual(0, - qubesmgmt.tools.qvm_pool.main(['-l'], app=self.app)) + qubesadmin.tools.qvm_pool.main(['-l'], app=self.app)) self.assertEqual(stdout.getvalue(), 'NAME DRIVER\n' 'pool-file file\n' @@ -47,9 +47,9 @@ class TC_00_qvm_pool(qubesmgmt.tests.QubesTestCase): ('dom0', 'mgmt.pool.ListDrivers', None, None)] = \ b'0\x00file dir_path revisions_to_keep\n' \ b'lvm volume_group thin_pool revisions_to_keep\n' - with qubesmgmt.tests.tools.StdoutBuffer() as stdout: + with qubesadmin.tests.tools.StdoutBuffer() as stdout: self.assertEqual(0, - qubesmgmt.tools.qvm_pool.main(['--help-drivers'], app=self.app)) + qubesadmin.tools.qvm_pool.main(['--help-drivers'], app=self.app)) self.assertEqual(stdout.getvalue(), 'DRIVER OPTIONS\n' 'file dir_path, revisions_to_keep\n' @@ -62,7 +62,7 @@ class TC_00_qvm_pool(qubesmgmt.tests.QubesTestCase): ('dom0', 'mgmt.pool.Add', 'file', b'name=test-pool\ndir_path=/some/path\n')] = b'0\x00' self.assertEqual(0, - qubesmgmt.tools.qvm_pool.main( + qubesadmin.tools.qvm_pool.main( ['--add', 'test-pool', 'file', '-o', 'dir_path=/some/path'], app=self.app)) self.assertAllCalled() @@ -71,7 +71,7 @@ class TC_00_qvm_pool(qubesmgmt.tests.QubesTestCase): self.app.expected_calls[ ('dom0', 'mgmt.pool.Remove', 'test-pool', None)] = b'0\x00' self.assertEqual(0, - qubesmgmt.tools.qvm_pool.main(['--remove', 'test-pool'], + qubesadmin.tools.qvm_pool.main(['--remove', 'test-pool'], app=self.app)) self.assertAllCalled() @@ -81,9 +81,9 @@ class TC_00_qvm_pool(qubesmgmt.tests.QubesTestCase): self.app.expected_calls[ ('dom0', 'mgmt.pool.Info', 'pool-lvm', None)] = \ b'0\x00driver=lvm\nvolume_group=qubes_dom0\nthin_pool=pool00\n' - with qubesmgmt.tests.tools.StdoutBuffer() as stdout: + with qubesadmin.tests.tools.StdoutBuffer() as stdout: self.assertEqual(0, - qubesmgmt.tools.qvm_pool.main(['-i', 'pool-lvm'], + qubesadmin.tools.qvm_pool.main(['-i', 'pool-lvm'], app=self.app)) self.assertEqual(stdout.getvalue(), 'name pool-lvm\n' diff --git a/qubesmgmt/tests/tools/qvm_prefs.py b/qubesadmin/tests/tools/qvm_prefs.py similarity index 83% rename from qubesmgmt/tests/tools/qvm_prefs.py rename to qubesadmin/tests/tools/qvm_prefs.py index cfcc919..bcde372 100644 --- a/qubesmgmt/tests/tools/qvm_prefs.py +++ b/qubesadmin/tests/tools/qvm_prefs.py @@ -19,12 +19,12 @@ # with this program; if not, see . import sys -import qubesmgmt.tests -import qubesmgmt.tests.tools -import qubesmgmt.tools.qvm_prefs +import qubesadmin.tests +import qubesadmin.tests.tools +import qubesadmin.tools.qvm_prefs -class TC_00_qvm_prefs(qubesmgmt.tests.QubesTestCase): +class TC_00_qvm_prefs(qubesadmin.tests.QubesTestCase): def test_000_list(self): self.app.expected_calls[ ('dom0', 'mgmt.vm.List', None, None)] = \ @@ -38,8 +38,8 @@ class TC_00_qvm_prefs(qubesmgmt.tests.QubesTestCase): self.app.expected_calls[ ('dom0', 'mgmt.vm.property.Get', 'prop2', None)] = \ b'0\x00default=False type=str value2' - with qubesmgmt.tests.tools.StdoutBuffer() as stdout: - self.assertEqual(0, qubesmgmt.tools.qvm_prefs.main([ + with qubesadmin.tests.tools.StdoutBuffer() as stdout: + self.assertEqual(0, qubesadmin.tools.qvm_prefs.main([ 'dom0'], app=self.app)) self.assertEqual(stdout.getvalue(), 'prop1 D value1\n' @@ -48,8 +48,8 @@ class TC_00_qvm_prefs(qubesmgmt.tests.QubesTestCase): def test_001_no_vm(self): with self.assertRaises(SystemExit): - with qubesmgmt.tests.tools.StderrBuffer() as stderr: - qubesmgmt.tools.qvm_prefs.main([], app=self.app) + with qubesadmin.tests.tools.StderrBuffer() as stderr: + qubesadmin.tools.qvm_prefs.main([], app=self.app) if sys.version_info[0] == 2: self.assertIn('too few arguments', stderr.getvalue()) else: @@ -64,7 +64,7 @@ class TC_00_qvm_prefs(qubesmgmt.tests.QubesTestCase): self.app.expected_calls[ ('dom0', 'mgmt.vm.property.Set', 'default_user', b'testuser')] = \ b'0\x00' - self.assertEqual(0, qubesmgmt.tools.qvm_prefs.main([ + self.assertEqual(0, qubesadmin.tools.qvm_prefs.main([ 'dom0', 'default_user', 'testuser'], app=self.app)) self.assertAllCalled() @@ -76,8 +76,8 @@ class TC_00_qvm_prefs(qubesmgmt.tests.QubesTestCase): ('dom0', 'mgmt.vm.property.Get', 'no_such_property', None)] = \ b'2\x00AttributeError\x00\x00no_such_property\x00' with self.assertRaises(SystemExit): - with qubesmgmt.tests.tools.StderrBuffer() as stderr: - qubesmgmt.tools.qvm_prefs.main([ + with qubesadmin.tests.tools.StderrBuffer() as stderr: + qubesadmin.tools.qvm_prefs.main([ 'dom0', 'no_such_property'], app=self.app) self.assertIn('no such property: \'no_such_property\'', stderr.getvalue()) @@ -91,8 +91,8 @@ class TC_00_qvm_prefs(qubesmgmt.tests.QubesTestCase): ('dom0', 'mgmt.vm.property.Set', 'no_such_property', b'value')] = \ b'2\x00AttributeError\x00\x00no_such_property\x00' with self.assertRaises(SystemExit): - with qubesmgmt.tests.tools.StderrBuffer() as stderr: - qubesmgmt.tools.qvm_prefs.main([ + with qubesadmin.tests.tools.StderrBuffer() as stderr: + qubesadmin.tools.qvm_prefs.main([ 'dom0', 'no_such_property', 'value'], app=self.app) self.assertIn('no such property: \'no_such_property\'', stderr.getvalue()) diff --git a/qubesmgmt/tests/tools/qvm_remove.py b/qubesadmin/tests/tools/qvm_remove.py similarity index 84% rename from qubesmgmt/tests/tools/qvm_remove.py rename to qubesadmin/tests/tools/qvm_remove.py index 3ede6f4..0e60416 100644 --- a/qubesmgmt/tests/tools/qvm_remove.py +++ b/qubesadmin/tests/tools/qvm_remove.py @@ -18,12 +18,12 @@ # You should have received a copy of the GNU Lesser General Public License along # with this program; if not, see . -import qubesmgmt.tests -import qubesmgmt.tests.tools -import qubesmgmt.tools.qvm_remove +import qubesadmin.tests +import qubesadmin.tests.tools +import qubesadmin.tools.qvm_remove -class TC_00_qvm_remove(qubesmgmt.tests.QubesTestCase): +class TC_00_qvm_remove(qubesadmin.tests.QubesTestCase): def test_000_single(self): self.app.expected_calls[ ('dom0', 'mgmt.vm.List', None, None)] = \ @@ -31,5 +31,5 @@ class TC_00_qvm_remove(qubesmgmt.tests.QubesTestCase): self.app.expected_calls[ ('some-vm', 'mgmt.vm.Remove', None, None)] = \ b'0\x00\n' - qubesmgmt.tools.qvm_remove.main(['some-vm'], app=self.app) + qubesadmin.tools.qvm_remove.main(['some-vm'], app=self.app) self.assertAllCalled() diff --git a/qubesmgmt/tests/tools/qvm_run.py b/qubesadmin/tests/tools/qvm_run.py similarity index 94% rename from qubesmgmt/tests/tools/qvm_run.py rename to qubesadmin/tests/tools/qvm_run.py index be01e1a..f369461 100644 --- a/qubesmgmt/tests/tools/qvm_run.py +++ b/qubesadmin/tests/tools/qvm_run.py @@ -24,11 +24,11 @@ import unittest.mock import subprocess import sys -import qubesmgmt.tests -import qubesmgmt.tools.qvm_run +import qubesadmin.tests +import qubesadmin.tools.qvm_run -class TC_00_qvm_run(qubesmgmt.tests.QubesTestCase): +class TC_00_qvm_run(qubesadmin.tests.QubesTestCase): def setUp(self): if sys.stdout is not sys.__stdout__ or \ sys.stderr is not sys.__stderr__: @@ -41,7 +41,7 @@ class TC_00_qvm_run(qubesmgmt.tests.QubesTestCase): # self.app.expected_calls[ # ('test-vm', 'mgmt.vm.List', None, None)] = \ # b'0\x00test-vm class=AppVM state=Running\n' - ret = qubesmgmt.tools.qvm_run.main(['test-vm', 'command'], app=self.app) + ret = qubesadmin.tools.qvm_run.main(['test-vm', 'command'], app=self.app) self.assertEqual(ret, 0) # make sure we have the same instance below null = self.app.service_calls[0][2]['stdout'] @@ -66,7 +66,7 @@ class TC_00_qvm_run(qubesmgmt.tests.QubesTestCase): # self.app.expected_calls[ # ('test-vm', 'mgmt.vm.List', None, None)] = \ # b'0\x00test-vm class=AppVM state=Running\n' - ret = qubesmgmt.tools.qvm_run.main(['test-vm', 'test-vm2', 'command'], + ret = qubesadmin.tools.qvm_run.main(['test-vm', 'test-vm2', 'command'], app=self.app) self.assertEqual(ret, 0) for i in range(0, len(self.app.service_calls), 2): @@ -106,7 +106,7 @@ class TC_00_qvm_run(qubesmgmt.tests.QubesTestCase): # b'0\x00test-vm class=AppVM state=Running\n' echo = subprocess.Popen(['echo', 'some-data'], stdout=subprocess.PIPE) with unittest.mock.patch('sys.stdin', echo.stdout): - ret = qubesmgmt.tools.qvm_run.main( + ret = qubesadmin.tools.qvm_run.main( ['--pass-io', 'test-vm', 'command'], app=self.app) @@ -134,7 +134,7 @@ class TC_00_qvm_run(qubesmgmt.tests.QubesTestCase): echo = subprocess.Popen(['echo', 'some-data'], stdout=subprocess.PIPE) with unittest.mock.patch('sys.stdin', echo.stdout): with unittest.mock.patch('sys.stdout', stdout): - ret = qubesmgmt.tools.qvm_run.main( + ret = qubesadmin.tools.qvm_run.main( ['--pass-io', 'test-vm', 'command'], app=self.app) @@ -164,7 +164,7 @@ class TC_00_qvm_run(qubesmgmt.tests.QubesTestCase): echo = subprocess.Popen(['echo', 'some-data'], stdout=subprocess.PIPE) with unittest.mock.patch('sys.stdin', echo.stdout): with unittest.mock.patch('sys.stdout', stdout): - ret = qubesmgmt.tools.qvm_run.main( + ret = qubesadmin.tools.qvm_run.main( ['--pass-io', '--no-color-output', 'test-vm', 'command'], app=self.app) @@ -194,7 +194,7 @@ class TC_00_qvm_run(qubesmgmt.tests.QubesTestCase): echo = subprocess.Popen(['echo', 'some-data'], stdout=subprocess.PIPE) with unittest.mock.patch('sys.stdin', echo.stdout): with unittest.mock.patch('sys.stdout', stdout): - ret = qubesmgmt.tools.qvm_run.main( + ret = qubesadmin.tools.qvm_run.main( ['--pass-io', '--no-filter-esc', 'test-vm', 'command'], app=self.app) @@ -220,7 +220,7 @@ class TC_00_qvm_run(qubesmgmt.tests.QubesTestCase): # self.app.expected_calls[ # ('test-vm', 'mgmt.vm.List', None, None)] = \ # b'0\x00test-vm class=AppVM state=Running\n' - ret = qubesmgmt.tools.qvm_run.main( + ret = qubesadmin.tools.qvm_run.main( ['--pass-io', '--localcmd', 'local-command', 'test-vm', 'command'], app=self.app) diff --git a/qubesmgmt/tests/tools/qvm_shutdown.py b/qubesadmin/tests/tools/qvm_shutdown.py similarity index 80% rename from qubesmgmt/tests/tools/qvm_shutdown.py rename to qubesadmin/tests/tools/qvm_shutdown.py index b7ea306..272d9b7 100644 --- a/qubesmgmt/tests/tools/qvm_shutdown.py +++ b/qubesadmin/tests/tools/qvm_shutdown.py @@ -18,24 +18,24 @@ # You should have received a copy of the GNU Lesser General Public License along # with this program; if not, see . -import qubesmgmt.tests -import qubesmgmt.tools.qvm_shutdown +import qubesadmin.tests +import qubesadmin.tools.qvm_shutdown -class TC_00_qvm_shutdown(qubesmgmt.tests.QubesTestCase): +class TC_00_qvm_shutdown(qubesadmin.tests.QubesTestCase): def test_000_with_vm(self): self.app.expected_calls[ ('dom0', 'mgmt.vm.List', None, None)] = \ b'0\x00some-vm class=AppVM state=Running\n' self.app.expected_calls[ ('some-vm', 'mgmt.vm.Shutdown', None, None)] = b'0\x00' - qubesmgmt.tools.qvm_shutdown.main(['some-vm'], app=self.app) + qubesadmin.tools.qvm_shutdown.main(['some-vm'], app=self.app) self.assertAllCalled() def test_001_missing_vm(self): with self.assertRaises(SystemExit): - with qubesmgmt.tests.tools.StderrBuffer() as stderr: - qubesmgmt.tools.qvm_shutdown.main([], app=self.app) + with qubesadmin.tests.tools.StderrBuffer() as stderr: + qubesadmin.tools.qvm_shutdown.main([], app=self.app) self.assertIn('one of the arguments --all VMNAME is required', stderr.getvalue()) self.assertAllCalled() @@ -45,8 +45,8 @@ class TC_00_qvm_shutdown(qubesmgmt.tests.QubesTestCase): ('dom0', 'mgmt.vm.List', None, None)] = \ b'0\x00some-vm class=AppVM state=Running\n' with self.assertRaises(SystemExit): - with qubesmgmt.tests.tools.StderrBuffer() as stderr: - qubesmgmt.tools.qvm_shutdown.main(['no-such-vm'], app=self.app) + with qubesadmin.tests.tools.StderrBuffer() as stderr: + qubesadmin.tools.qvm_shutdown.main(['no-such-vm'], app=self.app) self.assertIn('no such domain', stderr.getvalue()) self.assertAllCalled() @@ -59,7 +59,7 @@ class TC_00_qvm_shutdown(qubesmgmt.tests.QubesTestCase): self.app.expected_calls[ ('dom0', 'mgmt.vm.List', None, None)] = \ b'0\x00some-vm class=AppVM state=Halted\n' - qubesmgmt.tools.qvm_shutdown.main(['some-vm'], app=self.app) + qubesadmin.tools.qvm_shutdown.main(['some-vm'], app=self.app) self.assertAllCalled() def test_004_multiple_vms(self): @@ -73,7 +73,7 @@ class TC_00_qvm_shutdown(qubesmgmt.tests.QubesTestCase): ('dom0', 'mgmt.vm.List', None, None)] = \ b'0\x00some-vm class=AppVM state=Running\n' \ b'other-vm class=AppVM state=Running\n' - qubesmgmt.tools.qvm_shutdown.main(['some-vm', 'other-vm'], app=self.app), + qubesadmin.tools.qvm_shutdown.main(['some-vm', 'other-vm'], app=self.app), self.assertAllCalled() def test_010_wait(self): diff --git a/qubesmgmt/tests/tools/qvm_start.py b/qubesadmin/tests/tools/qvm_start.py similarity index 79% rename from qubesmgmt/tests/tools/qvm_start.py rename to qubesadmin/tests/tools/qvm_start.py index ef15cb9..7b29e01 100644 --- a/qubesmgmt/tests/tools/qvm_start.py +++ b/qubesadmin/tests/tools/qvm_start.py @@ -18,25 +18,25 @@ # You should have received a copy of the GNU Lesser General Public License along # with this program; if not, see . -import qubesmgmt.tests -import qubesmgmt.tests.tools -import qubesmgmt.tools.qvm_start +import qubesadmin.tests +import qubesadmin.tests.tools +import qubesadmin.tools.qvm_start -class TC_00_qvm_start(qubesmgmt.tests.QubesTestCase): +class TC_00_qvm_start(qubesadmin.tests.QubesTestCase): def test_000_with_vm(self): self.app.expected_calls[ ('dom0', 'mgmt.vm.List', None, None)] = \ b'0\x00some-vm class=AppVM state=Running\n' self.app.expected_calls[ ('some-vm', 'mgmt.vm.Start', None, None)] = b'0\x00' - qubesmgmt.tools.qvm_start.main(['some-vm'], app=self.app) + qubesadmin.tools.qvm_start.main(['some-vm'], app=self.app) self.assertAllCalled() def test_001_missing_vm(self): with self.assertRaises(SystemExit): - with qubesmgmt.tests.tools.StderrBuffer() as stderr: - qubesmgmt.tools.qvm_start.main([], app=self.app) + with qubesadmin.tests.tools.StderrBuffer() as stderr: + qubesadmin.tools.qvm_start.main([], app=self.app) self.assertIn('one of the arguments --all VMNAME is required', stderr.getvalue()) self.assertAllCalled() @@ -46,8 +46,8 @@ class TC_00_qvm_start(qubesmgmt.tests.QubesTestCase): ('dom0', 'mgmt.vm.List', None, None)] = \ b'0\x00some-vm class=AppVM state=Running\n' with self.assertRaises(SystemExit): - with qubesmgmt.tests.tools.StderrBuffer() as stderr: - qubesmgmt.tools.qvm_start.main(['no-such-vm'], app=self.app) + with qubesadmin.tests.tools.StderrBuffer() as stderr: + qubesadmin.tools.qvm_start.main(['no-such-vm'], app=self.app) self.assertIn('no such domain', stderr.getvalue()) self.assertAllCalled() @@ -61,7 +61,7 @@ class TC_00_qvm_start(qubesmgmt.tests.QubesTestCase): ('dom0', 'mgmt.vm.List', None, None)] = \ b'0\x00some-vm class=AppVM state=Running\n' self.assertEqual( - qubesmgmt.tools.qvm_start.main(['some-vm'], app=self.app), + qubesadmin.tools.qvm_start.main(['some-vm'], app=self.app), 1) self.assertAllCalled() diff --git a/qubesmgmt/tests/tools/qvm_start_gui.py b/qubesadmin/tests/tools/qvm_start_gui.py similarity index 96% rename from qubesmgmt/tests/tools/qvm_start_gui.py rename to qubesadmin/tests/tools/qvm_start_gui.py index 14ad876..3e83b74 100644 --- a/qubesmgmt/tests/tools/qvm_start_gui.py +++ b/qubesadmin/tests/tools/qvm_start_gui.py @@ -23,14 +23,14 @@ import unittest.mock import asyncio -import qubesmgmt.tests -import qubesmgmt.tools.qvm_start_gui +import qubesadmin.tests +import qubesadmin.tools.qvm_start_gui -class TC_00_qvm_start_gui(qubesmgmt.tests.QubesTestCase): +class TC_00_qvm_start_gui(qubesadmin.tests.QubesTestCase): def setUp(self): super(TC_00_qvm_start_gui, self).setUp() - self.launcher = qubesmgmt.tools.qvm_start_gui.GUILauncher(self.app) + self.launcher = qubesadmin.tools.qvm_start_gui.GUILauncher(self.app) @unittest.mock.patch('subprocess.check_output') def test_000_kde_args(self, proc_mock): @@ -329,7 +329,7 @@ HDMI2 disconnected (normal left inverted right x axis y axis) VGA1 disconnected (normal left inverted right x axis y axis) VIRTUAL1 disconnected (normal left inverted right x axis y axis) '''.splitlines() - self.assertEqual(qubesmgmt.tools.qvm_start_gui.get_monitor_layout(), + self.assertEqual(qubesadmin.tools.qvm_start_gui.get_monitor_layout(), ['1920 1200 0 0\n']) @unittest.mock.patch('subprocess.Popen') @@ -338,7 +338,7 @@ VIRTUAL1 disconnected (normal left inverted right x axis y axis) LVDS1 connected 1600x900+0+0 (normal left inverted right x axis y axis) VGA1 connected 1280x1024+1600+0 (normal left inverted right x axis y axis) '''.splitlines() - self.assertEqual(qubesmgmt.tools.qvm_start_gui.get_monitor_layout(), + self.assertEqual(qubesadmin.tools.qvm_start_gui.get_monitor_layout(), ['1600 900 0 0\n', '1280 1024 1600 0\n']) @unittest.mock.patch('subprocess.Popen') @@ -348,7 +348,7 @@ HDMI1 connected 2560x1920+0+0 (normal left inverted right x axis y axis) 372mm x 1920x1200 60.00*+ '''.splitlines() dpi = 150 - self.assertEqual(qubesmgmt.tools.qvm_start_gui.get_monitor_layout(), + self.assertEqual(qubesadmin.tools.qvm_start_gui.get_monitor_layout(), ['2560 1920 0 0 {} {}\n'.format( int(2560/dpi*254/10), int(1920/dpi*254/10))]) @@ -359,7 +359,7 @@ HDMI1 connected 2560x1920+0+0 (normal left inverted right x axis y axis) 310mm x 1920x1200 60.00*+ '''.splitlines() dpi = 200 - self.assertEqual(qubesmgmt.tools.qvm_start_gui.get_monitor_layout(), + self.assertEqual(qubesadmin.tools.qvm_start_gui.get_monitor_layout(), ['2560 1920 0 0 {} {}\n'.format( int(2560/dpi*254/10), int(1920/dpi*254/10))]) @@ -370,6 +370,6 @@ HDMI1 connected 2560x1920+0+0 (normal left inverted right x axis y axis) 206mm x 1920x1200 60.00*+ '''.splitlines() dpi = 300 - self.assertEqual(qubesmgmt.tools.qvm_start_gui.get_monitor_layout(), + self.assertEqual(qubesadmin.tools.qvm_start_gui.get_monitor_layout(), ['2560 1920 0 0 {} {}\n'.format( int(2560/dpi*254/10), int(1920/dpi*254/10))]) diff --git a/qubesmgmt/tests/tools/qvm_unpause.py b/qubesadmin/tests/tools/qvm_unpause.py similarity index 81% rename from qubesmgmt/tests/tools/qvm_unpause.py rename to qubesadmin/tests/tools/qvm_unpause.py index 463a3dc..6ac56e4 100644 --- a/qubesmgmt/tests/tools/qvm_unpause.py +++ b/qubesadmin/tests/tools/qvm_unpause.py @@ -18,24 +18,24 @@ # You should have received a copy of the GNU Lesser General Public License along # with this program; if not, see . -import qubesmgmt.tests -import qubesmgmt.tools.qvm_unpause +import qubesadmin.tests +import qubesadmin.tools.qvm_unpause -class TC_00_qvm_unpause(qubesmgmt.tests.QubesTestCase): +class TC_00_qvm_unpause(qubesadmin.tests.QubesTestCase): def test_000_with_vm(self): self.app.expected_calls[ ('dom0', 'mgmt.vm.List', None, None)] = \ b'0\x00some-vm class=AppVM state=Running\n' self.app.expected_calls[ ('some-vm', 'mgmt.vm.Unpause', None, None)] = b'0\x00' - qubesmgmt.tools.qvm_unpause.main(['some-vm'], app=self.app) + qubesadmin.tools.qvm_unpause.main(['some-vm'], app=self.app) self.assertAllCalled() def test_001_missing_vm(self): with self.assertRaises(SystemExit): - with qubesmgmt.tests.tools.StderrBuffer() as stderr: - qubesmgmt.tools.qvm_unpause.main([], app=self.app) + with qubesadmin.tests.tools.StderrBuffer() as stderr: + qubesadmin.tools.qvm_unpause.main([], app=self.app) self.assertIn('one of the arguments --all VMNAME is required', stderr.getvalue()) self.assertAllCalled() @@ -45,8 +45,8 @@ class TC_00_qvm_unpause(qubesmgmt.tests.QubesTestCase): ('dom0', 'mgmt.vm.List', None, None)] = \ b'0\x00some-vm class=AppVM state=Running\n' with self.assertRaises(SystemExit): - with qubesmgmt.tests.tools.StderrBuffer() as stderr: - qubesmgmt.tools.qvm_unpause.main(['no-such-vm'], app=self.app) + with qubesadmin.tests.tools.StderrBuffer() as stderr: + qubesadmin.tools.qvm_unpause.main(['no-such-vm'], app=self.app) self.assertIn('no such domain', stderr.getvalue()) self.assertAllCalled() @@ -60,7 +60,7 @@ class TC_00_qvm_unpause(qubesmgmt.tests.QubesTestCase): ('dom0', 'mgmt.vm.List', None, None)] = \ b'0\x00some-vm class=AppVM state=Halted\n' self.assertEqual( - qubesmgmt.tools.qvm_unpause.main(['some-vm'], app=self.app), + qubesadmin.tools.qvm_unpause.main(['some-vm'], app=self.app), 1) self.assertAllCalled() @@ -76,7 +76,7 @@ class TC_00_qvm_unpause(qubesmgmt.tests.QubesTestCase): b'0\x00some-vm class=AppVM state=Running\n' \ b'other-vm class=AppVM state=Running\n' self.assertEqual( - qubesmgmt.tools.qvm_unpause.main(['some-vm', 'other-vm'], + qubesadmin.tools.qvm_unpause.main(['some-vm', 'other-vm'], app=self.app), 0) self.assertAllCalled() diff --git a/qubesmgmt/tests/tools/qvm_volume.py b/qubesadmin/tests/tools/qvm_volume.py similarity index 87% rename from qubesmgmt/tests/tools/qvm_volume.py rename to qubesadmin/tests/tools/qvm_volume.py index 3da0066..0008536 100644 --- a/qubesmgmt/tests/tools/qvm_volume.py +++ b/qubesadmin/tests/tools/qvm_volume.py @@ -18,12 +18,12 @@ # You should have received a copy of the GNU Lesser General Public License along # with this program; if not, see . -import qubesmgmt.tests -import qubesmgmt.tests.tools -import qubesmgmt.tools.qvm_volume +import qubesadmin.tests +import qubesadmin.tests.tools +import qubesadmin.tools.qvm_volume -class TC_00_qvm_volume(qubesmgmt.tests.QubesTestCase): +class TC_00_qvm_volume(qubesadmin.tests.QubesTestCase): def setup_expected_calls_for_list(self, vms=('vm1', 'sys-net')): self.app.expected_calls[ @@ -49,9 +49,9 @@ class TC_00_qvm_volume(qubesmgmt.tests.QubesTestCase): def test_000_list(self): self.setup_expected_calls_for_list() - with qubesmgmt.tests.tools.StdoutBuffer() as stdout: + with qubesadmin.tests.tools.StdoutBuffer() as stdout: self.assertEqual(0, - qubesmgmt.tools.qvm_volume.main(['ls', '-i'], app=self.app)) + qubesadmin.tools.qvm_volume.main(['ls', '-i'], app=self.app)) self.assertEqual(stdout.getvalue(), 'POOL:VOLUME VMNAME VOLUME_NAME ' 'REVERT_POSSIBLE\n' @@ -64,9 +64,9 @@ class TC_00_qvm_volume(qubesmgmt.tests.QubesTestCase): def test_001_list_domain(self): self.setup_expected_calls_for_list(vms=('vm1',)) - with qubesmgmt.tests.tools.StdoutBuffer() as stdout: + with qubesadmin.tests.tools.StdoutBuffer() as stdout: self.assertEqual(0, - qubesmgmt.tools.qvm_volume.main(['ls', '-i', 'vm1'], + qubesadmin.tools.qvm_volume.main(['ls', '-i', 'vm1'], app=self.app)) self.assertEqual(stdout.getvalue(), 'POOL:VOLUME VMNAME VOLUME_NAME REVERT_POSSIBLE\n' @@ -81,9 +81,9 @@ class TC_00_qvm_volume(qubesmgmt.tests.QubesTestCase): b'0\x00pool-file\nother-pool\n' del self.app.expected_calls[ ('vm1', 'mgmt.vm.volume.ListSnapshots', 'private', None)] - with qubesmgmt.tests.tools.StdoutBuffer() as stdout: + with qubesadmin.tests.tools.StdoutBuffer() as stdout: self.assertEqual(0, - qubesmgmt.tools.qvm_volume.main( + qubesadmin.tools.qvm_volume.main( ['ls', '-i', '-p', 'pool-file', 'vm1'], app=self.app)) self.assertEqual(stdout.getvalue(), @@ -101,9 +101,9 @@ class TC_00_qvm_volume(qubesmgmt.tests.QubesTestCase): del self.app.expected_calls[ ('sys-net', 'mgmt.vm.volume.ListSnapshots', 'private', None)] - with qubesmgmt.tests.tools.StdoutBuffer() as stdout: + with qubesadmin.tests.tools.StdoutBuffer() as stdout: self.assertEqual(0, - qubesmgmt.tools.qvm_volume.main( + qubesadmin.tools.qvm_volume.main( ['ls', '-i', '-p', 'pool-file'], app=self.app)) self.assertEqual(stdout.getvalue(), @@ -120,9 +120,9 @@ class TC_00_qvm_volume(qubesmgmt.tests.QubesTestCase): b'0\x00vm1 class=AppVM state=Running\n' \ b'vm2 class=AppVM state=Running\n' \ b'vm3 class=AppVM state=Running\n' - with qubesmgmt.tests.tools.StdoutBuffer() as stdout: + with qubesadmin.tests.tools.StdoutBuffer() as stdout: self.assertEqual(0, - qubesmgmt.tools.qvm_volume.main( + qubesadmin.tools.qvm_volume.main( ['ls', '-i', 'vm1', 'vm2'], app=self.app)) self.assertEqual(stdout.getvalue(), 'POOL:VOLUME VMNAME VOLUME_NAME REVERT_POSSIBLE\n' @@ -143,7 +143,7 @@ class TC_00_qvm_volume(qubesmgmt.tests.QubesTestCase): ('testvm', 'mgmt.vm.volume.Resize', 'private', b'10737418240')] = \ b'0\x00' self.assertEqual(0, - qubesmgmt.tools.qvm_volume.main( + qubesadmin.tools.qvm_volume.main( ['extend', 'testvm:private', '10GiB'], app=self.app)) self.assertAllCalled() @@ -158,9 +158,9 @@ class TC_00_qvm_volume(qubesmgmt.tests.QubesTestCase): ('testvm', 'mgmt.vm.volume.Resize', 'private', b'1073741824')] = \ b'2\x00StoragePoolException\x00\x00Failed to resize volume: ' \ b'shrink not allowed\x00' - with qubesmgmt.tests.tools.StderrBuffer() as stderr: + with qubesadmin.tests.tools.StderrBuffer() as stderr: self.assertEqual(1, - qubesmgmt.tools.qvm_volume.main( + qubesadmin.tools.qvm_volume.main( ['extend', 'testvm:private', '1GiB'], app=self.app)) self.assertIn('shrink not allowed', stderr.getvalue()) diff --git a/qubesmgmt/tests/vm/__init__.py b/qubesadmin/tests/vm/__init__.py similarity index 93% rename from qubesmgmt/tests/vm/__init__.py rename to qubesadmin/tests/vm/__init__.py index 597edc9..94fc448 100644 --- a/qubesmgmt/tests/vm/__init__.py +++ b/qubesadmin/tests/vm/__init__.py @@ -18,10 +18,10 @@ # You should have received a copy of the GNU Lesser General Public License along # with this program; if not, see . -import qubesmgmt.tests +import qubesadmin.tests -class VMTestCase(qubesmgmt.tests.QubesTestCase): +class VMTestCase(qubesadmin.tests.QubesTestCase): def setUp(self): super(VMTestCase, self).setUp() self.app.expected_calls[('dom0', 'mgmt.vm.List', None, None)] = \ diff --git a/qubesmgmt/tests/vm/actions.py b/qubesadmin/tests/vm/actions.py similarity index 96% rename from qubesmgmt/tests/vm/actions.py rename to qubesadmin/tests/vm/actions.py index 4ff5b97..e7352de 100644 --- a/qubesmgmt/tests/vm/actions.py +++ b/qubesadmin/tests/vm/actions.py @@ -19,10 +19,10 @@ # with this program; if not, see . import unittest -import qubesmgmt.tests.vm +import qubesadmin.tests.vm -class TC_00_Actions(qubesmgmt.tests.vm.VMTestCase): +class TC_00_Actions(qubesadmin.tests.vm.VMTestCase): def test_000_start(self): self.app.expected_calls[ ('test-vm', 'mgmt.vm.Start', None, None)] = \ diff --git a/qubesmgmt/tests/vm/properties.py b/qubesadmin/tests/vm/properties.py similarity index 96% rename from qubesmgmt/tests/vm/properties.py rename to qubesadmin/tests/vm/properties.py index b970f78..b181f53 100644 --- a/qubesmgmt/tests/vm/properties.py +++ b/qubesadmin/tests/vm/properties.py @@ -18,10 +18,10 @@ # You should have received a copy of the GNU Lesser General Public License along # with this program; if not, see . -import qubesmgmt.tests.vm +import qubesadmin.tests.vm -class TC_00_Properties(qubesmgmt.tests.vm.VMTestCase): +class TC_00_Properties(qubesadmin.tests.vm.VMTestCase): def test_000_list(self): self.app.expected_calls[ @@ -57,7 +57,7 @@ class TC_00_Properties(qubesmgmt.tests.vm.VMTestCase): self.app.expected_calls[ ('test-vm', 'mgmt.vm.property.Get', 'prop1', None)] = \ b'0\x00default=False type=vm test-vm' - self.assertIsInstance(self.vm.prop1, qubesmgmt.vm.QubesVM) + self.assertIsInstance(self.vm.prop1, qubesadmin.vm.QubesVM) self.assertEqual(self.vm.prop1.name, 'test-vm') self.assertAllCalled() @@ -144,7 +144,7 @@ class TC_00_Properties(qubesmgmt.tests.vm.VMTestCase): self.app.expected_calls[ ('test-vm', 'mgmt.vm.property.Reset', 'prop1', None)] = \ b'0\x00' - self.vm.prop1 = qubesmgmt.DEFAULT + self.vm.prop1 = qubesadmin.DEFAULT self.assertAllCalled() def test_031_reset(self): @@ -155,7 +155,7 @@ class TC_00_Properties(qubesmgmt.tests.vm.VMTestCase): self.assertAllCalled() -class TC_01_SpecialCases(qubesmgmt.tests.vm.VMTestCase): +class TC_01_SpecialCases(qubesadmin.tests.vm.VMTestCase): def test_000_get_name(self): # should not make any mgmt call self.assertEqual(self.vm.name, 'test-vm') diff --git a/qubesmgmt/tests/vm/storage.py b/qubesadmin/tests/vm/storage.py similarity index 95% rename from qubesmgmt/tests/vm/storage.py rename to qubesadmin/tests/vm/storage.py index ea91559..e93d0a7 100644 --- a/qubesmgmt/tests/vm/storage.py +++ b/qubesadmin/tests/vm/storage.py @@ -18,10 +18,10 @@ # You should have received a copy of the GNU Lesser General Public License along # with this program; if not, see . -import qubesmgmt.tests.vm +import qubesadmin.tests.vm -class TestVMVolumes(qubesmgmt.tests.vm.VMTestCase): +class TestVMVolumes(qubesadmin.tests.vm.VMTestCase): def test_000_list_volumes(self): self.app.expected_calls[ ('test-vm', 'mgmt.vm.volume.List', None, None)] = \ diff --git a/qubesmgmt/tools/__init__.py b/qubesadmin/tools/__init__.py similarity index 98% rename from qubesmgmt/tools/__init__.py rename to qubesadmin/tools/__init__.py index 31c013b..3dadde1 100644 --- a/qubesmgmt/tools/__init__.py +++ b/qubesadmin/tools/__init__.py @@ -31,9 +31,9 @@ import subprocess import sys import textwrap -import qubesmgmt.log -import qubesmgmt.exc -import qubesmgmt.vm +import qubesadmin.log +import qubesadmin.exc +import qubesadmin.vm #: constant returned when some action should be performed on all qubes VM_ALL = object() @@ -156,7 +156,7 @@ class VmNameAction(QubesAction): namespace.domains = [ vm for vm in app.domains - if not isinstance(vm, qubesmgmt.vm.AdminVM) and + if not isinstance(vm, qubesadmin.vm.AdminVM) and vm.name not in namespace.exclude ] else: @@ -303,7 +303,7 @@ class PoolsAction(QubesAction): try: pools = [app.pools[name] for name in pool_names] setattr(namespace, self.dest, pools) - except qubesmgmt.exc.QubesException as e: + except qubesadmin.exc.QubesException as e: parser.error(str(e)) sys.exit(2) @@ -371,7 +371,7 @@ class QubesArgumentParser(argparse.ArgumentParser): if app is not None: namespace.app = app else: - namespace.app = qubesmgmt.Qubes() + namespace.app = qubesadmin.Qubes() for action in self._actions: # pylint: disable=protected-access @@ -414,9 +414,9 @@ class QubesArgumentParser(argparse.ArgumentParser): verbose = namespace.verbose - namespace.quiet if verbose >= 2: - qubesmgmt.log.enable_debug() + qubesadmin.log.enable_debug() elif verbose >= 1: - qubesmgmt.log.enable() + qubesadmin.log.enable() # pylint: disable=no-self-use def print_error(self, *args, **kwargs): @@ -473,7 +473,7 @@ def get_parser_for_command(command): ''' module = importlib.import_module( - '.' + command.replace('-', '_'), 'qubesmgmt.tools') + '.' + command.replace('-', '_'), 'qubesadmin.tools') try: parser = module.parser diff --git a/qubesmgmt/tools/dochelpers.py b/qubesadmin/tools/dochelpers.py similarity index 97% rename from qubesmgmt/tools/dochelpers.py rename to qubesadmin/tools/dochelpers.py index e3703d5..863f444 100644 --- a/qubesmgmt/tools/dochelpers.py +++ b/qubesadmin/tools/dochelpers.py @@ -40,7 +40,7 @@ import sphinx.errors import sphinx.locale import sphinx.util.docfields -import qubesmgmt.tools +import qubesadmin.tools SUBCOMMANDS_TITLE = 'COMMANDS' OPTIONS_TITLE = 'OPTIONS' @@ -53,7 +53,7 @@ def make_rst_section(heading, char): def prepare_manpage(command): '''Build a man page skeleton''' - parser = qubesmgmt.tools.get_parser_for_command(command) + parser = qubesadmin.tools.get_parser_for_command(command) stream = io.StringIO() stream.write('.. program:: {}\n\n'.format(command)) stream.write(make_rst_section( @@ -221,7 +221,7 @@ class ManpageCheckVisitor(docutils.nodes.SparseNodeVisitor): def __init__(self, app, command, document): docutils.nodes.SparseNodeVisitor.__init__(self, document) try: - parser = qubesmgmt.tools.get_parser_for_command(command) + parser = qubesadmin.tools.get_parser_for_command(command) except ImportError: app.warn('cannot import module for command') self.parser = None @@ -241,7 +241,7 @@ class ManpageCheckVisitor(docutils.nodes.SparseNodeVisitor): continue if issubclass(action.__class__, - qubesmgmt.tools.AliasedSubParsersAction): + qubesadmin.tools.AliasedSubParsersAction): for cmd, cmd_parser in action._name_parser_map.items(): self.sub_commands[cmd] = set() for sub_action in cmd_parser._actions: diff --git a/qubesmgmt/tools/qubes_prefs.py b/qubesadmin/tools/qubes_prefs.py similarity index 87% rename from qubesmgmt/tools/qubes_prefs.py rename to qubesadmin/tools/qubes_prefs.py index fdc5e59..7be1fd2 100644 --- a/qubesmgmt/tools/qubes_prefs.py +++ b/qubesadmin/tools/qubes_prefs.py @@ -27,20 +27,20 @@ from __future__ import print_function import sys -import qubesmgmt -import qubesmgmt.tools.qvm_prefs +import qubesadmin +import qubesadmin.tools.qvm_prefs def get_parser(): '''Prepare argument parser''' - return qubesmgmt.tools.qvm_prefs.get_parser(None) + return qubesadmin.tools.qvm_prefs.get_parser(None) def main(args=None, app=None): # pylint: disable=missing-docstring parser = get_parser() args = parser.parse_args(args, app=app) target = args.app - return qubesmgmt.tools.qvm_prefs.process_actions(parser, args, target) + return qubesadmin.tools.qvm_prefs.process_actions(parser, args, target) if __name__ == '__main__': sys.exit(main()) diff --git a/qubesmgmt/tools/qvm_check.py b/qubesadmin/tools/qvm_check.py similarity index 94% rename from qubesmgmt/tools/qvm_check.py rename to qubesadmin/tools/qvm_check.py index ab7c869..9d0fc3c 100644 --- a/qubesmgmt/tools/qvm_check.py +++ b/qubesadmin/tools/qvm_check.py @@ -25,10 +25,10 @@ from __future__ import print_function import sys -import qubesmgmt.tools -import qubesmgmt.vm +import qubesadmin.tools +import qubesadmin.vm -parser = qubesmgmt.tools.QubesArgumentParser(description=__doc__, +parser = qubesadmin.tools.QubesArgumentParser(description=__doc__, vmname_nargs='+') parser.add_argument("--running", action="store_true", dest="running", default=False, help="Determine if (any of given) VM is running") @@ -65,7 +65,7 @@ def main(args=None, app=None): return 0 if paused else 1 elif args.template: template = [vm for vm in domains if isinstance(vm, - qubesmgmt.vm.TemplateVM)] + qubesadmin.vm.TemplateVM)] if args.verbose: print_msg(template, "is a template", "are templates") return 0 if template else 1 diff --git a/qubesmgmt/tools/qvm_clone.py b/qubesadmin/tools/qvm_clone.py similarity index 98% rename from qubesmgmt/tools/qvm_clone.py rename to qubesadmin/tools/qvm_clone.py index bd03f1b..fb4cb4e 100644 --- a/qubesmgmt/tools/qvm_clone.py +++ b/qubesadmin/tools/qvm_clone.py @@ -24,7 +24,7 @@ import sys -from qubesmgmt.tools import QubesArgumentParser +from qubesadmin.tools import QubesArgumentParser parser = QubesArgumentParser(description=__doc__, vmname_nargs=1) parser.add_argument('new_name', diff --git a/qubesmgmt/tools/qvm_create.py b/qubesadmin/tools/qvm_create.py similarity index 92% rename from qubesmgmt/tools/qvm_create.py rename to qubesadmin/tools/qvm_create.py index 979853f..91bf9c7 100644 --- a/qubesmgmt/tools/qvm_create.py +++ b/qubesadmin/tools/qvm_create.py @@ -32,18 +32,18 @@ from __future__ import print_function import argparse import sys -import qubesmgmt -import qubesmgmt.tools +import qubesadmin +import qubesadmin.tools -parser = qubesmgmt.tools.QubesArgumentParser() +parser = qubesadmin.tools.QubesArgumentParser() parser.add_argument('--class', '-C', dest='cls', default='AppVM', help='specify the class of the new domain (default: %(default)s)') parser.add_argument('--property', '--prop', - action=qubesmgmt.tools.PropertyAction, + action=qubesadmin.tools.PropertyAction, help='set domain\'s property, like "internal", "memory" or "vcpus"') parser.add_argument('--pool', '-p', @@ -58,11 +58,11 @@ parser.add_argument('-P', help='change all volume pools to specified pool') parser.add_argument('--template', '-t', - action=qubesmgmt.tools.SinglePropertyAction, + action=qubesadmin.tools.SinglePropertyAction, help='specify the TemplateVM to use') parser.add_argument('--label', '-l', - action=qubesmgmt.tools.SinglePropertyAction, + action=qubesadmin.tools.SinglePropertyAction, help='specify the label to use for the new domain' ' (e.g. red, yellow, green, ...)') @@ -80,7 +80,7 @@ parser_root.add_argument('--no-root', help=argparse.SUPPRESS) parser.add_argument('name', metavar='VMNAME', - action=qubesmgmt.tools.SinglePropertyAction, + action=qubesadmin.tools.SinglePropertyAction, nargs='?', help='name of the domain to create') @@ -131,7 +131,7 @@ def main(args=None, app=None): template=args.properties.pop('template', None), pool=pool, pools=pools) - except qubesmgmt.exc.QubesException as e: + except qubesadmin.exc.QubesException as e: args.app.log.error('Error creating VM: {!s}'.format(e)) return 1 @@ -139,7 +139,7 @@ def main(args=None, app=None): for prop, value in args.properties.items(): try: setattr(vm, prop, value) - except qubesmgmt.exc.QubesException as e: + except qubesadmin.exc.QubesException as e: args.app.log.error( 'Error setting property {} (but VM created): {!s}'. format(prop, e)) diff --git a/qubesmgmt/tools/qvm_device.py b/qubesadmin/tools/qvm_device.py similarity index 90% rename from qubesmgmt/tools/qvm_device.py rename to qubesadmin/tools/qvm_device.py index 9ae3e93..53d4cd8 100644 --- a/qubesmgmt/tools/qvm_device.py +++ b/qubesadmin/tools/qvm_device.py @@ -27,10 +27,10 @@ import argparse import os import sys -import qubesmgmt -import qubesmgmt.exc -import qubesmgmt.tools -import qubesmgmt.devices +import qubesadmin +import qubesadmin.exc +import qubesadmin.tools +import qubesadmin.devices def prepare_table(dev_list): @@ -62,7 +62,7 @@ def prepare_table(dev_list): class Line(object): '''Helper class to hold single device info for listing''' # pylint: disable=too-few-public-methods - def __init__(self, device: qubesmgmt.devices.DeviceInfo, attached_to=None): + def __init__(self, device: qubesadmin.devices.DeviceInfo, attached_to=None): self.ident = "{!s}:{!s}".format(device.backend_domain, device.ident) self.description = device.description self.attached_to = attached_to if attached_to else "" @@ -103,7 +103,7 @@ def list_devices(args): result[dev].frontends.append(str(domain)) - qubesmgmt.tools.print_table(prepare_table(result.values())) + qubesadmin.tools.print_table(prepare_table(result.values())) def attach_device(args): @@ -133,16 +133,16 @@ def init_list_parser(sub_parsers): list_parser = sub_parsers.add_parser('list', aliases=('ls', 'l'), help='list devices') - vm_name_group = qubesmgmt.tools.VmNameGroup( - list_parser, required=False, vm_action=qubesmgmt.tools.VmNameAction, + vm_name_group = qubesadmin.tools.VmNameGroup( + list_parser, required=False, vm_action=qubesadmin.tools.VmNameAction, help='list devices assigned to specific domain(s)') list_parser._mutually_exclusive_groups.append(vm_name_group) list_parser.set_defaults(func=list_devices) -class DeviceAction(qubesmgmt.tools.QubesAction): +class DeviceAction(qubesadmin.tools.QubesAction): ''' Action for argument parser that gets the - :py:class:``qubesmgmt.device.DeviceAssignment`` from a + :py:class:``qubesadmin.device.DeviceAssignment`` from a BACKEND:DEVICE_ID string. ''' # pylint: disable=too-few-public-methods @@ -172,13 +172,13 @@ class DeviceAction(qubesmgmt.tools.QubesAction): try: dev = vm.devices[devclass][device_id] if not self.allow_unknown and isinstance(dev, - qubesmgmt.devices.UnknownDevice): + qubesadmin.devices.UnknownDevice): raise KeyError(device_id) except KeyError: parser.error_runtime( "backend vm {!r} doesn't expose device {!r}" .format(vmname, device_id)) - device_assignment = qubesmgmt.devices.DeviceAssignment(vm, + device_assignment = qubesadmin.devices.DeviceAssignment(vm, device_id) setattr(namespace, self.dest, device_assignment) except ValueError: @@ -190,10 +190,10 @@ def get_parser(device_class=None): '''Create :py:class:`argparse.ArgumentParser` suitable for :program:`qvm-block`. ''' - parser = qubesmgmt.tools.QubesArgumentParser(description=__doc__, + parser = qubesadmin.tools.QubesArgumentParser(description=__doc__, want_app=True) parser.register('action', 'parsers', - qubesmgmt.tools.AliasedSubParsersAction) + qubesadmin.tools.AliasedSubParsersAction) if device_class: parser.add_argument('devclass', const=device_class, action='store_const', @@ -212,9 +212,9 @@ def get_parser(device_class=None): "detach", help="Detach device from domain", aliases=('d', 'dt')) attach_parser.add_argument('VMNAME', nargs=1, - action=qubesmgmt.tools.VmNameAction) + action=qubesadmin.tools.VmNameAction) detach_parser.add_argument('VMNAME', nargs=1, - action=qubesmgmt.tools.VmNameAction) + action=qubesadmin.tools.VmNameAction) attach_parser.add_argument(metavar='BACKEND:DEVICE_ID', dest='device_assignment', @@ -246,7 +246,7 @@ def main(args=None, app=None): args = get_parser(devclass).parse_args(args, app=app) try: args.func(args) - except qubesmgmt.exc.QubesException as e: + except qubesadmin.exc.QubesException as e: print(str(e), file=sys.stderr) return 1 return 0 diff --git a/qubesmgmt/tools/qvm_features.py b/qubesadmin/tools/qvm_features.py similarity index 94% rename from qubesmgmt/tools/qvm_features.py rename to qubesadmin/tools/qvm_features.py index 5d2300b..244ea01 100644 --- a/qubesmgmt/tools/qvm_features.py +++ b/qubesadmin/tools/qvm_features.py @@ -28,10 +28,10 @@ from __future__ import print_function import sys -import qubesmgmt -import qubesmgmt.tools +import qubesadmin +import qubesadmin.tools -parser = qubesmgmt.tools.QubesArgumentParser( +parser = qubesadmin.tools.QubesArgumentParser( vmname_nargs=1, description='manage domain\'s features') @@ -64,7 +64,7 @@ def main(args=None, app=None): parser.error('--unset requires a feature') features = [(feat, vm.features[feat]) for feat in vm.features] - qubesmgmt.tools.print_table(features) + qubesadmin.tools.print_table(features) elif args.delete: if args.value is not None: diff --git a/qubesmgmt/tools/qvm_firewall.py b/qubesadmin/tools/qvm_firewall.py similarity index 95% rename from qubesmgmt/tools/qvm_firewall.py rename to qubesadmin/tools/qvm_firewall.py index 73d7990..2f4f910 100644 --- a/qubesmgmt/tools/qvm_firewall.py +++ b/qubesadmin/tools/qvm_firewall.py @@ -25,9 +25,9 @@ import argparse import sys import itertools -import qubesmgmt.exc -import qubesmgmt.firewall -import qubesmgmt.tools +import qubesadmin.exc +import qubesadmin.firewall +import qubesadmin.tools class RuleAction(argparse.Action): @@ -65,10 +65,10 @@ class RuleAction(argparse.Action): assumed_order.remove('icmptype') elif key == 'proto' and value in ['icmp']: assumed_order.remove('dstports') - rule = qubesmgmt.firewall.Rule(None, **kwargs) + rule = qubesadmin.firewall.Rule(None, **kwargs) setattr(namespace, self.dest, rule) -parser = qubesmgmt.tools.QubesArgumentParser(vmname_nargs=1) +parser = qubesadmin.tools.QubesArgumentParser(vmname_nargs=1) action = parser.add_subparsers(dest='command', help='action to perform') @@ -119,7 +119,7 @@ def rules_list_table(vm): rule.comment, ]] rows.append(row) - qubesmgmt.tools.print_table([header] + rows) + qubesadmin.tools.print_table([header] + rows) def rules_list_raw(vm): @@ -176,7 +176,7 @@ def main(args=None, app=None): rules_list_table(vm) if args.reload: vm.firewall.reload() - except qubesmgmt.exc.QubesException as e: + except qubesadmin.exc.QubesException as e: parser.print_error(str(e)) return 1 return 0 diff --git a/qubesmgmt/tools/qvm_kill.py b/qubesadmin/tools/qvm_kill.py similarity index 89% rename from qubesmgmt/tools/qvm_kill.py rename to qubesadmin/tools/qvm_kill.py index d62076e..9bba46d 100644 --- a/qubesmgmt/tools/qvm_kill.py +++ b/qubesadmin/tools/qvm_kill.py @@ -22,10 +22,10 @@ import sys -import qubesmgmt.exc -import qubesmgmt.tools +import qubesadmin.exc +import qubesadmin.tools -parser = qubesmgmt.tools.QubesArgumentParser( +parser = qubesadmin.tools.QubesArgumentParser( description='forceful shutdown of a domain', vmname_nargs='+') @@ -42,7 +42,7 @@ def main(args=None, app=None): for domain in args.domains: try: domain.kill() - except (IOError, OSError, qubesmgmt.exc.QubesException) as e: + except (IOError, OSError, qubesadmin.exc.QubesException) as e: exit_code = 1 parser.print_error(str(e)) diff --git a/qubesmgmt/tools/qvm_ls.py b/qubesadmin/tools/qvm_ls.py similarity index 96% rename from qubesmgmt/tools/qvm_ls.py rename to qubesadmin/tools/qvm_ls.py index 63ae7a8..1b4e728 100644 --- a/qubesmgmt/tools/qvm_ls.py +++ b/qubesadmin/tools/qvm_ls.py @@ -33,10 +33,10 @@ import collections import sys import textwrap -import qubesmgmt -import qubesmgmt.tools -import qubesmgmt.utils -import qubesmgmt.vm +import qubesadmin +import qubesadmin.tools +import qubesadmin.utils +import qubesadmin.vm # # columns @@ -57,7 +57,7 @@ class Column(object): def __init__(self, head, attr=None, doc=None): self.ls_head = head - self.__doc__ = doc if doc is None else qubesmgmt.utils.format_doc(doc) + self.__doc__ = doc if doc is None else qubesadmin.utils.format_doc(doc) # intentionally not always do set self._attr, # to cause AttributeError in self.format() @@ -213,18 +213,18 @@ class StatusColumn(Column): When it is HVM (optimised VM), the letter is capital. ''' - if isinstance(vm, qubesmgmt.vm.AdminVM): + if isinstance(vm, qubesadmin.vm.AdminVM): return '0' ret = None # TODO right order, depending on inheritance - if isinstance(vm, qubesmgmt.vm.TemplateVM): + if isinstance(vm, qubesadmin.vm.TemplateVM): ret = 't' - if isinstance(vm, qubesmgmt.vm.AppVM): + if isinstance(vm, qubesadmin.vm.AppVM): ret = 'a' - if isinstance(vm, qubesmgmt.vm.StandaloneVM): + if isinstance(vm, qubesadmin.vm.StandaloneVM): ret = 's' - if isinstance(vm, qubesmgmt.vm.DispVM): + if isinstance(vm, qubesadmin.vm.DispVM): ret = 'd' if ret is not None: @@ -405,7 +405,7 @@ class Table(object): table_data.append(self.get_head()) for vm in sorted(self.app.domains): table_data.append(self.get_row(vm)) - qubesmgmt.tools.print_table(table_data, stream=stream) + qubesadmin.tools.print_table(table_data, stream=stream) else: for vm in sorted(self.app.domains): stream.write('|'.join(self.get_row(vm)) + '\n') @@ -488,7 +488,7 @@ def get_parser(): wrapper = textwrap.TextWrapper(width=80, break_on_hyphens=False, initial_indent=' ', subsequent_indent=' ') - parser = qubesmgmt.tools.QubesArgumentParser( + parser = qubesadmin.tools.QubesArgumentParser( formatter_class=argparse.RawTextHelpFormatter, description='List Qubes domains and their parametres.', epilog='available formats (see --help-formats):\n{}\n\n' @@ -533,7 +533,7 @@ def main(args=None, app=None): parser = get_parser() try: args = parser.parse_args(args, app=app) - except qubesmgmt.exc.QubesException as e: + except qubesadmin.exc.QubesException as e: parser.print_error(str(e)) return 1 diff --git a/qubesmgmt/tools/qvm_pause.py b/qubesadmin/tools/qvm_pause.py similarity index 90% rename from qubesmgmt/tools/qvm_pause.py rename to qubesadmin/tools/qvm_pause.py index 2cf1880..837cab3 100644 --- a/qubesmgmt/tools/qvm_pause.py +++ b/qubesadmin/tools/qvm_pause.py @@ -21,10 +21,10 @@ '''qvm-pause - Pause a domain''' import sys -import qubesmgmt +import qubesadmin -parser = qubesmgmt.tools.QubesArgumentParser(vmname_nargs='+', +parser = qubesadmin.tools.QubesArgumentParser(vmname_nargs='+', description='pause a domain') @@ -40,7 +40,7 @@ def main(args=None, app=None): for domain in args.domains: try: domain.pause() - except (IOError, OSError, qubesmgmt.exc.QubesException) as e: + except (IOError, OSError, qubesadmin.exc.QubesException) as e: exit_code = 1 parser.print_error(str(e)) diff --git a/qubesmgmt/tools/qvm_pool.py b/qubesadmin/tools/qvm_pool.py similarity index 93% rename from qubesmgmt/tools/qvm_pool.py rename to qubesadmin/tools/qvm_pool.py index 2ac7943..027c055 100644 --- a/qubesmgmt/tools/qvm_pool.py +++ b/qubesadmin/tools/qvm_pool.py @@ -25,13 +25,13 @@ from __future__ import print_function import argparse import sys -import qubesmgmt -import qubesmgmt.exc -import qubesmgmt.storage -import qubesmgmt.tools +import qubesadmin +import qubesadmin.exc +import qubesadmin.storage +import qubesadmin.tools -class _Info(qubesmgmt.tools.PoolsAction): +class _Info(qubesadmin.tools.PoolsAction): ''' Action for argument parser that displays pool info and exits. ''' def __init__(self, option_strings, help='print pool info and exit', @@ -48,7 +48,7 @@ def pool_info(pool): ''' Prints out pool name and config ''' data = [("name", pool.name)] data += [i for i in sorted(pool.config.items()) if i[0] != 'name'] - qubesmgmt.tools.print_table(data) + qubesadmin.tools.print_table(data) def list_pools(app): @@ -56,7 +56,7 @@ def list_pools(app): result = [('NAME', 'DRIVER')] for pool in app.pools: result += [(pool.name, pool.driver)] - qubesmgmt.tools.print_table(result) + qubesadmin.tools.print_table(result) class _Remove(argparse.Action): @@ -110,7 +110,7 @@ class _Options(argparse.Action): def get_parser(): ''' Parses the provided args ''' - parser = qubesmgmt.tools.QubesArgumentParser(description=__doc__) + parser = qubesadmin.tools.QubesArgumentParser(description=__doc__) parser.add_argument('-o', action=_Options, dest='options', default={}) group = parser.add_mutually_exclusive_group() group.add_argument('-l', @@ -144,7 +144,7 @@ def main(args=None, app=None): parser = get_parser() try: args = parser.parse_args(args, app=app) - except qubesmgmt.exc.QubesException as e: + except qubesadmin.exc.QubesException as e: parser.print_error(str(e)) return 1 @@ -156,12 +156,12 @@ def main(args=None, app=None): params = args.app.pool_driver_parameters(driver) driver_options = ', '.join(params) result += [(driver, driver_options)] - qubesmgmt.tools.print_table(result) + qubesadmin.tools.print_table(result) elif args.command == 'add': try: args.app.add_pool(name=args.name, driver=args.driver, **args.options) - except qubesmgmt.exc.QubesException as e: + except qubesadmin.exc.QubesException as e: parser.error('failed to add pool %s: %s\n' % (args.name, str(e))) elif args.command == 'remove': try: diff --git a/qubesmgmt/tools/qvm_prefs.py b/qubesadmin/tools/qvm_prefs.py similarity index 97% rename from qubesmgmt/tools/qvm_prefs.py rename to qubesadmin/tools/qvm_prefs.py index 13df85b..21dce6e 100644 --- a/qubesmgmt/tools/qvm_prefs.py +++ b/qubesadmin/tools/qvm_prefs.py @@ -26,15 +26,15 @@ from __future__ import print_function import sys import textwrap -import qubesmgmt -import qubesmgmt.tools -import qubesmgmt.utils -import qubesmgmt.vm +import qubesadmin +import qubesadmin.tools +import qubesadmin.utils +import qubesadmin.vm def get_parser(vmname_nargs=1): '''Return argument parser for generic property-related tool''' - parser = qubesmgmt.tools.QubesArgumentParser( + parser = qubesadmin.tools.QubesArgumentParser( vmname_nargs=vmname_nargs) parser.add_argument('--help-properties', diff --git a/qubesmgmt/tools/qvm_remove.py b/qubesadmin/tools/qvm_remove.py similarity index 96% rename from qubesmgmt/tools/qvm_remove.py rename to qubesadmin/tools/qvm_remove.py index 488e029..b5a3ad0 100644 --- a/qubesmgmt/tools/qvm_remove.py +++ b/qubesadmin/tools/qvm_remove.py @@ -23,7 +23,7 @@ import sys -from qubesmgmt.tools import QubesArgumentParser +from qubesadmin.tools import QubesArgumentParser parser = QubesArgumentParser(description=__doc__, want_app=True, diff --git a/qubesmgmt/tools/qvm_run.py b/qubesadmin/tools/qvm_run.py similarity index 97% rename from qubesmgmt/tools/qvm_run.py rename to qubesadmin/tools/qvm_run.py index 103a78b..1fefb16 100644 --- a/qubesmgmt/tools/qvm_run.py +++ b/qubesadmin/tools/qvm_run.py @@ -30,10 +30,10 @@ import functools import logging -import qubesmgmt.tools -import qubesmgmt.exc +import qubesadmin.tools +import qubesadmin.exc -parser = qubesmgmt.tools.QubesArgumentParser(vmname_nargs='+') +parser = qubesadmin.tools.QubesArgumentParser(vmname_nargs='+') parser.add_argument('--user', '-u', metavar='USER', help='run command in a qube as USER (available only from dom0)') @@ -169,7 +169,7 @@ def main(args=None, app=None): loop.close() proc.stdin.close() procs.append(proc) - except qubesmgmt.exc.QubesException as e: + except qubesadmin.exc.QubesException as e: if args.color_output: sys.stdout.write('\033[0m') sys.stdout.flush() diff --git a/qubesmgmt/tools/qvm_shutdown.py b/qubesadmin/tools/qvm_shutdown.py similarity index 94% rename from qubesmgmt/tools/qvm_shutdown.py rename to qubesadmin/tools/qvm_shutdown.py index eefecc1..e8aff02 100644 --- a/qubesmgmt/tools/qvm_shutdown.py +++ b/qubesadmin/tools/qvm_shutdown.py @@ -27,10 +27,10 @@ from __future__ import print_function import sys import time -import qubesmgmt.tools -import qubesmgmt.exc +import qubesadmin.tools +import qubesadmin.exc -parser = qubesmgmt.tools.QubesArgumentParser( +parser = qubesadmin.tools.QubesArgumentParser( description=__doc__, vmname_nargs='+') parser.add_argument('--force', @@ -55,7 +55,7 @@ def main(args=None, app=None): # pylint: disable=missing-docstring for vm in args.domains: try: vm.shutdown(force=args.force) - except qubesmgmt.exc.QubesVMNotStartedError: + except qubesadmin.exc.QubesVMNotStartedError: pass if not args.wait: diff --git a/qubesmgmt/tools/qvm_start.py b/qubesadmin/tools/qvm_start.py similarity index 90% rename from qubesmgmt/tools/qvm_start.py rename to qubesadmin/tools/qvm_start.py index 9a5ae85..ae37e15 100644 --- a/qubesmgmt/tools/qvm_start.py +++ b/qubesadmin/tools/qvm_start.py @@ -22,10 +22,10 @@ import sys -import qubesmgmt.exc -import qubesmgmt.tools +import qubesadmin.exc +import qubesadmin.tools -parser = qubesmgmt.tools.QubesArgumentParser( +parser = qubesadmin.tools.QubesArgumentParser( description='start a domain', vmname_nargs='+') parser.add_argument('--skip-if-running', @@ -47,7 +47,7 @@ def main(args=None, app=None): continue try: domain.start() - except (IOError, OSError, qubesmgmt.exc.QubesException) as e: + except (IOError, OSError, qubesadmin.exc.QubesException) as e: exit_code = 1 parser.print_error(str(e)) diff --git a/qubesmgmt/tools/qvm_start_gui.py b/qubesadmin/tools/qvm_start_gui.py similarity index 97% rename from qubesmgmt/tools/qvm_start_gui.py rename to qubesadmin/tools/qvm_start_gui.py index 58ed4d4..84d49ab 100644 --- a/qubesmgmt/tools/qvm_start_gui.py +++ b/qubesadmin/tools/qvm_start_gui.py @@ -29,10 +29,10 @@ import asyncio import re import daemon.pidfile -import qubesmgmt -import qubesmgmt.events -import qubesmgmt.tools -import qubesmgmt.vm +import qubesadmin +import qubesadmin.events +import qubesadmin.tools +import qubesadmin.vm GUI_DAEMON_PATH = '/usr/bin/qubes-guid' QUBES_ICON_DIR = '/usr/share/icons/hicolor/128x128/devices' @@ -104,10 +104,10 @@ def get_monitor_layout(): class GUILauncher(object): '''Launch GUI daemon for VMs''' - def __init__(self, app: qubesmgmt.app.QubesBase): + def __init__(self, app: qubesadmin.app.QubesBase): ''' Initialize GUILauncher. - :param app: :py:class:`qubesmgmt.Qubes` instance + :param app: :py:class:`qubesadmin.Qubes` instance ''' self.app = app self.started_processes = {} @@ -269,7 +269,7 @@ class GUILauncher(object): '''Send monitor layout to all (running) VMs''' monitor_layout = get_monitor_layout() for vm in self.app.domains: - if isinstance(vm, qubesmgmt.vm.AdminVM): + if isinstance(vm, qubesadmin.vm.AdminVM): continue if vm.is_running(): if not vm.features.check_with_template('gui', True): @@ -297,7 +297,7 @@ class GUILauncher(object): monitor_layout = get_monitor_layout() for vm in self.app.domains: - if isinstance(vm, qubesmgmt.vm.AdminVM): + if isinstance(vm, qubesadmin.vm.AdminVM): continue if vm.is_running(): asyncio.ensure_future(self.start_gui(vm, @@ -318,7 +318,7 @@ else: pidfile_path = os.path.join(os.environ.get('HOME', '/'), '.qvm-start-gui.pid') -parser = qubesmgmt.tools.QubesArgumentParser( +parser = qubesadmin.tools.QubesArgumentParser( description='start GUI for qube(s)', vmname_nargs='*') parser.add_argument('--watch', action='store_true', help='Keep watching for further domains startups, must be used with --all') @@ -339,7 +339,7 @@ def main(args=None): if args.watch: with daemon.pidfile.TimeoutPIDLockFile(args.pidfile): loop = asyncio.get_event_loop() - events = qubesmgmt.events.EventsDispatcher(args.app) + events = qubesadmin.events.EventsDispatcher(args.app) launcher.register_events(events) events_listener = asyncio.ensure_future(events.listen_for_events()) diff --git a/qubesmgmt/tools/qvm_unpause.py b/qubesadmin/tools/qvm_unpause.py similarity index 91% rename from qubesmgmt/tools/qvm_unpause.py rename to qubesadmin/tools/qvm_unpause.py index b944366..02d1d70 100644 --- a/qubesmgmt/tools/qvm_unpause.py +++ b/qubesadmin/tools/qvm_unpause.py @@ -21,10 +21,10 @@ '''qvm-unpause - Unpause a domain''' import sys -import qubesmgmt +import qubesadmin -parser = qubesmgmt.tools.QubesArgumentParser( +parser = qubesadmin.tools.QubesArgumentParser( vmname_nargs='+', description='unpause a domain') @@ -41,7 +41,7 @@ def main(args=None, app=None): for domain in args.domains: try: domain.unpause() - except (IOError, OSError, qubesmgmt.exc.QubesException) as e: + except (IOError, OSError, qubesadmin.exc.QubesException) as e: exit_code = 1 parser.print_error(str(e)) diff --git a/qubesmgmt/tools/qvm_volume.py b/qubesadmin/tools/qvm_volume.py similarity index 90% rename from qubesmgmt/tools/qvm_volume.py rename to qubesadmin/tools/qvm_volume.py index 4e815ec..75c8928 100644 --- a/qubesmgmt/tools/qvm_volume.py +++ b/qubesadmin/tools/qvm_volume.py @@ -26,10 +26,10 @@ from __future__ import print_function import sys -import qubesmgmt -import qubesmgmt.exc -import qubesmgmt.tools -import qubesmgmt.utils +import qubesadmin +import qubesadmin.exc +import qubesadmin.tools +import qubesadmin.utils def prepare_table(vd_list, full=False): @@ -129,7 +129,7 @@ def list_volumes(args): if x.domains] else: result = [x for p in vd_dict.values() for x in p.values()] - qubesmgmt.tools.print_table(prepare_table(result, full=args.full)) + qubesadmin.tools.print_table(prepare_table(result, full=args.full)) def revert_volume(args): @@ -139,7 +139,7 @@ def revert_volume(args): try: pool = app.pools[volume.pool] pool.revert(volume) - except qubesmgmt.exc.StoragePoolException as e: + except qubesadmin.exc.StoragePoolException as e: print(str(e), file=sys.stderr) sys.exit(1) @@ -149,7 +149,7 @@ def extend_volumes(args): subcommand ''' volume = args.volume - size = qubesmgmt.utils.parse_size(args.size) + size = qubesadmin.utils.parse_size(args.size) volume.resize(size) @@ -159,15 +159,15 @@ def init_list_parser(sub_parsers): list_parser = sub_parsers.add_parser('list', aliases=('ls', 'l'), help='list storage volumes') list_parser.add_argument('-p', '--pool', dest='pools', - action=qubesmgmt.tools.PoolsAction) + action=qubesadmin.tools.PoolsAction) list_parser.add_argument('-i', '--internal', action='store_true', help='Show internal volumes') list_parser.add_argument( '--full', action='store_true', help='print full line for each POOL_NAME:VOLUME_ID & vm combination') - vm_name_group = qubesmgmt.tools.VmNameGroup( - list_parser, required=False, vm_action=qubesmgmt.tools.VmNameAction, + vm_name_group = qubesadmin.tools.VmNameGroup( + list_parser, required=False, vm_action=qubesadmin.tools.VmNameAction, help='list volumes from specified domain(s)') list_parser._mutually_exclusive_groups.append(vm_name_group) list_parser.set_defaults(func=list_volumes) @@ -179,7 +179,7 @@ def init_revert_parser(sub_parsers): 'revert', aliases=('rv', 'r'), help='revert volume to previous revision') revert_parser.add_argument(metavar='VM:VOLUME', dest='volume', - action=qubesmgmt.tools.VMVolumeAction) + action=qubesadmin.tools.VMVolumeAction) revert_parser.set_defaults(func=revert_volume) @@ -188,7 +188,7 @@ def init_extend_parser(sub_parsers): extend_parser = sub_parsers.add_parser( "extend", help="extend volume from domain") extend_parser.add_argument(metavar='VM:VOLUME', dest='volume', - action=qubesmgmt.tools.VMVolumeAction) + action=qubesadmin.tools.VMVolumeAction) extend_parser.add_argument('size', help='New size in bytes') extend_parser.set_defaults(func=extend_volumes) @@ -196,10 +196,10 @@ def get_parser(): '''Create :py:class:`argparse.ArgumentParser` suitable for :program:`qvm-block`. ''' - parser = qubesmgmt.tools.QubesArgumentParser(description=__doc__, + parser = qubesadmin.tools.QubesArgumentParser(description=__doc__, want_app=True) parser.register('action', 'parsers', - qubesmgmt.tools.AliasedSubParsersAction) + qubesadmin.tools.AliasedSubParsersAction) sub_parsers = parser.add_subparsers( title='commands', description="For more information see qvm-block command -h", @@ -217,7 +217,7 @@ def main(args=None, app=None): try: args = parser.parse_args(args, app=app) args.func(args) - except qubesmgmt.exc.QubesException as e: + except qubesadmin.exc.QubesException as e: parser.print_error(str(e)) return 1 diff --git a/qubesmgmt/utils.py b/qubesadmin/utils.py similarity index 97% rename from qubesmgmt/utils.py rename to qubesadmin/utils.py index 984aa31..707b611 100644 --- a/qubesmgmt/utils.py +++ b/qubesadmin/utils.py @@ -29,7 +29,7 @@ import pkg_resources import docutils import docutils.core import docutils.io -import qubesmgmt.exc +import qubesadmin.exc def format_doc(docstring): @@ -74,7 +74,7 @@ def parse_size(size): size = size[:-len(unit)].strip() return int(size) * multiplier - raise qubesmgmt.exc.QubesException("Invalid size: {0}.".format(size)) + raise qubesadmin.exc.QubesException("Invalid size: {0}.".format(size)) def mbytes_to_kmg(size): diff --git a/qubesmgmt/vm/__init__.py b/qubesadmin/vm/__init__.py similarity index 94% rename from qubesmgmt/vm/__init__.py rename to qubesadmin/vm/__init__.py index 8029d72..1d73bdd 100644 --- a/qubesmgmt/vm/__init__.py +++ b/qubesadmin/vm/__init__.py @@ -21,15 +21,15 @@ '''Qubes VM objects.''' import logging -import qubesmgmt.base -import qubesmgmt.exc -import qubesmgmt.storage -import qubesmgmt.features -import qubesmgmt.devices -import qubesmgmt.firewall +import qubesadmin.base +import qubesadmin.exc +import qubesadmin.storage +import qubesadmin.features +import qubesadmin.devices +import qubesadmin.firewall -class QubesVM(qubesmgmt.base.PropertyHolder): +class QubesVM(qubesadmin.base.PropertyHolder): '''Qubes domain.''' log = None @@ -44,9 +44,9 @@ class QubesVM(qubesmgmt.base.PropertyHolder): super(QubesVM, self).__init__(app, 'mgmt.vm.property.', name) self._volumes = None self.log = logging.getLogger(name) - self.features = qubesmgmt.features.Features(self) - self.devices = qubesmgmt.devices.DeviceManager(self) - self.firewall = qubesmgmt.firewall.Firewall(self) + self.features = qubesadmin.features.Features(self) + self.devices = qubesadmin.devices.DeviceManager(self) + self.firewall = qubesadmin.firewall.Firewall(self) @property def name(self): @@ -218,7 +218,7 @@ class QubesVM(qubesmgmt.base.PropertyHolder): for volname in volumes_list.decode('ascii').splitlines(): if not volname: continue - self._volumes[volname] = qubesmgmt.storage.Volume(self.app, + self._volumes[volname] = qubesadmin.storage.Volume(self.app, vm=self.name, vm_name=volname) return self._volumes @@ -248,7 +248,7 @@ class QubesVM(qubesmgmt.base.PropertyHolder): stdouterr = p.communicate(input=input) if p.returncode: - raise qubesmgmt.exc.QubesVMError(self, + raise qubesadmin.exc.QubesVMError(self, 'service {!r} failed with retcode {!r}; ' 'stdout={!r} stderr={!r}'.format( service, p.returncode, *stdouterr)) diff --git a/rpm_spec/qubes-core-mgmt-client.spec b/rpm_spec/qubes-core-admin-client.spec similarity index 64% rename from rpm_spec/qubes-core-mgmt-client.spec rename to rpm_spec/qubes-core-admin-client.spec index c4f082e..f3ae2ca 100644 --- a/rpm_spec/qubes-core-mgmt-client.spec +++ b/rpm_spec/qubes-core-admin-client.spec @@ -1,7 +1,7 @@ -Name: qubes-core-mgmt-client +Name: qubes-core-admin-client Version: %(cat version) Release: 0.1%{?dist} -Summary: Qubes OS management client tools +Summary: Qubes OS admin client tools Group: Qubes License: LGPLv2.1+ @@ -13,7 +13,7 @@ BuildRequires: python2-devel BuildRequires: python3-devel BuildRequires: python3-sphinx BuildRequires: python3-dbus -Requires: python3-qubesmgmt +Requires: python3-qubesadmin BuildArch: noarch %if 0%{?qubes_builder} @@ -23,19 +23,19 @@ BuildArch: noarch %description This package include managemt tools, like qvm-*. -%package -n python2-qubesmgmt -Summary: Python2 module qubesmgmt +%package -n python2-qubesadmin +Summary: Python2 module qubesadmin Requires: python2-daemon -%description -n python2-qubesmgmt -Python2 module qubesmgmt. +%description -n python2-qubesadmin +Python2 module qubesadmin. -%package -n python3-qubesmgmt -Summary: Python3 module qubesmgmt +%package -n python3-qubesadmin +Summary: Python3 module qubesadmin Requires: python3-daemon -%description -n python3-qubesmgmt -Python3 module qubesmgmt. +%description -n python3-qubesadmin +Python3 module qubesadmin. %prep %if !0%{?qubes_builder} @@ -64,13 +64,13 @@ make -C doc DESTDIR=$RPM_BUILD_ROOT \ %{_mandir}/man1/qvm-*.1* %{_mandir}/man1/qubes*.1* -%files -n python2-qubesmgmt -%{python_sitelib}/qubesmgmt-*egg-info -%{python_sitelib}/qubesmgmt +%files -n python2-qubesadmin +%{python_sitelib}/qubesadmin-*egg-info +%{python_sitelib}/qubesadmin -%files -n python3-qubesmgmt -%{python3_sitelib}/qubesmgmt-*egg-info -%{python3_sitelib}/qubesmgmt +%files -n python3-qubesadmin +%{python3_sitelib}/qubesadmin-*egg-info +%{python3_sitelib}/qubesadmin %changelog diff --git a/run-tests b/run-tests index a1ff989..4489a04 100755 --- a/run-tests +++ b/run-tests @@ -10,4 +10,4 @@ export PYTHONPATH [ -r version ] || ln -s ${ROOTDIR}/version ./ [ -r setup.py ] || ln -s ${ROOTDIR}/setup.py ./ "${PYTHON}" ./setup.py egg_info --egg-base "${TESTPYTHONPATH}" -"${PYTHON}" -m coverage run --rcfile=$ROOTDIR/ci/coveragerc -m unittest discover -s qubesmgmt/tests -p '*.py' -v "$@" +"${PYTHON}" -m coverage run --rcfile=$ROOTDIR/ci/coveragerc -m unittest discover -s qubesadmin/tests -p '*.py' -v "$@" diff --git a/setup.py b/setup.py index c233f8b..88ec1d5 100644 --- a/setup.py +++ b/setup.py @@ -5,25 +5,25 @@ import sys exclude=[] if sys.version_info[0:2] < (3, 5): - exclude = ['qubesmgmt.events', 'qubesmgmt.tools', 'qubesmgmt.tests.tools'] + exclude = ['qubesadmin.events', 'qubesadmin.tools', 'qubesadmin.tests.tools'] if __name__ == '__main__': setuptools.setup( - name='qubesmgmt', + name='qubesadmin', version=open('version').read().strip(), author='Invisible Things Lab', author_email='marmarek@invisiblethingslab.com', - description='Qubes mgmt API package', + description='Qubes Admin API package', license='LGPL2.1+', url='https://www.qubes-os.org/', packages=setuptools.find_packages(exclude=exclude), entry_points={ - 'qubesmgmt.vm': [ - 'AppVM = qubesmgmt.vm:AppVM', - 'TemplateVM = qubesmgmt.vm:TemplateVM', - 'StandaloneVM = qubesmgmt.vm:StandaloneVM', - 'AdminVM = qubesmgmt.vm:AdminVM', - 'DispVM = qubesmgmt.vm:DispVM', + 'qubesadmin.vm': [ + 'AppVM = qubesadmin.vm:AppVM', + 'TemplateVM = qubesadmin.vm:TemplateVM', + 'StandaloneVM = qubesadmin.vm:StandaloneVM', + 'AdminVM = qubesadmin.vm:AdminVM', + 'DispVM = qubesadmin.vm:DispVM', ], }, diff --git a/test-packages/.gitignore b/test-packages/.gitignore index 9bede6a..fc8b926 100644 --- a/test-packages/.gitignore +++ b/test-packages/.gitignore @@ -1 +1 @@ -qubesmgmt.egg-info +qubesadmin.egg-info