Search in sources :

Example 11 with Patch

use of org.jboss.as.patching.metadata.Patch in project wildfly-core by wildfly.

the class FileTaskTestCase method testRemoveFile.

@Test
public void testRemoveFile() throws Exception {
    // start from a base installation
    // with a file in it
    String fileName = "standalone.sh";
    File standaloneShellFile = touch(env.getInstalledImage().getJbossHome(), "bin", fileName);
    dump(standaloneShellFile, "original script to run standalone AS7");
    // build a one-off patch for the base installation
    // with 1 removed file
    ContentModification fileRemoved = ContentModificationUtils.removeMisc(standaloneShellFile, "bin", fileName);
    Patch patch = PatchBuilder.create().setPatchId(randomString()).setDescription(randomString()).oneOffPatchIdentity(productConfig.getProductName(), productConfig.getProductVersion()).getParent().addContentModification(fileRemoved).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);
    // / file has been removed from the AS7 installation
    assertFileDoesNotExist(standaloneShellFile);
    // but it's been backed up
    assertFileExists(env.getInstalledImage().getPatchHistoryDir(patch.getPatchId()), "misc", "bin", fileName);
}
Also used : PatchingResult(org.jboss.as.patching.tool.PatchingResult) TestUtils.randomString(org.jboss.as.patching.runner.TestUtils.randomString) TestUtils.createPatchXMLFile(org.jboss.as.patching.runner.TestUtils.createPatchXMLFile) 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 12 with Patch

use of org.jboss.as.patching.metadata.Patch in project wildfly-core by wildfly.

the class ModuleTaskTestCase method testAddModule.

@Test
public void testAddModule() throws Exception {
    // build a one-off patch for the base installation
    // with 1 added module
    String patchID = randomString();
    File patchDir = mkdir(tempDir, patchID);
    String baseLayerPatchID = randomString();
    String moduleName = randomString();
    ContentModification moduleAdded = ContentModificationUtils.addModule(patchDir, baseLayerPatchID, moduleName);
    Patch patch = PatchBuilder.create().setPatchId(patchID).setDescription(randomString()).oneOffPatchIdentity(productConfig.getProductName(), productConfig.getProductVersion()).getParent().oneOffPatchElement(baseLayerPatchID, 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(baseLayerPatchID);
    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) 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 13 with Patch

use of org.jboss.as.patching.metadata.Patch in project wildfly-core by wildfly.

the class AbstractPatchingTest method apply.

protected PatchingResult apply(final PatchingTestStepBuilder builder, final ContentVerificationPolicy verificationPolicy, final PatchStepAssertions assertions) throws PatchingException {
    final Patch patch = builder.build();
    final File installation = new File(tempDir, JBOSS_INSTALLATION);
    try {
        assertions.before(installation, patch, installationManager);
    } catch (IOException e) {
        throw new PatchingException(e);
    }
    // Write patch
    writePatch(builder.getPatchDir(), patch);
    // Create the patch tool and apply the patch
    final PatchTool patchTool = PatchTool.Factory.create(installationManager);
    final PatchingResult result = patchTool.applyPatch(builder.getPatchDir(), verificationPolicy);
    result.commit();
    final InstalledIdentity identity = ((InstallationManagerImpl) installationManager).getInstalledIdentity(patch.getIdentity().getName(), null);
    Assert.assertTrue(identity.getAllInstalledPatches().contains(patch.getPatchId()));
    try {
        assertions.after(installation, patch, installationManager);
    } catch (IOException e) {
        throw new PatchingException(e);
    }
    return result;
}
Also used : InstalledIdentity(org.jboss.as.patching.installation.InstalledIdentity) PatchingException(org.jboss.as.patching.PatchingException) PatchingResult(org.jboss.as.patching.tool.PatchingResult) InstallationManagerImpl(org.jboss.as.patching.installation.InstallationManagerImpl) PatchTool(org.jboss.as.patching.tool.PatchTool) IOException(java.io.IOException) Patch(org.jboss.as.patching.metadata.Patch) File(java.io.File)

Example 14 with Patch

use of org.jboss.as.patching.metadata.Patch in project wildfly-core by wildfly.

the class ModuleTaskTestCase method testUpdateModule.

@Test
public void testUpdateModule() throws Exception {
    String moduleName = randomString();
    // create an empty module in the AS7 installation base layer
    File baseModuleDir = newFile(env.getInstalledImage().getModulesDir(), SYSTEM, LAYERS, BASE);
    File moduleDir = createModule0(baseModuleDir, moduleName);
    // build a one-off patch for the base installation
    // with 1 module updated
    String patchID = randomString();
    String baseLayerPatchID = randomString();
    File patchDir = mkdir(tempDir, patchID);
    // create the patch with the updated module
    ContentModification moduleModified = ContentModificationUtils.modifyModule(patchDir, baseLayerPatchID, moduleDir, "new resource in the module");
    Patch patch = PatchBuilder.create().setPatchId(patchID).setDescription(randomString()).oneOffPatchIdentity(productConfig.getProductName(), productConfig.getProductVersion()).getParent().oneOffPatchElement(baseLayerPatchID, BASE, false).addContentModification(moduleModified).getParent().build();
    createPatchXMLFile(patchDir, patch);
    File zippedPatch = createZippedPatchFile(patchDir, patch.getPatchId());
    PatchingResult result = executePatch(zippedPatch);
    assertPatchHasBeenApplied(result, patch);
    tree(env.getInstalledImage().getJbossHome());
    InstalledIdentity installedIdentity = loadInstalledIdentity();
    File modulesPatchDir = installedIdentity.getLayers().get(0).loadTargetInfo().getDirectoryStructure().getModulePatchDirectory(baseLayerPatchID);
    assertDirExists(modulesPatchDir);
    // check that the defined module is the updated one
    assertDefinedModule(modulesPatchDir, moduleName, moduleModified.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) 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 15 with Patch

use of org.jboss.as.patching.metadata.Patch in project wildfly-core by wildfly.

the class PatchMergeUnitTestCase method createRollbackInfo.

static RollbackInfo createRollbackInfo(String id, byte[] oih, byte[] oth, byte[] rih, byte[] rth) {
    // 
    final MiscContentItem oi = new MiscContentItem(name, path, oih);
    final MiscContentItem ri = new MiscContentItem(name, path, rih);
    // 
    final Patch o = createPatch(id, Patch.PatchType.ONE_OFF, new ContentModification(oi, oth, ModificationType.MODIFY));
    final Patch r = createPatch(id, Patch.PatchType.ONE_OFF, new ContentModification(ri, rth, ModificationType.MODIFY));
    // 
    return new RollbackInfo(o, r);
}
Also used : MiscContentItem(org.jboss.as.patching.metadata.MiscContentItem) Patch(org.jboss.as.patching.metadata.Patch) ContentModification(org.jboss.as.patching.metadata.ContentModification)

Aggregations

Patch (org.jboss.as.patching.metadata.Patch)110 ContentModification (org.jboss.as.patching.metadata.ContentModification)94 File (java.io.File)93 Test (org.junit.Test)66 IoUtils.newFile (org.jboss.as.patching.IoUtils.newFile)60 PatchingTestUtil.createPatchXMLFile (org.jboss.as.test.patching.PatchingTestUtil.createPatchXMLFile)55 PatchingTestUtil.createZippedPatchFile (org.jboss.as.test.patching.PatchingTestUtil.createZippedPatchFile)52 PatchingTestUtil.randomString (org.jboss.as.test.patching.PatchingTestUtil.randomString)47 ProductConfig (org.jboss.as.version.ProductConfig)39 TestUtils.randomString (org.jboss.as.patching.runner.TestUtils.randomString)33 TestUtils.createPatchXMLFile (org.jboss.as.patching.runner.TestUtils.createPatchXMLFile)30 TestUtils.createZippedPatchFile (org.jboss.as.patching.runner.TestUtils.createZippedPatchFile)30 Module (org.jboss.as.test.patching.util.module.Module)29 PatchingResult (org.jboss.as.patching.tool.PatchingResult)24 PatchingTestUtil.readFile (org.jboss.as.test.patching.PatchingTestUtil.readFile)24 InstalledIdentity (org.jboss.as.patching.installation.InstalledIdentity)22 IOException (java.io.IOException)14 PatchBuilder (org.jboss.as.patching.metadata.PatchBuilder)14 PatchElement (org.jboss.as.patching.metadata.PatchElement)13 HashUtils.hashFile (org.jboss.as.patching.HashUtils.hashFile)12