"""
info = qa_utils.GetObjectInfo(["gnt-cluster", "info"])
policy = info["Instance policy - limits for instances"]
- ret_specs = {}
- ret_policy = {}
- ispec_keys = constants.ISPECS_MINMAX_KEYS | frozenset([constants.ISPECS_STD])
- for (key, val) in policy.items():
- if key in ispec_keys:
- for (par, pval) in val.items():
- if par == "memory-size":
- par = "mem-size"
- d = ret_specs.setdefault(par, {})
- d[key] = pval
- else:
- ret_policy[key] = val
+ (ret_policy, ret_specs) = qa_utils.ParseIPolicy(policy)
# Sanity checks
assert len(ret_specs) > 0
@return: same as L{_GetClusterIPolicy}
"""
- if old_values:
- (old_policy, old_specs) = old_values
- else:
- (old_policy, old_specs) = _GetClusterIPolicy()
- if new_specs:
- cmd = ["gnt-cluster", "modify"]
- for (par, keyvals) in new_specs.items():
- if par == "spindle-use":
- # ignore spindle-use, which is not settable
- continue
- cmd += [
- "--specs-%s" % par,
- ",".join(["%s=%s" % (k, v) for (k, v) in keyvals.items()]),
- ]
- AssertCommand(cmd, fail=fail)
- # Check the new state
- (eff_policy, eff_specs) = _GetClusterIPolicy()
- AssertEqual(eff_policy, old_policy)
- if fail:
- AssertEqual(eff_specs, old_specs)
- else:
- for par in eff_specs:
- for key in eff_specs[par]:
- if par in new_specs and key in new_specs[par]:
- AssertEqual(int(eff_specs[par][key]), int(new_specs[par][key]))
- else:
- AssertEqual(int(eff_specs[par][key]), int(old_specs[par][key]))
- return (eff_policy, eff_specs)
+ build_cmd = lambda opts: ["gnt-cluster", "modify"] + opts
+ return qa_utils.TestSetISpecs(new_specs, get_policy_fn=_GetClusterIPolicy,
+ build_cmd_fn=build_cmd, fail=fail,
+ old_values=old_values)
def TestClusterModifyISpecs():
"""gnt-cluster modify --specs-*"""
- params = ["mem-size", "disk-size", "disk-count", "cpu-count", "nic-count"]
+ params = ["memory-size", "disk-size", "disk-count", "cpu-count", "nic-count"]
(cur_policy, cur_specs) = _GetClusterIPolicy()
for par in params:
test_values = [
(cur_policy, cur_specs) = TestClusterSetISpecs(new_vals, fail=not good,
old_values=cur_state)
+ # Get the ipolicy command
+ mnode = qa_config.GetMasterNode()
+ initcmd = GetCommandOutput(mnode.primary, "gnt-cluster show-ispecs-cmd")
+ modcmd = ["gnt-cluster", "modify"]
+ opts = initcmd.split()
+ assert opts[0:2] == ["gnt-cluster", "init"]
+ for k in range(2, len(opts) - 1):
+ if opts[k].startswith("--ipolicy-"):
+ assert k + 2 <= len(opts)
+ modcmd.extend(opts[k:k + 2])
+ # Re-apply the ipolicy (this should be a no-op)
+ AssertCommand(modcmd)
+ new_initcmd = GetCommandOutput(mnode.primary, "gnt-cluster show-ispecs-cmd")
+ AssertEqual(initcmd, new_initcmd)
+
def TestClusterInfo():
"""gnt-cluster info"""