blob: 652800cf8d85079a2e3e7691a3f0c4be9e1422af (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
"""Test to see if docs exists for routes and methods in the placement API."""
import sys
from nova.api.openstack.placement import handler
# A humane ordering of HTTP methods for sorted output.
ORDERED_METHODS = ['GET', 'POST', 'PUT', 'PATCH', 'DELETE']
def _header_line(map_entry):
method, route = map_entry
line = '.. rest_method:: %s %s' % (method, route)
return line
def inspect_doc(doc_file):
"""Load up doc_file and see if any routes are missing.
The routes are defined in handler.ROUTE_DECLARATIONS.
"""
routes = []
for route in sorted(handler.ROUTE_DECLARATIONS, key=len):
# Skip over the '' route.
if route:
for method in ORDERED_METHODS:
if method in handler.ROUTE_DECLARATIONS[route]:
routes.append((method, route))
header_lines = []
for map_entry in routes:
header_lines.append(_header_line(map_entry))
with open(doc_file) as doc_fh:
content_lines = doc_fh.read().splitlines()
missing_lines = []
for line in header_lines:
if line not in content_lines:
missing_lines.append(line)
if missing_lines:
print('Documentation likely missing for the following routes:')
for line in missing_lines:
print(line)
return 1
return 0
if __name__ == '__main__':
doc_file = sys.argv[1]
sys.exit(inspect_doc(doc_file))
|