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 " Patch provider:network_type..."
126 sed -i '/network_type:/d' ${VRNC_INPUT_TEMPLATE_FILE}
128 # Delete the provider:segmentation_id
129 echo " Patch provider:segmentation_id..."
130 sed -i '/segmentation_id:/d' ${VRNC_INPUT_TEMPLATE_FILE}
132 # Delete the provider:physical_network
133 echo " Patch 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 compute:signal_transport..."
144 sed -i '1,$s/HEAT_SIGNAL/NO_SIGNAL/g' ${VRNC_OUTPUT_TEMPLATE_FILE}
149 translator_and_deploy_vRNC() {
152 # 1. Delete parser stack ${PARSER_STACK_NAME}, use admin user in admin project
153 openstack ${debug} stack list | grep -qow ${PARSER_STACK_NAME} && {
154 echo " Stack ${PARSER_STACK_NAME} exist, delete it first."
155 openstack stack delete --yes --wait ${PARSER_STACK_NAME}
157 # 2. Switch env to parser project temporally
158 echo " Switch openstack env to parser project"
159 change_env_to_parser_user_project
162 # 3. Patch provider network
163 echo " Make patch for provider network"
164 make_patch_for_provider_network
167 echo " Translator use parser:"
168 echo " 1. Input file: ${VRNC_INPUT_TEMPLATE_FILE}"
169 echo " 2. Output file: ${VRNC_OUTPUT_TEMPLATE_FILE}"
170 heat-translator --template-type tosca --template-file ${VRNC_INPUT_TEMPLATE_FILE} \
171 --output-file ${VRNC_OUTPUT_TEMPLATE_FILE}
174 # 5. Patch translated file
175 echo " Make patch for translated file..."
176 make_patch_for_translated_file
180 echo " Deploy stack..."
181 [[ "${PARSER_CI_DEBUG}" == "true" ]] && debug="--debug" || debug=""
182 openstack ${debug} stack create --timeout 30 --wait --enable-rollback \
183 -t ${VRNC_OUTPUT_TEMPLATE_FILE} ${PARSER_STACK_NAME}
185 # 7. Validate the deploy result.
186 echo " Checking the result of deployment..."
187 openstack ${debug} stack show ${PARSER_STACK_NAME} | grep -qow "CREATE_COMPLETE" && {
188 echo " Check the result of deployment successfully."
190 echo " Check the result of deployment unsuccessfully."
196 reset_parser_test() {
200 echo " Clean-up the environment..."
201 # 1. Delete resource created by parser user
203 # 1). Switch env to parser project temporally
204 change_env_to_parser_user_project
206 # 2). Delete the stack ${PARSER_STACK_NAME}
208 openstack ${debug} stack list | grep -qow ${PARSER_STACK_NAME} && {
209 echo " Stack ${PARSER_STACK_NAME} has been created, delete it after test."
211 openstack ${debug} stack delete --yes --wait ${PARSER_STACK_NAME}
215 # 3). Delete patch tmp file ${VRNC_INPUT_TEMPLATE_FILE}
216 [ -e ${VRNC_OUTPUT_TEMPLATE_FILE} -a ${PARSER_CI_DEBUG} != "true" ] && {
217 echo " Delete patch temp file ${VRNC_INPUT_TEMPLATE_FILE} after test."
218 rm -fr ${VRNC_INPUT_TEMPLATE_FILE}
221 # 4). Delete hot tmp file ${VRNC_OUTPUT_TEMPLATE_FILE}
222 [ -e ${VRNC_OUTPUT_TEMPLATE_FILE} -a ${PARSER_CI_DEBUG} != "true" ] && {
223 echo " Delete hot temp file ${VRNC_OUTPUT_TEMPLATE_FILE} after test."
224 rm -fr ${VRNC_OUTPUT_TEMPLATE_FILE}
227 # 5). Delete tmp image ${PARSER_IMAGE_FILE}
228 [[ -e ${PARSER_IMAGE_FILE} ]] && {
229 echo " Delete local image file ${PARSER_IMAGE_FILE} after test."
230 rm -fr ${PARSER_IMAGE_FILE}
233 # 6). Delete tmp image ${PARSER_IMAGE_URL_FILE}
234 [ -e ${PARSER_IMAGE_URL_FILE} -a ${PARSER_CI_DEBUG} != "true" ] && {
235 echo " Delete local URL image file ${PARSER_IMAGE_URL_FILE} after test."
236 rm -fr ${PARSER_IMAGE_URL_FILE}
239 # 7). Delete image from openstack
240 parser_image_id=$(openstack ${debug} image list | grep -w "${PARSER_IMAGE_NAME}" | awk '{print $2}')
241 [[ -n "${parser_image_id}" ]] && openstack image delete "${parser_image_id}"
246 # 2. Delete role, user and project
247 echo " Delete user ${PARSER_USER}'s role from project ${PARSER_PROJECT}"
248 openstack ${debug} user role list "${PARSER_USER}" --project "${PARSER_PROJECT}" \
249 | grep -qow "${PARSER_ROLE}" && {
250 openstack ${debug} role remove "${PARSER_ROLE}" --user "${PARSER_USER}" \
251 --project "${PARSER_PROJECT}"
254 echo " Delete user ${PARSER_USER}"
255 openstack ${debug} user list | grep -qow "${PARSER_USER}" && {
256 openstack user delete "${PARSER_USER}"
259 echo " Delete project ${PARSER_PROJECT}"
260 openstack ${debug} project list | grep -qwo "${PARSER_PROJECT}" && {
261 openstack project delete "${PARSER_PROJECT}"
265 echo "======================= Parser functest end =========================="
273 echo "======================= Parser functest begin =========================="
276 trap reset_parser_test EXIT
278 # start syslog for loghander
279 service rsyslog restart
281 echo "|========= 1/4. Preparing VM image for parser... =========|"
282 download_parser_image
283 register_parser_image
286 echo "|========= 2/4. Creating test user for parser... =========|"
287 create_parser_user_and_project
290 echo "|========= 3/4. Parse -> translate -> deploy vRNC... =========|"
291 translator_and_deploy_vRNC
294 echo "|========= 4/4. Test ok... =========|"