Search in sources :

Example 6 with PatchingResult

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

the class CumulativePatchTestCase method testApplyReleasePatchThenOneOffPatch.

@Test
public void testApplyReleasePatchThenOneOffPatch() 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 installedIdentity = loadInstalledIdentity();
    final String resultingVersion = productConfig.getProductVersion() + "-Release1";
    Patch releasePatch = PatchBuilder.create().setPatchId(releasePatchID).setDescription(randomString()).upgradeIdentity(installedIdentity.getIdentity().getName(), installedIdentity.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());
}
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)

Example 7 with PatchingResult

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

the class FileTaskTestCase method testUpdateFile.

@Test
public void testUpdateFile() throws Exception {
    // start from a base installation
    // with a file in it
    File binDir = mkdir(env.getInstalledImage().getJbossHome(), "bin");
    String fileName = "standalone.sh";
    File standaloneShellFile = touch(binDir, fileName);
    dump(standaloneShellFile, "original script to run standalone AS7");
    // build a one-off patch for the base installation
    // with 1 updated file
    String patchID = randomString();
    File patchDir = mkdir(tempDir, patchID);
    ContentModification fileModified = ContentModificationUtils.modifyMisc(patchDir, patchID, "updated script", standaloneShellFile, "bin", "standalone.sh");
    Patch patch = PatchBuilder.create().setPatchId(patchID).setDescription(randomString()).oneOffPatchIdentity(productConfig.getProductName(), productConfig.getProductVersion()).getParent().addContentModification(fileModified).build();
    // create the patch
    createPatchXMLFile(patchDir, patch);
    File zippedPatch = createZippedPatchFile(patchDir, patch.getPatchId());
    PatchingResult result = executePatch(zippedPatch);
    assertPatchHasBeenApplied(result, patch);
    // / file has been updated in the AS7 installation
    // and it's the new one
    assertFileExists(standaloneShellFile);
    assertFileContent(fileModified.getItem().getContentHash(), standaloneShellFile);
    // the existing file has been backed up
    File backupFile = assertFileExists(env.getInstalledImage().getPatchHistoryDir(patchID), "misc", "bin", fileName);
    assertFileContent(fileModified.getTargetHash(), backupFile);
}
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 8 with PatchingResult

use of org.jboss.as.patching.tool.PatchingResult 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 9 with PatchingResult

use of org.jboss.as.patching.tool.PatchingResult 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 10 with PatchingResult

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

the class UpdateModifiedFileTaskTestCase method testUpdateModifiedFileWithOVERRIDE_ALL.

@Test
public void testUpdateModifiedFileWithOVERRIDE_ALL() throws Exception {
    PatchingResult result = runner.applyPatch(zippedPatch, ContentVerificationPolicy.OVERRIDE_ALL);
    assertPatchHasBeenApplied(result, patch);
    // / file has been updated in the AS7 installation
    // and it's the new one
    assertFileExists(modifiedFile);
    assertArrayEquals(updatedHash, hashFile(modifiedFile));
    // the existing file has been backed up
    File backupFile = assertFileExists(env.getInstalledImage().getPatchHistoryDir(patch.getPatchId()), "misc", "bin", modifiedFile.getName());
    assertArrayEquals(expectedModifiedHash, hashFile(backupFile));
}
Also used : PatchingResult(org.jboss.as.patching.tool.PatchingResult) 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) 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