Fix functest_run script for role of heat_stack_owner
[parser.git] / tests / functest_run.sh
index 2b45089..b866ab9 100755 (executable)
@@ -9,6 +9,8 @@
 ##############################################################################
 
 PARSER_CI_DEBUG=${CI_DEBUG:-false}
+PRASER_WORK_DIR=$(cd $(dirname $0) && pwd)
+
 [[ "${PARSER_CI_DEBUG}" == "true" ]] && {
     set -x
     debug="--debug"
@@ -16,15 +18,27 @@ PARSER_CI_DEBUG=${CI_DEBUG:-false}
     set +x
     debug=""
 }
-
-PARSER_IMAGE_URL_FILE=cirros-0.3.0-x86_64-disk.img
-PARSER_IMAGE_URL=https://launchpad.net/cirros/trunk/0.3.0/+download/${PARSER_IMAGE_URL_FILE}
-PARSER_IMAGE_NAME=rhel-6.5-test-image
+LOCAL_IMAGE_FILE=${1:-""}
+
+if [ -e "${LOCAL_IMAGE_FILE}" ]; then
+    echo "Input local image file: ${LOCAL_IMAGE_FILE}"
+    PARSER_IMAGE_URL_FILE=${LOCAL_IMAGE_FILE}
+else
+    echo "No local image file or the file(${LOCAL_IMAGE_FILE}) doesn't exsit!"
+
+    PARSER_IMAGE_URL_FILE=cirros-0.3.5-x86_64-disk.img
+    PARSER_IMAGE_VERSION=$(echo ${PARSER_IMAGE_URL_FILE} | awk -F- '{print $2}')
+    # PARSER_IMAGE_URL=https://launchpad.net/cirros/trunk/0.3.0/+download/${PARSER_IMAGE_URL_FILE}
+    PARSER_IMAGE_URL=http://download.cirros-cloud.net/${PARSER_IMAGE_VERSION}/${PARSER_IMAGE_URL_FILE}
+    echo "so will download image(${PARSER_IMAGE_URL_FILE}) from ${PARSER_IMAGE_URL}."
+fi
+
+# PARSER_IMAGE_NAME=rhel-6.5-test-image
+# fiexd image name according to the translator default vlaue of images
+PARSER_IMAGE_NAME=cirros-0.3.2-x86_64-uec
 PARSER_IMAGE_FILE="${PARSER_IMAGE_NAME}.img"
 PARSER_IMAGE_FORMAT=qcow2
 
-PARSER_VM_FLAVOR=m1.tiny
-
 PARSER_USER=parser
 PARSER_PASSWORD=parser
 PARSER_EMAIL='shang.xiaodong@zte.com.cn'
@@ -36,8 +50,9 @@ PARSER_ROLE=admin
 PARSER_STACK_NAME=vRNC_Stack
 
 # VRNC_INPUT_TEMPLATE_FILE=../tosca2heat/tosca-parser/toscaparser/extensions/nfv/tests/data/vRNC/Definitions/vRNC.yaml
-VRNC_INPUT_TEMPLATE_RAW_FILE=../tosca2heat/heat-translator/translator/tests/data/test_tosca_nfv_sample.yaml
-VRNC_OUTPUT_TEMPLATE_FILE=./vRNC_Hot_Template.yaml
+# VRNC_INPUT_TEMPLATE_RAW_FILE=../tosca2heat/heat-translator/translator/tests/data/test_tosca_nfv_sample.yaml
+VRNC_INPUT_TEMPLATE_RAW_FILE=../tosca2heat/heat-translator/translator/tests/data/vRNC/Definitions/vRNC.yaml
+VRNC_OUTPUT_TEMPLATE_FILE=../tosca2heat/heat-translator/translator/tests/data/vRNC/vRNC_Hot_Template.yaml
 
 VRNC_INPUT_TEMPLATE_FILE=${VRNC_INPUT_TEMPLATE_RAW_FILE%.*}_patch.yaml
 
@@ -95,7 +110,9 @@ create_parser_user_and_project() {
     } || {
         openstack ${debug} role add ${PARSER_ROLE} --user ${PARSER_USER} \
                            --project ${PARSER_PROJECT}
-        echo "  Grant user ${PARSER_USER} the role ${PARSER_ROLE} in project ${PARSER_PROJECT} successful."
+        openstack ${debug} role add heat_stack_owner --user ${PARSER_USER} \
+                           --project ${PARSER_PROJECT}
+        echo "  Grant user ${PARSER_USER} the role ${PARSER_ROLE} and heat_stack_owner in project ${PARSER_PROJECT} successful."
     }
 
 }
@@ -107,6 +124,9 @@ change_env_to_parser_user_project() {
     export OS_PROJECT_NAME=${PARSER_PROJECT}
     export OS_TENANT_NAME=${PARSER_TENANT}
 
+    export OS_PROJECT_DOMAIN_NAME=${OS_PROJECT_DOMAIN_NAME:-'Default'}
+    export OS_USER_DOMAIN_NAME=${OS_USER_DOMAIN_NAME:-'Default'}
+
 }
 
 
@@ -114,27 +134,37 @@ make_patch_for_provider_network() {
 
     # copy temp file
     echo "    Patch provider network for input file:"
-    echo "        Raw yaml file: ${VRNC_INPUT_TEMPLATE_RAW_FILE}"
-    echo "        Patched yaml file: ${VRNC_INPUT_TEMPLATE_FILE}"
+    echo "      Raw yaml file: ${VRNC_INPUT_TEMPLATE_RAW_FILE}"
+    echo "      Patched yaml file: ${VRNC_INPUT_TEMPLATE_FILE}"
     cp ${VRNC_INPUT_TEMPLATE_RAW_FILE} ${VRNC_INPUT_TEMPLATE_FILE}
     echo ""
 
     # Delete the provider:network_type
-    echo "    Patch provider:network_type..."
+    echo "      Patching provider:network_type..."
     sed -i '/network_type:/d' ${VRNC_INPUT_TEMPLATE_FILE}
 
     # Delete the provider:segmentation_id
-    echo "    Patch provider:segmentation_id..."
+    echo "      Patching provider:segmentation_id..."
     sed -i '/segmentation_id:/d' ${VRNC_INPUT_TEMPLATE_FILE}
 
     # Delete the provider:physical_network
-    echo "    Patch provider:physical_network..."
+    echo "      Patching provider:physical_network..."
     sed -i '/physical_network:/d' ${VRNC_INPUT_TEMPLATE_FILE}
 
     echo ""
 
 }
 
+make_patch_for_translated_file() {
+
+    # Replace the signal_transport
+    echo "    Patch yaml file: ${VRNC_OUTPUT_TEMPLATE_FILE}"
+    echo ""
+    echo "    Patching compute:signal_transport"
+    sed -i '1,$s/HEAT_SIGNAL/NO_SIGNAL/g' ${VRNC_OUTPUT_TEMPLATE_FILE}
+
+}
+
 
 translator_and_deploy_vRNC() {
 
@@ -161,13 +191,30 @@ translator_and_deploy_vRNC() {
             --output-file ${VRNC_OUTPUT_TEMPLATE_FILE}
         echo ""
 
-        # 5. deploy vRNC
+        # 5. Patch translated file
+        echo "  Make patch for translated file:"
+        make_patch_for_translated_file
+        echo ""
+
+        # 6. deploy vRNC
         echo "  Deploy stack..."
         [[ "${PARSER_CI_DEBUG}" == "true" ]] && debug="--debug" || debug=""
-        openstack ${debug} stack create --timeout 30 --wait --enable-rollback \
+        openstack ${debug} stack create --timeout 15 --wait --enable-rollback \
                                         -t ${VRNC_OUTPUT_TEMPLATE_FILE} ${PARSER_STACK_NAME}
 
-        # 6. Validate the deploy result.
+        # 7. basic information.
+        echo "  The basic information of deployment..."
+        openstack ${debug} stack show ${PARSER_STACK_NAME}
+
+        # 8. deployed resources.
+        echo "  The resources of deployment..."
+        openstack ${debug} stack resource list ${PARSER_STACK_NAME}
+
+        # 9. deployed outputs.
+        echo "  The outputs of deployment..."
+        openstack ${debug} stack output list ${PARSER_STACK_NAME}
+
+        # 10. Validate the deploy result.
         echo "  Checking the result of deployment..."
         openstack ${debug} stack show ${PARSER_STACK_NAME} | grep -qow "CREATE_COMPLETE" && {
             echo "    Check the result of deployment successfully."
@@ -247,7 +294,7 @@ reset_parser_test() {
     }
 
     echo ""
-    echo "======================= Parser functest end =========================="
+    echo "======================={ Parser functest end }=========================="
     echo ""
     echo ""
 
@@ -255,13 +302,13 @@ reset_parser_test() {
 
 echo ""
 echo ""
-echo "======================= Parser functest begin =========================="
+echo "======================={ Parser functest begin }=========================="
 echo ""
 
 trap reset_parser_test EXIT
 
 # start syslog for loghander
-service rsyslog restart
+which service > /dev/null  && service rsyslog restart || true
 
 echo "|========= 1/4. Preparing VM image for parser...     =========|"
 download_parser_image