fix(ec2): report the network interface IPv6 address (#9027)

An ENI could have IPv6 addresses assigned while its top-level
ipv6Address was missing from CreateNetworkInterface and
DescribeNetworkInterfaces. The shared serializer now reports the first
assigned address there, keeps the ipv6AddressesSet list, and omits the
field when the interface has none.

Ported from Emanuel Aseghehey's AndreKurait/floci#1239.
This commit is contained in:
Andre Kurait authored and GitHub committed 2026-11-19 20:36:25 -04:00
1 parent 2ab20905a2
commit a6a609d62f
3 files changed
+33 -1

No files matched your search

+1 -1
View File
@@ -1298,7 +1298,7 @@ profile.
| Action | Description |
|--------|-------------|
| CreateNetworkInterface | Creates a standalone elastic network interface (ENI) in a subnet, unattached. `Ipv6Addresses` names IPv6 addresses inside one of the subnet's IPv6 blocks; `Ipv6AddressCount` draws that many from the subnet. Left out, the subnet's `AssignIpv6AddressOnCreation` gives the interface one address; an explicit `0` overrides it. |
| CreateNetworkInterface | Creates a standalone elastic network interface (ENI) in a subnet, unattached. `Ipv6Addresses` names IPv6 addresses inside one of the subnet's IPv6 blocks; `Ipv6AddressCount` draws that many from the subnet. Left out, the subnet's `AssignIpv6AddressOnCreation` gives the interface one address; an explicit `0` overrides it. Create and describe responses also expose the first assigned IPv6 address as `ipv6Address`, omitting it when the interface has none. |
| DescribeNetworkInterfaces | Lists network interfaces known to the local EC2 service, both an instance's implicit primary interface and standalone ENIs created via `CreateNetworkInterface`. |
| AttachNetworkInterface | Attaches an available standalone ENI to a running or stopped instance at a device index. |
| DetachNetworkInterface | Detaches a standalone ENI by attachment ID, returning it to `available`. |
@@ -5508,6 +5508,9 @@ public class Ec2QueryHandler {
}
xml.end("privateIpAddressesSet");
}
if (ni.getIpv6Addresses() != null && !ni.getIpv6Addresses().isEmpty()) {
xml.elem("ipv6Address", ni.getIpv6Addresses().getFirst());
}
xml.raw(ipv6AddressesSetXml(ni.getIpv6Addresses()));
return xml.build();
}
@@ -25,6 +25,7 @@ import java.util.function.Consumer;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
@@ -53,6 +54,34 @@ class Ec2NetworkInterfaceIpv6IntegrationTest {
assertEquals(addresses, addresses(describe(fixture, created.networkInterfaceId())));
}
@Test
void reportsTheFirstIpv6AddressOnCreateAndDescribe() {
Fixture fixture = fixture();
NetworkInterface created = fixture.client().createNetworkInterface(request -> request
.subnetId(fixture.subnet()).ipv6AddressCount(2)).networkInterface();
cleanup.register(() -> fixture.client().deleteNetworkInterface(request -> request
.networkInterfaceId(created.networkInterfaceId())));
List<String> assigned = addresses(created);
assertEquals(assigned.getFirst(), created.ipv6Address());
assertEquals(assigned.getFirst(), describe(fixture, created.networkInterfaceId()).ipv6Address());
fixture.client().unassignIpv6Addresses(request -> request
.networkInterfaceId(created.networkInterfaceId()).ipv6Addresses(assigned.getFirst()));
assertEquals(assigned.get(1), describe(fixture, created.networkInterfaceId()).ipv6Address());
}
@Test
void omitsTheTopLevelIpv6AddressWhenNoneRemain() {
Fixture fixture = fixture();
String eni = create(fixture, request -> { });
assertNull(describe(fixture, eni).ipv6Address());
List<String> assigned = fixture.client().assignIpv6Addresses(request -> request
.networkInterfaceId(eni).ipv6AddressCount(1)).assignedIpv6Addresses();
fixture.client().unassignIpv6Addresses(request -> request
.networkInterfaceId(eni).ipv6Addresses(assigned));
assertNull(describe(fixture, eni).ipv6Address());
}
// Catches: an explicit Ipv6AddressCount of 0 read as "not given", so the subnet's AssignIpv6AddressOnCreation
// still hands out an address, where the API reference says 0 overrides it.
@Test