Change in vdsm[master]: vdsmapi: prepare for event naming
piotr.kliczewski at gmail.com
piotr.kliczewski at gmail.com
Mon Apr 11 16:59:11 UTC 2016
Piotr Kliczewski has uploaded a new change for review.
Change subject: vdsmapi: prepare for event naming
......................................................................
vdsmapi: prepare for event naming
Change-Id: I31f119b7809ae7536d3cab4de6298c648402614d
Signed-off-by: pkliczewski <piotr.kliczewski at gmail.com>
---
M lib/api/vdsmapi.py
M lib/vdsm/rpc/Bridge.py
M tests/vdsmapi_test.py
3 files changed, 31 insertions(+), 33 deletions(-)
git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/99/55999/1
diff --git a/lib/api/vdsmapi.py b/lib/api/vdsmapi.py
index 1fe82bb..4f6f4ac 100644
--- a/lib/api/vdsmapi.py
+++ b/lib/api/vdsmapi.py
@@ -91,7 +91,8 @@
raise SchemaNotFound("Unable to find API schema file")
def get_params(self, class_name, method_name):
- return self.get_method(class_name, method_name).get('params', [])
+ return self.get_method('%s.%s' % (class_name,
+ method_name)).get('params', [])
def get_param_names(self, class_name, method_name):
return [param.get('name') for param in self.get_params(class_name,
@@ -109,14 +110,14 @@
if 'defaultvalue' in param]
def get_ret_param(self, class_name, method_name):
- return self.get_method(class_name, method_name).get('return', {})
+ return self.get_method('%s.%s' % (class_name,
+ method_name)).get('return', {})
- def get_method(self, class_name, method_name):
- verb_name = '%s.%s' % (class_name, method_name)
+ def get_method(self, name):
try:
- return self._methods[verb_name]
+ return self._methods[name]
except KeyError:
- raise MethodNotFound(verb_name)
+ raise MethodNotFound(name)
def get_type(self, type_name):
try:
@@ -157,7 +158,8 @@
'provided when calling %s.%s' % (name, class_name,
method_name))
continue
- self._verify_type(param, arg, class_name, method_name)
+ self._verify_type(param, arg, '%s.%s' % (class_name,
+ method_name))
except Exception as e:
if type(e).__name__ == 'JsonRpcInvalidParamsError':
raise
@@ -165,14 +167,14 @@
' verification for %s.%s'
% (class_name, method_name))
- def _verify_type(self, param, arg, class_name, method_name):
+ def _verify_type(self, param, arg, identifier):
# check whether a parameter is in a list
if isinstance(param, list):
if not isinstance(arg, list):
self._report_inconsistency('Parameter %s is not a list'
% (arg))
for a in arg:
- self._verify_type(param[0], a, class_name, method_name)
+ self._verify_type(param[0], a, identifier)
return
# check whether a parameter is defined as primitive type
elif param in primitive_types.keys():
@@ -185,8 +187,8 @@
if t == 'dict':
# it seems that there is no other way to have it fixed
self._report_inconsistency(
- 'Unsupported type %s in %s.%s please fix'
- % (t, class_name, method_name))
+ 'Unsupported type %s in %s please fix'
+ % (t, identifier))
# check whether it is a primitive type
elif t in primitive_types.keys():
self._check_primitive_type(t, arg, name)
@@ -194,8 +196,7 @@
else:
# if type is a string call type verification method
if isinstance(t, (str, unicode)):
- self._verify_complex_type(t, param, arg, name, class_name,
- method_name)
+ self._verify_complex_type(t, param, arg, name, identifier)
# if type is in a list we need to get the type and call
# type verification method
elif isinstance(t, list):
@@ -203,24 +204,21 @@
self._report_inconsistency('Parameter %s is not list'
% (arg))
for a in arg:
- self._verify_type(t[0], a, class_name, method_name)
+ self._verify_type(t[0], a, identifier)
else:
# call complex type verification
self._verify_complex_type(t.get('type'), t, arg, name,
- class_name, method_name)
+ identifier)
- def _verify_complex_type(self, t_type, t, arg, name, class_name,
- method_name):
+ def _verify_complex_type(self, t_type, t, arg, name, identifier):
if t_type == 'alias':
# if alias we need to check sourcetype
self._check_primitive_type(t.get('sourcetype'), arg, name)
elif t_type == 'map':
# if map we need to check key and value types
for key, value in arg.iteritems():
- self._verify_type(t.get('key-type'), key, class_name,
- method_name)
- self._verify_type(t.get('value-type'), value, class_name,
- method_name)
+ self._verify_type(t.get('key-type'), key, identifier)
+ self._verify_type(t.get('value-type'), value, identifier)
elif t_type == 'union':
# if union we need to check whether parameter matches on of the
# values defined
@@ -229,7 +227,7 @@
prop_names = [prop.get('name') for prop in props]
if not [key for key in arg.keys() if key not in prop_names]:
self._verify_complex_type(value.get('type'), value, arg,
- name, class_name, method_name)
+ name, identifier)
return
self._report_inconsistency('Provided parameters %s do not match'
' any of union %s values'
@@ -239,10 +237,9 @@
if arg not in t.get('values').keys():
self._report_inconsistency('Provided value "%s" not'
' defined in %s enum for'
- ' %s.%s' % (arg,
- t.get('name'),
- class_name,
- method_name))
+ ' %s' % (arg,
+ t.get('name'),
+ identifier))
else:
# if object we need to check whether all the properties
# match values provided
@@ -266,7 +263,7 @@
if value == 'needs updating':
self._report_inconsistency(
'No default value specified for %s parameter in'
- ' %s.%s' % (p_name, class_name, method_name))
+ ' %s' % (p_name, identifier))
if value == 'no-default':
continue
if a is None or a == value:
@@ -275,18 +272,18 @@
if a is None:
self._report_inconsistency(
'Required property %s is not provided when calling'
- ' %s.%s' % (p_name, class_name, method_name))
+ ' %s' % (p_name, identifier))
continue
# call type verification
- self._verify_type(prop, a, class_name, method_name)
+ self._verify_type(prop, a, identifier)
def verify_retval(self, class_name, method_name, ret):
try:
ret_args = self.get_ret_param(class_name, method_name)
if ret_args:
- self._verify_type(ret_args.get('type'), ret, class_name,
- method_name)
+ self._verify_type(ret_args.get('type'), ret,
+ '%s.%s' % (class_name, method_name))
except Exception as e:
if type(e).__name__ == 'JsonRpcInvalidParamsError':
raise
diff --git a/lib/vdsm/rpc/Bridge.py b/lib/vdsm/rpc/Bridge.py
index 79afb66..cb47d69 100644
--- a/lib/vdsm/rpc/Bridge.py
+++ b/lib/vdsm/rpc/Bridge.py
@@ -98,8 +98,8 @@
def dispatch(self, method):
try:
+ self._schema.get_method(method)
className, methodName = method.split('.', 1)
- self._schema.get_method(className, methodName)
except (KeyError, ValueError):
raise yajsonrpc.JsonRpcMethodNotFoundError(method)
return partial(self._dynamicMethod, className, methodName)
diff --git a/tests/vdsmapi_test.py b/tests/vdsmapi_test.py
index 11a22ff..dc483d7 100644
--- a/tests/vdsmapi_test.py
+++ b/tests/vdsmapi_test.py
@@ -114,6 +114,7 @@
params)
self.assertIn('StorageDomainType', e.exception.message)
+ print(e.exception.message)
@api_strict_mode()
def test_list_ret(self):
@@ -301,7 +302,7 @@
def test_missing_method(self):
with self.assertRaises(vdsmapi.MethodNotFound):
- _schema.schema().get_method('Missing_class', 'missing_method')
+ _schema.schema().get_method('missing_method')
def test_missing_type(self):
with self.assertRaises(vdsmapi.TypeNotFound):
--
To view, visit https://gerrit.ovirt.org/55999
To unsubscribe, visit https://gerrit.ovirt.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I31f119b7809ae7536d3cab4de6298c648402614d
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Piotr Kliczewski <piotr.kliczewski at gmail.com>
More information about the vdsm-patches
mailing list