Commit fa84c8a4 authored by Bernardo Dal Seno's avatar Bernardo Dal Seno

Add QA for instance creation with policy violation

When instance policy is violated, creation fails.
Signed-off-by: default avatarBernardo Dal Seno <bdalseno@google.com>
Reviewed-by: default avatarGuido Trotter <ultrotter@google.com>
parent ab4832d1
......@@ -499,6 +499,8 @@ def TestIPolicyPlainInstance():
(_, old_specs) = qa_cluster.TestClusterSetISpecs({})
node = qa_config.AcquireNode()
try:
# Log of policy changes, list of tuples: (change, policy_violated)
history = []
instance = qa_instance.TestInstanceAddWithPlainDisk([node])
try:
policyerror = [constants.CV_EINSTANCEPOLICY]
......@@ -507,6 +509,7 @@ def TestIPolicyPlainInstance():
(iminval, imaxval) = qa_instance.GetInstanceSpec(instance["name"], par)
# Some specs must be multiple of 4
new_spec = _BuildSpecDict(par, imaxval + 4, imaxval + 4, imaxval + 4)
history.append((new_spec, True))
qa_cluster.TestClusterSetISpecs(new_spec)
qa_cluster.AssertClusterVerify(warnings=policyerror)
if iminval > 0:
......@@ -516,12 +519,22 @@ def TestIPolicyPlainInstance():
else:
upper = iminval - 1
new_spec = _BuildSpecDict(par, 0, upper, upper)
history.append((new_spec, True))
qa_cluster.TestClusterSetISpecs(new_spec)
qa_cluster.AssertClusterVerify(warnings=policyerror)
qa_cluster.TestClusterSetISpecs(old_specs)
history.append((old_specs, False))
qa_instance.TestInstanceRemove(instance)
finally:
qa_config.ReleaseInstance(instance)
# Now we replay the same policy changes, and we expect that the instance
# cannot be created for the cases where we had a policy violation above
for (change, failed) in history:
qa_cluster.TestClusterSetISpecs(change)
if failed:
qa_instance.TestInstanceAddWithPlainDisk([node], fail=True)
# Instance creation with no policy violation has been tested already
finally:
qa_config.ReleaseNode(node)
......
......@@ -63,7 +63,7 @@ def _GetGenericAddParameters(inst, force_mac=None):
return params
def _DiskTest(node, disk_template):
def _DiskTest(node, disk_template, fail=False):
instance = qa_config.AcquireInstance()
try:
cmd = (["gnt-instance", "add",
......@@ -73,16 +73,22 @@ def _DiskTest(node, disk_template):
_GetGenericAddParameters(instance))
cmd.append(instance["name"])
AssertCommand(cmd)
AssertCommand(cmd, fail=fail)
_CheckSsconfInstanceList(instance["name"])
qa_config.SetInstanceTemplate(instance, disk_template)
if not fail:
_CheckSsconfInstanceList(instance["name"])
qa_config.SetInstanceTemplate(instance, disk_template)
return instance
return instance
except:
qa_config.ReleaseInstance(instance)
raise
# Handle the case where creation is expected to fail
assert fail
qa_config.ReleaseInstance(instance)
return None
def _GetInstanceInfo(instance):
"""Return information about the actual state of an instance.
......@@ -257,11 +263,13 @@ def IsDiskReplacingSupported(instance):
return templ == constants.DT_DRBD8
@InstanceCheck(None, INST_UP, RETURN_VALUE)
def TestInstanceAddWithPlainDisk(nodes):
def TestInstanceAddWithPlainDisk(nodes, fail=False):
"""gnt-instance add -t plain"""
assert len(nodes) == 1
return _DiskTest(nodes[0]["primary"], "plain")
instance = _DiskTest(nodes[0]["primary"], constants.DT_PLAIN, fail=fail)
if not fail:
qa_utils.RunInstanceCheck(instance, True)
return instance
@InstanceCheck(None, INST_UP, RETURN_VALUE)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment