use of org.jboss.as.test.patching.util.module.Module in project wildfly-core by wildfly.
the class PatchBundleTestCase method createNextCumulativePatchAddingRandomModule.
private File createNextCumulativePatchAddingRandomModule(String patchID, String asVersion, final String currentPatch, final String targetAsVersion, File targetDir) throws Exception {
String layerPatchID = "layer" + patchID;
File cpPatchDir = mkdir(tempDir, patchID);
final String moduleName = "org.wildfly.test." + randomString();
// Create the version module
final String versionModuleName = ProductInfo.getVersionModule();
final Module modifiedModule = PatchingTestUtil.createVersionModule(targetAsVersion);
// Calculate the target hash of the currently active module
final String currentLayerPatchID = "layer" + currentPatch;
File originalVersionModulePath = new File(tempDir, currentPatch);
originalVersionModulePath = new File(originalVersionModulePath, currentLayerPatchID);
originalVersionModulePath = new File(originalVersionModulePath, Constants.MODULES);
originalVersionModulePath = newFile(originalVersionModulePath, versionModuleName.split("\\."));
originalVersionModulePath = new File(originalVersionModulePath, ProductInfo.getVersionModuleSlot());
byte[] patchedAsVersionHash = HashUtils.hashFile(originalVersionModulePath);
assert patchedAsVersionHash != null;
final ResourceItem resourceItem1 = new ResourceItem("testFile1", "content1".getBytes(StandardCharsets.UTF_8));
final ResourceItem resourceItem2 = new ResourceItem("testFile2", "content2".getBytes(StandardCharsets.UTF_8));
Module newModule = new Module.Builder(moduleName).miscFile(resourceItem1).miscFile(resourceItem2).build();
ContentModification moduleAdded = ContentModificationUtils.addModule(cpPatchDir, layerPatchID, newModule);
ContentModification versionModuleModified = ContentModificationUtils.modifyModule(cpPatchDir, layerPatchID, patchedAsVersionHash, modifiedModule);
ProductConfig productConfig = new ProductConfig(PRODUCT, asVersion, "main");
Patch cpPatch = PatchBuilder.create().setPatchId(patchID).setDescription("A cp patch.").upgradeIdentity(productConfig.getProductName(), productConfig.getProductVersion(), targetAsVersion).getParent().upgradeElement(layerPatchID, "base", false).addContentModification(versionModuleModified).addContentModification(moduleAdded).getParent().build();
createPatchXMLFile(cpPatchDir, cpPatch);
return createZippedPatchFile(cpPatchDir, patchID, targetDir);
}
use of org.jboss.as.test.patching.util.module.Module in project wildfly-core by wildfly.
the class PatchInfoTestBase method applyPatch.
protected byte[] applyPatch(String product, String version, String newVersion, String patchID, String layer, String layerPatchId, byte[] targetHash) throws Exception {
final File patchDir = mkdir(tempDir, patchID);
final Module module = new Module.Builder("module-test").miscFile(new ResourceItem("resource-test", ("resource patch " + patchID).getBytes(StandardCharsets.UTF_8))).build();
// create the patch with the updated module
final ContentModification moduleModified = ContentModificationUtils.modifyModule(patchDir, layerPatchId, targetHash, module);
PatchBuilder patchBuilder = PatchBuilder.create().setPatchId(patchID).setDescription(randomString());
if (newVersion != null) {
patchBuilder = patchBuilder.upgradeIdentity(product, version, newVersion).getParent().upgradeElement(layerPatchId, layer, false).addContentModification(moduleModified).getParent();
} else {
patchBuilder = patchBuilder.oneOffPatchIdentity(product, version).getParent().oneOffPatchElement(layerPatchId, layer, false).addContentModification(moduleModified).getParent();
}
final Patch patch = patchBuilder.build();
// create the patch
createPatchXMLFile(patchDir, patch);
final File zippedPatch = createZippedPatchFile(patchDir, patch.getPatchId());
// apply the patch and check if server is in restart-required mode
controller.start();
try {
Assert.assertTrue("Patch should be accepted", CliUtilsForPatching.applyPatch(zippedPatch.getAbsolutePath()));
Assert.assertTrue("server should be in restart-required mode", CliUtilsForPatching.doesServerRequireRestart());
} finally {
controller.stop();
}
return moduleModified.getItem().getContentHash();
}
use of org.jboss.as.test.patching.util.module.Module in project wildfly-core by wildfly.
the class PatchInfoTestCase method setup.
@Before
public void setup() throws Exception {
bytesOs = new ByteArrayOutputStream();
final Module module = new Module.Builder("module-test").miscFile(new ResourceItem("resource-test", ("module resource").getBytes(StandardCharsets.UTF_8))).build();
moduleDir = module.writeToDisk(new File(MODULES_PATH));
}
use of org.jboss.as.test.patching.util.module.Module in project wildfly-core by wildfly.
the class RollbackLastUnitTestCase method testMain.
@Test
public void testMain() throws Exception {
// 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 to be updated w/o a conflict
File baseModuleDir = newFile(new File(PatchingTestUtil.AS_DISTRIBUTION), MODULES, SYSTEM, LAYERS, BASE);
String moduleName = "module-test";
Module module = new Module.Builder(moduleName).miscFile(new ResourceItem("resource-test", "new resource in the module".getBytes(StandardCharsets.UTF_8))).build();
File moduleDir = module.writeToDisk(new File(MODULES_PATH));
// create the patch with the updated module
ContentModification moduleModified = ContentModificationUtils.modifyModule(patchDir, patchElementId, HashUtils.hashFile(moduleDir), module);
// create a file for the conflict
String fileName = "file-test.txt";
File miscFile = touch(new File(PatchingTestUtil.AS_DISTRIBUTION, "bin"), fileName);
dump(miscFile, "original script to run standalone AS7");
byte[] originalFileHash = HashUtils.hashFile(miscFile);
// patch the file
ContentModification fileModified = ContentModificationUtils.modifyMisc(patchDir, patchID, "updated script", miscFile, "bin", fileName);
Patch patch = PatchBuilder.create().setPatchId(patchID).setDescription(randomString()).upgradeIdentity(productConfig.getProductName(), productConfig.getProductVersion(), productConfig.getProductVersion() + "CP1").getParent().addContentModification(fileModified).upgradeElement(patchElementId, "base", false).addContentModification(moduleModified).getParent().build();
// create the patch
createPatchXMLFile(patchDir, patch);
File zippedPatch = createZippedPatchFile(patchDir, patch.getPatchId());
// no patches applied
assertPatchElements(baseModuleDir, null);
controller.start();
// apply the patch using the cli
CommandContext ctx = CLITestUtil.getCommandContext();
try {
ctx.connectController();
ctx.handle("patch apply " + zippedPatch.getAbsolutePath());
} catch (Exception e) {
ctx.terminateSession();
throw e;
} finally {
controller.stop();
}
// first patch applied
assertPatchElements(baseModuleDir, new String[] { patchElementId }, false);
byte[] patch1FileHash = HashUtils.hashFile(miscFile);
assertNotEqual(originalFileHash, patch1FileHash);
// next patch
final String patchID2 = randomString();
final String patchElementId2 = randomString();
final File patchedModule = newFile(baseModuleDir, ".overlays", patchElementId, moduleName);
Module modifiedModule = new Module.Builder(moduleName).miscFile(new ResourceItem("resource-test", "another module update".getBytes(StandardCharsets.UTF_8))).build();
ContentModification fileModified2 = ContentModificationUtils.modifyMisc(patchDir, patchID2, "another file update", miscFile, "bin", fileName);
ContentModification moduleModified2 = ContentModificationUtils.modifyModule(patchDir, patchElementId2, HashUtils.hashFile(patchedModule), modifiedModule);
Patch patch2 = PatchBuilder.create().setPatchId(patchID2).setDescription(randomString()).upgradeIdentity(productConfig.getProductName(), productConfig.getProductVersion() + "CP1", productConfig.getProductName() + "CP2").getParent().addContentModification(fileModified2).upgradeElement(patchElementId2, "base", false).addContentModification(moduleModified2).getParent().build();
createPatchXMLFile(patchDir, patch2);
File zippedPatch2 = createZippedPatchFile(patchDir, patch2.getPatchId());
controller.start();
try {
ctx.handle("patch apply " + zippedPatch2.getAbsolutePath());
} catch (Exception e) {
e.printStackTrace();
ctx.terminateSession();
throw e;
} finally {
controller.stop();
}
// both patches applied
assertPatchElements(baseModuleDir, new String[] { patchElementId, patchElementId2 }, false);
byte[] patch2FileHash = HashUtils.hashFile(miscFile);
assertNotEqual(patch1FileHash, patch2FileHash);
assertNotEqual(originalFileHash, patch2FileHash);
controller.start();
try {
ctx.handle("patch rollback --reset-configuration=false");
} catch (Exception e) {
ctx.terminateSession();
throw e;
} finally {
controller.stop();
}
byte[] curFileHash = HashUtils.hashFile(miscFile);
assertNotEqual(curFileHash, patch2FileHash);
assertArrayEquals(curFileHash, patch1FileHash);
assertNotEqual(curFileHash, originalFileHash);
controller.start();
try {
// only the first patch is present
assertPatchElements(baseModuleDir, new String[] { patchElementId }, false);
ctx.handle("patch rollback --reset-configuration=false");
} catch (Exception e) {
ctx.terminateSession();
throw e;
} finally {
ctx.terminateSession();
controller.stop();
}
try {
controller.start();
// no patches present
assertPatchElements(baseModuleDir, null, false);
} finally {
controller.stop();
}
curFileHash = HashUtils.hashFile(miscFile);
assertNotEqual(curFileHash, patch2FileHash);
assertNotEqual(curFileHash, patch1FileHash);
assertArrayEquals(curFileHash, originalFileHash);
}
use of org.jboss.as.test.patching.util.module.Module in project wildfly-core by wildfly.
the class ShowHistoryUnitTestCase method testCP.
@Test
public void testCP() throws Exception {
Module module = new Module.Builder("module-test").miscFile(new ResourceItem("resource-test", ("module resource").getBytes(StandardCharsets.UTF_8))).build();
File moduleDir = module.writeToDisk(new File(MODULES_PATH));
byte[] targetHash = HashUtils.hashFile(moduleDir);
targetHash = applyCP("cp1", targetHash);
final ModelNode response = showHistory();
assertTrue(response.has("outcome"));
assertEquals("success", response.get("outcome").asString());
assertTrue(response.has("result"));
final List<ModelNode> list = response.get("result").asList();
assertEquals(1, list.size());
assertPatchInfo(list.get(0), "cp1", "cumulative", "false");
}
Aggregations