mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(ec2): assign a public IP only when the subnet opts in via MapPublicIpOnLaunch (#2023)
* fix(ec2): assign a public IP only when the subnet opts in via MapPublicIpOnLaunch (#1984) Every instance was given PublicIpAddress 127.0.0.1 unconditionally in Ec2ContainerManager, so a private-subnet instance wrongly reported an internet-facing address (breaks the ssh-reachability / public-vs-private distinction). runInstances now flags the instance (associatePublicIp) from its subnet's MapPublicIpOnLaunch, and the container manager exposes a public address only when that flag is set. Private-subnet instances get no PublicIpAddress — DescribeInstances omits the element (XmlBuilder skips nulls), matching real EC2. The value for public instances stays the host-reachable 127.0.0.1 (unchanged). Unit test covers the public-vs-private flag. Supports the aws-bench project: un-excludes the ssh-reachability scenario. * fix(ec2): honor the launch-time AssociatePublicIpAddress override * fix(ec2): honor the top-level AssociatePublicIpAddress and an explicit-false launch configuration Two gaps left by the previous commit, both flagged in review. RunInstances only read the override off the primary network-interface spec (NetworkInterface.1.AssociatePublicIpAddress), so the legacy top-level AssociatePublicIpAddress parameter — what the CLI and older SDKs send — was silently dropped and the subnet default decided instead. It is now read as a fallback; AWS rejects both shapes at once, so the interface spec wins when present. The launch-configuration path was worse than before. LaunchConfiguration stored a primitive boolean, so an absent flag and an explicit false were indistinguishable, and the reconciler could only forward an explicit true. An LC that set AssociatePublicIpAddress=false in a MapPublicIpOnLaunch subnet still got a public address. The field is now a nullable Boolean the whole way through (service, query handler, CFN provisioner), so false overrides the subnet and only null falls back to it. DescribeLaunchConfigurations omits the element when it was never set, as AWS does. Tests: a handler-level test pins all four parse cases (top-level, interface spec, both present, absent), and the reconciler test pins true/false/null reaching runInstances unchanged.
This commit is contained in:
1 parent
188588b4eb
commit
2ab795c6dc
12 files changed
+404
-23
No files matched your search
+52
-5
@@ -2,6 +2,7 @@ package io.github.hectorvent.floci.services.autoscaling;
|
||||
|
||||
import io.github.hectorvent.floci.services.autoscaling.model.AsgInstance;
|
||||
import io.github.hectorvent.floci.services.autoscaling.model.AutoScalingGroup;
|
||||
import io.github.hectorvent.floci.services.autoscaling.model.LaunchConfiguration;
|
||||
import io.github.hectorvent.floci.services.autoscaling.model.MixedInstancesPolicy;
|
||||
import io.github.hectorvent.floci.services.ec2.Ec2Service;
|
||||
import io.github.hectorvent.floci.services.ec2.model.Instance;
|
||||
@@ -96,7 +97,7 @@ class AutoScalingReconcilerTest {
|
||||
reservation.setInstances(List.of(ec2Instance));
|
||||
when(ec2Service.runInstances(eq("us-east-1"), eq("ami-version-1"), eq("t3.micro"),
|
||||
eq(1), eq(1), eq(null), eq(List.of()), eq(null), eq(null),
|
||||
anyList(), eq(null), eq("arn:aws:iam::000000000000:instance-profile/app-profile"))).thenReturn(reservation);
|
||||
anyList(), eq(null), eq("arn:aws:iam::000000000000:instance-profile/app-profile"), eq(null))).thenReturn(reservation);
|
||||
|
||||
reconciler.reconcile(asg);
|
||||
|
||||
@@ -107,7 +108,7 @@ class AutoScalingReconcilerTest {
|
||||
ArgumentCaptor<List<Tag>> tags = ArgumentCaptor.captor();
|
||||
verify(ec2Service).runInstances(eq("us-east-1"), eq("ami-version-1"), eq("t3.micro"),
|
||||
eq(1), eq(1), eq(null), eq(List.of()), eq(null), eq(null),
|
||||
tags.capture(), eq(null), eq("arn:aws:iam::000000000000:instance-profile/app-profile"));
|
||||
tags.capture(), eq(null), eq("arn:aws:iam::000000000000:instance-profile/app-profile"), eq(null));
|
||||
assertEquals(propagatedTags.size(), tags.getValue().size());
|
||||
assertEquals("app.ClusterId", tags.getValue().get(0).getKey());
|
||||
assertEquals("development", tags.getValue().get(0).getValue());
|
||||
@@ -115,6 +116,51 @@ class AutoScalingReconcilerTest {
|
||||
assertEquals("2001", tags.getValue().get(1).getValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
void scaleOutForwardsLaunchConfigurationAssociatePublicIpAddressBothDirections() {
|
||||
// An LC that explicitly sets false must suppress the public IP even in a
|
||||
// MapPublicIpOnLaunch subnet, so false has to reach runInstances as
|
||||
// FALSE rather than null (null means "use the subnet default").
|
||||
assertLaunchConfigurationForwards(Boolean.FALSE);
|
||||
assertLaunchConfigurationForwards(Boolean.TRUE);
|
||||
assertLaunchConfigurationForwards(null);
|
||||
}
|
||||
|
||||
private void assertLaunchConfigurationForwards(Boolean associatePublicIp) {
|
||||
AutoScalingService asgService = mock(AutoScalingService.class);
|
||||
Ec2Service ec2Service = mock(Ec2Service.class);
|
||||
ElbV2Service elbV2Service = mock(ElbV2Service.class);
|
||||
AutoScalingReconciler reconciler = new AutoScalingReconciler(asgService, ec2Service, elbV2Service);
|
||||
|
||||
AutoScalingGroup asg = new AutoScalingGroup();
|
||||
asg.setRegion("us-east-1");
|
||||
asg.setAutoScalingGroupName("app-asg");
|
||||
asg.setDesiredCapacity(1);
|
||||
asg.setLaunchConfigurationName("app-lc");
|
||||
|
||||
LaunchConfiguration lc = new LaunchConfiguration();
|
||||
lc.setLaunchConfigurationName("app-lc");
|
||||
lc.setImageId("ami-lc");
|
||||
lc.setInstanceType("t3.micro");
|
||||
lc.setAssociatePublicIpAddress(associatePublicIp);
|
||||
when(asgService.describeLaunchConfigurations("us-east-1", List.of("app-lc")))
|
||||
.thenReturn(List.of(lc));
|
||||
|
||||
Instance ec2Instance = new Instance();
|
||||
ec2Instance.setInstanceId("i-lc-launched");
|
||||
Reservation reservation = new Reservation();
|
||||
reservation.setInstances(List.of(ec2Instance));
|
||||
when(ec2Service.runInstances(eq("us-east-1"), eq("ami-lc"), eq("t3.micro"),
|
||||
eq(1), eq(1), eq(null), anyList(), eq(null), eq(null),
|
||||
anyList(), eq(null), eq(null), eq(associatePublicIp))).thenReturn(reservation);
|
||||
|
||||
reconciler.reconcile(asg);
|
||||
|
||||
verify(ec2Service).runInstances(eq("us-east-1"), eq("ami-lc"), eq("t3.micro"),
|
||||
eq(1), eq(1), eq(null), anyList(), eq(null), eq(null),
|
||||
anyList(), eq(null), eq(null), eq(associatePublicIp));
|
||||
}
|
||||
|
||||
@Test
|
||||
void scaleOutStoresResolvedLaunchTemplateVersionForAliases() {
|
||||
AutoScalingService asgService = mock(AutoScalingService.class);
|
||||
@@ -144,7 +190,7 @@ class AutoScalingReconcilerTest {
|
||||
reservation.setInstances(List.of(ec2Instance));
|
||||
when(ec2Service.runInstances(eq("us-east-1"), eq("ami-version-7"), eq("t3.micro"),
|
||||
eq(1), eq(1), eq(null), eq(List.of()), eq(null), eq(null),
|
||||
eq(List.of()), eq(null), eq(null))).thenReturn(reservation);
|
||||
eq(List.of()), eq(null), eq(null), eq(null))).thenReturn(reservation);
|
||||
|
||||
reconciler.reconcile(asg);
|
||||
|
||||
@@ -193,7 +239,7 @@ class AutoScalingReconcilerTest {
|
||||
reservation.setInstances(List.of(ec2Instance));
|
||||
when(ec2Service.runInstances(eq("us-east-1"), eq("ami-version-3"), eq("t3.small"),
|
||||
eq(1), eq(1), eq(null), eq(List.of()), eq(null), eq(null),
|
||||
eq(List.of()), eq(null), eq(null))).thenReturn(reservation);
|
||||
eq(List.of()), eq(null), eq(null), eq(null))).thenReturn(reservation);
|
||||
|
||||
reconciler.reconcile(asg);
|
||||
|
||||
@@ -204,7 +250,7 @@ class AutoScalingReconcilerTest {
|
||||
assertEquals("t3.small", asg.getInstances().getFirst().getInstanceType());
|
||||
verify(ec2Service).runInstances(eq("us-east-1"), eq("ami-version-3"), eq("t3.small"),
|
||||
eq(1), eq(1), eq(null), eq(List.of()), eq(null), eq(null),
|
||||
eq(List.of()), eq(null), eq(null));
|
||||
eq(List.of()), eq(null), eq(null), eq(null));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -273,6 +319,7 @@ class AutoScalingReconcilerTest {
|
||||
org.mockito.ArgumentMatchers.any(),
|
||||
org.mockito.ArgumentMatchers.any(),
|
||||
org.mockito.ArgumentMatchers.any(),
|
||||
org.mockito.ArgumentMatchers.any(),
|
||||
org.mockito.ArgumentMatchers.any());
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,170 @@
|
||||
package io.github.hectorvent.floci.services.ec2;
|
||||
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import io.github.hectorvent.floci.config.EmulatorConfig;
|
||||
import io.github.hectorvent.floci.core.storage.PersistentStorage;
|
||||
import io.github.hectorvent.floci.core.storage.StorageBackend;
|
||||
import io.github.hectorvent.floci.services.ec2.model.Address;
|
||||
import io.github.hectorvent.floci.services.ec2.model.Image;
|
||||
import io.github.hectorvent.floci.services.ec2.model.InternetGateway;
|
||||
import io.github.hectorvent.floci.services.ec2.model.KeyPair;
|
||||
import io.github.hectorvent.floci.services.ec2.model.LaunchTemplate;
|
||||
import io.github.hectorvent.floci.services.ec2.model.NatGateway;
|
||||
import io.github.hectorvent.floci.services.ec2.model.NetworkAcl;
|
||||
import io.github.hectorvent.floci.services.ec2.model.Instance;
|
||||
import io.github.hectorvent.floci.services.ec2.model.Reservation;
|
||||
import io.github.hectorvent.floci.services.ec2.model.RouteTable;
|
||||
import io.github.hectorvent.floci.services.ec2.model.SecurityGroup;
|
||||
import io.github.hectorvent.floci.services.ec2.model.SecurityGroupRule;
|
||||
import io.github.hectorvent.floci.services.ec2.model.Snapshot;
|
||||
import io.github.hectorvent.floci.services.ec2.model.SpotInstanceRequest;
|
||||
import io.github.hectorvent.floci.services.ec2.model.Subnet;
|
||||
import io.github.hectorvent.floci.services.ec2.model.Tag;
|
||||
import io.github.hectorvent.floci.services.ec2.model.Volume;
|
||||
import io.github.hectorvent.floci.services.ec2.model.Vpc;
|
||||
import io.github.hectorvent.floci.services.ec2.model.VpcEndpoint;
|
||||
import io.github.hectorvent.floci.services.ec2.portforward.Ec2PortForwardManager;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.io.TempDir;
|
||||
|
||||
import java.nio.file.Path;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
/**
|
||||
* Regression test for issue #1984: a public IP must be assigned only to instances
|
||||
* whose subnet opts in via MapPublicIpOnLaunch. Before the fix every instance got
|
||||
* PublicIpAddress 127.0.0.1 regardless of subnet, so a private-subnet instance
|
||||
* wrongly looked internet-facing. The launch-time flag (associatePublicIp) drives
|
||||
* whether Ec2ContainerManager exposes a public address once the container is up.
|
||||
*/
|
||||
class Ec2PublicIpOnLaunchTest {
|
||||
|
||||
private static final String REGION = "us-east-1";
|
||||
private static final String AMI = "ami-0abcdef1234567890";
|
||||
|
||||
@Test
|
||||
void publicSubnetInstanceGetsPublicIpFlag_privateDoesNot(@TempDir Path dir) {
|
||||
Ec2Service ec2 = newService(dir);
|
||||
Vpc vpc = ec2.createVpc(REGION, "10.0.0.0/16", false);
|
||||
|
||||
Subnet publicSubnet = ec2.createSubnet(REGION, vpc.getVpcId(), "10.0.0.0/24", REGION + "a");
|
||||
ec2.modifySubnetAttribute(REGION, publicSubnet.getSubnetId(), "mapPublicIpOnLaunch", "true");
|
||||
|
||||
Subnet privateSubnet = ec2.createSubnet(REGION, vpc.getVpcId(), "10.0.1.0/24", REGION + "a");
|
||||
// privateSubnet keeps MapPublicIpOnLaunch=false (the createSubnet default)
|
||||
|
||||
Instance inPublic = runOne(ec2, publicSubnet.getSubnetId());
|
||||
Instance inPrivate = runOne(ec2, privateSubnet.getSubnetId());
|
||||
|
||||
assertTrue(inPublic.isAssociatePublicIp(),
|
||||
"instance in a MapPublicIpOnLaunch subnet must be flagged for a public IP");
|
||||
assertFalse(inPrivate.isAssociatePublicIp(),
|
||||
"instance in a private subnet must NOT be flagged for a public IP");
|
||||
|
||||
// The behavior #1984 is about, not just the flag: after the container
|
||||
// manager's gate runs, a private-subnet instance reports no public
|
||||
// address while a public-subnet one reports the host-reachable one.
|
||||
applyContainerManagerPublicIpGate(inPublic);
|
||||
applyContainerManagerPublicIpGate(inPrivate);
|
||||
assertEquals("127.0.0.1", inPublic.getPublicIpAddress(),
|
||||
"public-subnet instance must report the host-reachable public IP");
|
||||
assertNull(inPrivate.getPublicIpAddress(),
|
||||
"private-subnet instance must report no public IP");
|
||||
assertNull(inPrivate.getPublicDnsName(),
|
||||
"private-subnet instance must report no public DNS name");
|
||||
}
|
||||
|
||||
@Test
|
||||
void launchTimeOverrideBeatsSubnetDefaultBothDirections(@TempDir Path dir) {
|
||||
Ec2Service ec2 = newService(dir);
|
||||
Vpc vpc = ec2.createVpc(REGION, "10.0.0.0/16", false);
|
||||
|
||||
Subnet publicSubnet = ec2.createSubnet(REGION, vpc.getVpcId(), "10.0.0.0/24", REGION + "a");
|
||||
ec2.modifySubnetAttribute(REGION, publicSubnet.getSubnetId(), "mapPublicIpOnLaunch", "true");
|
||||
Subnet privateSubnet = ec2.createSubnet(REGION, vpc.getVpcId(), "10.0.1.0/24", REGION + "a");
|
||||
|
||||
// AWS precedence: the launch-time AssociatePublicIpAddress override wins
|
||||
// over the subnet attribute in both directions.
|
||||
Instance forcedOn = runOne(ec2, privateSubnet.getSubnetId(), Boolean.TRUE);
|
||||
Instance forcedOff = runOne(ec2, publicSubnet.getSubnetId(), Boolean.FALSE);
|
||||
|
||||
assertTrue(forcedOn.isAssociatePublicIp(),
|
||||
"launch-time true must force a public IP in a private subnet");
|
||||
assertFalse(forcedOff.isAssociatePublicIp(),
|
||||
"launch-time false must suppress the public IP in a public subnet");
|
||||
}
|
||||
|
||||
/**
|
||||
* Mirrors the gate in Ec2ContainerManager (launch(), the
|
||||
* isAssociatePublicIp branch): public addresses are set only for flagged
|
||||
* instances. The manager is mocked out here to keep Docker away, so the
|
||||
* decision is replicated verbatim — if the branch there changes shape,
|
||||
* update this too.
|
||||
*/
|
||||
private static void applyContainerManagerPublicIpGate(Instance instance) {
|
||||
if (instance.isAssociatePublicIp()) {
|
||||
instance.setPublicIpAddress("127.0.0.1");
|
||||
instance.setPublicDnsName("localhost");
|
||||
}
|
||||
}
|
||||
|
||||
private Instance runOne(Ec2Service ec2, String subnetId) {
|
||||
return runOne(ec2, subnetId, null);
|
||||
}
|
||||
|
||||
private Instance runOne(Ec2Service ec2, String subnetId, Boolean associatePublicIp) {
|
||||
Reservation r = ec2.runInstances(REGION, AMI, "t2.micro", 1, 1, null,
|
||||
List.of(), subnetId, null, List.of(), null, null, associatePublicIp);
|
||||
return r.getInstances().get(0);
|
||||
}
|
||||
|
||||
private Ec2Service newService(Path dir) {
|
||||
EmulatorConfig config = mock(EmulatorConfig.class);
|
||||
when(config.defaultAccountId()).thenReturn("000000000000");
|
||||
// mock() == true short-circuits the container launch in runInstances, so
|
||||
// no Docker is needed — the associatePublicIp flag is set before that.
|
||||
EmulatorConfig.ServicesConfig services = mock(EmulatorConfig.ServicesConfig.class);
|
||||
EmulatorConfig.Ec2ServiceConfig ec2Cfg = mock(EmulatorConfig.Ec2ServiceConfig.class);
|
||||
when(config.services()).thenReturn(services);
|
||||
when(services.ec2()).thenReturn(ec2Cfg);
|
||||
when(ec2Cfg.mock()).thenReturn(true);
|
||||
Ec2ImageCatalog imageCatalog = new Ec2ImageCatalog();
|
||||
// A mock container manager makes launch() a no-op — the associatePublicIp
|
||||
// flag is set on the instance BEFORE launch, so no Docker is needed here.
|
||||
return new Ec2Service(config, mock(Ec2ContainerManager.class), mock(Ec2PortForwardManager.class),
|
||||
new AmiImageResolver(imageCatalog), imageCatalog,
|
||||
new Ec2InstanceTypeCatalog(),
|
||||
load(dir, "ec2-vpcs.json", new TypeReference<Map<String, Vpc>>() {}),
|
||||
load(dir, "ec2-subnets.json", new TypeReference<Map<String, Subnet>>() {}),
|
||||
load(dir, "ec2-security-groups.json", new TypeReference<Map<String, SecurityGroup>>() {}),
|
||||
load(dir, "ec2-security-group-rules.json", new TypeReference<Map<String, SecurityGroupRule>>() {}),
|
||||
load(dir, "ec2-internet-gateways.json", new TypeReference<Map<String, InternetGateway>>() {}),
|
||||
load(dir, "ec2-route-tables.json", new TypeReference<Map<String, RouteTable>>() {}),
|
||||
load(dir, "ec2-key-pairs.json", new TypeReference<Map<String, KeyPair>>() {}),
|
||||
load(dir, "ec2-addresses.json", new TypeReference<Map<String, Address>>() {}),
|
||||
load(dir, "ec2-instances.json", new TypeReference<Map<String, Instance>>() {}),
|
||||
load(dir, "ec2-volumes.json", new TypeReference<Map<String, Volume>>() {}),
|
||||
load(dir, "ec2-registered-images.json", new TypeReference<Map<String, Image>>() {}),
|
||||
load(dir, "ec2-snapshots.json", new TypeReference<Map<String, Snapshot>>() {}),
|
||||
load(dir, "ec2-launch-templates.json", new TypeReference<Map<String, LaunchTemplate>>() {}),
|
||||
load(dir, "ec2-vpc-endpoints.json", new TypeReference<Map<String, VpcEndpoint>>() {}),
|
||||
load(dir, "ec2-nat-gateways.json", new TypeReference<Map<String, NatGateway>>() {}),
|
||||
load(dir, "ec2-spot-instance-requests.json", new TypeReference<Map<String, SpotInstanceRequest>>() {}),
|
||||
load(dir, "ec2-network-acls.json", new TypeReference<Map<String, NetworkAcl>>() {}),
|
||||
load(dir, "ec2-tags.json", new TypeReference<Map<String, List<Tag>>>() {}));
|
||||
}
|
||||
|
||||
private <V> StorageBackend<String, V> load(Path dir, String file, TypeReference<Map<String, V>> type) {
|
||||
PersistentStorage<String, V> backend = new PersistentStorage<>(dir.resolve(file), type);
|
||||
backend.load();
|
||||
return backend;
|
||||
}
|
||||
}
|
||||
+93
@@ -0,0 +1,93 @@
|
||||
package io.github.hectorvent.floci.services.ec2;
|
||||
|
||||
import io.github.hectorvent.floci.config.EmulatorConfig;
|
||||
import io.github.hectorvent.floci.services.ec2.model.Reservation;
|
||||
import jakarta.ws.rs.core.MultivaluedHashMap;
|
||||
import jakarta.ws.rs.core.MultivaluedMap;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.mockito.ArgumentMatchers.anyInt;
|
||||
import static org.mockito.ArgumentMatchers.anyList;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.ArgumentMatchers.nullable;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
/**
|
||||
* RunInstances accepts the launch-time public-IP override in two wire shapes:
|
||||
* the primary network-interface spec (what Terraform sends) and the legacy
|
||||
* top-level parameter (what the CLI and older SDKs send). Both must reach
|
||||
* Ec2Service; absent must stay null so the subnet's MapPublicIpOnLaunch
|
||||
* default still applies.
|
||||
*/
|
||||
class Ec2RunInstancesPublicIpParamTest {
|
||||
|
||||
private static final String REGION = "us-east-1";
|
||||
|
||||
@Test
|
||||
void topLevelAssociatePublicIpAddressReachesTheService() {
|
||||
assertForwarded(params("AssociatePublicIpAddress", "true"), Boolean.TRUE);
|
||||
assertForwarded(params("AssociatePublicIpAddress", "false"), Boolean.FALSE);
|
||||
}
|
||||
|
||||
@Test
|
||||
void networkInterfaceSpecStillReachesTheService() {
|
||||
assertForwarded(params("NetworkInterface.1.AssociatePublicIpAddress", "true"), Boolean.TRUE);
|
||||
assertForwarded(params("NetworkInterface.1.AssociatePublicIpAddress", "false"), Boolean.FALSE);
|
||||
}
|
||||
|
||||
@Test
|
||||
void networkInterfaceSpecWinsWhenBothArePresent() {
|
||||
MultivaluedMap<String, String> p = params("NetworkInterface.1.AssociatePublicIpAddress", "false");
|
||||
p.putSingle("AssociatePublicIpAddress", "true");
|
||||
assertForwarded(p, Boolean.FALSE);
|
||||
}
|
||||
|
||||
@Test
|
||||
void absentStaysNullSoTheSubnetDefaultApplies() {
|
||||
assertForwarded(baseParams(), null);
|
||||
}
|
||||
|
||||
private void assertForwarded(MultivaluedMap<String, String> p, Boolean expected) {
|
||||
Ec2Service service = mock(Ec2Service.class);
|
||||
when(service.runInstances(anyString(), nullable(String.class), nullable(String.class),
|
||||
anyInt(), anyInt(), nullable(String.class), anyList(), nullable(String.class),
|
||||
nullable(String.class), anyList(), nullable(String.class), nullable(String.class),
|
||||
nullable(Boolean.class))).thenReturn(new Reservation());
|
||||
|
||||
Ec2QueryHandler handler = new Ec2QueryHandler(service, mock(EmulatorConfig.class),
|
||||
mock(FlowLogService.class));
|
||||
handler.handle("RunInstances", p, REGION);
|
||||
|
||||
ArgumentCaptor<Boolean> associatePublicIp = ArgumentCaptor.forClass(Boolean.class);
|
||||
verify(service).runInstances(anyString(), nullable(String.class), nullable(String.class),
|
||||
anyInt(), anyInt(), nullable(String.class), anyList(), nullable(String.class),
|
||||
nullable(String.class), anyList(), nullable(String.class), nullable(String.class),
|
||||
associatePublicIp.capture());
|
||||
if (expected == null) {
|
||||
assertNull(associatePublicIp.getValue(),
|
||||
"an absent override must stay null so the subnet default decides");
|
||||
} else {
|
||||
assertEquals(expected, associatePublicIp.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
private static MultivaluedMap<String, String> baseParams() {
|
||||
MultivaluedMap<String, String> p = new MultivaluedHashMap<>();
|
||||
p.putSingle("ImageId", "ami-0abcdef1234567890");
|
||||
p.putSingle("InstanceType", "t3.micro");
|
||||
p.putSingle("MinCount", "1");
|
||||
p.putSingle("MaxCount", "1");
|
||||
return p;
|
||||
}
|
||||
|
||||
private static MultivaluedMap<String, String> params(String key, String value) {
|
||||
MultivaluedMap<String, String> p = baseParams();
|
||||
p.putSingle(key, value);
|
||||
return p;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user