Add --skip-resource option to project cleanup
Story: 2010370 Depends-On: https://review.opendev.org/c/openstack/openstacksdk/+/878646 Change-Id: I9eb10cfd8612fa9faf2a734a517078b12a9ca3c3 Signed-off-by: Jan Hartkopf <jhartkopf@inovex.de>
This commit is contained in:
parent
18a6199ed0
commit
f29e3ccc37
@ -79,6 +79,12 @@ class ProjectCleanup(command.Command):
|
||||
metavar='<YYYY-MM-DDTHH24:MI:SS>',
|
||||
help=_('Only delete resources updated before the given time'),
|
||||
)
|
||||
parser.add_argument(
|
||||
'--skip-resource',
|
||||
metavar='<resource>',
|
||||
help='Skip cleanup of specific resource (repeat if necessary)',
|
||||
action='append',
|
||||
)
|
||||
identity_common.add_project_domain_option_to_parser(parser)
|
||||
return parser
|
||||
|
||||
@ -114,7 +120,10 @@ class ProjectCleanup(command.Command):
|
||||
filters['updated_at'] = parsed_args.updated_before
|
||||
|
||||
project_connect.project_cleanup(
|
||||
dry_run=True, status_queue=status_queue, filters=filters
|
||||
dry_run=True,
|
||||
status_queue=status_queue,
|
||||
filters=filters,
|
||||
skip_resources=parsed_args.skip_resource,
|
||||
)
|
||||
|
||||
data = []
|
||||
|
@ -84,7 +84,12 @@ class TestProjectCleanup(TestProjectCleanupBase):
|
||||
filters = {'created_at': '2200-01-01', 'updated_at': '2200-01-02'}
|
||||
|
||||
calls = [
|
||||
mock.call(dry_run=True, status_queue=mock.ANY, filters=filters),
|
||||
mock.call(
|
||||
dry_run=True,
|
||||
status_queue=mock.ANY,
|
||||
filters=filters,
|
||||
skip_resources=None,
|
||||
),
|
||||
mock.call(dry_run=False, status_queue=mock.ANY, filters=filters),
|
||||
]
|
||||
self.project_cleanup_mock.assert_has_calls(calls)
|
||||
@ -110,7 +115,12 @@ class TestProjectCleanup(TestProjectCleanupBase):
|
||||
|
||||
self.sdk_connect_as_project_mock.assert_called_with(self.project)
|
||||
calls = [
|
||||
mock.call(dry_run=True, status_queue=mock.ANY, filters={}),
|
||||
mock.call(
|
||||
dry_run=True,
|
||||
status_queue=mock.ANY,
|
||||
filters={},
|
||||
skip_resources=None,
|
||||
),
|
||||
mock.call(dry_run=False, status_queue=mock.ANY, filters={}),
|
||||
]
|
||||
self.project_cleanup_mock.assert_has_calls(calls)
|
||||
@ -135,7 +145,12 @@ class TestProjectCleanup(TestProjectCleanupBase):
|
||||
|
||||
self.sdk_connect_as_project_mock.assert_called_with(self.project)
|
||||
calls = [
|
||||
mock.call(dry_run=True, status_queue=mock.ANY, filters={}),
|
||||
mock.call(
|
||||
dry_run=True,
|
||||
status_queue=mock.ANY,
|
||||
filters={},
|
||||
skip_resources=None,
|
||||
),
|
||||
mock.call(dry_run=False, status_queue=mock.ANY, filters={}),
|
||||
]
|
||||
self.project_cleanup_mock.assert_has_calls(calls)
|
||||
@ -160,7 +175,12 @@ class TestProjectCleanup(TestProjectCleanupBase):
|
||||
|
||||
self.sdk_connect_as_project_mock.assert_called_with(self.project)
|
||||
calls = [
|
||||
mock.call(dry_run=True, status_queue=mock.ANY, filters={}),
|
||||
mock.call(
|
||||
dry_run=True,
|
||||
status_queue=mock.ANY,
|
||||
filters={},
|
||||
skip_resources=None,
|
||||
),
|
||||
]
|
||||
self.project_cleanup_mock.assert_has_calls(calls)
|
||||
|
||||
@ -184,7 +204,10 @@ class TestProjectCleanup(TestProjectCleanupBase):
|
||||
|
||||
self.sdk_connect_as_project_mock.assert_called_with(self.project)
|
||||
self.project_cleanup_mock.assert_called_once_with(
|
||||
dry_run=True, status_queue=mock.ANY, filters={}
|
||||
dry_run=True,
|
||||
status_queue=mock.ANY,
|
||||
filters={},
|
||||
skip_resources=None,
|
||||
)
|
||||
|
||||
self.assertIsNone(result)
|
||||
@ -208,7 +231,42 @@ class TestProjectCleanup(TestProjectCleanupBase):
|
||||
|
||||
self.sdk_connect_as_project_mock.assert_not_called()
|
||||
calls = [
|
||||
mock.call(dry_run=True, status_queue=mock.ANY, filters={}),
|
||||
mock.call(
|
||||
dry_run=True,
|
||||
status_queue=mock.ANY,
|
||||
filters={},
|
||||
skip_resources=None,
|
||||
),
|
||||
mock.call(dry_run=False, status_queue=mock.ANY, filters={}),
|
||||
]
|
||||
self.project_cleanup_mock.assert_has_calls(calls)
|
||||
|
||||
self.assertIsNone(result)
|
||||
|
||||
def test_project_cleanup_with_skip_resource(self):
|
||||
skip_resource = "block_storage.backup"
|
||||
arglist = [
|
||||
'--project',
|
||||
self.project.id,
|
||||
'--skip-resource',
|
||||
skip_resource,
|
||||
]
|
||||
verifylist = [('skip_resource', [skip_resource])]
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
result = None
|
||||
|
||||
with mock.patch('sys.stdin', StringIO('y')):
|
||||
result = self.cmd.take_action(parsed_args)
|
||||
|
||||
self.sdk_connect_as_project_mock.assert_called_with(self.project)
|
||||
|
||||
calls = [
|
||||
mock.call(
|
||||
dry_run=True,
|
||||
status_queue=mock.ANY,
|
||||
filters={},
|
||||
skip_resources=[skip_resource],
|
||||
),
|
||||
mock.call(dry_run=False, status_queue=mock.ANY, filters={}),
|
||||
]
|
||||
self.project_cleanup_mock.assert_has_calls(calls)
|
||||
|
@ -0,0 +1,8 @@
|
||||
---
|
||||
features:
|
||||
- |
|
||||
A new option ``--skip-resource`` has been added to the
|
||||
``project cleanup`` command. This allows to exclude
|
||||
certain resources from project cleanups, e. g.
|
||||
``--skip-resource "block_storage.backup"`` to keep
|
||||
Cinder backups.
|
@ -7,7 +7,7 @@ pbr!=2.1.0,>=2.0.0 # Apache-2.0
|
||||
cryptography>=2.7 # BSD/Apache-2.0
|
||||
cliff>=3.5.0 # Apache-2.0
|
||||
iso8601>=0.1.11 # MIT
|
||||
openstacksdk>=0.103.0 # Apache-2.0
|
||||
openstacksdk>=1.4.0 # Apache-2.0
|
||||
osc-lib>=2.3.0 # Apache-2.0
|
||||
oslo.i18n>=3.15.3 # Apache-2.0
|
||||
oslo.utils>=3.33.0 # Apache-2.0
|
||||
|
Loading…
Reference in New Issue
Block a user