Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

443 rds cleanup #458

Merged
merged 3 commits into from
Aug 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .stestr.blacklist.functional
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,4 @@ otcextensions.tests.functional.sdk.nat.v2.test_dnat*
otcextensions.tests.functional.osclient.kms*
otcextensions.tests.functional.sdk.imsv1*
otcextensions.tests.functional.sdk.imsv2*
otcextensions.tests.functional.sdk.rds.v3*
89 changes: 89 additions & 0 deletions otcextensions/sdk/rds/v3/_proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -510,3 +510,92 @@ def wait_for_backup(self, backup, status='COMPLETED', failures=None,
failures = ['FAILED'] if failures is None else failures
return resource.wait_for_status(
self, backup, status, failures, interval, wait)

def wait_for_delete(self, res, interval=2, wait=120, callback=None):
"""Wait for a resource to be deleted.

:param res: The resource to wait on to be deleted.
:type resource: A :class:`~openstack.resource.Resource` object.
:param interval: Number of seconds to wait before to consecutive
checks. Default to 2.
:param wait: Maximum number of seconds to wait before the change.
Default to 120.
:param callback: A callback function. This will be called with a single
value, progress, which is a percentage value from 0-100.

:returns: The resource is returned on success.
:raises: :class:`~openstack.exceptions.ResourceTimeout` if transition
to delete failed to occur in the specified seconds.
"""
return resource.wait_for_delete(self, res, interval, wait, callback)

def _get_cleanup_dependencies(self):
return {
'rds': {
'before': ['network']
}
}

def _service_cleanup(
self,
dry_run=True,
client_status_queue=None,
identified_resources=None,
filters=None,
resource_evaluation_fn=None,
skip_resources=None,
):
if self.should_skip_resource_cleanup("instance", skip_resources):
return

instances = []
for instance in self.instances():
if not dry_run:
for tag in instance.tags:
self.remove_tag(instance, tag['key'])
self._service_cleanup_del_res(
self.remove_tag,
tag['key'],
dry_run=dry_run,
client_status_queue=client_status_queue,
identified_resources=identified_resources,
filters=filters,
resource_evaluation_fn=resource_evaluation_fn,
)
for backup in self.backups(instance):
if 'Automated' not in backup.type:
self._service_cleanup_del_res(
self.delete_backup,
backup,
dry_run=dry_run,
client_status_queue=client_status_queue,
identified_resources=identified_resources,
filters=filters,
resource_evaluation_fn=resource_evaluation_fn,
)
need_delete = self._service_cleanup_del_res(
self.delete_instance,
instance,
dry_run=dry_run,
client_status_queue=client_status_queue,
identified_resources=identified_resources,
filters=filters,
resource_evaluation_fn=resource_evaluation_fn,
)
if not dry_run and need_delete:
instances.append(instance)

for instance in instances:
self.wait_for_delete(instance)

for config in self.configurations():
if 'Default-' not in config.name:
self._service_cleanup_del_res(
self.delete_configuration,
config,
dry_run=dry_run,
client_status_queue=client_status_queue,
identified_resources=identified_resources,
filters=filters,
resource_evaluation_fn=resource_evaluation_fn,
)
2 changes: 1 addition & 1 deletion otcextensions/sdk/rds/v3/instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ class Instance(_base.Resource):
switch_strategy = resource.Body('switch_strategy')
#: Lists the tags and their values attached to the instance.
#: *Type:dict*
tags = resource.Body('tags', type=dict)
tags = resource.Body('tags', type=list)
#: Time Zone.
#: *Type:string*
time_zone = resource.Body('time_zone')
Expand Down
20 changes: 20 additions & 0 deletions otcextensions/tests/functional/sdk/rds/v3/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.

from otcextensions.tests.functional import base


class TestRdsCleanUp(base.BaseFunctionalTest):

def setUp(self):
super(TestRdsCleanUp, self).setUp()
self.client = self.conn.rds
23 changes: 23 additions & 0 deletions otcextensions/tests/functional/sdk/rds/v3/test_cleanup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.

from otcextensions.tests.functional.sdk.rds.v3 import TestRdsCleanUp


class TestCleanup(TestRdsCleanUp):
def setUp(self):
super(TestCleanup, self).setUp()

def test_01_cleanup(self):
self.client._service_cleanup(dry_run=False)
instances = list(self.client.instances())
self.assertEqual(len(instances), 0)