Revision 3af47e13 test/docs_unittest.py
b/test/docs_unittest.py | ||
---|---|---|
28 | 28 |
from ganeti import utils |
29 | 29 |
from ganeti import cmdlib |
30 | 30 |
from ganeti import build |
31 |
from ganeti import compat |
|
31 | 32 |
from ganeti.rapi import connector |
32 | 33 |
|
33 | 34 |
import testutils |
34 | 35 |
|
35 | 36 |
|
37 |
VALID_URI_RE = re.compile(r"^[-/a-z0-9]*$") |
|
38 |
|
|
39 |
|
|
36 | 40 |
class TestDocs(unittest.TestCase): |
37 | 41 |
"""Documentation tests""" |
38 | 42 |
|
... | ... | |
68 | 72 |
msg=("Missing documentation for hook %s/%s" % |
69 | 73 |
(lucls.HTYPE, lucls.HPATH))) |
70 | 74 |
|
75 |
def _CheckRapiResource(self, uri, fixup): |
|
76 |
# Apply fixes before testing |
|
77 |
for (rx, value) in fixup.items(): |
|
78 |
uri = rx.sub(value, uri) |
|
79 |
|
|
80 |
self.assertTrue(VALID_URI_RE.match(uri), msg="Invalid URI %r" % uri) |
|
71 | 81 |
|
72 | 82 |
def testRapiDocs(self): |
73 | 83 |
"""Check whether all RAPI resources are documented. |
... | ... | |
75 | 85 |
""" |
76 | 86 |
rapidoc = self._ReadDocFile("rapi.rst") |
77 | 87 |
|
78 |
node_name = "[node_name]" |
|
79 |
instance_name = "[instance_name]" |
|
80 |
group_name = "[group_name]" |
|
81 |
job_id = "[job_id]" |
|
82 |
disk_index = "[disk_index]" |
|
88 |
node_name = re.escape("[node_name]") |
|
89 |
instance_name = re.escape("[instance_name]") |
|
90 |
group_name = re.escape("[group_name]") |
|
91 |
job_id = re.escape("[job_id]") |
|
92 |
disk_index = re.escape("[disk_index]") |
|
93 |
|
|
94 |
resources = connector.GetHandlers(node_name, instance_name, group_name, |
|
95 |
job_id, disk_index) |
|
96 |
|
|
97 |
uri_check_fixup = { |
|
98 |
re.compile(node_name): "node1examplecom", |
|
99 |
re.compile(instance_name): "inst1examplecom", |
|
100 |
re.compile(group_name): "group4440", |
|
101 |
re.compile(job_id): "9409", |
|
102 |
re.compile(disk_index): "123", |
|
103 |
} |
|
83 | 104 |
|
84 |
resources = connector.GetHandlers(re.escape(node_name), |
|
85 |
re.escape(instance_name), |
|
86 |
re.escape(group_name), |
|
87 |
re.escape(job_id), |
|
88 |
re.escape(disk_index)) |
|
105 |
assert compat.all(VALID_URI_RE.match(value) |
|
106 |
for value in uri_check_fixup.values()), \ |
|
107 |
"Fixup values must be valid URIs, too" |
|
89 | 108 |
|
90 | 109 |
titles = [] |
91 | 110 |
|
... | ... | |
105 | 124 |
if hasattr(key, "match"): |
106 | 125 |
self.assert_(key.pattern.startswith("^/2/"), |
107 | 126 |
msg="Pattern %r does not start with '^/2/'" % key.pattern) |
127 |
self.assertEqual(key.pattern[-1], "$") |
|
108 | 128 |
|
109 | 129 |
found = False |
110 | 130 |
for title in titles: |
111 |
if (title.startswith("``") and |
|
112 |
title.endswith("``") and |
|
113 |
key.match(title[2:-2])): |
|
114 |
found = True |
|
115 |
break |
|
131 |
if title.startswith("``") and title.endswith("``"): |
|
132 |
uri = title[2:-2] |
|
133 |
if key.match(uri): |
|
134 |
self._CheckRapiResource(uri, uri_check_fixup) |
|
135 |
found = True |
|
136 |
break |
|
116 | 137 |
|
117 | 138 |
if not found: |
118 | 139 |
# TODO: Find better way of identifying resource |
... | ... | |
122 | 143 |
self.assert_(key.startswith("/2/") or key in prefix_exception, |
123 | 144 |
msg="Path %r does not start with '/2/'" % key) |
124 | 145 |
|
125 |
if ("``%s``" % key) not in titles: |
|
146 |
if ("``%s``" % key) in titles: |
|
147 |
self._CheckRapiResource(key, {}) |
|
148 |
else: |
|
126 | 149 |
undocumented.append(key) |
127 | 150 |
|
128 | 151 |
self.failIf(undocumented, |
Also available in: Unified diff