Search in sources :

Example 26 with Module

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

the class PatchOpInputStreamIndexAsFSPathUnitTestCase method testMain.

@Test
public void testMain() throws Exception {
    // build a one-off patch for the base installation
    // with 1 updated file
    String patchID = randomString();
    String patchElementId = randomString();
    File patchDir = mkdir(tempDir, patchID);
    // create a module to be updated w/o a conflict
    File baseModuleDir = newFile(new File(PatchingTestUtil.AS_DISTRIBUTION), MODULES, SYSTEM, LAYERS, BASE);
    String moduleName = "module-test";
    Module module = new Module.Builder(moduleName).miscFile(new ResourceItem("resource-test", "new resource in the module".getBytes())).build();
    File moduleDir = module.writeToDisk(new File(MODULES_PATH));
    // create the patch with the updated module
    ContentModification moduleModified = ContentModificationUtils.modifyModule(patchDir, patchElementId, HashUtils.hashFile(moduleDir), module);
    // create a file for the conflict
    String fileName = "file-test.txt";
    File miscFile = touch(new File(PatchingTestUtil.AS_DISTRIBUTION, "bin"), fileName);
    dump(miscFile, "original script to run standalone AS7");
    byte[] originalFileHash = HashUtils.hashFile(miscFile);
    // patch the file
    ContentModification fileModified = ContentModificationUtils.modifyMisc(patchDir, patchID, "updated script", miscFile, "bin", fileName);
    Patch patch = PatchBuilder.create().setPatchId(patchID).setDescription(randomString()).upgradeIdentity(productConfig.getProductName(), productConfig.getProductVersion(), productConfig.getProductVersion() + "CP1").getParent().addContentModification(fileModified).upgradeElement(patchElementId, "base", false).addContentModification(moduleModified).getParent().build();
    // create the patch
    createPatchXMLFile(patchDir, patch);
    File zippedPatch = createZippedPatchFile(patchDir, patch.getPatchId());
    // no patches applied
    assertPatchElements(baseModuleDir, null);
    controller.start();
    // apply the patch using the cli
    CommandContext ctx = CLITestUtil.getCommandContext();
    try {
        ctx.connectController();
        ctx.handle("/core-service=patching:patch(input-stream-index=" + escapePath(zippedPatch.getAbsolutePath()) + ")");
    } catch (Exception e) {
        ctx.terminateSession();
        throw e;
    } finally {
        controller.stop();
    }
    // first patch applied
    assertPatchElements(baseModuleDir, new String[] { patchElementId }, false);
    byte[] patch1FileHash = HashUtils.hashFile(miscFile);
    assertNotEqual(originalFileHash, patch1FileHash);
}
Also used : CommandContext(org.jboss.as.cli.CommandContext) PatchBuilder(org.jboss.as.patching.metadata.PatchBuilder) 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) Test(org.junit.Test)

Example 27 with Module

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

the class CPRollingbackOneOffTestCase method testOneOffCP.

/**
 * One-off patch updates a module then a CP updates another module rolling back the one-off.
 */
@Test
public void testOneOffCP() throws Exception {
    // build a one-off patch for the base installation
    // with 1 updated file
    String patchID = randomString();
    File patchDir = mkdir(tempDir, patchID);
    final String patchElement1Id = randomString();
    // create a module to be updated w/o a conflict
    File baseModuleDir = newFile(new File(PatchingTestUtil.AS_DISTRIBUTION), MODULES, SYSTEM, LAYERS, BASE);
    String moduleAName = "org.a.module-a";
    Module moduleA = new Module.Builder(moduleAName).resourceRoot(new ResourceItem(jarA.getName(), jarABytes)).miscFile(new ResourceItem("resource-a", "resource a in the module".getBytes(StandardCharsets.UTF_8))).build();
    File moduleADir = moduleA.writeToDisk(new File(MODULES_PATH));
    String moduleBName = "org.b.module-b";
    Module moduleB = new Module.Builder(moduleBName).resourceRoot(new ResourceItem(jarB.getName(), jarBBytes)).miscFile(new ResourceItem("resource-b", "resource b in the module".getBytes(StandardCharsets.UTF_8))).build();
    File moduleBDir = moduleB.writeToDisk(new File(MODULES_PATH));
    moduleA = new Module.Builder(moduleAName).miscFile(new ResourceItem("resource-a", "resource a one-off".getBytes(StandardCharsets.UTF_8))).build();
    // create the patch with the updated module
    ContentModification moduleAModified = ContentModificationUtils.modifyModule(patchDir, patchElement1Id, HashUtils.hashFile(moduleADir), moduleA);
    Patch patch = PatchBuilder.create().setPatchId(patchID).setDescription(randomString()).oneOffPatchIdentity(productConfig.getProductName(), productConfig.getProductVersion()).getParent().oneOffPatchElement(patchElement1Id, "base", false).addContentModification(moduleAModified).getParent().build();
    // create the patch
    createPatchXMLFile(patchDir, patch);
    File zippedPatch = createZippedPatchFile(patchDir, patch.getPatchId());
    // no patches applied
    assertPatchElements(baseModuleDir, null);
    applyPatch(zippedPatch);
    assertPatchElements(baseModuleDir, new String[] { patchElement1Id }, false);
    patchID = randomString();
    final String patchElement2Id = randomString();
    patchDir = mkdir(tempDir, patchID);
    moduleB = new Module.Builder(moduleBName).miscFile(new ResourceItem("resource-b", "resource b cp".getBytes(StandardCharsets.UTF_8))).build();
    // create the patch with the updated module
    ContentModification moduleBModified = ContentModificationUtils.modifyModule(patchDir, patchElement2Id, HashUtils.hashFile(moduleBDir), moduleB);
    patch = PatchBuilder.create().setPatchId(patchID).setDescription(randomString()).upgradeIdentity(productConfig.getProductName(), productConfig.getProductVersion(), productConfig.getProductVersion() + "_CP1").getParent().upgradeElement(patchElement2Id, "base", false).addContentModification(moduleBModified).getParent().build();
    // create the patch
    createPatchXMLFile(patchDir, patch);
    zippedPatch = createZippedPatchFile(patchDir, patch.getPatchId());
    applyPatch(zippedPatch);
    assertPatchElements(baseModuleDir, new String[] { patchElement1Id, patchElement2Id }, false);
    assertControllerStarts();
    rollbackLast();
    assertPatchElements(baseModuleDir, new String[] { patchElement1Id }, false);
    assertControllerStarts();
    rollbackLast();
    assertPatchElements(baseModuleDir, null);
    assertControllerStarts();
}
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) Test(org.junit.Test)

Example 28 with Module

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

the class ShowHistoryUnitTestCase method testOneOffAndCP.

@Test
public void testOneOffAndCP() throws Exception {
    Module module = new Module.Builder("module-test").miscFile(new ResourceItem("resource-test", ("module resource").getBytes(StandardCharsets.UTF_8))).build();
    File moduleDir = module.writeToDisk(new File(MODULES_PATH));
    byte[] targetHash = HashUtils.hashFile(moduleDir);
    targetHash = applyOneOff("oneoff1", targetHash);
    targetHash = applyCP("cp1", targetHash);
    final ModelNode response = showHistory();
    assertTrue(response.has("outcome"));
    assertEquals("success", response.get("outcome").asString());
    assertTrue(response.has("result"));
    final List<ModelNode> list = response.get("result").asList();
    assertEquals(2, list.size());
    assertPatchInfo(list.get(0), "cp1", "cumulative", "false");
    assertPatchInfo(list.get(1), "oneoff1", "one-off", "false");
}
Also used : Module(org.jboss.as.test.patching.util.module.Module) ModelNode(org.jboss.dmr.ModelNode) File(java.io.File) Test(org.junit.Test)

Example 29 with Module

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

the class ShowHistoryUnitTestCase method testOneOff.

@Test
public void testOneOff() throws Exception {
    Module module = new Module.Builder("module-test").miscFile(new ResourceItem("resource-test", ("module resource").getBytes(StandardCharsets.UTF_8))).build();
    File moduleDir = module.writeToDisk(new File(MODULES_PATH));
    byte[] targetHash = HashUtils.hashFile(moduleDir);
    targetHash = applyOneOff("oneoff1", targetHash);
    final ModelNode response = showHistory();
    assertTrue(response.has("outcome"));
    assertEquals("success", response.get("outcome").asString());
    assertTrue(response.has("result"));
    final List<ModelNode> list = response.get("result").asList();
    assertEquals(1, list.size());
    assertPatchInfo(list.get(0), "oneoff1", "one-off", "false");
}
Also used : Module(org.jboss.as.test.patching.util.module.Module) ModelNode(org.jboss.dmr.ModelNode) File(java.io.File) Test(org.junit.Test)

Example 30 with Module

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

the class AgeOutHistoryUnitTestCase method testCPBeforeCPWithOneOffs.

@Test
public void testCPBeforeCPWithOneOffs() throws Exception {
    Module module = new Module.Builder("module-test").miscFile(new ResourceItem("resource-test", ("module resource").getBytes(StandardCharsets.UTF_8))).build();
    File moduleDir = module.writeToDisk(new File(MODULES_PATH));
    byte[] targetHash = HashUtils.hashFile(moduleDir);
    targetHash = applyCP("cp0", targetHash);
    targetHash = applyCP("cp1", targetHash);
    targetHash = applyOneOff("oneoff1", targetHash);
    targetHash = applyOneOff("oneoff2", targetHash);
    controller.start();
    try {
        client = createClient();
        assertPatched(client, new String[] { "oneoff2", "oneoff1", "cp1", "cp0" }, new boolean[] { false, false, true, true }, new boolean[] { false, false, false, false });
        assertRollbackList(client, new String[] { "oneoff2", "oneoff1", "cp1", "cp0" }, new boolean[] { false, false, true, true }, new boolean[] { false, false, false, false });
        ageoutHistory(client);
        assertCleanedUp("cp0");
        assertPatched(client, new String[] { "oneoff2", "oneoff1", "cp1", "cp0" }, new boolean[] { false, false, true, true }, new boolean[] { false, false, false, true });
        assertRollbackList(client, new String[] { "oneoff2", "oneoff1", "cp1" }, new boolean[] { false, false, true }, new boolean[] { false, false, false });
    } finally {
        controller.stop();
    }
}
Also used : PatchBuilder(org.jboss.as.patching.metadata.PatchBuilder) 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) Test(org.junit.Test)

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