Skip to content

Commit

Permalink
cleanup dms implemented partially (#495)
Browse files Browse the repository at this point in the history
cleanup dms implemented partially

Reviewed-by: Anton Sidelnikov
  • Loading branch information
RusselSand authored Nov 26, 2024
1 parent 4c0a4fc commit 5be7ab6
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 0 deletions.
1 change: 1 addition & 0 deletions .stestr.blacklist.functional
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,4 @@ otcextensions.tests.functional.sdk.rds.v3*
otcextensions.tests.functional.sdk.dws.v1.test_cleanup
otcextensions.tests.functional.sdk.identity.v3*
otcextensions.tests.functional.osclient.identity.v3*
otcextensions.tests.functional.sdk.dms.v1.test_cleanup
66 changes: 66 additions & 0 deletions otcextensions/sdk/dms/v1/_proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from otcextensions.sdk.dms.v1 import product as _product
from otcextensions.sdk.dms.v1 import queue as _queue
from otcextensions.sdk.dms.v1 import topic as _topic
from openstack import resource


class Proxy(proxy.Proxy):
Expand Down Expand Up @@ -410,3 +411,68 @@ def maintenance_windows(self, **kwargs):
:class:`~otcextensions.sdk.dms.v1.maintenance_window.MaintenanceWindow`
"""
return self._list(_mw.MaintenanceWindow, **kwargs)

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():
for topic in self.topics(instance):
self._service_cleanup_del_res(
self.delete_topic,
topic,
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)
21 changes: 21 additions & 0 deletions otcextensions/tests/functional/sdk/dms/v1/test_cleanup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# 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 TestDmsCleanup(base.BaseFunctionalTest):
def setUp(self):
super(TestDmsCleanup, self).setUp()
self.client = self.conn.dms

def test_01_cleanup(self):
self.client._service_cleanup(dry_run=False)

0 comments on commit 5be7ab6

Please sign in to comment.