Revision d9b67f70
b/lib/rapi/client.py | ||
---|---|---|
760 | 760 |
""" |
761 | 761 |
return self._SendRequest(HTTP_GET, "/2/jobs/%d" % job_id, None, None) |
762 | 762 |
|
763 |
def WaitForJobChange(self, job_id, fields, prev_job_info, prev_log_serial): |
|
764 |
"""Waits for job changes. |
|
765 |
|
|
766 |
@type job_id: int |
|
767 |
@param job_id: Job ID for which to wait |
|
768 |
|
|
769 |
""" |
|
770 |
body = { |
|
771 |
"fields": fields, |
|
772 |
"previous_job_info": prev_job_info, |
|
773 |
"previous_log_serial": prev_log_serial, |
|
774 |
} |
|
775 |
|
|
776 |
return self._SendRequest(HTTP_GET, "/2/jobs/%s/wait" % job_id, None, body) |
|
777 |
|
|
763 | 778 |
def CancelJob(self, job_id, dry_run=False): |
764 | 779 |
"""Cancels a job. |
765 | 780 |
|
b/test/ganeti.rapi.client_unittest.py | ||
---|---|---|
27 | 27 |
import warnings |
28 | 28 |
|
29 | 29 |
from ganeti import http |
30 |
from ganeti import serializer |
|
30 | 31 |
|
31 | 32 |
from ganeti.rapi import connector |
32 | 33 |
from ganeti.rapi import rlib2 |
... | ... | |
133 | 134 |
self.failUnless(isinstance(rapi.GetLastHandler(), rlib2.R_version)) |
134 | 135 |
|
135 | 136 |
|
136 |
class GanetiRapiClientTests(unittest.TestCase): |
|
137 |
"""Tests for remote API client. |
|
138 |
|
|
139 |
""" |
|
140 |
|
|
137 |
class GanetiRapiClientTests(testutils.GanetiTestCase): |
|
141 | 138 |
def setUp(self): |
139 |
testutils.GanetiTestCase.setUp(self) |
|
140 |
|
|
142 | 141 |
self.rapi = RapiMock() |
143 | 142 |
self.http = OpenerDirectorMock(self.rapi) |
144 | 143 |
self.client = client.GanetiRapiClient('master.foo.com') |
... | ... | |
324 | 323 |
self.assertHandler(rlib2.R_2_jobs_id) |
325 | 324 |
self.assertItems(["1234"]) |
326 | 325 |
|
326 |
def testWaitForJobChange(self): |
|
327 |
fields = ["id", "summary"] |
|
328 |
expected = { |
|
329 |
"job_info": [123, "something"], |
|
330 |
"log_entries": [], |
|
331 |
} |
|
332 |
|
|
333 |
self.rapi.AddResponse(serializer.DumpJson(expected)) |
|
334 |
result = self.client.WaitForJobChange(123, fields, [], -1) |
|
335 |
self.assertEqualValues(expected, result) |
|
336 |
self.assertHandler(rlib2.R_2_jobs_id_wait) |
|
337 |
self.assertItems(["123"]) |
|
338 |
|
|
327 | 339 |
def testCancelJob(self): |
328 | 340 |
self.rapi.AddResponse("[true, \"Job 123 will be canceled\"]") |
329 | 341 |
self.assertEqual([True, "Job 123 will be canceled"], |
Also available in: Unified diff