[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
This commit is contained in:
Nik Everett 2015-09-02 15:16:53 -04:00
parent 821021f0e4
commit ab5c981ed2
5 changed files with 174 additions and 14 deletions

View File

@ -34,6 +34,8 @@
<!-- rpmbuild location : default to /usr/bin/rpmbuild --> <!-- rpmbuild location : default to /usr/bin/rpmbuild -->
<packaging.rpm.rpmbuild>/usr/bin/rpmbuild</packaging.rpm.rpmbuild> <packaging.rpm.rpmbuild>/usr/bin/rpmbuild</packaging.rpm.rpmbuild>
<upgrade.from.version>2.0.0-beta1</upgrade.from.version>
</properties> </properties>
<build> <build>
@ -92,6 +94,14 @@
<version>${elasticsearch.version}</version> <version>${elasticsearch.version}</version>
<type>deb</type> <type>deb</type>
</artifactItem> </artifactItem>
<artifactItem>
<!-- We also use an old version of elasticsearch for
testing upgrades -->
<groupId>org.elasticsearch.distribution.deb</groupId>
<artifactId>elasticsearch</artifactId>
<version>${upgrade.from.version}</version>
<type>deb</type>
</artifactItem>
<artifactItem> <artifactItem>
<groupId>org.elasticsearch.plugin</groupId> <groupId>org.elasticsearch.plugin</groupId>
<artifactId>jvm-example</artifactId> <artifactId>jvm-example</artifactId>
@ -219,6 +229,21 @@
</target> </target>
</configuration> </configuration>
</execution> </execution>
<execution>
<id>setup-version-files</id>
<phase>pre-integration-test</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<target>
<echo message="${project.version}"
file="${project.build.directory}/testroot/version"/>
<echo message="${upgrade.from.version}"
file="${project.build.directory}/testroot/upgrade_from_version"/>
</target>
</configuration>
</execution>
<execution> <execution>
<id>test-vms</id> <id>test-vms</id>
<phase>integration-test</phase> <phase>integration-test</phase>
@ -269,6 +294,14 @@
<version>${elasticsearch.version}</version> <version>${elasticsearch.version}</version>
<type>rpm</type> <type>rpm</type>
</artifactItem> </artifactItem>
<artifactItem>
<!-- We also use an old version of elasticsearch for
testing upgrades -->
<groupId>org.elasticsearch.distribution.rpm</groupId>
<artifactId>elasticsearch</artifactId>
<version>${upgrade.from.version}</version>
<type>rpm</type>
</artifactItem>
</artifactItems> </artifactItems>
</configuration> </configuration>
</execution> </execution>
@ -309,6 +342,14 @@
<version>${elasticsearch.version}</version> <version>${elasticsearch.version}</version>
<type>rpm</type> <type>rpm</type>
</artifactItem> </artifactItem>
<artifactItem>
<!-- We also use an old version of elasticsearch for
testing upgrades -->
<groupId>org.elasticsearch.distribution.rpm</groupId>
<artifactId>elasticsearch</artifactId>
<version>${upgrade.from.version}</version>
<type>rpm</type>
</artifactItem>
</artifactItems> </artifactItems>
</configuration> </configuration>
</execution> </execution>

View File

@ -46,7 +46,7 @@ setup() {
} }
@test "[DEB] package is available" { @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 ] [ "$count" -eq 1 ]
} }
@ -56,7 +56,7 @@ setup() {
} }
@test "[DEB] install package" { @test "[DEB] install package" {
dpkg -i elasticsearch*.deb dpkg -i elasticsearch-$(cat version).deb
} }
@test "[DEB] package is installed" { @test "[DEB] package is installed" {

View File

@ -45,7 +45,7 @@ setup() {
} }
@test "[RPM] package is available" { @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 ] [ "$count" -eq 1 ]
} }
@ -55,7 +55,7 @@ setup() {
} }
@test "[RPM] install package" { @test "[RPM] install package" {
rpm -i elasticsearch*.rpm rpm -i elasticsearch-$(cat version).rpm
} }
@test "[RPM] package is installed" { @test "[RPM] package is installed" {

View File

@ -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
}

View File

@ -234,10 +234,25 @@ verify_package_installation() {
# Install the rpm or deb package # Install the rpm or deb package
install_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 if is_rpm; then
rpm -i elasticsearch*.rpm rpm $rpmCommand elasticsearch-$version.rpm
elif is_dpkg; then elif is_dpkg; then
dpkg -i elasticsearch*.deb dpkg -i elasticsearch-$version.deb
else else
skip "Only rpm or deb supported" skip "Only rpm or deb supported"
fi fi
@ -318,6 +333,8 @@ clean_before_test() {
} }
start_elasticsearch_service() { start_elasticsearch_service() {
local desiredStatus=${1:-green}
if [ -f "/tmp/elasticsearch/bin/elasticsearch" ]; then if [ -f "/tmp/elasticsearch/bin/elasticsearch" ]; then
# su and the Elasticsearch init script work together to break bats. # su and the Elasticsearch init script work together to break bats.
# sudo isolates bats enough from the init script so everything continues # sudo isolates bats enough from the init script so everything continues
@ -342,7 +359,7 @@ start_elasticsearch_service() {
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
fi fi
wait_for_elasticsearch_status wait_for_elasticsearch_status $desiredStatus
if [ -r "/tmp/elasticsearch/elasticsearch.pid" ]; then if [ -r "/tmp/elasticsearch/elasticsearch.pid" ]; then
pid=$(cat /tmp/elasticsearch/elasticsearch.pid) pid=$(cat /tmp/elasticsearch/elasticsearch.pid)
@ -389,10 +406,7 @@ stop_elasticsearch_service() {
# Waits for Elasticsearch to reach a given status (defaults to "green") # Waits for Elasticsearch to reach a given status (defaults to "green")
wait_for_elasticsearch_status() { wait_for_elasticsearch_status() {
local desired_status="green" local desiredStatus=${1:-green}
if [ "x$1" != "x" ]; then
status="$1"
fi
echo "Making sure elasticsearch is up..." echo "Making sure elasticsearch is up..."
wget -O - --retry-connrefused --waitretry=1 --timeout=60 http://localhost:9200 || { 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..." 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 if [ $? -eq 0 ]; then
echo "Connected" echo "Connected"
else else
@ -426,8 +440,8 @@ wait_for_elasticsearch_status() {
echo $output echo $output
false false
fi fi
echo $output | grep $desired_status || { echo $output | grep $desiredStatus || {
echo "unexpected status: '$output' wanted '$desired_status'" echo "unexpected status: '$output' wanted '$desiredStatus'"
false false
} }
} }