Fix documentation of --delete-old: affects only managed jobs.

As far back as its introduction (2cefa400), the `--delete-old` option
has only ever deleted jobs that were marked with the special
"<!-- Managed by Jenkins Job Builder -->" comment that JJB adds to
descriptions.

This change fixes the documentation of the `--delete-old` option,
which erroneously used to state that even jobs that were never
managed by JJB would be subject to deletion.

The test for the feature was slightly enriched as well: the fact
that unmanaged jobs were not deleted, was not actually tested.

Change-Id: I438a7b555b6e122869988b3a2b9ea40896004122
This commit is contained in:
Jonathan Perret 2016-07-13 17:26:22 +02:00
parent d6add35e72
commit 2a050be26d
2 changed files with 7 additions and 6 deletions

View File

@ -266,8 +266,9 @@ jobs::
jenkins-jobs update --delete-old /path/to/defs
Obsolete jobs are *all* jobs not managed by JJB, even jobs which
were *never* managed by JJB.
Obsolete jobs are jobs once managed by JJB (as distinguished by a special
comment that JJB appends to their description), that were not generated in this
JJB run.
There is also a command to delete **all** jobs.
**WARNING**: Use with caution::

View File

@ -73,10 +73,10 @@ class UpdateTests(CmdTestsBase):
update_job is called, and have the get_jobs() method return additional
jobs not in the input yaml to test that the code in cmd will call
delete_job() after update_job() when '--delete-old' is set but only
for the extra jobs.
for the extra managed jobs.
"""
# set up some test data
jobs = ['old_job001', 'old_job002']
jobs = ['old_job001', 'old_job002', 'unmanaged']
extra_jobs = [{'name': name} for name in jobs]
builder_obj = builder.Builder('http://jenkins.example.com',
@ -105,7 +105,7 @@ class UpdateTests(CmdTestsBase):
with mock.patch('jenkins_jobs.builder.Jenkins.update_job') as update:
with mock.patch('jenkins_jobs.builder.Jenkins.is_managed',
return_value=True):
side_effect=(lambda name: name != 'unmanaged')):
self.execute_jenkins_jobs_with_args(args)
self.assertEquals(2, update.call_count,
"Expected Jenkins.update_job to be called '%d' "
@ -113,7 +113,7 @@ class UpdateTests(CmdTestsBase):
"Called with: %s" % (2, update.call_count,
update.mock_calls))
calls = [mock.call(name) for name in jobs]
calls = [mock.call(name) for name in jobs if name != 'unmanaged']
self.assertEqual(2, delete_job_mock.call_count,
"Expected Jenkins.delete_job to be called '%d' "
"times got '%d' calls instead.\n"