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" ]] && {
20 # PARSER_IMAGE_URL_FILE=cirros-0.3.0-x86_64-disk.img
21 PARSER_IMAGE_URL_FILE=cirros-0.3.2-x86_64-disk.img
22 # PARSER_IMAGE_URL=https://launchpad.net/cirros/trunk/0.3.0/+download/${PARSER_IMAGE_URL_FILE}
23 PARSER_IMAGE_URL=http://download.cirros-cloud.net/0.3.2/${PARSER_IMAGE_URL_FILE}
24 # PARSER_IMAGE_NAME=rhel-6.5-test-image
25 PARSER_IMAGE_NAME=cirros-0.3.2-x86_64-uec
26 PARSER_IMAGE_FILE="${PARSER_IMAGE_NAME}.img"
27 PARSER_IMAGE_FORMAT=qcow2
30 PARSER_PASSWORD=parser
31 PARSER_EMAIL='shang.xiaodong@zte.com.cn'
33 PARSER_TENANT=${PARSER_PROJECT}
37 PARSER_STACK_NAME=vRNC_Stack
39 # VRNC_INPUT_TEMPLATE_FILE=../tosca2heat/tosca-parser/toscaparser/extensions/nfv/tests/data/vRNC/Definitions/vRNC.yaml
40 # VRNC_INPUT_TEMPLATE_RAW_FILE=../tosca2heat/heat-translator/translator/tests/data/test_tosca_nfv_sample.yaml
41 VRNC_INPUT_TEMPLATE_RAW_FILE=../tosca2heat/heat-translator/translator/tests/data/vRNC/Definitions/vRNC.yaml
42 VRNC_OUTPUT_TEMPLATE_FILE=../tosca2heat/heat-translator/translator/tests/data/vRNC/vRNC_Hot_Template.yaml
44 VRNC_INPUT_TEMPLATE_FILE=${VRNC_INPUT_TEMPLATE_RAW_FILE%.*}_patch.yaml
46 download_parser_image() {
47 [ -e "${PARSER_IMAGE_URL_FILE}" ] && {
48 echo " Image ${PARSER_IMAGE_URL_FILE} has bee cached, needn't download again."
49 cp ${PARSER_IMAGE_URL_FILE} ${PARSER_IMAGE_FILE}
54 echo " Download image ${PARSER_IMAGE_URL_FILE}..."
55 wget ${PARSER_IMAGE_URL} -o ${PARSER_IMAGE_FILE}
58 register_parser_image() {
59 openstack ${debug} image list | grep -qwo "${PARSER_IMAGE_NAME}" && {
60 echo " Image ${PARSER_IMAGE_NAME} has bee registed, needn't registe again."
65 echo " Registe image ${PARSER_IMAGE_NAME}..."
66 openstack ${debug} image create "${PARSER_IMAGE_NAME}" \
68 --disk-format ${PARSER_IMAGE_FORMAT} \
69 --container-format bare \
70 --file ${PARSER_IMAGE_FILE}
73 create_parser_user_and_project() {
75 # 1. create parser project
76 openstack ${debug} project list | grep -qwo "${PARSER_PROJECT}" && {
77 echo " Project ${PARSER_PROJECT} exist, doesn't create agian."
79 openstack ${debug} project create ${PARSER_PROJECT} \
80 --description "Project for parser test"
81 echo " Create project ${PARSER_PROJECT} successful."
84 # 2. create parser user.
85 openstack ${debug} user list | grep -qwo ${PARSER_USER} && {
86 echo " User ${PARSER_USER} exist, doesn't create again."
88 openstack ${debug} user create ${PARSER_USER} --password ${PARSER_PASSWORD} \
89 --project ${PARSER_PROJECT} --email ${PARSER_EMAIL}
90 echo " Create user ${PARSER_USER} successful."
93 # 3. grant role for parser user
94 openstack ${debug} user role list ${PARSER_USER} --project ${PARSER_PROJECT} \
95 | grep -qow ${PARSER_ROLE} && {
96 echo " User ${PARSER_USER} has role ${PARSER_ROLE} in project ${PARSER_PROJECT}, doesn't create."
98 openstack ${debug} role add ${PARSER_ROLE} --user ${PARSER_USER} \
99 --project ${PARSER_PROJECT}
100 echo " Grant user ${PARSER_USER} the role ${PARSER_ROLE} in project ${PARSER_PROJECT} successful."
105 change_env_to_parser_user_project() {
107 export OS_USERNAME=${PARSER_USER}
108 export OS_PASSWORD=${PARSER_PASSWORD}
109 export OS_PROJECT_NAME=${PARSER_PROJECT}
110 export OS_TENANT_NAME=${PARSER_TENANT}
115 make_patch_for_provider_network() {
118 echo " Patch provider network for input file:"
119 echo " Raw yaml file: ${VRNC_INPUT_TEMPLATE_RAW_FILE}"
120 echo " Patched yaml file: ${VRNC_INPUT_TEMPLATE_FILE}"
121 cp ${VRNC_INPUT_TEMPLATE_RAW_FILE} ${VRNC_INPUT_TEMPLATE_FILE}
124 # Delete the provider:network_type
125 echo " Patching provider:network_type..."
126 sed -i '/network_type:/d' ${VRNC_INPUT_TEMPLATE_FILE}
128 # Delete the provider:segmentation_id
129 echo " Patching provider:segmentation_id..."
130 sed -i '/segmentation_id:/d' ${VRNC_INPUT_TEMPLATE_FILE}
132 # Delete the provider:physical_network
133 echo " Patching provider:physical_network..."
134 sed -i '/physical_network:/d' ${VRNC_INPUT_TEMPLATE_FILE}
140 make_patch_for_translated_file() {
142 # Replace the signal_transport
143 echo " Patch yaml file: ${VRNC_OUTPUT_TEMPLATE_FILE}"
145 echo " Patching compute:signal_transport:"
146 sed -i '1,$s/HEAT_SIGNAL/NO_SIGNAL/g' ${VRNC_OUTPUT_TEMPLATE_FILE}
151 translator_and_deploy_vRNC() {
154 # 1. Delete parser stack ${PARSER_STACK_NAME}, use admin user in admin project
155 openstack ${debug} stack list | grep -qow ${PARSER_STACK_NAME} && {
156 echo " Stack ${PARSER_STACK_NAME} exist, delete it first."
157 openstack stack delete --yes --wait ${PARSER_STACK_NAME}
159 # 2. Switch env to parser project temporally
160 echo " Switch openstack env to parser project"
161 change_env_to_parser_user_project
164 # 3. Patch provider network
165 echo " Make patch for provider network"
166 make_patch_for_provider_network
169 echo " Translator use parser:"
170 echo " 1. Input file: ${VRNC_INPUT_TEMPLATE_FILE}"
171 echo " 2. Output file: ${VRNC_OUTPUT_TEMPLATE_FILE}"
172 heat-translator --template-type tosca --template-file ${VRNC_INPUT_TEMPLATE_FILE} \
173 --output-file ${VRNC_OUTPUT_TEMPLATE_FILE}
176 # 5. Patch translated file
177 echo " Make patch for translated file:"
178 make_patch_for_translated_file
182 echo " Deploy stack..."
183 [[ "${PARSER_CI_DEBUG}" == "true" ]] && debug="--debug" || debug=""
184 openstack ${debug} stack create --timeout 15 --wait --enable-rollback \
185 -t ${VRNC_OUTPUT_TEMPLATE_FILE} ${PARSER_STACK_NAME}
187 # 7. basic information.
188 echo " The basic information of deployment..."
189 openstack ${debug} stack show ${PARSER_STACK_NAME}
191 # 8. deployed resources.
192 echo " The resources of deployment..."
193 openstack ${debug} stack resource list ${PARSER_STACK_NAME}
195 # 9. deployed outputs.
196 echo " The outputs of deployment..."
197 openstack ${debug} stack output list ${PARSER_STACK_NAME}
199 # 10. Validate the deploy result.
200 echo " Checking the result of deployment..."
201 openstack ${debug} stack show ${PARSER_STACK_NAME} | grep -qow "CREATE_COMPLETE" && {
202 echo " Check the result of deployment successfully."
204 echo " Check the result of deployment unsuccessfully."
210 reset_parser_test() {
214 echo " Clean-up the environment..."
215 # 1. Delete resource created by parser user
217 # 1). Switch env to parser project temporally
218 change_env_to_parser_user_project
220 # 2). Delete the stack ${PARSER_STACK_NAME}
222 openstack ${debug} stack list | grep -qow ${PARSER_STACK_NAME} && {
223 echo " Stack ${PARSER_STACK_NAME} has been created, delete it after test."
225 openstack ${debug} stack delete --yes --wait ${PARSER_STACK_NAME}
229 # 3). Delete patch tmp file ${VRNC_INPUT_TEMPLATE_FILE}
230 [ -e ${VRNC_OUTPUT_TEMPLATE_FILE} -a ${PARSER_CI_DEBUG} != "true" ] && {
231 echo " Delete patch temp file ${VRNC_INPUT_TEMPLATE_FILE} after test."
232 rm -fr ${VRNC_INPUT_TEMPLATE_FILE}
235 # 4). Delete hot tmp file ${VRNC_OUTPUT_TEMPLATE_FILE}
236 [ -e ${VRNC_OUTPUT_TEMPLATE_FILE} -a ${PARSER_CI_DEBUG} != "true" ] && {
237 echo " Delete hot temp file ${VRNC_OUTPUT_TEMPLATE_FILE} after test."
238 rm -fr ${VRNC_OUTPUT_TEMPLATE_FILE}
241 # 5). Delete tmp image ${PARSER_IMAGE_FILE}
242 [[ -e ${PARSER_IMAGE_FILE} ]] && {
243 echo " Delete local image file ${PARSER_IMAGE_FILE} after test."
244 rm -fr ${PARSER_IMAGE_FILE}
247 # 6). Delete tmp image ${PARSER_IMAGE_URL_FILE}
248 [ -e ${PARSER_IMAGE_URL_FILE} -a ${PARSER_CI_DEBUG} != "true" ] && {
249 echo " Delete local URL image file ${PARSER_IMAGE_URL_FILE} after test."
250 rm -fr ${PARSER_IMAGE_URL_FILE}
253 # 7). Delete image from openstack
254 parser_image_id=$(openstack ${debug} image list | grep -w "${PARSER_IMAGE_NAME}" | awk '{print $2}')
255 [[ -n "${parser_image_id}" ]] && openstack image delete "${parser_image_id}"
260 # 2. Delete role, user and project
261 echo " Delete user ${PARSER_USER}'s role from project ${PARSER_PROJECT}"
262 openstack ${debug} user role list "${PARSER_USER}" --project "${PARSER_PROJECT}" \
263 | grep -qow "${PARSER_ROLE}" && {
264 openstack ${debug} role remove "${PARSER_ROLE}" --user "${PARSER_USER}" \
265 --project "${PARSER_PROJECT}"
268 echo " Delete user ${PARSER_USER}"
269 openstack ${debug} user list | grep -qow "${PARSER_USER}" && {
270 openstack user delete "${PARSER_USER}"
273 echo " Delete project ${PARSER_PROJECT}"
274 openstack ${debug} project list | grep -qwo "${PARSER_PROJECT}" && {
275 openstack project delete "${PARSER_PROJECT}"
279 echo "======================={ Parser functest end }=========================="
287 echo "======================={ Parser functest begin }=========================="
290 trap reset_parser_test EXIT
292 # start syslog for loghander
293 service rsyslog restart
295 echo "|========= 1/4. Preparing VM image for parser... =========|"
296 download_parser_image
297 register_parser_image
300 echo "|========= 2/4. Creating test user for parser... =========|"
301 create_parser_user_and_project
304 echo "|========= 3/4. Parse -> translate -> deploy vRNC... =========|"
305 translator_and_deploy_vRNC
308 echo "|========= 4/4. Test ok... =========|"