Revision 1afa108c test/ganeti.rapi.testutils_unittest.py
b/test/ganeti.rapi.testutils_unittest.py | ||
---|---|---|
27 | 27 |
from ganeti import constants |
28 | 28 |
from ganeti import errors |
29 | 29 |
from ganeti import opcodes |
30 |
from ganeti import luxi |
|
30 | 31 |
from ganeti import rapi |
32 |
from ganeti import utils |
|
31 | 33 |
|
32 | 34 |
import ganeti.rapi.testutils |
35 |
import ganeti.rapi.client |
|
33 | 36 |
|
34 | 37 |
import testutils |
35 | 38 |
|
36 | 39 |
|
40 |
KNOWN_UNUSED_LUXI = frozenset([ |
|
41 |
luxi.REQ_SUBMIT_MANY_JOBS, |
|
42 |
luxi.REQ_ARCHIVE_JOB, |
|
43 |
luxi.REQ_AUTOARCHIVE_JOBS, |
|
44 |
luxi.REQ_QUERY_EXPORTS, |
|
45 |
luxi.REQ_QUERY_CONFIG_VALUES, |
|
46 |
luxi.REQ_QUERY_TAGS, |
|
47 |
luxi.REQ_QUEUE_SET_DRAIN_FLAG, |
|
48 |
luxi.REQ_SET_WATCHER_PAUSE, |
|
49 |
]) |
|
50 |
|
|
51 |
|
|
52 |
# Global variable for storing used LUXI calls |
|
53 |
_used_luxi_calls = None |
|
54 |
|
|
55 |
|
|
37 | 56 |
class TestHideInternalErrors(unittest.TestCase): |
38 | 57 |
def test(self): |
39 | 58 |
def inner(): |
... | ... | |
96 | 115 |
vor(opcodes.OpTestDummy.OP_ID, None) |
97 | 116 |
|
98 | 117 |
|
118 |
class TestInputTestClient(unittest.TestCase): |
|
119 |
def setUp(self): |
|
120 |
self.cl = rapi.testutils.InputTestClient() |
|
121 |
|
|
122 |
def tearDown(self): |
|
123 |
_used_luxi_calls.update(self.cl._GetLuxiCalls()) |
|
124 |
|
|
125 |
def testGetInfo(self): |
|
126 |
self.assertTrue(self.cl.GetInfo() is NotImplemented) |
|
127 |
|
|
128 |
def testPrepareExport(self): |
|
129 |
result = self.cl.PrepareExport("inst1.example.com", |
|
130 |
constants.EXPORT_MODE_LOCAL) |
|
131 |
self.assertTrue(result is NotImplemented) |
|
132 |
self.assertRaises(rapi.client.GanetiApiError, self.cl.PrepareExport, |
|
133 |
"inst1.example.com", "###invalid###") |
|
134 |
|
|
135 |
def testGetJobs(self): |
|
136 |
self.assertTrue(self.cl.GetJobs() is NotImplemented) |
|
137 |
|
|
138 |
def testQuery(self): |
|
139 |
result = self.cl.Query(constants.QR_NODE, ["name"]) |
|
140 |
self.assertTrue(result is NotImplemented) |
|
141 |
|
|
142 |
def testQueryFields(self): |
|
143 |
result = self.cl.QueryFields(constants.QR_INSTANCE) |
|
144 |
self.assertTrue(result is NotImplemented) |
|
145 |
|
|
146 |
def testCancelJob(self): |
|
147 |
self.assertTrue(self.cl.CancelJob("1") is NotImplemented) |
|
148 |
|
|
149 |
def testGetNodes(self): |
|
150 |
self.assertTrue(self.cl.GetNodes() is NotImplemented) |
|
151 |
|
|
152 |
def testGetInstances(self): |
|
153 |
self.assertTrue(self.cl.GetInstances() is NotImplemented) |
|
154 |
|
|
155 |
def testGetGroups(self): |
|
156 |
self.assertTrue(self.cl.GetGroups() is NotImplemented) |
|
157 |
|
|
158 |
def testWaitForJobChange(self): |
|
159 |
result = self.cl.WaitForJobChange("1", ["id"], None, None) |
|
160 |
self.assertTrue(result is NotImplemented) |
|
161 |
|
|
162 |
|
|
163 |
class CustomTestRunner(unittest.TextTestRunner): |
|
164 |
def run(self, *args): |
|
165 |
global _used_luxi_calls |
|
166 |
assert _used_luxi_calls is None |
|
167 |
|
|
168 |
diff = (KNOWN_UNUSED_LUXI - luxi.REQ_ALL) |
|
169 |
assert not diff, "Non-existing LUXI calls listed as unused: %s" % diff |
|
170 |
|
|
171 |
_used_luxi_calls = set() |
|
172 |
try: |
|
173 |
# Run actual tests |
|
174 |
result = unittest.TextTestRunner.run(self, *args) |
|
175 |
|
|
176 |
diff = _used_luxi_calls & KNOWN_UNUSED_LUXI |
|
177 |
if diff: |
|
178 |
raise AssertionError("LUXI methods marked as unused were called: %s" % |
|
179 |
utils.CommaJoin(diff)) |
|
180 |
|
|
181 |
diff = (luxi.REQ_ALL - KNOWN_UNUSED_LUXI - _used_luxi_calls) |
|
182 |
if diff: |
|
183 |
raise AssertionError("The following LUXI methods were not used: %s" % |
|
184 |
utils.CommaJoin(diff)) |
|
185 |
finally: |
|
186 |
# Reset global variable |
|
187 |
_used_luxi_calls = None |
|
188 |
|
|
189 |
return result |
|
190 |
|
|
191 |
|
|
99 | 192 |
if __name__ == "__main__": |
100 |
testutils.GanetiTestProgram() |
|
193 |
testutils.GanetiTestProgram(testRunner=CustomTestRunner) |
Also available in: Unified diff