Change in vdsm[master]: schema: externalize api_strict_mode

piotr.kliczewski at gmail.com piotr.kliczewski at gmail.com
Wed Apr 20 09:36:04 UTC 2016


Piotr Kliczewski has uploaded a new change for review.

Change subject: schema: externalize api_strict_mode
......................................................................

schema: externalize api_strict_mode

This patch prepares the code to generate api doc based on yml schema.
During the build process we want run html generation before config
module is created from the template. In order to mitigate missing module
failre we want to pass strict mode setting in ctor instead of getting it
from configuration.


Change-Id: I93dad74177d1991c322988b6bf9f0887701ee47a
Signed-off-by: pkliczewski <piotr.kliczewski at gmail.com>
---
M lib/api/vdsmapi.py
M lib/vdsm/jsonrpcvdscli.py
M lib/vdsm/rpc/Bridge.py
M tests/schemaValidationTest.py
M tests/vdsmapi_test.py
M tests/vmApiTests.py
6 files changed, 15 insertions(+), 27 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/86/56386/1

diff --git a/lib/api/vdsmapi.py b/lib/api/vdsmapi.py
index 7e06579..bef41a5 100644
--- a/lib/api/vdsmapi.py
+++ b/lib/api/vdsmapi.py
@@ -25,7 +25,6 @@
 import six
 import yaml
 
-from vdsm.config import config
 from yajsonrpc import JsonRpcInvalidParamsError
 
 
@@ -77,8 +76,8 @@
 
     log = logging.getLogger("SchemaCache")
 
-    def __init__(self, paths):
-        self._strict_mode = config.getboolean('devel', 'api_strict_mode')
+    def __init__(self, paths, mode):
+        self._strict_mode = mode
         self._methods = {}
         self._types = {}
         try:
diff --git a/lib/vdsm/jsonrpcvdscli.py b/lib/vdsm/jsonrpcvdscli.py
index 5c03539..8860e10 100644
--- a/lib/vdsm/jsonrpcvdscli.py
+++ b/lib/vdsm/jsonrpcvdscli.py
@@ -70,7 +70,9 @@
 class _Server(object):
 
     def __init__(self, client, xml_compat):
-        self._schema = vdsmapi.Schema([vdsmapi.find_schema()])
+        api_strict_mode = config.getboolean('devel', 'api_strict_mode')
+        self._schema = vdsmapi.Schema([vdsmapi.find_schema()],
+                                      api_strict_mode)
         self._client = client
         self._xml_compat = xml_compat
         self._default_timeout = CALL_TIMEOUT
diff --git a/lib/vdsm/rpc/Bridge.py b/lib/vdsm/rpc/Bridge.py
index c69a971..514f8fb 100644
--- a/lib/vdsm/rpc/Bridge.py
+++ b/lib/vdsm/rpc/Bridge.py
@@ -25,6 +25,7 @@
 import yajsonrpc
 from api import vdsmapi
 
+from vdsm.config import config
 from vdsm.netinfo.addresses import getDeviceByIP
 from vdsm.exception import VdsmException
 
@@ -61,12 +62,14 @@
 class DynamicBridge(object):
     def __init__(self):
         paths = [vdsmapi.find_schema()]
+        api_strict_mode = config.getboolean('devel', 'api_strict_mode')
         if _glusterEnabled:
             paths.append(vdsmapi.find_schema('vdsm-api-gluster'))
-        self._schema = vdsmapi.Schema(paths)
+        self._schema = vdsmapi.Schema(paths, api_strict_mode)
 
         self._event_schema = vdsmapi.Schema(
-            [vdsmapi.find_schema('vdsm-events')])
+            [vdsmapi.find_schema('vdsm-events')],
+            api_strict_mode)
 
         self._threadLocal = threading.local()
         self.log = logging.getLogger('DynamicBridge')
diff --git a/tests/schemaValidationTest.py b/tests/schemaValidationTest.py
index 28fbe88..d8358e5 100644
--- a/tests/schemaValidationTest.py
+++ b/tests/schemaValidationTest.py
@@ -96,7 +96,7 @@
         with schema_not_found():
             path = vdsmapi.find_schema()
             gluster_path = vdsmapi.find_schema('vdsm-api-gluster')
-            schema = vdsmapi.Schema([path, gluster_path])
+            schema = vdsmapi.Schema([path, gluster_path], True)
 
             for class_name, class_obj in self._get_api_classes(api_mod):
                 apiObj = getattr(api_mod, class_name)
diff --git a/tests/vdsmapi_test.py b/tests/vdsmapi_test.py
index 5a2470d..e521ee3 100644
--- a/tests/vdsmapi_test.py
+++ b/tests/vdsmapi_test.py
@@ -22,8 +22,7 @@
 from api import vdsmapi
 from yajsonrpc import JsonRpcError
 
-from monkeypatch import MonkeyPatch
-from testlib import VdsmTestCase as TestCaseBase, make_config
+from testlib import VdsmTestCase as TestCaseBase
 
 try:
     import gluster.apiwrapper as gapi
@@ -31,11 +30,6 @@
     gapi
 except ImportError:
     _glusterEnabled = False
-
-
-def api_strict_mode():
-        return MonkeyPatch(vdsmapi, 'config', make_config(
-            [('devel', 'api_strict_mode', 'true')]))
 
 
 class SchemaWrapper(object):
@@ -49,13 +43,13 @@
             paths = [vdsmapi.find_schema()]
             if _glusterEnabled:
                 paths.append(vdsmapi.find_schema('vdsm-api-gluster'))
-            self._schema = vdsmapi.Schema(paths)
+            self._schema = vdsmapi.Schema(paths, True)
         return self._schema
 
     def events_schema(self):
         if self._events_schema is None:
             path = [vdsmapi.find_schema('vdsm-events')]
-            self._events_schema = vdsmapi.Schema(path)
+            self._events_schema = vdsmapi.Schema(path, True)
         return self._events_schema
 
 
@@ -65,7 +59,6 @@
 
 class DataVerificationTests(TestCaseBase):
 
-    @api_strict_mode()
     def test_optional_params(self):
         params = {u"addr": u"rack05-pdu01-lab4.tlv.redhat.com", u"port": 54321,
                   u"agent": u"apc_snmp", u"username": u"emesika",
@@ -74,13 +67,11 @@
 
         _schema.schema().verify_params('Host', 'fenceNode', params)
 
-    @api_strict_mode()
     def test_ok_response(self):
         ret = {u'power': u'on'}
 
         _schema.schema().verify_retval('Host', 'fenceNode', ret)
 
-    @api_strict_mode()
     def test_unknown_response_type(self):
         with self.assertRaises(JsonRpcError) as e:
             ret = {u'My caps': u'My capabilites'}
@@ -89,7 +80,6 @@
 
         self.assertIn('My caps', e.exception.message)
 
-    @api_strict_mode()
     def test_unknown_param(self):
         params = {u"storagepoolID": u"00000002-0002-0002-0002-0000000000f6",
                   u"onlyForce": True,
@@ -100,7 +90,6 @@
 
         self.assertIn('onlyForce', e.exception.message)
 
-    @api_strict_mode()
     def test_wrong_param_type(self):
         params = {u"storagepoolID": u"00000000-0000-0000-0000-000000000000",
                   u"domainType": u"1",
@@ -117,14 +106,12 @@
         self.assertIn('StorageDomainType', e.exception.message)
         print(e.exception.message)
 
-    @api_strict_mode()
     def test_list_ret(self):
         ret = [{u"status": 0, u"id": u"f6de012c-be35-47cb-94fb-f01074a5f9ef"}]
 
         _schema.schema().verify_retval('StoragePool',
                                        'disconnectStorageServer', ret)
 
-    @api_strict_mode()
     def test_complex_ret_type(self):
         ret = {u"cpuStatistics": {u"1": {u"cpuUser": 1.47,
                                          u"numaNodeIndex": 0,
@@ -279,7 +266,6 @@
 
         _schema.schema().verify_retval('Host', 'getStats', ret)
 
-    @api_strict_mode()
     def test_badly_defined_ret_type(self):
         ret = {u'pci_0000_00_1b_0':
                {u'params':
@@ -309,8 +295,6 @@
         with self.assertRaises(vdsmapi.TypeNotFound):
             _schema.schema().get_type('Missing_type')
 
-    @MonkeyPatch(vdsmapi, 'config',
-                 make_config([('devel', 'api_strict_mode', 'true')]))
     def test_events_params(self):
         params = {u"notify_time": 4303947020,
                   u"426aef82-ea1d-4442-91d3-fd876540e0f0":
diff --git a/tests/vmApiTests.py b/tests/vmApiTests.py
index 2f32e8c..32b352f 100644
--- a/tests/vmApiTests.py
+++ b/tests/vmApiTests.py
@@ -39,7 +39,7 @@
     @utils.memoized
     def _getAPI(self):
         paths = [vdsmapi.find_schema()]
-        return vdsmapi.Schema(paths)
+        return vdsmapi.Schema(paths, True)
 
     def assertVmStatsSchemaCompliancy(self, schema, stats):
         api = self._getAPI()


-- 
To view, visit https://gerrit.ovirt.org/56386
To unsubscribe, visit https://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I93dad74177d1991c322988b6bf9f0887701ee47a
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