Fix error thrown in presence of placeholder tasks

When there are placeholder tasks in an executor for a node then there is no
build number yet assigned and attempting to access that key in the dictionary
will fail.

This fix filters out any tasks which are instances of that class before
proceeding.

Change-Id: Ie5b237c3e6023c1822f91e5982ec84f1a363130c
Closes-Bug: #1659787
This commit is contained in:
grahamlyons 2017-02-09 16:30:52 +00:00
parent 0843ae7850
commit 106048dd87
2 changed files with 38 additions and 1 deletions

View File

@ -1146,7 +1146,7 @@ class Jenkins(object):
raise
for executor in info['executors']:
executable = executor['currentExecutable']
if executable:
if executable and 'PlaceholderTask' not in executable.get('_class', ''):
executor_number = executor['number']
build_number = executable['number']
url = executable['url']

View File

@ -417,3 +417,40 @@ class JenkinsListRunningBuildsTest(JenkinsTestBase):
builds = self.j.get_running_builds()
# Should treat the slave as not running any builds
self.assertEqual([], builds)
@patch.object(jenkins.Jenkins, 'get_node_info')
@patch.object(jenkins.Jenkins, 'get_nodes')
def test_placeholder_task_in_queue(self, nodes_mock, node_info_mock):
nodes_to_return = [{
'name': "foo-slave", 'offline': False
}]
nodes_mock.return_value = nodes_to_return
node_info_to_return = {
"executors": [
{
"currentExecutable": None,
"currentWorkUnit": None,
"idle": True,
"likelyStuck": False,
"number": 1,
"progress": -1
},
{
'currentExecutable': {
'_class': (
'org.jenkinsci.plugins.workflow.support.steps.'
'ExecutorStepExecution$PlaceholderTask$'
'PlaceholderExecutable'
)
},
'currentWorkUnit': {},
'idle': False,
'likelyStuck': False,
'number': 1,
'progress': 0
}
],
}
node_info_mock.return_value = node_info_to_return
builds = self.j.get_running_builds()
self.assertEqual([], builds)