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}
112 export OS_PROJECT_DOMAIN_NAME=${OS_PROJECT_DOMAIN_NAME:-'Default'}
113 export OS_USER_DOMAIN_NAME=${OS_USER_DOMAIN_NAME:-'Default'}
118 make_patch_for_provider_network() {
121 echo " Patch provider network for input file:"
122 echo " Raw yaml file: ${VRNC_INPUT_TEMPLATE_RAW_FILE}"
123 echo " Patched yaml file: ${VRNC_INPUT_TEMPLATE_FILE}"
124 cp ${VRNC_INPUT_TEMPLATE_RAW_FILE} ${VRNC_INPUT_TEMPLATE_FILE}
127 # Delete the provider:network_type
128 echo " Patching provider:network_type..."
129 sed -i '/network_type:/d' ${VRNC_INPUT_TEMPLATE_FILE}
131 # Delete the provider:segmentation_id
132 echo " Patching provider:segmentation_id..."
133 sed -i '/segmentation_id:/d' ${VRNC_INPUT_TEMPLATE_FILE}
135 # Delete the provider:physical_network
136 echo " Patching provider:physical_network..."
137 sed -i '/physical_network:/d' ${VRNC_INPUT_TEMPLATE_FILE}
143 make_patch_for_translated_file() {
145 # Replace the signal_transport
146 echo " Patch yaml file: ${VRNC_OUTPUT_TEMPLATE_FILE}"
148 echo " Patching compute:signal_transport"
149 sed -i '1,$s/HEAT_SIGNAL/NO_SIGNAL/g' ${VRNC_OUTPUT_TEMPLATE_FILE}
154 translator_and_deploy_vRNC() {
157 # 1. Delete parser stack ${PARSER_STACK_NAME}, use admin user in admin project
158 openstack ${debug} stack list | grep -qow ${PARSER_STACK_NAME} && {
159 echo " Stack ${PARSER_STACK_NAME} exist, delete it first."
160 openstack stack delete --yes --wait ${PARSER_STACK_NAME}
162 # 2. Switch env to parser project temporally
163 echo " Switch openstack env to parser project"
164 change_env_to_parser_user_project
167 # 3. Patch provider network
168 echo " Make patch for provider network"
169 make_patch_for_provider_network
172 echo " Translator use parser:"
173 echo " 1. Input file: ${VRNC_INPUT_TEMPLATE_FILE}"
174 echo " 2. Output file: ${VRNC_OUTPUT_TEMPLATE_FILE}"
175 heat-translator --template-type tosca --template-file ${VRNC_INPUT_TEMPLATE_FILE} \
176 --output-file ${VRNC_OUTPUT_TEMPLATE_FILE}
179 # 5. Patch translated file
180 echo " Make patch for translated file:"
181 make_patch_for_translated_file
185 echo " Deploy stack..."
186 [[ "${PARSER_CI_DEBUG}" == "true" ]] && debug="--debug" || debug=""
187 openstack ${debug} stack create --timeout 15 --wait --enable-rollback \
188 -t ${VRNC_OUTPUT_TEMPLATE_FILE} ${PARSER_STACK_NAME}
190 # 7. basic information.
191 echo " The basic information of deployment..."
192 openstack ${debug} stack show ${PARSER_STACK_NAME}
194 # 8. deployed resources.
195 echo " The resources of deployment..."
196 openstack ${debug} stack resource list ${PARSER_STACK_NAME}
198 # 9. deployed outputs.
199 echo " The outputs of deployment..."
200 openstack ${debug} stack output list ${PARSER_STACK_NAME}
202 # 10. Validate the deploy result.
203 echo " Checking the result of deployment..."
204 openstack ${debug} stack show ${PARSER_STACK_NAME} | grep -qow "CREATE_COMPLETE" && {
205 echo " Check the result of deployment successfully."
207 echo " Check the result of deployment unsuccessfully."
213 reset_parser_test() {
217 echo " Clean-up the environment..."
218 # 1. Delete resource created by parser user
220 # 1). Switch env to parser project temporally
221 change_env_to_parser_user_project
223 # 2). Delete the stack ${PARSER_STACK_NAME}
225 openstack ${debug} stack list | grep -qow ${PARSER_STACK_NAME} && {
226 echo " Stack ${PARSER_STACK_NAME} has been created, delete it after test."
228 openstack ${debug} stack delete --yes --wait ${PARSER_STACK_NAME}
232 # 3). Delete patch tmp file ${VRNC_INPUT_TEMPLATE_FILE}
233 [ -e ${VRNC_OUTPUT_TEMPLATE_FILE} -a ${PARSER_CI_DEBUG} != "true" ] && {
234 echo " Delete patch temp file ${VRNC_INPUT_TEMPLATE_FILE} after test."
235 rm -fr ${VRNC_INPUT_TEMPLATE_FILE}
238 # 4). Delete hot tmp file ${VRNC_OUTPUT_TEMPLATE_FILE}
239 [ -e ${VRNC_OUTPUT_TEMPLATE_FILE} -a ${PARSER_CI_DEBUG} != "true" ] && {
240 echo " Delete hot temp file ${VRNC_OUTPUT_TEMPLATE_FILE} after test."
241 rm -fr ${VRNC_OUTPUT_TEMPLATE_FILE}
244 # 5). Delete tmp image ${PARSER_IMAGE_FILE}
245 [[ -e ${PARSER_IMAGE_FILE} ]] && {
246 echo " Delete local image file ${PARSER_IMAGE_FILE} after test."
247 rm -fr ${PARSER_IMAGE_FILE}
250 # 6). Delete tmp image ${PARSER_IMAGE_URL_FILE}
251 [ -e ${PARSER_IMAGE_URL_FILE} -a ${PARSER_CI_DEBUG} != "true" ] && {
252 echo " Delete local URL image file ${PARSER_IMAGE_URL_FILE} after test."
253 rm -fr ${PARSER_IMAGE_URL_FILE}
256 # 7). Delete image from openstack
257 parser_image_id=$(openstack ${debug} image list | grep -w "${PARSER_IMAGE_NAME}" | awk '{print $2}')
258 [[ -n "${parser_image_id}" ]] && openstack image delete "${parser_image_id}"
263 # 2. Delete role, user and project
264 echo " Delete user ${PARSER_USER}'s role from project ${PARSER_PROJECT}"
265 openstack ${debug} user role list "${PARSER_USER}" --project "${PARSER_PROJECT}" \
266 | grep -qow "${PARSER_ROLE}" && {
267 openstack ${debug} role remove "${PARSER_ROLE}" --user "${PARSER_USER}" \
268 --project "${PARSER_PROJECT}"
271 echo " Delete user ${PARSER_USER}"
272 openstack ${debug} user list | grep -qow "${PARSER_USER}" && {
273 openstack user delete "${PARSER_USER}"
276 echo " Delete project ${PARSER_PROJECT}"
277 openstack ${debug} project list | grep -qwo "${PARSER_PROJECT}" && {
278 openstack project delete "${PARSER_PROJECT}"
282 echo "======================={ Parser functest end }=========================="
290 echo "======================={ Parser functest begin }=========================="
293 trap reset_parser_test EXIT
295 # start syslog for loghander
296 service rsyslog restart
298 echo "|========= 1/4. Preparing VM image for parser... =========|"
299 download_parser_image
300 register_parser_image
303 echo "|========= 2/4. Creating test user for parser... =========|"
304 create_parser_user_and_project
307 echo "|========= 3/4. Parse -> translate -> deploy vRNC... =========|"
308 translator_and_deploy_vRNC
311 echo "|========= 4/4. Test ok... =========|"