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']
|
private_img_size = qubes.config.defaults['private_img_size']
|
||||||
root_img_size = qubes.config.defaults['root_img_size']
|
root_img_size = qubes.config.defaults['root_img_size']
|
||||||
|
|
||||||
def __init__(self, name, revisions_to_keep=1, **kwargs):
|
def __init__(self, *, name, revisions_to_keep=1):
|
||||||
super().__init__(**kwargs)
|
|
||||||
self._volumes_collection = VolumesCollection(self)
|
self._volumes_collection = VolumesCollection(self)
|
||||||
self.name = name
|
self.name = name
|
||||||
self.revisions_to_keep = revisions_to_keep
|
self.revisions_to_keep = revisions_to_keep
|
||||||
kwargs['name'] = self.name
|
|
||||||
|
|
||||||
def __eq__(self, other):
|
def __eq__(self, other):
|
||||||
if isinstance(other, Pool):
|
if isinstance(other, Pool):
|
||||||
|
@ -52,9 +52,8 @@ class FilePool(qubes.storage.Pool):
|
|||||||
''' # pylint: disable=protected-access
|
''' # pylint: disable=protected-access
|
||||||
driver = 'file'
|
driver = 'file'
|
||||||
|
|
||||||
def __init__(self, revisions_to_keep=1, dir_path=None, **kwargs):
|
def __init__(self, *, name, revisions_to_keep=1, dir_path):
|
||||||
super().__init__(revisions_to_keep=revisions_to_keep, **kwargs)
|
super().__init__(name=name, revisions_to_keep=revisions_to_keep)
|
||||||
assert dir_path, "No pool dir_path specified"
|
|
||||||
self.dir_path = os.path.normpath(dir_path)
|
self.dir_path = os.path.normpath(dir_path)
|
||||||
self._volumes = []
|
self._volumes = []
|
||||||
|
|
||||||
|
@ -154,8 +154,7 @@ class LinuxKernel(Pool):
|
|||||||
''' Provides linux kernels '''
|
''' Provides linux kernels '''
|
||||||
driver = 'linux-kernel'
|
driver = 'linux-kernel'
|
||||||
|
|
||||||
def __init__(self, name=None, dir_path=None):
|
def __init__(self, *, name, dir_path):
|
||||||
assert dir_path, 'Missing dir_path'
|
|
||||||
super().__init__(name=name, revisions_to_keep=0)
|
super().__init__(name=name, revisions_to_keep=0)
|
||||||
self.dir_path = dir_path
|
self.dir_path = dir_path
|
||||||
|
|
||||||
|
@ -80,8 +80,8 @@ class ThinPool(qubes.storage.Pool):
|
|||||||
|
|
||||||
driver = 'lvm_thin'
|
driver = 'lvm_thin'
|
||||||
|
|
||||||
def __init__(self, volume_group, thin_pool, revisions_to_keep=1, **kwargs):
|
def __init__(self, *, name, revisions_to_keep=1, volume_group, thin_pool):
|
||||||
super().__init__(revisions_to_keep=revisions_to_keep, **kwargs)
|
super().__init__(name=name, revisions_to_keep=revisions_to_keep)
|
||||||
self.volume_group = volume_group
|
self.volume_group = volume_group
|
||||||
self.thin_pool = thin_pool
|
self.thin_pool = thin_pool
|
||||||
self._pool_id = "{!s}/{!s}".format(volume_group, thin_pool)
|
self._pool_id = "{!s}/{!s}".format(volume_group, thin_pool)
|
||||||
|
@ -58,9 +58,9 @@ class ReflinkPool(qubes.storage.Pool):
|
|||||||
driver = 'file-reflink'
|
driver = 'file-reflink'
|
||||||
_known_dir_path_prefixes = ['appvms', 'vm-templates']
|
_known_dir_path_prefixes = ['appvms', 'vm-templates']
|
||||||
|
|
||||||
def __init__(self, dir_path, setup_check=True, revisions_to_keep=1,
|
def __init__(self, *, name, revisions_to_keep=1,
|
||||||
**kwargs):
|
dir_path, setup_check=True):
|
||||||
super().__init__(revisions_to_keep=revisions_to_keep, **kwargs)
|
super().__init__(name=name, revisions_to_keep=revisions_to_keep)
|
||||||
self._setup_check = qubes.property.bool(None, None, setup_check)
|
self._setup_check = qubes.property.bool(None, None, setup_check)
|
||||||
self._volumes = {}
|
self._volumes = {}
|
||||||
self.dir_path = os.path.abspath(dir_path)
|
self.dir_path = os.path.abspath(dir_path)
|
||||||
|
@ -30,8 +30,8 @@ from qubes.tests import SystemTestCase, QubesTestCase
|
|||||||
|
|
||||||
|
|
||||||
class TestPool(unittest.mock.Mock):
|
class TestPool(unittest.mock.Mock):
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, **kwargs):
|
||||||
super(TestPool, self).__init__(*args, spec=qubes.storage.Pool, **kwargs)
|
super(TestPool, self).__init__(spec=qubes.storage.Pool, **kwargs)
|
||||||
try:
|
try:
|
||||||
self.name = kwargs['name']
|
self.name = kwargs['name']
|
||||||
except KeyError:
|
except KeyError:
|
||||||
|
@ -62,7 +62,7 @@ class TC_90_AppVM(qubes.tests.vm.qubesvm.QubesVMTestsMixin,
|
|||||||
qubes.tests.QubesTestCase):
|
qubes.tests.QubesTestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super().setUp()
|
super().setUp()
|
||||||
self.app.pools['default'] = TestPool('default')
|
self.app.pools['default'] = TestPool(name='default')
|
||||||
self.app.pools['linux-kernel'] = mock.Mock(**{
|
self.app.pools['linux-kernel'] = mock.Mock(**{
|
||||||
'init_volume.return_value.pool': 'linux-kernel'})
|
'init_volume.return_value.pool': 'linux-kernel'})
|
||||||
self.template = qubes.vm.templatevm.TemplateVM(self.app, None,
|
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()
|
super(TC_00_DispVM, self).setUp()
|
||||||
self.app = TestApp()
|
self.app = TestApp()
|
||||||
self.app.save = mock.Mock()
|
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(**{
|
self.app.pools['linux-kernel'] = mock.Mock(**{
|
||||||
'init_volume.return_value.pool': 'linux-kernel'})
|
'init_volume.return_value.pool': 'linux-kernel'})
|
||||||
self.app.vmm.offline_mode = True
|
self.app.vmm.offline_mode = True
|
||||||
|
Loading…
Reference in New Issue
Block a user