Story 2011049: Add --force flag to update-all command
Without it, using this command in scripts is impossible. Change-Id: Ifd44fe0171a7753c9a09e9b05047ce2965c183f3
This commit is contained in:
parent
eb08e60765
commit
1ead727a2d
@ -8,6 +8,7 @@ Features added
|
||||
~~~~~~~~~~~~~~
|
||||
|
||||
* `--delete-old` flag for `update` cli command is now deletes obsolete views also, not only jobs.
|
||||
* Add `--force` flag to `delete-all` cli command to allow it's usage in scripts.
|
||||
|
||||
Bugs fixed
|
||||
~~~~~~~~~~
|
||||
|
@ -52,6 +52,12 @@ class DeleteAllSubCommand(base.BaseSubCommand):
|
||||
default=False,
|
||||
help="delete only views",
|
||||
)
|
||||
delete_all.add_argument(
|
||||
"-f",
|
||||
"--force",
|
||||
action="store_true",
|
||||
help="Do not ask interactively for confirmation. Ba cautious!",
|
||||
)
|
||||
|
||||
def execute(self, options, jjb_config):
|
||||
builder = JenkinsManager(jjb_config)
|
||||
@ -68,7 +74,7 @@ class DeleteAllSubCommand(base.BaseSubCommand):
|
||||
else:
|
||||
reach.update(("jobs", "views"))
|
||||
|
||||
if not utils.confirm(
|
||||
if not options.force and not utils.confirm(
|
||||
"Sure you want to delete *ALL* {} from Jenkins "
|
||||
"server?\n(including those not managed by Jenkins "
|
||||
"Job Builder)".format(" AND ".join(reach))
|
||||
|
@ -44,3 +44,29 @@ def test_delete_all_abort(mocker, default_config_file, execute_jenkins_jobs):
|
||||
args = ["--conf", default_config_file, "delete-all"]
|
||||
with pytest.raises(SystemExit):
|
||||
execute_jenkins_jobs(args)
|
||||
|
||||
|
||||
def test_delete_all_forced(mocker, default_config_file, execute_jenkins_jobs):
|
||||
"""
|
||||
Test handling the deletion of a job and a view with --force flag.
|
||||
"""
|
||||
|
||||
delete_jobs = mocker.patch(
|
||||
"jenkins_jobs.cli.subcommand.base.JenkinsManager.delete_all_jobs"
|
||||
)
|
||||
delete_views = mocker.patch(
|
||||
"jenkins_jobs.cli.subcommand.base.JenkinsManager.delete_all_views"
|
||||
)
|
||||
get_jobs = mocker.patch("jenkins_jobs.builder.jenkins.Jenkins.get_all_jobs")
|
||||
get_jobs.return_value = [{"name": name} for name in ["job-1"]]
|
||||
get_views = mocker.patch("jenkins_jobs.builder.jenkins.Jenkins.get_views")
|
||||
get_views.return_value = [{"name": name} for name in ["view-1"]]
|
||||
input = mocker.patch("jenkins_jobs.utils.input", return_value="n")
|
||||
|
||||
args = ["--conf", default_config_file, "delete-all", "--force"]
|
||||
execute_jenkins_jobs(args)
|
||||
|
||||
input.assert_not_called()
|
||||
|
||||
assert delete_jobs.call_count == 1
|
||||
assert delete_views.call_count == 1
|
||||
|
Loading…
x
Reference in New Issue
Block a user