From bfc5f47fe2b11592c26fecbf09624fca11123a02 Mon Sep 17 00:00:00 2001 From: Nik Everett Date: Tue, 15 Sep 2015 17:55:12 -0400 Subject: [PATCH 1/5] [test] Fix centos-6 tests Right now we execute some debian-isms in the init.d tests. This switches to trying both the debian and centos ways to stop services from starting automatically. --- .../src/test/resources/packaging/scripts/70_sysv_initd.bats | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/qa/vagrant/src/test/resources/packaging/scripts/70_sysv_initd.bats b/qa/vagrant/src/test/resources/packaging/scripts/70_sysv_initd.bats index 4f134ba68f7..667039a39a1 100644 --- a/qa/vagrant/src/test/resources/packaging/scripts/70_sysv_initd.bats +++ b/qa/vagrant/src/test/resources/packaging/scripts/70_sysv_initd.bats @@ -40,12 +40,13 @@ setup() { @test "[INIT.D] remove any leftover configuration to start elasticsearch on restart" { # This configuration can be added with a command like: # $ sudo update-rc.d elasticsearch defaults 95 10 - # but we want to test that the RPM _doesn't_ add it on its own. + # but we want to test that the RPM and deb _don't_ add it on its own. # Note that it'd be incorrect to use: # $ sudo update-rc.d elasticsearch disable # here because that'd prevent elasticsearch from installing the symlinks # that cause it to be started on restart. - sudo update-rc.d -f elasticsearch remove + sudo update-rc.d -f elasticsearch remove || true + sudo chkconfig elasticsearch off || true } @test "[INIT.D] install elasticsearch" { From 516ba6c8f67afc3719520e7a09fb83a48a242d2b Mon Sep 17 00:00:00 2001 From: Shaunak Kashyap Date: Tue, 15 Sep 2015 13:37:29 -0700 Subject: [PATCH 2/5] Using gcloud CLI as gcutil CLI has been deprecated --- docs/plugins/cloud-gce.asciidoc | 107 ++++++++++++-------------------- 1 file changed, 41 insertions(+), 66 deletions(-) diff --git a/docs/plugins/cloud-gce.asciidoc b/docs/plugins/cloud-gce.asciidoc index 3a7959f496f..2461888aabe 100644 --- a/docs/plugins/cloud-gce.asciidoc +++ b/docs/plugins/cloud-gce.asciidoc @@ -74,38 +74,36 @@ If you did not set it yet, you can define your default project you will work on: gcloud config set project es-cloud -------------------------------------------------- +[[cloud-gce-usage-discovery-long-login]] + +If you haven't already, login to Google Cloud + +[source,sh] +-------------------------------------------------- +gcloud auth login +-------------------------------------------------- + +This will open your browser. You will be asked to sign-in to a Google account and +authorize access to the Google Cloud SDK. + [[cloud-gce-usage-discovery-long-first-instance]] ===== Creating your first instance [source,sh] -------------------------------------------------- -gcutil addinstance myesnode1 \ - --service_account_scope=compute-rw,storage-full \ - --persistent_boot_disk +gcloud compute instances create myesnode1 \ + --zone \ + --scopes compute-rw -------------------------------------------------- -Then follow these steps: - -* You will be asked to open a link in your browser. Login and allow access to listed services. -* You will get back a verification code. Copy and paste it in your terminal. -* You should see an `Authentication successful.` message. -* Choose your zone, e.g. `europe-west1-a`. -* Choose your compute instance size, e.g. `f1-micro`. -* Choose your OS, e.g. `projects/debian-cloud/global/images/debian-7-wheezy-v20140606`. -* You may be asked to create a ssh key. Follow the instructions to create one. - When done, a report like this one should appears: [source,text] -------------------------------------------------- -Table of resources: - -+-----------+--------------+-------+---------+--------------+----------------+----------------+----------------+---------+----------------+ -| name | machine-type | image | network | network-ip | external-ip | disks | zone | status | status-message | -+-----------+--------------+-------+---------+--------------+----------------+----------------+----------------+---------+----------------+ -| myesnode1 | f1-micro | | default | 10.240.20.57 | 192.158.29.199 | boot-myesnode1 | europe-west1-a | RUNNING | | -+-----------+--------------+-------+---------+--------------+----------------+----------------+----------------+---------+----------------+ +Created [https://www.googleapis.com/compute/v1/projects/es-cloud-1070/zones/us-central1-f/instances/myesnode1]. +NAME ZONE MACHINE_TYPE PREEMPTIBLE INTERNAL_IP EXTERNAL_IP STATUS +myesnode1 us-central1-f n1-standard-1 10.240.133.54 104.197.94.25 RUNNING -------------------------------------------------- You can now connect to your instance: @@ -127,7 +125,7 @@ It's important when creating an instance that the correct permissions are set. A [source,text] -------------------------------------------------- -service_account_scope=compute-rw +scopes=compute-rw -------------------------------------------------- Failing to set this will result in unauthorized messages when starting Elasticsearch. @@ -238,7 +236,7 @@ gsutil mb gs://esimage gsutil cp /tmp/e4686d7f5bf904a924ae0cfeb58d0827c6d5b966.image.tar.gz gs://esimage # Then add your image to images collection: -gcutil addimage elasticsearch-1-2-1 gs://esimage/e4686d7f5bf904a924ae0cfeb58d0827c6d5b966.image.tar.gz +gcloud compute images create elasticsearch-2-0-0 --source-uri gs://esimage/e4686d7f5bf904a924ae0cfeb58d0827c6d5b966.image.tar.gz # If the previous command did not work for you, logout from your instance # and launch the same command from your local machine. @@ -252,13 +250,11 @@ As you have now an image, you can create as many instances as you need: [source,sh] -------------------------------------------------- # Just change node name (here myesnode2) -gcutil addinstance --image=elasticsearch-1-2-1 myesnode2 +gcloud compute instances create myesnode2 --image elasticsearch-2-0-0 --zone europe-west1-a # If you want to provide all details directly, you can use: -gcutil addinstance --image=elasticsearch-1-2-1 \ - --kernel=projects/google/global/kernels/gce-v20130603 myesnode2 \ - --zone europe-west1-a --machine_type f1-micro --service_account_scope=compute-rw \ - --persistent_boot_disk +gcloud compute instances create myesnode2 --image=elasticsearch-2-0-0 \ + --zone europe-west1-a --machine-type f1-micro --scopes=compute-rw -------------------------------------------------- [[cloud-gce-usage-discovery-remove-instance]] @@ -269,11 +265,11 @@ You can use https://cloud.google.com/console[Google Cloud Console] or CLI to man [source,sh] -------------------------------------------------- # Stopping and removing instances -gcutil deleteinstance myesnode1 myesnode2 \ +gcloud compute instances delete myesnode1 myesnode2 \ --zone=europe-west1-a # Consider removing disk as well if you don't need them anymore -gcutil deletedisk boot-myesnode1 boot-myesnode2 \ +gcloud compute disks deleted boot-myesnode1 boot-myesnode2 \ --zone=europe-west1-a -------------------------------------------------- @@ -315,9 +311,8 @@ Add your tag when building the new instance: [source,sh] -------------------------------------------------- -gcutil --project=es-cloud addinstance myesnode1 \ - --service_account_scope=compute-rw \ - --persistent_boot_disk \ +gcloud compute instances create myesnode1 --project=es-cloud \ + --scopes=compute-rw \ --tags=elasticsearch,dev -------------------------------------------------- @@ -344,21 +339,19 @@ But you can specify the port value elasticsearch is meant to use using google co [[cloud-gce-usage-discovery-port-create]] ===== When creating instance -Add `--metadata=es_port:9301` option: +Add `--metadata es_port=9301` option: [source,sh] -------------------------------------------------- # when creating first instance -gcutil addinstance myesnode1 \ - --service_account_scope=compute-rw,storage-full \ - --persistent_boot_disk \ - --metadata=es_port:9301 +gcloud compute instances create myesnode1 \ + --scopes=compute-rw,storage-full \ + --metadata es_port=9301 # when creating an instance from an image -gcutil addinstance --image=elasticsearch-1-0-0-RC1 \ - --kernel=projects/google/global/kernels/gce-v20130603 myesnode2 \ - --zone europe-west1-a --machine_type f1-micro --service_account_scope=compute-rw \ - --persistent_boot_disk --metadata=es_port:9301 +gcloud compute instances create myesnode2 --image=elasticsearch-1-0-0-RC1 \ + --zone europe-west1-a --machine-type f1-micro --scopes=compute-rw \ + --metadata es_port=9301 -------------------------------------------------- [[cloud-gce-usage-discovery-port-run]] @@ -366,20 +359,9 @@ gcutil addinstance --image=elasticsearch-1-0-0-RC1 \ [source,sh] -------------------------------------------------- -# Get metadata fingerprint -gcutil getinstance myesnode1 --zone=europe-west1-a -+------------------------+---------------------+ -| property | value | -+------------------------+---------------------+ -| metadata | | -| fingerprint | 42WmSpB8rSM= | -+------------------------+---------------------+ - -# Use that fingerprint -gcutil setinstancemetadata myesnode1 \ - --zone=europe-west1-a \ - --metadata=es_port:9301 \ - --fingerprint=42WmSpB8rSM= +gcloud compute instances add-metadata myesnode1 \ + --zone europe-west1-a \ + --metadata es_port=9301 -------------------------------------------------- @@ -389,18 +371,11 @@ gcutil setinstancemetadata myesnode1 \ [[cloud-gce-usage-discovery-tips-projectid]] ===== Store project id locally -If you don't want to repeat the project id each time, you can save it in `~/.gcutil.flags` file using: +If you don't want to repeat the project id each time, you can save it in the local gcloud config [source,sh] -------------------------------------------------- -gcutil getproject --project=es-cloud --cache_flag_values --------------------------------------------------- - -`~/.gcutil.flags` file now contains: - -[source,text] --------------------------------------------------- ---project=es-cloud +gcloud config set project es-cloud -------------------------------------------------- [[cloud-gce-usage-discovery-tips-permissions]] @@ -409,14 +384,14 @@ gcutil getproject --project=es-cloud --cache_flag_values If you have created a machine without the correct permissions, you will see `403 unauthorized` error messages. The only way to alter these permissions is to delete the instance (NOT THE DISK). Then create another with the correct permissions. -Creating machines with gcutil:: +Creating machines with gcloud:: + -- Ensure the following flags are set: [source,text] -------------------------------------------------- ---service_account_scope=compute-rw +--scopes=compute-rw -------------------------------------------------- -- From 058d3859421f59942cc406fd565147ac20a70e11 Mon Sep 17 00:00:00 2001 From: Nik Everett Date: Tue, 15 Sep 2015 17:20:53 -0400 Subject: [PATCH 3/5] [test] Add opensuse-13 to packaging tests This gets opensuse-13 working with vagrant and the packaging tests. They pass with some minor tweaks. Closes #13507 --- Vagrantfile | 16 +++++++++++++++- qa/vagrant/pom.xml | 2 +- .../resources/packaging/scripts/60_systemd.bats | 16 ++++++++++------ .../packaging/scripts/packaging_test_utils.bash | 2 +- 4 files changed, 27 insertions(+), 9 deletions(-) diff --git a/Vagrantfile b/Vagrantfile index 29822177b7f..4c86d027a0e 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -68,11 +68,16 @@ Vagrant.configure(2) do |config| config.vm.box = "boxcutter/fedora22" dnf_common config end + config.vm.define "opensuse-13" do |config| + config.vm.box = "chef/opensuse-13" + config.vm.box_url = "http://opscode-vm-bento.s3.amazonaws.com/vagrant/virtualbox/opscode_opensuse-13.2-x86_64_chef-provisionerless.box" + suse_common config + end # Switch the default share for the project root from /vagrant to # /elasticsearch because /vagrant is confusing when there is a project inside # the elasticsearch project called vagrant.... config.vm.synced_folder ".", "/vagrant", disabled: true - config.vm.synced_folder "", "/elasticsearch" + config.vm.synced_folder ".", "/elasticsearch" if Vagrant.has_plugin?("vagrant-cachier") config.cache.scope = :box end @@ -150,6 +155,14 @@ def dnf_common(config) end end +def suse_common(config) + provision(config, + update_command: "zypper --non-interactive list-updates", + update_tracking_file: "/var/cache/zypp/packages/last_update", + install_command: "zypper --non-interactive --quiet install --no-recommends", + java_package: "java-1_8_0-openjdk-devel") +end + # Register the main box provisioning script. # @param config Vagrant's config object. Required. # @param update_command [String] The command used to update the package @@ -194,6 +207,7 @@ def provision(config, #{extra} installed java || install #{java_package} + ensure tar ensure curl ensure unzip diff --git a/qa/vagrant/pom.xml b/qa/vagrant/pom.xml index af0ae73353a..1c368726c42 100644 --- a/qa/vagrant/pom.xml +++ b/qa/vagrant/pom.xml @@ -21,7 +21,7 @@ sudo bats $BATS/${testScripts} precise, trusty, vivid, jessie - centos-6, centos-7, fedora-22, oel-7 + centos-6, centos-7, oel-7, fedora-22, opensuse-13 trusty centos-7 diff --git a/qa/vagrant/src/test/resources/packaging/scripts/60_systemd.bats b/qa/vagrant/src/test/resources/packaging/scripts/60_systemd.bats index 77e8d807362..25685a86dd1 100644 --- a/qa/vagrant/src/test/resources/packaging/scripts/60_systemd.bats +++ b/qa/vagrant/src/test/resources/packaging/scripts/60_systemd.bats @@ -99,23 +99,27 @@ setup() { @test "[SYSTEMD] stop (running)" { systemctl stop elasticsearch.service +} +@test "[SYSTEMD] status (stopping)" { run systemctl status elasticsearch.service - [ "$status" -eq 3 ] || "Expected exit code 3 meaning stopped" + # I'm not sure why suse exits 0 here, but it does + if [ ! -e /etc/SuSE-release ]; then + [ "$status" -eq 3 ] || "Expected exit code 3 meaning stopped but got $status" + fi echo "$output" | grep "Active:" | grep "inactive" } @test "[SYSTEMD] stop (stopped)" { systemctl stop elasticsearch.service - - run systemctl status elasticsearch.service - [ "$status" -eq 3 ] || "Expected exit code 3 meaning stopped" - echo "$output" | grep "Active:" | grep "inactive" } @test "[SYSTEMD] status (stopped)" { run systemctl status elasticsearch.service - [ "$status" -eq 3 ] || "Expected exit code 3 meaning stopped" + # I'm not sure why suse exits 0 here, but it does + if [ ! -e /etc/SuSE-release ]; then + [ "$status" -eq 3 ] || "Expected exit code 3 meaning stopped but got $status" + fi echo "$output" | grep "Active:" | grep "inactive" } 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 ff7255c5417..78ab3519d0b 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 @@ -414,7 +414,7 @@ wait_for_elasticsearch_status() { local desiredStatus=${1:-green} 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 --tries 60 http://localhost:9200 || { echo "Looks like elasticsearch never started. Here is its log:" if [ -r "/tmp/elasticsearch/elasticsearch.pid" ]; then cat /tmp/elasticsearch/log/elasticsearch.log From 8d02efd0881f1cf51fb89fc5764f5e54a7e1e2b4 Mon Sep 17 00:00:00 2001 From: Nik Everett Date: Tue, 1 Sep 2015 22:12:18 -0400 Subject: [PATCH 4/5] [test] Packaging test for filesystem scripts Adds a tests for loading scripts from the filesystem for search templates and for search filters. Closes #13184 --- .../packaging/scripts/20_tar_package.bats | 7 + .../packaging/scripts/30_deb_package.bats | 9 +- .../packaging/scripts/40_rpm_package.bats | 9 +- .../packaging/scripts/60_systemd.bats | 8 +- .../packaging/scripts/70_sysv_initd.bats | 8 +- .../packaging/scripts/80_upgrade.bats | 3 +- .../scripts/example/scripts/is_guide.groovy | 1 + .../scripts/example/scripts/is_guide.mustache | 7 + .../packaging/scripts/os_package.bash | 109 ++++++++++++++ .../scripts/packaging_test_utils.bash | 136 +++++------------- .../packaging/scripts/plugin_test_cases.bash | 6 +- .../test/resources/packaging/scripts/tar.bash | 21 +++ 12 files changed, 209 insertions(+), 115 deletions(-) create mode 100644 qa/vagrant/src/test/resources/packaging/scripts/example/scripts/is_guide.groovy create mode 100644 qa/vagrant/src/test/resources/packaging/scripts/example/scripts/is_guide.mustache create mode 100644 qa/vagrant/src/test/resources/packaging/scripts/os_package.bash diff --git a/qa/vagrant/src/test/resources/packaging/scripts/20_tar_package.bats b/qa/vagrant/src/test/resources/packaging/scripts/20_tar_package.bats index a4332ce4eb1..3b5acc75d57 100644 --- a/qa/vagrant/src/test/resources/packaging/scripts/20_tar_package.bats +++ b/qa/vagrant/src/test/resources/packaging/scripts/20_tar_package.bats @@ -34,6 +34,8 @@ load tar setup() { skip_not_tar_gz + export ESHOME=/tmp/elasticsearch + export_elasticsearch_paths } ################################## @@ -74,6 +76,11 @@ setup() { # Check that Elasticsearch is working ################################## @test "[TAR] test elasticsearch" { + # Install scripts used to test script filters and search templates before + # starting Elasticsearch so we don't have to wait for elasticsearch to scan for + # them. + install_elasticsearch_test_scripts + start_elasticsearch_service run_elasticsearch_tests 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 2579e6a7359..d0a692194f8 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 @@ -31,10 +31,12 @@ # Load test utilities load packaging_test_utils +load os_package # Cleans everything for the 1st execution setup() { skip_not_dpkg + export_elasticsearch_paths } ################################## @@ -79,8 +81,11 @@ setup() { } @test "[DEB] test elasticsearch" { + # Install scripts used to test script filters and search templates before + # starting Elasticsearch so we don't have to wait for elasticsearch to scan for + # them. + install_elasticsearch_test_scripts start_elasticsearch_service - run_elasticsearch_tests } @@ -133,6 +138,8 @@ setup() { } @test "[DEB] purge package" { + # User installed scripts aren't removed so we'll just get them ourselves + rm -rf $ESSCRIPTS dpkg --purge 'elasticsearch' } 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 09bb5b0b39a..91b6d8c0156 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 @@ -30,10 +30,12 @@ # Load test utilities load packaging_test_utils +load os_package # Cleans everything for the 1st execution setup() { skip_not_rpm + export_elasticsearch_paths } ################################## @@ -74,12 +76,17 @@ setup() { } @test "[RPM] test elasticsearch" { + # Install scripts used to test script filters and search templates before + # starting Elasticsearch so we don't have to wait for elasticsearch to scan for + # them. + install_elasticsearch_test_scripts start_elasticsearch_service - run_elasticsearch_tests } @test "[RPM] remove package" { + # User installed scripts aren't removed so we'll just get them ourselves + rm -rf $ESSCRIPTS rpm -e 'elasticsearch' } diff --git a/qa/vagrant/src/test/resources/packaging/scripts/60_systemd.bats b/qa/vagrant/src/test/resources/packaging/scripts/60_systemd.bats index 25685a86dd1..76487fc1b3c 100644 --- a/qa/vagrant/src/test/resources/packaging/scripts/60_systemd.bats +++ b/qa/vagrant/src/test/resources/packaging/scripts/60_systemd.bats @@ -30,11 +30,13 @@ # Load test utilities load packaging_test_utils +load os_package # Cleans everything for the 1st execution setup() { skip_not_systemd skip_not_dpkg_or_rpm + export_elasticsearch_paths } @test "[SYSTEMD] install elasticsearch" { @@ -61,10 +63,12 @@ setup() { } @test "[SYSTEMD] start" { + # Install scripts used to test script filters and search templates before + # starting Elasticsearch so we don't have to wait for elasticsearch to scan for + # them. + install_elasticsearch_test_scripts systemctl start elasticsearch.service - wait_for_elasticsearch_status - assert_file_exist "/var/run/elasticsearch/elasticsearch.pid" } diff --git a/qa/vagrant/src/test/resources/packaging/scripts/70_sysv_initd.bats b/qa/vagrant/src/test/resources/packaging/scripts/70_sysv_initd.bats index 667039a39a1..bb6e44c4e0c 100644 --- a/qa/vagrant/src/test/resources/packaging/scripts/70_sysv_initd.bats +++ b/qa/vagrant/src/test/resources/packaging/scripts/70_sysv_initd.bats @@ -30,11 +30,13 @@ # Load test utilities load packaging_test_utils +load os_package # Cleans everything for the 1st execution setup() { skip_not_sysvinit skip_not_dpkg_or_rpm + export_elasticsearch_paths } @test "[INIT.D] remove any leftover configuration to start elasticsearch on restart" { @@ -64,10 +66,12 @@ setup() { } @test "[INIT.D] start" { + # Install scripts used to test script filters and search templates before + # starting Elasticsearch so we don't have to wait for elasticsearch to scan for + # them. + install_elasticsearch_test_scripts service elasticsearch start - wait_for_elasticsearch_status - assert_file_exist "/var/run/elasticsearch/elasticsearch.pid" } diff --git a/qa/vagrant/src/test/resources/packaging/scripts/80_upgrade.bats b/qa/vagrant/src/test/resources/packaging/scripts/80_upgrade.bats index fceea65d29a..65d212e56d8 100644 --- a/qa/vagrant/src/test/resources/packaging/scripts/80_upgrade.bats +++ b/qa/vagrant/src/test/resources/packaging/scripts/80_upgrade.bats @@ -32,6 +32,7 @@ # Load test utilities load packaging_test_utils +load os_package # Cleans everything for the 1st execution setup() { @@ -50,7 +51,7 @@ setup() { @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 + curl -s localhost:9200 false } } diff --git a/qa/vagrant/src/test/resources/packaging/scripts/example/scripts/is_guide.groovy b/qa/vagrant/src/test/resources/packaging/scripts/example/scripts/is_guide.groovy new file mode 100644 index 00000000000..d19029afd40 --- /dev/null +++ b/qa/vagrant/src/test/resources/packaging/scripts/example/scripts/is_guide.groovy @@ -0,0 +1 @@ +_source['title'] == 'Elasticsearch - The Definitive Guide' diff --git a/qa/vagrant/src/test/resources/packaging/scripts/example/scripts/is_guide.mustache b/qa/vagrant/src/test/resources/packaging/scripts/example/scripts/is_guide.mustache new file mode 100644 index 00000000000..faf5b4fdbe2 --- /dev/null +++ b/qa/vagrant/src/test/resources/packaging/scripts/example/scripts/is_guide.mustache @@ -0,0 +1,7 @@ +{ + "query": { + "script": { + "script_file": "is_guide" + } + } +} diff --git a/qa/vagrant/src/test/resources/packaging/scripts/os_package.bash b/qa/vagrant/src/test/resources/packaging/scripts/os_package.bash new file mode 100644 index 00000000000..4907cdf7ac3 --- /dev/null +++ b/qa/vagrant/src/test/resources/packaging/scripts/os_package.bash @@ -0,0 +1,109 @@ +#!/bin/sh + +# This file contains some utilities to test the elasticsearch scripts with +# the .deb/.rpm packages. + +# 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. + +# 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. + + +# Export some useful paths. +export_elasticsearch_paths() { + export ESHOME="/usr/share/elasticsearch" + export ESPLUGINS="$ESHOME/plugins" + export ESCONFIG="/etc/elasticsearch" + export ESSCRIPTS="$ESCONFIG/scripts" + export ESDATA="/var/lib/elasticsearch" + export ESLOG="/var/log/elasticsearch" + export ESPIDDIR="/var/run/elasticsearch" +} + +# 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' + 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 $rpmCommand elasticsearch-$version.rpm + elif is_dpkg; then + dpkg -i elasticsearch-$version.deb + else + skip "Only rpm or deb supported" + fi +} + +# Checks that all directories & files are correctly installed after a deb or +# rpm install. +verify_package_installation() { + id elasticsearch + + getent group elasticsearch + + assert_file "$ESHOME" d root 755 + assert_file "$ESHOME/bin" d root 755 + assert_file "$ESHOME/lib" d root 755 + assert_file "$ESCONFIG" d root 755 + assert_file "$ESCONFIG/elasticsearch.yml" f root 644 + assert_file "$ESCONFIG/logging.yml" f root 644 + assert_file "$ESDATA" d elasticsearch 755 + assert_file "$ESLOG" d elasticsearch 755 + assert_file "$ESPLUGINS" d elasticsearch 755 + assert_file "$ESPIDDIR" d elasticsearch 755 + assert_file "$ESHOME/NOTICE.txt" f root 644 + assert_file "$ESHOME/README.textile" f root 644 + + if is_dpkg; then + # Env file + assert_file "/etc/default/elasticsearch" f root 644 + + # Doc files + assert_file "/usr/share/doc/elasticsearch" d root 755 + assert_file "/usr/share/doc/elasticsearch/copyright" f root 644 + fi + + if is_rpm; then + # Env file + assert_file "/etc/sysconfig/elasticsearch" f root 644 + # License file + assert_file "/usr/share/elasticsearch/LICENSE.txt" f root 644 + fi + + if is_systemd; then + assert_file "/usr/lib/systemd/system/elasticsearch.service" f root 644 + assert_file "/usr/lib/tmpfiles.d/elasticsearch.conf" f root 644 + assert_file "/usr/lib/sysctl.d/elasticsearch.conf" f root 644 + fi +} 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 78ab3519d0b..82775ae62d8 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 @@ -177,106 +177,6 @@ assert_output() { echo "$output" | grep -E "$1" } -# Checks that all directories & files are correctly installed -# after a package (deb/rpm) install -verify_package_installation() { - - run id elasticsearch - [ "$status" -eq 0 ] - - run getent group elasticsearch - [ "$status" -eq 0 ] - - # Home dir - assert_file "/usr/share/elasticsearch" d root 755 - # Bin dir - assert_file "/usr/share/elasticsearch/bin" d root 755 - assert_file "/usr/share/elasticsearch/lib" d root 755 - # Conf dir - assert_file "/etc/elasticsearch" d root 755 - assert_file "/etc/elasticsearch/elasticsearch.yml" f root 644 - assert_file "/etc/elasticsearch/logging.yml" f root 644 - # Data dir - assert_file "/var/lib/elasticsearch" d elasticsearch 755 - # Log dir - assert_file "/var/log/elasticsearch" d elasticsearch 755 - # Plugins dir - assert_file "/usr/share/elasticsearch/plugins" d elasticsearch 755 - # PID dir - assert_file "/var/run/elasticsearch" d elasticsearch 755 - # Readme files - assert_file "/usr/share/elasticsearch/NOTICE.txt" f root 644 - assert_file "/usr/share/elasticsearch/README.textile" f root 644 - - if is_dpkg; then - # Env file - assert_file "/etc/default/elasticsearch" f root 644 - - # Doc files - assert_file "/usr/share/doc/elasticsearch" d root 755 - assert_file "/usr/share/doc/elasticsearch/copyright" f root 644 - - fi - - if is_rpm; then - # Env file - assert_file "/etc/sysconfig/elasticsearch" f root 644 - # License file - assert_file "/usr/share/elasticsearch/LICENSE.txt" f root 644 - fi - - if is_systemd; then - assert_file "/usr/lib/systemd/system/elasticsearch.service" f root 644 - assert_file "/usr/lib/tmpfiles.d/elasticsearch.conf" f root 644 - assert_file "/usr/lib/sysctl.d/elasticsearch.conf" f root 644 - fi -} - -# 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' - 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 $rpmCommand elasticsearch-$version.rpm - elif is_dpkg; then - dpkg -i elasticsearch-$version.deb - else - skip "Only rpm or deb supported" - fi -} - -# Checks that all directories & files are correctly installed -# after a archive (tar.gz/zip) install -verify_archive_installation() { - assert_file "$ESHOME" d - assert_file "$ESHOME/bin" d - assert_file "$ESHOME/bin/elasticsearch" f - assert_file "$ESHOME/bin/elasticsearch.in.sh" f - assert_file "$ESHOME/bin/plugin" f - assert_file "$ESCONFIG" d - assert_file "$ESCONFIG/elasticsearch.yml" f - assert_file "$ESCONFIG/logging.yml" f - assert_file "$ESHOME/lib" d - assert_file "$ESHOME/NOTICE.txt" f - assert_file "$ESHOME/LICENSE.txt" f - assert_file "$ESHOME/README.textile" f -} - # Deletes everything before running a test file clean_before_test() { @@ -417,7 +317,7 @@ wait_for_elasticsearch_status() { wget -O - --retry-connrefused --waitretry=1 --timeout=60 --tries 60 http://localhost:9200 || { echo "Looks like elasticsearch never started. Here is its log:" if [ -r "/tmp/elasticsearch/elasticsearch.pid" ]; then - cat /tmp/elasticsearch/log/elasticsearch.log + cat /tmp/elasticsearch/logs/elasticsearch.log else if [ -e '/var/log/elasticsearch/elasticsearch.log' ]; then cat /var/log/elasticsearch/elasticsearch.log @@ -451,7 +351,12 @@ wait_for_elasticsearch_status() { } } -# Executes some very basic Elasticsearch tests +install_elasticsearch_test_scripts() { + install_script is_guide.groovy + install_script is_guide.mustache +} + +# Executes some basic Elasticsearch tests run_elasticsearch_tests() { # TODO this assertion is the same the one made when waiting for # elasticsearch to start @@ -463,8 +368,22 @@ run_elasticsearch_tests() { "title": "Elasticsearch - The Definitive Guide" }' - curl -s -XGET 'http://localhost:9200/_cat/count?h=count&v=false&pretty' | - grep -w "1" + curl -s -XGET 'http://localhost:9200/_count?pretty' | + grep \"count\"\ :\ 1 + + curl -s -XPOST 'http://localhost:9200/library/book/_count?pretty' -d '{ + "query": { + "script": { + "script_file": "is_guide" + } + } + }' | grep \"count\"\ :\ 1 + + curl -s -XGET 'http://localhost:9200/library/book/_search/template?pretty' -d '{ + "template": { + "file": "is_guide" + } + }' | grep \"total\"\ :\ 1 curl -s -XDELETE 'http://localhost:9200/_all' } @@ -480,3 +399,12 @@ move_config() { chown -R elasticsearch:elasticsearch "$ESCONFIG" assert_file_exist "$ESCONFIG/elasticsearch.yml" } + +# Copies a script into the Elasticsearch install. +install_script() { + local name=$1 + mkdir -p $ESSCRIPTS + local script="$BATS_TEST_DIRNAME/example/scripts/$name" + echo "Installing $script to $ESSCRIPTS" + cp $script $ESSCRIPTS +} diff --git a/qa/vagrant/src/test/resources/packaging/scripts/plugin_test_cases.bash b/qa/vagrant/src/test/resources/packaging/scripts/plugin_test_cases.bash index 24900aa01ee..08491d14d07 100644 --- a/qa/vagrant/src/test/resources/packaging/scripts/plugin_test_cases.bash +++ b/qa/vagrant/src/test/resources/packaging/scripts/plugin_test_cases.bash @@ -53,7 +53,6 @@ setup() { if [ $BATS_TEST_NUMBER == 1 ] || [[ $BATS_TEST_NAME =~ install_jvm.*example ]] || [ ! -d "$ESHOME" ]; then - echo "cleaning" >> /tmp/ss clean_before_test install fi @@ -69,14 +68,13 @@ if [[ "$BATS_TEST_FILENAME" =~ 25_tar_plugins.bats$ ]]; then export ESHOME=/tmp/elasticsearch export_elasticsearch_paths else + load os_package if is_rpm; then GROUP='RPM PLUGINS' elif is_dpkg; then GROUP='DEB PLUGINS' fi - export ESHOME="/usr/share/elasticsearch" - export ESPLUGINS="$ESHOME/plugins" - export ESCONFIG="/etc/elasticsearch" + export_elasticsearch_paths install() { install_package verify_package_installation diff --git a/qa/vagrant/src/test/resources/packaging/scripts/tar.bash b/qa/vagrant/src/test/resources/packaging/scripts/tar.bash index 7725edf4b94..0940a265206 100644 --- a/qa/vagrant/src/test/resources/packaging/scripts/tar.bash +++ b/qa/vagrant/src/test/resources/packaging/scripts/tar.bash @@ -70,4 +70,25 @@ move_elasticsearch() { export_elasticsearch_paths() { export ESPLUGINS="$ESHOME/plugins" export ESCONFIG="$ESHOME/config" + export ESSCRIPTS="$ESCONFIG/scripts" + export ESDATA="$ESHOME/data" + export ESLOG="$ESHOME/logs" + +} + +# Checks that all directories & files are correctly installed +# after a archive (tar.gz/zip) install +verify_archive_installation() { + assert_file "$ESHOME" d + assert_file "$ESHOME/bin" d + assert_file "$ESHOME/bin/elasticsearch" f + assert_file "$ESHOME/bin/elasticsearch.in.sh" f + assert_file "$ESHOME/bin/plugin" f + assert_file "$ESCONFIG" d + assert_file "$ESCONFIG/elasticsearch.yml" f + assert_file "$ESCONFIG/logging.yml" f + assert_file "$ESHOME/lib" d + assert_file "$ESHOME/NOTICE.txt" f + assert_file "$ESHOME/LICENSE.txt" f + assert_file "$ESHOME/README.textile" f } From 37ba02ab214f18dba90b653eed71bcc31a39519a Mon Sep 17 00:00:00 2001 From: Lee Hinman Date: Wed, 16 Sep 2015 10:10:42 -0600 Subject: [PATCH 5/5] [TEST] Fix incorrect location for greaterThanOrEqual fix --- .../java/org/elasticsearch/cluster/ClusterInfoServiceIT.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/src/test/java/org/elasticsearch/cluster/ClusterInfoServiceIT.java b/core/src/test/java/org/elasticsearch/cluster/ClusterInfoServiceIT.java index d985ada147c..03721281116 100644 --- a/core/src/test/java/org/elasticsearch/cluster/ClusterInfoServiceIT.java +++ b/core/src/test/java/org/elasticsearch/cluster/ClusterInfoServiceIT.java @@ -161,11 +161,11 @@ public class ClusterInfoServiceIT extends ESIntegTestCase { } for (DiskUsage usage : mostUsages.values()) { logger.info("--> usage: {}", usage); - assertThat("usage has be retrieved", usage.getFreeBytes(), greaterThanOrEqualTo(0L)); + assertThat("usage has be retrieved", usage.getFreeBytes(), greaterThan(0L)); } for (Long size : shardSizes.values()) { logger.info("--> shard size: {}", size); - assertThat("shard size is greater than 0", size, greaterThan(0L)); + assertThat("shard size is greater than 0", size, greaterThanOrEqualTo(0L)); } ClusterService clusterService = internalTestCluster.getInstance(ClusterService.class, internalTestCluster.getMasterName()); ClusterState state = clusterService.state();