Skip to content

Commit

Permalink
cleanup nat gw (#504)
Browse files Browse the repository at this point in the history
cleanup nat gw

Reviewed-by: Anton Sidelnikov
  • Loading branch information
RusselSand authored Jan 20, 2025
1 parent 4bb07ef commit 7061969
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 5 deletions.
1 change: 1 addition & 0 deletions .stestr.blacklist.functional
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,4 @@ 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
otcextensions.tests.functional.sdk.nat.v2.test_cleanup
53 changes: 48 additions & 5 deletions otcextensions/sdk/nat/v2/_proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -356,18 +356,61 @@ def _get_cleanup_dependencies(self):
}
}

def _service_cleanup(self, dry_run=True, client_status_queue=None,
def _service_cleanup(self,
dry_run=True,
client_status_queue=None,
identified_resources=None,
filters=None, resource_evaluation_fn=None):
for obj in self.gateways():
filters=None,
resource_evaluation_fn=None,
skip_resources=None):
if self.should_skip_resource_cleanup("gateway",
skip_resources):
return

gateways = []
for gateway in self.gateways():
snat_rules = []
for snat in self.snat_rules():
need_delete = self._service_cleanup_del_res(
self.delete_snat_rule,
snat,
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:
snat_rules.append(snat)
dnat_rules = []
for dnat in self.dnat_rules():
need_delete = self._service_cleanup_del_res(
self.delete_dnat_rule,
dnat,
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:
dnat_rules.append(dnat)
for snat in snat_rules:
self.wait_for_delete_snat(snat)
for dnat in dnat_rules:
self.wait_for_delete_dnat(dnat)
need_delete = self._service_cleanup_del_res(
self.delete_gateway,
obj,
gateway,
dry_run=dry_run,
client_status_queue=client_status_queue,
identified_resources=identified_resources,
filters=filters,
resource_evaluation_fn=resource_evaluation_fn)
if dry_run and need_delete:
for port in self._connection.network.ports(device_id=obj.id):
for port in self._connection.network.ports(
device_id=gateway.id):
identified_resources[port.id] = port
if not dry_run and need_delete:
gateways.append(gateway)

for gateway in gateways:
self.wait_for_delete_gateway(gateway)
28 changes: 28 additions & 0 deletions otcextensions/tests/functional/sdk/nat/v2/test_cleanup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# 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 openstack import _log


from otcextensions.tests.functional import base

_logger = _log.setup_logging('openstack')


class TestCleanup(base.BaseFunctionalTest):
def setUp(self):
super(TestCleanup, self).setUp()

def test_01_delete(self):
gateways = list(self.conn.nat.gateways())
self.conn.nat._service_cleanup(dry_run=False)
gateways = list(self.conn.nat.gateways())
self.assertEqual(len(gateways), 0)

0 comments on commit 7061969

Please sign in to comment.