storage: clean up __init__() of Pool() and subclasses
- Remove **kwargs - Make all arguments keyword-only - Use required arguments instead of asserts QubesOS/qubes-issues#5895
This commit is contained in:
parent
652bf3b6d9
commit
5ed762d152
@ -716,12 +716,10 @@ class Pool:
|
||||
private_img_size = qubes.config.defaults['private_img_size']
|
||||
root_img_size = qubes.config.defaults['root_img_size']
|
||||
|
||||
def __init__(self, name, revisions_to_keep=1, **kwargs):
|
||||
super().__init__(**kwargs)
|
||||
def __init__(self, *, name, revisions_to_keep=1):
|
||||
self._volumes_collection = VolumesCollection(self)
|
||||
self.name = name
|
||||
self.revisions_to_keep = revisions_to_keep
|
||||
kwargs['name'] = self.name
|
||||
|
||||
def __eq__(self, other):
|
||||
if isinstance(other, Pool):
|
||||
|
@ -52,9 +52,8 @@ class FilePool(qubes.storage.Pool):
|
||||
''' # pylint: disable=protected-access
|
||||
driver = 'file'
|
||||
|
||||
def __init__(self, revisions_to_keep=1, dir_path=None, **kwargs):
|
||||
super().__init__(revisions_to_keep=revisions_to_keep, **kwargs)
|
||||
assert dir_path, "No pool dir_path specified"
|
||||
def __init__(self, *, name, revisions_to_keep=1, dir_path):
|
||||
super().__init__(name=name, revisions_to_keep=revisions_to_keep)
|
||||
self.dir_path = os.path.normpath(dir_path)
|
||||
self._volumes = []
|
||||
|
||||
|
@ -154,8 +154,7 @@ class LinuxKernel(Pool):
|
||||
''' Provides linux kernels '''
|
||||
driver = 'linux-kernel'
|
||||
|
||||
def __init__(self, name=None, dir_path=None):
|
||||
assert dir_path, 'Missing dir_path'
|
||||
def __init__(self, *, name, dir_path):
|
||||
super().__init__(name=name, revisions_to_keep=0)
|
||||
self.dir_path = dir_path
|
||||
|
||||
|
@ -80,8 +80,8 @@ class ThinPool(qubes.storage.Pool):
|
||||
|
||||
driver = 'lvm_thin'
|
||||
|
||||
def __init__(self, volume_group, thin_pool, revisions_to_keep=1, **kwargs):
|
||||
super().__init__(revisions_to_keep=revisions_to_keep, **kwargs)
|
||||
def __init__(self, *, name, revisions_to_keep=1, volume_group, thin_pool):
|
||||
super().__init__(name=name, revisions_to_keep=revisions_to_keep)
|
||||
self.volume_group = volume_group
|
||||
self.thin_pool = thin_pool
|
||||
self._pool_id = "{!s}/{!s}".format(volume_group, thin_pool)
|
||||
|
@ -58,9 +58,9 @@ class ReflinkPool(qubes.storage.Pool):
|
||||
driver = 'file-reflink'
|
||||
_known_dir_path_prefixes = ['appvms', 'vm-templates']
|
||||
|
||||
def __init__(self, dir_path, setup_check=True, revisions_to_keep=1,
|
||||
**kwargs):
|
||||
super().__init__(revisions_to_keep=revisions_to_keep, **kwargs)
|
||||
def __init__(self, *, name, revisions_to_keep=1,
|
||||
dir_path, setup_check=True):
|
||||
super().__init__(name=name, revisions_to_keep=revisions_to_keep)
|
||||
self._setup_check = qubes.property.bool(None, None, setup_check)
|
||||
self._volumes = {}
|
||||
self.dir_path = os.path.abspath(dir_path)
|
||||
|
@ -30,8 +30,8 @@ from qubes.tests import SystemTestCase, QubesTestCase
|
||||
|
||||
|
||||
class TestPool(unittest.mock.Mock):
|
||||
def __init__(self, *args, **kwargs):
|
||||
super(TestPool, self).__init__(*args, spec=qubes.storage.Pool, **kwargs)
|
||||
def __init__(self, **kwargs):
|
||||
super(TestPool, self).__init__(spec=qubes.storage.Pool, **kwargs)
|
||||
try:
|
||||
self.name = kwargs['name']
|
||||
except KeyError:
|
||||
|
@ -62,7 +62,7 @@ class TC_90_AppVM(qubes.tests.vm.qubesvm.QubesVMTestsMixin,
|
||||
qubes.tests.QubesTestCase):
|
||||
def setUp(self):
|
||||
super().setUp()
|
||||
self.app.pools['default'] = TestPool('default')
|
||||
self.app.pools['default'] = TestPool(name='default')
|
||||
self.app.pools['linux-kernel'] = mock.Mock(**{
|
||||
'init_volume.return_value.pool': 'linux-kernel'})
|
||||
self.template = qubes.vm.templatevm.TemplateVM(self.app, None,
|
||||
|
@ -47,7 +47,7 @@ class TC_00_DispVM(qubes.tests.QubesTestCase):
|
||||
super(TC_00_DispVM, self).setUp()
|
||||
self.app = TestApp()
|
||||
self.app.save = mock.Mock()
|
||||
self.app.pools['default'] = qubes.tests.vm.appvm.TestPool('default')
|
||||
self.app.pools['default'] = qubes.tests.vm.appvm.TestPool(name='default')
|
||||
self.app.pools['linux-kernel'] = mock.Mock(**{
|
||||
'init_volume.return_value.pool': 'linux-kernel'})
|
||||
self.app.vmm.offline_mode = True
|
||||
|
Loading…
Reference in New Issue
Block a user