Skip to content

Commit fe64ae0

Browse files
authored
Fix DiscoveryEc2AvailabilityZoneAttributeNoImdsIT (#118821)
This test asserts that no AZ attribute is set, assuming that the current AZ is unavailable, but in fact that's not true when running these tests in EC2. With this commit we override the IMDS endpoint address to one that definitely does not exist. Relates #118675 Closes #118564
1 parent 41a4660 commit fe64ae0

File tree

1 file changed

+4
-10
lines changed

1 file changed

+4
-10
lines changed

plugins/discovery-ec2/src/javaRestTest/java/org/elasticsearch/discovery/ec2/DiscoveryEc2AvailabilityZoneAttributeNoImdsIT.java

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,30 +9,24 @@
99

1010
package org.elasticsearch.discovery.ec2;
1111

12-
import com.amazonaws.util.EC2MetadataUtils;
13-
1412
import org.elasticsearch.client.Request;
1513
import org.elasticsearch.test.cluster.ElasticsearchCluster;
16-
import org.elasticsearch.test.rest.ESRestTestCase;
1714
import org.junit.ClassRule;
1815

1916
import java.io.IOException;
2017

21-
public class DiscoveryEc2AvailabilityZoneAttributeNoImdsIT extends ESRestTestCase {
18+
public class DiscoveryEc2AvailabilityZoneAttributeNoImdsIT extends DiscoveryEc2AvailabilityZoneAttributeTestCase {
2219
@ClassRule
23-
public static ElasticsearchCluster cluster = ElasticsearchCluster.local()
24-
.plugin("discovery-ec2")
25-
.setting(AwsEc2Service.AUTO_ATTRIBUTE_SETTING.getKey(), "true")
26-
.build();
20+
// use an address which definitely isn't running an IMDS, just in case we're running these tests in EC2
21+
public static ElasticsearchCluster cluster = DiscoveryEc2AvailabilityZoneAttributeTestCase.buildCluster(() -> "http://127.0.0.1:1");
2722

2823
@Override
2924
protected String getTestRestCluster() {
3025
return cluster.getHttpAddresses();
3126
}
3227

28+
@Override // the base class asserts that the attribute is set, but we don't want that here
3329
public void testAvailabilityZoneAttribute() throws IOException {
34-
assumeTrue("test only in non-AWS environment", EC2MetadataUtils.getInstanceId() == null);
35-
3630
final var nodesInfoResponse = assertOKAndCreateObjectPath(client().performRequest(new Request("GET", "/_nodes/_all/_none")));
3731
for (final var nodeId : nodesInfoResponse.evaluateMapKeys("nodes")) {
3832
assertNull(nodesInfoResponse.evaluateExact("nodes", nodeId, "attributes", "aws_availability_zone"));

0 commit comments

Comments
 (0)