From 840b5072a1b3a4f646a5a9f4ae3e5551cf8a04a0 Mon Sep 17 00:00:00 2001 From: chenhb-zte Date: Fri, 3 Feb 2017 09:14:31 +0800 Subject: [PATCH] Switch task parser to custom yaml 1.Switch task parser to custom yaml, custom yaml deprecates duplicate key and loads task in the same order as they are in task file. 2.Remove duplicate scenario KeystoneBasic.create_delete_user. Change-Id: I3b338f63eca0ac217a6376f6d6705da69fb97e80 --- rally-jobs/rally-keystone-api-v2.yaml | 11 ----------- rally-jobs/rally-mos.yaml | 11 ----------- rally-jobs/rally.yaml | 11 ----------- rally/cli/commands/task.py | 4 ++-- rally/task/context.py | 4 ++-- rally/task/validation.py | 4 ++-- tests/unit/task/test_validation.py | 2 +- 7 files changed, 7 insertions(+), 40 deletions(-) diff --git a/rally-jobs/rally-keystone-api-v2.yaml b/rally-jobs/rally-keystone-api-v2.yaml index e59e8bf1d9..98c40aa5a4 100644 --- a/rally-jobs/rally-keystone-api-v2.yaml +++ b/rally-jobs/rally-keystone-api-v2.yaml @@ -197,17 +197,6 @@ failure_rate: max: 0 - KeystoneBasic.create_delete_user: - - - args: {} - runner: - type: "constant" - times: 10 - concurrency: 10 - sla: - failure_rate: - max: 0 - KeystoneBasic.create_and_delete_service: - runner: diff --git a/rally-jobs/rally-mos.yaml b/rally-jobs/rally-mos.yaml index 64c0d33d19..f51cd23bfb 100644 --- a/rally-jobs/rally-mos.yaml +++ b/rally-jobs/rally-mos.yaml @@ -116,17 +116,6 @@ failure_rate: max: 0 - KeystoneBasic.create_delete_user: - - - args: {} - runner: - type: "constant" - times: 1 - concurrency: 1 - sla: - failure_rate: - max: 0 - HeatStacks.create_and_list_stack: - args: diff --git a/rally-jobs/rally.yaml b/rally-jobs/rally.yaml index d188ecb0fa..fc20829ec3 100644 --- a/rally-jobs/rally.yaml +++ b/rally-jobs/rally.yaml @@ -197,17 +197,6 @@ failure_rate: max: 0 - KeystoneBasic.create_delete_user: - - - args: {} - runner: - type: "constant" - times: 10 - concurrency: 10 - sla: - failure_rate: - max: 0 - KeystoneBasic.create_and_delete_service: - runner: diff --git a/rally/cli/commands/task.py b/rally/cli/commands/task.py index e50bc108bb..f0290056be 100644 --- a/rally/cli/commands/task.py +++ b/rally/cli/commands/task.py @@ -26,7 +26,6 @@ import jsonschema from oslo_utils import uuidutils import six from six.moves.urllib import parse as urlparse -import yaml from rally.cli import cliutils from rally.cli import envutils @@ -36,6 +35,7 @@ from rally.common.io import junit from rally.common import logging from rally.common import utils as rutils from rally.common import version +from rally.common import yamlutils as yaml from rally import consts from rally import exceptions from rally import plugins @@ -80,7 +80,7 @@ class TaskCommands(object): try: kw = args and yaml.safe_load(args) kw = {} if kw is None else kw - except yaml.parser.ParserError as e: + except yaml.ParserError as e: print_invalid_header(src_name, args) print(_("%(source)s has to be YAML or JSON. Details:" "\n\n%(err)s\n") diff --git a/rally/task/context.py b/rally/task/context.py index 8de3dd58f4..d06dc58bc9 100644 --- a/rally/task/context.py +++ b/rally/task/context.py @@ -75,12 +75,12 @@ class BaseContext(plugin.Plugin, functional.FunctionalMixin, # NOTE(amaretskiy): self.config is a constant data and must be # immutable or write-protected type to prevent # unexpected changes in runtime - if type(config) == dict: + if isinstance(config, dict): if hasattr(self, "DEFAULT_CONFIG"): for key, value in self.DEFAULT_CONFIG.items(): config.setdefault(key, value) self.config = utils.LockedDict(config) - elif type(config) == list: + elif isinstance(config, list): self.config = tuple(config) else: # NOTE(amaretskiy): It is improbable that config can be a None, diff --git a/rally/task/validation.py b/rally/task/validation.py index 8ff2a4d576..b6899955c4 100755 --- a/rally/task/validation.py +++ b/rally/task/validation.py @@ -21,10 +21,10 @@ import re from glanceclient import exc as glance_exc from novaclient import exceptions as nova_exc import six -import yaml from rally.common.i18n import _ from rally.common import objects +from rally.common import yamlutils as yaml from rally import consts from rally import exceptions from rally import osclients @@ -171,7 +171,7 @@ def file_exists(config, clients, deployment, param_name, mode=os.R_OK, def check_command_dict(command): """Check command-specifying dict `command', raise ValueError on error.""" - if type(command) != dict: + if not isinstance(command, dict): raise ValueError("Command must be a dictionary") # NOTE(pboldin): Here we check for the values not for presence of the keys diff --git a/tests/unit/task/test_validation.py b/tests/unit/task/test_validation.py index d6d3400fc0..4bac49d2c4 100755 --- a/tests/unit/task/test_validation.py +++ b/tests/unit/task/test_validation.py @@ -923,7 +923,7 @@ class ValidatorsTestCase(test.TestCase): valid) @mock.patch( - "yaml.safe_load", + "rally.common.yamlutils.safe_load", return_value={ "version": "2.0", "name": "wb",