Commit 70b0d2a2 authored by Michael Hanselmann's avatar Michael Hanselmann
Browse files

Ensure all resources are used by RAPI client

Signed-off-by: default avatarMichael Hanselmann <>
Reviewed-by: default avatarRené Nussbaumer <>
parent b680c8be
......@@ -30,6 +30,7 @@ import pycurl
from ganeti import constants
from ganeti import http
from ganeti import serializer
from ganeti import utils
from ganeti.rapi import connector
from ganeti.rapi import rlib2
......@@ -40,6 +41,15 @@ import testutils
_URI_RE = re.compile(r"https://(?P<host>.*):(?P<port>\d+)(?P<path>/.*)")
# List of resource handlers which aren't used by the RAPI client
# Global variable for collecting used handlers
_used_handlers = None
def _GetPathFromUri(uri):
"""Gets the path and query from a URI.
......@@ -107,8 +117,12 @@ class RapiMock(object):
self._last_req_data = request_body
HandlerClass, items, args = self._mapper.getController(path)
self._last_handler = HandlerClass(items, args, None)
(handler_cls, items, args) = self._mapper.getController(path)
# Record handler as used
self._last_handler = handler_cls(items, args, None)
if not hasattr(self._last_handler, method.upper()):
raise http.HttpNotImplemented(message="Method not implemented")
......@@ -1130,5 +1144,27 @@ class GanetiRapiClientTests(testutils.GanetiTestCase):
self.assertEqual(self.rapi.CountPending(), 0)
class RapiTestRunner(unittest.TextTestRunner):
def run(self, *args):
global _used_handlers
assert _used_handlers is None
_used_handlers = set()
# Run actual tests
result =, *args)
diff = (set(connector.CONNECTOR.values()) - _used_handlers -
if diff:
raise AssertionError("The following RAPI resources were not used by the"
" RAPI client: %r" % utils.CommaJoin(diff))
# Reset global variable
_used_handlers = None
return result
if __name__ == '__main__':
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment