Skip to content

Commit

Permalink
Allow aarch64 ironbank image, fix enrollment test (#82563)
Browse files Browse the repository at this point in the history
Fixes #81999.

Change `EnrollmentProcessTests` and the testing infrastructure so
that `ServerUtils` can send requests to the correct local port.
This is also a step towards addressing #79688.

Also change the Iron Bank build to that it works on aarch64. This
isn't currently a supported configuration, but it's useful for
testing.
  • Loading branch information
pugnascotia committed Jan 13, 2022
1 parent 50015e5 commit 49b44cb
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 25 deletions.
1 change: 1 addition & 0 deletions distribution/docker/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ ext.expansions = { Architecture architecture, DockerBase base ->
def buildDate = BuildParams.isCi() ? BuildParams.buildDate : BuildParams.buildDate.truncatedTo(ChronoUnit.DAYS)

return [
'arch' : architecture.classifier,
'base_image' : base.image,
'bin_dir' : base == DockerBase.IRON_BANK ? 'scripts' : 'bin',
'build_date' : buildDate,
Expand Down
8 changes: 5 additions & 3 deletions distribution/docker/src/docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,15 @@ RUN mkdir /usr/share/elasticsearch
WORKDIR /usr/share/elasticsearch
<% if (docker_base == "iron_bank") {
// Iron Bank always copies the local artifact
// Iron Bank always copies the local artifact. It uses `arch` from the
// template context variables.
%>
COPY elasticsearch-${version}-linux-x86_64.tar.gz /tmp/elasticsearch.tar.gz
COPY elasticsearch-${version}-linux-${arch}.tar.gz /tmp/elasticsearch.tar.gz
<% } else {
// Fetch the appropriate Elasticsearch distribution for this architecture.
// Keep this command on one line - it is replaced with a `COPY` during local builds.
// It uses the `arch` command to fetch the correct distro for the build machine.
// It uses the `arch` shell command to fetch the correct distro for the build machine,
// which is needed for Docker Hub builds.
%>
RUN curl --retry 10 -S -L --output /tmp/elasticsearch.tar.gz https://artifacts-no-kpi.elastic.co/downloads/elasticsearch/elasticsearch-${version}-linux-\$(arch).tar.gz
<% } %>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import java.net.Socket;
import java.util.List;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;

import static org.elasticsearch.packaging.util.Archives.installArchive;
import static org.elasticsearch.packaging.util.Archives.verifyArchiveInstallation;
Expand All @@ -31,10 +30,7 @@
import static org.elasticsearch.packaging.util.docker.Docker.waitForElasticsearch;
import static org.elasticsearch.packaging.util.docker.DockerRun.builder;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.emptyOrNullString;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.not;
import static org.junit.Assume.assumeTrue;

public class EnrollmentProcessTests extends PackagingTestCase {
Expand Down Expand Up @@ -96,21 +92,20 @@ public void test20DockerAutoFormCluster() throws Exception {
verifySecurityAutoConfigured(installation);
waitForElasticsearch(installation);
final String node1ContainerId = Docker.getContainerId();
String createTokenResult = installation.executables().createEnrollmentToken.run("-s node").stdout;
assertThat(createTokenResult, not(emptyOrNullString()));
final List<String> noWarningOutputLines = createTokenResult.lines()

final String enrollmentToken = installation.executables().createEnrollmentToken.run("-s node").stdout.lines()
.filter(line -> line.startsWith("WARNING:") == false)
.collect(Collectors.toList());
assertThat(noWarningOutputLines.size(), equalTo(1));
.findFirst()
.orElseThrow(() -> new AssertionError("Failing to find any non-warning output lines"));

// installation refers to second node from now on
installation = runAdditionalContainer(
distribution(),
builder().envVar("ENROLLMENT_TOKEN", noWarningOutputLines.get(0)).extraArgs("--publish 9301:9300 --publish 9201:9200")
);
installation = runAdditionalContainer(distribution(), builder().envVar("ENROLLMENT_TOKEN", enrollmentToken), 9201, 9301);

// TODO Make our packaging test methods aware of multiple installations, see https://github.com/elastic/elasticsearch/issues/79688
waitForElasticsearch(installation);
verifyContainerInstallation(installation);
verifySecurityAutoConfigured(installation);

// Allow some time for the second node to join the cluster, we can probably do this more elegantly in
// https://github.com/elastic/elasticsearch/issues/79688
// Then verify that the two nodes formed a cluster
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public class Installation {
public final Path envFile;
@Nullable
private String elasticPassword; // auto-configured password upon installation
public final int port;

private Installation(
Shell sh,
Expand All @@ -47,7 +48,8 @@ private Installation(
Path plugins,
Path modules,
Path pidDir,
Path envFile
Path envFile,
int port
) {
this.sh = sh;
this.distribution = distribution;
Expand All @@ -62,6 +64,7 @@ private Installation(
this.modules = modules;
this.pidDir = pidDir;
this.envFile = envFile;
this.port = port;
this.elasticPassword = null;
}

Expand All @@ -76,7 +79,8 @@ public static Installation ofArchive(Shell sh, Distribution distribution, Path h
home.resolve("plugins"),
home.resolve("modules"),
null,
null
null,
9200
);
}

Expand All @@ -96,11 +100,12 @@ public static Installation ofPackage(Shell sh, Distribution distribution) {
Paths.get("/usr/share/elasticsearch/plugins"),
Paths.get("/usr/share/elasticsearch/modules"),
Paths.get("/var/run/elasticsearch"),
envFile
envFile,
9200
);
}

public static Installation ofContainer(Shell sh, Distribution distribution) {
public static Installation ofContainer(Shell sh, Distribution distribution, int port) {
String root = "/usr/share/elasticsearch";
return new Installation(
sh,
Expand All @@ -112,10 +117,15 @@ public static Installation ofContainer(Shell sh, Distribution distribution) {
Paths.get(root + "/plugins"),
Paths.get(root + "/modules"),
null,
null
null,
port
);
}

public static Installation ofContainer(Shell sh, Distribution distribution) {
return ofContainer(sh, distribution, 9200);
}

/**
* Returns the user that owns this installation.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ private static void waitForXpack(Installation installation) {
int retries = 60;
while (retries > 0) {
retries -= 1;
try (Socket s = new Socket(InetAddress.getLoopbackAddress(), 9200)) {
try (Socket s = new Socket(InetAddress.getLoopbackAddress(), installation.port)) {
return;
} catch (IOException e) {
// ignore, only want to establish a connection
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,15 +126,19 @@ public static Installation runContainer(Distribution distribution, DockerRun bui
*
* @param distribution details about the docker image being tested
* @param builder the command to run
* @param restPort the port to expose the REST endpoint on
* @param transportPort the port to expose the transport endpoint on
* @return an installation that models the running container
*/
public static Installation runAdditionalContainer(Distribution distribution, DockerRun builder) {
public static Installation runAdditionalContainer(Distribution distribution, DockerRun builder, int restPort, int transportPort) {
// TODO Maybe revisit this as part of https://github.com/elastic/elasticsearch/issues/79688
final String command = builder.distribution(distribution).build();
final String command = builder.distribution(distribution)
.extraArgs("--publish", transportPort + ":9300", "--publish", restPort + ":9200")
.build();
logger.info("Running command: " + command);
containerId = sh.run(command).stdout.trim();
waitForElasticsearchToStart();
return Installation.ofContainer(dockerShell, distribution);
return Installation.ofContainer(dockerShell, distribution, restPort);
}

/**
Expand Down

0 comments on commit 49b44cb

Please sign in to comment.