Fix failing after refactoring CLI test for execution

After refactoring tests need to wait a little bit more time before
execution will be in 'SUCCESS' state, that's why it was needed to add
extra method that will check execution state and wait for 'Success'.

Change-Id: I4c85d227c171d4b819dd288a00c7fb32258f11ba
Closes-Bug: #1435263
This commit is contained in:
Anastasia Kuznetsova
2015-03-23 13:56:38 +04:00
parent 103e5ecb9a
commit fa636f3479
2 changed files with 31 additions and 4 deletions

View File

@@ -13,6 +13,9 @@
# under the License.
import os
import time
from tempest_lib import exceptions
from mistralclient.tests.functional.cli import base
@@ -161,3 +164,29 @@ class MistralClientTestBase(base.MistralCLIAuth, base.MistralCLIAltAuth):
f.write(file_body)
f.close()
self.addCleanup(os.remove, file_name)
def wait_execution_success(self, exec_id, timeout=180):
start_time = time.time()
ex = self.mistral_admin('execution-get', params=exec_id)
exec_state = self.get_value_of_field(ex, 'State')
expected_states = ['SUCCESS', 'RUNNING']
while exec_state != 'SUCCESS':
if time.time() - start_time > timeout:
msg = ("Execution exceeds timeout {0} to change state "
"to SUCCESS. Execution: {1}".format(timeout, ex))
raise exceptions.TimeoutException(msg)
ex = self.mistral_admin('execution-get', params=exec_id)
exec_state = self.get_value_of_field(ex, 'State')
if exec_state not in expected_states:
msg = ("Execution state %s is not in expected "
"states: %s" % (exec_state, expected_states))
raise exceptions.TempestException(msg)
time.sleep(2)
return True

View File

@@ -301,10 +301,8 @@ class ExecutionCLITests(base_v2.MistralClientTestBase):
"%s input task_name" % self.reverse_wf['Name'])
exec_id = self.get_value_of_field(execution, 'ID')
execution = self.mistral_admin(
'execution-get', params=exec_id)
exec_state = self.get_value_of_field(execution, 'State')
self.assertEqual('SUCCESS', exec_state)
result = self.wait_execution_success(exec_id)
self.assertTrue(result)
def test_execution_update(self):
execution = self.execution_create(self.direct_wf['Name'])