From 11d276c73cdd848c0287f6718d0163369cefd157 Mon Sep 17 00:00:00 2001 From: Ian Wienand Date: Thu, 2 Jul 2015 09:34:34 +1000 Subject: [PATCH] local call masks errors in subshells In another "things from the man page" The return status is 0 unless local is used outside a function, an invalid name is supplied, or name is a readonly variable. Thus if anything fails in "cmd" of "local foo=$( cmd )" we don't notice. Change-Id: I22b10d5d39f014b6c92d2e101b167cbacf81afca --- functions-common | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/functions-common b/functions-common index 322bf82f30..a2a9a3daf4 100644 --- a/functions-common +++ b/functions-common @@ -684,9 +684,10 @@ function policy_add { # Gets or creates a domain # Usage: get_or_create_domain function get_or_create_domain { + local domain_id local os_url="$KEYSTONE_SERVICE_URI_V3" # Gets domain id - local domain_id=$( + domain_id=$( # Gets domain id openstack --os-token=$OS_TOKEN --os-url=$os_url \ --os-identity-api-version=3 domain show $1 \ @@ -705,8 +706,9 @@ function get_or_create_domain { function get_or_create_group { local desc="${3:-}" local os_url="$KEYSTONE_SERVICE_URI_V3" + local group_id # Gets group id - local group_id=$( + group_id=$( # Creates new group with --or-show openstack --os-token=$OS_TOKEN --os-url=$os_url \ --os-identity-api-version=3 group create $1 \ @@ -719,13 +721,14 @@ function get_or_create_group { # Gets or creates user # Usage: get_or_create_user [] function get_or_create_user { + local user_id if [[ ! -z "$4" ]]; then local email="--email=$4" else local email="" fi # Gets user id - local user_id=$( + user_id=$( # Creates new user with --or-show openstack user create \ $1 \ @@ -743,7 +746,8 @@ function get_or_create_user { # Gets or creates project # Usage: get_or_create_project function get_or_create_project { - local project_id=$( + local project_id + project_id=$( # Creates new project with --or-show openstack --os-url=$KEYSTONE_SERVICE_URI_V3 \ --os-identity-api-version=3 \ @@ -757,7 +761,8 @@ function get_or_create_project { # Gets or creates role # Usage: get_or_create_role function get_or_create_role { - local role_id=$( + local role_id + role_id=$( # Creates role with --or-show openstack role create $1 \ --os-url=$KEYSTONE_SERVICE_URI_V3 \ @@ -770,8 +775,9 @@ function get_or_create_role { # Gets or adds user role to project # Usage: get_or_add_user_project_role function get_or_add_user_project_role { + local user_role_id # Gets user role id - local user_role_id=$(openstack role list \ + user_role_id=$(openstack role list \ --user $2 \ --os-url=$KEYSTONE_SERVICE_URI_V3 \ --os-identity-api-version=3 \ @@ -795,8 +801,9 @@ function get_or_add_user_project_role { # Gets or adds group role to project # Usage: get_or_add_group_project_role function get_or_add_group_project_role { + local group_role_id # Gets group role id - local group_role_id=$(openstack role list \ + group_role_id=$(openstack role list \ --os-url=$KEYSTONE_SERVICE_URI_V3 \ --os-identity-api-version=3 \ --group $2 \ @@ -822,8 +829,9 @@ function get_or_add_group_project_role { # Gets or creates service # Usage: get_or_create_service function get_or_create_service { + local service_id # Gets service id - local service_id=$( + service_id=$( # Gets service id openstack service show $2 -f value -c id 2>/dev/null || # Creates new service if not exists @@ -841,7 +849,8 @@ function get_or_create_service { # Create an endpoint with a specific interface # Usage: _get_or_create_endpoint_with_interface function _get_or_create_endpoint_with_interface { - local endpoint_id=$(openstack endpoint list \ + local endpoint_id + endpoint_id=$(openstack endpoint list \ --os-url $KEYSTONE_SERVICE_URI_V3 \ --os-identity-api-version=3 \ --service $1 \