@Test public void removeSecurityGroupsSingleNetworkInterface () throws Exception { String chaosSecurityGroupId = "sg-ch@0$"; Map<String, Set<String>> map = Map.of("eni-123456", Set.of("sg-123456")); doReturn(map).when(awsEC2Platform).getNetworkInterfaceToSecurityGroupsMap(INSTANCE_ID); doReturn(chaosSecurityGroupId).when(awsEC2Platform).getChaosSecurityGroupForInstance(INSTANCE_ID); awsEC2Container.removeSecurityGroups(experiment); verify(awsEC2Platform, times(1)).setSecurityGroupIds("eni-123456", Set.of(chaosSecurityGroupId)); experiment.getSelfHealingMethod().run(); verify(awsEC2Platform, times(1)).setSecurityGroupIds("eni-123456", Set.of("sg-123456")); experiment.getCheckContainerHealth().call(); verify(awsEC2Platform, times(1)).verifySecurityGroupIdsOfNetworkInterfaceMap(INSTANCE_ID, map); }
@ChaosExperiment(experimentType = ExperimentType.NETWORK) public void removeSecurityGroups (Experiment experiment) { Map<String, Set<String>> originalSecurityGroups = awsEC2Platform.getNetworkInterfaceToSecurityGroupsMap(instanceId); Set<String> networkInterfaceIds = originalSecurityGroups.keySet(); Collection<String> chaosSecurityGroupId = Set.of(awsEC2Platform.getChaosSecurityGroupForInstance(instanceId)); Callable<ContainerHealth> baseMethod = () -> awsEC2Platform.verifySecurityGroupIdsOfNetworkInterfaceMap(instanceId, originalSecurityGroups) ? ContainerHealth.NORMAL : ContainerHealth.RUNNING_EXPERIMENT; experiment.setCheckContainerHealth(autoscalingHealthcheckWrapper(baseMethod)); Runnable selfHealingBaseMethod = () -> originalSecurityGroups.forEach((key, value) -> awsEC2Platform.setSecurityGroupIds(key, value)); experiment.setSelfHealingMethod(autoscalingSelfHealingWrapper(selfHealingBaseMethod)); networkInterfaceIds.forEach(networkInterfaceId -> awsEC2Platform.setSecurityGroupIds(networkInterfaceId, chaosSecurityGroupId)); }
AwsEC2Container extends AwsContainer { @ChaosExperiment(experimentType = ExperimentType.NETWORK) public void removeSecurityGroups (Experiment experiment) { Map<String, Set<String>> originalSecurityGroups = awsEC2Platform.getNetworkInterfaceToSecurityGroupsMap(instanceId); Set<String> networkInterfaceIds = originalSecurityGroups.keySet(); Collection<String> chaosSecurityGroupId = Set.of(awsEC2Platform.getChaosSecurityGroupForInstance(instanceId)); Callable<ContainerHealth> baseMethod = () -> awsEC2Platform.verifySecurityGroupIdsOfNetworkInterfaceMap(instanceId, originalSecurityGroups) ? ContainerHealth.NORMAL : ContainerHealth.RUNNING_EXPERIMENT; experiment.setCheckContainerHealth(autoscalingHealthcheckWrapper(baseMethod)); Runnable selfHealingBaseMethod = () -> originalSecurityGroups.forEach((key, value) -> awsEC2Platform.setSecurityGroupIds(key, value)); experiment.setSelfHealingMethod(autoscalingSelfHealingWrapper(selfHealingBaseMethod)); networkInterfaceIds.forEach(networkInterfaceId -> awsEC2Platform.setSecurityGroupIds(networkInterfaceId, chaosSecurityGroupId)); } }
AwsEC2Container extends AwsContainer { @ChaosExperiment(experimentType = ExperimentType.NETWORK) public void removeSecurityGroups (Experiment experiment) { Map<String, Set<String>> originalSecurityGroups = awsEC2Platform.getNetworkInterfaceToSecurityGroupsMap(instanceId); Set<String> networkInterfaceIds = originalSecurityGroups.keySet(); Collection<String> chaosSecurityGroupId = Set.of(awsEC2Platform.getChaosSecurityGroupForInstance(instanceId)); Callable<ContainerHealth> baseMethod = () -> awsEC2Platform.verifySecurityGroupIdsOfNetworkInterfaceMap(instanceId, originalSecurityGroups) ? ContainerHealth.NORMAL : ContainerHealth.RUNNING_EXPERIMENT; experiment.setCheckContainerHealth(autoscalingHealthcheckWrapper(baseMethod)); Runnable selfHealingBaseMethod = () -> originalSecurityGroups.forEach((key, value) -> awsEC2Platform.setSecurityGroupIds(key, value)); experiment.setSelfHealingMethod(autoscalingSelfHealingWrapper(selfHealingBaseMethod)); networkInterfaceIds.forEach(networkInterfaceId -> awsEC2Platform.setSecurityGroupIds(networkInterfaceId, chaosSecurityGroupId)); } private  AwsEC2Container(); }
AwsEC2Container extends AwsContainer { @ChaosExperiment(experimentType = ExperimentType.NETWORK) public void removeSecurityGroups (Experiment experiment) { Map<String, Set<String>> originalSecurityGroups = awsEC2Platform.getNetworkInterfaceToSecurityGroupsMap(instanceId); Set<String> networkInterfaceIds = originalSecurityGroups.keySet(); Collection<String> chaosSecurityGroupId = Set.of(awsEC2Platform.getChaosSecurityGroupForInstance(instanceId)); Callable<ContainerHealth> baseMethod = () -> awsEC2Platform.verifySecurityGroupIdsOfNetworkInterfaceMap(instanceId, originalSecurityGroups) ? ContainerHealth.NORMAL : ContainerHealth.RUNNING_EXPERIMENT; experiment.setCheckContainerHealth(autoscalingHealthcheckWrapper(baseMethod)); Runnable selfHealingBaseMethod = () -> originalSecurityGroups.forEach((key, value) -> awsEC2Platform.setSecurityGroupIds(key, value)); experiment.setSelfHealingMethod(autoscalingSelfHealingWrapper(selfHealingBaseMethod)); networkInterfaceIds.forEach(networkInterfaceId -> awsEC2Platform.setSecurityGroupIds(networkInterfaceId, chaosSecurityGroupId)); } private  AwsEC2Container(); static AwsEC2ContainerBuilder builder(); String getInstanceId(); String getGroupIdentifier(); String getKeyName(); String getName(); boolean isSSHCapable(); String getImageId(); @Override Platform getPlatform(); @Override boolean eligibleForExperiments(); @Override String getSimpleName(); @Override String getAggregationIdentifier(); @Override DataDogIdentifier getDataDogIdentifier(); @Override boolean isCattle(); @Override boolean supportsShellBasedExperiments(); @ChaosExperiment(experimentType = ExperimentType.STATE) void stopContainer(Experiment experiment); @ChaosExperiment(experimentType = ExperimentType.STATE) void restartContainer(Experiment experiment); @ChaosExperiment(experimentType = ExperimentType.STATE, experimentScope = ExperimentScope.CATTLE) void terminateASGContainer(Experiment experiment); @ChaosExperiment(experimentType = ExperimentType.NETWORK) void removeSecurityGroups(Experiment experiment); String getRoutableAddress(); String getPublicAddress(); }
AwsEC2Container extends AwsContainer { @ChaosExperiment(experimentType = ExperimentType.NETWORK) public void removeSecurityGroups (Experiment experiment) { Map<String, Set<String>> originalSecurityGroups = awsEC2Platform.getNetworkInterfaceToSecurityGroupsMap(instanceId); Set<String> networkInterfaceIds = originalSecurityGroups.keySet(); Collection<String> chaosSecurityGroupId = Set.of(awsEC2Platform.getChaosSecurityGroupForInstance(instanceId)); Callable<ContainerHealth> baseMethod = () -> awsEC2Platform.verifySecurityGroupIdsOfNetworkInterfaceMap(instanceId, originalSecurityGroups) ? ContainerHealth.NORMAL : ContainerHealth.RUNNING_EXPERIMENT; experiment.setCheckContainerHealth(autoscalingHealthcheckWrapper(baseMethod)); Runnable selfHealingBaseMethod = () -> originalSecurityGroups.forEach((key, value) -> awsEC2Platform.setSecurityGroupIds(key, value)); experiment.setSelfHealingMethod(autoscalingSelfHealingWrapper(selfHealingBaseMethod)); networkInterfaceIds.forEach(networkInterfaceId -> awsEC2Platform.setSecurityGroupIds(networkInterfaceId, chaosSecurityGroupId)); } private  AwsEC2Container(); static AwsEC2ContainerBuilder builder(); String getInstanceId(); String getGroupIdentifier(); String getKeyName(); String getName(); boolean isSSHCapable(); String getImageId(); @Override Platform getPlatform(); @Override boolean eligibleForExperiments(); @Override String getSimpleName(); @Override String getAggregationIdentifier(); @Override DataDogIdentifier getDataDogIdentifier(); @Override boolean isCattle(); @Override boolean supportsShellBasedExperiments(); @ChaosExperiment(experimentType = ExperimentType.STATE) void stopContainer(Experiment experiment); @ChaosExperiment(experimentType = ExperimentType.STATE) void restartContainer(Experiment experiment); @ChaosExperiment(experimentType = ExperimentType.STATE, experimentScope = ExperimentScope.CATTLE) void terminateASGContainer(Experiment experiment); @ChaosExperiment(experimentType = ExperimentType.NETWORK) void removeSecurityGroups(Experiment experiment); String getRoutableAddress(); String getPublicAddress();  }