From b90d3e4d6d38972001dae0d82c464977004fbe05 Mon Sep 17 00:00:00 2001 From: gong yong sheng Date: Fri, 26 Aug 2016 20:46:51 +0800 Subject: [PATCH] Add a shell script for developers to prepare functional test env After devstack installation, to run functional test cases, the nova instance quota, keypair and neutron port quota should be set to a level which will not block tests. This patch adds a tool to do this preparation so that developers can easily run functional tests locally. Change-Id: I1c2fae110863906e3f7601456dbf79ff06da4c40 Closes-bug: #1617303 --- doc/source/devref/tacker_functional_test.rst | 20 +++++++-- tacker/tests/contrib/post_test_hook.sh | 16 +------ tacker/tests/contrib/post_test_hook_lib.sh | 46 ++++++++++++++++++++ tools/prepare_functional_test.sh | 18 ++++++++ 4 files changed, 82 insertions(+), 18 deletions(-) create mode 100644 tacker/tests/contrib/post_test_hook_lib.sh create mode 100755 tools/prepare_functional_test.sh diff --git a/doc/source/devref/tacker_functional_test.rst b/doc/source/devref/tacker_functional_test.rst index 7b320fd7d..cada2c45a 100644 --- a/doc/source/devref/tacker_functional_test.rst +++ b/doc/source/devref/tacker_functional_test.rst @@ -88,17 +88,29 @@ Important guidelines to follow: Execution of testcase: ====================== -* From tacker directory, testcases can be executed using following commands: +* Install tacker server via devstack installation, which registers + tacker service and endpoint, creates "nfv_user" and "nfv" project, + and registers default VIM with the created user and project. - (Note: Make sure tacker server is installed and running) +* Under tacker project dir, to prepare function test env via: - * To execute all testcases or one testcase use below commands: +.. code-block:: console + + ./tools/prepare_functional_test.sh + +* From tacker directory, all function testcases can be executed using + following commands: .. code-block:: console tox -e functional - tox -e functional tacker.tests.functional.vnfd. +* Or from tacker directory, specific testcases can be executed using + following commands: + +.. code-block:: console + + tox -e functional tacker.tests.functional.xxx.yyy. Committing testcase and opening a review: diff --git a/tacker/tests/contrib/post_test_hook.sh b/tacker/tests/contrib/post_test_hook.sh index 1def6cff7..43916fd27 100755 --- a/tacker/tests/contrib/post_test_hook.sh +++ b/tacker/tests/contrib/post_test_hook.sh @@ -53,19 +53,7 @@ function generate_testr_results { fi } -function fixup_nova_quota { - echo "Disable nova compute instance & core quota" - source $DEVSTACK_DIR/openrc admin admin - nova quota-class-update --instances -1 --cores -1 default -} - -# Adding nova keypair to support key_name (#1578785). -function add_key { - echo "Adding nova key" - source $DEVSTACK_DIR/openrc admin admin - userId=$(openstack user list | awk '/\ nfv_user\ / {print $2}') - nova keypair-add userKey --user $userId > keypair.priv -} +source ${TACKER_DIR}/tacker/tests/contrib/post_test_hook_lib.sh if [[ "$venv" == dsvm-functional* ]] then @@ -73,7 +61,7 @@ then sudo_env= log_dir="/tmp/${venv}-logs" - fixup_nova_quota + fixup_quota add_key fi diff --git a/tacker/tests/contrib/post_test_hook_lib.sh b/tacker/tests/contrib/post_test_hook_lib.sh new file mode 100644 index 000000000..f5b04175c --- /dev/null +++ b/tacker/tests/contrib/post_test_hook_lib.sh @@ -0,0 +1,46 @@ +#!/bin/bash -x +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +PRIVATE_KEY_FILE=${PRIVATE_KEY_FILE:-"keypair.priv"} + +function fixup_quota { + source $DEVSTACK_DIR/openrc admin admin + echo "Disable nova compute instance & core quota" + nova quota-class-update --instances -1 --cores -1 default + projectId=$(openstack project list | awk '/\ nfv\ / {print $2}') + echo "Disable neutron port quota on project 'nfv' $projectId" + neutron quota-update --tenant-id $projectId --port -1 +} + +# Adding nova keypair if not exist to support key_name (#1578785). +function add_key_if_not_exist { + echo "Adding nova key if not exist" + source $DEVSTACK_DIR/openrc admin admin + userId=$(openstack user list | awk '/\ nfv_user\ / {print $2}') + nova keypair-show userKey --user $userId >/dev/null + if [[ "$?" != "0" ]]; then + nova keypair-add userKey --user $userId > ${PRIVATE_KEY_FILE} + else + echo "Keypair userKey already exists" + fi +} + +# Adding nova keypair to support key_name (#1578785). +# used by OpenStack CI since it will fail if $? is not 0 +function add_key { + echo "Adding nova key" + source $DEVSTACK_DIR/openrc admin admin + userId=$(openstack user list | awk '/\ nfv_user\ / {print $2}') + nova keypair-add userKey --user $userId > ${PRIVATE_KEY_FILE} +} diff --git a/tools/prepare_functional_test.sh b/tools/prepare_functional_test.sh new file mode 100755 index 000000000..725765b65 --- /dev/null +++ b/tools/prepare_functional_test.sh @@ -0,0 +1,18 @@ +# This script is used to prepare functional test env after devstack +# installation of tacker + +DEVSTACK_DIR=${DEVSTACK_DIR:-~/devstack} +TACKER_DIR=$(dirname "$0")/.. +PRIVATE_KEY_FILE=${PRIVATE_KEY_FILE:-/dev/null} +NFV_USER=${NFV_USER:-"nfv_user"} + +# Test devstack dir setting +if [ ! -f ${DEVSTACK_DIR}/openrc ]; then + echo "Please set right DEVSTACK_DIR" + exit 1 +fi + +source ${TACKER_DIR}/tacker/tests/contrib/post_test_hook_lib.sh + +fixup_quota +add_key_if_not_exist