diff --git a/scripts/openstack-cleanup/main.py b/scripts/openstack-cleanup/main.py
index 9bc24d3f3796432fbf2fb8e164be2a634407fdc1..511f060871ecf41ef85a85de8c73e562c8fd1bb4 100755
--- a/scripts/openstack-cleanup/main.py
+++ b/scripts/openstack-cleanup/main.py
@@ -42,8 +42,26 @@ def main():
                conn.network.security_groups())
 
     print('Ports...')
-    map_if_old(conn.network.delete_port,
-               conn.network.ports())
+    try:
+        map_if_old(conn.network.delete_port,
+                   conn.network.ports())
+    except openstack.exceptions.ConflictException as ex:
+        # Need to find subnet-id which should be removed from a router
+        for sn in conn.network.subnets():
+            try:
+                fn_if_old(conn.network.delete_subnet, sn)
+            except openstack.exceptions.ConflictException:
+                for r in conn.network.routers():
+                    print("Deleting subnet %s from router %s", sn, r)
+                    try:
+                        conn.network.remove_interface_from_router(
+                            r, subnet_id=sn.id)
+                    except Exception as ex:
+                        print("Failed to delete subnet from router as %s", ex)
+
+        # After removing unnecessary subnet from router, retry to delete ports
+        map_if_old(conn.network.delete_port,
+                   conn.network.ports())
 
     print('Subnets...')
     map_if_old(conn.network.delete_subnet,