Revision ec996117 qa/qa_group.py
b/qa/qa_group.py | ||
---|---|---|
87 | 87 |
@rtype: tuple |
88 | 88 |
@return: (policy, specs), where: |
89 | 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
|
|
90 |
- specs is dict of dict, specs[key][par] is a spec value, where key is
|
|
91 | 91 |
"min" or "max" |
92 | 92 |
|
93 | 93 |
""" |
... | ... | |
98 | 98 |
(ret_policy, ret_specs) = qa_utils.ParseIPolicy(policy) |
99 | 99 |
|
100 | 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 |
|
101 |
assert "min" in ret_specs and "max" in ret_specs |
|
105 | 102 |
assert len(ret_policy) > 0 |
106 | 103 |
return (ret_policy, ret_specs) |
107 | 104 |
|
108 | 105 |
|
109 |
def _TestGroupSetISpecs(groupname, new_specs, fail=False, old_values=None): |
|
106 |
def _TestGroupSetISpecs(groupname, new_specs=None, diff_specs=None, |
|
107 |
fail=False, old_values=None): |
|
110 | 108 |
"""Change instance specs on a group. |
111 | 109 |
|
110 |
At most one of new_specs or diff_specs can be specified. |
|
111 |
|
|
112 | 112 |
@type groupname: string |
113 | 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. |
|
114 |
@type new_specs: dict |
|
115 |
@param new_specs: new complete specs, in the same format returned by |
|
116 |
L{_GetGroupIPolicy} |
|
117 |
@type diff_specs: dict |
|
118 |
@param diff_specs: diff_specs[key][par], where key is "min", "max". It |
|
119 |
can be an incomplete specifications or an empty dictionary. |
|
117 | 120 |
@type fail: bool |
118 | 121 |
@param fail: if the change is expected to fail |
119 | 122 |
@type old_values: tuple |
120 | 123 |
@param old_values: (old_policy, old_specs), as returned by |
121 |
L{_GetGroupIPolicy} |
|
124 |
L{_GetGroupIPolicy}
|
|
122 | 125 |
@return: same as L{_GetGroupIPolicy} |
123 | 126 |
|
124 | 127 |
""" |
125 | 128 |
build_cmd = lambda opts: ["gnt-group", "modify"] + opts + [groupname] |
126 | 129 |
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 |
return qa_utils.TestSetISpecs( |
|
131 |
new_specs=new_specs, diff_specs=diff_specs, |
|
132 |
get_policy_fn=get_policy, build_cmd_fn=build_cmd, |
|
133 |
fail=fail, old_values=old_values) |
|
130 | 134 |
|
131 | 135 |
|
132 | 136 |
def _TestGroupModifyISpecs(groupname): |
133 | 137 |
# This test is built on the assumption that the default ipolicy holds for |
134 | 138 |
# the node group under test |
135 | 139 |
old_values = _GetGroupIPolicy(groupname) |
136 |
mod_values = _TestGroupSetISpecs(groupname,
|
|
137 |
dict((p, {"min": 4, "max": 4})
|
|
138 |
for p in constants.ISPECS_PARAMETERS),
|
|
140 |
samevals = dict((p, 4) for p in constants.ISPECS_PARAMETERS)
|
|
141 |
base_specs = {"min": samevals, "max": samevals}
|
|
142 |
mod_values = _TestGroupSetISpecs(groupname, new_specs=base_specs,
|
|
139 | 143 |
old_values=old_values) |
140 | 144 |
for par in constants.ISPECS_PARAMETERS: |
141 | 145 |
# First make sure that the test works with good values |
142 |
mod_values = _TestGroupSetISpecs(groupname, {par: {"min": 8, "max": 8}}, |
|
146 |
good_specs = {"min": {par: 8}, "max": {par: 8}} |
|
147 |
mod_values = _TestGroupSetISpecs(groupname, diff_specs=good_specs, |
|
143 | 148 |
old_values=mod_values) |
144 |
_TestGroupSetISpecs(groupname, {par: {"min": 8, "max": 4}}, |
|
145 |
fail=True, old_values=mod_values) |
|
149 |
bad_specs = {"min": {par: 8}, "max": {par: 4}} |
|
150 |
_TestGroupSetISpecs(groupname, diff_specs=bad_specs, fail=True, |
|
151 |
old_values=mod_values) |
|
146 | 152 |
AssertCommand(["gnt-group", "modify", "--ipolicy-bounds-specs", "default", |
147 | 153 |
groupname]) |
148 | 154 |
AssertEqual(_GetGroupIPolicy(groupname), old_values) |
Also available in: Unified diff