Commit 924e95f9 authored by Michael Hanselmann's avatar Michael Hanselmann
Browse files

QA: Test instance creation/deletion via RAPI client


Signed-off-by: default avatarMichael Hanselmann <hansmi@google.com>
Reviewed-by: default avatarGuido Trotter <ultrotter@google.com>
parent 8a47b447
......@@ -311,10 +311,12 @@ def main():
RunTest(qa_rapi.TestNode, pnode)
if qa_config.TestEnabled("instance-add-plain-disk"):
rapi_instance = RunTest(qa_rapi.TestRapiInstanceAdd, pnode)
RunCommonInstanceTests(rapi_instance)
RunTest(qa_rapi.TestRapiInstanceRemove, rapi_instance)
del rapi_instance
for use_client in [True, False]:
rapi_instance = RunTest(qa_rapi.TestRapiInstanceAdd, pnode,
use_client)
RunCommonInstanceTests(rapi_instance)
RunTest(qa_rapi.TestRapiInstanceRemove, rapi_instance, use_client)
del rapi_instance
if qa_config.TestEnabled('instance-add-plain-disk'):
instance = RunTest(qa_instance.TestInstanceAddWithPlainDisk, pnode)
......
......@@ -262,22 +262,41 @@ def _WaitForRapiJob(job_id):
rapi.client_utils.PollJob(_rapi_client, job_id, cli.StdioJobPollReportCb())
def TestRapiInstanceAdd(node):
def TestRapiInstanceAdd(node, use_client):
"""Test adding a new instance via RAPI"""
instance = qa_config.AcquireInstance()
try:
body = {
"name": instance["name"],
"os": qa_config.get("os"),
"disk_template": constants.DT_PLAIN,
"pnode": node["primary"],
"memory": utils.ParseUnit(qa_config.get("mem")),
"disks": [utils.ParseUnit(size) for size in qa_config.get("disk")],
}
(job_id, ) = _DoTests([
("/2/instances", _VerifyReturnsJob, "POST", body),
])
memory = utils.ParseUnit(qa_config.get("mem"))
disk_sizes = [utils.ParseUnit(size) for size in qa_config.get("disk")]
if use_client:
disks = [{"size": size} for size in disk_sizes]
nics = [{}]
beparams = {
constants.BE_MEMORY: memory,
}
job_id = _rapi_client.CreateInstance(constants.INSTANCE_CREATE,
instance["name"],
constants.DT_PLAIN,
disks, nics,
os=qa_config.get("os"),
pnode=node["primary"],
beparams=beparams)
else:
body = {
"name": instance["name"],
"os": qa_config.get("os"),
"disk_template": constants.DT_PLAIN,
"pnode": node["primary"],
"memory": memory,
"disks": disk_sizes,
}
(job_id, ) = _DoTests([
("/2/instances", _VerifyReturnsJob, "POST", body),
])
_WaitForRapiJob(job_id)
......@@ -287,11 +306,14 @@ def TestRapiInstanceAdd(node):
raise
def TestRapiInstanceRemove(instance):
def TestRapiInstanceRemove(instance, use_client):
"""Test removing instance via RAPI"""
(job_id, ) = _DoTests([
("/2/instances/%s" % instance["name"], _VerifyReturnsJob, "DELETE", None),
])
if use_client:
job_id = _rapi_client.DeleteInstance(instance["name"])
else:
(job_id, ) = _DoTests([
("/2/instances/%s" % instance["name"], _VerifyReturnsJob, "DELETE", None),
])
_WaitForRapiJob(job_id)
......
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