Search in sources :

Example 11 with ContentModification

use of org.jboss.as.patching.metadata.ContentModification 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 12 with ContentModification

use of org.jboss.as.patching.metadata.ContentModification 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 13 with ContentModification

use of org.jboss.as.patching.metadata.ContentModification 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)

Example 14 with ContentModification

use of org.jboss.as.patching.metadata.ContentModification 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 15 with ContentModification

use of org.jboss.as.patching.metadata.ContentModification 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)

Aggregations

ContentModification (org.jboss.as.patching.metadata.ContentModification)129 File (java.io.File)100 Patch (org.jboss.as.patching.metadata.Patch)94 Test (org.junit.Test)72 IoUtils.newFile (org.jboss.as.patching.IoUtils.newFile)70 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)36 TestUtils.createPatchXMLFile (org.jboss.as.patching.runner.TestUtils.createPatchXMLFile)34 TestUtils.createZippedPatchFile (org.jboss.as.patching.runner.TestUtils.createZippedPatchFile)34 Module (org.jboss.as.test.patching.util.module.Module)29 HashUtils.hashFile (org.jboss.as.patching.HashUtils.hashFile)25 PatchingTestUtil.readFile (org.jboss.as.test.patching.PatchingTestUtil.readFile)24 PatchingResult (org.jboss.as.patching.tool.PatchingResult)20 MiscContentItem (org.jboss.as.patching.metadata.MiscContentItem)18 InstalledIdentity (org.jboss.as.patching.installation.InstalledIdentity)17 PatchBuilder (org.jboss.as.patching.metadata.PatchBuilder)16 ContentItem (org.jboss.as.patching.metadata.ContentItem)12