Commit 2c0be3d0 authored by Michael Hanselmann's avatar Michael Hanselmann

Add check for RAPI paths to start with /2

During a discussion in July 2010 it was decided that we'll stabilize on /2. See
message ID <20100716180012.GA9423@google.com> for reference.
Signed-off-by: default avatarMichael Hanselmann <hansmi@google.com>
Reviewed-by: default avatarIustin Pop <iustin@google.com>
parent a9b144cb
......@@ -159,6 +159,10 @@ def GetHandlers(node_name_pattern, instance_name_pattern, job_id_pattern):
"""Returns all supported resources and their handlers.
"""
# Important note: New resources should always be added under /2. During a
# discussion in July 2010 it was decided that having per-resource versions
# is more flexible and future-compatible than versioning the whole remote
# API.
return {
"/": R_root,
......@@ -213,9 +217,9 @@ def GetHandlers(node_name_pattern, instance_name_pattern, job_id_pattern):
rlib2.R_2_instances_name_migrate,
"/2/jobs": rlib2.R_2_jobs,
re.compile(r'/2/jobs/(%s)$' % job_id_pattern):
re.compile(r"^/2/jobs/(%s)$" % job_id_pattern):
rlib2.R_2_jobs_id,
re.compile(r'/2/jobs/(%s)/wait$' % job_id_pattern):
re.compile(r"^/2/jobs/(%s)/wait$" % job_id_pattern):
rlib2.R_2_jobs_id_wait,
"/2/tags": rlib2.R_2_tags,
......
......@@ -92,11 +92,16 @@ class TestDocs(unittest.TestCase):
prevline = line
prefix_exception = frozenset(["/", "/version", "/2"])
undocumented = []
for key, handler in resources.iteritems():
# Regex objects
if hasattr(key, "match"):
self.assert_(key.pattern.startswith("^/2/"),
msg="Pattern %r does not start with '^/2/'" % key.pattern)
found = False
for title in titles:
if (title.startswith("``") and
......@@ -107,10 +112,14 @@ class TestDocs(unittest.TestCase):
if not found:
# TODO: Find better way of identifying resource
undocumented.append(str(handler))
undocumented.append(key.pattern)
else:
self.assert_(key.startswith("/2/") or key in prefix_exception,
msg="Path %r does not start with '/2/'" % key)
elif ("``%s``" % key) not in titles:
undocumented.append(key)
if ("``%s``" % key) not in titles:
undocumented.append(key)
self.failIf(undocumented,
msg=("Missing RAPI resource documentation for %s" %
......
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