Search in sources :

Example 1 with PatchingResult

use of org.jboss.as.patching.tool.PatchingResult in project wildfly-core by wildfly.

the class PatchBundleUnitTestCase method testSkipInstalled.

@Test
public void testSkipInstalled() 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 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);
    apply(cp1);
    apply(cp2);
    // Prepare multi patch
    final File multiPatch = prepare(builder.getRoot(), cp1, cp2, cp3);
    // 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), cp3.build(), mgr);
    } catch (IOException e) {
        throw new PatchingException(e);
    }
}
Also used : PatchingException(org.jboss.as.patching.PatchingException) InstallationManager(org.jboss.as.patching.installation.InstallationManager) PatchingResult(org.jboss.as.patching.tool.PatchingResult) PatchTool(org.jboss.as.patching.tool.PatchTool) IOException(java.io.IOException) File(java.io.File) Test(org.junit.Test)

Example 2 with PatchingResult

use of org.jboss.as.patching.tool.PatchingResult in project wildfly-core by wildfly.

the class PatchBundleUnitTestCase method testRevert.

@Test
public void testRevert() 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
    InstallationManager mgr = loadInstallationManager();
    final PatchTool patchTool = PatchTool.Factory.create(mgr);
    final PatchingResult result = patchTool.applyPatch(multiPatch, ContentVerificationPolicy.STRICT);
    result.rollback();
    mgr = loadInstallationManager();
    checkNotApplied(builder.getRoot(), mgr, cp1, cp2, cp3, cp4, cp5);
}
Also used : InstallationManager(org.jboss.as.patching.installation.InstallationManager) PatchingResult(org.jboss.as.patching.tool.PatchingResult) PatchTool(org.jboss.as.patching.tool.PatchTool) File(java.io.File) Test(org.junit.Test)

Example 3 with PatchingResult

use of org.jboss.as.patching.tool.PatchingResult in project wildfly-core by wildfly.

the class CumulativePatchTestCase method testApplyReleasePatch.

@Test
public void testApplyReleasePatch() throws Exception {
    // build a Release patch for the base installation
    // with 1 added module
    String patchID = randomString();
    String layerPatchID = randomString();
    File patchDir = mkdir(tempDir, patchID);
    String moduleName = randomString();
    ContentModification moduleAdded = ContentModificationUtils.addModule(patchDir, layerPatchID, moduleName);
    InstalledIdentity installedIdentity = loadInstalledIdentity();
    Patch patch = PatchBuilder.create().setPatchId(patchID).setDescription(randomString()).upgradeIdentity(installedIdentity.getIdentity().getName(), installedIdentity.getIdentity().getVersion(), productConfig.getProductVersion() + "-Release1").getParent().upgradeElement(layerPatchID, BASE, false).addContentModification(moduleAdded).getParent().build();
    createPatchXMLFile(patchDir, patch);
    File zippedPatch = createZippedPatchFile(patchDir, patchID);
    PatchingResult result = executePatch(zippedPatch);
    assertPatchHasBeenApplied(result, patch);
    InstalledIdentity updatedInstalledIdentity = loadInstalledIdentity();
    File modulePatchDirectory = updatedInstalledIdentity.getLayers().get(0).loadTargetInfo().getDirectoryStructure().getModulePatchDirectory(layerPatchID);
    assertDirExists(modulePatchDirectory);
    assertDefinedModule(modulePatchDirectory, moduleName, moduleAdded.getItem().getContentHash());
}
Also used : InstalledIdentity(org.jboss.as.patching.installation.InstalledIdentity) PatchingResult(org.jboss.as.patching.tool.PatchingResult) TestUtils.randomString(org.jboss.as.patching.runner.TestUtils.randomString) IoUtils.newFile(org.jboss.as.patching.IoUtils.newFile) TestUtils.createPatchXMLFile(org.jboss.as.patching.runner.TestUtils.createPatchXMLFile) HashUtils.hashFile(org.jboss.as.patching.HashUtils.hashFile) File(java.io.File) TestUtils.createZippedPatchFile(org.jboss.as.patching.runner.TestUtils.createZippedPatchFile) ContentModification(org.jboss.as.patching.metadata.ContentModification) Patch(org.jboss.as.patching.metadata.Patch) Test(org.junit.Test)

Example 4 with PatchingResult

use of org.jboss.as.patching.tool.PatchingResult in project wildfly-core by wildfly.

the class CumulativePatchTestCase method testApplyReleasePatchAndRollback.

@Test
public void testApplyReleasePatchAndRollback() throws Exception {
    // start from a base installation
    // 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 Release 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 fileModified = ContentModificationUtils.modifyMisc(patchDir, patchID, "updated script", standaloneShellFile, "bin", "standalone.sh");
    InstalledIdentity installedIdentity = loadInstalledIdentity();
    Patch patch = PatchBuilder.create().setPatchId(patchID).setDescription(randomString()).upgradeIdentity(installedIdentity.getIdentity().getName(), installedIdentity.getIdentity().getVersion(), productConfig.getProductVersion() + "-Release1").getParent().upgradeElement(layerPatchID, BASE, false).addContentModification(moduleAdded).getParent().addContentModification(fileModified).build();
    createPatchXMLFile(patchDir, patch);
    File zippedPatch = createZippedPatchFile(patchDir, patchID);
    Identity identityBeforePatch = loadInstalledIdentity().getIdentity();
    PatchingResult result = executePatch(zippedPatch);
    assertPatchHasBeenApplied(result, patch);
    assertFileExists(standaloneShellFile);
    assertFileContent(fileModified.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);
    tree(env.getInstalledImage().getJbossHome());
    assertPatchHasBeenRolledBack(rollbackResult, identityBeforePatch);
    assertFileExists(standaloneShellFile);
    assertFileContent(existingHash, standaloneShellFile);
}
Also used : InstalledIdentity(org.jboss.as.patching.installation.InstalledIdentity) PatchingResult(org.jboss.as.patching.tool.PatchingResult) TestUtils.randomString(org.jboss.as.patching.runner.TestUtils.randomString) Identity(org.jboss.as.patching.installation.Identity) InstalledIdentity(org.jboss.as.patching.installation.InstalledIdentity) IoUtils.newFile(org.jboss.as.patching.IoUtils.newFile) TestUtils.createPatchXMLFile(org.jboss.as.patching.runner.TestUtils.createPatchXMLFile) HashUtils.hashFile(org.jboss.as.patching.HashUtils.hashFile) File(java.io.File) TestUtils.createZippedPatchFile(org.jboss.as.patching.runner.TestUtils.createZippedPatchFile) ContentModification(org.jboss.as.patching.metadata.ContentModification) Patch(org.jboss.as.patching.metadata.Patch) Test(org.junit.Test)

Example 5 with PatchingResult

use of org.jboss.as.patching.tool.PatchingResult in project wildfly-core by wildfly.

the class CumulativePatchTestCase method testApplyReleasePatchThenOneOffPatchThenRollbackReleasePatch.

@Test
public void testApplyReleasePatchThenOneOffPatchThenRollbackReleasePatch() throws Exception {
    // build a Release patch for the base installation
    // with 1 added module
    String releasePatchID = randomString();
    String releaseLayerPatchID = randomString();
    File releasePatchDir = mkdir(tempDir, releasePatchID);
    String moduleName = randomString();
    ContentModification moduleAdded = ContentModificationUtils.addModule(releasePatchDir, releaseLayerPatchID, moduleName);
    InstalledIdentity identityBeforePatch = loadInstalledIdentity();
    final String resultingVersion = identityBeforePatch.getIdentity().getVersion() + "-Release1";
    Patch releasePatch = PatchBuilder.create().setPatchId(releasePatchID).setDescription(randomString()).upgradeIdentity(identityBeforePatch.getIdentity().getName(), identityBeforePatch.getIdentity().getVersion(), resultingVersion).getParent().upgradeElement(releaseLayerPatchID, BASE, false).addContentModification(moduleAdded).getParent().build();
    createPatchXMLFile(releasePatchDir, releasePatch);
    File zippedReleasePatch = createZippedPatchFile(releasePatchDir, releasePatchID);
    PatchingResult resultOfReleasePatch = executePatch(zippedReleasePatch);
    assertPatchHasBeenApplied(resultOfReleasePatch, releasePatch);
    // FIXME when is the product version persisted when the release is applied?
    productConfig = new ProductConfig(productConfig.getProductName(), productConfig.getProductVersion() + "-Release1", productConfig.getConsoleSlot());
    InstalledIdentity updatedInstalledIdentity = loadInstalledIdentity();
    File modulePatchDirectory = updatedInstalledIdentity.getLayers().get(0).loadTargetInfo().getDirectoryStructure().getModulePatchDirectory(releaseLayerPatchID);
    assertDirExists(modulePatchDirectory);
    assertDefinedModule(modulePatchDirectory, moduleName, moduleAdded.getItem().getContentHash());
    // apply a one-off patch now
    String oneOffPatchID = randomString();
    String oneOffLayerPatchID = randomString();
    File oneOffPatchDir = mkdir(tempDir, oneOffPatchID);
    ContentModification moduleModified = ContentModificationUtils.modifyModule(oneOffPatchDir, oneOffLayerPatchID, newFile(modulePatchDirectory, moduleName), "new resource in the module");
    Patch oneOffPatch = PatchBuilder.create().setPatchId(oneOffPatchID).setDescription(randomString()).oneOffPatchIdentity(productConfig.getProductName(), resultingVersion).getParent().oneOffPatchElement(oneOffLayerPatchID, BASE, false).addContentModification(moduleModified).getParent().build();
    createPatchXMLFile(oneOffPatchDir, oneOffPatch);
    File zippedOneOffPatch = createZippedPatchFile(oneOffPatchDir, oneOffPatchID);
    PatchingResult resultOfOneOffPatch = executePatch(zippedOneOffPatch);
    assertPatchHasBeenApplied(resultOfOneOffPatch, oneOffPatch);
    InstalledIdentity installedIdentityAfterOneOffPatch = loadInstalledIdentity();
    modulePatchDirectory = installedIdentityAfterOneOffPatch.getLayers().get(0).loadTargetInfo().getDirectoryStructure().getModulePatchDirectory(oneOffLayerPatchID);
    assertDirExists(modulePatchDirectory);
    assertDefinedModule(modulePatchDirectory, moduleName, moduleModified.getItem().getContentHash());
    // rollback the release patch, this should also rollback the one-off patch
    PatchingResult resultOfReleasePatchRollback = rollback(releasePatchID);
    tree(env.getInstalledImage().getJbossHome());
    assertPatchHasBeenRolledBack(resultOfReleasePatchRollback, identityBeforePatch.getIdentity());
    updatedInstalledIdentity = loadInstalledIdentity();
    File layerModuleRoot = updatedInstalledIdentity.getLayers().get(0).loadTargetInfo().getDirectoryStructure().getModuleRoot();
    assertDirDoesNotExist(newFile(layerModuleRoot, moduleName));
}
Also used : InstalledIdentity(org.jboss.as.patching.installation.InstalledIdentity) PatchingResult(org.jboss.as.patching.tool.PatchingResult) ProductConfig(org.jboss.as.version.ProductConfig) TestUtils.randomString(org.jboss.as.patching.runner.TestUtils.randomString) IoUtils.newFile(org.jboss.as.patching.IoUtils.newFile) TestUtils.createPatchXMLFile(org.jboss.as.patching.runner.TestUtils.createPatchXMLFile) HashUtils.hashFile(org.jboss.as.patching.HashUtils.hashFile) File(java.io.File) TestUtils.createZippedPatchFile(org.jboss.as.patching.runner.TestUtils.createZippedPatchFile) ContentModification(org.jboss.as.patching.metadata.ContentModification) Patch(org.jboss.as.patching.metadata.Patch) Test(org.junit.Test)

Aggregations

PatchingResult (org.jboss.as.patching.tool.PatchingResult)37 File (java.io.File)31 Test (org.junit.Test)27 TestUtils.createPatchXMLFile (org.jboss.as.patching.runner.TestUtils.createPatchXMLFile)25 TestUtils.createZippedPatchFile (org.jboss.as.patching.runner.TestUtils.createZippedPatchFile)25 Patch (org.jboss.as.patching.metadata.Patch)24 TestUtils.randomString (org.jboss.as.patching.runner.TestUtils.randomString)23 ContentModification (org.jboss.as.patching.metadata.ContentModification)20 InstalledIdentity (org.jboss.as.patching.installation.InstalledIdentity)17 IoUtils.newFile (org.jboss.as.patching.IoUtils.newFile)13 HashUtils.hashFile (org.jboss.as.patching.HashUtils.hashFile)12 PatchingException (org.jboss.as.patching.PatchingException)9 PatchTool (org.jboss.as.patching.tool.PatchTool)8 IOException (java.io.IOException)5 DirectoryStructure (org.jboss.as.patching.DirectoryStructure)5 Identity (org.jboss.as.patching.installation.Identity)5 InstallationManager (org.jboss.as.patching.installation.InstallationManager)4 OperationContext (org.jboss.as.controller.OperationContext)3 ContentVerificationPolicy (org.jboss.as.patching.tool.ContentVerificationPolicy)3 ModelNode (org.jboss.dmr.ModelNode)3