use of org.jboss.as.patching.metadata.ContentModification in project wildfly-core by wildfly.
the class OneOffPatchTestCase method testApplyOneOffPatch.
@Test
public void testApplyOneOffPatch() throws Exception {
// build a one-off patch for the base installation
// with 1 added module
String oneOffPatchID = randomString();
String oneOffLayerPatchID = randomString();
File oneOffPatchDir = mkdir(tempDir, oneOffPatchID);
String moduleName = randomString();
ContentModification moduleAdded = ContentModificationUtils.addModule(oneOffPatchDir, oneOffLayerPatchID, moduleName);
Patch oneOffPatch = PatchBuilder.create().setPatchId(oneOffPatchID).setDescription(randomString()).oneOffPatchIdentity(productConfig.getProductName(), productConfig.getProductVersion()).getParent().oneOffPatchElement(oneOffLayerPatchID, BASE, false).addContentModification(moduleAdded).getParent().build();
createPatchXMLFile(oneOffPatchDir, oneOffPatch);
File zippedPatch = createZippedPatchFile(oneOffPatchDir, oneOffPatchID);
PatchingResult result = executePatch(zippedPatch);
assertPatchHasBeenApplied(result, oneOffPatch);
InstalledIdentity updatedInstalledIdentity = loadInstalledIdentity();
File modulePatchDirectory = updatedInstalledIdentity.getLayers().get(0).loadTargetInfo().getDirectoryStructure().getModulePatchDirectory(oneOffLayerPatchID);
assertDirExists(modulePatchDirectory);
assertDefinedModule(modulePatchDirectory, moduleName, moduleAdded.getItem().getContentHash());
}
use of org.jboss.as.patching.metadata.ContentModification in project wildfly-core by wildfly.
the class RemoveModifiedFileTaskTestCase method setUp.
@Before
public void setUp() throws Exception {
// with a file in it
File binDir = mkdir(env.getInstalledImage().getJbossHome(), "bin");
String fileName = "standalone.sh";
removedFile = touch(binDir, fileName);
dump(removedFile, "modified script to run standalone AS");
expectedModifiedHash = hashFile(removedFile);
// let's simulate that the file has been modified by the users by using a hash that is not the file checksum
byte[] unmodifiedHash = randomString().getBytes(StandardCharsets.UTF_8);
String patchID = randomString();
File patchDir = mkdir(tempDir, patchID);
File updatedFile = touch(patchDir, "misc", "bin", fileName);
dump(updatedFile, "updated script");
// build a one-off patch for the base installation
// with 1 removed file
fileRemoved = new ContentModification(new MiscContentItem(fileName, new String[] { "bin" }, NO_CONTENT), unmodifiedHash, REMOVE);
patch = PatchBuilder.create().setPatchId(patchID).setDescription(randomString()).oneOffPatchIdentity(productConfig.getProductName(), productConfig.getProductVersion()).getParent().addContentModification(fileRemoved).build();
// create the patch
createPatchXMLFile(patchDir, patch);
zippedPatch = createZippedPatchFile(patchDir, patch.getPatchId());
runner = newPatchTool();
}
use of org.jboss.as.patching.metadata.ContentModification in project wildfly-core by wildfly.
the class PatchUndoTestCase method testWrongModuleContent.
@Test
public void testWrongModuleContent() throws Exception {
final PatchingTestBuilder builder = createDefaultBuilder();
// Add some random content
ContentModificationUtils.addModule(builder.getRoot(), "base-patch-001", "test.module", randomString());
// Override the hash with a wrong one
final ModuleItem item = new ModuleItem("test.module", "main", WRONG_HASH);
final ContentModification wrongModification = new ContentModification(item, IoUtils.NO_CONTENT, ModificationType.ADD);
final PatchingTestStepBuilder step1 = builder.createStepBuilder();
step1.oneOffPatchIdentity(PRODUCT_VERSION).setPatchId("oo1").oneOffPatchElement("base-patch-001", "base", false).addContentModification(wrongModification).getParent().addFileWithRandomContent(null, "test", "content");
//
try {
apply(step1);
Assert.fail("should have failed");
} catch (PatchingException e) {
Assert.assertFalse(builder.hasFile("test", "content"));
final InstalledIdentity identity = loadInstallationManager().getDefaultIdentity();
final PatchableTarget base = identity.getLayer("base");
Assert.assertFalse(base.getDirectoryStructure().getModulePatchDirectory("base-patch-001").exists());
Assert.assertFalse(identity.getInstalledImage().getPatchHistoryDir("oo1").exists());
}
}
use of org.jboss.as.patching.metadata.ContentModification in project wildfly-core by wildfly.
the class PatchUndoTestCase method testWrongModuleContentOverride.
private void testWrongModuleContentOverride(final ContentVerificationPolicy contentVerificationPolicy) throws Exception {
final PatchingTestBuilder builder = createDefaultBuilder();
// Add some random content
ContentModificationUtils.addModule(builder.getRoot(), "base-patch-003", "test.module", randomString());
// Override the hash with a wrong one
final ModuleItem item = new ModuleItem("test.module", "main", WRONG_HASH);
final ContentModification wrongModification = new ContentModification(item, IoUtils.NO_CONTENT, ModificationType.ADD);
final PatchingTestStepBuilder step1 = builder.createStepBuilder();
step1.oneOffPatchIdentity(PRODUCT_VERSION).setPatchId("oo3").oneOffPatchElement("base-patch-003", "base", false).addContentModification(wrongModification).getParent().addFileWithRandomContent(null, "test", "content");
apply(step1, contentVerificationPolicy);
Assert.assertTrue(builder.hasFile("test", "content"));
final InstalledIdentity identity = loadInstallationManager().getDefaultIdentity();
final PatchableTarget base = identity.getLayer("base");
Assert.assertTrue(base.getDirectoryStructure().getModulePatchDirectory("base-patch-003").exists());
Assert.assertTrue(identity.getInstalledImage().getPatchHistoryDir("oo3").exists());
}
use of org.jboss.as.patching.metadata.ContentModification in project wildfly-core by wildfly.
the class ConfigurationBackupTestCase method testCumulativePatch.
@Test
public void testCumulativePatch() throws Exception {
// build a cumulative 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();
final PatchBuilder builder = PatchBuilder.create();
builder.setPatchId(patchID).setDescription(randomString()).upgradeIdentity(installedIdentity.getIdentity().getName(), installedIdentity.getIdentity().getVersion(), productConfig.getProductVersion() + "-CP1").getParent().upgradeElement(layerPatchID, BASE, false).addContentModification(moduleAdded);
Patch patch = builder.build();
checkApplyPatchAndRollbackRestoresBackupConfiguration(patchDir, patch);
}
Aggregations