Commit d9b67f70 authored by Michael Hanselmann's avatar Michael Hanselmann
Browse files

RAPI client: Allow waiting for job changes


Signed-off-by: default avatarMichael Hanselmann <hansmi@google.com>
Reviewed-by: default avatarIustin Pop <iustin@google.com>
parent 793a8f7c
......@@ -760,6 +760,21 @@ class GanetiRapiClient(object):
"""
return self._SendRequest(HTTP_GET, "/2/jobs/%d" % job_id, None, None)
def WaitForJobChange(self, job_id, fields, prev_job_info, prev_log_serial):
"""Waits for job changes.
@type job_id: int
@param job_id: Job ID for which to wait
"""
body = {
"fields": fields,
"previous_job_info": prev_job_info,
"previous_log_serial": prev_log_serial,
}
return self._SendRequest(HTTP_GET, "/2/jobs/%s/wait" % job_id, None, body)
def CancelJob(self, job_id, dry_run=False):
"""Cancels a job.
......
......@@ -27,6 +27,7 @@ import unittest
import warnings
from ganeti import http
from ganeti import serializer
from ganeti.rapi import connector
from ganeti.rapi import rlib2
......@@ -133,12 +134,10 @@ class RapiMockTest(unittest.TestCase):
self.failUnless(isinstance(rapi.GetLastHandler(), rlib2.R_version))
class GanetiRapiClientTests(unittest.TestCase):
"""Tests for remote API client.
"""
class GanetiRapiClientTests(testutils.GanetiTestCase):
def setUp(self):
testutils.GanetiTestCase.setUp(self)
self.rapi = RapiMock()
self.http = OpenerDirectorMock(self.rapi)
self.client = client.GanetiRapiClient('master.foo.com')
......@@ -324,6 +323,19 @@ class GanetiRapiClientTests(unittest.TestCase):
self.assertHandler(rlib2.R_2_jobs_id)
self.assertItems(["1234"])
def testWaitForJobChange(self):
fields = ["id", "summary"]
expected = {
"job_info": [123, "something"],
"log_entries": [],
}
self.rapi.AddResponse(serializer.DumpJson(expected))
result = self.client.WaitForJobChange(123, fields, [], -1)
self.assertEqualValues(expected, result)
self.assertHandler(rlib2.R_2_jobs_id_wait)
self.assertItems(["123"])
def testCancelJob(self):
self.rapi.AddResponse("[true, \"Job 123 will be canceled\"]")
self.assertEqual([True, "Job 123 will be canceled"],
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment