From: Lukáš Doktor <[email protected]>

This error message covers most cases of the missing config key thus
it allow us to use params[] for required configs instead of checking
and raising custom exceptions.

Changes from v1:
 * Raise a custom error, ParamNotFound, that inherits
   from error.TestNAError, that will make the tests
   that lack a mandatory param to be skipped.

Signed-off-by: Lukáš Doktor <[email protected]>
---
 virttest/utils_params.py | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/virttest/utils_params.py b/virttest/utils_params.py
index 67538c1..f871bd2 100644
--- a/virttest/utils_params.py
+++ b/virttest/utils_params.py
@@ -1,10 +1,25 @@
 import UserDict
+from autotest.client.shared import error
+
+
+class ParamNotFound(error.TestNAError):
+    pass
 
 
 class Params(UserDict.IterableUserDict):
     """
     A dict-like object passed to every test.
     """
+    def __getitem__(self, key):
+        """ overrides the error messages of missing params[$key] """
+        try:
+            return UserDict.IterableUserDict.__getitem__(self, key)
+        except KeyError:
+            raise ParamNotFound("Mandatory parameter '%s' is missing. "
+                                "Check your cfg files for typos/mistakes" %
+                                key)
+
+
     def objects(self, key):
         """
         Return the names of objects defined using a given key.
-- 
1.8.2

_______________________________________________
Virt-test-devel mailing list
[email protected]
https://www.redhat.com/mailman/listinfo/virt-test-devel

Reply via email to