From 54e78b61b9d04e877a4931e1d14df44dff367679 Mon Sep 17 00:00:00 2001 From: Nik Everett Date: Wed, 2 Sep 2015 12:44:17 -0400 Subject: [PATCH 1/2] [test] Test that packages don't start service We don't want either the deb or rpm package to start elasticsearch as soon as they install nor do we want the package to register elasticsearch to start on restart. That action is reserved for the administrator. This adds tests for that. Closes #13122 --- .../packaging/scripts/30_deb_package.bats | 7 +++++++ .../packaging/scripts/40_rpm_package.bats | 7 +++++++ .../resources/packaging/scripts/60_systemd.bats | 8 ++++++++ .../packaging/scripts/70_sysv_initd.bats | 17 +++++++++++++++++ 4 files changed, 39 insertions(+) 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 8f605216a61..dde6a98a911 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 @@ -67,6 +67,13 @@ setup() { verify_package_installation } +@test "[DEB] elasticsearch isn't started by package install" { + # Wait a second to give Elasticsearch a change to start if it is going to. + # This isn't perfect by any means but its something. + sleep 1 + ! ps aux | grep elasticsearch | grep java +} + @test "[DEB] test elasticsearch" { start_elasticsearch_service 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 588fe382699..09bb5b0b39a 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 @@ -66,6 +66,13 @@ setup() { verify_package_installation } +@test "[RPM] elasticsearch isn't started by package install" { + # Wait a second to give Elasticsearch a change to start if it is going to. + # This isn't perfect by any means but its something. + sleep 1 + ! ps aux | grep elasticsearch | grep java +} + @test "[RPM] test elasticsearch" { start_elasticsearch_service 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 8df4f4a980b..77e8d807362 100644 --- a/qa/vagrant/src/test/resources/packaging/scripts/60_systemd.bats +++ b/qa/vagrant/src/test/resources/packaging/scripts/60_systemd.bats @@ -46,6 +46,14 @@ setup() { systemctl daemon-reload } +@test "[SYSTEMD] daemon isn't enabled on restart" { + # Rather than restart the VM we just ask systemd if it plans on starting + # elasticsearch on restart. Not as strong as a restart but much much + # faster. + run systemctl is-enabled elasticsearch.service + [ "$output" = "disabled" ] +} + @test "[SYSTEMD] enable" { systemctl enable elasticsearch.service 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 5bf43163ab1..7a40711bc46 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 @@ -37,11 +37,28 @@ setup() { skip_not_dpkg_or_rpm } +@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. + # 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 +} + @test "[INIT.D] install elasticsearch" { clean_before_test install_package } +@test "[INIT.D] daemon isn't enabled on restart" { + # Rather than restart the VM which would be slow we check for the symlinks + # that init.d uses to restart the application on startup. + ! find /etc/rc[0123456].d | grep elasticsearch +} + @test "[INIT.D] start" { service elasticsearch start From 800fb5f7f5c42122a187eeb2733485f244421617 Mon Sep 17 00:00:00 2001 From: Nik Everett Date: Thu, 10 Sep 2015 11:55:03 -0400 Subject: [PATCH 2/2] [test] Document implementation choices There are two other obvious ways to implement the "packages don't start elasticsearch" checks but when you work through them they aren't as nice as the implementation of the checks that we use now. This just adds documentation to that effect. --- .../src/test/resources/packaging/scripts/30_deb_package.bats | 4 ++++ .../src/test/resources/packaging/scripts/70_sysv_initd.bats | 3 +++ 2 files changed, 7 insertions(+) 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 dde6a98a911..2579e6a7359 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 @@ -72,6 +72,10 @@ setup() { # This isn't perfect by any means but its something. sleep 1 ! ps aux | grep elasticsearch | grep java + # You might be tempted to use jps instead of the above but that'd have to + # look like: + # ! sudo -u elasticsearch jps | grep -i elasticsearch + # which isn't really easier to read than the above. } @test "[DEB] test elasticsearch" { 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 7a40711bc46..4f134ba68f7 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 @@ -57,6 +57,9 @@ setup() { # Rather than restart the VM which would be slow we check for the symlinks # that init.d uses to restart the application on startup. ! find /etc/rc[0123456].d | grep elasticsearch + # Note that we don't use -iname above because that'd have to look like: + # [ $(find /etc/rc[0123456].d -iname "elasticsearch*" | wc -l) -eq 0 ] + # Which isn't really clearer than what we do use. } @test "[INIT.D] start" {