Revision cbaf1652 qa/qa_group.py
b/qa/qa_group.py | ||
---|---|---|
79 | 79 |
AssertCommand(["gnt-group", "remove", group1]) |
80 | 80 |
|
81 | 81 |
|
82 |
def _GetGroupIPolicy(groupname): |
|
83 |
"""Return the run-time values of the cluster-level instance policy. |
|
84 |
|
|
85 |
@type groupname: string |
|
86 |
@param groupname: node group name |
|
87 |
@rtype: tuple |
|
88 |
@return: (policy, specs), where: |
|
89 |
- policy is a dictionary of the policy values, instance specs excluded |
|
90 |
- specs is dict of dict, specs[par][key] is a spec value, where key is |
|
91 |
"min" or "max" |
|
92 |
|
|
93 |
""" |
|
94 |
info = qa_utils.GetObjectInfo(["gnt-group", "info", groupname]) |
|
95 |
assert len(info) == 1 |
|
96 |
policy = info[0]["Instance policy"] |
|
97 |
|
|
98 |
(ret_policy, ret_specs) = qa_utils.ParseIPolicy(policy) |
|
99 |
|
|
100 |
# Sanity checks |
|
101 |
assert len(ret_specs) > 0 |
|
102 |
good = all("min" in d and "max" in d |
|
103 |
for d in ret_specs.values()) |
|
104 |
assert good, "Missing item in specs: %s" % ret_specs |
|
105 |
assert len(ret_policy) > 0 |
|
106 |
return (ret_policy, ret_specs) |
|
107 |
|
|
108 |
|
|
109 |
def _TestGroupSetISpecs(groupname, new_specs, fail=False, old_values=None): |
|
110 |
"""Change instance specs on a group. |
|
111 |
|
|
112 |
@type groupname: string |
|
113 |
@param groupname: group name |
|
114 |
@type new_specs: dict of dict |
|
115 |
@param new_specs: new_specs[par][key], where key is "min", "max", "std". It |
|
116 |
can be an empty dictionary. |
|
117 |
@type fail: bool |
|
118 |
@param fail: if the change is expected to fail |
|
119 |
@type old_values: tuple |
|
120 |
@param old_values: (old_policy, old_specs), as returned by |
|
121 |
L{_GetGroupIPolicy} |
|
122 |
@return: same as L{_GetGroupIPolicy} |
|
123 |
|
|
124 |
""" |
|
125 |
build_cmd = lambda opts: ["gnt-group", "modify"] + opts + [groupname] |
|
126 |
get_policy = lambda: _GetGroupIPolicy(groupname) |
|
127 |
return qa_utils.TestSetISpecs(new_specs, get_policy_fn=get_policy, |
|
128 |
build_cmd_fn=build_cmd, fail=fail, |
|
129 |
old_values=old_values) |
|
130 |
|
|
131 |
|
|
82 | 132 |
def _TestGroupModifyISpecs(groupname): |
133 |
# This test is built on the assumption that the default ipolicy holds for |
|
134 |
# the node group under test |
|
135 |
old_values = _GetGroupIPolicy(groupname) |
|
136 |
mod_values = _TestGroupSetISpecs(groupname, |
|
137 |
dict((p, {"min": 4, "max": 4}) |
|
138 |
for p in constants.ISPECS_PARAMETERS), |
|
139 |
old_values=old_values) |
|
140 |
for par in constants.ISPECS_PARAMETERS: |
|
141 |
# First make sure that the test works with good values |
|
142 |
mod_values = _TestGroupSetISpecs(groupname, {par: {"min": 8, "max": 8}}, |
|
143 |
old_values=mod_values) |
|
144 |
_TestGroupSetISpecs(groupname, {par: {"min": 8, "max": 4}}, |
|
145 |
fail=True, old_values=mod_values) |
|
146 |
AssertCommand(["gnt-group", "modify", "--ipolicy-bounds-specs", "default", |
|
147 |
groupname]) |
|
148 |
AssertEqual(_GetGroupIPolicy(groupname), old_values) |
|
149 |
|
|
83 | 150 |
# Get the ipolicy command (from the cluster config) |
84 | 151 |
mnode = qa_config.GetMasterNode() |
85 | 152 |
addcmd = GetCommandOutput(mnode.primary, utils.ShellQuoteArgs([ |
... | ... | |
103 | 170 |
|
104 | 171 |
def _TestGroupModifyIPolicy(groupname): |
105 | 172 |
_TestGroupModifyISpecs(groupname) |
106 |
AssertCommand(["gnt-group", "modify", "--ipolicy-vcpu-ratio", |
|
107 |
"3.5", groupname]) |
|
108 |
AssertCommand(["gnt-group", "modify", "--ipolicy-vcpu-ratio", |
|
109 |
"default", groupname]) |
|
173 |
|
|
174 |
# We assume that the default ipolicy holds |
|
175 |
(old_policy, old_specs) = _GetGroupIPolicy(groupname) |
|
176 |
for (par, setval, iname, expval) in [ |
|
177 |
("vcpu-ratio", 1.5, None, 1.5), |
|
178 |
("spindle-ratio", 1.5, None, 1.5), |
|
179 |
("disk-templates", constants.DT_PLAIN, |
|
180 |
"enabled disk templates", constants.DT_PLAIN) |
|
181 |
]: |
|
182 |
if not iname: |
|
183 |
iname = par |
|
184 |
build_cmdline = lambda val: ["gnt-group", "modify", "--ipolicy-" + par, |
|
185 |
str(val), groupname] |
|
186 |
|
|
187 |
AssertCommand(build_cmdline(setval)) |
|
188 |
(new_policy, new_specs) = _GetGroupIPolicy(groupname) |
|
189 |
AssertEqual(new_specs, old_specs) |
|
190 |
for (p, val) in new_policy.items(): |
|
191 |
if p == iname: |
|
192 |
AssertEqual(val, expval) |
|
193 |
else: |
|
194 |
AssertEqual(val, old_policy[p]) |
|
195 |
|
|
196 |
AssertCommand(build_cmdline("default")) |
|
197 |
(new_policy, new_specs) = _GetGroupIPolicy(groupname) |
|
198 |
AssertEqual(new_specs, old_specs) |
|
199 |
AssertEqual(new_policy, old_policy) |
|
110 | 200 |
|
111 | 201 |
|
112 | 202 |
def TestGroupModify(): |
Also available in: Unified diff