allow disabled to remain the last setting

Change-Id: I5a31a38c8fd50b5bf8d952ad7bab38a535895ed5
This commit is contained in:
Chris Cheng 2024-06-24 11:37:43 +08:00 committed by 程澈
parent ed2c37304c
commit 8bffa4d520
2 changed files with 16 additions and 0 deletions

View File

@ -350,9 +350,18 @@ class JenkinsManager(object):
@concurrent
def parallel_update_job(self, job):
self.fix_disabled(job)
self.update_job(job.name, job.output().decode("utf-8"))
return (job.name, job.md5())
def fix_disabled(self, job):
el = job.xml.find("./disabled")
if el is not None:
return
info = self.jenkins.get_job_info(job.name)
disabled = info["disabled"]
XML.SubElement(job.xml, "disabled").text = str(disabled).lower()
################
# View related #
################

View File

@ -29,6 +29,7 @@ def test_update_jobs(mocker, fixtures_dir, default_config_file, execute_jenkins_
"""
mocker.patch("jenkins_jobs.builder.jenkins.Jenkins.job_exists")
mocker.patch("jenkins_jobs.builder.jenkins.Jenkins.get_all_jobs")
mocker.patch("jenkins_jobs.builder.JenkinsManager.fix_disabled")
reconfig_job = mocker.patch("jenkins_jobs.builder.jenkins.Jenkins.reconfig_job")
path = fixtures_dir / "cmd-002.yaml"
@ -53,6 +54,7 @@ def test_update_jobs_enabled_only(
"""
mocker.patch("jenkins_jobs.builder.jenkins.Jenkins.job_exists")
mocker.patch("jenkins_jobs.builder.jenkins.Jenkins.get_all_jobs")
mocker.patch("jenkins_jobs.builder.JenkinsManager.fix_disabled")
reconfig_job = mocker.patch("jenkins_jobs.builder.jenkins.Jenkins.reconfig_job")
path = fixtures_dir / "cmd-002.yaml"
@ -77,6 +79,7 @@ def test_update_jobs_decode_job_output(
mocker.patch("jenkins_jobs.builder.JenkinsManager.is_job", return_value=True)
mocker.patch("jenkins_jobs.builder.JenkinsManager.get_jobs")
mocker.patch("jenkins_jobs.builder.JenkinsManager.get_job_md5")
mocker.patch("jenkins_jobs.builder.JenkinsManager.fix_disabled")
update_job_mock = mocker.patch("jenkins_jobs.builder.JenkinsManager.update_job")
# don't care about the value returned here
@ -104,6 +107,7 @@ def test_update_jobs_and_delete_old(
True.
"""
mocker.patch("jenkins_jobs.builder.jenkins.Jenkins.job_exists")
mocker.patch("jenkins_jobs.builder.JenkinsManager.fix_disabled")
jenkins_get_all_jobs = mocker.patch(
"jenkins_jobs.builder.jenkins.Jenkins.get_all_jobs"
)
@ -241,6 +245,7 @@ def test_update_jobs_and_views(
"""
mocker.patch("jenkins_jobs.builder.jenkins.Jenkins.job_exists")
mocker.patch("jenkins_jobs.builder.jenkins.Jenkins.get_all_jobs")
mocker.patch("jenkins_jobs.builder.JenkinsManager.fix_disabled")
reconfig_job = mocker.patch("jenkins_jobs.builder.jenkins.Jenkins.reconfig_job")
mocker.patch("jenkins_jobs.builder.jenkins.Jenkins.view_exists")
@ -277,6 +282,7 @@ def test_update_jobs_only(
"""
mocker.patch("jenkins_jobs.builder.jenkins.Jenkins.job_exists")
mocker.patch("jenkins_jobs.builder.jenkins.Jenkins.get_all_jobs")
mocker.patch("jenkins_jobs.builder.JenkinsManager.fix_disabled")
reconfig_job = mocker.patch("jenkins_jobs.builder.jenkins.Jenkins.reconfig_job")
mocker.patch("jenkins_jobs.builder.jenkins.Jenkins.view_exists")
@ -365,6 +371,7 @@ def test_update_views_and_delete_old_jobs_only(
No views should be deleted or updated.
"""
mocker.patch("jenkins_jobs.builder.jenkins.Jenkins.job_exists")
mocker.patch("jenkins_jobs.builder.JenkinsManager.fix_disabled")
jenkins_get_all_jobs = mocker.patch(
"jenkins_jobs.builder.jenkins.Jenkins.get_all_jobs"
)