OpenSearch/qa/os
Rory Hunter 24f7d4e83b
Add Docker packaging tests on 7.x (#48857)
Backport of #46599 and #47640. Add packaging tests for Docker.

* Introduce packaging tests for Docker (#46599)

Closes #37617. Add packaging tests for our Docker images, similar to what
we have for RPMs or Debian packages. This works by running a container and
probing it e.g. via `docker exec`. Test can also be run in Vagrant, by
exporting the Docker images to disk and loading them again in VMs. Docker
is installed via `Vagrantfile` in a selection of boxes.

* Only define Docker pkg tests if Docker is available (#47640)

Closes #47639, and unmutes tests that were muted in b958467.

The Docker packaging tests were being defined irrespective of whether
Docker was actually available in the current environment. Instead,
implement exclude lists so that in environments where Docker is not
available, no Docker packaging tests are defined. For CI hosts, the build
checks `.ci/dockerOnLinuxExclusions`. The Vagrant VMs can defined the
extension property `shouldTestDocker` property to opt-in to packaging
tests.

As part of this, define a seperate utility class for checking Docker,
and call that instead of defining checks in-line in BuildPlugin.groovy
2019-11-05 15:17:59 +00:00
..
bats Increase timeouts for packaging tests (#48528) 2019-10-28 06:48:11 +02:00
centos-6 Rename vagrant project to os (#45509) (#45530) 2019-08-14 10:30:41 -07:00
centos-7 Add Docker packaging tests on 7.x (#48857) 2019-11-05 15:17:59 +00:00
debian-8 Rename vagrant project to os (#45509) (#45530) 2019-08-14 10:30:41 -07:00
debian-9 Add Docker packaging tests on 7.x (#48857) 2019-11-05 15:17:59 +00:00
fedora-28 Add Docker packaging tests on 7.x (#48857) 2019-11-05 15:17:59 +00:00
fedora-29 Add Docker packaging tests on 7.x (#48857) 2019-11-05 15:17:59 +00:00
oel-6 Rename vagrant project to os (#45509) (#45530) 2019-08-14 10:30:41 -07:00
oel-7 Rename vagrant project to os (#45509) (#45530) 2019-08-14 10:30:41 -07:00
opensuse-42 Rename vagrant project to os (#45509) (#45530) 2019-08-14 10:30:41 -07:00
sles-12 Rename vagrant project to os (#45509) (#45530) 2019-08-14 10:30:41 -07:00
src/test/java/org/elasticsearch/packaging Add Docker packaging tests on 7.x (#48857) 2019-11-05 15:17:59 +00:00
ubuntu-1604 Add Docker packaging tests on 7.x (#48857) 2019-11-05 15:17:59 +00:00
ubuntu-1804 Add Docker packaging tests on 7.x (#48857) 2019-11-05 15:17:59 +00:00
windows-2012r2 Separate distro tests to be per distribution (#45565) 2019-08-20 13:12:15 -07:00
windows-2016 Separate distro tests to be per distribution (#45565) 2019-08-20 13:12:15 -07:00
README.md Rename vagrant project to os (#45509) (#45530) 2019-08-14 10:30:41 -07:00
build.gradle Add a packagingTask for every os project (#48400) 2019-10-28 06:48:06 +02:00

README.md

packaging tests

This project contains tests that verify the distributions we build work correctly on the operating systems we support. They're intended to cover the steps a user would take when installing and configuring an Elasticsearch distribution. They're not intended to have significant coverage of the behavior of Elasticsearch's features.

There are two types of tests in this project. The old tests live in src/test/ and are written in Bats, which is a flavor of bash scripts that run as unit tests. These tests are deprecated because Bats is unmaintained and cannot run on Windows.

The new tests live in src/main/ and are written in Java. Like the old tests, this project's tests are run inside the VM, not on your host. All new packaging tests should be added to this set of tests if possible.

Running these tests

See the section in TESTING.asciidoc

Adding a new test class

When gradle runs the packaging tests on a VM, it runs the full suite by default. To add a test class to the suite, add its class to the @SuiteClasses annotation in PackagingTests.java. If a test class is added to the project but not to this annotation, it will not run in CI jobs. The test classes are run in the order they are listed in the annotation.

Choosing which distributions to test

Distributions are represented by enum values which know if they are compatible with the platform the tests are currently running on. To skip a test if the distribution it's using isn't compatible with the current platform, put this assumption in your test method or in a @Before method

assumeTrue(distribution.packaging.compatible);

Similarly if you write a test that is intended only for particular platforms, you can make an assumption using the constants and methods in Platforms.java

assumeTrue("only run on windows", Platforms.WINDOWS);

assumeTrue("only run if using systemd", Platforms.isSystemd());

Writing a test that covers multiple distributions

It seems like the way to do this that makes it the most straightforward to run and reproduce specific test cases is to create a test case class with an abstract method that provides the distribution

public abstract class MyTestCase {
  @Test
  public void myTest() { /* do something with the value of #distribution() */ }
  abstract Distribution distribution();
}

and then for each distribution you want to test, create a subclass

public class MyTestDefaultTar extends MyTestCase {
  @Override
  Distribution distribution() { return Distribution.DEFAULT_TAR; }
}

That way when a test fails the user gets told explicitly that MyTestDefaultTar failed, and to reproduce it they should run that class. See ArchiveTestCase and its children for an example of this.

Running external commands

In general it's probably best to avoid running external commands when a good Java alternative exists. For example most filesystem operations can be done with the java.nio.file APIs. For those that aren't, use an instance of Shell

This class runs scripts in either bash with the bash -c <script> syntax, or in powershell with the powershell.exe -Command <script> syntax.

Shell sh = new Shell();

// equivalent to `bash -c 'echo $foo; echo $bar'`
sh.bash("echo $foo; echo $bar");

// equivalent to `powershell.exe -Command 'Write-Host $foo; Write-Host $bar'`
sh.powershell("Write-Host $foo; Write-Host $bar");

Notes about powershell

Powershell scripts for the most part have backwards compatibility with legacy cmd.exe commands and their syntax. Most of the commands you'll want to use in powershell are Cmdlets which generally don't have a one-to-one mapping with an executable file.

When writing powershell commands in this project it's worth testing them by hand, as sometimes when a script can't be interpreted correctly it will fail silently.