Add the task waiter for test_services_reconfiguration

The nailgun validator for openstack config raises an exception
when 'deployment' task is present for particular cluster
and has 'pending' or 'running' state, so, we should implement
equivalent check on fuel-qa side.

Change-Id: I720e8fcd21907c64b393bc933056aef61167b25f
Closes-Bug: #1618880
This commit is contained in:
Alisa Tselovalnikova 2016-09-29 12:41:01 +03:00
parent 4a045267f0
commit c47aa7ea7a
2 changed files with 32 additions and 11 deletions

View File

@ -36,6 +36,7 @@ from keystoneauth1 import exceptions
from keystoneauth1.identity import V2Password
from keystoneauth1.session import Session as KeystoneSession
import netaddr
import six
from proboscis.asserts import assert_equal
from proboscis.asserts import assert_false
from proboscis.asserts import assert_is_not_none
@ -1024,12 +1025,28 @@ class FuelWebClient29(object):
@logwrap
def get_last_task_id(self, cluster_id, task_name):
tasks = self.client.get_tasks()
tasks_ids = []
filtered_tasks = self.filter_tasks(self.client.get_tasks(),
cluster=cluster_id,
name=task_name)
return max([task['id'] for task in filtered_tasks])
@staticmethod
@logwrap
def filter_tasks(tasks, **filters):
res = []
for task in tasks:
if task['cluster'] == cluster_id and task['name'] == task_name:
tasks_ids.append(task['id'])
return min(tasks_ids)
for f_key, f_value in six.iteritems(filters):
if task.get(f_key) != f_value:
break
else:
res.append(task)
return res
@logwrap
def wait_for_tasks_presence(self, get_tasks, **filters):
wait(lambda: self.filter_tasks(get_tasks(), **filters),
timeout=300,
timeout_msg="Timeout exceeded while waiting for tasks.")
def deploy_cluster_wait_progress(self, cluster_id, progress,
return_task=None):
@ -1386,14 +1403,15 @@ class FuelWebClient29(object):
timeout=timeout)
@logwrap
def task_wait(self, task, timeout, interval=5):
def task_wait(self, task, timeout, interval=5, states=None):
# check task is finished by default
states = states or ('ready', 'error')
logger.info('Wait for task {0} seconds: {1}'.format(
timeout, pretty_log(task, indent=1)))
start = time.time()
wait(
lambda: (self.client.get_task(task['id'])['status']
not in ('pending', 'running')),
lambda: (self.client.get_task(task['id'])['status'] in states),
interval=interval,
timeout=timeout,
timeout_msg='Waiting task {0!r} timeout {1} sec '
@ -1401,9 +1419,8 @@ class FuelWebClient29(object):
took = time.time() - start
task = self.client.get_task(task['id'])
logger.info('Task finished. Took {0} seconds. {1}'.format(
took,
pretty_log(task, indent=1)))
logger.info('Task changed its state to one of {}. Took {} seconds.'
' {}'.format(states, took, pretty_log(task, indent=1)))
return task
@logwrap

View File

@ -1189,6 +1189,10 @@ class ServicesReconfiguration(TestBasic):
self.show_step(3)
task = self.fuel_web.deploy_cluster(cluster_id)
# wait for creation of child 'deployment' task
self.fuel_web.wait_for_tasks_presence(self.fuel_web.client.get_tasks,
name='deployment',
parent_id=task.get('id'))
self.show_step(4)
self.show_step(5)