Skip to content

Commit 65b667a

Browse files
Zuulopenstack-gerrit
authored andcommitted
Merge "Add auto-approve option to project cleanup"
2 parents 5eb89e4 + 7506eb8 commit 65b667a

File tree

3 files changed

+50
-11
lines changed

3 files changed

+50
-11
lines changed

openstackclient/common/project_cleanup.py

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,16 @@ class ProjectCleanup(command.Command):
4848

4949
def get_parser(self, prog_name):
5050
parser = super(ProjectCleanup, self).get_parser(prog_name)
51-
parser.add_argument(
51+
action_group = parser.add_mutually_exclusive_group()
52+
action_group.add_argument(
5253
'--dry-run',
5354
action='store_true',
54-
help=_("List a project's resources")
55+
help=_("List a project's resources but do not delete them")
56+
)
57+
action_group.add_argument(
58+
'--auto-approve',
59+
action='store_true',
60+
help=_("Delete resources without asking for confirmation")
5561
)
5662
project_group = parser.add_mutually_exclusive_group(required=True)
5763
project_group.add_argument(
@@ -67,12 +73,12 @@ def get_parser(self, prog_name):
6773
parser.add_argument(
6874
'--created-before',
6975
metavar='<YYYY-MM-DDTHH24:MI:SS>',
70-
help=_('Drop resources created before the given time')
76+
help=_('Only delete resources created before the given time')
7177
)
7278
parser.add_argument(
7379
'--updated-before',
7480
metavar='<YYYY-MM-DDTHH24:MI:SS>',
75-
help=_('Drop resources updated before the given time')
81+
help=_('Only delete resources updated before the given time')
7682
)
7783
identity_common.add_project_domain_option_to_parser(parser)
7884
return parser
@@ -127,12 +133,13 @@ def take_action(self, parsed_args):
127133
if parsed_args.dry_run:
128134
return
129135

130-
confirm = ask_user_yesno(
131-
_("These resources will be deleted. Are you sure"))
136+
if not parsed_args.auto_approve:
137+
if not ask_user_yesno(
138+
_("These resources will be deleted. Are you sure")):
139+
return
132140

133-
if confirm:
134-
self.log.warning(_('Deleting resources'))
141+
self.log.warning(_('Deleting resources'))
135142

136-
project_connect.project_cleanup(dry_run=False,
137-
status_queue=status_queue,
138-
filters=filters)
143+
project_connect.project_cleanup(dry_run=False,
144+
status_queue=status_queue,
145+
filters=filters)

openstackclient/tests/unit/common/test_project_cleanup.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,32 @@ def test_project_cleanup_with_filters(self):
8585

8686
self.assertIsNone(result)
8787

88+
def test_project_cleanup_with_auto_approve(self):
89+
arglist = [
90+
'--project', self.project.id,
91+
'--auto-approve',
92+
]
93+
verifylist = [
94+
('dry_run', False),
95+
('auth_project', False),
96+
('project', self.project.id),
97+
('auto_approve', True),
98+
]
99+
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
100+
result = None
101+
102+
result = self.cmd.take_action(parsed_args)
103+
104+
self.sdk_connect_as_project_mock.assert_called_with(
105+
self.project)
106+
calls = [
107+
mock.call(dry_run=True, status_queue=mock.ANY, filters={}),
108+
mock.call(dry_run=False, status_queue=mock.ANY, filters={})
109+
]
110+
self.project_cleanup_mock.assert_has_calls(calls)
111+
112+
self.assertIsNone(result)
113+
88114
def test_project_cleanup_with_project(self):
89115
arglist = [
90116
'--project', self.project.id,
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
features:
3+
- |
4+
An ``--auto-approve`` option has been added to the
5+
``project cleanup`` command. This allows the interactive
6+
confirmation of resource deletion to be skipped.

0 commit comments

Comments
 (0)