From e17ff7c7090a41ce61b8bfcf703cc86c2d37ef75 Mon Sep 17 00:00:00 2001 From: Sumit Naiksatam Date: Wed, 4 Mar 2015 13:38:28 -0800 Subject: [PATCH] Provide hooks for FWaaS repo functional gate This provides the needed hook files so that functional tests can be run in the neutron-fwaas repo. A placeholder test case is added, to actually exercise the gate. In a separate commit, real test cases will be added. Change-Id: Iaad6d5d42a103cbaabbf32b7371254cefc4578fb --- neutron_fwaas/tests/contrib/README | 3 ++ neutron_fwaas/tests/contrib/filters.template | 20 +++++++ neutron_fwaas/tests/contrib/gate_hook.sh | 53 +++++++++++++++++++ neutron_fwaas/tests/contrib/post_test_hook.sh | 46 ++++++++++++++++ neutron_fwaas/tests/functional/__init__.py | 0 .../tests/functional/test_fwaas_driver.py | 31 +++++++++++ 6 files changed, 153 insertions(+) create mode 100644 neutron_fwaas/tests/contrib/README create mode 100644 neutron_fwaas/tests/contrib/filters.template create mode 100644 neutron_fwaas/tests/contrib/gate_hook.sh create mode 100644 neutron_fwaas/tests/contrib/post_test_hook.sh create mode 100644 neutron_fwaas/tests/functional/__init__.py create mode 100644 neutron_fwaas/tests/functional/test_fwaas_driver.py diff --git a/neutron_fwaas/tests/contrib/README b/neutron_fwaas/tests/contrib/README new file mode 100644 index 000000000..78dbe5583 --- /dev/null +++ b/neutron_fwaas/tests/contrib/README @@ -0,0 +1,3 @@ +The files in this directory are intended for use by the +infra jobs that run the various functional test +suite in the gate for the neutron-fwaas repo. diff --git a/neutron_fwaas/tests/contrib/filters.template b/neutron_fwaas/tests/contrib/filters.template new file mode 100644 index 000000000..78189d760 --- /dev/null +++ b/neutron_fwaas/tests/contrib/filters.template @@ -0,0 +1,20 @@ +# neutron-rootwrap command filters to support functional testing. It +# is NOT intended to be used outside of a test environment. +# +# This file should be owned by (and only-writeable by) the root user + +[Filters] +# '$BASE_PATH' is intended to be replaced with the expected tox path +# (e.g. /opt/stack/new/neutron/.tox/dsvm-functional) by the neutron +# functional jenkins job. This ensures that tests can kill the +# processes that they launch with their containing tox environment's +# python. +kill_tox_python: KillFilter, root, $BASE_PATH/bin/python, -9 + +# enable ping from namespace +ping_filter: CommandFilter, ping, root + +# enable curl from namespace +curl_filter: CommandFilter, curl, root +tee_filter: CommandFilter, tee, root +tee_kill: KillFilter, root, tee, -9 diff --git a/neutron_fwaas/tests/contrib/gate_hook.sh b/neutron_fwaas/tests/contrib/gate_hook.sh new file mode 100644 index 000000000..e6c47165b --- /dev/null +++ b/neutron_fwaas/tests/contrib/gate_hook.sh @@ -0,0 +1,53 @@ +#!/bin/bash + +set -ex + +CONTRIB_DIR="$BASE/new/neutron-fwaas/neutron_fwaas/tests/contrib" + +$BASE/new/devstack-gate/devstack-vm-gate.sh + +# Add a rootwrap filter to support test-only +# configuration (e.g. a KillFilter for processes that +# use the python installed in a tox env). +FUNC_FILTER=$CONTRIB_DIR/filters.template +sed -e "s+\$BASE_PATH+$BASE/new/neutron-fwaas/.tox/dsvm-functional+" \ + $FUNC_FILTER | sudo tee /etc/neutron/rootwrap.d/functional.filters > /dev/null + +# Use devstack functions to install mysql and psql servers +TOP_DIR=$BASE/new/devstack +source $TOP_DIR/functions +source $TOP_DIR/inc/meta-config +source $TOP_DIR/stackrc +source $TOP_DIR/lib/database +source $TOP_DIR/localrc + +disable_service postgresql +enable_service mysql +initialize_database_backends +install_database + +disable_service mysql +enable_service postgresql +initialize_database_backends +install_database + +# Set up the 'openstack_citest' user and database in each backend +tmp_dir=`mktemp -d` + +cat << EOF > $tmp_dir/mysql.sql +CREATE DATABASE openstack_citest; +CREATE USER 'openstack_citest'@'localhost' IDENTIFIED BY 'openstack_citest'; +CREATE USER 'openstack_citest' IDENTIFIED BY 'openstack_citest'; +GRANT ALL PRIVILEGES ON *.* TO 'openstack_citest'@'localhost'; +GRANT ALL PRIVILEGES ON *.* TO 'openstack_citest'; +FLUSH PRIVILEGES; +EOF +/usr/bin/mysql -u root < $tmp_dir/mysql.sql + +cat << EOF > $tmp_dir/postgresql.sql +CREATE USER openstack_citest WITH CREATEDB LOGIN PASSWORD 'openstack_citest'; +CREATE DATABASE openstack_citest WITH OWNER openstack_citest; +EOF +# User/group postgres needs to be given access to tmp_dir +setfacl -m g:postgres:rwx $tmp_dir +sudo -u postgres /usr/bin/psql --file=$tmp_dir/postgresql.sql diff --git a/neutron_fwaas/tests/contrib/post_test_hook.sh b/neutron_fwaas/tests/contrib/post_test_hook.sh new file mode 100644 index 000000000..5c56f6c7c --- /dev/null +++ b/neutron_fwaas/tests/contrib/post_test_hook.sh @@ -0,0 +1,46 @@ +#!/bin/bash + +set -xe + +NEUTRON_DIR="$BASE/new/neutron-fwaas" +TEMPEST_DIR="$BASE/new/tempest" +SCRIPTS_DIR="/usr/local/jenkins/slave_scripts" + +function generate_testr_results { + # Give job user rights to access tox logs + sudo -H -u $owner chmod o+rw . + sudo -H -u $owner chmod o+rw -R .testrepository + if [ -f ".testrepository/0" ] ; then + .tox/dsvm-functional/bin/subunit-1to2 < .testrepository/0 > ./testrepository.subunit + .tox/dsvm-functional/bin/python $SCRIPTS_DIR/subunit2html.py ./testrepository.subunit testr_results.html + gzip -9 ./testrepository.subunit + gzip -9 ./testr_results.html + sudo mv ./*.gz /opt/stack/logs/ + fi +} + + +function dsvm_functional_prep_func { + : +} + + +owner=stack +prep_func="dsvm_functional_prep_func" + +# Set owner permissions according to job's requirements. +cd $NEUTRON_DIR +sudo chown -R $owner:stack $NEUTRON_DIR +# Prep the environment according to job's requirements. +$prep_func + +# Run tests +echo "Running neutron dsvm-functional test suite" +set +e +sudo -H -u $owner tox -e dsvm-functional +testr_exit_code=$? +set -e + +# Collect and parse results +generate_testr_results +exit $testr_exit_code diff --git a/neutron_fwaas/tests/functional/__init__.py b/neutron_fwaas/tests/functional/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/neutron_fwaas/tests/functional/test_fwaas_driver.py b/neutron_fwaas/tests/functional/test_fwaas_driver.py new file mode 100644 index 000000000..450d1e166 --- /dev/null +++ b/neutron_fwaas/tests/functional/test_fwaas_driver.py @@ -0,0 +1,31 @@ +# Copyright (c) 2015 Cisco Systems, Inc. +# All Rights Reserved. +# +# 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. + +# NOTE: The purpose of this module is to provide a nop test to verify that +# the functional gate is working. + +from neutron.tests.functional.agent.linux import base + + +class TestFWaaSDriver(base.BaseLinuxTestCase): + + """Test the Iptables implmentation of the FWaaS driver.""" + + # NOTE: Tests may be added/removed/changed, when this is fleshed out + # in future commits. + + def test_status_reporting(self): + """Test status reported correctly to agent.""" + pass