#
-# Copyright (C) 2007, 2008 Google Inc.
+# Copyright (C) 2007, 2008, 2009, 2010 Google Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
for uri, verify, method, body in uris:
assert uri.startswith("/")
+ print "%s %s" % (method, uri)
data = _rapi_client._SendRequest(method, uri, None, body)
if verify is not None:
else:
AssertEqual(data, verify)
- results.append(data)
+ results.append(data)
return results
("/2/os", None, 'GET', None),
])
+ # Test HTTP Not Found
+ for method in ["GET", "PUT", "POST", "DELETE"]:
+ try:
+ _DoTests([("/99/resource/not/here/99", None, method, None)])
+ except rapi.client.GanetiApiError, err:
+ AssertEqual(err.code, 404)
+ else:
+ raise qa_error.Error("Non-existent resource didn't return HTTP 404")
+
+ # Test HTTP Not Implemented
+ for method in ["PUT", "POST", "DELETE"]:
+ try:
+ _DoTests([("/version", None, method, None)])
+ except rapi.client.GanetiApiError, err:
+ AssertEqual(err.code, 501)
+ else:
+ raise qa_error.Error("Non-implemented method didn't fail")
+
def TestInstance(instance):
"""Testing getting instance(s) info via remote API.
def _VerifyTags(data):
AssertEqual(sorted(tags), sorted(data))
+ query = "&".join("tag=%s" % i for i in tags)
+
+ # Add tags
+ (job_id, ) = _DoTests([
+ ("%s?%s" % (uri, query), _VerifyReturnsJob, "PUT", None),
+ ])
+ _WaitForRapiJob(job_id)
+
+ # Retrieve tags
_DoTests([
(uri, _VerifyTags, 'GET', None),
])
+ # Remove tags
+ (job_id, ) = _DoTests([
+ ("%s?%s" % (uri, query), _VerifyReturnsJob, "DELETE", None),
+ ])
+ _WaitForRapiJob(job_id)
+
def _WaitForRapiJob(job_id):
"""Waits for a job to finish.
_WaitForRapiJob(_rapi_client.RenameInstance(name1, name2))
-def TestInterClusterInstanceMove(src_instance, dest_instance, pnode, snode):
+def TestRapiInstanceModify(instance):
+ """Test modifying instance via RAPI"""
+ def _ModifyInstance(**kwargs):
+ _WaitForRapiJob(_rapi_client.ModifyInstance(instance["name"], **kwargs))
+
+ _ModifyInstance(hvparams={
+ constants.HV_KERNEL_ARGS: "single",
+ })
+
+ _ModifyInstance(beparams={
+ constants.BE_VCPUS: 3,
+ })
+
+ _ModifyInstance(beparams={
+ constants.BE_VCPUS: constants.VALUE_DEFAULT,
+ })
+
+ _ModifyInstance(hvparams={
+ constants.HV_KERNEL_ARGS: constants.VALUE_DEFAULT,
+ })
+
+
+def TestInterClusterInstanceMove(src_instance, dest_instance,
+ pnode, snode, tnode):
"""Test tools/move-instance"""
master = qa_config.GetMasterNode()
rapi_pw_file.flush()
# TODO: Run some instance tests before moving back
- for srcname, destname in [(src_instance["name"], dest_instance["name"]),
- (dest_instance["name"], src_instance["name"])]:
+
+ if snode is None:
+ # instance is not redundant, but we still need to pass a node
+ # (which will be ignored)
+ fsec = tnode
+ else:
+ fsec = snode
+ # note: pnode:snode are the *current* nodes, so we move it first to
+ # tnode:pnode, then back to pnode:snode
+ for si, di, pn, sn in [(src_instance["name"], dest_instance["name"],
+ tnode["primary"], pnode["primary"]),
+ (dest_instance["name"], src_instance["name"],
+ pnode["primary"], fsec["primary"])]:
cmd = [
"../tools/move-instance",
"--verbose",
"--src-ca-file=%s" % _rapi_ca.name,
"--src-username=%s" % _rapi_username,
"--src-password-file=%s" % rapi_pw_file.name,
- "--dest-instance-name=%s" % destname,
- "--dest-primary-node=%s" % pnode["primary"],
- "--dest-secondary-node=%s" % snode["primary"],
-
+ "--dest-instance-name=%s" % di,
+ "--dest-primary-node=%s" % pn,
+ "--dest-secondary-node=%s" % sn,
+ "--net=0:mac=%s" % constants.VALUE_GENERATE,
master["primary"],
master["primary"],
- srcname,
+ si,
]
AssertEqual(StartLocalCommand(cmd).wait(), 0)