use of org.jboss.as.patching.metadata.Patch in project wildfly-core by wildfly.
the class CumulativePatchTestCase method testApplyReleasePatch.
@Test
public void testApplyReleasePatch() throws Exception {
// build a Release patch for the base installation
// with 1 added module
String patchID = randomString();
String layerPatchID = randomString();
File patchDir = mkdir(tempDir, patchID);
String moduleName = randomString();
ContentModification moduleAdded = ContentModificationUtils.addModule(patchDir, layerPatchID, moduleName);
InstalledIdentity installedIdentity = loadInstalledIdentity();
Patch patch = PatchBuilder.create().setPatchId(patchID).setDescription(randomString()).upgradeIdentity(installedIdentity.getIdentity().getName(), installedIdentity.getIdentity().getVersion(), productConfig.getProductVersion() + "-Release1").getParent().upgradeElement(layerPatchID, BASE, false).addContentModification(moduleAdded).getParent().build();
createPatchXMLFile(patchDir, patch);
File zippedPatch = createZippedPatchFile(patchDir, patchID);
PatchingResult result = executePatch(zippedPatch);
assertPatchHasBeenApplied(result, patch);
InstalledIdentity updatedInstalledIdentity = loadInstalledIdentity();
File modulePatchDirectory = updatedInstalledIdentity.getLayers().get(0).loadTargetInfo().getDirectoryStructure().getModulePatchDirectory(layerPatchID);
assertDirExists(modulePatchDirectory);
assertDefinedModule(modulePatchDirectory, moduleName, moduleAdded.getItem().getContentHash());
}
use of org.jboss.as.patching.metadata.Patch in project wildfly-core by wildfly.
the class CumulativePatchTestCase method testApplyReleasePatchAndRollback.
@Test
public void testApplyReleasePatchAndRollback() throws Exception {
// start from a base installation
// create an existing file in the AS7 installation
File binDir = mkdir(env.getInstalledImage().getJbossHome(), "bin");
String fileName = "standalone.sh";
File standaloneShellFile = touch(binDir, fileName);
dump(standaloneShellFile, "original script to run standalone AS7");
byte[] existingHash = hashFile(standaloneShellFile);
// build a Release patch for the base installation
// with 1 added module
// and 1 updated file
String patchID = randomString();
String layerPatchID = randomString();
File patchDir = mkdir(tempDir, patchID);
String moduleName = randomString();
ContentModification moduleAdded = ContentModificationUtils.addModule(patchDir, layerPatchID, moduleName);
ContentModification fileModified = ContentModificationUtils.modifyMisc(patchDir, patchID, "updated script", standaloneShellFile, "bin", "standalone.sh");
InstalledIdentity installedIdentity = loadInstalledIdentity();
Patch patch = PatchBuilder.create().setPatchId(patchID).setDescription(randomString()).upgradeIdentity(installedIdentity.getIdentity().getName(), installedIdentity.getIdentity().getVersion(), productConfig.getProductVersion() + "-Release1").getParent().upgradeElement(layerPatchID, BASE, false).addContentModification(moduleAdded).getParent().addContentModification(fileModified).build();
createPatchXMLFile(patchDir, patch);
File zippedPatch = createZippedPatchFile(patchDir, patchID);
Identity identityBeforePatch = loadInstalledIdentity().getIdentity();
PatchingResult result = executePatch(zippedPatch);
assertPatchHasBeenApplied(result, patch);
assertFileExists(standaloneShellFile);
assertFileContent(fileModified.getItem().getContentHash(), standaloneShellFile);
InstalledIdentity updatedInstalledIdentity = loadInstalledIdentity();
File modulePatchDirectory = updatedInstalledIdentity.getLayers().get(0).loadTargetInfo().getDirectoryStructure().getModulePatchDirectory(layerPatchID);
assertDirExists(modulePatchDirectory);
assertDefinedModule(modulePatchDirectory, moduleName, moduleAdded.getItem().getContentHash());
// rollback the patch based on the updated PatchInfo
PatchingResult rollbackResult = rollback(patchID);
tree(env.getInstalledImage().getJbossHome());
assertPatchHasBeenRolledBack(rollbackResult, identityBeforePatch);
assertFileExists(standaloneShellFile);
assertFileContent(existingHash, standaloneShellFile);
}
use of org.jboss.as.patching.metadata.Patch in project wildfly-core by wildfly.
the class CumulativePatchTestCase method testApplyReleasePatchThenOneOffPatchThenRollbackReleasePatch.
@Test
public void testApplyReleasePatchThenOneOffPatchThenRollbackReleasePatch() throws Exception {
// build a Release patch for the base installation
// with 1 added module
String releasePatchID = randomString();
String releaseLayerPatchID = randomString();
File releasePatchDir = mkdir(tempDir, releasePatchID);
String moduleName = randomString();
ContentModification moduleAdded = ContentModificationUtils.addModule(releasePatchDir, releaseLayerPatchID, moduleName);
InstalledIdentity identityBeforePatch = loadInstalledIdentity();
final String resultingVersion = identityBeforePatch.getIdentity().getVersion() + "-Release1";
Patch releasePatch = PatchBuilder.create().setPatchId(releasePatchID).setDescription(randomString()).upgradeIdentity(identityBeforePatch.getIdentity().getName(), identityBeforePatch.getIdentity().getVersion(), resultingVersion).getParent().upgradeElement(releaseLayerPatchID, BASE, false).addContentModification(moduleAdded).getParent().build();
createPatchXMLFile(releasePatchDir, releasePatch);
File zippedReleasePatch = createZippedPatchFile(releasePatchDir, releasePatchID);
PatchingResult resultOfReleasePatch = executePatch(zippedReleasePatch);
assertPatchHasBeenApplied(resultOfReleasePatch, releasePatch);
// FIXME when is the product version persisted when the release is applied?
productConfig = new ProductConfig(productConfig.getProductName(), productConfig.getProductVersion() + "-Release1", productConfig.getConsoleSlot());
InstalledIdentity updatedInstalledIdentity = loadInstalledIdentity();
File modulePatchDirectory = updatedInstalledIdentity.getLayers().get(0).loadTargetInfo().getDirectoryStructure().getModulePatchDirectory(releaseLayerPatchID);
assertDirExists(modulePatchDirectory);
assertDefinedModule(modulePatchDirectory, moduleName, moduleAdded.getItem().getContentHash());
// apply a one-off patch now
String oneOffPatchID = randomString();
String oneOffLayerPatchID = randomString();
File oneOffPatchDir = mkdir(tempDir, oneOffPatchID);
ContentModification moduleModified = ContentModificationUtils.modifyModule(oneOffPatchDir, oneOffLayerPatchID, newFile(modulePatchDirectory, moduleName), "new resource in the module");
Patch oneOffPatch = PatchBuilder.create().setPatchId(oneOffPatchID).setDescription(randomString()).oneOffPatchIdentity(productConfig.getProductName(), resultingVersion).getParent().oneOffPatchElement(oneOffLayerPatchID, BASE, false).addContentModification(moduleModified).getParent().build();
createPatchXMLFile(oneOffPatchDir, oneOffPatch);
File zippedOneOffPatch = createZippedPatchFile(oneOffPatchDir, oneOffPatchID);
PatchingResult resultOfOneOffPatch = executePatch(zippedOneOffPatch);
assertPatchHasBeenApplied(resultOfOneOffPatch, oneOffPatch);
InstalledIdentity installedIdentityAfterOneOffPatch = loadInstalledIdentity();
modulePatchDirectory = installedIdentityAfterOneOffPatch.getLayers().get(0).loadTargetInfo().getDirectoryStructure().getModulePatchDirectory(oneOffLayerPatchID);
assertDirExists(modulePatchDirectory);
assertDefinedModule(modulePatchDirectory, moduleName, moduleModified.getItem().getContentHash());
// rollback the release patch, this should also rollback the one-off patch
PatchingResult resultOfReleasePatchRollback = rollback(releasePatchID);
tree(env.getInstalledImage().getJbossHome());
assertPatchHasBeenRolledBack(resultOfReleasePatchRollback, identityBeforePatch.getIdentity());
updatedInstalledIdentity = loadInstalledIdentity();
File layerModuleRoot = updatedInstalledIdentity.getLayers().get(0).loadTargetInfo().getDirectoryStructure().getModuleRoot();
assertDirDoesNotExist(newFile(layerModuleRoot, moduleName));
}
use of org.jboss.as.patching.metadata.Patch in project wildfly-core by wildfly.
the class CumulativePatchTestCase method testApplyReleasePatchThenOneOffPatch.
@Test
public void testApplyReleasePatchThenOneOffPatch() throws Exception {
// build a Release patch for the base installation
// with 1 added module
String releasePatchID = randomString();
String releaseLayerPatchID = randomString();
File releasePatchDir = mkdir(tempDir, releasePatchID);
String moduleName = randomString();
ContentModification moduleAdded = ContentModificationUtils.addModule(releasePatchDir, releaseLayerPatchID, moduleName);
InstalledIdentity installedIdentity = loadInstalledIdentity();
final String resultingVersion = productConfig.getProductVersion() + "-Release1";
Patch releasePatch = PatchBuilder.create().setPatchId(releasePatchID).setDescription(randomString()).upgradeIdentity(installedIdentity.getIdentity().getName(), installedIdentity.getIdentity().getVersion(), resultingVersion).getParent().upgradeElement(releaseLayerPatchID, BASE, false).addContentModification(moduleAdded).getParent().build();
createPatchXMLFile(releasePatchDir, releasePatch);
File zippedReleasePatch = createZippedPatchFile(releasePatchDir, releasePatchID);
PatchingResult resultOfReleasePatch = executePatch(zippedReleasePatch);
assertPatchHasBeenApplied(resultOfReleasePatch, releasePatch);
// FIXME when is the product version persisted when the release is applied?
productConfig = new ProductConfig(productConfig.getProductName(), productConfig.getProductVersion() + "-Release1", productConfig.getConsoleSlot());
InstalledIdentity updatedInstalledIdentity = loadInstalledIdentity();
File modulePatchDirectory = updatedInstalledIdentity.getLayers().get(0).loadTargetInfo().getDirectoryStructure().getModulePatchDirectory(releaseLayerPatchID);
assertDirExists(modulePatchDirectory);
assertDefinedModule(modulePatchDirectory, moduleName, moduleAdded.getItem().getContentHash());
// apply a one-off patch now
String oneOffPatchID = randomString();
String oneOffLayerPatchID = randomString();
File oneOffPatchDir = mkdir(tempDir, oneOffPatchID);
ContentModification moduleModified = ContentModificationUtils.modifyModule(oneOffPatchDir, oneOffLayerPatchID, newFile(modulePatchDirectory, moduleName), "new resource in the module");
Patch oneOffPatch = PatchBuilder.create().setPatchId(oneOffPatchID).setDescription(randomString()).oneOffPatchIdentity(productConfig.getProductName(), resultingVersion).getParent().oneOffPatchElement(oneOffLayerPatchID, BASE, false).addContentModification(moduleModified).getParent().build();
createPatchXMLFile(oneOffPatchDir, oneOffPatch);
File zippedOneOffPatch = createZippedPatchFile(oneOffPatchDir, oneOffPatchID);
PatchingResult resultOfOneOffPatch = executePatch(zippedOneOffPatch);
assertPatchHasBeenApplied(resultOfOneOffPatch, oneOffPatch);
InstalledIdentity installedIdentityAfterOneOffPatch = loadInstalledIdentity();
modulePatchDirectory = installedIdentityAfterOneOffPatch.getLayers().get(0).loadTargetInfo().getDirectoryStructure().getModulePatchDirectory(oneOffLayerPatchID);
assertDirExists(modulePatchDirectory);
assertDefinedModule(modulePatchDirectory, moduleName, moduleModified.getItem().getContentHash());
}
use of org.jboss.as.patching.metadata.Patch in project wildfly-core by wildfly.
the class FileTaskTestCase method testUpdateFile.
@Test
public void testUpdateFile() throws Exception {
// start from a base installation
// with a file in it
File binDir = mkdir(env.getInstalledImage().getJbossHome(), "bin");
String fileName = "standalone.sh";
File standaloneShellFile = touch(binDir, fileName);
dump(standaloneShellFile, "original script to run standalone AS7");
// build a one-off patch for the base installation
// with 1 updated file
String patchID = randomString();
File patchDir = mkdir(tempDir, patchID);
ContentModification fileModified = ContentModificationUtils.modifyMisc(patchDir, patchID, "updated script", standaloneShellFile, "bin", "standalone.sh");
Patch patch = PatchBuilder.create().setPatchId(patchID).setDescription(randomString()).oneOffPatchIdentity(productConfig.getProductName(), productConfig.getProductVersion()).getParent().addContentModification(fileModified).build();
// create the patch
createPatchXMLFile(patchDir, patch);
File zippedPatch = createZippedPatchFile(patchDir, patch.getPatchId());
PatchingResult result = executePatch(zippedPatch);
assertPatchHasBeenApplied(result, patch);
// / file has been updated in the AS7 installation
// and it's the new one
assertFileExists(standaloneShellFile);
assertFileContent(fileModified.getItem().getContentHash(), standaloneShellFile);
// the existing file has been backed up
File backupFile = assertFileExists(env.getInstalledImage().getPatchHistoryDir(patchID), "misc", "bin", fileName);
assertFileContent(fileModified.getTargetHash(), backupFile);
}
Aggregations