2 ##############################################################################
3 # Copyright (c) 2016 ZTE Corporation.
5 # All rights reserved. This program and the accompanying materials
6 # are made available under the terms of the Apache License, Version 2.0
7 # which accompanies this distribution, and is available at
8 # http://www.apache.org/licenses/LICENSE-2.0
9 ##############################################################################
11 [[ "${CI_DEBUG:-true}" == "true" ]] && set -x
13 PARSER_IMAGE_URL=https://launchpad.net/cirros/trunk/0.3.0/+download/cirros-0.3.0-x86_64-disk.img
14 PARSER_IMAGE_NAME=cirros
15 PARSER_IMAGE_FILE="${PARSER_IMAGE_NAME}.img"
16 PARSER_IMAGE_FORMAT=qcow2
18 PARSER_VM_FLAVOR=m1.tiny
21 PARSER_PASSWORD=parser
23 PARSER_TENANT=${PARSER_PROJECT}
27 PARSER_STACK_NAME=vRNC_Stack
29 VRNC_INPUT_TEMPLATE_FILE=../tosca2heat/tosca-parser/toscaparser/extensions/nfv/tests/data/vRNC/Definitions/vRNC.yaml
30 VRNC_OUTPUT_TEMPLATE_FILE=./vRNC_Hot_Template.yaml
32 download_parser_image() {
33 [ -e "${PARSER_IMAGE_FILE}" ] && return 0
34 wget "${PARSER_IMAGE_URL}" -o "$IMAGE_FILE"
37 register_parser_image() {
38 openstack image list | grep -qwo "${PARSER_IMAGE_NAME}" && return 0
39 openstack image create "${PARSER_IMAGE_NAME}" \
41 --disk-format "$IMAGE_FORMAT" \
42 --container-format bare \
43 --file "${PARSER_IMAGE_FILE}"
46 create_parser_user_and_project() {
48 # 1. create parser user.
49 openstack user list | grep -qwo "${PARSER_USER}" && {
50 echo "User ${PARSER_USER} exist, doesn't crate."
52 openstack user create "${PARSER_USER}" --password "${PARSR_PASSWORD}"
53 echo "Create user ${PARSER_USER} successful."
56 # 2. create parser project
57 openstack project list | grep -qwo "${PARSER_PROJECT}" && {
58 echo "Project ${PARSER_PROJECT} exist, doesn't crate."
60 openstack project create "${PARSER_PROJECT}"
61 echo "Create project ${PARSER_PROJECT} successful."
64 # 3. grant role for parser user
65 openstack user role list "${PARSER_USER}" --project "${PARSER_PROJECT}" \
66 | grep -qow " ${PARSER_ROLE}" && {
67 echo "User ${PARSER_USER} has role ${PARSER_ROLE} in project ${PARSER_PROJECT}, doesn't crate."
69 openstack role add "${PARSER_ROLE}" --user "${PARSER_USER}" \
70 --project "${PARSER_PROJECT}"
71 echo "Grant user ${PARSER_USER} the role ${PARSER_ROLE} in project ${PARSER_PROJECT} successful."
76 change_env_to_parser_user_project() {
78 export OS_USERNAME="$PARSER_USER"
79 export OS_PASSWORD="$PARSER_PASSWORD"
80 export OS_PROJECT_NAME="$PARSER_PROJECT"
81 export OS_TENANT_NAME="$PARSER_TENANT"
85 translator_and_deploy_vRNC() {
87 # 1. Delete parser stack ${PARSER_STACK_NAME}, use admin user in admin project
88 heat stack-list | grep -qow ${PARSER_STACK_NAME} && {
89 echo "stack ${PARSER_STACK_NAME} exist, delete it first."
90 heat stack-delete ${PARSER_STACK_NAME}
92 # 2. Switch env to parser project temporally
93 change_env_to_parser_user_project
95 # 3. Translator and deploy vRNC
96 heat-translator -f ${VRNC_INPUT_TEMPLATE_FILE} -o ${VRNC_OUTPUT_TEMPLATE_FILE} --deploy True
98 # 4. Wait for create vRNC
101 # 5. Validate the deploy result.
107 reset_parser_test() {
114 # 1. Switch env to parser project temporally
115 change_env_to_parser_user_project
117 # 2. Delete the stack ${PARSER_STACK_NAME}
118 heat stack-list | grep -qow ${PARSER_STACK_NAME} && {
119 echo "stack ${PARSER_STACK_NAME} exist, delete it."
120 heat stack-delete ${PARSER_STACK_NAME}
126 # 3. Delete parser user and project
127 parser_image_id=$(openstack image list | grep -ow "${PARSER_IMAGE_NAME}" | awk '{print $2}')
129 [ -n "${parser_image_id}" ] && openstack image delete "${parser_image_id}"
130 openstack role remove "${PARSER_ROLE}" --user "${PARSER_USER}" \
131 --project "${PARSER_PROJECT}"
132 openstack project delete "${PARSER_PROJECT}"
133 openstack user delete "${PARSER_USER}"
141 echo "======================= Parser functest begin =========================="
143 trap reset_parser_test EXIT
145 echo " 1. Preparing VM image for parser..."
146 download_parser_image
147 register_parser_image
149 echo " 2. Creating test user for parser..."
150 create_parser_user_and_project
152 echo " 3. Parse -> translate -> deploy vRNC..."
153 translator_and_deploy_vRNC
155 echo " 4. clear the test evn..."
156 reset_parser_test "ok"
158 echo "======================= Parser functest end =========================="