use of org.jboss.as.test.patching.util.module.Module in project wildfly-core by wildfly.
the class ShowHistoryUnitTestCase method testMain.
@Test
public void testMain() throws Exception {
// create a module
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);
for (int i = 0; i < patchIds.length; ++i) {
if (patchTypes[i]) {
targetHash = applyCP(patchIds[i], targetHash);
} else {
targetHash = applyOneOff(patchIds[i], 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(patchIds.length, list.size());
for (int i = 0; i < patchIds.length; ++i) {
assertPatchInfo(list.get(i), patchIds[patchIds.length - 1 - i], patchTypes[patchTypes.length - 1 - i] ? "cumulative" : "one-off", "false");
}
}
use of org.jboss.as.test.patching.util.module.Module in project wildfly-core by wildfly.
the class BasicOneOffPatchingScenariosTestCase method testModifyAModule.
/**
* Create a new module in AS distribution,
* create a patch which modifies it by adding a new text file into it.
*/
@Test
public void testModifyAModule() throws Exception {
ProductConfig productConfig = new ProductConfig(PRODUCT, AS_VERSION, "main");
final String moduleName = "org.wildfly.test." + randomString();
// add a new empty module to eap dist
Module module = new Module.Builder(moduleName).build();
File moduleDir = module.writeToDisk(new File(MODULES_PATH));
logger.tracef("moduleDir = %s", moduleDir.getAbsolutePath());
// prepare the patch
String patchID = randomString();
String baseLayerPatchID = randomString();
File patchDir = mkdir(tempDir, patchID);
Module updatedModule = new Module.Builder(moduleName).miscFile(new ResourceItem("res1", "new resource in the module".getBytes(StandardCharsets.UTF_8))).build();
// Also see if we can update jboss-modules
final File installation = new File(AS_DISTRIBUTION);
final ContentModification jbossModulesModification = PatchingTestUtil.updateModulesJar(installation, new File(patchDir, baseLayerPatchID));
// create the patch with the updated module
ContentModification moduleModified = ContentModificationUtils.modifyModule(patchDir, baseLayerPatchID, HashUtils.hashFile(moduleDir), updatedModule);
Patch patch = PatchBuilder.create().setPatchId(patchID).setDescription(randomString()).oneOffPatchIdentity(productConfig.getProductName(), productConfig.getProductVersion()).getParent().oneOffPatchElement(baseLayerPatchID, BASE, false).addContentModification(moduleModified).addContentModification(jbossModulesModification).getParent().build();
createPatchXMLFile(patchDir, patch);
File zippedPatch = createZippedPatchFile(patchDir, patchID);
logger.info(zippedPatch.getAbsolutePath());
// apply patch and check if server is in restart-required mode
controller.start();
Assert.assertTrue("Patch should be accepted", CliUtilsForPatching.applyPatch(zippedPatch.getAbsolutePath()));
Assert.assertTrue("server should be in restart-required mode", CliUtilsForPatching.doesServerRequireRestart());
controller.stop();
controller.start();
Assert.assertTrue("The patch " + patchID + " should be listed as installed", CliUtilsForPatching.getInstalledPatches().contains(patchID));
File newFile = newFile(new File(PATCHES_PATH), baseLayerPatchID);
newFile = newFile(newFile, moduleName.split("\\."));
newFile = newFile(newFile, "main", "res1");
Assert.assertTrue("File " + newFile.getAbsolutePath() + " should exist", newFile.exists());
// check that JBoss Modules picks up the module from the right path
List<String> paths = CliUtilsForPatching.getResourceLoaderPathsForModule(moduleName, false);
Assert.assertTrue("Module should be loaded from the .overlays directory but was: " + paths.get(0), paths.get(0).contains(".overlays" + File.separator + baseLayerPatchID));
// rollback the patch and check if server is in restart-required mode
Assert.assertTrue("Rollback should be accepted", CliUtilsForPatching.rollbackPatch(patchID));
Assert.assertTrue("server should be in restart-required mode", CliUtilsForPatching.doesServerRequireRestart());
controller.stop();
controller.start();
Assert.assertFalse("The patch " + patchID + " NOT should be listed as installed", CliUtilsForPatching.getInstalledPatches().contains(patchID));
Assert.assertFalse("File " + newFile.getAbsolutePath() + " should not exist", newFile.exists());
paths = CliUtilsForPatching.getResourceLoaderPathsForModule(moduleName, false);
Assert.assertFalse("Module should NOT be loaded from the .overlays directory but was: " + paths.get(0), paths.get(0).contains(".overlays" + File.separator + baseLayerPatchID));
// reapply patch and check if server is in restart-required mode
Assert.assertTrue("Patch should be accepted", CliUtilsForPatching.applyPatch(zippedPatch.getAbsolutePath()));
Assert.assertTrue("server should be in restart-required mode", CliUtilsForPatching.doesServerRequireRestart());
controller.stop();
controller.start();
Assert.assertTrue("The patch " + patchID + " should be listed as installed", CliUtilsForPatching.getInstalledPatches().contains(patchID));
// check that JBoss Modules picks up the module from the right path
paths = CliUtilsForPatching.getResourceLoaderPathsForModule(moduleName, false);
Assert.assertTrue("Module should be loaded from the .overlays directory but was: " + paths.get(0), paths.get(0).contains(".overlays" + File.separator + baseLayerPatchID));
Assert.assertTrue("File " + newFile.getAbsolutePath() + " should exist", newFile.exists());
controller.stop();
}
use of org.jboss.as.test.patching.util.module.Module in project wildfly-core by wildfly.
the class BasicOneOffPatchingScenariosTestCase method testOneOffPatchAddingAModule.
/**
* Prepare a one-off patch which adds a new module "org.wildfly.awesomemodule" to the base layer. Apply it, check that the module was installed
* Roll it back, check that the files was deleted, created and apply it again to make sure re-applying works as expected
*
* @throws Exception
*/
@Test
public void testOneOffPatchAddingAModule() throws Exception {
// prepare the patch
String patchID = randomString();
String invalidPatchId = randomString();
String layerPatchID = randomString();
File oneOffPatchDir = mkdir(tempDir, patchID);
File invalidOneOffPatchDir = mkdir(tempDir, invalidPatchId);
final String moduleName = "org.wildfly.test." + randomString();
final String modulePath = PATCHES_PATH + FILE_SEPARATOR + layerPatchID + FILE_SEPARATOR + moduleName.replace(".", FILE_SEPARATOR) + FILE_SEPARATOR + "main";
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();
// create valid patch
ContentModification moduleAdded = ContentModificationUtils.addModule(oneOffPatchDir, layerPatchID, newModule);
ProductConfig productConfig = new ProductConfig(PRODUCT, AS_VERSION, "main");
Patch oneOffPatch = PatchBuilder.create().setPatchId(patchID).setDescription("A one-off patch adding a new module.").oneOffPatchIdentity(productConfig.getProductName(), productConfig.getProductVersion()).getParent().oneOffPatchElement(layerPatchID, "base", false).setDescription("New module for the base layer").addContentModification(moduleAdded).getParent().build();
createPatchXMLFile(oneOffPatchDir, oneOffPatch);
File zippedPatch = createZippedPatchFile(oneOffPatchDir, patchID);
// create invalid patch - replaced layerPatchId with patchID
ContentModification invalidContentModification = ContentModificationUtils.addModule(invalidOneOffPatchDir, invalidPatchId, newModule);
Patch invalidOneOffPatch = PatchBuilder.create().setPatchId(invalidPatchId).setDescription("A invalid one-off patch adding a new module.").oneOffPatchIdentity(productConfig.getProductName(), productConfig.getProductVersion()).getParent().oneOffPatchElement(layerPatchID, "base", false).setDescription("New module for the base layer").addContentModification(invalidContentModification).getParent().build();
createPatchXMLFile(invalidOneOffPatchDir, invalidOneOffPatch);
File zippedInvalidPatch = createZippedPatchFile(invalidOneOffPatchDir, invalidPatchId);
// try to apply invalid one off patch and apply valid patch and check if server is in restart-required mode
controller.start();
Assert.assertFalse("Patch shouldn't be accepted", CliUtilsForPatching.applyPatch(zippedInvalidPatch.getAbsolutePath()));
Assert.assertTrue("Patch should be accepted", CliUtilsForPatching.applyPatch(zippedPatch.getAbsolutePath()));
Assert.assertTrue("server should be in restart-required mode", CliUtilsForPatching.doesServerRequireRestart());
controller.stop();
// check if patch is listed as installed, files exists on correct place
controller.start();
List<String> paths = CliUtilsForPatching.getResourceLoaderPathsForModule(moduleName, false);
Assert.assertTrue("Module should be loaded from the .overlays directory but was: " + paths.get(0), paths.get(0).contains(".overlays" + File.separator + layerPatchID));
Assert.assertTrue("The patch " + patchID + " should be listed as installed", CliUtilsForPatching.getInstalledPatches().contains(patchID));
Assert.assertTrue("The file " + resourceItem1.getItemName() + " should exist", new File(modulePath + FILE_SEPARATOR + resourceItem1.getItemName()).exists());
Assert.assertTrue("The file " + resourceItem2.getItemName() + " should exist", new File(modulePath + FILE_SEPARATOR + resourceItem2.getItemName()).exists());
// look into patch history
List<ModelNode> history = CliUtilsForPatching.getPatchingHistory();
Assert.assertTrue("Patch " + patchID + " should be visible in history: " + Arrays.deepToString(history.toArray()), PatchingTestUtil.isOneOffPatchContainedInHistory(history, patchID));
// rollback the patch and check if server is in restart-required mode
Assert.assertTrue("Rollback should be accepted", CliUtilsForPatching.rollbackPatch(patchID));
Assert.assertTrue("server should be in restart-required mode", CliUtilsForPatching.doesServerRequireRestart());
controller.stop();
// check if patch is not listed
controller.start();
// check that module is not active
try {
CliUtilsForPatching.getResourceLoaderPathsForModule(moduleName, true);
Assert.fail("Module " + moduleName + " should have been removed");
} catch (RuntimeException expected) {
}
Assert.assertFalse("The patch " + patchID + " NOT should be listed as installed", CliUtilsForPatching.getInstalledPatches().contains(patchID));
Assert.assertFalse("The file " + resourceItem1.getItemName() + "should have been deleted", new File(modulePath + FILE_SEPARATOR + resourceItem1.getItemName()).exists());
Assert.assertFalse("The file " + resourceItem2.getItemName() + "should have been deleted", new File(modulePath + FILE_SEPARATOR + resourceItem2.getItemName()).exists());
// reapply patch and check if server is in restart-required mode
Assert.assertTrue("Patch should be accepted", CliUtilsForPatching.applyPatch(zippedPatch.getAbsolutePath()));
Assert.assertTrue("server should be in restart-required mode", CliUtilsForPatching.doesServerRequireRestart());
controller.stop();
// check if patch is listed as installed, files exists on correct place
controller.start();
paths = CliUtilsForPatching.getResourceLoaderPathsForModule(moduleName, false);
Assert.assertTrue("Module should be loaded from the .overlays directory but was: " + paths.get(0), paths.get(0).contains(".overlays" + File.separator + layerPatchID));
Assert.assertTrue("The patch " + patchID + " should be listed as installed", CliUtilsForPatching.getInstalledPatches().contains(patchID));
Assert.assertTrue("The file " + resourceItem1.getItemName() + " should exist", new File(modulePath + FILE_SEPARATOR + resourceItem1.getItemName()).exists());
Assert.assertTrue("The file " + resourceItem2.getItemName() + " should exist", new File(modulePath + FILE_SEPARATOR + resourceItem2.getItemName()).exists());
controller.stop();
}
use of org.jboss.as.test.patching.util.module.Module in project wildfly-core by wildfly.
the class OverridePreserveTestCase method testOverrideModules.
/**
* Prepare a patch that modifies module.
* Modify this module before installing the patch.
* apply patch with --override-modules
* rollback patch
*/
@Test
public void testOverrideModules() throws Exception {
ProductConfig productConfig = new ProductConfig(PRODUCT, AS_VERSION, "main");
String moduleName = "org.wildfly.test." + randomString();
// add a new empty module to eap dist
Module module = new Module.Builder(moduleName).build();
File moduleDir = module.writeToDisk(new File(MODULES_PATH));
logger.trace("moduleDir = " + moduleDir.getAbsolutePath());
// prepare the patch
String patchID = randomString();
String baseLayerPatchID = randomString();
File patchDir = mkdir(tempDir, patchID);
Module updatedModule = new Module.Builder(moduleName).miscFile(new ResourceItem("res1", "new resource in the module".getBytes(StandardCharsets.UTF_8))).build();
// create the patch with the updated module
ContentModification moduleModified = ContentModificationUtils.modifyModule(patchDir, baseLayerPatchID, HashUtils.hashFile(moduleDir), updatedModule);
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, patchID);
logger.debug(zippedPatch.getAbsolutePath());
// modify module
File fileModifyModule = newFile(moduleDir, "newFile");
dump(fileModifyModule, "test content");
// apply patch without --override-modules
controller.start();
Assert.assertFalse("Server should reject patch installation in this case", CliUtilsForPatching.applyPatch(zippedPatch.getAbsolutePath()));
// apply patch with --override-modules
Assert.assertTrue("Patch should be accepted", CliUtilsForPatching.applyPatch(zippedPatch.getAbsolutePath(), CliUtilsForPatching.OVERRIDE_MODULES));
Assert.assertTrue("server should be in restart-required mode", CliUtilsForPatching.doesServerRequireRestart());
controller.stop();
controller.start();
Assert.assertTrue("The patch " + patchID + " should be listed as installed", CliUtilsForPatching.getInstalledPatches().contains(patchID));
// rollback patch
Assert.assertTrue("Rollback should be accepted", CliUtilsForPatching.rollbackPatch(patchID, CliUtilsForPatching.OVERRIDE_MODULES));
Assert.assertTrue("server should be in restart-required mode", CliUtilsForPatching.doesServerRequireRestart());
controller.stop();
controller.start();
try {
Assert.assertFalse("The patch " + patchID + " NOT should be listed as installed", CliUtilsForPatching.getInstalledPatches().contains(patchID));
// no patches present
assertPatchElements(PatchingTestUtil.BASE_MODULE_DIRECTORY, null, false);
} finally {
controller.stop();
}
}
use of org.jboss.as.test.patching.util.module.Module in project wildfly-core by wildfly.
the class CumulativePatchingScenariosTestCase method createInvalidCumulativePatch.
private File createInvalidCumulativePatch(String patchID, String asVersion, final String targetAsVersion) throws Exception {
String layerPatchID = randomString();
File cpPatchDir = mkdir(tempDir, patchID);
// Create the version module
final String versionModuleName = ProductInfo.getVersionModule();
final String slot = ProductInfo.getVersionModuleSlot();
final String originalVersionModulePath = MODULES_PATH + FILE_SEPARATOR + versionModuleName.replace(".", FILE_SEPARATOR) + FILE_SEPARATOR + slot;
final Module modifiedModule = PatchingTestUtil.createVersionModule(targetAsVersion);
// create broken patch - replaced layerPatchID with patchID
ContentModification versionModuleModified = ContentModificationUtils.modifyModule(cpPatchDir, patchID, HashUtils.hashFile(new File(originalVersionModulePath)), modifiedModule);
Patch cpPatch = PatchBuilder.create().setPatchId(patchID).setDescription("A cp patch.").upgradeIdentity(PRODUCT, asVersion, targetAsVersion).getParent().upgradeElement(layerPatchID, "base", false).addContentModification(versionModuleModified).getParent().build();
createPatchXMLFile(cpPatchDir, cpPatch);
return createZippedPatchFile(cpPatchDir, patchID);
}
Aggregations