mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
testclient: fix fix asyn job query for sync command
This commit is contained in:
parent
f8aaf1a126
commit
9777b7d193
@ -20,21 +20,25 @@ class jobStatus(object):
|
|||||||
self.jobId = None
|
self.jobId = None
|
||||||
self.responsecls = None
|
self.responsecls = None
|
||||||
class workThread(threading.Thread):
|
class workThread(threading.Thread):
|
||||||
def __init__(self, in_queue, outqueue, apiClient, db=None):
|
def __init__(self, in_queue, outqueue, apiClient, db=None, lock=None):
|
||||||
threading.Thread.__init__(self)
|
threading.Thread.__init__(self)
|
||||||
self.inqueue = in_queue
|
self.inqueue = in_queue
|
||||||
self.output = outqueue
|
self.output = outqueue
|
||||||
self.connection = copy.copy(apiClient.connection)
|
self.connection = apiClient.connection
|
||||||
self.db = None
|
self.db = None
|
||||||
|
self.lock = lock
|
||||||
|
|
||||||
def queryAsynJob(self, job):
|
def queryAsynJob(self, job):
|
||||||
if job.jobId is None:
|
if job.jobId is None:
|
||||||
return job
|
return job
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
self.lock.acquire()
|
||||||
result = self.connection.pollAsyncJob(job.jobId, job.responsecls).jobresult
|
result = self.connection.pollAsyncJob(job.jobId, job.responsecls).jobresult
|
||||||
except cloudstackException.cloudstackAPIException, e:
|
except cloudstackException.cloudstackAPIException, e:
|
||||||
result = str(e)
|
result = str(e)
|
||||||
|
finally:
|
||||||
|
self.lock.release()
|
||||||
|
|
||||||
job.result = result
|
job.result = result
|
||||||
return job
|
return job
|
||||||
@ -45,8 +49,11 @@ class workThread(threading.Thread):
|
|||||||
jobstatus = jobStatus()
|
jobstatus = jobStatus()
|
||||||
jobId = None
|
jobId = None
|
||||||
try:
|
try:
|
||||||
if not cmd.isAsync:
|
self.lock.acquire()
|
||||||
|
|
||||||
|
if cmd.isAsync == "false":
|
||||||
jobstatus.startTime = time.time()
|
jobstatus.startTime = time.time()
|
||||||
|
|
||||||
result = self.connection.make_request(cmd)
|
result = self.connection.make_request(cmd)
|
||||||
jobstatus.result = result
|
jobstatus.result = result
|
||||||
jobstatus.endTime = time.time()
|
jobstatus.endTime = time.time()
|
||||||
@ -69,6 +76,9 @@ class workThread(threading.Thread):
|
|||||||
except:
|
except:
|
||||||
jobstatus.status = False
|
jobstatus.status = False
|
||||||
jobstatus.result = sys.exc_info()
|
jobstatus.result = sys.exc_info()
|
||||||
|
finally:
|
||||||
|
self.lock.release()
|
||||||
|
|
||||||
return jobstatus
|
return jobstatus
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
@ -146,11 +156,11 @@ class asyncJobMgr(object):
|
|||||||
|
|
||||||
def waitForComplete(self, workers=10):
|
def waitForComplete(self, workers=10):
|
||||||
self.inqueue.join()
|
self.inqueue.join()
|
||||||
|
lock = threading.Lock()
|
||||||
resultQueue = Queue.Queue()
|
resultQueue = Queue.Queue()
|
||||||
'''intermediate result is stored in self.outqueue'''
|
'''intermediate result is stored in self.outqueue'''
|
||||||
for i in range(workers):
|
for i in range(workers):
|
||||||
worker = workThread(self.outqueue, resultQueue, self.apiClient, self.db)
|
worker = workThread(self.outqueue, resultQueue, self.apiClient, self.db, lock)
|
||||||
worker.start()
|
worker.start()
|
||||||
|
|
||||||
self.outqueue.join()
|
self.outqueue.join()
|
||||||
@ -166,9 +176,9 @@ class asyncJobMgr(object):
|
|||||||
'''put commands into a queue at first, then start workers numbers threads to execute this commands'''
|
'''put commands into a queue at first, then start workers numbers threads to execute this commands'''
|
||||||
def submitCmdsAndWait(self, cmds, workers=10):
|
def submitCmdsAndWait(self, cmds, workers=10):
|
||||||
self.submitCmds(cmds)
|
self.submitCmds(cmds)
|
||||||
|
lock = threading.Lock()
|
||||||
for i in range(workers):
|
for i in range(workers):
|
||||||
worker = workThread(self.inqueue, self.outqueue, self.apiClient, self.db)
|
worker = workThread(self.inqueue, self.outqueue, self.apiClient, self.db, lock)
|
||||||
worker.start()
|
worker.start()
|
||||||
|
|
||||||
return self.waitForComplete(workers)
|
return self.waitForComplete(workers)
|
||||||
|
|||||||
@ -114,7 +114,7 @@ class cloudConnection(object):
|
|||||||
i = i + 1
|
i = i + 1
|
||||||
|
|
||||||
if self.logging is not None:
|
if self.logging is not None:
|
||||||
self.logging.debug("sending command: " + str(requests))
|
self.logging.debug("sending command: %s %s"%(commandName, str(requests)))
|
||||||
result = None
|
result = None
|
||||||
if self.auth:
|
if self.auth:
|
||||||
result = self.make_request_with_auth(commandName, requests)
|
result = self.make_request_with_auth(commandName, requests)
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
from cloudstackTestCase import *
|
from cloudstackTestCase import *
|
||||||
|
|
||||||
class TestCase1(cloudstackTestCase):
|
class TestCase1(cloudstackTestCase):
|
||||||
|
@unittest.skip("demonstrating skipping")
|
||||||
def test_cloudstackapi(self):
|
def test_cloudstackapi(self):
|
||||||
apiClient = self.testClient.getApiClient()
|
apiClient = self.testClient.getApiClient()
|
||||||
listtmcmd = listTemplates.listTemplatesCmd()
|
listtmcmd = listTemplates.listTemplatesCmd()
|
||||||
|
|||||||
@ -7,5 +7,18 @@ class TestCase2(cloudstackTestCase):
|
|||||||
listtmcmd.id = 10
|
listtmcmd.id = 10
|
||||||
listtmcmd.zoneid = 1
|
listtmcmd.zoneid = 1
|
||||||
listtmcmd.templatefilter = "featured"
|
listtmcmd.templatefilter = "featured"
|
||||||
listtmresponse = apiClient.listTemplates(listtmcmd)
|
#listtmresponse = apiClient.listTemplates(listtmcmd)
|
||||||
self.debug(listtmresponse[0].isready)
|
#self.debug(listtmresponse[0].isready)
|
||||||
|
|
||||||
|
listhostcmd=listHosts.listHostsCmd()
|
||||||
|
listhostcmd.zoneid=1
|
||||||
|
listhostcmd.type="Routing"
|
||||||
|
|
||||||
|
asyncJobResult=self.testClient.submitCmdsAndWait([listhostcmd],1)
|
||||||
|
listVMresponse = asyncJobResult[0].result
|
||||||
|
self.debug("Total Number of Hosts: " + str(len(listVMresponse)))
|
||||||
|
|
||||||
|
'''
|
||||||
|
for i in listhostresponse:
|
||||||
|
self.debug("id: " + i.id +" pod id: " + i.podid +" host tag: " + i.hosttags)
|
||||||
|
'''
|
||||||
@ -26,6 +26,7 @@ class TestCase1(cloudstackTestCase):
|
|||||||
self.zoneId = tmpl.zoneid
|
self.zoneId = tmpl.zoneid
|
||||||
break
|
break
|
||||||
|
|
||||||
|
@unittest.skip("demonstrating skipping")
|
||||||
def test_cloudstackapi(self):
|
def test_cloudstackapi(self):
|
||||||
apiClient = self.testClient.getApiClient()
|
apiClient = self.testClient.getApiClient()
|
||||||
|
|
||||||
@ -73,7 +74,7 @@ class TestCase1(cloudstackTestCase):
|
|||||||
createvm.zoneid = self.zoneId
|
createvm.zoneid = self.zoneId
|
||||||
vmcmds.append(createvm)
|
vmcmds.append(createvm)
|
||||||
|
|
||||||
result = self.testClient.submitCmdsAndWait(vmcmds)
|
result = self.testClient.submitCmdsAndWait(vmcmds, 5)
|
||||||
for jobstatus in result:
|
for jobstatus in result:
|
||||||
if jobstatus.status == 1:
|
if jobstatus.status == 1:
|
||||||
self.debug(jobstatus.result.id)
|
self.debug(jobstatus.result.id)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user