Search in sources :

Example 36 with Module

use of org.jboss.as.test.patching.util.module.Module in project wildfly-core by wildfly.

the class BasicOneOffPatchingScenariosTestCase method testOneOffPatchRemovingAModule.

/**
 * Prepare a one-off patch which removes module. Apply it, check that the module was removed
 * Roll it back, check that the module was restored apply it again to make sure re-applying works as expected
 *
 * @throws Exception
 */
@Test
public void testOneOffPatchRemovingAModule() throws Exception {
    // prepare the patch
    String patchID = randomString();
    String layerPatchID = randomString();
    File oneOffPatchDir = mkdir(tempDir, patchID);
    // creates an empty module
    final String moduleName = "org.wildfly.test." + randomString();
    Module module = new Module.Builder(moduleName).build();
    File moduleDir = module.writeToDisk(new File(MODULES_PATH));
    File patchModuleDir = newFile(new File(PATCHES_PATH), layerPatchID);
    patchModuleDir = newFile(patchModuleDir, moduleName.split("\\."));
    File moduleXml = newFile(patchModuleDir, "main", "module.xml");
    ContentModification moduleRemoved = ContentModificationUtils.removeModule(moduleName, moduleDir);
    ProductConfig productConfig = new ProductConfig(PRODUCT, AS_VERSION, "main");
    Patch oneOffPatch = PatchBuilder.create().setPatchId(patchID).setDescription("A one-off patch removing a module.").oneOffPatchIdentity(productConfig.getProductName(), productConfig.getProductVersion()).getParent().oneOffPatchElement(layerPatchID, "base", false).setDescription("Remove module").addContentModification(moduleRemoved).getParent().build();
    createPatchXMLFile(oneOffPatchDir, oneOffPatch);
    File zippedPatch = createZippedPatchFile(oneOffPatchDir, patchID);
    // apply the patch and check if server is in restart-required mode
    controller.start();
    Assert.assertTrue("Patch should be accepted", CliUtilsForPatching.applyPatch(zippedPatch.getAbsolutePath()));
    Assert.assertTrue("server should be in restart-required mode", CliUtilsForPatching.doesServerRequireRestart());
    controller.stop();
    // check if patch is listed as installed, files exists on correct place
    controller.start();
    Assert.assertTrue("The patch " + patchID + " should be listed as installed", CliUtilsForPatching.getInstalledPatches().contains(patchID));
    Assert.assertTrue("The file " + moduleXml.getName() + " should exist", moduleXml.exists());
    // check that the module is not active
    try {
        List<String> paths = CliUtilsForPatching.getResourceLoaderPathsForModule(moduleName, true);
        Assert.fail("Module " + moduleName + " should have been removed by the patch");
    } catch (RuntimeException expected) {
    }
    // rollback the patch and check if server is in restart-required mode
    Assert.assertTrue("Rollback should be accepted", CliUtilsForPatching.rollbackPatch(patchID));
    Assert.assertTrue("server should be in restart-required mode", CliUtilsForPatching.doesServerRequireRestart());
    controller.stop();
    // check if patch is not listed
    controller.start();
    // check that the module exists
    CliUtilsForPatching.getResourceLoaderPathsForModule(moduleName, true);
    Assert.assertFalse("The patch " + patchID + " NOT should be listed as installed", CliUtilsForPatching.getInstalledPatches().contains(patchID));
    CliUtilsForPatching.getResourceLoaderPathsForModule(moduleName, true);
    // reapply patch and check if server is in restart-required mode
    Assert.assertTrue("Patch should be accepted", CliUtilsForPatching.applyPatch(zippedPatch.getAbsolutePath()));
    Assert.assertTrue("server should be in restart-required mode", CliUtilsForPatching.doesServerRequireRestart());
    controller.stop();
    // check if patch is listed as installed, files exists on correct place
    controller.start();
    Assert.assertTrue("The patch " + patchID + " should be listed as installed", CliUtilsForPatching.getInstalledPatches().contains(patchID));
    Assert.assertTrue("The file " + moduleXml.getName() + " should exist", moduleXml.exists());
    // check that the module is not active
    try {
        CliUtilsForPatching.getResourceLoaderPathsForModule(moduleName, true);
        Assert.fail("Module " + moduleName + " should have been removed by the patch");
    } catch (RuntimeException expected) {
    }
    controller.stop();
}
Also used : ProductConfig(org.jboss.as.version.ProductConfig) PatchingTestUtil.randomString(org.jboss.as.test.patching.PatchingTestUtil.randomString) Module(org.jboss.as.test.patching.util.module.Module) IoUtils.newFile(org.jboss.as.patching.IoUtils.newFile) PatchingTestUtil.createZippedPatchFile(org.jboss.as.test.patching.PatchingTestUtil.createZippedPatchFile) File(java.io.File) PatchingTestUtil.createPatchXMLFile(org.jboss.as.test.patching.PatchingTestUtil.createPatchXMLFile) PatchingTestUtil.readFile(org.jboss.as.test.patching.PatchingTestUtil.readFile) ContentModification(org.jboss.as.patching.metadata.ContentModification) Patch(org.jboss.as.patching.metadata.Patch) Test(org.junit.Test)

Example 37 with Module

use of org.jboss.as.test.patching.util.module.Module in project wildfly-core by wildfly.

the class MergedPatchesTestCase method createCP2.

private File createCP2(String patchID, String asVersion, final String currentPatch, final String targetAsVersion, File targetDir) throws Exception {
    String layerPatchID = "layer" + patchID;
    File cpPatchDir = mkdir(tempDir, patchID);
    final String moduleName = "org.wildfly.test." + randomString("cp2");
    // Create the version module
    final String versionModuleName = ProductInfo.getVersionModule();
    final Module modifiedModule = PatchingTestUtil.createVersionModule(targetAsVersion);
    // Calculate the target hash of the currently active module
    final String currentLayerPatchID = "layer" + currentPatch;
    File originalVersionModulePath = new File(tempDir, currentPatch);
    originalVersionModulePath = new File(originalVersionModulePath, currentLayerPatchID);
    originalVersionModulePath = new File(originalVersionModulePath, Constants.MODULES);
    originalVersionModulePath = newFile(originalVersionModulePath, versionModuleName.split("\\."));
    originalVersionModulePath = new File(originalVersionModulePath, ProductInfo.getVersionModuleSlot());
    byte[] patchedAsVersionHash = HashUtils.hashFile(originalVersionModulePath);
    assert patchedAsVersionHash != null;
    final ResourceItem resourceItem1 = new ResourceItem("testFile1", "content1".getBytes(StandardCharsets.UTF_8));
    final ResourceItem resourceItem2 = new ResourceItem("testFile2", "content2".getBytes(StandardCharsets.UTF_8));
    Module newModule = new Module.Builder(moduleName).miscFile(resourceItem1).miscFile(resourceItem2).build();
    ContentModification moduleAdded = ContentModificationUtils.addModule(cpPatchDir, layerPatchID, newModule);
    ContentModification versionModuleModified = ContentModificationUtils.modifyModule(cpPatchDir, layerPatchID, patchedAsVersionHash, modifiedModule);
    ProductConfig productConfig = new ProductConfig(PRODUCT, asVersion, "main");
    Patch cpPatch = PatchBuilder.create().setPatchId(patchID).setDescription("A cp patch.").upgradeIdentity(productConfig.getProductName(), productConfig.getProductVersion(), targetAsVersion).getParent().upgradeElement(layerPatchID, "base", false).addContentModification(versionModuleModified).addContentModification(moduleAdded).getParent().build();
    createPatchXMLFile(cpPatchDir, cpPatch);
    return createZippedPatchFile(cpPatchDir, patchID, targetDir);
}
Also used : ProductConfig(org.jboss.as.version.ProductConfig) PatchingTestUtil.randomString(org.jboss.as.test.patching.PatchingTestUtil.randomString) Module(org.jboss.as.test.patching.util.module.Module) IoUtils.newFile(org.jboss.as.patching.IoUtils.newFile) PatchingTestUtil.createZippedPatchFile(org.jboss.as.test.patching.PatchingTestUtil.createZippedPatchFile) File(java.io.File) PatchingTestUtil.createPatchXMLFile(org.jboss.as.test.patching.PatchingTestUtil.createPatchXMLFile) ContentModification(org.jboss.as.patching.metadata.ContentModification) Patch(org.jboss.as.patching.metadata.Patch)

Example 38 with Module

use of org.jboss.as.test.patching.util.module.Module in project wildfly-core by wildfly.

the class MergedPatchesTestCase method createCP3.

private File createCP3(String patchID, String asVersion, final String currentPatch, final String targetAsVersion, File targetDir) throws Exception {
    String layerPatchID = "layer" + patchID;
    File cpPatchDir = mkdir(tempDir, patchID);
    // Also see if we can update jboss-modules
    final File installation = new File(AS_DISTRIBUTION);
    final File patchDir = new File(cpPatchDir, patchID);
    final ContentModification jbossModulesModification = PatchingTestUtil.updateModulesJar(installation, patchDir);
    // Create the version module
    final String versionModuleName = ProductInfo.getVersionModule();
    final Module modifiedModule = PatchingTestUtil.createVersionModule(targetAsVersion);
    // Calculate the target hash of the currently active module
    final String currentLayerPatchID = "layer" + currentPatch;
    File originalVersionModulePath = new File(tempDir, currentPatch);
    originalVersionModulePath = new File(originalVersionModulePath, currentLayerPatchID);
    originalVersionModulePath = new File(originalVersionModulePath, Constants.MODULES);
    originalVersionModulePath = newFile(originalVersionModulePath, versionModuleName.split("\\."));
    originalVersionModulePath = new File(originalVersionModulePath, ProductInfo.getVersionModuleSlot());
    byte[] patchedAsVersionHash = HashUtils.hashFile(originalVersionModulePath);
    assert patchedAsVersionHash != null;
    ContentModification versionModuleModified = ContentModificationUtils.modifyModule(cpPatchDir, layerPatchID, patchedAsVersionHash, modifiedModule);
    Patch cpPatch = PatchBuilder.create().setPatchId(patchID).setDescription("A cp patch.").upgradeIdentity(PRODUCT, asVersion, targetAsVersion).getParent().upgradeElement(layerPatchID, "base", false).addContentModification(versionModuleModified).getParent().addContentModification(jbossModulesModification).build();
    createPatchXMLFile(cpPatchDir, cpPatch);
    return createZippedPatchFile(cpPatchDir, patchID, targetDir);
}
Also used : PatchingTestUtil.randomString(org.jboss.as.test.patching.PatchingTestUtil.randomString) Module(org.jboss.as.test.patching.util.module.Module) IoUtils.newFile(org.jboss.as.patching.IoUtils.newFile) PatchingTestUtil.createZippedPatchFile(org.jboss.as.test.patching.PatchingTestUtil.createZippedPatchFile) File(java.io.File) PatchingTestUtil.createPatchXMLFile(org.jboss.as.test.patching.PatchingTestUtil.createPatchXMLFile) ContentModification(org.jboss.as.patching.metadata.ContentModification) Patch(org.jboss.as.patching.metadata.Patch)

Example 39 with Module

use of org.jboss.as.test.patching.util.module.Module in project wildfly-core by wildfly.

the class MergedPatchesTestCase method createCP1.

private File createCP1(String patchID, String asVersion, final String targetAsVersion, File targetDir) throws Exception {
    cp1LayerPatchID = "layer" + patchID;
    File cpPatchDir = mkdir(tempDir, patchID);
    cp1AddedModuleName = "org.wildfly.test." + randomString("cp1");
    cp1ResourceItem1 = new ResourceItem("testFile1", "content1".getBytes(StandardCharsets.UTF_8));
    cp1ResourceItem2 = new ResourceItem("testFile2", "content2".getBytes(StandardCharsets.UTF_8));
    Module newModule = new Module.Builder(cp1AddedModuleName).miscFile(cp1ResourceItem1).miscFile(cp1ResourceItem2).build();
    // Create the version module
    final String versionModuleName = ProductInfo.getVersionModule();
    cp1Slot = ProductInfo.getVersionModuleSlot();
    final String originalVersionModulePath = MODULES_PATH + FILE_SEPARATOR + versionModuleName.replace(".", FILE_SEPARATOR) + FILE_SEPARATOR + cp1Slot;
    final Module modifiedModule = PatchingTestUtil.createVersionModule(targetAsVersion);
    ContentModification moduleAdded = ContentModificationUtils.addModule(cpPatchDir, cp1LayerPatchID, newModule);
    ContentModification versionModuleModified = ContentModificationUtils.modifyModule(cpPatchDir, cp1LayerPatchID, HashUtils.hashFile(new File(originalVersionModulePath)), modifiedModule);
    Patch cpPatch = PatchBuilder.create().setPatchId(patchID).setDescription("A cp patch.").upgradeIdentity(PRODUCT, asVersion, targetAsVersion).getParent().upgradeElement(cp1LayerPatchID, "base", false).addContentModification(moduleAdded).addContentModification(versionModuleModified).getParent().build();
    createPatchXMLFile(cpPatchDir, cpPatch);
    return createZippedPatchFile(cpPatchDir, patchID, targetDir);
}
Also used : PatchingTestUtil.randomString(org.jboss.as.test.patching.PatchingTestUtil.randomString) Module(org.jboss.as.test.patching.util.module.Module) IoUtils.newFile(org.jboss.as.patching.IoUtils.newFile) PatchingTestUtil.createZippedPatchFile(org.jboss.as.test.patching.PatchingTestUtil.createZippedPatchFile) File(java.io.File) PatchingTestUtil.createPatchXMLFile(org.jboss.as.test.patching.PatchingTestUtil.createPatchXMLFile) ContentModification(org.jboss.as.patching.metadata.ContentModification) Patch(org.jboss.as.patching.metadata.Patch)

Aggregations

File (java.io.File)39 Module (org.jboss.as.test.patching.util.module.Module)39 PatchingTestUtil.createPatchXMLFile (org.jboss.as.test.patching.PatchingTestUtil.createPatchXMLFile)34 PatchingTestUtil.createZippedPatchFile (org.jboss.as.test.patching.PatchingTestUtil.createZippedPatchFile)34 ContentModification (org.jboss.as.patching.metadata.ContentModification)29 Patch (org.jboss.as.patching.metadata.Patch)29 IoUtils.newFile (org.jboss.as.patching.IoUtils.newFile)28 PatchingTestUtil.randomString (org.jboss.as.test.patching.PatchingTestUtil.randomString)28 Test (org.junit.Test)21 PatchBuilder (org.jboss.as.patching.metadata.PatchBuilder)15 ProductConfig (org.jboss.as.version.ProductConfig)14 PatchingTestUtil.readFile (org.jboss.as.test.patching.PatchingTestUtil.readFile)9 ModelNode (org.jboss.dmr.ModelNode)5 BundledPatch (org.jboss.as.patching.metadata.BundledPatch)3 PatchingTestUtil.createPatchBundleXMLFile (org.jboss.as.test.patching.PatchingTestUtil.createPatchBundleXMLFile)3 CommandContext (org.jboss.as.cli.CommandContext)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 Before (org.junit.Before)1