use of com.sequenceiq.cloudbreak.cloud.model.InstanceAuthentication in project cloudbreak by hortonworks.
the class AwsMetaDataCollectorTest method collectNewOneGroup.
@Test
public void collectNewOneGroup() {
List<CloudInstance> vms = new ArrayList<>();
List<Volume> volumes = new ArrayList<>();
InstanceAuthentication instanceAuthentication = new InstanceAuthentication("sshkey", "", "cloudbreak");
vms.add(new CloudInstance(null, new InstanceTemplate("fla", "cbgateway", 5L, volumes, InstanceStatus.CREATED, null, 0L), instanceAuthentication));
when(awsClient.createCloudFormationClient(any(AwsCredentialView.class), eq("region"))).thenReturn(amazonCFClient);
when(awsClient.createAutoScalingClient(any(AwsCredentialView.class), eq("region"))).thenReturn(amazonASClient);
when(awsClient.createAccess(any(AwsCredentialView.class), eq("region"))).thenReturn(amazonEC2Client);
when(cloudFormationStackUtil.getAutoscalingGroupName(any(AuthenticatedContext.class), any(AmazonCloudFormationClient.class), eq("cbgateway"))).thenReturn("cbgateway-AAA");
List<String> gatewayIds = Collections.singletonList("i-1");
when(cloudFormationStackUtil.getInstanceIds(any(AmazonAutoScalingClient.class), eq("cbgateway-AAA"))).thenReturn(gatewayIds);
when(cloudFormationStackUtil.createDescribeInstancesRequest(eq(gatewayIds))).thenReturn(describeInstancesRequestGw);
when(amazonEC2Client.describeInstances(describeInstancesRequestGw)).thenReturn(describeInstancesResultGw);
Instance instance = Mockito.mock(Instance.class);
when(instance.getInstanceId()).thenReturn("i-1");
when(instance.getPrivateIpAddress()).thenReturn("privateIp");
when(instance.getPublicIpAddress()).thenReturn("publicIp");
List<Reservation> gatewayReservations = Collections.singletonList(getReservation(instance));
when(describeInstancesResultGw.getReservations()).thenReturn(gatewayReservations);
AuthenticatedContext ac = authenticatedContext();
List<CloudVmMetaDataStatus> statuses = awsMetadataCollector.collect(ac, null, vms);
verify(amazonEC2Client).createTags(any(CreateTagsRequest.class));
Assert.assertEquals(1, statuses.size());
Assert.assertEquals("i-1", statuses.get(0).getCloudVmInstanceStatus().getCloudInstance().getInstanceId());
Assert.assertEquals("privateIp", statuses.get(0).getMetaData().getPrivateIp());
Assert.assertEquals("publicIp", statuses.get(0).getMetaData().getPublicIp());
}
use of com.sequenceiq.cloudbreak.cloud.model.InstanceAuthentication in project cloudbreak by hortonworks.
the class AwsMetaDataCollectorTest method collectAlreadyTaggedOneGroup.
@Test
public void collectAlreadyTaggedOneGroup() {
List<CloudInstance> vms = new ArrayList<>();
List<Volume> volumes = new ArrayList<>();
InstanceAuthentication instanceAuthentication = new InstanceAuthentication("sshkey", "", "cloudbreak");
vms.add(new CloudInstance("i-1", new InstanceTemplate("fla", "cbgateway", 5L, volumes, InstanceStatus.CREATED, null, 0L), instanceAuthentication));
when(awsClient.createCloudFormationClient(any(AwsCredentialView.class), eq("region"))).thenReturn(amazonCFClient);
when(awsClient.createAutoScalingClient(any(AwsCredentialView.class), eq("region"))).thenReturn(amazonASClient);
when(awsClient.createAccess(any(AwsCredentialView.class), eq("region"))).thenReturn(amazonEC2Client);
when(cloudFormationStackUtil.getAutoscalingGroupName(any(AuthenticatedContext.class), any(AmazonCloudFormationClient.class), eq("cbgateway"))).thenReturn("cbgateway-AAA");
List<String> gatewayIds = Collections.singletonList("i-1");
when(cloudFormationStackUtil.getInstanceIds(any(AmazonAutoScalingClient.class), eq("cbgateway-AAA"))).thenReturn(gatewayIds);
when(cloudFormationStackUtil.createDescribeInstancesRequest(eq(gatewayIds))).thenReturn(describeInstancesRequestGw);
when(amazonEC2Client.describeInstances(describeInstancesRequestGw)).thenReturn(describeInstancesResultGw);
Instance instance = Mockito.mock(Instance.class);
when(instance.getInstanceId()).thenReturn("i-1");
when(instance.getPrivateIpAddress()).thenReturn("privateIp");
when(instance.getPublicIpAddress()).thenReturn("publicIp");
Tag tag = new Tag();
tag.setKey("cbname");
tag.setValue("somevalue");
when(instance.getTags()).thenReturn(Collections.singletonList(tag));
List<Reservation> gatewayReservations = Collections.singletonList(getReservation(instance));
when(describeInstancesResultGw.getReservations()).thenReturn(gatewayReservations);
AuthenticatedContext ac = authenticatedContext();
List<CloudVmMetaDataStatus> statuses = awsMetadataCollector.collect(ac, null, vms);
verify(amazonEC2Client, never()).createTags(any(CreateTagsRequest.class));
Assert.assertEquals(1, statuses.size());
Assert.assertEquals("i-1", statuses.get(0).getCloudVmInstanceStatus().getCloudInstance().getInstanceId());
Assert.assertEquals("privateIp", statuses.get(0).getMetaData().getPrivateIp());
Assert.assertEquals("publicIp", statuses.get(0).getMetaData().getPublicIp());
}
use of com.sequenceiq.cloudbreak.cloud.model.InstanceAuthentication in project cloudbreak by hortonworks.
the class AwsMetaDataCollectorTest method collectNewOldIsTagged.
@Test
public void collectNewOldIsTagged() {
List<CloudInstance> vms = new ArrayList<>();
List<Volume> volumes = new ArrayList<>();
InstanceAuthentication instanceAuthentication = new InstanceAuthentication("sshkey", "", "cloudbreak");
vms.add(new CloudInstance(null, new InstanceTemplate("fla", "cbgateway", 5L, volumes, InstanceStatus.CREATED, null, 0L), instanceAuthentication));
when(awsClient.createCloudFormationClient(any(AwsCredentialView.class), eq("region"))).thenReturn(amazonCFClient);
when(awsClient.createAutoScalingClient(any(AwsCredentialView.class), eq("region"))).thenReturn(amazonASClient);
when(awsClient.createAccess(any(AwsCredentialView.class), eq("region"))).thenReturn(amazonEC2Client);
when(cloudFormationStackUtil.getAutoscalingGroupName(any(AuthenticatedContext.class), any(AmazonCloudFormationClient.class), eq("cbgateway"))).thenReturn("cbgateway-AAA");
List<String> gatewayIds = Arrays.asList("i-1", "i-new");
when(cloudFormationStackUtil.getInstanceIds(any(AmazonAutoScalingClient.class), eq("cbgateway-AAA"))).thenReturn(gatewayIds);
when(cloudFormationStackUtil.createDescribeInstancesRequest(eq(gatewayIds))).thenReturn(describeInstancesRequestGw);
when(amazonEC2Client.describeInstances(describeInstancesRequestGw)).thenReturn(describeInstancesResultGw);
Instance instance1 = Mockito.mock(Instance.class);
when(instance1.getInstanceId()).thenReturn("i-1");
when(instance1.getPrivateIpAddress()).thenReturn("privateIp1");
when(instance1.getPublicIpAddress()).thenReturn("publicIp1");
Tag tag = new Tag();
tag.setKey("cbname");
tag.setValue("somevalue");
when(instance1.getTags()).thenReturn(Collections.singletonList(tag));
Instance instance2 = Mockito.mock(Instance.class);
when(instance2.getInstanceId()).thenReturn("i-new");
when(instance2.getPrivateIpAddress()).thenReturn("privateIp2");
when(instance2.getPublicIpAddress()).thenReturn("publicIp2");
List<Reservation> gatewayReservations = Collections.singletonList(getReservation(instance1, instance2));
when(describeInstancesResultGw.getReservations()).thenReturn(gatewayReservations);
AuthenticatedContext ac = authenticatedContext();
List<CloudVmMetaDataStatus> statuses = awsMetadataCollector.collect(ac, null, vms);
verify(amazonEC2Client, times(1)).createTags(any(CreateTagsRequest.class));
Assert.assertEquals(1, statuses.size());
Assert.assertEquals("i-new", statuses.get(0).getCloudVmInstanceStatus().getCloudInstance().getInstanceId());
Assert.assertEquals("privateIp2", statuses.get(0).getMetaData().getPrivateIp());
Assert.assertEquals("publicIp2", statuses.get(0).getMetaData().getPublicIp());
}
use of com.sequenceiq.cloudbreak.cloud.model.InstanceAuthentication in project cloudbreak by hortonworks.
the class AwsResourceConnectorTest method testFindNonOverLappingCIDRWithNon24Subnets.
@Test
public void testFindNonOverLappingCIDRWithNon24Subnets() {
InstanceAuthentication instanceAuthentication = new InstanceAuthentication("sshkey", "", "cloudbreak");
Group group1 = new Group("group1", InstanceGroupType.CORE, Collections.emptyList(), null, null, instanceAuthentication, instanceAuthentication.getLoginUserName(), instanceAuthentication.getPublicKey());
Map<String, Object> networkParameters = new HashMap<>();
networkParameters.put("vpcId", "vpc-12345678");
networkParameters.put("internetGatewayId", "igw-12345678");
Network network = new Network(new Subnet(null), networkParameters);
CloudStack cloudStack = new CloudStack(singletonList(group1), network, null, emptyMap(), emptyMap(), null, instanceAuthentication, instanceAuthentication.getLoginUserName(), instanceAuthentication.getPublicKey());
AuthenticatedContext authenticatedContext = mock(AuthenticatedContext.class);
CloudContext cloudContext = mock(CloudContext.class);
Location location = mock(Location.class);
Vpc vpc = mock(Vpc.class);
DescribeVpcsResult describeVpcsResult = mock(DescribeVpcsResult.class);
AmazonEC2Client ec2Client = mock(AmazonEC2Client.class);
com.amazonaws.services.ec2.model.Subnet subnet1 = mock(com.amazonaws.services.ec2.model.Subnet.class);
com.amazonaws.services.ec2.model.Subnet subnet2 = mock(com.amazonaws.services.ec2.model.Subnet.class);
com.amazonaws.services.ec2.model.Subnet subnet3 = mock(com.amazonaws.services.ec2.model.Subnet.class);
com.amazonaws.services.ec2.model.Subnet subnet4 = mock(com.amazonaws.services.ec2.model.Subnet.class);
DescribeSubnetsResult subnetsResult = mock(DescribeSubnetsResult.class);
when(authenticatedContext.getCloudContext()).thenReturn(cloudContext);
when(cloudContext.getLocation()).thenReturn(location);
when(cloudContext.getName()).thenReturn(new String(new byte[] { 23 }));
when(location.getRegion()).thenReturn(Region.region("eu-west-1"));
when(awsClient.createAccess(any(), any())).thenReturn(ec2Client);
when(ec2Client.describeVpcs(any())).thenReturn(describeVpcsResult);
when(describeVpcsResult.getVpcs()).thenReturn(singletonList(vpc));
when(vpc.getCidrBlock()).thenReturn("10.0.0.0/16");
when(ec2Client.describeSubnets(any())).thenReturn(subnetsResult);
when(subnetsResult.getSubnets()).thenReturn(Arrays.asList(subnet1, subnet2, subnet3, subnet4));
when(subnet1.getCidrBlock()).thenReturn("10.0.0.0/20");
when(subnet2.getCidrBlock()).thenReturn("10.0.16.0/20");
when(subnet3.getCidrBlock()).thenReturn("10.0.32.0/20");
when(subnet4.getCidrBlock()).thenReturn("10.0.48.0/24");
String cidr = underTest.findNonOverLappingCIDR(authenticatedContext, cloudStack);
Assert.assertEquals("10.0.49.0/24", cidr);
}
use of com.sequenceiq.cloudbreak.cloud.model.InstanceAuthentication in project cloudbreak by hortonworks.
the class AwsResourceConnectorTest method testFindNonOverLappingCIDRWithNon24Subnets3.
@Test
public void testFindNonOverLappingCIDRWithNon24Subnets3() {
InstanceAuthentication instanceAuthentication = new InstanceAuthentication("sshkey", "", "cloudbreak");
Group group1 = new Group("group1", InstanceGroupType.CORE, Collections.emptyList(), null, null, instanceAuthentication, instanceAuthentication.getLoginUserName(), instanceAuthentication.getPublicKey());
Map<String, Object> networkParameters = new HashMap<>();
networkParameters.put("vpcId", "vpc-12345678");
networkParameters.put("internetGatewayId", "igw-12345678");
Network network = new Network(new Subnet(null), networkParameters);
CloudStack cloudStack = new CloudStack(singletonList(group1), network, null, emptyMap(), emptyMap(), null, instanceAuthentication, instanceAuthentication.getLoginUserName(), instanceAuthentication.getPublicKey());
AuthenticatedContext authenticatedContext = mock(AuthenticatedContext.class);
CloudContext cloudContext = mock(CloudContext.class);
Location location = mock(Location.class);
Vpc vpc = mock(Vpc.class);
DescribeVpcsResult describeVpcsResult = mock(DescribeVpcsResult.class);
AmazonEC2Client ec2Client = mock(AmazonEC2Client.class);
com.amazonaws.services.ec2.model.Subnet subnet1 = mock(com.amazonaws.services.ec2.model.Subnet.class);
com.amazonaws.services.ec2.model.Subnet subnet2 = mock(com.amazonaws.services.ec2.model.Subnet.class);
com.amazonaws.services.ec2.model.Subnet subnet3 = mock(com.amazonaws.services.ec2.model.Subnet.class);
com.amazonaws.services.ec2.model.Subnet subnet4 = mock(com.amazonaws.services.ec2.model.Subnet.class);
DescribeSubnetsResult subnetsResult = mock(DescribeSubnetsResult.class);
when(authenticatedContext.getCloudContext()).thenReturn(cloudContext);
when(cloudContext.getLocation()).thenReturn(location);
when(cloudContext.getName()).thenReturn(new String(new byte[] { 15 }));
when(location.getRegion()).thenReturn(Region.region("eu-west-1"));
when(awsClient.createAccess(any(), any())).thenReturn(ec2Client);
when(ec2Client.describeVpcs(any())).thenReturn(describeVpcsResult);
when(describeVpcsResult.getVpcs()).thenReturn(singletonList(vpc));
when(vpc.getCidrBlock()).thenReturn("10.0.0.0/16");
when(ec2Client.describeSubnets(any())).thenReturn(subnetsResult);
when(subnetsResult.getSubnets()).thenReturn(Arrays.asList(subnet1, subnet2, subnet3, subnet4));
when(subnet1.getCidrBlock()).thenReturn("10.0.0.0/20");
when(subnet2.getCidrBlock()).thenReturn("10.0.16.0/20");
when(subnet3.getCidrBlock()).thenReturn("10.0.32.0/20");
when(subnet4.getCidrBlock()).thenReturn("10.0.48.0/20");
String cidr = underTest.findNonOverLappingCIDR(authenticatedContext, cloudStack);
Assert.assertEquals("10.0.64.0/24", cidr);
}
Aggregations