From c2a55c005e3586eb820e528dcf74b9d2b32fbb31 Mon Sep 17 00:00:00 2001 From: Salvatore Orlando Date: Thu, 29 Apr 2021 09:43:35 -0700 Subject: [PATCH] Catch exception when cleanup fails Print an error message instead of a full traceback. Exit with code 1. Change-Id: I6102d14d1b4552a76d0aa694f758f2750abe5328 --- devstack/tools/nsxp_cleanup.py | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/devstack/tools/nsxp_cleanup.py b/devstack/tools/nsxp_cleanup.py index aebe731c13..27160ab557 100755 --- a/devstack/tools/nsxp_cleanup.py +++ b/devstack/tools/nsxp_cleanup.py @@ -14,8 +14,7 @@ # under the License. import optparse - -import sqlalchemy as sa +import sys from neutron.db.models import l3 from neutron.db.models import securitygroup @@ -24,7 +23,7 @@ from neutron.db import models_v2 from neutron.db.qos import models as qos_models from neutron_lib.db import model_base from oslo_db.sqlalchemy import models - +import sqlalchemy as sa from vmware_nsxlib import v3 from vmware_nsxlib.v3 import config from vmware_nsxlib.v3 import exceptions @@ -617,8 +616,13 @@ if __name__ == "__main__": (options, args) = parser.parse_args() # Get NSX REST client - nsx_client = NSXClient(options.policy_ip, options.username, - options.password, options.db_connection, - options.allow_passthrough) - # Clean all objects created by OpenStack - nsx_client.cleanup_all() + try: + nsx_client = NSXClient(options.policy_ip, options.username, + options.password, options.db_connection, + options.allow_passthrough) + # Clean all objects created by OpenStack + nsx_client.cleanup_all() + except Exception as e: + print("Unable to cleanup NSX-T Policy resources due to: %s." + "Please retry." % e) + sys.exit(1)