Search in sources :

Example 96 with ContentModification

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

the class OneOffPatchTestCase method testApplyOneOffPatch.

@Test
public void testApplyOneOffPatch() throws Exception {
    // build a one-off patch for the base installation
    // with 1 added module
    String oneOffPatchID = randomString();
    String oneOffLayerPatchID = randomString();
    File oneOffPatchDir = mkdir(tempDir, oneOffPatchID);
    String moduleName = randomString();
    ContentModification moduleAdded = ContentModificationUtils.addModule(oneOffPatchDir, oneOffLayerPatchID, moduleName);
    Patch oneOffPatch = PatchBuilder.create().setPatchId(oneOffPatchID).setDescription(randomString()).oneOffPatchIdentity(productConfig.getProductName(), productConfig.getProductVersion()).getParent().oneOffPatchElement(oneOffLayerPatchID, BASE, false).addContentModification(moduleAdded).getParent().build();
    createPatchXMLFile(oneOffPatchDir, oneOffPatch);
    File zippedPatch = createZippedPatchFile(oneOffPatchDir, oneOffPatchID);
    PatchingResult result = executePatch(zippedPatch);
    assertPatchHasBeenApplied(result, oneOffPatch);
    InstalledIdentity updatedInstalledIdentity = loadInstalledIdentity();
    File modulePatchDirectory = updatedInstalledIdentity.getLayers().get(0).loadTargetInfo().getDirectoryStructure().getModulePatchDirectory(oneOffLayerPatchID);
    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) HashUtils.hashFile(org.jboss.as.patching.HashUtils.hashFile) 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 97 with ContentModification

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

the class RemoveModifiedFileTaskTestCase method setUp.

@Before
public void setUp() throws Exception {
    // with a file in it
    File binDir = mkdir(env.getInstalledImage().getJbossHome(), "bin");
    String fileName = "standalone.sh";
    removedFile = touch(binDir, fileName);
    dump(removedFile, "modified script to run standalone AS");
    expectedModifiedHash = hashFile(removedFile);
    // let's simulate that the file has been modified by the users by using a hash that is not the file checksum
    byte[] unmodifiedHash = randomString().getBytes(StandardCharsets.UTF_8);
    String patchID = randomString();
    File patchDir = mkdir(tempDir, patchID);
    File updatedFile = touch(patchDir, "misc", "bin", fileName);
    dump(updatedFile, "updated script");
    // build a one-off patch for the base installation
    // with 1 removed file
    fileRemoved = new ContentModification(new MiscContentItem(fileName, new String[] { "bin" }, NO_CONTENT), unmodifiedHash, REMOVE);
    patch = PatchBuilder.create().setPatchId(patchID).setDescription(randomString()).oneOffPatchIdentity(productConfig.getProductName(), productConfig.getProductVersion()).getParent().addContentModification(fileRemoved).build();
    // create the patch
    createPatchXMLFile(patchDir, patch);
    zippedPatch = createZippedPatchFile(patchDir, patch.getPatchId());
    runner = newPatchTool();
}
Also used : MiscContentItem(org.jboss.as.patching.metadata.MiscContentItem) TestUtils.randomString(org.jboss.as.patching.runner.TestUtils.randomString) 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) Before(org.junit.Before)

Example 98 with ContentModification

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

the class PatchUndoTestCase method testWrongModuleContent.

@Test
public void testWrongModuleContent() throws Exception {
    final PatchingTestBuilder builder = createDefaultBuilder();
    // Add some random content
    ContentModificationUtils.addModule(builder.getRoot(), "base-patch-001", "test.module", randomString());
    // Override the hash with a wrong one
    final ModuleItem item = new ModuleItem("test.module", "main", WRONG_HASH);
    final ContentModification wrongModification = new ContentModification(item, IoUtils.NO_CONTENT, ModificationType.ADD);
    final PatchingTestStepBuilder step1 = builder.createStepBuilder();
    step1.oneOffPatchIdentity(PRODUCT_VERSION).setPatchId("oo1").oneOffPatchElement("base-patch-001", "base", false).addContentModification(wrongModification).getParent().addFileWithRandomContent(null, "test", "content");
    // 
    try {
        apply(step1);
        Assert.fail("should have failed");
    } catch (PatchingException e) {
        Assert.assertFalse(builder.hasFile("test", "content"));
        final InstalledIdentity identity = loadInstallationManager().getDefaultIdentity();
        final PatchableTarget base = identity.getLayer("base");
        Assert.assertFalse(base.getDirectoryStructure().getModulePatchDirectory("base-patch-001").exists());
        Assert.assertFalse(identity.getInstalledImage().getPatchHistoryDir("oo1").exists());
    }
}
Also used : ModuleItem(org.jboss.as.patching.metadata.ModuleItem) InstalledIdentity(org.jboss.as.patching.installation.InstalledIdentity) PatchableTarget(org.jboss.as.patching.installation.PatchableTarget) PatchingException(org.jboss.as.patching.PatchingException) ContentModification(org.jboss.as.patching.metadata.ContentModification) Test(org.junit.Test)

Example 99 with ContentModification

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

the class PatchUndoTestCase method testWrongModuleContentOverride.

private void testWrongModuleContentOverride(final ContentVerificationPolicy contentVerificationPolicy) throws Exception {
    final PatchingTestBuilder builder = createDefaultBuilder();
    // Add some random content
    ContentModificationUtils.addModule(builder.getRoot(), "base-patch-003", "test.module", randomString());
    // Override the hash with a wrong one
    final ModuleItem item = new ModuleItem("test.module", "main", WRONG_HASH);
    final ContentModification wrongModification = new ContentModification(item, IoUtils.NO_CONTENT, ModificationType.ADD);
    final PatchingTestStepBuilder step1 = builder.createStepBuilder();
    step1.oneOffPatchIdentity(PRODUCT_VERSION).setPatchId("oo3").oneOffPatchElement("base-patch-003", "base", false).addContentModification(wrongModification).getParent().addFileWithRandomContent(null, "test", "content");
    apply(step1, contentVerificationPolicy);
    Assert.assertTrue(builder.hasFile("test", "content"));
    final InstalledIdentity identity = loadInstallationManager().getDefaultIdentity();
    final PatchableTarget base = identity.getLayer("base");
    Assert.assertTrue(base.getDirectoryStructure().getModulePatchDirectory("base-patch-003").exists());
    Assert.assertTrue(identity.getInstalledImage().getPatchHistoryDir("oo3").exists());
}
Also used : ModuleItem(org.jboss.as.patching.metadata.ModuleItem) InstalledIdentity(org.jboss.as.patching.installation.InstalledIdentity) PatchableTarget(org.jboss.as.patching.installation.PatchableTarget) ContentModification(org.jboss.as.patching.metadata.ContentModification)

Example 100 with ContentModification

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

the class ConfigurationBackupTestCase method testCumulativePatch.

@Test
public void testCumulativePatch() throws Exception {
    // build a cumulative 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();
    final PatchBuilder builder = PatchBuilder.create();
    builder.setPatchId(patchID).setDescription(randomString()).upgradeIdentity(installedIdentity.getIdentity().getName(), installedIdentity.getIdentity().getVersion(), productConfig.getProductVersion() + "-CP1").getParent().upgradeElement(layerPatchID, BASE, false).addContentModification(moduleAdded);
    Patch patch = builder.build();
    checkApplyPatchAndRollbackRestoresBackupConfiguration(patchDir, patch);
}
Also used : InstalledIdentity(org.jboss.as.patching.installation.InstalledIdentity) PatchBuilder(org.jboss.as.patching.metadata.PatchBuilder) HashUtils.bytesToHexString(org.jboss.as.patching.HashUtils.bytesToHexString) TestUtils.randomString(org.jboss.as.patching.runner.TestUtils.randomString) 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

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