Ejemplo n.º 1
0
    def testRecursiveUpdate(self):
        target = {"a": {"b": {"c": 3},
                        "d": 4,
                        "e": 5},
                  "f": 6}

        source1 = {"a": {"e": 10,
                         "g": 11}}

        self.assertEqual(recursiveOverlayDict(target, source1),
                         {"a": {"b": {"c": 3},
                                "d": 4,
                                "e": 10,
                                "g": 11},
                          "f": 6})

        # value assignment to a dict not allowed
        self.assertRaises(ValueError, recursiveOverlayDict, target, {"a": 4})
        self.assertRaises(
            ValueError, recursiveOverlayDict, target, {"f": {"r": 2}})

        self.assertEqual(
            recursiveOverlayDict(target, {"a": {"b": {"c": 7}}}),
            {"a": {"b": {"c": 7},
                   "d": 4,
                   "e": 5},
             "f": 6})

        recursiveOverlayDict(target, {"f": 7})
        self.assertRaises(
            ValueError, recursiveOverlayDict, target, {"f": 7}, False)
Ejemplo n.º 2
0
def createAdaptedConfig(tmpDir,
                        sourceCfg,
                        targetCfg,
                        startSnapshot=None,
                        endSnapshot=None):
    testConfiguration()

    if startSnapshot:
        sourceCfg["start_snapshot"] = startSnapshot

    if endSnapshot:
        sourceCfg["end_snapshot"] = endSnapshot

    targetCfg["volume_manager"] = {
        "tlog_path": os.path.join(tmpDir, "tlogs"),
        "metadata_path": os.path.join(tmpDir, "metadata")
    }

    targetCfg["scocache"] = {
        "scocache_mount_points": [{
            "path": os.path.join(tmpDir, "scocache"),
            "size": "1GiB"
        }]
    }

    # keys with non-dict values already specified in cfg are kept
    cfg = getConfigTemplate()

    # bit hacky all this
    if sourceCfg != None:
        cfg = auxiliary.recursiveOverlayDict(
            {"source_configuration": sourceCfg}, cfg)
    else:
        del cfg["source_configuration"]

    cfg = auxiliary.recursiveOverlayDict({"target_configuration": targetCfg},
                                         cfg)

    cfg["scratch_dir"] = os.path.join(tmpDir, "scratch")

    maybeCreateDirs(cfg)

    configFile = os.path.join(tmpDir, CONFIG_NAME)
    with open(configFile, "w") as fp:
        json.dump(cfg, fp, indent=4)
    return configFile
Ejemplo n.º 3
0
    def testRecursiveUpdate(self):
        target = {"a": {"b": {"c": 3}, "d": 4, "e": 5}, "f": 6}

        source1 = {"a": {"e": 10, "g": 11}}

        self.assertEqual(recursiveOverlayDict(target, source1), {
            "a": {
                "b": {
                    "c": 3
                },
                "d": 4,
                "e": 10,
                "g": 11
            },
            "f": 6
        })

        # value assignment to a dict not allowed
        self.assertRaises(ValueError, recursiveOverlayDict, target, {"a": 4})
        self.assertRaises(ValueError, recursiveOverlayDict, target,
                          {"f": {
                              "r": 2
                          }})

        self.assertEqual(recursiveOverlayDict(target, {"a": {
            "b": {
                "c": 7
            }
        }}), {
            "a": {
                "b": {
                    "c": 7
                },
                "d": 4,
                "e": 5
            },
            "f": 6
        })

        recursiveOverlayDict(target, {"f": 7})
        self.assertRaises(ValueError, recursiveOverlayDict, target, {"f": 7},
                          False)
Ejemplo n.º 4
0
def _changeTarget(jobType, target, dictParams):
    verifyBackendWithNameSpaceType(target)
    testConfiguration()
    jobID = jobType + "_job_" + str(uuid.uuid1())
    logger.info("Starting %s" % jobID)
    with auxiliary.cleanedUpDir(os.path.join(env.tmpDir, jobID),
                                cleanupOnException=True) as tmpDir:
        targetCfg = auxiliary.recursiveOverlayDict(target.getJSONDict(),
                                                   dictParams)
        prepareEnvironment(jobID, tmpDir, None, targetCfg)
        runInEnvironment(tmpDir, [RESTORE_BINARY], jobID)
Ejemplo n.º 5
0
def createAdaptedConfig(tmpDir,
                        sourceCfg,
                        targetCfg,
                        startSnapshot=None,
                        endSnapshot=None):
    testConfiguration()

    if startSnapshot:
        sourceCfg["start_snapshot"] = startSnapshot

    if endSnapshot:
        sourceCfg["end_snapshot"] = endSnapshot

    targetCfg["volume_manager"] = {"tlog_path": os.path.join(tmpDir, "tlogs"),
                                   "metadata_path": os.path.join(tmpDir, "metadata")}

    targetCfg["scocache"] = {"scocache_mount_points":
                             [{"path": os.path.join(tmpDir, "scocache"), "size": "1GiB"}]}

    # keys with non-dict values already specified in cfg are kept
    cfg = getConfigTemplate()

    # bit hacky all this
    if sourceCfg != None:
        cfg = auxiliary.recursiveOverlayDict(
            {"source_configuration": sourceCfg},
            cfg)
    else:
        del cfg["source_configuration"]

    cfg = auxiliary.recursiveOverlayDict({"target_configuration": targetCfg},
                                         cfg)

    cfg["scratch_dir"] = os.path.join(tmpDir, "scratch")

    maybeCreateDirs(cfg)

    configFile = os.path.join(tmpDir, CONFIG_NAME)
    with open(configFile, "w") as fp:
        json.dump(cfg, fp, indent=4)
    return configFile
Ejemplo n.º 6
0
def _changeTarget(jobType, target, dictParams):
    verifyBackendWithNameSpaceType(target)
    testConfiguration()
    jobID = jobType + "_job_" + str(uuid.uuid1())
    logger.info("Starting %s" % jobID)
    with auxiliary.cleanedUpDir(os.path.join(env.tmpDir,
                                             jobID),
                                cleanupOnException=True) as tmpDir:
        targetCfg = auxiliary.recursiveOverlayDict(target.getJSONDict(),
                                                   dictParams)
        prepareEnvironment(jobID,
                           tmpDir,
                           None,
                           targetCfg)
        runInEnvironment(tmpDir, [RESTORE_BINARY], jobID)