Merge "Delete old managed folders when calling update subcommand with --delete-old option"
This commit is contained in:
commit
d0b438cf25
@ -132,12 +132,11 @@ class JenkinsManager(object):
|
||||
self._job_format(job_name)))
|
||||
self.jenkins.create_job(job_name, xml)
|
||||
|
||||
def is_job(self, job_name):
|
||||
# first use cache
|
||||
if job_name in self.job_list:
|
||||
return True
|
||||
def is_job(self, job_name, use_cache=True):
|
||||
if use_cache:
|
||||
if job_name in self.job_list:
|
||||
return True
|
||||
|
||||
# if not exists, use jenkins
|
||||
return self.jenkins.job_exists(job_name)
|
||||
|
||||
def get_job_md5(self, job_name):
|
||||
@ -200,7 +199,9 @@ class JenkinsManager(object):
|
||||
keep = []
|
||||
for job in jobs:
|
||||
# python-jenkins stores the folder and name as 'fullname'
|
||||
if job['fullname'] not in keep:
|
||||
# Check if the job was deleted when his parent folder was deleted
|
||||
if job['fullname'] not in keep and \
|
||||
self.is_job(job['fullname'], use_cache=False):
|
||||
if self.is_managed(job['fullname']):
|
||||
logger.info("Removing obsolete jenkins job {0}"
|
||||
.format(job['fullname']))
|
||||
|
@ -60,11 +60,13 @@ class TestCaseTestJenkinsManager(base.BaseTestCase):
|
||||
|
||||
with mock.patch.multiple('jenkins_jobs.builder.JenkinsManager',
|
||||
get_jobs=mock.DEFAULT,
|
||||
is_job=mock.DEFAULT,
|
||||
is_managed=mock.DEFAULT,
|
||||
delete_job=mock.DEFAULT) as patches:
|
||||
patches['get_jobs'].return_value = [{'fullname': 'job1'},
|
||||
{'fullname': 'job2'}]
|
||||
patches['is_managed'].side_effect = [True, True]
|
||||
patches['is_job'].side_effect = [True, True]
|
||||
|
||||
self.builder.delete_old_managed()
|
||||
self.assertEqual(patches['delete_job'].call_count, 2)
|
||||
|
Loading…
Reference in New Issue
Block a user