From 2a050be26da4c39b4ccddd4bc73391491708cf04 Mon Sep 17 00:00:00 2001 From: Jonathan Perret Date: Wed, 13 Jul 2016 17:26:22 +0200 Subject: [PATCH] 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 "" 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 --- doc/source/execution.rst | 5 +++-- tests/cmd/subcommands/test_update.py | 8 ++++---- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/doc/source/execution.rst b/doc/source/execution.rst index 8dc2434f6..4323ea726 100644 --- a/doc/source/execution.rst +++ b/doc/source/execution.rst @@ -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:: diff --git a/tests/cmd/subcommands/test_update.py b/tests/cmd/subcommands/test_update.py index 10874aea7..6a7f432a3 100644 --- a/tests/cmd/subcommands/test_update.py +++ b/tests/cmd/subcommands/test_update.py @@ -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"