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

cleanup nat gw #504

Merged
merged 2 commits into from
Jan 20, 2025
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 @@ -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)
Loading