Search in sources :

Example 16 with Patch

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

the class ContentConflictsUnitTestCase method testApply.

/**
 * Tests content conflicts reporting in the CLI during patch application.
 *
 * The test creates 2 misc files, 2 modules and 2 bundles and a patch
 * which updates all of them. Before the patch is applied, one file,
 * one module and one bundle are modified on the disk. The patch is
 * expected to fail and the failure description should contain the
 * info about the conflicting content items.
 *
 * @throws Exception
 */
@Test
public void testApply() throws Exception {
    final File binDir = createInstalledImage(env, "consoleSlot", productConfig.getProductName(), productConfig.getProductVersion());
    // build a one-off patch for the base installation
    // with 1 updated file
    String patchID = randomString();
    File patchDir = mkdir(tempDir, patchID);
    // create a module for the conflict
    File baseModuleDir = newFile(env.getInstalledImage().getModulesDir(), SYSTEM, LAYERS, BASE);
    String moduleConflictName = "module-conflict";
    File moduleConflictDir = createModule0(baseModuleDir, moduleConflictName);
    // create the patch with the updated module
    ContentModification moduleConflictModified = ContentModificationUtils.modifyModule(patchDir, patchID, moduleConflictDir, "new resource in the module");
    // create a module to be updated w/o a conflict
    String moduleNoConflictName = "module-no-conflict";
    File moduleNoConflictDir = createModule0(baseModuleDir, moduleNoConflictName);
    // create the patch with the updated module
    ContentModification moduleNoConflictModified = ContentModificationUtils.modifyModule(patchDir, patchID, moduleNoConflictDir, "new resource in the module");
    // create a file for the conflict
    String fileConflictName = "file-conflict.txt";
    File conflictFile = touch(binDir, fileConflictName);
    dump(conflictFile, "original script to run standalone AS7");
    // patch the file
    ContentModification fileConflictModified = ContentModificationUtils.modifyMisc(patchDir, patchID, "updated script", conflictFile, "bin", fileConflictName);
    // create a file for the conflict
    String fileNoConflictName = "file-no-conflict.txt";
    File noConflictFile = touch(binDir, fileNoConflictName);
    dump(noConflictFile, "original script to run standalone AS7");
    // patch the file
    ContentModification fileNoConflictModified = ContentModificationUtils.modifyMisc(patchDir, patchID, "updated script", noConflictFile, "bin", fileNoConflictName);
    // TestUtils.tree(env.getInstalledImage().getJbossHome());
    Patch patch = PatchBuilder.create().setPatchId(patchID).setDescription(randomString()).oneOffPatchIdentity(productConfig.getProductName(), productConfig.getProductVersion()).getParent().addContentModification(fileConflictModified).addContentModification(fileNoConflictModified).oneOffPatchElement(patchID, "base", false).addContentModification(moduleConflictModified).addContentModification(moduleNoConflictModified).getParent().build();
    // create the patch
    createPatchXMLFile(patchDir, patch, false);
    File zippedPatch = createZippedPatchFile(patchDir, patch.getPatchId());
    // create a conflict for the file
    dump(conflictFile, "conflicting change");
    // create a conflict for the module
    createModule0(baseModuleDir, moduleConflictName, "oops");
    // apply the patch using the cli
    CommandContext ctx = CommandContextFactory.getInstance().newCommandContext();
    try {
        ctx.handle("patch apply " + zippedPatch.getAbsolutePath() + " --distribution=" + env.getInstalledImage().getJbossHome());
        fail("Conflicts expected.");
    } catch (CommandLineException e) {
        // e.printStackTrace();
        final int relativeIndex = env.getInstalledImage().getJbossHome().getAbsolutePath().length() + 1;
        assertConflicts(e, moduleConflictName + ":main", conflictFile.getAbsolutePath().substring(relativeIndex));
    } finally {
        ctx.terminateSession();
    }
}
Also used : CommandContext(org.jboss.as.cli.CommandContext) 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) CommandLineException(org.jboss.as.cli.CommandLineException) Test(org.junit.Test)

Example 17 with Patch

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

the class ContentConflictsUnitTestCase method testRollback.

/**
 * Tests content conflicts reporting in the CLI during patch rollback.
 *
 * The test creates 2 misc files, 2 modules and 2 bundles and a patch
 * which updates all of them. The patch is applied. Then one file,
 * one module and one bundle are modified on the disk. The patch is
 * rolled back then which is expected to fail and the failure description
 * should contain the info about the conflicting content items.
 *
 * @throws Exception
 */
@Test
public void testRollback() throws Exception {
    final File binDir = createInstalledImage(env, "consoleSlot", productConfig.getProductName(), productConfig.getProductVersion());
    // 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 for the conflict
    File baseModuleDir = newFile(env.getInstalledImage().getModulesDir(), SYSTEM, LAYERS, BASE);
    String moduleConflictName = "module-conflict";
    File moduleConflictDir = createModule0(baseModuleDir, moduleConflictName);
    // create the patch with the updated module
    ContentModification moduleConflictModified = ContentModificationUtils.modifyModule(patchDir, patchElementId, moduleConflictDir, "new resource in the module");
    // create a module to be updated w/o a conflict
    String moduleNoConflictName = "module-no-conflict";
    File moduleNoConflictDir = createModule0(baseModuleDir, moduleNoConflictName);
    // create the patch with the updated module
    ContentModification moduleNoConflictModified = ContentModificationUtils.modifyModule(patchDir, patchElementId, moduleNoConflictDir, "new resource in the module");
    // create a file for the conflict
    String fileConflictName = "file-conflict.txt";
    File conflictFile = touch(binDir, fileConflictName);
    dump(conflictFile, "original script to run standalone AS7");
    // patch the file
    ContentModification fileConflictModified = ContentModificationUtils.modifyMisc(patchDir, patchID, "updated script", conflictFile, "bin", fileConflictName);
    // create a file for the conflict
    String fileNoConflictName = "file-no-conflict.txt";
    File noConflictFile = touch(binDir, fileNoConflictName);
    dump(noConflictFile, "original script to run standalone AS7");
    // patch the file
    ContentModification fileNoConflictModified = ContentModificationUtils.modifyMisc(patchDir, patchID, "updated script", noConflictFile, "bin", fileNoConflictName);
    // TestUtils.tree(env.getInstalledImage().getJbossHome());
    Patch patch = PatchBuilder.create().setPatchId(patchID).setDescription(randomString()).oneOffPatchIdentity(productConfig.getProductName(), productConfig.getProductVersion()).getParent().addContentModification(fileConflictModified).addContentModification(fileNoConflictModified).oneOffPatchElement(patchElementId, "base", false).addContentModification(moduleConflictModified).addContentModification(moduleNoConflictModified).getParent().build();
    // create the patch
    createPatchXMLFile(patchDir, patch, false);
    File zippedPatch = createZippedPatchFile(patchDir, patch.getPatchId());
    // apply the patch using the cli
    CommandContext ctx = CommandContextFactory.getInstance().newCommandContext();
    try {
        ctx.handle("patch apply " + zippedPatch.getAbsolutePath() + " --distribution=" + env.getInstalledImage().getJbossHome());
    } catch (CommandLineException e) {
        ctx.terminateSession();
        fail("Failed to apply the patch: " + e);
    }
    // create a conflict for the file
    dump(conflictFile, "conflicting change");
    // create a conflict for the module
    createModule0(baseModuleDir, moduleConflictName, "oops");
    try {
        ctx.handle("patch rollback --patch-id=" + patchID + " --distribution=" + env.getInstalledImage().getJbossHome() + " --reset-configuration=false");
        fail("Conflicts expected");
    } catch (CommandLineException e) {
        final int relativeIndex = env.getInstalledImage().getJbossHome().getAbsolutePath().length() + 1;
        // TODO modules and bundles are not checked at the moment
        assertConflicts(e, moduleConflictName + ":main", conflictFile.getAbsolutePath().substring(relativeIndex));
    // assertConflicts(e, conflictFile.getAbsolutePath().substring(relativeIndex));
    } finally {
        ctx.terminateSession();
    }
}
Also used : CommandContext(org.jboss.as.cli.CommandContext) 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) CommandLineException(org.jboss.as.cli.CommandLineException) Test(org.junit.Test)

Example 18 with Patch

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

the class ResetConfigurationUnitTestCase method testResetConfigurationTrue.

/**
 * Applies a patch, modifies standalone, appclient and domain xml config and rolls back the patch
 * with --reset-configuration=true
 * The expected result is:
 * - the modified config files are replaced with the original configuration files;
 * - the restored-configuration dir is not created in any of the configuration dirs
 * .
 * @throws Exception
 */
@Test
public void testResetConfigurationTrue() throws Exception {
    final File binDir = createInstalledImage(env, "consoleSlot", productConfig.getProductName(), productConfig.getProductVersion());
    // 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 file for the conflict
    String fileNoConflictName = "file-no-conflict.txt";
    File noConflictFile = touch(binDir, fileNoConflictName);
    dump(noConflictFile, "original script to run standalone AS7");
    // patch the file
    ContentModification fileNoConflictModified = ContentModificationUtils.modifyMisc(patchDir, patchID, "updated script", noConflictFile, "bin", fileNoConflictName);
    // TestUtils.tree(env.getInstalledImage().getJbossHome());
    Patch patch = PatchBuilder.create().setPatchId(patchID).setDescription(randomString()).upgradeIdentity(productConfig.getProductName(), productConfig.getProductVersion(), productConfig.getProductVersion() + "CP1").getParent().addContentModification(fileNoConflictModified).upgradeElement(patchElementId, "base", false).getParent().build();
    // create the patch
    createPatchXMLFile(patchDir, patch, false);
    File zippedPatch = createZippedPatchFile(patchDir, patch.getPatchId());
    // apply the patch using the cli
    CommandContext ctx = CommandContextFactory.getInstance().newCommandContext();
    try {
        ctx.handle("patch apply " + zippedPatch.getAbsolutePath() + " --distribution=" + env.getInstalledImage().getJbossHome());
    } catch (Exception e) {
        ctx.terminateSession();
        throw e;
    }
    // check the config files have been backed up
    File backupAppclientXmlFile = assertFileExists(env.getInstalledImage().getPatchHistoryDir(patch.getPatchId()), "configuration", "appclient", "appclient.xml");
    assertFileContent(originalAppClientHash, backupAppclientXmlFile);
    File backupStandaloneXmlFile = assertFileExists(env.getInstalledImage().getPatchHistoryDir(patch.getPatchId()), "configuration", "standalone", "standalone.xml");
    assertFileContent(originalStandaloneHash, backupStandaloneXmlFile);
    File backupDomainXmlFile = assertFileExists(env.getInstalledImage().getPatchHistoryDir(patch.getPatchId()), "configuration", "domain", "domain.xml");
    assertFileContent(originalDomainHash, backupDomainXmlFile);
    // let's change the standalone.xml file
    dump(standaloneXmlFile, "<updated standalone configuration with changes from the added module>");
    byte[] updatedStandaloneXmlFile = hashFile(standaloneXmlFile);
    assertNotEquals(bytesToHexString(originalStandaloneHash), bytesToHexString(updatedStandaloneXmlFile));
    dump(appClientXmlFile, "<updated app client configuration with changes from the added module>");
    byte[] updatedAppClientXmlHash = hashFile(appClientXmlFile);
    assertNotEquals(bytesToHexString(originalAppClientHash), bytesToHexString(updatedAppClientXmlHash));
    dump(domainXmlFile, "<updated domain configuration with changes from the added module>");
    byte[] updatedDomainXmlHash = hashFile(domainXmlFile);
    assertNotEquals(bytesToHexString(originalDomainHash), bytesToHexString(updatedDomainXmlHash));
    try {
        ctx.handle("patch rollback --reset-configuration=true --distribution=" + env.getInstalledImage().getJbossHome());
    } finally {
        ctx.terminateSession();
    }
    // TestUtils.tree(env.getInstalledImage().getJbossHome());
    File rolledBackStandaloneXmlFile = assertFileExists(env.getInstalledImage().getStandaloneDir(), "configuration", "standalone.xml");
    assertEquals(bytesToHexString(originalStandaloneHash), bytesToHexString(hashFile(rolledBackStandaloneXmlFile)));
    File rolledBackAppClientXmlFile = assertFileExists(env.getInstalledImage().getAppClientDir(), "configuration", "appclient.xml");
    assertEquals(bytesToHexString(originalAppClientHash), bytesToHexString(hashFile(rolledBackAppClientXmlFile)));
    File rolledBackDomainXmlFile = assertFileExists(env.getInstalledImage().getDomainDir(), "configuration", "domain.xml");
    assertEquals(bytesToHexString(originalDomainHash), bytesToHexString(hashFile(rolledBackDomainXmlFile)));
    assertDirDoesNotExist(env.getInstalledImage().getStandaloneDir(), "configuration", "restored-configuration");
    assertDirDoesNotExist(env.getInstalledImage().getAppClientDir(), "configuration", "restored-configuration");
    assertDirDoesNotExist(env.getInstalledImage().getDomainDir(), "configuration", "restored-configuration");
}
Also used : CommandContext(org.jboss.as.cli.CommandContext) 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) IOException(java.io.IOException) Test(org.junit.Test)

Example 19 with Patch

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

the class ResetConfigurationUnitTestCase method testResetConfigurationFalse.

/**
 * Applies a patch, modifies standalone, appclient and domain xml config and rolls back the patch
 * with --reset-configuration=false
 * The expected result is:
 * - the modified config files remain as-is;
 * - in each configuration dir a new restored-configuration dir is created with the original,
 *   unmodified configuration files.
 *
 * @throws Exception
 */
@Test
public void testResetConfigurationFalse() throws Exception {
    final File binDir = createInstalledImage(env, "consoleSlot", productConfig.getProductName(), productConfig.getProductVersion());
    // 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 file for the conflict
    String fileNoConflictName = "file-no-conflict.txt";
    File noConflictFile = touch(binDir, fileNoConflictName);
    dump(noConflictFile, "original script to run standalone AS7");
    // patch the file
    ContentModification fileNoConflictModified = ContentModificationUtils.modifyMisc(patchDir, patchID, "updated script", noConflictFile, "bin", fileNoConflictName);
    // TestUtils.tree(env.getInstalledImage().getJbossHome());
    Patch patch = PatchBuilder.create().setPatchId(patchID).setDescription(randomString()).upgradeIdentity(productConfig.getProductName(), productConfig.getProductVersion(), productConfig.getProductVersion() + "CP1").getParent().addContentModification(fileNoConflictModified).upgradeElement(patchElementId, "base", false).getParent().build();
    // create the patch
    createPatchXMLFile(patchDir, patch, false);
    File zippedPatch = createZippedPatchFile(patchDir, patch.getPatchId());
    // apply the patch using the cli
    CommandContext ctx = CommandContextFactory.getInstance().newCommandContext();
    try {
        ctx.handle("patch apply " + zippedPatch.getAbsolutePath() + " --distribution=" + env.getInstalledImage().getJbossHome());
    } catch (Exception e) {
        ctx.terminateSession();
        throw e;
    }
    // check the config files have been backed up
    File backupAppclientXmlFile = assertFileExists(env.getInstalledImage().getPatchHistoryDir(patch.getPatchId()), "configuration", "appclient", "appclient.xml");
    assertFileContent(originalAppClientHash, backupAppclientXmlFile);
    File backupStandaloneXmlFile = assertFileExists(env.getInstalledImage().getPatchHistoryDir(patch.getPatchId()), "configuration", "standalone", "standalone.xml");
    assertFileContent(originalStandaloneHash, backupStandaloneXmlFile);
    File backupDomainXmlFile = assertFileExists(env.getInstalledImage().getPatchHistoryDir(patch.getPatchId()), "configuration", "domain", "domain.xml");
    assertFileContent(originalDomainHash, backupDomainXmlFile);
    // let's change the standalone.xml file
    dump(standaloneXmlFile, "<updated standalone configuration with changes from the added module>");
    byte[] updatedStandaloneXmlHash = hashFile(standaloneXmlFile);
    dump(appClientXmlFile, "<updated app client configuration with changes from the added module>");
    byte[] updatedAppClientXmlHash = hashFile(appClientXmlFile);
    dump(domainXmlFile, "<updated domain configuration with changes from the added module>");
    byte[] updatedDomainXmlHash = hashFile(domainXmlFile);
    try {
        ctx.handle("patch rollback --reset-configuration=false --distribution=" + env.getInstalledImage().getJbossHome());
    } finally {
        ctx.terminateSession();
    }
    // TestUtils.tree(env.getInstalledImage().getJbossHome());
    assertRestoredConfig(env.getInstalledImage().getStandaloneDir(), "standalone.xml", updatedStandaloneXmlHash, originalStandaloneHash);
    assertRestoredConfig(env.getInstalledImage().getAppClientDir(), "appclient.xml", updatedAppClientXmlHash, originalAppClientHash);
    assertRestoredConfig(env.getInstalledImage().getDomainDir(), "domain.xml", updatedDomainXmlHash, originalDomainHash);
}
Also used : CommandContext(org.jboss.as.cli.CommandContext) 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) IOException(java.io.IOException) Test(org.junit.Test)

Example 20 with Patch

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

the class AbstractPatchingTest method rollback.

protected PatchingResult rollback(final PatchingTestStepBuilder builder, final ContentVerificationPolicy verificationPolicy, final PatchStepAssertions assertions, boolean rollbackTo) throws PatchingException {
    final Patch patch = builder.build();
    final File installation = new File(tempDir, JBOSS_INSTALLATION);
    try {
        assertions.before(installation, patch, installationManager);
    } catch (IOException e) {
        throw new PatchingException(e);
    }
    final String patchId = patch.getPatchId();
    final PatchTool patchTool = PatchTool.Factory.create(installationManager);
    final PatchingResult result = patchTool.rollback(patchId, verificationPolicy, rollbackTo, false);
    result.commit();
    final InstalledIdentity identity = installationManager.getInstalledIdentity(patch.getIdentity().getName(), null);
    Assert.assertFalse(identity.getAllInstalledPatches().contains(patch.getPatchId()));
    try {
        assertions.after(installation, patch, installationManager);
    } catch (IOException e) {
        throw new PatchingException(e);
    }
    return result;
}
Also used : InstalledIdentity(org.jboss.as.patching.installation.InstalledIdentity) PatchingException(org.jboss.as.patching.PatchingException) PatchingResult(org.jboss.as.patching.tool.PatchingResult) PatchTool(org.jboss.as.patching.tool.PatchTool) IOException(java.io.IOException) TestUtils.randomString(org.jboss.as.patching.runner.TestUtils.randomString) Patch(org.jboss.as.patching.metadata.Patch) File(java.io.File)

Aggregations

Patch (org.jboss.as.patching.metadata.Patch)110 ContentModification (org.jboss.as.patching.metadata.ContentModification)94 File (java.io.File)93 Test (org.junit.Test)66 IoUtils.newFile (org.jboss.as.patching.IoUtils.newFile)60 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)33 TestUtils.createPatchXMLFile (org.jboss.as.patching.runner.TestUtils.createPatchXMLFile)30 TestUtils.createZippedPatchFile (org.jboss.as.patching.runner.TestUtils.createZippedPatchFile)30 Module (org.jboss.as.test.patching.util.module.Module)29 PatchingResult (org.jboss.as.patching.tool.PatchingResult)24 PatchingTestUtil.readFile (org.jboss.as.test.patching.PatchingTestUtil.readFile)24 InstalledIdentity (org.jboss.as.patching.installation.InstalledIdentity)22 IOException (java.io.IOException)14 PatchBuilder (org.jboss.as.patching.metadata.PatchBuilder)14 PatchElement (org.jboss.as.patching.metadata.PatchElement)13 HashUtils.hashFile (org.jboss.as.patching.HashUtils.hashFile)12