From 7b9daa829fe137cb3da377c89b293f01e5fa0871 Mon Sep 17 00:00:00 2001 From: armando-migliaccio Date: Thu, 9 Jan 2014 05:53:09 -0800 Subject: [PATCH] VMware NSX: add sanity checks for NSX cluster backend Ensure that all transport nodes registered are up and running. A failure here, may prevent a lot of failures down the lines. Change-Id: I3473928e296ec6792f34bc27a4ae797fed337e7c Closes-bug: #1267468 --- neutron/plugins/nicira/check_nsx_config.py | 37 +++++++++++++++++++--- 1 file changed, 33 insertions(+), 4 deletions(-) diff --git a/neutron/plugins/nicira/check_nsx_config.py b/neutron/plugins/nicira/check_nsx_config.py index 31bb0a992..9da30a9fa 100644 --- a/neutron/plugins/nicira/check_nsx_config.py +++ b/neutron/plugins/nicira/check_nsx_config.py @@ -68,6 +68,23 @@ def get_transport_zones(cluster): return [transport_zone['uuid'] for transport_zone in transport_zones] +def get_transport_nodes(cluster): + transport_nodes = config_helper("transport-node", cluster) + return [transport_node['uuid'] for transport_node in transport_nodes] + + +def is_transport_node_connected(cluster, node_uuid): + try: + return nvplib.do_request('GET', + "/ws.v1/transport-node/%s/status" % node_uuid, + cluster=cluster)['connection']['connected'] + except Exception as e: + msg = (_("Error '%(err)s' when connecting to controller(s): %(ctl)s.") + % {'err': str(e), + 'ctl': ', '.join(get_nsx_controllers(cluster))}) + raise Exception(msg) + + def main(): if len(sys.argv) != 2: help(sys.argv[0]) @@ -125,10 +142,22 @@ def main(): "(%s) is missing from NSX transport zones!" % cfg.CONF.default_tz_uuid) errors += 1 - - if errors: + transport_nodes = get_transport_nodes(cluster) + print("\tTransport nodes: %s" % transport_nodes) + node_errors = [] + for node in transport_nodes: + if not is_transport_node_connected(cluster, node): + node_errors.append(node) + + # Use different exit codes, so that we can distinguish + # between config and runtime errors + if len(node_errors): + print("\nThere are one or mode transport nodes that are " + "not connected: %s. Please, revise!" % node_errors) + sys.exit(10) + elif errors: print("\nThere are %d errors with your configuration. " - " Please, revise!" % errors) - sys.exit(1) + "Please, revise!" % errors) + sys.exit(12) else: print("Done.") -- 2.45.2