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 PARSER_CI_DEBUG=${CI_DEBUG:-true}
12 [[ "${PARSER_CI_DEBUG}" == "true" ]] && set -x
14 PARSER_IMAGE_URL_FILE=cirros-0.3.0-x86_64-disk.img
15 PARSER_IMAGE_URL=https://launchpad.net/cirros/trunk/0.3.0/+download/${PARSER_IMAGE_URL_FILE}
16 PARSER_IMAGE_NAME=rhel-6.5-test-image
17 PARSER_IMAGE_FILE="${PARSER_IMAGE_NAME}.img"
18 PARSER_IMAGE_FORMAT=qcow2
20 PARSER_VM_FLAVOR=m1.tiny
23 PARSER_PASSWORD=parser
25 PARSER_TENANT=${PARSER_PROJECT}
29 PARSER_STACK_NAME=vRNC_Stack
31 # VRNC_INPUT_TEMPLATE_FILE=../tosca2heat/tosca-parser/toscaparser/extensions/nfv/tests/data/vRNC/Definitions/vRNC.yaml
32 VRNC_INPUT_TEMPLATE_FILE=../tosca2heat/heat-translator/translator/tests/data/test_tosca_nfv_sample.yaml
34 VRNC_OUTPUT_TEMPLATE_FILE=./vRNC_Hot_Template.yaml
36 download_parser_image() {
37 [ -e "${PARSER_IMAGE_URL_FILE}" ] && {
38 echo "Image ${PARSER_IMAGE_URL_FILE} has bee cached, needn't download again."
39 cp ${PARSER_IMAGE_URL_FILE} ${PARSER_IMAGE_FILE}
43 echo "Download image ${PARSER_IMAGE_URL_FILE}..."
44 wget "${PARSER_IMAGE_URL}" -o "${PARSER_IMAGE_FILE}"
47 register_parser_image() {
48 openstack image list | grep -qwo "${PARSER_IMAGE_NAME}" && {
49 echo "Image ${PARSER_IMAGE_NAME} has bee registed, needn't registe again."
53 echo "Registe image ${PARSER_IMAGE_NAME}..."
54 openstack image create "${PARSER_IMAGE_NAME}" \
56 --disk-format "${PARSER_IMAGE_FORMAT}" \
57 --container-format bare \
58 --file "${PARSER_IMAGE_FILE}"
61 create_parser_user_and_project() {
63 # 1. create parser user.
64 openstack user list | grep -qwo "${PARSER_USER}" && {
65 echo "User ${PARSER_USER} exist, doesn't create again."
67 openstack user create "${PARSER_USER}" --password "${PARSER_PASSWORD}"
68 echo "Create user ${PARSER_USER} successful."
71 # 2. create parser project
72 openstack project list | grep -qwo "${PARSER_PROJECT}" && {
73 echo "Project ${PARSER_PROJECT} exist, doesn't create agian."
75 openstack project create "${PARSER_PROJECT}"
76 echo "Create project ${PARSER_PROJECT} successful."
79 # 3. grant role for parser user
80 openstack user role list "${PARSER_USER}" --project "${PARSER_PROJECT}" \
81 | grep -qow " ${PARSER_ROLE}" && {
82 echo "User ${PARSER_USER} has role ${PARSER_ROLE} in project ${PARSER_PROJECT}, doesn't create."
84 openstack role add "${PARSER_ROLE}" --user "${PARSER_USER}" \
85 --project "${PARSER_PROJECT}"
86 echo "Grant user ${PARSER_USER} the role ${PARSER_ROLE} in project ${PARSER_PROJECT} successful."
91 change_env_to_parser_user_project() {
93 export OS_USERNAME="$PARSER_USER"
94 export OS_PASSWORD="$PARSER_PASSWORD"
95 export OS_PROJECT_NAME="$PARSER_PROJECT"
96 export OS_TENANT_NAME="$PARSER_TENANT"
100 translator_and_deploy_vRNC() {
102 # 1. Delete parser stack ${PARSER_STACK_NAME}, use admin user in admin project
103 openstack stack list | grep -qow ${PARSER_STACK_NAME} && {
104 echo "stack ${PARSER_STACK_NAME} exist, delete it first."
105 openstack stack delete --yes --wait ${PARSER_STACK_NAME}
107 # 2. Switch env to parser project temporally
108 change_env_to_parser_user_project
110 # 3. Translator and deploy vRNC
111 heat-translator --template-type tosca --template-file ${VRNC_INPUT_TEMPLATE_FILE} \
112 --output-file ${VRNC_OUTPUT_TEMPLATE_FILE}
115 openstack stack create -t ${VRNC_OUTPUT_TEMPLATE_FILE} ${PARSER_STACK_NAME}
117 # 5. Wait for create vRNC
120 # 6. Validate the deploy result.
126 reset_parser_test() {
130 # 1. Delete resource created by parser user
132 # 1). Switch env to parser project temporally
133 change_env_to_parser_user_project
135 # 2). Delete the stack ${PARSER_STACK_NAME}
136 openstack stack list | grep -qow ${PARSER_STACK_NAME} && {
137 echo "stack ${PARSER_STACK_NAME} has been created, delete it after test."
138 openstack stack delete --yes --wait ${PARSER_STACK_NAME}
141 # 3). Delete hot tmp file ${VRNC_OUTPUT_TEMPLATE_FILE}
142 [ -e ${VRNC_OUTPUT_TEMPLATE_FILE} -a ${PARSER_CI_DEBUG} != "true" ] && {
143 echo "delete hot temp file ${VRNC_OUTPUT_TEMPLATE_FILE} after test."
144 rm -fr ${VRNC_OUTPUT_TEMPLATE_FILE}
147 # 4). Delete tmp image ${PARSER_IMAGE_FILE}
148 [[ -e ${PARSER_IMAGE_FILE} ]] && {
149 echo "delete local image file ${PARSER_IMAGE_FILE} after test."
150 rm -fr ${PARSER_IMAGE_FILE}
153 # 5). Delete tmp image ${PARSER_IMAGE_URL_FILE}
154 [ -e ${PARSER_IMAGE_URL_FILE} -a ${PARSER_CI_DEBUG} != "true" ] && {
155 echo "delete local URL image file ${PARSER_IMAGE_URL_FILE} after test."
156 rm -fr ${PARSER_IMAGE_URL_FILE}
159 # 6). Delete image from openstack
160 parser_image_id=$(openstack image list | grep -w "${PARSER_IMAGE_NAME}" | awk '{print $2}')
161 [[ -n "${parser_image_id}" ]] && openstack image delete "${parser_image_id}"
166 # 2. Delete role, user and project
167 openstack user role list "${PARSER_USER}" --project "${PARSER_PROJECT}" \
168 | grep -qow " ${PARSER_ROLE}" && {
169 openstack role remove "${PARSER_ROLE}" --user "${PARSER_USER}" \
170 --project "${PARSER_PROJECT}"
173 openstack project list | grep -qwo "${PARSER_PROJECT}" && {
174 openstack project delete "${PARSER_PROJECT}"
177 openstack user list | grep -qow "${PARSER_USER}" && {
178 openstack user delete "${PARSER_USER}"
184 echo "======================= Parser functest begin =========================="
186 trap reset_parser_test EXIT
188 # start syslog for loghander
189 service rsyslog restart
191 echo " ========= 1/4. Preparing VM image for parser... ========= "
192 download_parser_image
193 register_parser_image
195 echo " ========= 2/4. Creating test user for parser... ========= "
196 create_parser_user_and_project
198 echo " ========= 3/4. Parse -> translate -> deploy vRNC... ========= "
199 translator_and_deploy_vRNC
201 echo " ========= 4/4. Test ok... ========= "
203 echo "======================= Parser functest end =========================="