use of org.jboss.as.patching.tool.PatchingResult in project wildfly-core by wildfly.
the class AbstractPatchingTest method apply.
protected PatchingResult apply(final PatchingTestStepBuilder builder, final ContentVerificationPolicy verificationPolicy, final PatchStepAssertions assertions) 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);
}
// Write patch
writePatch(builder.getPatchDir(), patch);
// Create the patch tool and apply the patch
final PatchTool patchTool = PatchTool.Factory.create(installationManager);
final PatchingResult result = patchTool.applyPatch(builder.getPatchDir(), verificationPolicy);
result.commit();
final InstalledIdentity identity = ((InstallationManagerImpl) installationManager).getInstalledIdentity(patch.getIdentity().getName(), null);
Assert.assertTrue(identity.getAllInstalledPatches().contains(patch.getPatchId()));
try {
assertions.after(installation, patch, installationManager);
} catch (IOException e) {
throw new PatchingException(e);
}
return result;
}
use of org.jboss.as.patching.tool.PatchingResult in project wildfly-core by wildfly.
the class ConfigurationBackupTestCase method checkApplyPatchAndRollbackRestoresBackupConfiguration.
private void checkApplyPatchAndRollbackRestoresBackupConfiguration(File patchDir, Patch patch) throws Exception {
createPatchXMLFile(patchDir, patch);
File zippedPatch = createZippedPatchFile(patchDir, patch.getPatchId());
Identity identityBeforePatch = loadInstalledIdentity().getIdentity();
PatchingResult result = executePatch(zippedPatch);
assertPatchHasBeenApplied(result, patch);
// check the AS7 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);
tree(tempDir);
PatchingResult rollbackResult = rollback(patch.getPatchId());
assertPatchHasBeenRolledBack(rollbackResult, identityBeforePatch);
File rolledBackStandaloneXmlFile = assertFileExists(env.getInstalledImage().getStandaloneDir(), "configuration", "standalone.xml");
assertEquals("updated content was " + bytesToHexString(updatedStandaloneXmlFile), bytesToHexString(originalStandaloneHash), bytesToHexString(hashFile(rolledBackStandaloneXmlFile)));
}
use of org.jboss.as.patching.tool.PatchingResult in project wildfly-core by wildfly.
the class ModuleTaskTestCase method testUpdateModule.
@Test
public void testUpdateModule() throws Exception {
String moduleName = randomString();
// create an empty module in the AS7 installation base layer
File baseModuleDir = newFile(env.getInstalledImage().getModulesDir(), SYSTEM, LAYERS, BASE);
File moduleDir = createModule0(baseModuleDir, moduleName);
// build a one-off patch for the base installation
// with 1 module updated
String patchID = randomString();
String baseLayerPatchID = randomString();
File patchDir = mkdir(tempDir, patchID);
// create the patch with the updated module
ContentModification moduleModified = ContentModificationUtils.modifyModule(patchDir, baseLayerPatchID, moduleDir, "new resource in the module");
Patch patch = PatchBuilder.create().setPatchId(patchID).setDescription(randomString()).oneOffPatchIdentity(productConfig.getProductName(), productConfig.getProductVersion()).getParent().oneOffPatchElement(baseLayerPatchID, BASE, false).addContentModification(moduleModified).getParent().build();
createPatchXMLFile(patchDir, patch);
File zippedPatch = createZippedPatchFile(patchDir, patch.getPatchId());
PatchingResult result = executePatch(zippedPatch);
assertPatchHasBeenApplied(result, patch);
tree(env.getInstalledImage().getJbossHome());
InstalledIdentity installedIdentity = loadInstalledIdentity();
File modulesPatchDir = installedIdentity.getLayers().get(0).loadTargetInfo().getDirectoryStructure().getModulePatchDirectory(baseLayerPatchID);
assertDirExists(modulesPatchDir);
// check that the defined module is the updated one
assertDefinedModule(modulesPatchDir, moduleName, moduleModified.getItem().getContentHash());
}
use of org.jboss.as.patching.tool.PatchingResult in project wildfly-core by wildfly.
the class RemoveModifiedFileTaskTestCase method testRemovedModifiedFileWithOVERRIDE_ALL.
@Test
public void testRemovedModifiedFileWithOVERRIDE_ALL() throws Exception {
PatchingResult result = runner.applyPatch(zippedPatch, ContentVerificationPolicy.OVERRIDE_ALL);
assertPatchHasBeenApplied(result, patch);
// / file has been removed from the AS7 installation
// and it's the new one
assertFileDoesNotExist(removedFile);
// the existing file has been backed up
File backupFile = assertFileExists(env.getInstalledImage().getPatchHistoryDir(patch.getPatchId()), "misc", "bin", removedFile.getName());
assertArrayEquals(expectedModifiedHash, hashFile(backupFile));
}
use of org.jboss.as.patching.tool.PatchingResult 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