summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2019-12-07 15:03:00 +0200
committerLars Wirzenius <liw@liw.fi>2019-12-07 17:47:21 +0200
commita982ed72c84d51923dcd903c8d399f8cbb1083ad (patch)
tree268e7867bd6e3df0ac7344b368cf217e36dbbb7c
parente4580504ecda93889981f327efa20e20dab8f063 (diff)
downloadvmdb2-a982ed72c84d51923dcd903c8d399f8cbb1083ad.tar.gz
Add: vmdb.NotString error class
-rw-r--r--vmdb/__init__.py1
-rw-r--r--vmdb/plugins/mkfs_plugin.py15
-rw-r--r--vmdb/plugins/mkimg_plugin.py9
-rw-r--r--vmdb/step_list.py21
4 files changed, 29 insertions, 17 deletions
diff --git a/vmdb/__init__.py b/vmdb/__init__.py
index 91aa015..63cf1b7 100644
--- a/vmdb/__init__.py
+++ b/vmdb/__init__.py
@@ -22,6 +22,7 @@ from .step_list import (
StepRunnerList,
StepRunnerInterface,
NoMatchingRunner,
+ NotString,
StepError,
)
from .runcmd import (
diff --git a/vmdb/plugins/mkfs_plugin.py b/vmdb/plugins/mkfs_plugin.py
index 500699c..406ce51 100644
--- a/vmdb/plugins/mkfs_plugin.py
+++ b/vmdb/plugins/mkfs_plugin.py
@@ -18,18 +18,10 @@
import cliapp
-import logging
import vmdb
-class NotString(vmdb.StepError):
-
- def __init__(self, name, actual):
- msg = '%s: value must be string, got %r' % (name, actual)
- super().__init__(msg)
-
-
class MkfsPlugin(cliapp.Plugin):
def enable(self):
@@ -46,13 +38,12 @@ class MkfsStepRunner(vmdb.StepRunnerInterface):
tag = step['partition']
device = state.tags.get_dev(tag)
- logging.debug('state: %r', state.as_dict())
if not isinstance(fstype, str):
- raise NotString('mkfs', fstype)
+ raise vmdb.NotString('mkfs', fstype)
if not isinstance(tag, str):
- raise NotString('mkfs: tag', tag)
+ raise vmdb.NotString('mkfs: tag', tag)
if not isinstance(device, str):
- raise NotString('mkfs: device (for tag)', device)
+ raise vmdb.NotString('mkfs: device (for tag)', device)
cmd = ['/sbin/mkfs', '-t', fstype]
if 'label' in step:
diff --git a/vmdb/plugins/mkimg_plugin.py b/vmdb/plugins/mkimg_plugin.py
index 44fc57d..f68f7c3 100644
--- a/vmdb/plugins/mkimg_plugin.py
+++ b/vmdb/plugins/mkimg_plugin.py
@@ -40,4 +40,13 @@ class MkimgStepRunner(vmdb.StepRunnerInterface):
def run(self, step, settings, state):
filename = step['mkimg']
size = step['size']
+
+ if not isinstance(filename, str):
+ raise vmdb.NotString('mkimg', filename)
+ if not filename:
+ raise vmdb.IsEmptyString('mkimg', filename)
+
+ if not isinstance(size, str):
+ raise vmdb.NotString('mkimg: size', size)
+
vmdb.runcmd(['qemu-img', 'create', '-f', 'raw', filename, size])
diff --git a/vmdb/step_list.py b/vmdb/step_list.py
index f69b4bc..20e3ec6 100644
--- a/vmdb/step_list.py
+++ b/vmdb/step_list.py
@@ -16,6 +16,9 @@
# =*= License: GPL-3+ =*=
+import logging
+
+
import cliapp
@@ -75,12 +78,20 @@ class StepRunnerList:
class StepError(cliapp.AppException):
- pass
+ def __init__(self, msg):
+ logging.error(msg)
+ super().__init__(msg)
-class NoMatchingRunner(cliapp.AppException):
+class NoMatchingRunner(StepError):
def __init__(self, keys):
- super(NoMatchingRunner, self).__init__(
- 'No runner implements step with keys {}'.format(
- ', '.join(keys)))
+ super().__init__(
+ 'No runner implements step with keys {}'.format(', '.join(keys)))
+
+
+class NotString(StepError): # pragma: no cover
+
+ def __init__(self, name, actual):
+ msg = '%s: value must be string, got %r' % (name, actual)
+ super().__init__(msg)