From 15b607c245f0e42e6241ad064ae1d042c7ed87be Mon Sep 17 00:00:00 2001 From: David Johansen Date: Tue, 29 Oct 2013 16:59:49 -0700 Subject: [PATCH] Added systests for executor feature. Other fixes. - fixed missing index in executor. - removed unnecessary try/except block in executors --- jenkinsapi/executor.py | 2 +- jenkinsapi/executors.py | 15 +++---- jenkinsapi_tests/systests/test_executors.py | 61 ++++++++++++++++++++++++++++ jenkinsapi_tests/unittests/test_executors.py | 1 + 4 files changed, 69 insertions(+), 10 deletions(-) create mode 100644 jenkinsapi_tests/systests/test_executors.py diff --git a/jenkinsapi/executor.py b/jenkinsapi/executor.py index 531713c..4989b2a 100644 --- a/jenkinsapi/executor.py +++ b/jenkinsapi/executor.py @@ -44,7 +44,7 @@ class Executor(JenkinsBase): Get Executor number. """ self.poll() - return self._data[''] + return self._data['number'] def is_idle(self): """ diff --git a/jenkinsapi/executors.py b/jenkinsapi/executors.py index 5199214..9e2aaaf 100644 --- a/jenkinsapi/executors.py +++ b/jenkinsapi/executors.py @@ -33,12 +33,9 @@ class Executors(JenkinsBase): def __iter__(self): for index in range(self.count): executor_url = '%s/executors/%s' % (self.baseurl, index) - try: - yield Executor( - executor_url, - self.nodename, - self.jenkins, - index - ) - except JenkinsAPIException as exe: - log.error("Error querying Executors: %s", (exe,)) + yield Executor( + executor_url, + self.nodename, + self.jenkins, + index + ) diff --git a/jenkinsapi_tests/systests/test_executors.py b/jenkinsapi_tests/systests/test_executors.py new file mode 100644 index 0000000..b289069 --- /dev/null +++ b/jenkinsapi_tests/systests/test_executors.py @@ -0,0 +1,61 @@ +''' +System tests for `jenkinsapi.jenkins` module. +''' + +from jenkinsapi_tests.systests.base import BaseSystemTest +from jenkinsapi_tests.systests.job_configs import LONG_RUNNING_JOB +from jenkinsapi_tests.test_utils.random_strings import random_string +import logging +import time +import unittest + + +log = logging.getLogger(__name__) + + +class TestNodes(BaseSystemTest): + + def test_get_executors(self): + node_name = random_string() + self.jenkins.create_node(node_name) + executors = self.jenkins.get_executors(node_name) + self.assertEqual(executors.count, 2) + for count, execs in enumerate(executors): + self.assertEqual(count, execs.get_number()) + self.assertEqual(execs.is_idle(), True) + + def test_running_executor(self): + node_name = random_string() + self.jenkins.create_node(node_name) + job_name = 'create_%s' % random_string() + job = self.jenkins.create_job(job_name, LONG_RUNNING_JOB) + ii = job.invoke(invoke_pre_check_delay=2) + ii.block(until='not_queued') + + if job.is_running() is False: + time.sleep(1) + executors = self.jenkins.get_executors(node_name) + all_idle = True + for execs in executors: + if execs.is_idle() is False: + all_idle = False + self.assertNotEqual(execs.get_progress(), -1) + self.assertEqual(execs.get_current_executable(), ii.get_build_number()) + self.assertEqual(execs.likely_stuck(), False) + self.assertEqual(all_idle, True, "Executor should have been triggered.") + + def test_idle_executors(self): + node_name = random_string() + self.jenkins.create_node(node_name) + executors = self.jenkins.get_executors(node_name) + + for execs in executors: + self.assertEqual(execs.get_progress(), -1) + self.assertEqual(execs.get_current_executable(), None) + self.assertEqual(execs.likely_stuck(), False) + self.assertEqual(execs.is_idle(), True) + + +if __name__ == '__main__': + logging.basicConfig() + unittest.main() diff --git a/jenkinsapi_tests/unittests/test_executors.py b/jenkinsapi_tests/unittests/test_executors.py index 453721f..45159c4 100644 --- a/jenkinsapi_tests/unittests/test_executors.py +++ b/jenkinsapi_tests/unittests/test_executors.py @@ -2,6 +2,7 @@ import mock import types import unittest +from jenkinsapi.custom_exceptions import JenkinsAPIException from jenkinsapi.jenkins import Jenkins from jenkinsapi.executors import Executors from jenkinsapi.executor import Executor -- 2.7.4