Skip to content
Snippets Groups Projects
Commit d50a2223 authored by Michael Hanselmann's avatar Michael Hanselmann
Browse files

Check for duplicate RAPI URIs and handlers


Signed-off-by: default avatarMichael Hanselmann <hansmi@google.com>
Reviewed-by: default avatarIustin Pop <iustin@google.com>
parent 70b0d2a2
No related branches found
No related tags found
No related merge requests found
...@@ -99,6 +99,11 @@ class TestDocs(unittest.TestCase): ...@@ -99,6 +99,11 @@ class TestDocs(unittest.TestCase):
resources = connector.GetHandlers(node_name, instance_name, group_name, resources = connector.GetHandlers(node_name, instance_name, group_name,
job_id, disk_index) job_id, disk_index)
handler_dups = utils.FindDuplicates(resources.values())
self.assertFalse(handler_dups,
msg=("Resource handlers used more than once: %r" %
handler_dups))
uri_check_fixup = { uri_check_fixup = {
re.compile(node_name): "node1examplecom", re.compile(node_name): "node1examplecom",
re.compile(instance_name): "inst1examplecom", re.compile(instance_name): "inst1examplecom",
...@@ -123,6 +128,7 @@ class TestDocs(unittest.TestCase): ...@@ -123,6 +128,7 @@ class TestDocs(unittest.TestCase):
prefix_exception = frozenset(["/", "/version", "/2"]) prefix_exception = frozenset(["/", "/version", "/2"])
undocumented = [] undocumented = []
used_uris = []
for key, handler in resources.iteritems(): for key, handler in resources.iteritems():
# Regex objects # Regex objects
...@@ -137,6 +143,7 @@ class TestDocs(unittest.TestCase): ...@@ -137,6 +143,7 @@ class TestDocs(unittest.TestCase):
uri = title[2:-2] uri = title[2:-2]
if key.match(uri): if key.match(uri):
self._CheckRapiResource(uri, uri_check_fixup, handler) self._CheckRapiResource(uri, uri_check_fixup, handler)
used_uris.append(uri)
found = True found = True
break break
...@@ -150,6 +157,7 @@ class TestDocs(unittest.TestCase): ...@@ -150,6 +157,7 @@ class TestDocs(unittest.TestCase):
if ("``%s``" % key) in titles: if ("``%s``" % key) in titles:
self._CheckRapiResource(key, {}, handler) self._CheckRapiResource(key, {}, handler)
used_uris.append(key)
else: else:
undocumented.append(key) undocumented.append(key)
...@@ -157,6 +165,11 @@ class TestDocs(unittest.TestCase): ...@@ -157,6 +165,11 @@ class TestDocs(unittest.TestCase):
msg=("Missing RAPI resource documentation for %s" % msg=("Missing RAPI resource documentation for %s" %
utils.CommaJoin(undocumented))) utils.CommaJoin(undocumented)))
uri_dups = utils.FindDuplicates(used_uris)
self.failIf(uri_dups,
msg=("URIs matched by more than one resource: %s" %
utils.CommaJoin(uri_dups)))
class TestManpages(unittest.TestCase): class TestManpages(unittest.TestCase):
"""Manpage tests""" """Manpage tests"""
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment