Fix qubes.storage.file pylint warnings
This commit is contained in:
parent
20282c17fe
commit
72df863bb9
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user