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();
}
}
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();
}
}
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");
}
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);
}
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;
}
Aggregations