summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorshangxdy <shang.xiaodong@zte.com.cn>2016-07-31 01:16:21 +0800
committershangxdy <shang.xiaodong@zte.com.cn>2016-08-01 21:45:55 +0800
commitfe6c796bb9cf6c58aa81bfdfd796c6a9076a89b3 (patch)
treecc4f32a83d4c856f8457fac6e74d82c2ee02031d
parented2f6006158e120159f4422bc626cc0d5fe5cecf (diff)
Clear the test env when it is finished
As a tester; I want to return the initial state of a test caseļ¼› So i will clear the env when a testcase is finished. Change-Id: Ibeaa24d7fc29bab03d87719239fce965ef4dea26 JIRA:PARSER-71 Signed-off-by: shangxdy <shang.xiaodong@zte.com.cn>
-rwxr-xr-xtests/functest_run.sh59
1 files changed, 41 insertions, 18 deletions
diff --git a/tests/functest_run.sh b/tests/functest_run.sh
index b3f0743..09345f0 100755
--- a/tests/functest_run.sh
+++ b/tests/functest_run.sh
@@ -10,7 +10,8 @@
[[ "${CI_DEBUG:-true}" == "true" ]] && set -x
-PARSER_IMAGE_URL=https://launchpad.net/cirros/trunk/0.3.0/+download/cirros-0.3.0-x86_64-disk.img
+PARSER_IMAGE_URL_FILE=cirros-0.3.0-x86_64-disk.img
+PARSER_IMAGE_URL=https://launchpad.net/cirros/trunk/0.3.0/+download/${PARSER_IMAGE_URL_FILE}
PARSER_IMAGE_NAME=cirros
PARSER_IMAGE_FILE="${PARSER_IMAGE_NAME}.img"
PARSER_IMAGE_FORMAT=qcow2
@@ -26,19 +27,21 @@ PARSER_ROLE=admin
PARSER_STACK_NAME=vRNC_Stack
-VRNC_INPUT_TEMPLATE_FILE=../tosca2heat/tosca-parser/toscaparser/extensions/nfv/tests/data/vRNC/Definitions/vRNC.yaml
+# VRNC_INPUT_TEMPLATE_FILE=../tosca2heat/tosca-parser/toscaparser/extensions/nfv/tests/data/vRNC/Definitions/vRNC.yaml
+VRNC_INPUT_TEMPLATE_FILE=../tosca2heat/tosca-parser/toscaparser/extensions/nfv/tests/data/tosca_helloworld_nfv.yaml
+
VRNC_OUTPUT_TEMPLATE_FILE=./vRNC_Hot_Template.yaml
download_parser_image() {
- [ -e "${PARSER_IMAGE_FILE}" ] && return 0
- wget "${PARSER_IMAGE_URL}" -o "$IMAGE_FILE"
+ [ -e "${PARSER_IMAGE_URL_FILE}" ] && cp ${PARSER_IMAGE_URL_FILE} ${PARSER_IMAGE_FILE} && return 0
+ wget "${PARSER_IMAGE_URL}" -o "${PARSER_IMAGE_FILE}"
}
register_parser_image() {
openstack image list | grep -qwo "${PARSER_IMAGE_NAME}" && return 0
openstack image create "${PARSER_IMAGE_NAME}" \
--public \
- --disk-format "$IMAGE_FORMAT" \
+ --disk-format "${PARSER_IMAGE_FORMAT}" \
--container-format bare \
--file "${PARSER_IMAGE_FILE}"
}
@@ -49,7 +52,7 @@ create_parser_user_and_project() {
openstack user list | grep -qwo "${PARSER_USER}" && {
echo "User ${PARSER_USER} exist, doesn't crate."
} || {
- openstack user create "${PARSER_USER}" --password "${PARSR_PASSWORD}"
+ openstack user create "${PARSER_USER}" --password "${PARSER_PASSWORD}"
echo "Create user ${PARSER_USER} successful."
}
@@ -85,15 +88,15 @@ change_env_to_parser_user_project() {
translator_and_deploy_vRNC() {
(
# 1. Delete parser stack ${PARSER_STACK_NAME}, use admin user in admin project
- heat stack-list | grep -qow ${PARSER_STACK_NAME} && {
+ openstack stack list | grep -qow ${PARSER_STACK_NAME} && {
echo "stack ${PARSER_STACK_NAME} exist, delete it first."
- heat stack-delete ${PARSER_STACK_NAME}
+ openstack stack delete ${PARSER_STACK_NAME}
}
# 2. Switch env to parser project temporally
change_env_to_parser_user_project
# 3. Translator and deploy vRNC
- heat-translator -f ${VRNC_INPUT_TEMPLATE_FILE} -o ${VRNC_OUTPUT_TEMPLATE_FILE} --deploy True
+ heat-translator --template-type tosca -f ${VRNC_INPUT_TEMPLATE_FILE} -o ${VRNC_OUTPUT_TEMPLATE_FILE} --deploy True
# 4. Wait for create vRNC
sleep 60
@@ -115,9 +118,27 @@ reset_parser_test() {
change_env_to_parser_user_project
# 2. Delete the stack ${PARSER_STACK_NAME}
- heat stack-list | grep -qow ${PARSER_STACK_NAME} && {
- echo "stack ${PARSER_STACK_NAME} exist, delete it."
- heat stack-delete ${PARSER_STACK_NAME}
+ openstack stack list | grep -qow ${PARSER_STACK_NAME} && {
+ echo "stack ${PARSER_STACK_NAME} has been created, delete it after test."
+ openstack stack delete ${PARSER_STACK_NAME}
+ }
+
+ # 3. Delete hot tmp file ${VRNC_OUTPUT_TEMPLATE_FILE}
+ [[ -e ${VRNC_OUTPUT_TEMPLATE_FILE} ]] && {
+ echo "delete hot temp file ${VRNC_OUTPUT_TEMPLATE_FILE} after test."
+ rm -fr ${VRNC_OUTPUT_TEMPLATE_FILE}
+ }
+
+ # 4. Delete tmp image ${PARSER_IMAGE_FILE}
+ [[ -e ${PARSER_IMAGE_FILE} ]] && {
+ echo "delete local image file ${PARSER_IMAGE_FILE} after tes."
+ rm -fr ${PARSER_IMAGE_FILE}
+ }
+
+ # 5. Delete tmp image ${PARSER_IMAGE_URL_FILE}
+ [[ -e ${PARSER_IMAGE_URL_FILE} ]] && {
+ echo "delete local image file ${PARSER_IMAGE_URL_FILE} after tes."
+ rm -fr ${PARSER_IMAGE_URL_FILE}
}
sleep 3
@@ -132,7 +153,9 @@ reset_parser_test() {
openstack project delete "${PARSER_PROJECT}"
openstack user delete "${PARSER_USER}"
- if ret != "ok"
+ if [[ ret != "test_ok" ]]; then
+ echo " ========= 4/4. test error, check your env or code. ========= "
+ echo "======================= Parser functest end =========================="
exit 1
fi
}
@@ -142,18 +165,18 @@ echo "======================= Parser functest begin =========================="
trap reset_parser_test EXIT
-echo " 1. Preparing VM image for parser..."
+echo " ========= 1/4. Preparing VM image for parser... ========= "
download_parser_image
register_parser_image
-echo " 2. Creating test user for parser..."
+echo " ========= 2/4. Creating test user for parser... ========= "
create_parser_user_and_project
-echo " 3. Parse -> translate -> deploy vRNC..."
+echo " ========= 3/4. Parse -> translate -> deploy vRNC... ========= "
translator_and_deploy_vRNC
-echo " 4. clear the test evn..."
-reset_parser_test "ok"
+echo " ========= 4/4. Test ok, clear the test evn... ========= "
+reset_parser_test "test_ok"
echo "======================= Parser functest end =========================="