From 2d909ff03175203034f3e402e758bd8a6821ac89 Mon Sep 17 00:00:00 2001 From: Andrea Dell'Amico Date: Fri, 22 Sep 2017 19:23:20 +0200 Subject: [PATCH] smartgears get-scopes: try to manage all the scenarios correctly. --- .../smartgears/tasks/smartgears-app.yml | 1 - smartgears/smartgears/templates/get-scopes.j2 | 47 +++++++++---------- 2 files changed, 21 insertions(+), 27 deletions(-) diff --git a/smartgears/smartgears/tasks/smartgears-app.yml b/smartgears/smartgears/tasks/smartgears-app.yml index 6e3ab121..b3d6c6fd 100644 --- a/smartgears/smartgears/tasks/smartgears-app.yml +++ b/smartgears/smartgears/tasks/smartgears-app.yml @@ -119,7 +119,6 @@ become_user: '{{ smartgears_user }}' shell: /usr/local/bin/get-scopes {{ gcube_admin_token | default('') }} when: gcube_admin_token is defined or smartgears_upgrade - ignore_errors: True notify: Restart smartgears tags: [ 'smartgears', 'smartgears_conf', 'tomcat' ] diff --git a/smartgears/smartgears/templates/get-scopes.j2 b/smartgears/smartgears/templates/get-scopes.j2 index 3976db97..5933869e 100644 --- a/smartgears/smartgears/templates/get-scopes.j2 +++ b/smartgears/smartgears/templates/get-scopes.j2 @@ -8,33 +8,39 @@ LOCAL_ETC=/usr/local/etc LOG_PREFIX="get-scopes: " GHN_ENV_FILE=/etc/default/tomcat-instance-{{ item.http_port }}.local SMARTGEARS_VO_AUTH={{ smartgears_authorized_on_all_scopes }} -SMARTGEARS_UPGRADE={{ smartgears_upgrade }} SMARTGEARS_SAVED_STATE_F=saved_scopes_list.xml SMARTGEARS_SAVED_STATE_PATH={{ smartgears_user_home }}/SmartGears/$SMARTGEARS_SAVED_STATE_F SMARTGEARS_SCRIPTS_DIR={{ smartgears_user_home }}/SmartGears/scripts - +SMARTGEARS_RUNNING_STATE_FILE={{ smartgears_user_home }}/state/ghn.xml CONTAINER_XML_FILE={{ smartgears_install_path }}/container.xml # 0: True, 1: False USE_SAVED_STATE=1 - +TOKEN= RETVAL= -# Scenario: -# - First installation, no upgrade. -# - The node must run on all VOs -# In these cases we use our scopes list - -if [ "$SMARTGEARS_VO_AUTH" == 'false' ] ; then - if [ "$SMARTGEARS_UPGRADE" == 'True' ] ; then +if [ $# -eq 0 ] ; then + if [ -f $SMARTGEARS_RUNNING_STATE_FILE ] ; then + if [ "$SMARTGEARS_VO_AUTH" == 'true' ] ; then + # - The node must run on all VOs + logger "$LOG_PREFIX When the node must run on all the VOs a valid token is mandatory, aborting" + exit 1 + fi USE_SAVED_STATE=0 - logger "$LOG_PREFIX setting the correct variables so that we are going to use the local scopes" + echo "No token, assuming that we can use the local state" + logger "$LOG_PREFIX No token, assuming that we can use the local state" else - logger "$LOG_PREFIX We are going to use our scopes list. A valid token is mandatory" + # - First installation, no upgrade. + logger "$LOG_PREFIX No token was passed and not working state available, aborting" + exit 1 fi +elif [ $# -eq 1 ] ; then + logger "$LOG_PREFIX We have an authorization token" + TOKEN=$1 else - logger "$LOG_PREFIX We are going to use our scopes list. A valid token is mandatory" + logger "$LOG_PREFIX More than one parameter was passed, aborting" + exit 1 fi SCOPES_LIST="" @@ -45,16 +51,6 @@ else exit 1 fi - -if [ $# -ne 1 -a $USE_SAVED_STATE -ne 0 ] ; then - echo "The token must be passed as the sole argument when we are not using the local state" - logger "$LOG_PREFIX The token must be passed as the sole argument when we are not using the local state" - exit 1 -elif [ $# -eq 1 ] ; then - logger "$LOG_PREFIX We have an authorization token" - TOKEN=$1 -fi - {%if setup_nginx %} HTTP_PORT={{ http_port }} {% else %} @@ -94,13 +90,12 @@ cd $SMARTGEARS_SCRIPTS_DIR ./clean-container-state -s $SMARTGEARS_SAVED_STATE_F RETVAL=$? if [ $RETVAL -ne 0 ] ; then - # We were not able to get the running state from the IS. We get new ones - logger "$LOG_PREFIX We were not able to get the running state from the IS. We get new ones from the authorization service" + # We were not able to get the running state from the IS. Try to get new scope tokens + logger "$LOG_PREFIX We were not able to get the running state from the IS. Try to get new scope tokens from the authorization service" SCOPES_FILE={{ smartgears_user_home }}/.containerxml/2-container.xml get_scopes_from_auth fi - # Now that we have the tokens, we can assemble the container.xml file chmod 640 $CONTAINER_XML_FILE CREATE_CONTAINER_XML_RES=0