forked from elastic/elasticsearch
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
…astic#118541) Verifies that the plugin sets the `aws_availability_zone` automatically by reading the AZ name from the IMDS at startup.
- Loading branch information
1 parent
96ec2f6
commit 8a61275
Showing
12 changed files
with
265 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
...t/java/org/elasticsearch/discovery/ec2/DiscoveryEc2AvailabilityZoneAttributeImdsV1IT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the "Elastic License | ||
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side | ||
* Public License v 1"; you may not use this file except in compliance with, at | ||
* your election, the "Elastic License 2.0", the "GNU Affero General Public | ||
* License v3.0 only", or the "Server Side Public License, v 1". | ||
*/ | ||
|
||
package org.elasticsearch.discovery.ec2; | ||
|
||
import fixture.aws.imds.Ec2ImdsHttpFixture; | ||
import fixture.aws.imds.Ec2ImdsServiceBuilder; | ||
import fixture.aws.imds.Ec2ImdsVersion; | ||
|
||
import org.elasticsearch.test.cluster.ElasticsearchCluster; | ||
import org.junit.ClassRule; | ||
import org.junit.rules.RuleChain; | ||
import org.junit.rules.TestRule; | ||
|
||
public class DiscoveryEc2AvailabilityZoneAttributeImdsV1IT extends DiscoveryEc2AvailabilityZoneAttributeTestCase { | ||
private static final Ec2ImdsHttpFixture ec2ImdsHttpFixture = new Ec2ImdsHttpFixture( | ||
new Ec2ImdsServiceBuilder(Ec2ImdsVersion.V1).availabilityZoneSupplier( | ||
DiscoveryEc2AvailabilityZoneAttributeTestCase::getAvailabilityZone | ||
) | ||
); | ||
|
||
public static ElasticsearchCluster cluster = buildCluster(ec2ImdsHttpFixture::getAddress); | ||
|
||
@ClassRule | ||
public static TestRule ruleChain = RuleChain.outerRule(ec2ImdsHttpFixture).around(cluster); | ||
|
||
@Override | ||
protected String getTestRestCluster() { | ||
return cluster.getHttpAddresses(); | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
...t/java/org/elasticsearch/discovery/ec2/DiscoveryEc2AvailabilityZoneAttributeImdsV2IT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the "Elastic License | ||
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side | ||
* Public License v 1"; you may not use this file except in compliance with, at | ||
* your election, the "Elastic License 2.0", the "GNU Affero General Public | ||
* License v3.0 only", or the "Server Side Public License, v 1". | ||
*/ | ||
|
||
package org.elasticsearch.discovery.ec2; | ||
|
||
import fixture.aws.imds.Ec2ImdsHttpFixture; | ||
import fixture.aws.imds.Ec2ImdsServiceBuilder; | ||
import fixture.aws.imds.Ec2ImdsVersion; | ||
|
||
import org.elasticsearch.test.cluster.ElasticsearchCluster; | ||
import org.junit.ClassRule; | ||
import org.junit.rules.RuleChain; | ||
import org.junit.rules.TestRule; | ||
|
||
public class DiscoveryEc2AvailabilityZoneAttributeImdsV2IT extends DiscoveryEc2AvailabilityZoneAttributeTestCase { | ||
private static final Ec2ImdsHttpFixture ec2ImdsHttpFixture = new Ec2ImdsHttpFixture( | ||
new Ec2ImdsServiceBuilder(Ec2ImdsVersion.V2).availabilityZoneSupplier( | ||
DiscoveryEc2AvailabilityZoneAttributeTestCase::getAvailabilityZone | ||
) | ||
); | ||
|
||
public static ElasticsearchCluster cluster = buildCluster(ec2ImdsHttpFixture::getAddress); | ||
|
||
@ClassRule | ||
public static TestRule ruleChain = RuleChain.outerRule(ec2ImdsHttpFixture).around(cluster); | ||
|
||
@Override | ||
protected String getTestRestCluster() { | ||
return cluster.getHttpAddresses(); | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
...t/java/org/elasticsearch/discovery/ec2/DiscoveryEc2AvailabilityZoneAttributeNoImdsIT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the "Elastic License | ||
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side | ||
* Public License v 1"; you may not use this file except in compliance with, at | ||
* your election, the "Elastic License 2.0", the "GNU Affero General Public | ||
* License v3.0 only", or the "Server Side Public License, v 1". | ||
*/ | ||
|
||
package org.elasticsearch.discovery.ec2; | ||
|
||
import org.elasticsearch.client.Request; | ||
import org.elasticsearch.test.cluster.ElasticsearchCluster; | ||
import org.elasticsearch.test.rest.ESRestTestCase; | ||
import org.junit.ClassRule; | ||
|
||
import java.io.IOException; | ||
|
||
public class DiscoveryEc2AvailabilityZoneAttributeNoImdsIT extends ESRestTestCase { | ||
@ClassRule | ||
public static ElasticsearchCluster cluster = ElasticsearchCluster.local() | ||
.plugin("discovery-ec2") | ||
.setting(AwsEc2Service.AUTO_ATTRIBUTE_SETTING.getKey(), "true") | ||
.build(); | ||
|
||
@Override | ||
protected String getTestRestCluster() { | ||
return cluster.getHttpAddresses(); | ||
} | ||
|
||
public void testAvailabilityZoneAttribute() throws IOException { | ||
final var nodesInfoResponse = assertOKAndCreateObjectPath(client().performRequest(new Request("GET", "/_nodes/_all/_none"))); | ||
for (final var nodeId : nodesInfoResponse.evaluateMapKeys("nodes")) { | ||
assertNull(nodesInfoResponse.evaluateExact("nodes", nodeId, "attributes", "aws_availability_zone")); | ||
} | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
...t/java/org/elasticsearch/discovery/ec2/DiscoveryEc2AvailabilityZoneAttributeTestCase.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the "Elastic License | ||
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side | ||
* Public License v 1"; you may not use this file except in compliance with, at | ||
* your election, the "Elastic License 2.0", the "GNU Affero General Public | ||
* License v3.0 only", or the "Server Side Public License, v 1". | ||
*/ | ||
|
||
package org.elasticsearch.discovery.ec2; | ||
|
||
import org.elasticsearch.client.Request; | ||
import org.elasticsearch.common.util.concurrent.ConcurrentCollections; | ||
import org.elasticsearch.test.cluster.ElasticsearchCluster; | ||
import org.elasticsearch.test.rest.ESRestTestCase; | ||
import org.hamcrest.Matchers; | ||
|
||
import java.io.IOException; | ||
import java.util.Objects; | ||
import java.util.Set; | ||
import java.util.function.Supplier; | ||
|
||
public abstract class DiscoveryEc2AvailabilityZoneAttributeTestCase extends ESRestTestCase { | ||
|
||
private static final Set<String> createdAvailabilityZones = ConcurrentCollections.newConcurrentSet(); | ||
|
||
protected static String getAvailabilityZone() { | ||
final var zoneName = randomIdentifier(); | ||
createdAvailabilityZones.add(zoneName); | ||
return zoneName; | ||
} | ||
|
||
protected static ElasticsearchCluster buildCluster(Supplier<String> imdsFixtureAddressSupplier) { | ||
return ElasticsearchCluster.local() | ||
.plugin("discovery-ec2") | ||
.setting(AwsEc2Service.AUTO_ATTRIBUTE_SETTING.getKey(), "true") | ||
.systemProperty("com.amazonaws.sdk.ec2MetadataServiceEndpointOverride", imdsFixtureAddressSupplier) | ||
.build(); | ||
} | ||
|
||
public void testAvailabilityZoneAttribute() throws IOException { | ||
final var nodesInfoResponse = assertOKAndCreateObjectPath(client().performRequest(new Request("GET", "/_nodes/_all/_none"))); | ||
for (final var nodeId : nodesInfoResponse.evaluateMapKeys("nodes")) { | ||
assertThat( | ||
createdAvailabilityZones, | ||
Matchers.hasItem( | ||
Objects.requireNonNull(nodesInfoResponse.<String>evaluateExact("nodes", nodeId, "attributes", "aws_availability_zone")) | ||
) | ||
); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.