use of com.sequenceiq.it.cloudbreak.context.TestContext in project cloudbreak by hortonworks.
the class DistroXUpgradeTests method testDistroXUpgrades.
@Test(dataProvider = TEST_CONTEXT)
@UseSpotInstances
@Description(given = "there is a running Cloudbreak, and an environment with SDX and two DistroX clusters in " + "available state, one cluster created with deafult catalog and one cluster created with production catalog", when = "upgrade called on both DistroX clusters", then = "Both DistroX upgrade should be successful," + " the clusters should be up and running")
public void testDistroXUpgrades(TestContext testContext) {
String imageSettings = resourcePropertyProvider().getName();
String currentRuntimeVersion = commonClusterManagerProperties.getUpgrade().getDistroXUpgradeCurrentVersion();
String targetRuntimeVersion = commonClusterManagerProperties.getUpgrade().getDistroXUpgradeTargetVersion();
String currentRuntimeVersion3rdParty = commonClusterManagerProperties.getUpgrade().getDistroXUpgrade3rdPartyCurrentVersion();
String targetRuntimeVersion3rdParty = commonClusterManagerProperties.getUpgrade().getDistroXUpgrade3rdPartyTargetVersion();
String sdxName = resourcePropertyProvider().getName();
String distroXName = resourcePropertyProvider().getName();
String distroX3rdPartyName = resourcePropertyProvider().getName();
String thirdPartyCatalogName = resourcePropertyProvider().getName();
AtomicReference<String> uuid = new AtomicReference<>();
SdxDatabaseRequest sdxDatabaseRequest = new SdxDatabaseRequest();
sdxDatabaseRequest.setAvailabilityType(SdxDatabaseAvailabilityType.NONE);
testContext.given(sdxName, SdxTestDto.class).withRuntimeVersion(currentRuntimeVersion).withCloudStorage(getCloudStorageRequest(testContext)).withExternalDatabase(sdxDatabaseRequest).when(sdxTestClient.create(), key(sdxName)).await(SdxClusterStatusResponse.RUNNING, key(sdxName)).awaitForHealthyInstances().validate();
testContext.given(distroXName, DistroXTestDto.class).withTemplate(String.format(commonClusterManagerProperties.getInternalDistroXBlueprintType(), currentRuntimeVersion)).withPreferredSubnetsForInstanceNetworkIfMultiAzEnabledOrJustFirst().when(distroXTestClient.create(), key(distroXName)).validate();
createImageValidationSourceCatalog(testContext, commonClusterManagerProperties.getUpgrade().getImageCatalogUrl3rdParty(), thirdPartyCatalogName);
uuid.set(getUuid(testContext, thirdPartyCatalogName, currentRuntimeVersion3rdParty));
testContext.given(imageSettings, DistroXImageTestDto.class).withImageCatalog(thirdPartyCatalogName).withImageId(uuid.get()).given(distroX3rdPartyName, DistroXTestDto.class).withTemplate(String.format(commonClusterManagerProperties.getInternalDistroXBlueprintType(), currentRuntimeVersion3rdParty)).withPreferredSubnetsForInstanceNetworkIfMultiAzEnabledOrJustFirst().withImageSettings(imageSettings).when(distroXTestClient.create(), key(distroX3rdPartyName)).await(STACK_AVAILABLE, key(distroX3rdPartyName)).awaitForHealthyInstances().then((tc, testDto, client) -> checkImageId(testDto, uuid.get())).given(distroXName, DistroXTestDto.class).await(STACK_AVAILABLE, key(distroXName)).awaitForHealthyInstances().then(new AwsAvailabilityZoneAssertion()).validate();
testContext.given(DistroXUpgradeTestDto.class).withRuntime(targetRuntimeVersion).given(distroXName, DistroXTestDto.class).when(distroXTestClient.upgrade(), key(distroXName)).given(DistroXUpgradeTestDto.class).withRuntime(targetRuntimeVersion3rdParty).given(distroX3rdPartyName, DistroXTestDto.class).when(distroXTestClient.upgrade(), key(distroX3rdPartyName)).await(STACK_AVAILABLE, key(distroX3rdPartyName)).awaitForHealthyInstances().given(distroXName, DistroXTestDto.class).await(STACK_AVAILABLE, key(distroXName)).awaitForHealthyInstances().then(new AwsAvailabilityZoneAssertion()).validate();
}
use of com.sequenceiq.it.cloudbreak.context.TestContext in project cloudbreak by hortonworks.
the class DistroXUpgradeTests method testDistroXEphemeralUpgrade.
@Test(dataProvider = TEST_CONTEXT)
@UseSpotInstances
@Description(given = "there is a running Cloudbreak, and an environment with SDX and DistroX cluster in available state", when = "upgrade called on the DistroX cluster", then = "DistroX upgrade should be successful, the cluster should be up and running")
public void testDistroXEphemeralUpgrade(TestContext testContext) {
String sdxName = resourcePropertyProvider().getName();
String distroXName = resourcePropertyProvider().getName();
String currentRuntimeVersion = commonClusterManagerProperties.getUpgrade().getDistroXUpgradeCurrentVersion();
String targetRuntimeVersion = commonClusterManagerProperties.getUpgrade().getDistroXUpgradeTargetVersion();
String username = testContext.getActingUserCrn().getResource();
String sanitizedUserName = SanitizerUtil.sanitizeWorkloadUsername(username);
testContext.given(sdxName, SdxTestDto.class).withCloudStorage().withRuntimeVersion(currentRuntimeVersion).when(sdxTestClient.create(), key(sdxName)).await(SdxClusterStatusResponse.RUNNING, key(sdxName)).awaitForHealthyInstances().validate();
testContext.given(distroXName, DistroXTestDto.class).withTemplate(String.format(commonClusterManagerProperties.getInternalDistroXBlueprintType(), currentRuntimeVersion)).withInstanceGroupsEntity(new DistroXInstanceGroupsBuilder(testContext).defaultHostGroup().withStorageOptimizedInstancetype().build()).when(distroXTestClient.create(), key(distroXName)).await(STACK_AVAILABLE).awaitForHealthyInstances().validate();
testContext.given(DistroXUpgradeTestDto.class).withRuntime(targetRuntimeVersion).given(distroXName, DistroXTestDto.class).when(distroXTestClient.upgrade(), key(distroXName)).await(STACK_AVAILABLE, key(distroXName)).awaitForHealthyInstances().then((tc, testDto, client) -> {
CloudFunctionality cloudFunctionality = tc.getCloudProvider().getCloudFunctionality();
List<InstanceGroupV4Response> instanceGroups = testDto.getResponse().getInstanceGroups();
cloudFunctionality.checkMountedDisks(instanceGroups, List.of(HostGroupType.WORKER.getName()));
return testDto;
}).then((tc, testDto, client) -> clouderaManagerUtil.checkClouderaManagerYarnNodemanagerRoleConfigGroupsDirect(testDto, sanitizedUserName, MOCK_UMS_PASSWORD)).validate();
}
use of com.sequenceiq.it.cloudbreak.context.TestContext in project cloudbreak by hortonworks.
the class DistroXImagesTests method testDistroXWithBaseImageCanBeCreatedSuccessfully.
@Test(dataProvider = TEST_CONTEXT)
@UseSpotInstances
@Description(given = "there is a running cloudbreak", when = "a valid DistroX create request is sent (latest Base Image)", then = "DistroX should be available and deletable")
public void testDistroXWithBaseImageCanBeCreatedSuccessfully(TestContext testContext) {
String imageSettings = resourcePropertyProvider().getName();
String imageCatalog = resourcePropertyProvider().getName();
String distrox = resourcePropertyProvider().getName();
AtomicReference<String> selectedImageID = new AtomicReference<>();
CloudProvider cloudProvider = testContext.getCloudProvider();
testContext.given(imageCatalog, ImageCatalogTestDto.class).when((tc, dto, client) -> {
selectedImageID.set(cloudProvider.getLatestBaseImageID(tc, dto, client));
return dto;
}).given(imageSettings, DistroXImageTestDto.class).withImageCatalog(cloudProvider.getImageCatalogName()).withImageId(selectedImageID.get()).given(distrox, DistroXTestDto.class).withImageSettings(imageSettings).when(distroXTestClient.create(), key(distrox)).await(STACK_AVAILABLE).awaitForHealthyInstances().then((tc, dto, client) -> {
Log.log(LOGGER, format(" Image Catalog Name: %s ", dto.getResponse().getImage().getCatalogName()));
Log.log(LOGGER, format(" Image Catalog URL: %s ", dto.getResponse().getImage().getCatalogUrl()));
Log.log(LOGGER, format(" Image ID: %s ", dto.getResponse().getImage().getId()));
if (!dto.getResponse().getImage().getId().equals(selectedImageID.get())) {
throw new TestFailException(" The selected image ID is: " + dto.getResponse().getImage().getId() + " instead of: " + selectedImageID.get());
}
return dto;
}).validate();
}
use of com.sequenceiq.it.cloudbreak.context.TestContext in project cloudbreak by hortonworks.
the class ReportListener method logUrl.
private void logUrl(ITestResult tr) {
TestContext testContext;
Object[] parameters = tr.getParameters();
if (parameters == null || parameters.length == 0) {
return;
}
try {
testContext = (TestContext) parameters[0];
} catch (ClassCastException e) {
return;
}
Iterable<Searchable> searchables = Iterables.filter(testContext.getResourceNames().values(), Searchable.class);
List<Searchable> listOfSearchables = StreamSupport.stream(searchables.spliterator(), false).collect(Collectors.toList());
if (listOfSearchables.size() == 0) {
return;
}
SearchUrl searchUrl = new KibanaSearchUrl();
tr.getTestContext().setAttribute(tr.getName() + SEARCH_URL, searchUrl.getSearchUrl(listOfSearchables, new Date(tr.getStartMillis()), new Date(tr.getEndMillis())));
String baseLocation = getCloudStorageBaseLocation(testContext);
CloudProviderProxy cloudProvider = testContext.getCloudProvider();
generateClusterLogsUrl(FreeIpaTestDto.class, tr, testContext.getResourceNames(), testContext.getResourceCrns(), baseLocation, cloudProvider);
generateClusterLogsUrl(SdxTestDto.class, tr, testContext.getResourceNames(), testContext.getResourceCrns(), baseLocation, cloudProvider);
generateClusterLogsUrl(SdxInternalTestDto.class, tr, testContext.getResourceNames(), testContext.getResourceCrns(), baseLocation, cloudProvider);
generateClusterLogsUrl(DistroXTestDto.class, tr, testContext.getResourceNames(), testContext.getResourceCrns(), baseLocation, cloudProvider);
}
use of com.sequenceiq.it.cloudbreak.context.TestContext in project cloudbreak by hortonworks.
the class TestInvocationListener method afterInvocation.
/**
* Collects all the available test resources to a JSON file based on the:
* - Related test DTO: provides a resource name type (eg.: environmentName),
* - Test Context: provides the resource's unique name (eg.: aws-test-039df4d8aec04a61965).
*
* Resource files can be saved based on the test cases (eg.: resource_names_testCreateNewEnvironmentWithNewNetworkAndNoInternet);
* because of each test has it's own Test Context, that has been built by the Given test steps for that thread of test execution.
*/
@Override
public void afterInvocation(IInvokedMethod invokedMethod, ITestResult testResult) {
TestContext testContext;
JSONObject jsonObject = new JSONObject();
Object[] parameters = testResult.getParameters();
if (parameters == null || parameters.length == 0) {
LOGGER.warn("Test context could not be found because parameters array is empty in test result.");
return;
}
try {
testContext = (TestContext) parameters[0];
} catch (ClassCastException e) {
LOGGER.warn("Test context could not be casted from test result parameters.");
return;
}
List<CloudbreakTestDto> testDtos = new ArrayList<>(testContext.getResourceNames().values());
List<CloudbreakTestDto> orderedTestDtos = testDtos.stream().sorted(new CompareByOrder()).collect(Collectors.toList());
for (CloudbreakTestDto testDto : orderedTestDtos) {
try {
String resourceNameType = Optional.ofNullable(testDto.getResourceNameType()).orElse("");
if (!resourceNameType.trim().isEmpty()) {
if (jsonObject.has(resourceNameType)) {
List<String> resourceNames = new ArrayList<>();
try {
JSONArray resources = jsonObject.getJSONArray(resourceNameType);
for (int i = 0; i < resources.length(); i++) {
String resource = resources.getString(i);
resourceNames.add(resource);
}
} catch (JSONException e) {
String resource = jsonObject.getString(resourceNameType);
resourceNames.add(resource);
}
resourceNames.add(testDto.getName());
LOGGER.info("Created resource name array: '{}'.", resourceNames);
JSONArray resourceNameArray = new JSONArray(resourceNames);
jsonObject.put(resourceNameType, resourceNameArray);
} else {
jsonObject.put(resourceNameType, testDto.getName());
}
LOGGER.info("Put Resource Name: '{}' to JSON Object.", testDto.getName());
}
} catch (Exception e) {
LOGGER.info("Appending JSON object is failing, because of: {}", e.getMessage(), e);
}
}
if (jsonObject.length() != 0) {
String fileName = "resource_names_" + testContext.getTestMethodName().orElseGet(this::getDefaultFileNameTag) + ".json";
try {
Files.writeString(Paths.get(fileName), jsonObject.toString());
LOGGER.info("Resource file have been created with name: {} and content: {}.", fileName, jsonObject);
} catch (IOException e) {
LOGGER.info("Creating/Appending resource file throws exception: {}", e.getMessage(), e);
} catch (Exception e) {
LOGGER.info("Creating/Appending resource file is failing, because of: {}", e.getMessage(), e);
}
} else {
LOGGER.info("No resources found, no output file needs to be created.");
}
}
Aggregations