limit the agent to a single concurrent command
This commit is contained in:
parent
37662a2933
commit
92a34f4b3f
@ -72,6 +72,9 @@ class BaseCommandResult(encoding.Serializable):
|
||||
('command_result', self.command_result),
|
||||
])
|
||||
|
||||
def is_done(self):
|
||||
return self.command_status != AgentCommandStatus.RUNNING
|
||||
|
||||
|
||||
class SyncCommandResult(BaseCommandResult):
|
||||
def __init__(self, command_name, command_params, success, result_or_error):
|
||||
@ -109,6 +112,10 @@ class AsyncCommandResult(BaseCommandResult):
|
||||
self.execution_thread.join()
|
||||
return self
|
||||
|
||||
def is_done(self):
|
||||
with self.command_state_lock:
|
||||
return super(AsyncCommandResult, self).is_done()
|
||||
|
||||
def run(self):
|
||||
try:
|
||||
result = self.execute()
|
||||
@ -224,6 +231,11 @@ class BaseTeethAgent(object):
|
||||
|
||||
def execute_command(self, command_name, **kwargs):
|
||||
"""Execute an agent command."""
|
||||
if len(self.command_results) > 0:
|
||||
last_command = self.command_results.values()[-1]
|
||||
if not last_command.is_done():
|
||||
raise errors.CommandExecutionError('agent is busy')
|
||||
|
||||
if command_name not in self.command_map:
|
||||
raise errors.InvalidCommandError(command_name)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user