Switch to the new Rally API

Use the new API classes in CLI and other parts of Rally code
(still leaving old API methods for compability).

ToDo in next patches:
 * Remove old API methods
 * add get(), list() methods to API.

Change-Id: I1eca518bca8b383e3e6ce05e99251c2d954f1b4e
This commit is contained in:
Mikhail Dubov 2015-01-27 18:54:05 +03:00
parent e2a204d35b
commit e2ebfa55e4
11 changed files with 47 additions and 49 deletions

View File

@ -113,7 +113,7 @@ class DeploymentCommands(object):
config = yaml.safe_load(deploy_file.read())
try:
deployment = api.create_deploy(config, name)
deployment = api.Deployment.create(config, name)
except jsonschema.ValidationError:
print(_("Config schema validation error: %s.") % sys.exc_info()[1])
return(1)
@ -139,7 +139,7 @@ class DeploymentCommands(object):
:param deployment: a UUID or name of the deployment
"""
api.recreate_deploy(deployment)
api.Deployment.recreate(deployment)
@cliutils.deprecated_args(
"--uuid", dest="deployment", type=str,
@ -156,7 +156,7 @@ class DeploymentCommands(object):
:param deployment: a UUID or name of the deployment
"""
api.destroy_deploy(deployment)
api.Deployment.destroy(deployment)
def list(self, deployment_list=None):
"""List existing deployments."""

View File

@ -105,7 +105,7 @@ class TaskCommands(object):
with open(task_file) as f:
try:
input_task = f.read()
rendered_task = api.task_template_render(input_task, **kw)
rendered_task = api.Task.render_template(input_task, **kw)
except Exception as e:
print(_("Failed to render task template:\n%(task)s\n%(err)s\n")
% {"task": input_task, "err": e},
@ -157,7 +157,7 @@ class TaskCommands(object):
return(1)
try:
api.task_validate(deployment, input_task)
api.Task.validate(deployment, input_task)
print("Task config is valid :)")
except exceptions.InvalidTaskException as e:
print("Task config is invalid: \n")
@ -200,14 +200,14 @@ class TaskCommands(object):
return(1)
try:
task = api.create_task(deployment, tag)
task = api.Task.create(deployment, tag)
print(cliutils.make_header(
_("Task %(tag)s %(uuid)s: started")
% {"uuid": task["uuid"], "tag": task["tag"]}))
print("Benchmarking... This can take a while...\n")
print("To track task status use:\n")
print("\trally task status\n\tor\n\trally task detailed\n")
api.start_task(deployment, input_task, task=task)
api.Task.start(deployment, input_task, task=task)
self.detailed(task_id=task["uuid"])
if do_use:
use.UseCommands().task(task["uuid"])
@ -222,7 +222,7 @@ class TaskCommands(object):
:param task_id: Task uuid
"""
api.abort_task(task_id)
api.Task.abort(task_id)
@cliutils.args("--uuid", type=str, dest="task_id", help="UUID of task")
@envutils.with_default_task_id
@ -572,9 +572,9 @@ class TaskCommands(object):
if isinstance(task_id, list):
for tid in task_id:
api.delete_task(tid, force=force)
api.Task.delete(tid, force=force)
else:
api.delete_task(task_id, force=force)
api.Task.delete(task_id, force=force)
@cliutils.args("--uuid", type=str, dest="task_id", help="uuid of task")
@cliutils.args("--json", dest="tojson",

View File

@ -80,8 +80,8 @@ class VerifyCommands(object):
"choose from: %s" % ", ".join(list(consts.TempestTestsSets) +
list(consts.TempestTestsAPI)))
return (1)
verification = api.verify(deployment, set_name, regex,
tempest_config)
verification = api.Verification.verify(deployment, set_name, regex,
tempest_config)
if do_use:
use.UseCommands().verification(verification["uuid"])

View File

@ -47,8 +47,8 @@ class TempestCommands(object):
"from.")
@envutils.with_default_deployment(cli_arg_name="deployment")
def install(self, deployment=None, source=None):
"""Install tempest."""
api.install_tempest(deployment, source)
"""Install Tempest."""
api.Verification.install_tempest(deployment, source)
def main():

View File

@ -97,4 +97,4 @@ class MultihostEngine(engine.EngineFactory):
def cleanup(self):
subdeploys = db.deployment_list(parent_uuid=self.deployment["uuid"])
for subdeploy in subdeploys:
rally.api.destroy_deploy(subdeploy["uuid"])
rally.api.Deployment.destroy(subdeploy["uuid"])

View File

@ -30,7 +30,7 @@ class DeploymentCommandsTestCase(test.TestCase):
@mock.patch.dict(os.environ, {'RALLY_DEPLOYMENT': 'my_deployment_id'})
@mock.patch('rally.cmd.commands.deployment.DeploymentCommands.list')
@mock.patch('rally.cmd.commands.deployment.api.create_deploy')
@mock.patch('rally.cmd.commands.deployment.api.Deployment.create')
@mock.patch('rally.cmd.commands.deployment.open',
mock.mock_open(read_data='{"some": "json"}'),
create=True)
@ -44,7 +44,7 @@ class DeploymentCommandsTestCase(test.TestCase):
'OS_TENANT_NAME': 'fake_tenant_name',
'OS_REGION_NAME': 'fake_region_name',
'RALLY_DEPLOYMENT': 'fake_deployment_id'})
@mock.patch('rally.cmd.commands.deployment.api.create_deploy')
@mock.patch('rally.cmd.commands.deployment.api.Deployment.create')
@mock.patch('rally.cmd.commands.deployment.DeploymentCommands.list')
def test_createfromenv(self, mock_list, mock_create):
self.deployment.create('from_env', True)
@ -64,7 +64,7 @@ class DeploymentCommandsTestCase(test.TestCase):
@mock.patch('rally.cmd.commands.deployment.DeploymentCommands.list')
@mock.patch('rally.cmd.commands.use.UseCommands.deployment')
@mock.patch('rally.cmd.commands.deployment.api.create_deploy',
@mock.patch('rally.cmd.commands.deployment.api.Deployment.create',
return_value=dict(uuid='uuid'))
@mock.patch('rally.cmd.commands.deployment.open',
mock.mock_open(read_data='{"uuid": "uuid"}'),
@ -76,7 +76,7 @@ class DeploymentCommandsTestCase(test.TestCase):
mock_create.assert_called_once_with({'uuid': 'uuid'}, 'fake_deploy')
mock_use_deployment.assert_called_once_with('uuid')
@mock.patch('rally.cmd.commands.deployment.api.recreate_deploy')
@mock.patch('rally.cmd.commands.deployment.api.Deployment.recreate')
def test_recreate(self, mock_recreate):
deployment_id = '43924f8b-9371-4152-af9f-4cf02b4eced4'
self.deployment.recreate(deployment_id)
@ -88,7 +88,7 @@ class DeploymentCommandsTestCase(test.TestCase):
self.assertRaises(exceptions.InvalidArgumentsException,
self.deployment.recreate, None)
@mock.patch('rally.cmd.commands.deployment.api.destroy_deploy')
@mock.patch('rally.cmd.commands.deployment.api.Deployment.destroy')
def test_destroy(self, mock_destroy):
deployment_id = '53fd0273-60ce-42e5-a759-36f1a683103e'
self.deployment.destroy(deployment_id)

View File

@ -100,8 +100,8 @@ class TaskCommandsTestCase(test.TestCase):
@mock.patch("rally.cmd.commands.task.TaskCommands.detailed")
@mock.patch("rally.cmd.commands.task.TaskCommands._load_task",
return_value={"some": "json"})
@mock.patch("rally.api.create_task")
@mock.patch("rally.cmd.commands.task.api.start_task")
@mock.patch("rally.api.Task.create")
@mock.patch("rally.cmd.commands.task.api.Task.start")
def test_start(self, mock_api, mock_create_task, mock_load,
mock_task_detailed):
mock_create_task.return_value = (
@ -134,22 +134,22 @@ class TaskCommandsTestCase(test.TestCase):
@mock.patch("rally.cmd.commands.task.TaskCommands._load_task")
@mock.patch("rally.cmd.commands.task.api")
def test_start_invalid_task(self, mock_api, mock_load):
mock_api.start_task.side_effect = exceptions.InvalidConfigException
mock_api.Task.start.side_effect = exceptions.InvalidConfigException
result = self.task.start("task_path", "deployment", tag="tag")
self.assertEqual(1, result)
mock_api.create_task.assert_called_once_with("deployment", "tag")
mock_api.start_task.assert_called_once_with(
mock_api.Task.create.assert_called_once_with("deployment", "tag")
mock_api.Task.start.assert_called_once_with(
"deployment", mock_load.return_value,
task=mock_api.create_task.return_value)
task=mock_api.Task.create.return_value)
@mock.patch("rally.cmd.commands.task.api")
def test_abort(self, mock_api):
test_uuid = "17860c43-2274-498d-8669-448eff7b073f"
mock_api.abort_task = mock.MagicMock()
mock_api.Task.abort = mock.MagicMock()
self.task.abort(test_uuid)
task.api.abort_task.assert_called_once_with(test_uuid)
task.api.Task.abort.assert_called_once_with(test_uuid)
@mock.patch("rally.cmd.commands.task.envutils.get_global")
def test_abort_no_task_id(self, mock_default):
@ -523,9 +523,9 @@ class TaskCommandsTestCase(test.TestCase):
task_uuid = "8dcb9c5e-d60b-4022-8975-b5987c7833f7"
force = False
with mock.patch("rally.cmd.commands.task.api") as mock_api:
mock_api.delete_task = mock.Mock()
mock_api.Task.delete = mock.Mock()
self.task.delete(task_uuid, force=force)
mock_api.delete_task.assert_called_once_with(task_uuid,
mock_api.Task.delete.assert_called_once_with(task_uuid,
force=force)
@mock.patch("rally.cmd.commands.task.api")
@ -536,10 +536,10 @@ class TaskCommandsTestCase(test.TestCase):
"018af931-0e5a-40d5-9d6f-b13f4a3a09fc"]
force = False
self.task.delete(task_uuids, force=force)
self.assertTrue(mock_api.delete_task.call_count == len(task_uuids))
self.assertTrue(mock_api.Task.delete.call_count == len(task_uuids))
expected_calls = [mock.call(task_uuid, force=force) for task_uuid
in task_uuids]
self.assertTrue(mock_api.delete_task.mock_calls == expected_calls)
self.assertTrue(mock_api.Task.delete.mock_calls == expected_calls)
@mock.patch("rally.cmd.commands.task.common_cliutils.print_list")
@mock.patch("rally.cmd.commands.task.objects.Task.get")
@ -569,7 +569,7 @@ class TaskCommandsTestCase(test.TestCase):
@mock.patch("rally.cmd.commands.task.open",
mock.mock_open(read_data="{\"some\": \"json\"}"),
create=True)
@mock.patch("rally.api.task_validate")
@mock.patch("rally.api.Task.validate")
def test_validate(self, mock_validate):
self.task.validate("path_to_config.json", "fake_id")
mock_validate.assert_called_once_with("fake_id", {"some": "json"})
@ -586,7 +586,7 @@ class TaskCommandsTestCase(test.TestCase):
mock_load.assert_called_once_with("path_to_task", args, args_file)
@mock.patch("rally.cmd.commands.task.TaskCommands._load_task")
@mock.patch("rally.api.task_validate")
@mock.patch("rally.api.Task.validate")
def test_validate_invalid(self, mock_task_validate, mock_load):
mock_task_validate.side_effect = exceptions.InvalidTaskException

View File

@ -46,7 +46,7 @@ class VerifyCommandsTestCase(test.TestCase):
self.flavor2.ram = 64
@mock.patch("rally.osclients.Clients")
@mock.patch("rally.api.verify")
@mock.patch("rally.api.Verification.verify")
def test_start(self, mock_verify, mock_clients):
deployment_id = "0fba91c6-82d5-4ce1-bd00-5d7c989552d9"
mock_clients().glance().images.list.return_value = [
@ -63,7 +63,7 @@ class VerifyCommandsTestCase(test.TestCase):
None)
@mock.patch("rally.osclients.Clients")
@mock.patch("rally.api.verify")
@mock.patch("rally.api.Verification.verify")
def test_start_with_user_specified_tempest_config(self, mock_verify,
mock_clients):
deployment_id = "0fba91c6-82d5-4ce1-bd00-5d7c989552d9"
@ -82,7 +82,7 @@ class VerifyCommandsTestCase(test.TestCase):
tempest_config.name)
tempest_config.close()
@mock.patch("rally.api.verify")
@mock.patch("rally.api.Verification.verify")
def test_start_with_wrong_set_name(self, mock_verify):
deployment_id = "f2009aae-6ef3-468e-96b2-3c987d584010"

View File

@ -37,7 +37,7 @@ class DBCommandsTestCase(test.TestCase):
super(DBCommandsTestCase, self).setUp()
self.db_commands = manage.DBCommands()
@mock.patch('rally.cmd.manage.db')
@mock.patch("rally.cmd.manage.db")
def test_recreate(self, mock_db):
self.db_commands.recreate()
calls = [mock.call.db_drop(), mock.call.db_create()]
@ -51,11 +51,9 @@ class TempestCommandsTestCase(test.TestCase):
self.tempest_commands = manage.TempestCommands()
self.tempest = mock.Mock()
@mock.patch("rally.cmd.manage.db.deployment_get",
return_value={"uuid": "e24b5af0-0e2a-4a70-9443-b30a88ab152e"})
@mock.patch("rally.verification.tempest.tempest.Tempest")
def test_install(self, mock_tempest, mock_d_get):
deployment_id = mock_d_get.return_value["uuid"]
mock_tempest.return_value = self.tempest
self.tempest_commands.install(deployment_id)
self.tempest.install.assert_called_once_with()
@mock.patch("rally.cmd.manage.api")
def test_install(self, mock_api):
deployment_uuid = "deployment_uuid"
self.tempest_commands.install(deployment_uuid)
mock_api.Verification.install_tempest.assert_called_once_with(
deployment_uuid, None)

View File

@ -108,7 +108,7 @@ class TestMultihostEngine(test.TestCase):
{'uuid': 'uuid2'}]
self.engine.cleanup()
api_calls = [
mock.call.destroy_deploy('uuid1'),
mock.call.destroy_deploy('uuid2'),
mock.call.Deployment.destroy('uuid1'),
mock.call.Deployment.destroy('uuid2'),
]
self.assertEqual(api_calls, m_api.mock_calls)

View File

@ -51,7 +51,7 @@ class RallyJobsTestCase(test.TestCase):
"args file %s must be dict in yaml or json "
"presenatation" % args_file)
task = api.task_template_render(task_file.read(), **args)
task = api.Task.render_template(task_file.read(), **args)
task = yaml.safe_load(task)
eng = engine.BenchmarkEngine(task, mock.MagicMock())