Revision bf968b7f test/docs_unittest.py

b/test/docs_unittest.py
26 26

  
27 27
from ganeti import utils
28 28
from ganeti import cmdlib
29
from ganeti.rapi import connector
29 30

  
30 31
import testutils
31 32

  
......
66 67
                      (lucls.HTYPE, lucls.HPATH)))
67 68

  
68 69

  
70
  def testRapiDocs(self):
71
    """Check whether all RAPI resources are documented.
72

  
73
    """
74
    rapidoc = self._ReadDocFile("rapi.rst")
75

  
76
    node_name = "[node_name]"
77
    instance_name = "[instance_name]"
78
    job_id = "[job_id]"
79

  
80
    resources = connector.GetHandlers(re.escape(node_name),
81
                                      re.escape(instance_name),
82
                                      re.escape(job_id))
83

  
84
    titles = []
85

  
86
    prevline = None
87
    for line in rapidoc.splitlines():
88
      if re.match(r"^\++$", line):
89
        titles.append(prevline)
90

  
91
      prevline = line
92

  
93
    undocumented = []
94

  
95
    for key, handler in resources.iteritems():
96
      # Regex objects
97
      if hasattr(key, "match"):
98
        found = False
99
        for title in titles:
100
          if (title.startswith("``") and
101
              title.endswith("``") and
102
              key.match(title[2:-2])):
103
            found = True
104
            break
105

  
106
        if not found:
107
          # TODO: Find better way of identifying resource
108
          undocumented.append(str(handler))
109

  
110
      elif ("``%s``" % key) not in titles:
111
        undocumented.append(key)
112

  
113
    self.failIf(undocumented,
114
                msg=("Missing RAPI resource documentation for %s" %
115
                     utils.CommaJoin(undocumented)))
116

  
117

  
69 118
if __name__ == "__main__":
70 119
  unittest.main()

Also available in: Unified diff