diff --git a/contrib/devstack/exercises/rally.sh b/contrib/devstack/exercises/rally.sh deleted file mode 100644 index d2728b5862..0000000000 --- a/contrib/devstack/exercises/rally.sh +++ /dev/null @@ -1,46 +0,0 @@ -#!/usr/bin/env bash - -# **rally.sh** - -echo "*********************************************************************" -echo "Begin DevStack Exercise: $0" -echo "*********************************************************************" - -# This script exits on an error so that errors don't compound and you see -# only the first error that occurred. -set -o errexit - -# Print the commands being run so that we can see the command that triggers -# an error. It is also useful for following allowing as the install occurs. -set -o xtrace - - -# Settings -# ======== - -# Keep track of the current directory -EXERCISE_DIR=$(cd $(dirname "$0") && pwd) -TOP_DIR=$(cd $EXERCISE_DIR/..; pwd) - -# Import common functions -source $TOP_DIR/functions - -# Import configuration -source $TOP_DIR/openrc - -# Import exercise configuration -source $TOP_DIR/exerciserc - -is_service_enabled rally || exit 55 - -# Import rally functions -source $TOP_DIR/lib/rally - -# Run tests -run_all_benchmarks - -set +o xtrace -echo "*********************************************************************" -echo "SUCCESS: End DevStack Exercise: $0" -echo "*********************************************************************" - diff --git a/contrib/devstack/lib/rally b/contrib/devstack/lib/rally index 235ecf7479..ed719fc45e 100644 --- a/contrib/devstack/lib/rally +++ b/contrib/devstack/lib/rally @@ -123,20 +123,6 @@ function init_rally() { fi } -# Run benchmarks from samples dir -function run_all_benchmarks() { - for CONF in $DEST/rally/doc/samples/tasks/*/*.yaml; do - case "$CONF" in - *large-ops*) - echo "Skipping large-ops benchmarks." - ;; - *) - rally task start --task $CONF - ;; - esac - done -} - # Restore xtrace $XTRACE diff --git a/rally-scenarios/rally.yaml b/rally-scenarios/rally.yaml new file mode 100644 index 0000000000..1c2e5120b6 --- /dev/null +++ b/rally-scenarios/rally.yaml @@ -0,0 +1,18 @@ +--- + KeystoneBasic.create_delete_user: + - + args: + name_length: 10 + runner: + type: "constant" + times: 10 + concurrency: 10 + + KeystoneBasic.create_and_list_tenants: + - + args: + name_length: 10 + runner: + type: "constant" + times: 10 + concurrency: 10 diff --git a/rally/cmd/commands/use.py b/rally/cmd/commands/use.py index 64e31cda5b..c99cb664a4 100644 --- a/rally/cmd/commands/use.py +++ b/rally/cmd/commands/use.py @@ -16,7 +16,6 @@ """ Rally command: use """ import os -import sys from rally.cmd import cliutils from rally import db @@ -58,14 +57,34 @@ class UseCommands(object): @cliutils.args('--uuid', type=str, dest='deploy_id', required=False, help='UUID of the deployment') - def deployment(self, deploy_id): + @cliutils.args('--name', type=str, dest='name', required=False, + help='Name of the deployment') + def deployment(self, deploy_id=None, name=None): """Set the RALLY_DEPLOYMENT env var to be used by all CLI commands :param deploy_id: a UUID of a deployment """ - print('Using deployment: %s' % deploy_id) + if not (name or deploy_id): + print('You should specify --name or --uuid of deployment') + return 1 + + deploy = None + + if name: + deployments = db.deployment_list(name=name) + if len(deployments) > 1: + print("Multiple deployments found by name: `%s`" % name) + return 1 + elif not deployments: + print("There is no `%s` deployment" % name) + return 1 + else: + deploy = deployments[0] + deploy_id = deploy["uuid"] + try: - deploy = db.deployment_get(deploy_id) + deploy = deploy or db.deployment_get(deploy_id) + print('Using deployment: %s' % deploy_id) self._ensure_rally_configuration_dir_exists() self._update_attribute_in_global_file('RALLY_DEPLOYMENT', deploy_id) @@ -80,7 +99,7 @@ class UseCommands(object): 'glance image-list') except exceptions.DeploymentNotFound: print('Deployment %s is not found.' % deploy_id) - sys.exit(1) + return 1 @cliutils.args('--uuid', type=str, dest='task_id', required=False, help='UUID of the task') diff --git a/rally/db/api.py b/rally/db/api.py index 0ef5bb7de8..88accbed50 100644 --- a/rally/db/api.py +++ b/rally/db/api.py @@ -204,15 +204,17 @@ def deployment_update(uuid, values): return IMPL.deployment_update(uuid, values) -def deployment_list(status=None, parent_uuid=None): +def deployment_list(status=None, parent_uuid=None, name=None): """Get list of deployments. :param status: if None returns any deployments with any status. :param parent_uuid: filter by parent. If None, return only "root" deployments. + :param name: Name of deployment :returns: a list of dicts with data on the deployments. """ - return IMPL.deployment_list(status=status, parent_uuid=parent_uuid) + return IMPL.deployment_list(status=status, parent_uuid=parent_uuid, + name=name) def resource_create(values): diff --git a/rally/db/sqlalchemy/api.py b/rally/db/sqlalchemy/api.py index 8af348a674..f8e652221c 100644 --- a/rally/db/sqlalchemy/api.py +++ b/rally/db/sqlalchemy/api.py @@ -22,6 +22,7 @@ import sqlalchemy as sa from rally.db.sqlalchemy import models from rally import exceptions from rally.openstack.common.db.sqlalchemy import session as db_session +from rally.openstack.common.gettextutils import _ CONF = cfg.CONF @@ -209,10 +210,13 @@ class Connection(object): deploy.update(values) return deploy - def deployment_list(self, status=None, parent_uuid=None): + def deployment_list(self, status=None, parent_uuid=None, name=None): query = self.model_query(models.Deployment).\ filter_by(parent_uuid=parent_uuid) - if status is not None: + + if name: + query = query.filter_by(name=name) + if status: query = query.filter_by(status=status) return query.all() diff --git a/tests/cmd/commands/test_use.py b/tests/cmd/commands/test_use.py index f697060859..8fc1c1e83d 100644 --- a/tests/cmd/commands/test_use.py +++ b/tests/cmd/commands/test_use.py @@ -18,21 +18,44 @@ import os import uuid from rally.cmd.commands import use +from rally.cmd import envutils from rally.openstack.common import test from rally import exceptions +MOD = 'rally.cmd.commands.use.' + class UseCommandsTestCase(test.BaseTestCase): def setUp(self): super(UseCommandsTestCase, self).setUp() self.use = use.UseCommands() + def test_deployment_use_no_args(self): + status = self.use.deployment() + self.assertEqual(1, status) + + @mock.patch(MOD + 'UseCommands._update_openrc_deployment_file') + @mock.patch(MOD + 'UseCommands._update_attribute_in_global_file') + @mock.patch(MOD + 'UseCommands._ensure_rally_configuration_dir_exists') + @mock.patch(MOD + 'db') + def test_deployment_use_by_name(self, m_db, m_ercde, m_uaigf, m_uodf): + fake_deployment = {'uuid': 'fake_uuid', + 'endpoints': 'fake_endpoints'} + m_db.deployment_list.return_value = [fake_deployment] + m_db.deployment_get.return_value = fake_deployment + status = self.use.deployment(name='fake_name') + self.assertIsNone(status) + m_db.deployment_list.assert_called_once_with(name='fake_name') + m_ercde.assert_called_once_with() + m_uaigf.assert_called_once_with(envutils.ENV_DEPLOYMENT, 'fake_uuid') + m_uodf.assert_called_once_with('fake_uuid', 'fake_endpoints') + @mock.patch('os.remove') @mock.patch('os.symlink') - @mock.patch('rally.cmd.commands.use.db.deployment_get') + @mock.patch(MOD + 'db.deployment_get') @mock.patch('os.path.exists') - @mock.patch('rally.cmd.commands.use.fileutils.update_env_file') + @mock.patch(MOD + 'fileutils.update_env_file') def test_deployment(self, mock_env, mock_path, mock_deployment, mock_symlink, mock_remove): deploy_id = str(uuid.uuid4()) @@ -60,15 +83,15 @@ class UseCommandsTestCase(test.BaseTestCase): mock_remove.assert_called_once_with(os.path.expanduser( '~/.rally/openrc')) - @mock.patch('rally.cmd.commands.use.db.deployment_get') + @mock.patch(MOD + 'db.deployment_get') def test_deployment_not_found(self, mock_deployment): deploy_id = str(uuid.uuid4()) mock_deployment.side_effect = exceptions.DeploymentNotFound( uuid=deploy_id) - self.assertRaises(SystemExit, self.use.deployment, deploy_id) + self.assertEqual(1, self.use.deployment(deploy_id)) - @mock.patch('rally.cmd.commands.use.fileutils._rewrite_env_file') - @mock.patch('rally.cmd.commands.use.db.task_get') + @mock.patch(MOD + 'fileutils._rewrite_env_file') + @mock.patch(MOD + 'db.task_get') def test_task(self, mock_task, mock_file): task_id = str(uuid.uuid4()) mock_task.return_value = True @@ -77,7 +100,7 @@ class UseCommandsTestCase(test.BaseTestCase): os.path.expanduser('~/.rally/globals'), ['RALLY_TASK=%s\n' % task_id]) - @mock.patch('rally.cmd.commands.use.db.task_get') + @mock.patch(MOD + 'db.task_get') def test_task_not_found(self, mock_task): task_id = str(uuid.uuid4()) mock_task.side_effect = exceptions.TaskNotFound(uuid=task_id) diff --git a/tests/db/test_api.py b/tests/db/test_api.py index b5c2dd2434..18ba968f96 100644 --- a/tests/db/test_api.py +++ b/tests/db/test_api.py @@ -269,14 +269,15 @@ class DeploymentTestCase(test.DBTestCase): self.assertEqual(sorted([deploy_one['uuid'], deploy_two['uuid']]), sorted([deploy['uuid'] for deploy in deploys])) - def test_deployment_list_with_status(self): + def test_deployment_list_with_status_and_name(self): deploy_one = db.deployment_create({}) deploy_two = db.deployment_create({ 'config': {}, 'status': consts.DeployStatus.DEPLOY_FAILED, }) + deploy_three = db.deployment_create({'name': 'deployment_name'}) deploys = db.deployment_list(status=consts.DeployStatus.DEPLOY_INIT) - self.assertEqual(len(deploys), 1) + self.assertEqual(len(deploys), 2) self.assertEqual(deploys[0]['uuid'], deploy_one['uuid']) deploys = db.deployment_list(status=consts.DeployStatus.DEPLOY_FAILED) self.assertEqual(len(deploys), 1) @@ -284,6 +285,9 @@ class DeploymentTestCase(test.DBTestCase): deploys = db.deployment_list( status=consts.DeployStatus.DEPLOY_FINISHED) self.assertEqual(len(deploys), 0) + deploys = db.deployment_list(name='deployment_name') + self.assertEqual(deploys[0]['uuid'], deploy_three['uuid']) + self.assertEqual(len(deploys), 1) def test_deployment_list_parent(self): deploy = db.deployment_create({}) diff --git a/tests_ci/pre_test_hook.sh b/tests_ci/rally-gate.sh similarity index 59% rename from tests_ci/pre_test_hook.sh rename to tests_ci/rally-gate.sh index 984883a8de..e3216abcd2 100755 --- a/tests_ci/pre_test_hook.sh +++ b/tests_ci/rally-gate.sh @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/sh -ex # # Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain @@ -12,13 +12,14 @@ # License for the specific language governing permissions and limitations # under the License. -# This script is executed inside pre_test_hook function in desvstack gate. +# This script is executed by post_test_hook function in desvstack gate. -# Install rally devstack integration +PROJECT=`echo $ZUUL_PROJECT | cut -d \/ -f 2` +SCENARIO=$BASE/new/$PROJECT/rally-scenarios/${RALLY_SCENARIO}.yaml -RALLY_BASE=/opt/stack/new/rally -DEVSTACK_BASE=/opt/stack/new/devstack -cp -r $RALLY_BASE/contrib/devstack/* $DEVSTACK_BASE/ - -export ENABLED_SERVICES=rally -export RUN_EXERCISES=rally +rally use deployment --name devstack +rally -dv task start --task $SCENARIO +mkdir rally-plot +rally task plot2html --out rally-plot/results.html +gzip -9 rally-plot/results.html +env