Search in sources :

Example 16 with ContentModification

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

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

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

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

the class PatchMergeUnitTestCase method testPreserveExisting.

@Test
public void testPreserveExisting() throws Exception {
    // content-item 'two' replacing 'one', but kept 'four'
    final RollbackInfo patch01 = createRollbackInfo("patch01", two, one, four, four);
    // content-item 'three' replacing 'two'
    final RollbackInfo patch02 = createRollbackInfo("patch02", three, four);
    // [patch-two, patch-one]
    final ContentTaskDefinitions defs = process(patch02, patch01);
    Assert.assertEquals(1, defs.size());
    final PatchingTasks.ContentTaskDefinition def = defs.get(new Location(new MiscContentItem(name, path, one)));
    Assert.assertNotNull(def);
    Assert.assertTrue(def.hasConflicts());
    // We want to got back to four
    Assert.assertEquals(four, def.getTarget().getItem().getContentHash());
    // The recorded action was preserving four
    Assert.assertEquals(four, def.getTarget().getTargetHash());
    // The current content however is three
    Assert.assertEquals(three, def.getLatest().getTargetHash());
    // And originally replaced four
    Assert.assertEquals(four, def.getLatest().getItem().getContentHash());
    // The resulting operation should replace 'three' with 'four'
    final ContentModification modification = PatchingTaskDescription.resolveDefinition(def);
    Assert.assertEquals(four, modification.getItem().getContentHash());
    Assert.assertEquals(three, modification.getTargetHash());
}
Also used : MiscContentItem(org.jboss.as.patching.metadata.MiscContentItem) ContentModification(org.jboss.as.patching.metadata.ContentModification) Test(org.junit.Test)

Example 20 with ContentModification

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

the class PatchMergeUnitTestCase method testOverrideExisting.

@Test
public void testOverrideExisting() throws Exception {
    // content-item 'two' replacing 'four', originally targeting 'one'
    final RollbackInfo patch01 = createRollbackInfo("patch01", two, one, four, two);
    // content-item 'three' replacing 'two'
    final RollbackInfo patch02 = createRollbackInfo("patch02", three, two);
    // [patch-two, patch-one]
    final ContentTaskDefinitions defs = process(patch02, patch01);
    Assert.assertEquals(1, defs.size());
    final PatchingTasks.ContentTaskDefinition def = defs.get(new Location(new MiscContentItem(name, path, one)));
    Assert.assertNotNull(def);
    Assert.assertTrue(def.hasConflicts());
    // We want to restore four (from the backup)
    Assert.assertEquals(four, def.getTarget().getItem().getContentHash());
    // The original target was two
    Assert.assertEquals(two, def.getTarget().getTargetHash());
    // The current content however is three
    Assert.assertEquals(three, def.getLatest().getTargetHash());
    // And originally replaced two
    Assert.assertEquals(two, def.getLatest().getItem().getContentHash());
    // The resulting operation should replace 'three' with 'four'
    final ContentModification modification = PatchingTaskDescription.resolveDefinition(def);
    Assert.assertEquals(four, modification.getItem().getContentHash());
    Assert.assertEquals(three, modification.getTargetHash());
}
Also used : MiscContentItem(org.jboss.as.patching.metadata.MiscContentItem) ContentModification(org.jboss.as.patching.metadata.ContentModification) 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