From 5cb12a228468924c506d2e552c1748f48528f6d8 Mon Sep 17 00:00:00 2001 From: Brent Eagles Date: Thu, 7 Feb 2013 14:38:52 -0330 Subject: Prevent the unexpected with nova-manage network modify. "nova-manage network modify" can misinterpret arguments if the user provides values where they are unexpected, specifically the --disassociate-project and --disassociate-host options. If the user provides a project or hostname value for either of these values, it will be interpreted as a positional argument and modify handler may behave as if other options were provided (e.g. project or host). This change handles the presence of a project or host option along with --disassociate-project or --disassociate-host as an error, printing a message and exiting immediately with an error code. While there are other approaches (e.g. perform the disassociate modifications while ignoring the others), preventing unexpected or inconsistent results by doing nothing seems safest. Change-Id: Iff7817fe3ed19a4ff330b4029f9c558d3b405e9b --- bin/nova-manage | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/bin/nova-manage b/bin/nova-manage index c793fed16..278af260b 100755 --- a/bin/nova-manage +++ b/bin/nova-manage @@ -560,14 +560,31 @@ class NetworkCommands(object): #1) Associate (set not None value given by project/host parameter) #2) Disassociate (set None by disassociate parameter) #3) Keep unchanged (project/host key is not added to 'net') + if dis_project: + net['project_id'] = None + if dis_host: + net['host'] = None + + # The --disassociate-X are boolean options, but if they user + # mistakenly provides a value, it will be used as a positional argument + # and be erroneously interepreted as some other parameter (e.g. + # a project instead of host value). The safest thing to do is error-out + # with a message indicating that there is probably a problem with + # how the disassociate modifications are being used. + if dis_project or dis_host: + if project or host: + error_msg = "ERROR: Unexpected arguments provided. Please " \ + "use separate commands." + print(error_msg) + sys.exit(1) + db.network_update(admin_context, network['id'], net) + return + if project: net['project_id'] = project - elif dis_project: - net['project_id'] = None if host: net['host'] = host - elif dis_host: - net['host'] = None + db.network_update(admin_context, network['id'], net) -- cgit