From 72df863bb9ba9b9a2a1d4a1c72bc749dd472c842 Mon Sep 17 00:00:00 2001 From: Bahtiar `kalkin-` Gadimov Date: Tue, 21 Jun 2016 12:47:47 +0200 Subject: [PATCH] Fix qubes.storage.file pylint warnings --- qubes/storage/file.py | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/qubes/storage/file.py b/qubes/storage/file.py index 5b5e04db..24b63a59 100644 --- a/qubes/storage/file.py +++ b/qubes/storage/file.py @@ -86,7 +86,7 @@ class FilePool(Pool): ''' Expands volume, throws :py:class:`qubst.storage.StoragePoolException` if given size is less than current_size - ''' + ''' # pylint: disable=no-self-use _type = volume.volume_type if _type not in ['origin', 'read-write', 'volatile']: raise StoragePoolException('Can not resize a %s volume %s' % @@ -170,7 +170,7 @@ class FilePool(Pool): def start(self, volume): if volume.volume_type == 'volatile': - self._reset_volume(volume) + _reset_volume(volume) if volume.volume_type in ['origin', 'snapshot']: _check_path(volume.path_origin) _check_path(volume.path_cow) @@ -182,18 +182,6 @@ class FilePool(Pool): def stop(self, volume): pass - @staticmethod - def _reset_volume(volume): - ''' Remove and recreate a volatile volume ''' - assert volume.volume_type == 'volatile', "Not a volatile volume" - assert volume.size - - _remove_if_exists(volume.path) - - with open(volume.path, "w") as f_volatile: - f_volatile.truncate(volume.size) - return volume - def target_dir(self, vm): """ Returns the path to vmdir depending on the type of the VM. @@ -251,6 +239,7 @@ class FilePool(Pool): expected_origin_type origin_pool = vm.app.get_pool(origin_vm.volume_config[name]['pool']) + assert isinstance(origin_pool, FilePool), 'Origin volume not a file volume' @@ -513,7 +502,7 @@ def copy_file(source, destination): def _remove_if_exists(path): - ''' Removes a path if it exist, silently succeeds if file does not exist ''' + ''' Removes a file if it exist, silently succeeds if file does not exist ''' if os.path.exists(path): os.remove(path) @@ -522,3 +511,16 @@ def _check_path(path): ''' Raise an StoragePoolException if ``path`` does not exist''' if not os.path.exists(path): raise StoragePoolException('Missing image file: %s' % path) + + +def _reset_volume(volume): + ''' Remove and recreate a volatile volume ''' + assert volume.volume_type == 'volatile', "Not a volatile volume" + + assert volume.size + + _remove_if_exists(volume) + + with open(volume.path, "w") as f_volatile: + f_volatile.truncate(volume.size) + return volume