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.0-x86_64-disk.img
24 PARSER_IMAGE_URL_FILE=cirros-0.3.2-x86_64-disk.img
26 # PARSER_IMAGE_URL=https://launchpad.net/cirros/trunk/0.3.0/+download/${PARSER_IMAGE_URL_FILE}
27 PARSER_IMAGE_URL=http://download.cirros-cloud.net/0.3.2/${PARSER_IMAGE_URL_FILE}
28 # PARSER_IMAGE_NAME=rhel-6.5-test-image
29 PARSER_IMAGE_NAME=cirros-0.3.2-x86_64-uec
30 PARSER_IMAGE_FILE="${PARSER_IMAGE_NAME}.img"
31 PARSER_IMAGE_FORMAT=qcow2
34 PARSER_PASSWORD=parser
35 PARSER_EMAIL='shang.xiaodong@zte.com.cn'
37 PARSER_TENANT=${PARSER_PROJECT}
41 PARSER_STACK_NAME=vRNC_Stack
43 # VRNC_INPUT_TEMPLATE_FILE=../tosca2heat/tosca-parser/toscaparser/extensions/nfv/tests/data/vRNC/Definitions/vRNC.yaml
44 # VRNC_INPUT_TEMPLATE_RAW_FILE=../tosca2heat/heat-translator/translator/tests/data/test_tosca_nfv_sample.yaml
45 VRNC_INPUT_TEMPLATE_RAW_FILE=../tosca2heat/heat-translator/translator/tests/data/vRNC/Definitions/vRNC.yaml
46 VRNC_OUTPUT_TEMPLATE_FILE=../tosca2heat/heat-translator/translator/tests/data/vRNC/vRNC_Hot_Template.yaml
48 VRNC_INPUT_TEMPLATE_FILE=${VRNC_INPUT_TEMPLATE_RAW_FILE%.*}_patch.yaml
50 download_parser_image() {
51 [ -e "${PARSER_IMAGE_URL_FILE}" ] && {
52 echo " Image ${PARSER_IMAGE_URL_FILE} has bee cached, needn't download again."
53 cp ${PARSER_IMAGE_URL_FILE} ${PARSER_IMAGE_FILE}
58 echo " Download image ${PARSER_IMAGE_URL_FILE}..."
59 wget ${PARSER_IMAGE_URL} -o ${PARSER_IMAGE_FILE}
62 register_parser_image() {
63 openstack ${debug} image list | grep -qwo "${PARSER_IMAGE_NAME}" && {
64 echo " Image ${PARSER_IMAGE_NAME} has bee registed, needn't registe again."
69 echo " Registe image ${PARSER_IMAGE_NAME}..."
70 openstack ${debug} image create "${PARSER_IMAGE_NAME}" \
72 --disk-format ${PARSER_IMAGE_FORMAT} \
73 --container-format bare \
74 --file ${PARSER_IMAGE_FILE}
77 create_parser_user_and_project() {
79 # 1. create parser project
80 openstack ${debug} project list | grep -qwo "${PARSER_PROJECT}" && {
81 echo " Project ${PARSER_PROJECT} exist, doesn't create agian."
83 openstack ${debug} project create ${PARSER_PROJECT} \
84 --description "Project for parser test"
85 echo " Create project ${PARSER_PROJECT} successful."
88 # 2. create parser user.
89 openstack ${debug} user list | grep -qwo ${PARSER_USER} && {
90 echo " User ${PARSER_USER} exist, doesn't create again."
92 openstack ${debug} user create ${PARSER_USER} --password ${PARSER_PASSWORD} \
93 --project ${PARSER_PROJECT} --email ${PARSER_EMAIL}
94 echo " Create user ${PARSER_USER} successful."
97 # 3. grant role for parser user
98 openstack ${debug} user role list ${PARSER_USER} --project ${PARSER_PROJECT} \
99 | grep -qow ${PARSER_ROLE} && {
100 echo " User ${PARSER_USER} has role ${PARSER_ROLE} in project ${PARSER_PROJECT}, doesn't create."
102 openstack ${debug} role add ${PARSER_ROLE} --user ${PARSER_USER} \
103 --project ${PARSER_PROJECT}
104 echo " Grant user ${PARSER_USER} the role ${PARSER_ROLE} in project ${PARSER_PROJECT} successful."
109 change_env_to_parser_user_project() {
111 export OS_USERNAME=${PARSER_USER}
112 export OS_PASSWORD=${PARSER_PASSWORD}
113 export OS_PROJECT_NAME=${PARSER_PROJECT}
114 export OS_TENANT_NAME=${PARSER_TENANT}
116 export OS_PROJECT_DOMAIN_NAME=${OS_PROJECT_DOMAIN_NAME:-'Default'}
117 export OS_USER_DOMAIN_NAME=${OS_USER_DOMAIN_NAME:-'Default'}
122 make_patch_for_provider_network() {
125 echo " Patch provider network for input file:"
126 echo " Raw yaml file: ${VRNC_INPUT_TEMPLATE_RAW_FILE}"
127 echo " Patched yaml file: ${VRNC_INPUT_TEMPLATE_FILE}"
128 cp ${VRNC_INPUT_TEMPLATE_RAW_FILE} ${VRNC_INPUT_TEMPLATE_FILE}
131 # Delete the provider:network_type
132 echo " Patching provider:network_type..."
133 sed -i '/network_type:/d' ${VRNC_INPUT_TEMPLATE_FILE}
135 # Delete the provider:segmentation_id
136 echo " Patching provider:segmentation_id..."
137 sed -i '/segmentation_id:/d' ${VRNC_INPUT_TEMPLATE_FILE}
139 # Delete the provider:physical_network
140 echo " Patching provider:physical_network..."
141 sed -i '/physical_network:/d' ${VRNC_INPUT_TEMPLATE_FILE}
147 make_patch_for_translated_file() {
149 # Replace the signal_transport
150 echo " Patch yaml file: ${VRNC_OUTPUT_TEMPLATE_FILE}"
152 echo " Patching compute:signal_transport"
153 sed -i '1,$s/HEAT_SIGNAL/NO_SIGNAL/g' ${VRNC_OUTPUT_TEMPLATE_FILE}
158 translator_and_deploy_vRNC() {
161 # 1. Delete parser stack ${PARSER_STACK_NAME}, use admin user in admin project
162 openstack ${debug} stack list | grep -qow ${PARSER_STACK_NAME} && {
163 echo " Stack ${PARSER_STACK_NAME} exist, delete it first."
164 openstack stack delete --yes --wait ${PARSER_STACK_NAME}
166 # 2. Switch env to parser project temporally
167 echo " Switch openstack env to parser project"
168 change_env_to_parser_user_project
171 # 3. Patch provider network
172 echo " Make patch for provider network"
173 make_patch_for_provider_network
176 echo " Translator use parser:"
177 echo " 1. Input file: ${VRNC_INPUT_TEMPLATE_FILE}"
178 echo " 2. Output file: ${VRNC_OUTPUT_TEMPLATE_FILE}"
179 heat-translator --template-type tosca --template-file ${VRNC_INPUT_TEMPLATE_FILE} \
180 --output-file ${VRNC_OUTPUT_TEMPLATE_FILE}
183 # 5. Patch translated file
184 echo " Make patch for translated file:"
185 make_patch_for_translated_file
189 echo " Deploy stack..."
190 [[ "${PARSER_CI_DEBUG}" == "true" ]] && debug="--debug" || debug=""
191 openstack ${debug} stack create --timeout 15 --wait --enable-rollback \
192 -t ${VRNC_OUTPUT_TEMPLATE_FILE} ${PARSER_STACK_NAME}
194 # 7. basic information.
195 echo " The basic information of deployment..."
196 openstack ${debug} stack show ${PARSER_STACK_NAME}
198 # 8. deployed resources.
199 echo " The resources of deployment..."
200 openstack ${debug} stack resource list ${PARSER_STACK_NAME}
202 # 9. deployed outputs.
203 echo " The outputs of deployment..."
204 openstack ${debug} stack output list ${PARSER_STACK_NAME}
206 # 10. Validate the deploy result.
207 echo " Checking the result of deployment..."
208 openstack ${debug} stack show ${PARSER_STACK_NAME} | grep -qow "CREATE_COMPLETE" && {
209 echo " Check the result of deployment successfully."
211 echo " Check the result of deployment unsuccessfully."
217 reset_parser_test() {
221 echo " Clean-up the environment..."
222 # 1. Delete resource created by parser user
224 # 1). Switch env to parser project temporally
225 change_env_to_parser_user_project
227 # 2). Delete the stack ${PARSER_STACK_NAME}
229 openstack ${debug} stack list | grep -qow ${PARSER_STACK_NAME} && {
230 echo " Stack ${PARSER_STACK_NAME} has been created, delete it after test."
232 openstack ${debug} stack delete --yes --wait ${PARSER_STACK_NAME}
236 # 3). Delete patch tmp file ${VRNC_INPUT_TEMPLATE_FILE}
237 [ -e ${VRNC_OUTPUT_TEMPLATE_FILE} -a ${PARSER_CI_DEBUG} != "true" ] && {
238 echo " Delete patch temp file ${VRNC_INPUT_TEMPLATE_FILE} after test."
239 rm -fr ${VRNC_INPUT_TEMPLATE_FILE}
242 # 4). Delete hot tmp file ${VRNC_OUTPUT_TEMPLATE_FILE}
243 [ -e ${VRNC_OUTPUT_TEMPLATE_FILE} -a ${PARSER_CI_DEBUG} != "true" ] && {
244 echo " Delete hot temp file ${VRNC_OUTPUT_TEMPLATE_FILE} after test."
245 rm -fr ${VRNC_OUTPUT_TEMPLATE_FILE}
248 # 5). Delete tmp image ${PARSER_IMAGE_FILE}
249 [[ -e ${PARSER_IMAGE_FILE} ]] && {
250 echo " Delete local image file ${PARSER_IMAGE_FILE} after test."
251 rm -fr ${PARSER_IMAGE_FILE}
254 # 6). Delete tmp image ${PARSER_IMAGE_URL_FILE}
255 [ -e ${PARSER_IMAGE_URL_FILE} -a ${PARSER_CI_DEBUG} != "true" ] && {
256 echo " Delete local URL image file ${PARSER_IMAGE_URL_FILE} after test."
257 rm -fr ${PARSER_IMAGE_URL_FILE}
260 # 7). Delete image from openstack
261 parser_image_id=$(openstack ${debug} image list | grep -w "${PARSER_IMAGE_NAME}" | awk '{print $2}')
262 [[ -n "${parser_image_id}" ]] && openstack image delete "${parser_image_id}"
267 # 2. Delete role, user and project
268 echo " Delete user ${PARSER_USER}'s role from project ${PARSER_PROJECT}"
269 openstack ${debug} user role list "${PARSER_USER}" --project "${PARSER_PROJECT}" \
270 | grep -qow "${PARSER_ROLE}" && {
271 openstack ${debug} role remove "${PARSER_ROLE}" --user "${PARSER_USER}" \
272 --project "${PARSER_PROJECT}"
275 echo " Delete user ${PARSER_USER}"
276 openstack ${debug} user list | grep -qow "${PARSER_USER}" && {
277 openstack user delete "${PARSER_USER}"
280 echo " Delete project ${PARSER_PROJECT}"
281 openstack ${debug} project list | grep -qwo "${PARSER_PROJECT}" && {
282 openstack project delete "${PARSER_PROJECT}"
286 echo "======================={ Parser functest end }=========================="
294 echo "======================={ Parser functest begin }=========================="
297 trap reset_parser_test EXIT
299 # start syslog for loghander
300 service rsyslog restart
302 echo "|========= 1/4. Preparing VM image for parser... =========|"
303 download_parser_image
304 register_parser_image
307 echo "|========= 2/4. Creating test user for parser... =========|"
308 create_parser_user_and_project
311 echo "|========= 3/4. Parse -> translate -> deploy vRNC... =========|"
312 translator_and_deploy_vRNC
315 echo "|========= 4/4. Test ok... =========|"