use of org.jboss.as.patching.tool.PatchingResult in project wildfly-core by wildfly.
the class MergingPatchContentTestCase method testMain.
/**
* This test creates three consequent CPs and applies them one by one first.
* Then creates a merged CP.
* Then rollsback one by one applying the merged CP and verifying the latest CP
* has been applied.
* This also tests the "undo", i.e. a rollback as one step, of the merged CP.
*/
@Test
public void testMain() throws Exception {
final InstalledIdentity installedIdentity = loadInstalledIdentity();
PatchingResult result;
assertNotPatched();
prepareCP1(installedIdentity);
result = executePatch(tool, cp1Zip);
assertCP1State(result);
prepareCP2(installedIdentity);
result = executePatch(tool, cp2Zip);
assertCP2State(result);
prepareCP3(installedIdentity);
result = executePatch(tool, cp3Zip);
assertCP3State(result);
// ls(installedIdentity.getInstalledImage().getJbossHome());
mergedZip = new File(tempDir, "merged-patch.zip");
PatchMerger.merge(cp1Zip, cp2Zip, mergedZip);
PatchMerger.merge(mergedZip, cp3Zip, mergedZip);
// File mergedDir = mkdir(tempDir, "merged2");
// ZipUtils.unzip(mergedZip, mergedDir);
// ls(mergedDir);
// less(new File(mergedDir, "patch.xml"));
result = rollback(tool, cp3.getPatchId());
assertCP2State(result);
result = executePatch(tool, mergedZip);
assertCP3State(result);
result = rollback(tool, cp3.getPatchId());
assertCP2State(result);
result = rollback(tool, cp2.getPatchId());
assertCP1State(result);
result = executePatch(tool, mergedZip);
assertCP3State(result);
result = rollback(tool, cp3.getPatchId());
assertCP1State(result);
result = rollback(tool, cp1.getPatchId());
assertNotPatched();
result = executePatch(tool, mergedZip);
assertCP3State(result);
result = rollback(tool, cp3.getPatchId());
assertNotPatched();
}
use of org.jboss.as.patching.tool.PatchingResult in project wildfly-core by wildfly.
the class PatchBundleUnitTestCase method testMultiInstall.
@Test
public void testMultiInstall() throws Exception {
final PatchingTestBuilder builder = createDefaultBuilder("layer-2", "layer-1", "base");
final byte[] moduleHashOne = new byte[20];
final byte[] moduleHashTwo = new byte[20];
final byte[] moduleHashThree = new byte[20];
final byte[] moduleHashFour = new byte[20];
final byte[] moduleHashFive = new byte[20];
final byte[] moduleHashSix = new byte[20];
final PatchingTestStepBuilder cp1 = builder.createStepBuilder();
cp1.setPatchId("CP1").upgradeIdentity(PRODUCT_VERSION, PRODUCT_VERSION).upgradeElement("base-CP1", "base", false).addModuleWithRandomContent("org.jboss.test", moduleHashOne);
final PatchingTestStepBuilder cp2 = builder.createStepBuilder();
cp2.setPatchId("CP2").upgradeIdentity(PRODUCT_VERSION, PRODUCT_VERSION).upgradeElement("layer-1-CP1", "layer-1", false).addModuleWithRandomContent("org.jboss.test.two", moduleHashTwo);
final PatchingTestStepBuilder cp3 = builder.createStepBuilder();
cp3.setPatchId("CP3").upgradeIdentity(PRODUCT_VERSION, PRODUCT_VERSION).upgradeElement("layer-2-CP1", "layer-2", false).removeModule("org.jboss.test.three", "main", moduleHashThree);
final PatchingTestStepBuilder cp4 = builder.createStepBuilder();
cp4.setPatchId("CP4").upgradeIdentity(PRODUCT_VERSION, PRODUCT_VERSION).upgradeElement("base-CP2", "base", false).addModuleWithRandomContent("org.jboss.test.four", moduleHashFour);
final PatchingTestStepBuilder cp5 = builder.createStepBuilder();
cp5.setPatchId("CP5").upgradeIdentity(PRODUCT_VERSION, PRODUCT_VERSION).upgradeElement("base-CP3", "base", false).updateModuleWithRandomContent("org.jboss.test.four", moduleHashFour, null).getParent().upgradeElement("layer-1-CP2", "layer-1", false).addModuleWithRandomContent("org.jboss.test.five", moduleHashFive).getParent().upgradeElement("layer-2-CP2", "layer-2", false).addModuleWithRandomContent("org.jboss.test.six", moduleHashSix);
final File multiPatch = prepare(builder.getRoot(), cp1, cp2, cp3, cp4, cp5);
// Create the patch tool and apply the patch
// Get installation manager instance for the unit test
InstallationManager mgr = updateInstallationManager();
final PatchTool patchTool = PatchTool.Factory.create(mgr);
final PatchingResult result = patchTool.applyPatch(multiPatch, ContentVerificationPolicy.STRICT);
result.commit();
try {
PatchStepAssertions.APPLY.after(builder.getFile(JBOSS_INSTALLATION), cp5.build(), mgr);
} catch (IOException e) {
throw new PatchingException(e);
}
mgr = loadInstallationManager();
final InstalledIdentity installedIdentity = mgr.getDefaultIdentity();
Assert.assertEquals(Arrays.asList(new String[] { "CP1", "CP2", "CP3", "CP4", "CP5" }), installedIdentity.getAllInstalledPatches());
PatchStepAssertions.assertModule("base-CP3", installedIdentity.getLayer("base"), "org.jboss.test", "main");
PatchStepAssertions.assertModule("base-CP3", installedIdentity.getLayer("base"), "org.jboss.test.four", "main");
PatchStepAssertions.assertModule("layer-1-CP2", installedIdentity.getLayer("layer-1"), "org.jboss.test.two", "main");
PatchStepAssertions.assertModule("layer-1-CP2", installedIdentity.getLayer("layer-1"), "org.jboss.test.five", "main");
PatchStepAssertions.assertModule("layer-2-CP2", installedIdentity.getLayer("layer-2"), "org.jboss.test.three", "main");
PatchStepAssertions.assertModule("layer-2-CP2", installedIdentity.getLayer("layer-2"), "org.jboss.test.six", "main");
rollback(cp5);
mgr = loadInstallationManager();
PatchStepAssertions.assertModule("base-CP2", installedIdentity.getLayer("base"), "org.jboss.test", "main");
PatchStepAssertions.assertModule("base-CP2", installedIdentity.getLayer("base"), "org.jboss.test.four", "main");
rollback(cp4);
rollback(cp3);
rollback(cp2);
rollback(cp1);
}
use of org.jboss.as.patching.tool.PatchingResult in project wildfly-core by wildfly.
the class ModuleTaskTestCase method testRemoveModule.
@Test
public void testRemoveModule() throws Exception {
String moduleName = randomString();
// create an empty module in the AS7 installation
File baseModuleDir = newFile(env.getInstalledImage().getModulesDir(), SYSTEM, LAYERS, BASE);
File moduleDir = createModule0(baseModuleDir, moduleName);
// build a one-off patch for the installation base layer
// with 1 module removed
String baseLayerPatchID = randomString();
Patch patch = PatchBuilder.create().setPatchId(randomString()).setDescription(randomString()).oneOffPatchIdentity(productConfig.getProductName(), productConfig.getProductVersion()).getParent().oneOffPatchElement(baseLayerPatchID, BASE, false).addContentModification(ContentModificationUtils.removeModule(moduleDir)).getParent().build();
// create the patch
File patchDir = mkdir(tempDir, patch.getPatchId());
createPatchXMLFile(patchDir, patch);
File zippedPatch = createZippedPatchFile(patchDir, patch.getPatchId());
PatchingResult result = executePatch(zippedPatch);
assertPatchHasBeenApplied(result, patch);
InstalledIdentity installedIdentity = loadInstalledIdentity();
File modulesPatchDir = installedIdentity.getLayers().get(0).loadTargetInfo().getDirectoryStructure().getModulePatchDirectory(baseLayerPatchID);
assertDirExists(modulesPatchDir);
assertDefinedAbsentModule(modulesPatchDir, moduleName);
}
use of org.jboss.as.patching.tool.PatchingResult in project wildfly-core by wildfly.
the class OneOffPatchTestCase method testApplyOneOffPatchAndRollback.
@Test
public void testApplyOneOffPatchAndRollback() throws Exception {
// create an existing file in the AS7 installation
File binDir = mkdir(env.getInstalledImage().getJbossHome(), "bin");
String fileName = "standalone.sh";
File standaloneShellFile = touch(binDir, fileName);
dump(standaloneShellFile, "original script to run standalone AS7");
byte[] existingHash = hashFile(standaloneShellFile);
// build a one-off patch for the base installation
// with 1 added module
// and 1 updated file
String patchID = randomString();
String layerPatchID = randomString();
File patchDir = mkdir(tempDir, patchID);
String moduleName = randomString();
ContentModification moduleAdded = ContentModificationUtils.addModule(patchDir, layerPatchID, moduleName);
ContentModification fileUpdated = ContentModificationUtils.modifyMisc(patchDir, patchID, "updated script", standaloneShellFile, "bin", "standalone.sh");
Identity identityBeforePatch = loadInstalledIdentity().getIdentity();
Patch patch = PatchBuilder.create().setPatchId(patchID).setDescription(randomString()).oneOffPatchIdentity(productConfig.getProductName(), productConfig.getProductVersion()).getParent().oneOffPatchElement(layerPatchID, BASE, false).addContentModification(moduleAdded).getParent().addContentModification(fileUpdated).build();
createPatchXMLFile(patchDir, patch);
File zippedPatch = createZippedPatchFile(patchDir, patchID);
PatchingResult result = executePatch(zippedPatch);
assertPatchHasBeenApplied(result, patch);
assertFileExists(standaloneShellFile);
assertFileContent(fileUpdated.getItem().getContentHash(), standaloneShellFile);
InstalledIdentity updatedInstalledIdentity = loadInstalledIdentity();
File modulePatchDirectory = updatedInstalledIdentity.getLayers().get(0).loadTargetInfo().getDirectoryStructure().getModulePatchDirectory(layerPatchID);
assertDirExists(modulePatchDirectory);
assertDefinedModule(modulePatchDirectory, moduleName, moduleAdded.getItem().getContentHash());
// rollback the patch based on the updated PatchInfo
PatchingResult rollbackResult = rollback(patchID);
assertPatchHasBeenRolledBack(rollbackResult, identityBeforePatch);
assertFileExists(standaloneShellFile);
assertFileContent(existingHash, standaloneShellFile);
}
use of org.jboss.as.patching.tool.PatchingResult in project wildfly-core by wildfly.
the class OneOffPatchTestCase method apply2OneOffPatchesAndRollbackTheFirstOne.
@Test
public void apply2OneOffPatchesAndRollbackTheFirstOne() throws Exception {
// create two files in the AS7 installation
File binDir = mkdir(env.getInstalledImage().getJbossHome(), "bin");
String standaloneFileName = "standalone.sh";
File standaloneShellFile = touch(binDir, standaloneFileName);
dump(standaloneShellFile, "original script to run standalone AS7");
byte[] existingHashForStandaloneShell = hashFile(standaloneShellFile);
String domainFileName = "domain.sh";
File domainShellFile = touch(binDir, domainFileName);
dump(domainShellFile, "original script to run domain AS7");
byte[] existingHashForDomainShell = hashFile(domainShellFile);
// build a one-off patch for the base installation
// with 1 added module
// and 1 updated file
String patchID = "patch-1-" + randomString();
String layerPatchID = randomString();
File patchDir = mkdir(tempDir, patchID);
String moduleName = randomString();
ContentModification moduleAdded = ContentModificationUtils.addModule(patchDir, layerPatchID, moduleName);
ContentModification fileUpdated = ContentModificationUtils.modifyMisc(patchDir, patchID, "updated script", standaloneShellFile, "bin", "standalone.sh");
Identity identityBeforePatch = loadInstalledIdentity().getIdentity();
Patch patch = PatchBuilder.create().setPatchId(patchID).setDescription(randomString()).oneOffPatchIdentity(productConfig.getProductName(), productConfig.getProductVersion()).getParent().oneOffPatchElement(layerPatchID, BASE, false).addContentModification(moduleAdded).getParent().addContentModification(fileUpdated).build();
createPatchXMLFile(patchDir, patch);
File zippedPatch = createZippedPatchFile(patchDir, patchID);
PatchingResult result = executePatch(zippedPatch);
assertPatchHasBeenApplied(result, patch);
assertFileExists(standaloneShellFile);
assertFileContent(fileUpdated.getItem().getContentHash(), standaloneShellFile);
InstalledIdentity updatedInstalledIdentity = loadInstalledIdentity();
File modulePatchDirectory = updatedInstalledIdentity.getLayers().get(0).loadTargetInfo().getDirectoryStructure().getModulePatchDirectory(layerPatchID);
assertDirExists(modulePatchDirectory);
assertDefinedModule(modulePatchDirectory, moduleName, moduleAdded.getItem().getContentHash());
// build a 2nd one-off patch for the base installation
// with 1 updated file
String patchID_2 = "patch-2-" + randomString();
File patchDir_2 = mkdir(tempDir, patchID_2);
ContentModification otherFileUpdated = ContentModificationUtils.modifyMisc(patchDir_2, patchID_2, "updated domain script", domainShellFile, "bin", "domain.sh");
Patch patch_2 = PatchBuilder.create().setPatchId(patchID_2).setDescription(randomString()).oneOffPatchIdentity(productConfig.getProductName(), productConfig.getProductVersion()).getParent().addContentModification(otherFileUpdated).build();
createPatchXMLFile(patchDir_2, patch_2);
File zippedPatch_2 = createZippedPatchFile(patchDir_2, patchID_2);
PatchingResult result_2 = executePatch(zippedPatch_2);
assertPatchHasBeenApplied(result_2, patch_2);
assertFileExists(domainShellFile);
assertFileContent(otherFileUpdated.getItem().getContentHash(), domainShellFile);
// rollback the *first* patch based on the updated PatchInfo
PatchingResult rollbackResult = rollback(patchID, true);
// both patches must be rolled back
assertFileExists(standaloneShellFile);
assertFileContent(existingHashForStandaloneShell, standaloneShellFile);
assertFileExists(domainShellFile);
assertFileContent(existingHashForDomainShell, domainShellFile);
}
Aggregations