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:-false}
12 [[ "${PARSER_CI_DEBUG}" == "true" ]] && {
21 PARSER_IMAGE_URL_FILE=$1
23 PARSER_IMAGE_URL_FILE=cirros-0.3.5-x86_64-disk.img
25 # PARSER_IMAGE_URL=https://launchpad.net/cirros/trunk/0.3.0/+download/${PARSER_IMAGE_URL_FILE}
26 PARSER_IMAGE_URL=http://download.cirros-cloud.net/0.3.2/${PARSER_IMAGE_URL_FILE}
27 # PARSER_IMAGE_NAME=rhel-6.5-test-image
28 PARSER_IMAGE_NAME=cirros-0.3.2-x86_64-uec
29 PARSER_IMAGE_FILE="${PARSER_IMAGE_NAME}.img"
30 PARSER_IMAGE_FORMAT=qcow2
33 PARSER_PASSWORD=parser
34 PARSER_EMAIL='shang.xiaodong@zte.com.cn'
36 PARSER_TENANT=${PARSER_PROJECT}
40 PARSER_STACK_NAME=vRNC_Stack
42 # VRNC_INPUT_TEMPLATE_FILE=../tosca2heat/tosca-parser/toscaparser/extensions/nfv/tests/data/vRNC/Definitions/vRNC.yaml
43 # VRNC_INPUT_TEMPLATE_RAW_FILE=../tosca2heat/heat-translator/translator/tests/data/test_tosca_nfv_sample.yaml
44 VRNC_INPUT_TEMPLATE_RAW_FILE=../tosca2heat/heat-translator/translator/tests/data/vRNC/Definitions/vRNC.yaml
45 VRNC_OUTPUT_TEMPLATE_FILE=../tosca2heat/heat-translator/translator/tests/data/vRNC/vRNC_Hot_Template.yaml
47 VRNC_INPUT_TEMPLATE_FILE=${VRNC_INPUT_TEMPLATE_RAW_FILE%.*}_patch.yaml
49 download_parser_image() {
50 [ -e "${PARSER_IMAGE_URL_FILE}" ] && {
51 echo " Image ${PARSER_IMAGE_URL_FILE} has bee cached, needn't download again."
52 cp ${PARSER_IMAGE_URL_FILE} ${PARSER_IMAGE_FILE}
57 echo " Download image ${PARSER_IMAGE_URL_FILE}..."
58 wget ${PARSER_IMAGE_URL} -o ${PARSER_IMAGE_FILE}
61 register_parser_image() {
62 openstack ${debug} image list | grep -qwo "${PARSER_IMAGE_NAME}" && {
63 echo " Image ${PARSER_IMAGE_NAME} has bee registed, needn't registe again."
68 echo " Registe image ${PARSER_IMAGE_NAME}..."
69 openstack ${debug} image create "${PARSER_IMAGE_NAME}" \
71 --disk-format ${PARSER_IMAGE_FORMAT} \
72 --container-format bare \
73 --file ${PARSER_IMAGE_FILE}
76 create_parser_user_and_project() {
78 # 1. create parser project
79 openstack ${debug} project list | grep -qwo "${PARSER_PROJECT}" && {
80 echo " Project ${PARSER_PROJECT} exist, doesn't create agian."
82 openstack ${debug} project create ${PARSER_PROJECT} \
83 --description "Project for parser test"
84 echo " Create project ${PARSER_PROJECT} successful."
87 # 2. create parser user.
88 openstack ${debug} user list | grep -qwo ${PARSER_USER} && {
89 echo " User ${PARSER_USER} exist, doesn't create again."
91 openstack ${debug} user create ${PARSER_USER} --password ${PARSER_PASSWORD} \
92 --project ${PARSER_PROJECT} --email ${PARSER_EMAIL}
93 echo " Create user ${PARSER_USER} successful."
96 # 3. grant role for parser user
97 openstack ${debug} user role list ${PARSER_USER} --project ${PARSER_PROJECT} \
98 | grep -qow ${PARSER_ROLE} && {
99 echo " User ${PARSER_USER} has role ${PARSER_ROLE} in project ${PARSER_PROJECT}, doesn't create."
101 openstack ${debug} role add ${PARSER_ROLE} --user ${PARSER_USER} \
102 --project ${PARSER_PROJECT}
103 echo " Grant user ${PARSER_USER} the role ${PARSER_ROLE} in project ${PARSER_PROJECT} successful."
108 change_env_to_parser_user_project() {
110 export OS_USERNAME=${PARSER_USER}
111 export OS_PASSWORD=${PARSER_PASSWORD}
112 export OS_PROJECT_NAME=${PARSER_PROJECT}
113 export OS_TENANT_NAME=${PARSER_TENANT}
115 export OS_PROJECT_DOMAIN_NAME=${OS_PROJECT_DOMAIN_NAME:-'Default'}
116 export OS_USER_DOMAIN_NAME=${OS_USER_DOMAIN_NAME:-'Default'}
121 make_patch_for_provider_network() {
124 echo " Patch provider network for input file:"
125 echo " Raw yaml file: ${VRNC_INPUT_TEMPLATE_RAW_FILE}"
126 echo " Patched yaml file: ${VRNC_INPUT_TEMPLATE_FILE}"
127 cp ${VRNC_INPUT_TEMPLATE_RAW_FILE} ${VRNC_INPUT_TEMPLATE_FILE}
130 # Delete the provider:network_type
131 echo " Patching provider:network_type..."
132 sed -i '/network_type:/d' ${VRNC_INPUT_TEMPLATE_FILE}
134 # Delete the provider:segmentation_id
135 echo " Patching provider:segmentation_id..."
136 sed -i '/segmentation_id:/d' ${VRNC_INPUT_TEMPLATE_FILE}
138 # Delete the provider:physical_network
139 echo " Patching provider:physical_network..."
140 sed -i '/physical_network:/d' ${VRNC_INPUT_TEMPLATE_FILE}
146 make_patch_for_translated_file() {
148 # Replace the signal_transport
149 echo " Patch yaml file: ${VRNC_OUTPUT_TEMPLATE_FILE}"
151 echo " Patching compute:signal_transport"
152 sed -i '1,$s/HEAT_SIGNAL/NO_SIGNAL/g' ${VRNC_OUTPUT_TEMPLATE_FILE}
157 translator_and_deploy_vRNC() {
160 # 1. Delete parser stack ${PARSER_STACK_NAME}, use admin user in admin project
161 openstack ${debug} stack list | grep -qow ${PARSER_STACK_NAME} && {
162 echo " Stack ${PARSER_STACK_NAME} exist, delete it first."
163 openstack stack delete --yes --wait ${PARSER_STACK_NAME}
165 # 2. Switch env to parser project temporally
166 echo " Switch openstack env to parser project"
167 change_env_to_parser_user_project
170 # 3. Patch provider network
171 echo " Make patch for provider network"
172 make_patch_for_provider_network
175 echo " Translator use parser:"
176 echo " 1. Input file: ${VRNC_INPUT_TEMPLATE_FILE}"
177 echo " 2. Output file: ${VRNC_OUTPUT_TEMPLATE_FILE}"
178 heat-translator --template-type tosca --template-file ${VRNC_INPUT_TEMPLATE_FILE} \
179 --output-file ${VRNC_OUTPUT_TEMPLATE_FILE}
182 # 5. Patch translated file
183 echo " Make patch for translated file:"
184 make_patch_for_translated_file
188 echo " Deploy stack..."
189 [[ "${PARSER_CI_DEBUG}" == "true" ]] && debug="--debug" || debug=""
190 openstack ${debug} stack create --timeout 15 --wait --enable-rollback \
191 -t ${VRNC_OUTPUT_TEMPLATE_FILE} ${PARSER_STACK_NAME}
193 # 7. basic information.
194 echo " The basic information of deployment..."
195 openstack ${debug} stack show ${PARSER_STACK_NAME}
197 # 8. deployed resources.
198 echo " The resources of deployment..."
199 openstack ${debug} stack resource list ${PARSER_STACK_NAME}
201 # 9. deployed outputs.
202 echo " The outputs of deployment..."
203 openstack ${debug} stack output list ${PARSER_STACK_NAME}
205 # 10. Validate the deploy result.
206 echo " Checking the result of deployment..."
207 openstack ${debug} stack show ${PARSER_STACK_NAME} | grep -qow "CREATE_COMPLETE" && {
208 echo " Check the result of deployment successfully."
210 echo " Check the result of deployment unsuccessfully."
216 reset_parser_test() {
220 echo " Clean-up the environment..."
221 # 1. Delete resource created by parser user
223 # 1). Switch env to parser project temporally
224 change_env_to_parser_user_project
226 # 2). Delete the stack ${PARSER_STACK_NAME}
228 openstack ${debug} stack list | grep -qow ${PARSER_STACK_NAME} && {
229 echo " Stack ${PARSER_STACK_NAME} has been created, delete it after test."
231 openstack ${debug} stack delete --yes --wait ${PARSER_STACK_NAME}
235 # 3). Delete patch tmp file ${VRNC_INPUT_TEMPLATE_FILE}
236 [ -e ${VRNC_OUTPUT_TEMPLATE_FILE} -a ${PARSER_CI_DEBUG} != "true" ] && {
237 echo " Delete patch temp file ${VRNC_INPUT_TEMPLATE_FILE} after test."
238 rm -fr ${VRNC_INPUT_TEMPLATE_FILE}
241 # 4). Delete hot tmp file ${VRNC_OUTPUT_TEMPLATE_FILE}
242 [ -e ${VRNC_OUTPUT_TEMPLATE_FILE} -a ${PARSER_CI_DEBUG} != "true" ] && {
243 echo " Delete hot temp file ${VRNC_OUTPUT_TEMPLATE_FILE} after test."
244 rm -fr ${VRNC_OUTPUT_TEMPLATE_FILE}
247 # 5). Delete tmp image ${PARSER_IMAGE_FILE}
248 [[ -e ${PARSER_IMAGE_FILE} ]] && {
249 echo " Delete local image file ${PARSER_IMAGE_FILE} after test."
250 rm -fr ${PARSER_IMAGE_FILE}
253 # 6). Delete tmp image ${PARSER_IMAGE_URL_FILE}
254 [ -e ${PARSER_IMAGE_URL_FILE} -a ${PARSER_CI_DEBUG} != "true" ] && {
255 echo " Delete local URL image file ${PARSER_IMAGE_URL_FILE} after test."
256 rm -fr ${PARSER_IMAGE_URL_FILE}
259 # 7). Delete image from openstack
260 parser_image_id=$(openstack ${debug} image list | grep -w "${PARSER_IMAGE_NAME}" | awk '{print $2}')
261 [[ -n "${parser_image_id}" ]] && openstack image delete "${parser_image_id}"
266 # 2. Delete role, user and project
267 echo " Delete user ${PARSER_USER}'s role from project ${PARSER_PROJECT}"
268 openstack ${debug} user role list "${PARSER_USER}" --project "${PARSER_PROJECT}" \
269 | grep -qow "${PARSER_ROLE}" && {
270 openstack ${debug} role remove "${PARSER_ROLE}" --user "${PARSER_USER}" \
271 --project "${PARSER_PROJECT}"
274 echo " Delete user ${PARSER_USER}"
275 openstack ${debug} user list | grep -qow "${PARSER_USER}" && {
276 openstack user delete "${PARSER_USER}"
279 echo " Delete project ${PARSER_PROJECT}"
280 openstack ${debug} project list | grep -qwo "${PARSER_PROJECT}" && {
281 openstack project delete "${PARSER_PROJECT}"
285 echo "======================={ Parser functest end }=========================="
293 echo "======================={ Parser functest begin }=========================="
296 trap reset_parser_test EXIT
298 # start syslog for loghander
299 service rsyslog restart
301 echo "|========= 1/4. Preparing VM image for parser... =========|"
302 download_parser_image
303 register_parser_image
306 echo "|========= 2/4. Creating test user for parser... =========|"
307 create_parser_user_and_project
310 echo "|========= 3/4. Parse -> translate -> deploy vRNC... =========|"
311 translator_and_deploy_vRNC
314 echo "|========= 4/4. Test ok... =========|"