From 81d68d22b462e53635ac9e723353ee829488c35f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Tr=C4=99bski?= Date: Thu, 20 Apr 2017 10:19:25 +0200 Subject: [PATCH] Enable tempest tests with uwsgi keystone Adjusted log-api devstack configuration to works with uwsgi deployed keystone. It is done by removing custom pieces of configuration regarding keystone communication and replacing that with devstack utilities wherever it is possible. Summary: * using configure_auth_token_middleware for log-api configuraton file * removed custom tempest.conf * using devstack/openrc to generate environmental variables OS_ containing necessary details for tempest.conf Extra: * moved kibana_version into monitoring group Story: 2000995 Task: 4183 Depends-On: I22686d05670fc6c947611f8044dea498239a4212 Change-Id: Ia95b3bef2734d639c6fec57484b60bc5377d659f --- devstack/files/kibana/kibana.yml | 3 +- devstack/files/tempest/tempest.conf | 37 --------- devstack/plugin.sh | 84 ++++++++++++++------- devstack/post_test_hook.sh | 105 ++++++++++++++++++++++---- monasca_log_api_tempest/README.md | 103 ++++++++++++++++--------- monasca_log_api_tempest/config.py | 9 +-- monasca_log_api_tempest/tests/base.py | 2 +- 7 files changed, 217 insertions(+), 126 deletions(-) delete mode 100644 devstack/files/tempest/tempest.conf diff --git a/devstack/files/kibana/kibana.yml b/devstack/files/kibana/kibana.yml index 5d33129e..0f7b02b4 100644 --- a/devstack/files/kibana/kibana.yml +++ b/devstack/files/kibana/kibana.yml @@ -71,8 +71,7 @@ logging.quiet: false logging.verbose: true # monasca-kibana-plugin configuration -monasca-kibana-plugin.port: %KEYSTONE_AUTH_PORT% -monasca-kibana-plugin.url: %KEYSTONE_AUTH_PROTOCOL%://%KEYSTONE_AUTH_HOST% +monasca-kibana-plugin.auth_uri: %KEYSTONE_AUTH_URI% monasca-kibana-plugin.enabled: True monasca-kibana-plugin.cookie.isSecure: False diff --git a/devstack/files/tempest/tempest.conf b/devstack/files/tempest/tempest.conf deleted file mode 100644 index 8d87ce5f..00000000 --- a/devstack/files/tempest/tempest.conf +++ /dev/null @@ -1,37 +0,0 @@ -# (C) Copyright 2016 FUJITSU LIMITED -# -# 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. - -[identity] - -username = demo -password = secretadmin -tenant_name = demo -domain_name = default -admin_username = admin -admin_password = secretadmin -admin_domain_name = default -admin_tenant_name = admin -alt_username = mini-mon -alt_password = password -alt_tenant_name = mini-mon -use_ssl = False -auth_version = v3 -uri = http://127.0.0.1:5000/v2.0/ -uri_v3 = http://127.0.0.1:35357/v3/ -kibana_version = 4.6.3 - -[auth] - -use_dynamic_credentials = true diff --git a/devstack/plugin.sh b/devstack/plugin.sh index ba8402cc..dab8dfb6 100644 --- a/devstack/plugin.sh +++ b/devstack/plugin.sh @@ -55,11 +55,15 @@ LOGSTASH_DIR=$DEST/logstash PLUGIN_FILES=$MONASCA_LOG_API_DIR/devstack/files +# Files inside this directory will be visible in gates log +GATE_CONFIGURATION_DIR=/etc/monasca-log-api + # TOP_LEVEL functions called from devstack coordinator ############################################################################### function pre_install { install_elk install_node_nvm + install_gate_config_holder } function install_monasca_log { @@ -78,6 +82,24 @@ function install_elk { install_kibana } +function install_gate_config_holder { + sudo install -d -o $STACK_USER $GATE_CONFIGURATION_DIR +} + +function install_monasca_common { + if use_library_from_git "monasca-common"; then + git_clone_by_name "monasca-common" + setup_dev_lib "monasca-common" + fi +} + +function install_monasca_statsd { + if use_library_from_git "monasca-statsd"; then + git_clone_by_name "monasca-statsd" + setup_dev_lib "monasca-statsd" + fi +} + function configure_monasca_log { configure_kafka configure_elasticsearch @@ -125,6 +147,7 @@ function clean_monasca_log { clean_elasticsearch clean_logstash clean_node_nvm + clean_gate_config_holder } ############################################################################### @@ -137,16 +160,10 @@ function install_monasca-log-api { if [ "$MONASCA_LOG_API_USE_MOD_WSGI" == "False" ]; then pip_install gunicorn fi - pip_install_gr python-memcached - if use_library_from_git "monasca-common"; then - git_clone_by_name "monasca-common" - setup_dev_lib "monasca-common" - fi - if use_library_from_git "monasca-statsd"; then - git_clone_by_name "monasca-statsd" - setup_dev_lib "monasca-statsd" - fi + install_keystonemiddleware + install_monasca_common + install_monasca_statsd if [ "$MONASCA_LOG_API_USE_MOD_WSGI" == "True" ]; then install_apache_wsgi @@ -164,6 +181,9 @@ function configure_monasca_log_api { sudo install -d -o $STACK_USER $MONASCA_LOG_API_CONF_DIR create_log_api_cache_dir + # ensure fresh installation of configuration files + rm -rf $MONASCA_LOG_API_CONF $MONASCA_LOG_API_PASTE_INI $MONASCA_LOG_API_LOGGING_CONF + if [[ "$MONASCA_LOG_API_CONF_DIR" != "$MONASCA_LOG_API_DIR/etc/monasca" ]]; then install -m 600 $MONASCA_LOG_API_DIR/etc/monasca/log-api-config.conf $MONASCA_LOG_API_CONF install -m 600 $MONASCA_LOG_API_DIR/etc/monasca/log-api-config.ini $MONASCA_LOG_API_PASTE_INI @@ -177,19 +197,10 @@ function configure_monasca_log_api { iniset "$MONASCA_LOG_API_CONF" kafka_healthcheck kafka_url $KAFKA_SERVICE_HOST:$KAFKA_SERVICE_PORT # configure keystone middleware - iniset "$MONASCA_LOG_API_CONF" keystone_authtoken auth_url $KEYSTONE_AUTH_URI - iniset "$MONASCA_LOG_API_CONF" keystone_authtoken auth_uri $KEYSTONE_AUTH_URI - iniset "$MONASCA_LOG_API_CONF" keystone_authtoken identity_uri $KEYSTONE_SERVICE_URI - iniset "$MONASCA_LOG_API_CONF" keystone_authtoken admin_user "admin" - iniset "$MONASCA_LOG_API_CONF" keystone_authtoken admin_password $ADMIN_PASSWORD - iniset "$MONASCA_LOG_API_CONF" keystone_authtoken admin_tenant_name "admin" - - # certs - iniset "$MONASCA_LOG_API_CONF" keystone_authtoken cafile $SSL_BUNDLE_FILE - iniset "$MONASCA_LOG_API_CONF" keystone_authtoken signing_dir $MONASCA_LOG_API_CACHE_DIR - - # memcached - iniset "$MONASCA_LOG_API_CONF" keystone_authtoken memcached_servers $SERVICE_HOST:11211 + configure_auth_token_middleware "$MONASCA_LOG_API_CONF" "admin" $MONASCA_LOG_API_CACHE_DIR + iniset "$MONASCA_LOG_API_CONF" keystone_authtoken region_name $REGION_NAME + iniset "$MONASCA_LOG_API_CONF" keystone_authtoken project_name "admin" + iniset "$MONASCA_LOG_API_CONF" keystone_authtoken password $ADMIN_PASSWORD # insecure if is_service_enabled tls-proxy; then @@ -207,6 +218,11 @@ function configure_monasca_log_api { configure_monasca_log_api_wsgi fi + # link configuration for the gate + ln -sf $MONASCA_LOG_API_CONF $GATE_CONFIGURATION_DIR + ln -sf $MONASCA_LOG_API_PASTE_INI $GATE_CONFIGURATION_DIR + ln -sf $MONASCA_LOG_API_LOGGING_CONF $GATE_CONFIGURATION_DIR + fi } @@ -384,6 +400,8 @@ function configure_elasticsearch { s|%ES_DATA_DIR%|$ELASTICSEARCH_DATA_DIR|g; s|%ES_LOG_DIR%|$ELASTICSEARCH_LOG_DIR|g; " -i $ELASTICSEARCH_CFG_DIR/elasticsearch.yml + + ln -sf $ELASTICSEARCH_CFG_DIR/elasticsearch.yml $GATE_CONFIGURATION_DIR/elasticsearch.yml fi } @@ -441,11 +459,10 @@ function configure_kibana { s|%KIBANA_SERVER_BASE_PATH%|$KIBANA_SERVER_BASE_PATH|g; s|%ES_SERVICE_BIND_HOST%|$ES_SERVICE_BIND_HOST|g; s|%ES_SERVICE_BIND_PORT%|$ES_SERVICE_BIND_PORT|g; - s|%KIBANA_LOG_DIR%|$KIBANA_LOG_DIR|g; - s|%KEYSTONE_AUTH_PORT%|$KEYSTONE_AUTH_PORT|g; - s|%KEYSTONE_AUTH_HOST%|$KEYSTONE_AUTH_HOST|g; - s|%KEYSTONE_AUTH_PROTOCOL%|$KEYSTONE_AUTH_PROTOCOL|g; + s|%KEYSTONE_AUTH_URI%|$KEYSTONE_AUTH_URI|g; " -i $KIBANA_CFG_DIR/kibana.yml + + ln -sf $KIBANA_CFG_DIR/kibana.yml $GATE_CONFIGURATION_DIR/kibana.yml fi } @@ -469,7 +486,6 @@ function clean_kibana { sudo rm -rf $KIBANA_DIR || true sudo rm -rf $FILES/kibana-${KIBANA_VERSION}.tar.gz || true - sudo rm -rf $KIBANA_LOG_DIR || true sudo rm -rf $KIBANA_CFG_DIR || true fi } @@ -496,6 +512,8 @@ function configure_monasca_log_persister { sudo sed -e " s|%ES_SERVICE_BIND_HOST%|$ES_SERVICE_BIND_HOST|g; " -i $LOG_PERSISTER_DIR/persister.conf + + ln -sf $LOG_PERSISTER_DIR/persister.conf $GATE_CONFIGURATION_DIR/log-persister.conf fi } @@ -528,6 +546,8 @@ function configure_monasca_log_transformer { s|%KAFKA_SERVICE_HOST%|$KAFKA_SERVICE_HOST|g; s|%KAFKA_SERVICE_PORT%|$KAFKA_SERVICE_PORT|g; " -i $LOG_TRANSFORMER_DIR/transformer.conf + + ln -sf $LOG_TRANSFORMER_DIR/transformer.conf $GATE_CONFIGURATION_DIR/log-transformer.conf fi } @@ -560,6 +580,8 @@ function configure_monasca_log_metrics { s|%KAFKA_SERVICE_HOST%|$KAFKA_SERVICE_HOST|g; s|%KAFKA_SERVICE_PORT%|$KAFKA_SERVICE_PORT|g; " -i $LOG_METRICS_DIR/log-metrics.conf + + ln -sf $LOG_METRICS_DIR/log-metrics.conf $GATE_CONFIGURATION_DIR/log-metrics.conf fi } @@ -604,6 +626,8 @@ function configure_monasca_log_agent { s|%KEYSTONE_AUTH_URI_V3%|$KEYSTONE_AUTH_URI_V3|g; " -i $LOG_AGENT_DIR/agent.conf + ln -sf $LOG_AGENT_DIR/agent.conf $GATE_CONFIGURATION_DIR/log-agent.conf + fi } @@ -618,7 +642,7 @@ function start_monasca_log_agent { if is_service_enabled monasca-log-agent; then echo_summary "Starting monasca-log-agent" local logstash="$LOGSTASH_DIR/bin/logstash" - run_process "monasca-log-agent" "sudo $logstash -f $LOG_AGENT_DIR/agent.conf" + run_process "monasca-log-agent" "$logstash -f $LOG_AGENT_DIR/agent.conf" "root" "root" fi } @@ -655,6 +679,10 @@ function clean_node_nvm { fi } +function clean_gate_config_holder { + sudo rm -rf $GATE_CONFIGURATION_DIR || true +} + function build_kibana_plugin { if is_service_enabled kibana; then echo "Building Kibana plugin" diff --git a/devstack/post_test_hook.sh b/devstack/post_test_hook.sh index 59134780..40eb4655 100644 --- a/devstack/post_test_hook.sh +++ b/devstack/post_test_hook.sh @@ -1,6 +1,6 @@ # # (C) Copyright 2015 Hewlett Packard Enterprise Development Company LP -# (C) Copyright 2016 FUJITSU LIMITED +# (C) Copyright 2016-2017 FUJITSU LIMITED # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -14,25 +14,98 @@ # implied. # See the License for the specific language governing permissions and # limitations under the License. -# -(cd $BASE/new/tempest/; sudo virtualenv .venv) -source $BASE/new/tempest/.venv/bin/activate +# Sleep some time until all services are starting +sleep 6 -(cd $BASE/new/tempest/; sudo -H pip install -r requirements.txt -r test-requirements.txt) -sudo -H pip install nose -sudo -H pip install numpy +function load_devstack_utilities { + source $BASE/new/devstack/stackrc + source $BASE/new/devstack/functions + source $BASE/new/devstack/openrc admin admin -(cd $BASE/new/; sudo sh -c 'cat monasca-log-api/devstack/files/tempest/tempest.conf >> tempest/etc/tempest.conf') + # print OS_ variables + env | grep OS_ +} -sudo cp $BASE/new/tempest/etc/logging.conf.sample $BASE/new/tempest/etc/logging.conf +function setup_monasca_log { + local constraints="-c $REQUIREMENTS_DIR/upper-constraints.txt" -(cd $BASE/new/monasca-log-api/; sudo -H pip install -r requirements.txt -r test-requirements.txt) -(cd $BASE/new/monasca-log-api/; sudo python setup.py install) + pushd $TEMPEST_DIR + sudo -EH pip install $constraints -r requirements.txt -r test-requirements.txt + popd; -(cd $BASE/new/tempest/; sudo testr init) + pushd $MONASCA_LOG_API_DIR + sudo -EH pip install $constraints -r requirements.txt -r test-requirements.txt + sudo -EH python setup.py install + popd; +} -(cd $BASE/new/tempest/; sudo sh -c 'testr list-tests monasca_log_api_tempest > monasca_log_api_tempest') -(cd $BASE/new/tempest/; sudo sh -c 'cat monasca_log_api_tempest') -(cd $BASE/new/tempest/; sudo sh -c 'cat monasca_log_api_tempest | grep gate > monasca_log_api_tempest_gate') -(cd $BASE/new/tempest/; sudo sh -c 'testr run --subunit --load-list=monasca_log_api_tempest_gate | subunit-trace --fails') +function set_tempest_conf { + + local conf_file=$TEMPEST_DIR/etc/tempest.conf + pushd $TEMPEST_DIR + oslo-config-generator \ + --config-file tempest/cmd/config-generator.tempest.conf \ + --output-file $conf_file + popd + + cp -f $DEST/tempest/etc/logging.conf.sample $DEST/tempest/etc/logging.conf + + # set identity section + iniset $conf_file identity admin_domain_scope True + + iniset $conf_file identity user_unique_last_password_count 2 + iniset $conf_file identity user_locakout_duration 5 + iniset $conf_file identity user_lockout_failure_attempts 2 + + iniset $conf_file identity uri $OS_AUTH_URL/v2.0 + iniset $conf_file identity uri_v3 $OS_AUTH_URL/v3 + iniset $conf_file identity auth_version v$OS_IDENTITY_API_VERSION + iniset $conf_file identity region $OS_REGION_NAME + + # NOTE(trebskit) we're processing a lot here, increase http timeout + iniset $conf_file identity-feature-enabled http_timeout 120 + + # set auth section + iniset $conf_file auth use_dynamic_credentials True + iniset $conf_file auth admin_username $OS_USERNAME + iniset $conf_file auth admin_password $OS_PASSWORD + iniset $conf_file auth admin_domain_name $OS_PROJECT_DOMAIN_ID + iniset $conf_file auth admin_project_name $OS_PROJECT_NAME + iniset $conf_file auth tempest_roles monasca-user + + # set monitoring section + iniset $conf_file monitoring kibana_version 4.6.3 +} + +function function_exists { + declare -f -F $1 > /dev/null +} + +if ! function_exists echo_summary; then + function echo_summary { + echo $@ + } +fi + +echo_summary "monasca's post_test_hook.sh was called..." +(set -o posix; set) + +# save ref to monasca-api dir +export MONASCA_LOG_API_DIR="$BASE/new/monasca-log-api" +export TEMPEST_DIR="$BASE/new/tempest" + +sudo chown -R jenkins:stack $MONASCA_LOG_API_DIR +sudo chown -R jenkins:stack $TEMPEST_DIR + +load_devstack_utilities +setup_monasca_log +set_tempest_conf + +# Run functional tests +echo "Running monasca-log tempest test suite" + +(cd $TEMPEST_DIR; testr init) +(cd $TEMPEST_DIR; testr list-tests monasca_log_api_tempest > monasca_log_api_tempest) +(cd $TEMPEST_DIR; cat monasca_log_api_tempest | grep gate > monasca_log_api_tempest_gate) +(cd $TEMPEST_DIR; testr run --subunit --load-list=$TEMPEST_DIR/monasca_log_api_tempest_gate | subunit-trace --fails) diff --git a/monasca_log_api_tempest/README.md b/monasca_log_api_tempest/README.md index 6e57415d..3efa1353 100644 --- a/monasca_log_api_tempest/README.md +++ b/monasca_log_api_tempest/README.md @@ -23,7 +23,7 @@ Therefore it is possible to proceed with installation as described # Configuration 1. Clone the OpenStack Tempest repo, and cd to it. -``` +```bash git clone https://git.openstack.org/openstack/tempest.git cd tempest ``` @@ -31,54 +31,83 @@ Therefore it is possible to proceed with installation as described 2. Create a virtualenv for running the Tempest tests and activate it. For example in the Tempest root dir -``` +```bash virtualenv .venv source .venv/bin/activate ``` 3. Install the Tempest requirements in the virtualenv. -``` - pip install -r requirements.txt -r test-requirements.txt - pip install nose +```bash + pip install \ + -c https://git.openstack.org/cgit/openstack/requirements/plain/upper-constraints.txt \ + -r requirements.txt \ + -r test-requirements.txt ``` 4. Create ```etc/tempest.conf``` in the Tempest root dir by running the following command: - ``` - oslo-config-generator --config-file tempest/cmd/config-generator.tempest.conf --output-file etc/tempest.conf - ``` +```bash + oslo-config-generator --config-file tempest/cmd/config-generator.tempest.conf --output-file etc/tempest.conf +``` Add the following sections to ```tempest.conf``` for testing using the monasca-vagrant environment. - ``` - [identity] - auth_version = v3 - admin_domain_name = Default - admin_tenant_name = admin - admin_password = admin - admin_username = admin - alt_tenant_name = demo - alt_password = admin - alt_username = alt_demo - tenant_name = mini-mon - password = password - username = mini-mon - uri_v3 = http://192.168.10.5:35357/v3/ - uri = http://192.168.10.5:35357/v2.0/ - force_tenant_isolation = False - allow_tenant_isolation = False - disable_ssl_certificate_validation = True - kibana_version = 4.6.3 +```ini + [identity] + region = RegionOne + auth_version = v3 + uri = http://10.36.99.238/identity_admin/v2.0 + uri_v3 = http://10.36.99.238/identity_admin/v3 + user_lockout_failure_attempts = 2 + user_locakout_duration = 5 + user_unique_last_password_count = 2 + admin_domain_scope = True - [auth] - allow_tenant_isolation = true - ``` + [auth] + tempest_roles = monasca-user + admin_project_name = admin + admin_domain_name = default + admin_password = secretadmin + admin_username = admin + use_dynamic_credentials = True - Edit the variable values in the identity section to match your particular - monasca-vagrant environment. + [monitoring] + kibana_version = 4.6.3 + api_version = v2.0 # or v3.0 +``` + +Edit the variable values in the identity section to match your particular +monasca-vagrant environment. Best way to do this might be + +```bash + source devstack/openrc {username} {password} +``` + +and collect all relevant values using + +```bash + env | grep OS_ +``` + +An output will be similar to this one + +```bash + OS_PROJECT_DOMAIN_ID=default + OS_REGION_NAME=RegionOne + OS_USER_DOMAIN_ID=default + OS_PROJECT_NAME=admin + OS_IDENTITY_API_VERSION=3 + OS_PASSWORD=secretadmin + OS_AUTH_TYPE=password + OS_AUTH_URL=http://10.36.99.238/identity_admin + OS_USERNAME=admin + OS_TENANT_NAME=admin + OS_VOLUME_API_VERSION=2 + OS_NO_CACHE=True +``` 5. Create ```etc/logging.conf``` in the Tempest root dir by making a copying ```logging.conf.sample```. @@ -92,9 +121,13 @@ Tempest root dir. cd into the monasa-log-api root directory. Making sure that the tempest virtual env is still active, run the following command. - ``` - python setup.py install - ``` +``` + pip install \ + -c https://git.openstack.org/cgit/openstack/requirements/plain/upper-constraints.txt \ + -r requirements.txt \ + -r test-requirements.txt + python setup.py install +``` See the [OpenStack Tempest Plugin Interface](http://docs.openstack.org/developer/tempest/plugin.html), for more diff --git a/monasca_log_api_tempest/config.py b/monasca_log_api_tempest/config.py index 9056ca38..1c63e9bd 100644 --- a/monasca_log_api_tempest/config.py +++ b/monasca_log_api_tempest/config.py @@ -24,7 +24,7 @@ ServiceAvailableGroup = [ cfg.BoolOpt('logs-search', default=True, help=('Whether or not Monasca-Log-Api search engine ' - '(ElasticSearch) is expected to be available')), + '(ElasticSearch) is expected to be available')) ] monitoring_group = cfg.OptGroup(name='monitoring', @@ -33,12 +33,7 @@ MonitoringGroup = [ cfg.StrOpt('api_version', default='v2.0', help='monasca-log-api API version'), -] - -IdentityGroup = [ cfg.StrOpt('kibana_version', - default='4.4.0', + default='4.6.3', help='Kibana version') ] - -cfg.CONF.register_opts(IdentityGroup, group='identity') diff --git a/monasca_log_api_tempest/tests/base.py b/monasca_log_api_tempest/tests/base.py index 4ecbf67f..4a06f0ec 100644 --- a/monasca_log_api_tempest/tests/base.py +++ b/monasca_log_api_tempest/tests/base.py @@ -76,7 +76,7 @@ def _get_headers(headers=None, content_type="application/json"): headers = {} headers.update({ 'Content-Type': content_type, - 'kbn-version': CONF.identity.kibana_version + 'kbn-version': CONF.monitoring.kibana_version }) return headers