From ab5c981ed2dcba2510e492867fbce84963e639bc Mon Sep 17 00:00:00 2001 From: Nik Everett Date: Wed, 2 Sep 2015 15:16:53 -0400 Subject: [PATCH 1/2] [test] Test upgrading from an older version Adds a test for upgrading from 2.0.0-beta1 to the version of that is built. Closes #13183 --- qa/vagrant/pom.xml | 41 +++++++ .../packaging/scripts/30_deb_package.bats | 4 +- .../packaging/scripts/40_rpm_package.bats | 4 +- .../packaging/scripts/80_upgrade.bats | 105 ++++++++++++++++++ .../scripts/packaging_test_utils.bash | 34 ++++-- 5 files changed, 174 insertions(+), 14 deletions(-) create mode 100644 qa/vagrant/src/test/resources/packaging/scripts/80_upgrade.bats diff --git a/qa/vagrant/pom.xml b/qa/vagrant/pom.xml index ed9422b64e2..647a5c8de1f 100644 --- a/qa/vagrant/pom.xml +++ b/qa/vagrant/pom.xml @@ -34,6 +34,8 @@ /usr/bin/rpmbuild + + 2.0.0-beta1 @@ -92,6 +94,14 @@ ${elasticsearch.version} deb + + + org.elasticsearch.distribution.deb + elasticsearch + ${upgrade.from.version} + deb + org.elasticsearch.plugin jvm-example @@ -219,6 +229,21 @@ + + setup-version-files + pre-integration-test + + run + + + + + + + + test-vms integration-test @@ -269,6 +294,14 @@ ${elasticsearch.version} rpm + + + org.elasticsearch.distribution.rpm + elasticsearch + ${upgrade.from.version} + rpm + @@ -309,6 +342,14 @@ ${elasticsearch.version} rpm + + + org.elasticsearch.distribution.rpm + elasticsearch + ${upgrade.from.version} + rpm + diff --git a/qa/vagrant/src/test/resources/packaging/scripts/30_deb_package.bats b/qa/vagrant/src/test/resources/packaging/scripts/30_deb_package.bats index 3367e62fcf8..38aa352d4c4 100644 --- a/qa/vagrant/src/test/resources/packaging/scripts/30_deb_package.bats +++ b/qa/vagrant/src/test/resources/packaging/scripts/30_deb_package.bats @@ -46,7 +46,7 @@ setup() { } @test "[DEB] package is available" { - count=$(find . -type f -name 'elastic*.deb' | wc -l) + count=$(ls elasticsearch-$(cat version).deb | wc -l) [ "$count" -eq 1 ] } @@ -56,7 +56,7 @@ setup() { } @test "[DEB] install package" { - dpkg -i elasticsearch*.deb + dpkg -i elasticsearch-$(cat version).deb } @test "[DEB] package is installed" { diff --git a/qa/vagrant/src/test/resources/packaging/scripts/40_rpm_package.bats b/qa/vagrant/src/test/resources/packaging/scripts/40_rpm_package.bats index cbcdd794c76..b5d8a7b2844 100644 --- a/qa/vagrant/src/test/resources/packaging/scripts/40_rpm_package.bats +++ b/qa/vagrant/src/test/resources/packaging/scripts/40_rpm_package.bats @@ -45,7 +45,7 @@ setup() { } @test "[RPM] package is available" { - count=$(find . -type f -name 'elastic*.rpm' | wc -l) + count=$(ls elasticsearch-$(cat version).rpm | wc -l) [ "$count" -eq 1 ] } @@ -55,7 +55,7 @@ setup() { } @test "[RPM] install package" { - rpm -i elasticsearch*.rpm + rpm -i elasticsearch-$(cat version).rpm } @test "[RPM] package is installed" { diff --git a/qa/vagrant/src/test/resources/packaging/scripts/80_upgrade.bats b/qa/vagrant/src/test/resources/packaging/scripts/80_upgrade.bats new file mode 100644 index 00000000000..fceea65d29a --- /dev/null +++ b/qa/vagrant/src/test/resources/packaging/scripts/80_upgrade.bats @@ -0,0 +1,105 @@ +#!/usr/bin/env bats + +# Tests upgrading elasticsearch from a previous version with the deb or rpm +# packages. Just uses a single node cluster on the current machine rather than +# fancy rolling restarts. + +# WARNING: This testing file must be executed as root and can +# dramatically change your system. It removes the 'elasticsearch' +# user/group and also many directories. Do not execute this file +# unless you know exactly what you are doing. + +# The test case can be executed with the Bash Automated +# Testing System tool available at https://github.com/sstephenson/bats +# Thanks to Sam Stephenson! + +# Licensed to Elasticsearch under one or more contributor +# license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright +# ownership. Elasticsearch licenses this file to you 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. + +# Load test utilities +load packaging_test_utils + +# Cleans everything for the 1st execution +setup() { + skip_not_dpkg_or_rpm +} + +@test "[UPGRADE] install old version" { + clean_before_test + install_package -v $(cat upgrade_from_version) +} + +@test "[UPGRADE] start old version" { + start_elasticsearch_service +} + +@test "[UPGRADE] check elasticsearch version is old version" { + curl -s localhost:9200 | grep \"number\"\ :\ \"$(cat upgrade_from_version)\" || { + echo "Installed an unexpected version:" + curl localhost:9200 + false + } +} + +@test "[UPGRADE] index some documents into a few indexes" { + curl -s -XPOST localhost:9200/library/book/1?pretty -d '{ + "title": "Elasticsearch - The Definitive Guide" + }' + curl -s -XPOST localhost:9200/library/book/2?pretty -d '{ + "title": "Brave New World" + }' + curl -s -XPOST localhost:9200/library2/book/1?pretty -d '{ + "title": "The Left Hand of Darkness" + }' +} + +@test "[UPGRADE] verify that the documents are there" { + curl -s localhost:9200/library/book/1?pretty | grep Elasticsearch + curl -s localhost:9200/library/book/2?pretty | grep World + curl -s localhost:9200/library2/book/1?pretty | grep Darkness +} + +@test "[UPGRADE] stop old version" { + stop_elasticsearch_service +} + +@test "[UPGRADE] install version under test" { + install_package -u +} + +@test "[UPGRADE] start version under test" { + start_elasticsearch_service yellow +} + +@test "[UPGRADE] check elasticsearch version is version under test" { + local versionToCheck=$(cat version | sed -e 's/-SNAPSHOT//') + curl -s localhost:9200 | grep \"number\"\ :\ \"$versionToCheck\" || { + echo "Installed an unexpected version:" + curl -s localhost:9200 + false + } +} + +@test "[UPGRADE] verify that the documents are there after restart" { + curl -s localhost:9200/library/book/1?pretty | grep Elasticsearch + curl -s localhost:9200/library/book/2?pretty | grep World + curl -s localhost:9200/library2/book/1?pretty | grep Darkness +} + +@test "[UPGRADE] stop version under test" { + stop_elasticsearch_service +} diff --git a/qa/vagrant/src/test/resources/packaging/scripts/packaging_test_utils.bash b/qa/vagrant/src/test/resources/packaging/scripts/packaging_test_utils.bash index 9eff5894c17..dd993debcfb 100644 --- a/qa/vagrant/src/test/resources/packaging/scripts/packaging_test_utils.bash +++ b/qa/vagrant/src/test/resources/packaging/scripts/packaging_test_utils.bash @@ -234,10 +234,25 @@ verify_package_installation() { # Install the rpm or deb package install_package() { + local version=$(cat version) + local rpmCommand='-i' + while getopts ":uv:" opt; do + case $opt in + u) + rpmCommand='-U' + ;; + v) + version=$OPTARG + ;; + \?) + echo "Invalid option: -$OPTARG" >&2 + ;; + esac + done if is_rpm; then - rpm -i elasticsearch*.rpm + rpm $rpmCommand elasticsearch-$version.rpm elif is_dpkg; then - dpkg -i elasticsearch*.deb + dpkg -i elasticsearch-$version.deb else skip "Only rpm or deb supported" fi @@ -318,6 +333,8 @@ clean_before_test() { } start_elasticsearch_service() { + local desiredStatus=${1:-green} + if [ -f "/tmp/elasticsearch/bin/elasticsearch" ]; then # su and the Elasticsearch init script work together to break bats. # sudo isolates bats enough from the init script so everything continues @@ -342,7 +359,7 @@ start_elasticsearch_service() { [ "$status" -eq 0 ] fi - wait_for_elasticsearch_status + wait_for_elasticsearch_status $desiredStatus if [ -r "/tmp/elasticsearch/elasticsearch.pid" ]; then pid=$(cat /tmp/elasticsearch/elasticsearch.pid) @@ -389,10 +406,7 @@ stop_elasticsearch_service() { # Waits for Elasticsearch to reach a given status (defaults to "green") wait_for_elasticsearch_status() { - local desired_status="green" - if [ "x$1" != "x" ]; then - status="$1" - fi + local desiredStatus=${1:-green} echo "Making sure elasticsearch is up..." wget -O - --retry-connrefused --waitretry=1 --timeout=60 http://localhost:9200 || { @@ -411,7 +425,7 @@ wait_for_elasticsearch_status() { } echo "Tring to connect to elasticsearch and wait for expected status..." - curl -sS "http://localhost:9200/_cluster/health?wait_for_status=$desired_status&timeout=60s&pretty" + curl -sS "http://localhost:9200/_cluster/health?wait_for_status=$desiredStatus&timeout=60s&pretty" if [ $? -eq 0 ]; then echo "Connected" else @@ -426,8 +440,8 @@ wait_for_elasticsearch_status() { echo $output false fi - echo $output | grep $desired_status || { - echo "unexpected status: '$output' wanted '$desired_status'" + echo $output | grep $desiredStatus || { + echo "unexpected status: '$output' wanted '$desiredStatus'" false } } From 04d254e57168df4f3f59a84caa9d6e11350d4261 Mon Sep 17 00:00:00 2001 From: Nik Everett Date: Fri, 4 Sep 2015 15:34:10 -0400 Subject: [PATCH 2/2] [test] Documentation for packaging tests --- qa/vagrant/pom.xml | 3 +++ .../packaging/scripts/packaging_test_utils.bash | 9 +++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/qa/vagrant/pom.xml b/qa/vagrant/pom.xml index 647a5c8de1f..b1ed9a3959a 100644 --- a/qa/vagrant/pom.xml +++ b/qa/vagrant/pom.xml @@ -35,6 +35,9 @@ /usr/bin/rpmbuild + 2.0.0-beta1 diff --git a/qa/vagrant/src/test/resources/packaging/scripts/packaging_test_utils.bash b/qa/vagrant/src/test/resources/packaging/scripts/packaging_test_utils.bash index dd993debcfb..ff7255c5417 100644 --- a/qa/vagrant/src/test/resources/packaging/scripts/packaging_test_utils.bash +++ b/qa/vagrant/src/test/resources/packaging/scripts/packaging_test_utils.bash @@ -232,7 +232,9 @@ verify_package_installation() { fi } -# Install the rpm or deb package +# Install the rpm or deb package. +# -u upgrade rather than install. This only matters for rpm. +# -v the version to upgrade to. Defaults to the version under test. install_package() { local version=$(cat version) local rpmCommand='-i' @@ -332,6 +334,8 @@ clean_before_test() { done } +# Start elasticsearch and wait for it to come up with a status. +# $1 - expected status - defaults to green start_elasticsearch_service() { local desiredStatus=${1:-green} @@ -404,7 +408,8 @@ stop_elasticsearch_service() { fi } -# Waits for Elasticsearch to reach a given status (defaults to "green") +# Waits for Elasticsearch to reach some status. +# $1 - expected status - defaults to green wait_for_elasticsearch_status() { local desiredStatus=${1:-green}