use of com.sequenceiq.freeipa.entity.Stack in project cloudbreak by hortonworks.
the class NetworkServiceTest method testAzureMultipleNetworkWithSameId.
@Test
public void testAzureMultipleNetworkWithSameId() {
Stack stack = new Stack();
stack.setCloudPlatform(PLATFORM);
stack.setRegion(REGION);
stack.setPlatformvariant(PLATFORM);
Credential credential = new Credential(PLATFORM, "", "", "", "acc");
ExtendedCloudCredential extendedCred = new ExtendedCloudCredential(new CloudCredential(), PLATFORM, "", "", "", new ArrayList<>());
CloudSubnet subnet1 = new CloudSubnet(SUBNET_1, SUBNET_1, "", "10.1.0.0/24");
CloudSubnet subnet2 = new CloudSubnet(SUBNET_2, SUBNET_2, "", "10.1.1.0/24");
CloudSubnet subnet3 = new CloudSubnet("indifferent", "indifferent", "", "10.1.2.0/24");
CloudNetwork cloudNetwork1 = new CloudNetwork("/rg1/" + NETWORK_ID, "/rg1/" + NETWORK_ID, Set.of(subnet1, subnet2, subnet3), Map.of());
CloudNetwork cloudNetwork2 = new CloudNetwork("/rg2/" + NETWORK_ID, "/rg2/" + NETWORK_ID, Set.of(new CloudSubnet(SUBNET_1, SUBNET_1, "", "10.2.0.0/24"), new CloudSubnet("test", "test")), Map.of());
Map<String, Set<CloudNetwork>> cloudNets = Map.of(REGION, Set.of(cloudNetwork1, cloudNetwork2));
CloudNetworks cloudNetworks = new CloudNetworks(cloudNets);
when(credentialService.getCredentialByEnvCrn(ENV_CRN)).thenReturn(credential);
when(extendedCloudCredentialConverter.convert(credential)).thenReturn(extendedCred);
when(cloudParameterService.getCloudNetworks(eq(extendedCred), eq(REGION), eq(PLATFORM), any())).thenReturn(cloudNetworks);
when(networkFilterProviderMap.get(any())).thenReturn(null);
Multimap<String, String> filteredSubnetWithCidr = underTest.getFilteredSubnetWithCidr(ENV_CRN, stack, NETWORK_ID, List.of(SUBNET_1, SUBNET_2));
assertEquals(3, filteredSubnetWithCidr.size());
assertEquals(2, filteredSubnetWithCidr.get(subnet1.getId()).size());
assertTrue(filteredSubnetWithCidr.get(subnet1.getId()).contains(subnet1.getCidr()));
assertTrue(filteredSubnetWithCidr.get(subnet1.getId()).contains("10.2.0.0/24"));
assertEquals(1, filteredSubnetWithCidr.get(subnet2.getId()).size());
assertEquals(subnet2.getCidr(), filteredSubnetWithCidr.get(subnet2.getId()).stream().findFirst().get());
}
use of com.sequenceiq.freeipa.entity.Stack in project cloudbreak by hortonworks.
the class RepairInstancesServiceTest method testRenameStackIfNeededWhenAlreadyRenamed.
@Test
public void testRenameStackIfNeededWhenAlreadyRenamed() {
Stack stack = createStack(DELETE_COMPLETED, List.of(InstanceStatus.TERMINATED, InstanceStatus.TERMINATED), 2);
Long terminationTime = 1638311233640L;
String stackName = "freeipa_" + terminationTime;
stack.setName(stackName);
stack.setTerminated(terminationTime);
underTest.renameStackIfNeeded(stack);
verify(terminationService, never()).finalizeTermination(any());
}
use of com.sequenceiq.freeipa.entity.Stack in project cloudbreak by hortonworks.
the class RepairInstancesServiceTest method testRebuild.
@Test
public void testRebuild() throws Exception {
Stack stack = createStack(Status.DELETE_COMPLETED, List.of(InstanceStatus.TERMINATED, InstanceStatus.TERMINATED), 2);
CreateFreeIpaRequest createFreeIpaRequest = new CreateFreeIpaRequest();
DescribeFreeIpaResponse response = new DescribeFreeIpaResponse();
when(stackService.getByCrnAndAccountIdEvenIfTerminated(ENVIRONMENT_ID1, ACCOUNT_ID, FREEIPA_CRN)).thenReturn(stack);
when(stackService.findByEnvironmentCrnAndAccountId(ENVIRONMENT_ID1, ACCOUNT_ID)).thenReturn(Optional.empty());
when(stackToCreateFreeIpaRequestConverter.convert(eq(stack))).thenReturn(createFreeIpaRequest);
when(freeIpaCreationService.launchFreeIpa(eq(createFreeIpaRequest), eq(ACCOUNT_ID))).thenReturn(response);
when(entitlementService.isFreeIpaRebuildEnabled(eq(ACCOUNT_ID))).thenReturn(true);
RebuildRequest rebuildRequest = new RebuildRequest();
rebuildRequest.setEnvironmentCrn(ENVIRONMENT_ID1);
rebuildRequest.setSourceCrn(FREEIPA_CRN);
assertEquals(response, underTest.rebuild(ACCOUNT_ID, rebuildRequest));
}
use of com.sequenceiq.freeipa.entity.Stack in project cloudbreak by hortonworks.
the class RepairInstancesServiceTest method testRepairInstancesWithForce.
@Test
void testRepairInstancesWithForce() {
Stack stack = createStack(Status.AVAILABLE, List.of(InstanceStatus.CREATED, InstanceStatus.CREATED));
List<String> instanceIds = List.of("i-2");
OperationStatus operationStatus = new OperationStatus();
when(stackService.getByEnvironmentCrnAndAccountIdWithListsAndMdcContext(ENVIRONMENT_ID1, ACCOUNT_ID)).thenReturn(stack);
when(operationService.startOperation(any(), any(), any(), any())).thenReturn(createOperation());
when(operationToOperationStatusConverter.convert(any())).thenReturn(operationStatus);
when(entitlementService.freeIpaHaRepairEnabled(any())).thenReturn(Boolean.TRUE);
when(stackUpdater.updateStackStatus(anyLong(), any(), any())).thenReturn(stack);
RepairInstancesRequest request = new RepairInstancesRequest();
request.setForceRepair(true);
request.setInstanceIds(instanceIds);
request.setEnvironmentCrn(ENVIRONMENT_ID1);
assertEquals(operationStatus, underTest.repairInstances(ACCOUNT_ID, request));
ArgumentCaptor acAcceptable = ArgumentCaptor.forClass(Acceptable.class);
verify(flowManager).notify(eq("REPAIR_TRIGGER_EVENT"), (Acceptable) acAcceptable.capture());
assertTrue(acAcceptable.getValue() instanceof RepairEvent);
RepairEvent repairEvent = (RepairEvent) acAcceptable.getValue();
assertEquals(instanceIds, repairEvent.getRepairInstanceIds());
verify(stackUpdater).updateStackStatus(eq(STACK_ID), eq(DetailedStackStatus.REPAIR_REQUESTED), any());
}
use of com.sequenceiq.freeipa.entity.Stack in project cloudbreak by hortonworks.
the class RepairInstancesServiceTest method testRepairAndAutodetectBadInstances.
@Test
public void testRepairAndAutodetectBadInstances() throws Exception {
Stack stack = createStack(Status.UNHEALTHY, List.of(InstanceStatus.DELETED_ON_PROVIDER_SIDE, InstanceStatus.CREATED));
OperationStatus operationStatus = new OperationStatus();
RepairInstancesRequest repairInstancesRequest = new RepairInstancesRequest();
repairInstancesRequest.setEnvironmentCrn(ENVIRONMENT_ID1);
repairInstancesRequest.setForceRepair(false);
when(stackService.getByEnvironmentCrnAndAccountIdWithListsAndMdcContext(ENVIRONMENT_ID1, ACCOUNT_ID)).thenReturn(stack);
when(healthDetailsService.getHealthDetails(ENVIRONMENT_ID1, ACCOUNT_ID)).thenReturn(createHealthDetails(InstanceStatus.DELETED_ON_PROVIDER_SIDE, InstanceStatus.CREATED));
when(entitlementService.freeIpaHaRepairEnabled(any())).thenReturn(Boolean.TRUE);
when(operationService.startOperation(any(), any(), any(), any())).thenReturn(createOperation());
when(operationToOperationStatusConverter.convert(any())).thenReturn(operationStatus);
assertEquals(operationStatus, underTest.repairInstances(ACCOUNT_ID, repairInstancesRequest));
verify(flowManager, times(1)).notify(eq(REPAIR_TRIGGER_EVENT), any());
}
Aggregations