def test(self):
     self.assertEqual(utils.FormatKeyValue({}), [])
     self.assertEqual(utils.FormatKeyValue({1: 2}), ["1=2"])
     self.assertEqual(utils.FormatKeyValue({
         "zzz": "0",
         "aaa": "1",
     }), ["aaa=1", "zzz=0"])
Beispiel #2
0
def TestClusterInit(rapi_user, rapi_secret):
    """gnt-cluster init"""
    master = qa_config.GetMasterNode()

    rapi_users_path = qa_utils.MakeNodePath(master, pathutils.RAPI_USERS_FILE)
    rapi_dir = os.path.dirname(rapi_users_path)

    # First create the RAPI credentials
    fh = tempfile.NamedTemporaryFile()
    try:
        fh.write("%s %s write\n" % (rapi_user, rapi_secret))
        fh.flush()

        tmpru = qa_utils.UploadFile(master.primary, fh.name)
        try:
            AssertCommand(["mkdir", "-p", rapi_dir])
            AssertCommand(["mv", tmpru, rapi_users_path])
        finally:
            AssertCommand(["rm", "-f", tmpru])
    finally:
        fh.close()

    # Initialize cluster
    enabled_disk_templates = qa_config.GetEnabledDiskTemplates()
    cmd = [
        "gnt-cluster",
        "init",
        "--primary-ip-version=%d" % qa_config.get("primary_ip_version", 4),
        "--enabled-hypervisors=%s" %
        ",".join(qa_config.GetEnabledHypervisors()),
        "--enabled-disk-templates=%s" % ",".join(enabled_disk_templates),
    ]
    if constants.DT_FILE in enabled_disk_templates:
        cmd.append("--file-storage-dir=%s" % qa_config.get(
            "default-file-storage-dir", pathutils.DEFAULT_FILE_STORAGE_DIR))

    for spec_type in ("mem-size", "disk-size", "disk-count", "cpu-count",
                      "nic-count"):
        for spec_val in ("min", "max", "std"):
            spec = qa_config.get(
                "ispec_%s_%s" % (spec_type.replace("-", "_"), spec_val), None)
            if spec is not None:
                cmd.append("--specs-%s=%s=%d" % (spec_type, spec_val, spec))

    if master.secondary:
        cmd.append("--secondary-ip=%s" % master.secondary)

    if utils.IsLvmEnabled(qa_config.GetEnabledDiskTemplates()):
        vgname = qa_config.get("vg-name", constants.DEFAULT_VG)
        if vgname:
            cmd.append("--vg-name=%s" % vgname)
        else:
            raise qa_error.Error("Please specify a volume group if you enable"
                                 " lvm-based disk templates in the QA.")

    master_netdev = qa_config.get("master-netdev", None)
    if master_netdev:
        cmd.append("--master-netdev=%s" % master_netdev)

    nicparams = qa_config.get("default-nicparams", None)
    if nicparams:
        cmd.append("--nic-parameters=%s" %
                   ",".join(utils.FormatKeyValue(nicparams)))

    # Cluster value of the exclusive-storage node parameter
    e_s = qa_config.get("exclusive-storage")
    if e_s is not None:
        cmd.extend(["--node-parameters", "exclusive_storage=%s" % e_s])
    else:
        e_s = False
    qa_config.SetExclusiveStorage(e_s)

    extra_args = qa_config.get("cluster-init-args")

    if extra_args:
        # This option was removed in 2.10, but in order to not break QA of older
        # branches we remove it from the extra_args if it is in there.
        opt_drbd_storage = "--no-drbd-storage"
        if opt_drbd_storage in extra_args:
            extra_args.remove(opt_drbd_storage)
        cmd.extend(extra_args)

    cmd.append(qa_config.get("name"))

    AssertCommand(cmd)

    cmd = ["gnt-cluster", "modify"]

    # hypervisor parameter modifications
    hvp = qa_config.get("hypervisor-parameters", {})
    for k, v in hvp.items():
        cmd.extend(["-H", "%s:%s" % (k, v)])
    # backend parameter modifications
    bep = qa_config.get("backend-parameters", "")
    if bep:
        cmd.extend(["-B", bep])

    if len(cmd) > 2:
        AssertCommand(cmd)

    # OS parameters
    osp = qa_config.get("os-parameters", {})
    for k, v in osp.items():
        AssertCommand(["gnt-os", "modify", "-O", v, k])

    # OS hypervisor parameters
    os_hvp = qa_config.get("os-hvp", {})
    for os_name in os_hvp:
        for hv, hvp in os_hvp[os_name].items():
            AssertCommand(
                ["gnt-os", "modify", "-H",
                 "%s:%s" % (hv, hvp), os_name])