Providing more information about fail job

When job if failed, we can see only id. Is not good.
In this patch added information about job(name, type)
closes-bug: #1510611

Change-Id: I83d2f722259ff8e02071f8c74bed71756a856e17
This commit is contained in:
Evgeny Sikachev 2015-10-19 17:39:52 +03:00
parent 9906e4c120
commit beefb27595
3 changed files with 50 additions and 22 deletions

View File

@ -178,14 +178,10 @@ class BaseTestCase(base.BaseTestCase):
@track_result("Check EDP jobs", False) @track_result("Check EDP jobs", False)
def check_run_jobs(self): def check_run_jobs(self):
jobs = {}
batching = self.testcase.get('edp_batching', batching = self.testcase.get('edp_batching',
len(self.testcase['edp_jobs_flow'])) len(self.testcase['edp_jobs_flow']))
batching_size = batching batching_size = batching
if self.testcase['edp_jobs_flow']: jobs = self.testcase.get('edp_jobs_flow', [])
jobs = self.testcase['edp_jobs_flow']
else:
jobs = []
pre_exec = [] pre_exec = []
for job in jobs: for job in jobs:
@ -283,20 +279,38 @@ class BaseTestCase(base.BaseTestCase):
configs) configs)
def _poll_jobs_status(self, exec_ids): def _poll_jobs_status(self, exec_ids):
with fixtures.Timeout( try:
timeouts.Defaults.instance.timeout_poll_jobs_status, with fixtures.Timeout(
gentle=True): timeouts.Defaults.instance.timeout_poll_jobs_status,
success = False gentle=True):
while not success: success = False
success = True polling_ids = list(exec_ids)
for exec_id in exec_ids: while not success:
status = self.sahara.get_job_status(exec_id) current_ids = list(polling_ids)
if status in ['FAILED', 'KILLED', 'DONEWITHERROR']: success = True
self.fail("Job %s in %s status" % (exec_id, status)) for exec_id in polling_ids:
if status != 'SUCCEEDED': status = self.sahara.get_job_status(exec_id)
success = False if status not in ['FAILED', 'KILLED', 'DONEWITHERROR',
"SUCCEEDED"]:
time.sleep(5) success = False
else:
current_ids.remove(exec_id)
polling_ids = list(current_ids)
time.sleep(5)
finally:
report = []
for exec_id in exec_ids:
status = self.sahara.get_job_status(exec_id)
if status != "SUCCEEDED":
info = self.sahara.get_job_info(exec_id)
report.append("Job with id={id}, name={name}, "
"type={type} has status "
"{status}".format(id=exec_id,
name=info.name,
type=info.type,
status=status))
if report:
self.fail("\n".join(report))
def _create_swift_data(self, source=None): def _create_swift_data(self, source=None):
container = self._get_swift_container() container = self._get_swift_container()

View File

@ -151,6 +151,10 @@ class SaharaClient(Client):
data = self.sahara_client.job_executions.get(exec_id) data = self.sahara_client.job_executions.get(exec_id)
return str(data.info['status']) return str(data.info['status'])
def get_job_info(self, exec_id):
job_execution = self.sahara_client.job_executions.get(exec_id)
return self.sahara_client.jobs.get(job_execution.job_id)
def get_cluster_id(self, name): def get_cluster_id(self, name):
if uuidutils.is_uuid_like(name): if uuidutils.is_uuid_like(name):
return name return name

View File

@ -55,10 +55,15 @@ class FakeCluster(object):
class FakeResponse(object): class FakeResponse(object):
def __init__(self, set_id=None, set_status=None, node_groups=None): def __init__(self, set_id=None, set_status=None, node_groups=None,
url=None, job_id=None, name=None, job_type=None):
self.id = set_id self.id = set_id
self.status = set_status self.status = set_status
self.node_groups = node_groups self.node_groups = node_groups
self.url = url
self.job_id = job_id
self.name = name
self.type = job_type
class TestBase(testtools.TestCase): class TestBase(testtools.TestCase):
@ -346,9 +351,11 @@ class TestBase(testtools.TestCase):
@mock.patch('sahara.tests.scenario.base.BaseTestCase.check_cinder', @mock.patch('sahara.tests.scenario.base.BaseTestCase.check_cinder',
return_value=None) return_value=None)
@mock.patch('sahara.tests.scenario.clients.SaharaClient.get_job_status', @mock.patch('sahara.tests.scenario.clients.SaharaClient.get_job_status',
return_value='SUCCEEDED') return_value='KILLED')
@mock.patch('saharaclient.api.base.ResourceManager._get', @mock.patch('saharaclient.api.base.ResourceManager._get',
return_value=FakeResponse(set_id='id_for_run_job_get')) return_value=FakeResponse(set_id='id_for_run_job_get',
job_type='Java',
name='test_job'))
@mock.patch('saharaclient.api.base.ResourceManager._create', @mock.patch('saharaclient.api.base.ResourceManager._create',
return_value=FakeResponse(set_id='id_for_run_job_create')) return_value=FakeResponse(set_id='id_for_run_job_create'))
@mock.patch('sahara.tests.scenario.base.BaseTestCase.' @mock.patch('sahara.tests.scenario.base.BaseTestCase.'
@ -398,6 +405,9 @@ class TestBase(testtools.TestCase):
] ]
with mock.patch('time.sleep'): with mock.patch('time.sleep'):
self.assertIsNone(self.base_scenario.check_run_jobs()) self.assertIsNone(self.base_scenario.check_run_jobs())
self.assertIn("Job with id=id_for_run_job_create, name=test_job, "
"type=Java has status KILLED",
self.base_scenario._results[-1]['traceback'][-1])
@mock.patch('sahara.tests.scenario.base.BaseTestCase.' @mock.patch('sahara.tests.scenario.base.BaseTestCase.'
'_poll_cluster_status', '_poll_cluster_status',