Merge "Add support for quiet down"
This commit is contained in:
commit
8923e660a9
@ -21,6 +21,7 @@ the things you can use it for:
|
||||
* Enable/Disable nodes
|
||||
* Get information on nodes
|
||||
* Create/delete/reconfig views
|
||||
* Put server in shutdown mode (quiet down)
|
||||
* and many more..
|
||||
|
||||
To install::
|
||||
|
@ -102,6 +102,7 @@ CREATE_VIEW = 'createView?name=%(name)s'
|
||||
CONFIG_VIEW = 'view/%(name)s/config.xml'
|
||||
DELETE_VIEW = 'view/%(name)s/doDelete'
|
||||
SCRIPT_TEXT = 'scriptText'
|
||||
QUIET_DOWN = 'quietDown'
|
||||
|
||||
# for testing only
|
||||
EMPTY_CONFIG_XML = '''<?xml version='1.0' encoding='UTF-8'?>
|
||||
@ -1007,3 +1008,15 @@ class Jenkins(object):
|
||||
'''
|
||||
request = Request(self._build_url(CONFIG_VIEW, locals()))
|
||||
return self.jenkins_open(request)
|
||||
|
||||
def quiet_down(self):
|
||||
'''Prepare Jenkins for shutdown.
|
||||
|
||||
No new builds will be started allowing running builds to complete
|
||||
prior to shutdown of the server.
|
||||
'''
|
||||
request = Request(self._build_url(QUIET_DOWN))
|
||||
self.jenkins_open(request)
|
||||
info = self.get_info()
|
||||
if not info['quietingDown']:
|
||||
raise JenkinsException('quiet down failed')
|
||||
|
59
tests/test_quiet_down.py
Normal file
59
tests/test_quiet_down.py
Normal file
@ -0,0 +1,59 @@
|
||||
import json
|
||||
from mock import patch
|
||||
|
||||
import jenkins
|
||||
from tests.base import JenkinsTestBase
|
||||
|
||||
|
||||
class JenkinsQuietDownTest(JenkinsTestBase):
|
||||
@patch.object(jenkins.Jenkins, 'jenkins_open')
|
||||
def test_success(self, jenkins_mock):
|
||||
job_info_to_return = {
|
||||
"quietingDown": True,
|
||||
}
|
||||
jenkins_mock.return_value = json.dumps(job_info_to_return)
|
||||
|
||||
self.j.quiet_down()
|
||||
|
||||
self.assertEqual(
|
||||
jenkins_mock.call_args_list[0][0][0].get_full_url(),
|
||||
u'http://example.com/quietDown')
|
||||
self.assertEqual(
|
||||
jenkins_mock.call_args_list[1][0][0].get_full_url(),
|
||||
u'http://example.com/api/json')
|
||||
self._check_requests(jenkins_mock.call_args_list)
|
||||
|
||||
@patch.object(jenkins.Jenkins, 'jenkins_open')
|
||||
def test_fail(self, jenkins_mock):
|
||||
job_info_to_return = {
|
||||
"quietingDown": False,
|
||||
}
|
||||
jenkins_mock.return_value = json.dumps(job_info_to_return)
|
||||
|
||||
with self.assertRaises(jenkins.JenkinsException) as context_manager:
|
||||
self.j.quiet_down()
|
||||
|
||||
self.assertEqual(
|
||||
jenkins_mock.call_args_list[0][0][0].get_full_url(),
|
||||
u'http://example.com/quietDown')
|
||||
self.assertEqual(
|
||||
jenkins_mock.call_args_list[1][0][0].get_full_url(),
|
||||
u'http://example.com/api/json')
|
||||
self.assertEqual(
|
||||
str(context_manager.exception),
|
||||
'quiet down failed')
|
||||
self._check_requests(jenkins_mock.call_args_list)
|
||||
|
||||
@patch.object(jenkins.Jenkins, 'jenkins_open')
|
||||
def test_http_fail(self, jenkins_mock):
|
||||
jenkins_mock.side_effect = jenkins.JenkinsException(
|
||||
'Error in request. Possibly authentication failed [401]: '
|
||||
'basic auth failed')
|
||||
|
||||
with self.assertRaises(jenkins.JenkinsException):
|
||||
self.j.quiet_down()
|
||||
|
||||
self.assertEqual(
|
||||
jenkins_mock.call_args[0][0].get_full_url(),
|
||||
u'http://example.com/quietDown')
|
||||
self._check_requests(jenkins_mock.call_args_list)
|
Loading…
Reference in New Issue
Block a user