Fix install_script
run_script needs explicit println call, and no longer return 'Result: [true|false]' because of appending magic string. Closes-Bug: #1806381 Change-Id: I795000a638d518d0247572318c5dbee068239b87
This commit is contained in:
@@ -1386,12 +1386,13 @@ class Jenkins(object):
|
|||||||
# run_script is an async call to run groovy. we need to wait a little
|
# run_script is an async call to run groovy. we need to wait a little
|
||||||
# before we can get a reliable response on whether a restart is needed
|
# before we can get a reliable response on whether a restart is needed
|
||||||
time.sleep(2)
|
time.sleep(2)
|
||||||
is_restart_required = ('Jenkins.instance.updateCenter'
|
is_restart_required = ('println('
|
||||||
'.isRestartRequiredForCompletion()')
|
'Jenkins.instance.updateCenter'
|
||||||
|
'.isRestartRequiredForCompletion()'
|
||||||
|
')')
|
||||||
|
|
||||||
# response is a string (i.e. u'Result: true\n'), return a bool instead
|
|
||||||
response_str = self.run_script(is_restart_required)
|
response_str = self.run_script(is_restart_required)
|
||||||
response = response_str.split(':')[1].strip().lower() == 'true'
|
response = response_str.strip().lower() == 'true'
|
||||||
return response
|
return response
|
||||||
|
|
||||||
def stop_build(self, name, number):
|
def stop_build(self, name, number):
|
||||||
|
|||||||
@@ -67,8 +67,8 @@ class JenkinsScriptTest(JenkinsTestBase):
|
|||||||
'.getNeededDependencies().each{it.deploy()};Jenkins'
|
'.getNeededDependencies().each{it.deploy()};Jenkins'
|
||||||
'.instance.updateCenter.getPlugin(\"jabber\").deploy();'))
|
'.instance.updateCenter.getPlugin(\"jabber\").deploy();'))
|
||||||
self.assertEqual(run_script_mock.call_args_list[1][0][0],
|
self.assertEqual(run_script_mock.call_args_list[1][0][0],
|
||||||
('Jenkins.instance.updateCenter'
|
('println(Jenkins.instance.updateCenter'
|
||||||
'.isRestartRequiredForCompletion()'))
|
'.isRestartRequiredForCompletion())'))
|
||||||
|
|
||||||
@patch.object(jenkins.Jenkins, 'jenkins_open')
|
@patch.object(jenkins.Jenkins, 'jenkins_open')
|
||||||
@patch.object(jenkins.Jenkins, 'run_script')
|
@patch.object(jenkins.Jenkins, 'run_script')
|
||||||
@@ -82,17 +82,17 @@ class JenkinsScriptTest(JenkinsTestBase):
|
|||||||
('Jenkins.instance.updateCenter'
|
('Jenkins.instance.updateCenter'
|
||||||
'.getPlugin(\"jabber\").deploy();'))
|
'.getPlugin(\"jabber\").deploy();'))
|
||||||
self.assertEqual(run_script_mock.call_args_list[1][0][0],
|
self.assertEqual(run_script_mock.call_args_list[1][0][0],
|
||||||
('Jenkins.instance.updateCenter'
|
('println(Jenkins.instance.updateCenter'
|
||||||
'.isRestartRequiredForCompletion()'))
|
'.isRestartRequiredForCompletion())'))
|
||||||
|
|
||||||
@patch.object(jenkins.Jenkins, 'jenkins_open', return_value='\n{}'.format(MAGIC_STR))
|
@patch.object(jenkins.Jenkins, 'jenkins_open', return_value='false\n{}'.format(MAGIC_STR))
|
||||||
def test_install_plugin_no_restart(self, jenkins_mock):
|
def test_install_plugin_no_restart(self, jenkins_mock):
|
||||||
'''Verify install plugin does not need a restart
|
'''Verify install plugin does not need a restart
|
||||||
'''
|
'''
|
||||||
j = jenkins.Jenkins(self.make_url(''), 'test', 'test')
|
j = jenkins.Jenkins(self.make_url(''), 'test', 'test')
|
||||||
self.assertFalse(j.install_plugin("jabber"))
|
self.assertFalse(j.install_plugin("jabber"))
|
||||||
|
|
||||||
@patch.object(jenkins.Jenkins, 'jenkins_open', return_value='\n{}'.format(MAGIC_STR))
|
@patch.object(jenkins.Jenkins, 'jenkins_open', return_value='true\n{}'.format(MAGIC_STR))
|
||||||
def test_install_plugin_restart(self, jenkins_mock):
|
def test_install_plugin_restart(self, jenkins_mock):
|
||||||
'''Verify install plugin needs a restart
|
'''Verify install plugin needs a restart
|
||||||
'''
|
'''
|
||||||
|
|||||||
Reference in New Issue
Block a user