diff --git a/rally/benchmark/context/roles.py b/rally/benchmark/context/roles.py index 8dbfe5898a..9d11f0e978 100644 --- a/rally/benchmark/context/roles.py +++ b/rally/benchmark/context/roles.py @@ -14,6 +14,7 @@ # under the License. from rally.benchmark.context import base +from rally import exceptions from rally.openstack.common.gettextutils import _ from rally.openstack.common import log as logging from rally import osclients @@ -57,9 +58,7 @@ class RoleGenerator(base.Context): role = def_role break else: - msg = (_("Role '%(role)s' does not exist in the list of roles") % - {"role": context_role}) - raise Exception(msg) + raise exceptions.NoSuchRole(role=context_role) LOG.debug("Adding role %s to all users" % (role.id)) for user in self.context["users"]: diff --git a/rally/benchmark/context/users.py b/rally/benchmark/context/users.py index 07f61cb30d..541757cd3f 100644 --- a/rally/benchmark/context/users.py +++ b/rally/benchmark/context/users.py @@ -14,6 +14,7 @@ # under the License. from oslo.config import cfg + from rally.benchmark.context import base from rally.benchmark import utils from rally import consts diff --git a/rally/benchmark/engine.py b/rally/benchmark/engine.py index 60fa0b06bf..3d25382fad 100644 --- a/rally/benchmark/engine.py +++ b/rally/benchmark/engine.py @@ -14,9 +14,10 @@ # under the License. import json +import traceback + import jsonschema import six -import traceback from rally.benchmark.context import base as base_ctx from rally.benchmark.context import users as users_ctx @@ -65,9 +66,10 @@ CONFIG_SCHEMA = { class BenchmarkEngine(object): - """The Benchmark engine class, an instance of which is initialized by the - Orchestrator with the benchmarks configuration and then is used to execute - all specified benchmark scenarios. + """The Benchmark engine class is used to execute benchmark scenarios. + + An instance of class is initialized by the Orchestrator with the benchmarks + configuration and then is used to execute all specified scenarios. .. note:: Typical usage: @@ -81,6 +83,7 @@ class BenchmarkEngine(object): def __init__(self, config, task): """BenchmarkEngine constructor. + :param config: The configuration with specified benchmark scenarios :param task: The current task which is being performed """ @@ -165,8 +168,9 @@ class BenchmarkEngine(object): @rutils.log_task_wrapper(LOG.info, _("Benchmarking.")) def run(self): - """Runs the benchmarks according to the test configuration - the benchmark engine was initialized with. + """Run the benchmark according to the test configuration. + + Test configuration is specified on engine initialization. :returns: List of dicts, each dict containing the results of all the corresponding benchmark test launches diff --git a/rally/benchmark/processing/charts/histogram.py b/rally/benchmark/processing/charts/histogram.py index 73eb58cf7f..c053a4fb01 100644 --- a/rally/benchmark/processing/charts/histogram.py +++ b/rally/benchmark/processing/charts/histogram.py @@ -81,8 +81,10 @@ def calculate_number_of_bins_half(data): def hvariety(data): - """Returns a list of dictionaries, where every dictionary - describes a method of calculating the number of bins. + """Describe methods of calculating the number of bins. + + :returns: List of dictionaries, where every dictionary + describes a method of calculating the number of bins. """ if len(data) == 0: raise ValueError("Cannot calculate number of histrogram bins " diff --git a/rally/benchmark/scenarios/authenticate/authenticate.py b/rally/benchmark/scenarios/authenticate/authenticate.py index c322cea25d..e8b81bc967 100644 --- a/rally/benchmark/scenarios/authenticate/authenticate.py +++ b/rally/benchmark/scenarios/authenticate/authenticate.py @@ -16,8 +16,9 @@ from rally.benchmark.scenarios import base class Authenticate(base.Scenario): - """This class should contain authentication mechanism for different - types of clients like Keystone. + """This class should contain authentication mechanism. + + For different types of clients like Keystone. """ @base.scenario() diff --git a/rally/benchmark/scenarios/base.py b/rally/benchmark/scenarios/base.py index efc6be0da0..aab4a56a96 100644 --- a/rally/benchmark/scenarios/base.py +++ b/rally/benchmark/scenarios/base.py @@ -25,7 +25,9 @@ from rally import utils def scenario(admin_only=False, context=None): - """This method is used as decorator for the methods of benchmark scenarios + """Add extra fields to benchmark scenarios methods. + + This method is used as decorator for the methods of benchmark scenarios and it adds following extra fields to the methods. 'is_scenario' is set to True 'admin_only' is set to True if a scenario require admin endpoints @@ -40,7 +42,8 @@ def scenario(admin_only=False, context=None): class Scenario(object): """This is base class for any benchmark scenario. - You should create subclass of this class. And you test scenarios will + + You should create subclass of this class. And your test scenarios will be auto discoverable and you will be able to specify it in test config. """ RESOURCE_NAME_PREFIX = "" diff --git a/rally/benchmark/scenarios/ceilometer/utils.py b/rally/benchmark/scenarios/ceilometer/utils.py index b0794e6657..c17560d0d2 100644 --- a/rally/benchmark/scenarios/ceilometer/utils.py +++ b/rally/benchmark/scenarios/ceilometer/utils.py @@ -19,9 +19,6 @@ from rally.benchmark.scenarios import utils as scenario_utils class CeilometerScenario(base.Scenario): - """This class should contain base operations for benchmarking Ceilometer, - most of them are GET/PUT/POST/DELETE Api calls. - """ RESOURCE_NAME_PREFIX = "rally_ceilometer_" def _get_alarm_dict(self, **kwargs): diff --git a/rally/benchmark/scenarios/cinder/utils.py b/rally/benchmark/scenarios/cinder/utils.py index 0477d64fb2..a939b3ae23 100644 --- a/rally/benchmark/scenarios/cinder/utils.py +++ b/rally/benchmark/scenarios/cinder/utils.py @@ -13,9 +13,10 @@ # License for the specific language governing permissions and limitations # under the License. -from oslo.config import cfg import time +from oslo.config import cfg + from rally.benchmark.scenarios import base from rally.benchmark.scenarios import utils as scenario_utils from rally.benchmark import utils as bench_utils diff --git a/rally/benchmark/scenarios/glance/utils.py b/rally/benchmark/scenarios/glance/utils.py index 771e71607e..91c2c84415 100644 --- a/rally/benchmark/scenarios/glance/utils.py +++ b/rally/benchmark/scenarios/glance/utils.py @@ -14,9 +14,10 @@ # under the License. import os -from oslo.config import cfg import time +from oslo.config import cfg + from rally.benchmark.scenarios import base from rally.benchmark.scenarios import utils as scenario_utils from rally.benchmark import utils as bench_utils @@ -97,7 +98,7 @@ class GlanceScenario(base.Scenario): update_resource=bench_utils.get_from_manager(), timeout=CONF.benchmark.glance_image_create_timeout, check_interval=CONF.benchmark. - glance_image_create_poll_interval) + glance_image_create_poll_interval) finally: if "data" in kw: diff --git a/rally/benchmark/scenarios/keystone/utils.py b/rally/benchmark/scenarios/keystone/utils.py index 7bdcd32846..62552765a1 100644 --- a/rally/benchmark/scenarios/keystone/utils.py +++ b/rally/benchmark/scenarios/keystone/utils.py @@ -22,10 +22,6 @@ def is_temporary(resource): class KeystoneScenario(base.Scenario): - """This class should contain base operations for benchmarking keystone, - most of them are creating/deleting resources. - """ - RESOURCE_NAME_PREFIX = "rally_keystone_" @scenario_utils.atomic_action_timer('keystone.create_user') diff --git a/rally/benchmark/scenarios/neutron/network.py b/rally/benchmark/scenarios/neutron/network.py index 50eeb788f3..aaa3c06b43 100644 --- a/rally/benchmark/scenarios/neutron/network.py +++ b/rally/benchmark/scenarios/neutron/network.py @@ -45,8 +45,10 @@ class NeutronNetworks(utils.NeutronScenario): subnet_create_args=None, subnet_cidr_start=None, subnets_per_network=None): - """Create a network, a given number of subnets - and then list all subnets. + """Test creating and listing a given number of subnets. + + The scenario creates a network, a given number of subnets and then + lists subnets. :param network_create_args: dict, POST /v2.0/networks request options :param subnet_create_args: dict, POST /v2.0/subnets request options @@ -69,7 +71,9 @@ class NeutronNetworks(utils.NeutronScenario): subnet_cidr_start=None, subnets_per_network=None, router_create_args=None): - """Create a network, a given number of subnets and routers + """Test creating and listing a given number of routers. + + Create a network, a given number of subnets and routers and then list all routers. :param network_create_args: dict, POST /v2.0/networks request options diff --git a/rally/benchmark/scenarios/neutron/utils.py b/rally/benchmark/scenarios/neutron/utils.py index 0de5082986..49b410759b 100644 --- a/rally/benchmark/scenarios/neutron/utils.py +++ b/rally/benchmark/scenarios/neutron/utils.py @@ -14,6 +14,7 @@ # under the License. import multiprocessing + import netaddr from rally.benchmark.scenarios import base @@ -21,9 +22,7 @@ from rally.benchmark.scenarios import utils as scenario_utils class NeutronScenario(base.Scenario): - """This class should contain base operations for benchmarking neutron, - most of them are creating/deleting resources. - """ + """This class should contain base operations for benchmarking neutron.""" RESOURCE_NAME_PREFIX = "rally_net_" SUBNET_IP_VERSION = 4 @@ -33,8 +32,7 @@ class NeutronScenario(base.Scenario): @classmethod def _generate_subnet_cidr(cls, network_id): - """Generate next subnet CIDR for given network, - without IP overlapping. + """Generate next subnet CIDR for network, without IP overlapping. :param network_id: str, network UUID for subnet :returns: str, next available subnet CIDR diff --git a/rally/benchmark/scenarios/nova/servers.py b/rally/benchmark/scenarios/nova/servers.py index 166abc5e65..7cf079b491 100644 --- a/rally/benchmark/scenarios/nova/servers.py +++ b/rally/benchmark/scenarios/nova/servers.py @@ -13,9 +13,10 @@ # License for the specific language governing permissions and limitations # under the License. -import jsonschema import random +import jsonschema + from rally.benchmark.scenarios import base from rally.benchmark.scenarios.cinder import utils as cinder_utils from rally.benchmark.scenarios.nova import utils @@ -94,8 +95,11 @@ class NovaServers(utils.NovaScenario, @validation.add(validation.image_valid_on_flavor("flavor", "image")) @base.scenario(context={"cleanup": ["nova"]}) def boot_and_bounce_server(self, image, flavor, **kwargs): - """Tests booting a server then performing stop/start or hard/soft - reboot a number of times. + """Test booting a server with further performing specified actions. + + Actions should be passed into kwargs. Available actions are + 'hard_reboot', 'soft_reboot', 'stop_start' and 'rescue_unrescue'. + Delete server after all actions. """ action_builder = self._bind_actions() actions = kwargs.get('actions', []) @@ -190,6 +194,7 @@ class NovaServers(utils.NovaScenario, def _rescue_and_unrescue_server(self, server): """Rescue and then unrescue the given server. + A rescue will be issued on the given server upon which time this method will wait for the server to become 'RESCUE'. Once the server is RESCUE a unrescue will be issued and diff --git a/rally/benchmark/scenarios/nova/utils.py b/rally/benchmark/scenarios/nova/utils.py index 612509cc33..6e953963b3 100644 --- a/rally/benchmark/scenarios/nova/utils.py +++ b/rally/benchmark/scenarios/nova/utils.py @@ -13,9 +13,10 @@ # License for the specific language governing permissions and limitations # under the License. -from oslo.config import cfg import time +from oslo.config import cfg + from rally.benchmark.scenarios import base from rally.benchmark.scenarios import utils as scenario_utils from rally.benchmark import utils as bench_utils @@ -241,12 +242,12 @@ class NovaScenario(base.Scenario): :param image: Image object """ image.delete() + check_interval = CONF.benchmark.nova_server_image_delete_poll_interval bench_utils.wait_for_delete( image, update_resource=bench_utils.get_from_manager(), timeout=CONF.benchmark.nova_server_image_delete_timeout, - check_interval= - CONF.benchmark.nova_server_image_delete_poll_interval + check_interval=check_interval ) @scenario_utils.atomic_action_timer('nova.create_image') @@ -263,13 +264,13 @@ class NovaScenario(base.Scenario): image_uuid = self.clients("nova").servers.create_image(server, server.name) image = self.clients("nova").images.get(image_uuid) + check_interval = CONF.benchmark.nova_server_image_create_poll_interval image = bench_utils.wait_for( image, is_ready=bench_utils.resource_is("ACTIVE"), update_resource=bench_utils.get_from_manager(), timeout=CONF.benchmark.nova_server_image_create_timeout, - check_interval= - CONF.benchmark.nova_server_image_create_poll_interval + check_interval=check_interval ) return image diff --git a/rally/benchmark/scenarios/tempest/utils.py b/rally/benchmark/scenarios/tempest/utils.py index 036ceb12fb..ec46ddb3e6 100644 --- a/rally/benchmark/scenarios/tempest/utils.py +++ b/rally/benchmark/scenarios/tempest/utils.py @@ -14,10 +14,11 @@ # under the License. import os -import six import subprocess import tempfile +import six + from rally import exceptions from rally.openstack.common.gettextutils import _ diff --git a/rally/benchmark/scenarios/utils.py b/rally/benchmark/scenarios/utils.py index 4efcde1a97..2bcba4d873 100644 --- a/rally/benchmark/scenarios/utils.py +++ b/rally/benchmark/scenarios/utils.py @@ -15,14 +15,14 @@ # under the License. import functools + import jsonschema from rally import utils class ActionBuilder(object): - """Builder class for mapping and creating action objects into - callable methods. + """Builder class for mapping and creating action objects. An action list is an array of single key/value dicts which takes the form: @@ -56,8 +56,7 @@ class ActionBuilder(object): } def __init__(self, action_keywords): - """Creates a new instance of the builder which supports the given - action keywords. + """Create a new instance of the builder for the given action keywords. :param action_keywords: A list of strings which are the keywords this instance of the builder supports. @@ -65,13 +64,13 @@ class ActionBuilder(object): self._bindings = {} self.schema = dict(ActionBuilder.SCHEMA_TEMPLATE) for kw in action_keywords: - self.schema['items']['properties'][kw] =\ - ActionBuilder.ITEM_TEMPLATE + self.schema['items']['properties'][kw] = ( + ActionBuilder.ITEM_TEMPLATE) def bind_action(self, action_key, action, *args, **kwargs): - """Binds an action and optionally static args/kwargs to an - action key. + """Bind an action to an action key. + Static args/kwargs can be optionally binded. :param action_key: The action keyword to bind the action to. :param action: A method/function to call for the action. :param args: (optional) Static positional args to prepend @@ -87,23 +86,24 @@ class ActionBuilder(object): } def validate(self, actions): - """Validates the list of action objects against the schema - for this builder. + """Validate the list of action objects against the builder schema. :param actions: The list of action objects to validate. """ jsonschema.validate(actions, self.schema) def _build(self, func, times, *args, **kwargs): - """Builds the wrapper action call.""" + """Build the wrapper action call.""" def _f(): for i in range(times): func(*args, **kwargs) return _f def build_actions(self, actions, *args, **kwargs): - """Builds a list of callable actions based on the given - action object list and the actions bound to this builder. + """Build a list of callable actions. + + A list of callable actions based on the given action object list and + the actions bound to this builder. :param actions: A list of action objects to build callable action for. @@ -129,8 +129,10 @@ class ActionBuilder(object): def atomic_action_timer(name): - """Decorates methods of the Scenario class requiring a measure of execution - time. This provides duration in seconds of each atomic action. + """Provide measure of execution time. + + Decorates methods of the Scenario class. + This provides duration in seconds of each atomic action. """ def wrap(func): @functools.wraps(func) @@ -156,7 +158,8 @@ class AtomicAction(utils.Timer): """ def __init__(self, scenario_instance, name): - """Constructor + """Create a new instance of the AtomicAction. + :param scenario_instance: instance of subclass of base scenario :param name: name of the ActionBuilder """ diff --git a/rally/benchmark/scenarios/vm/utils.py b/rally/benchmark/scenarios/vm/utils.py index 0d13785544..55d21e9b8d 100644 --- a/rally/benchmark/scenarios/vm/utils.py +++ b/rally/benchmark/scenarios/vm/utils.py @@ -24,6 +24,7 @@ class VMScenario(base.Scenario): @scenario_utils.atomic_action_timer('vm.run_command') def run_action(self, ssh, interpreter, script): """Run command inside an instance. + This is a separate function so that only script execution is timed """ return ssh.execute(interpreter, stdin=open(script, "rb")) @@ -34,7 +35,9 @@ class VMScenario(base.Scenario): def run_command(self, server, username, network, port, ip_version, interpreter, script): - """Create SSH connection for server, wait for server to become + """Run command via SSH on server. + + Create SSH connection for server, wait for server to become available (there is a delay between server being set to ACTIVE and sshd being available). Then call __run_command to actually execute the command. diff --git a/rally/benchmark/types.py b/rally/benchmark/types.py index 8f6aaf781a..03edba3bfe 100644 --- a/rally/benchmark/types.py +++ b/rally/benchmark/types.py @@ -72,7 +72,7 @@ def _id_from_name(resource_config, resources, typename): raise exceptions.InvalidScenarioArgument( "{typename} 'id', 'name', or 'regex' not found " "in '{resource_config}' ".format(typename=typename.title(), - resource_config=resource_config)) + resource_config=resource_config)) pattern = re.compile(patternstr) matching = filter(lambda resource: re.search(pattern, resource.name), @@ -80,13 +80,14 @@ def _id_from_name(resource_config, resources, typename): if not matching: raise exceptions.InvalidScenarioArgument( "{typename} with pattern '{pattern}' not found".format( - typename=typename.title(), pattern=pattern.pattern)) + typename=typename.title(), pattern=pattern.pattern)) elif len(matching) > 1: raise exceptions.InvalidScenarioArgument( - "{typename} with name '{pattern}' is ambiguous, " - "possible matches by id: {ids}".format( - typename=typename.title(), pattern=pattern.pattern, - ids=", ".join(map(operator.attrgetter("id"), matching)))) + "{typename} with name '{pattern}' is ambiguous, possible matches " + "by id: {ids}".format(typename=typename.title(), + pattern=pattern.pattern, + ids=", ".join(map(operator.attrgetter("id"), + matching)))) return matching[0].id diff --git a/rally/benchmark/utils.py b/rally/benchmark/utils.py index 709e4d9332..c744f37bc0 100644 --- a/rally/benchmark/utils.py +++ b/rally/benchmark/utils.py @@ -20,6 +20,7 @@ import time import traceback from novaclient.v1_1 import servers + from rally import exceptions diff --git a/rally/benchmark/validation.py b/rally/benchmark/validation.py index 07f5a3fedd..18bb7817ab 100644 --- a/rally/benchmark/validation.py +++ b/rally/benchmark/validation.py @@ -146,9 +146,9 @@ def image_exists(param_name): """ def image_exists_validator(**kwargs): clients = kwargs.get('clients') - image_id = types.ImageResourceType.transform(clients=clients, - resource_config= - kwargs.get(param_name)) + image_id = types.ImageResourceType.transform( + clients=clients, + resource_config=kwargs.get(param_name)) try: clients.glance().images.get(image=image_id) return ValidationResult() @@ -166,9 +166,9 @@ def flavor_exists(param_name): """ def flavor_exists_validator(**kwargs): clients = kwargs.get('clients') - flavor_id = types.FlavorResourceType.transform(clients=clients, - resource_config= - kwargs.get(param_name)) + flavor_id = types.FlavorResourceType.transform( + clients=clients, + resource_config=kwargs.get(param_name)) try: clients.nova().flavors.get(flavor=flavor_id) return ValidationResult() @@ -190,18 +190,18 @@ def image_valid_on_flavor(flavor_name, image_name): def image_valid_on_flavor_validator(**kwargs): clients = kwargs.get('clients') - flavor_id = types.FlavorResourceType.transform(clients=clients, - resource_config= - kwargs.get(flavor_name)) + flavor_id = types.FlavorResourceType.transform( + clients=clients, + resource_config=kwargs.get(flavor_name)) try: flavor = clients.nova().flavors.get(flavor=flavor_id) except nova_exc.NotFound: message = _("Flavor with id '%s' not found") % flavor_id return ValidationResult(False, message) - image_id = types.ImageResourceType.transform(clients=clients, - resource_config= - kwargs.get(image_name)) + image_id = types.ImageResourceType.transform( + clients=clients, + resource_config=kwargs.get(image_name)) try: image = clients.glance().images.get(image=image_id) except glance_exc.HTTPNotFound: diff --git a/rally/cmd/commands/deployment.py b/rally/cmd/commands/deployment.py index 3d2a2cb984..48d565cfac 100644 --- a/rally/cmd/commands/deployment.py +++ b/rally/cmd/commands/deployment.py @@ -148,6 +148,7 @@ class DeploymentCommands(object): @envutils.with_default_deploy_id def endpoint(self, deploy_id=None): """Print endpoint of the deployment. + :param deploy_id: a UUID of the deployment """ headers = ['auth_url', 'username', 'password', 'tenant_name', diff --git a/rally/cmd/commands/task.py b/rally/cmd/commands/task.py index c1742b350f..c00fba2ba4 100644 --- a/rally/cmd/commands/task.py +++ b/rally/cmd/commands/task.py @@ -16,14 +16,13 @@ """ Rally command: task """ from __future__ import print_function - import json import os import pprint import webbrowser -import yaml from oslo.config import cfg +import yaml from rally.benchmark.processing import plot from rally.benchmark.processing import utils diff --git a/rally/cmd/commands/use.py b/rally/cmd/commands/use.py index c99cb664a4..b4411cb437 100644 --- a/rally/cmd/commands/use.py +++ b/rally/cmd/commands/use.py @@ -104,8 +104,10 @@ class UseCommands(object): @cliutils.args('--uuid', type=str, dest='task_id', required=False, help='UUID of the task') def task(self, task_id): - """Set the RALLY_TASK env var so the user does not need to specify a - task UUID in the command requiring this parameter. + """Set the RALLY_TASK env var. + + Is used to allow the user not to specify a task UUID in the command + requiring this parameter. If the task uuid specified in parameter by the user does not exist, a TaskNotFound will be raised by task_get(). diff --git a/rally/cmd/envutils.py b/rally/cmd/envutils.py index 1f563b1ad3..43125f9f9a 100644 --- a/rally/cmd/envutils.py +++ b/rally/cmd/envutils.py @@ -13,9 +13,10 @@ # License for the specific language governing permissions and limitations # under the License. -import decorator import os +import decorator + from rally import exceptions from rally import fileutils from rally.openstack.common.gettextutils import _ diff --git a/rally/db/sqlalchemy/api.py b/rally/db/sqlalchemy/api.py index f8e652221c..ad72ddbd3c 100644 --- a/rally/db/sqlalchemy/api.py +++ b/rally/db/sqlalchemy/api.py @@ -96,9 +96,8 @@ class Connection(object): return query def _task_get(self, uuid, session=None): - task = self.model_query(models.Task, session=session).\ - filter_by(uuid=uuid).\ - first() + task = (self.model_query(models.Task, session=session). + filter_by(uuid=uuid).first()) if not task: raise exceptions.TaskNotFound(uuid=uuid) return task @@ -107,15 +106,14 @@ class Connection(object): return self._task_get(uuid) def task_get_detailed(self, uuid): - return self.model_query(models.Task).\ - options(sa.orm.joinedload('results')).\ - filter_by(uuid=uuid).\ - first() + return (self.model_query(models.Task). + options(sa.orm.joinedload('results')). + filter_by(uuid=uuid).first()) def task_get_detailed_last(self): - return self.model_query(models.Task).\ - options(sa.orm.joinedload('results')).\ - order_by(models.Task.id.desc()).first() + return (self.model_query(models.Task). + options(sa.orm.joinedload('results')). + order_by(models.Task.id.desc()).first()) def task_create(self, values): task = models.Task() @@ -140,14 +138,13 @@ class Connection(object): def task_delete(self, uuid, status=None): session = get_session() with session.begin(): - query = base_query = self.model_query(models.Task).\ - filter_by(uuid=uuid) + query = base_query = (self.model_query(models.Task). + filter_by(uuid=uuid)) if status is not None: query = base_query.filter_by(status=status) - self.model_query(models.TaskResult).\ - filter_by(task_uuid=uuid).\ - delete(synchronize_session=False) + (self.model_query(models.TaskResult).filter_by(task_uuid=uuid). + delete(synchronize_session=False)) count = query.delete(synchronize_session=False) if not count: @@ -166,14 +163,12 @@ class Connection(object): return result def task_result_get_all_by_uuid(self, uuid): - return self.model_query(models.TaskResult).\ - filter_by(task_uuid=uuid).\ - all() + return (self.model_query(models.TaskResult). + filter_by(task_uuid=uuid).all()) def _deployment_get(self, uuid, session=None): - deploy = self.model_query(models.Deployment, session=session).\ - filter_by(uuid=uuid).\ - first() + deploy = (self.model_query(models.Deployment, session=session). + filter_by(uuid=uuid).first()) if not deploy: raise exceptions.DeploymentNotFound(uuid=uuid) return deploy @@ -187,15 +182,13 @@ class Connection(object): def deployment_delete(self, uuid): session = get_session() with session.begin(): - count = self.model_query(models.Resource, session=session).\ - filter_by(deployment_uuid=uuid).\ - count() + count = (self.model_query(models.Resource, session=session). + filter_by(deployment_uuid=uuid).count()) if count: raise exceptions.DeploymentIsBusy(uuid=uuid) - count = self.model_query(models.Deployment, session=session).\ - filter_by(uuid=uuid).\ - delete(synchronize_session=False) + count = (self.model_query(models.Deployment, session=session). + filter_by(uuid=uuid).delete(synchronize_session=False)) if not count: raise exceptions.DeploymentNotFound(uuid=uuid) @@ -211,8 +204,8 @@ class Connection(object): return deploy def deployment_list(self, status=None, parent_uuid=None, name=None): - query = self.model_query(models.Deployment).\ - filter_by(parent_uuid=parent_uuid) + query = (self.model_query(models.Deployment). + filter_by(parent_uuid=parent_uuid)) if name: query = query.filter_by(name=name) @@ -227,8 +220,8 @@ class Connection(object): return resource def resource_get_all(self, deployment_uuid, provider_name=None, type=None): - query = self.model_query(models.Resource).\ - filter_by(deployment_uuid=deployment_uuid) + query = (self.model_query(models.Resource). + filter_by(deployment_uuid=deployment_uuid)) if provider_name is not None: query = query.filter_by(provider_name=provider_name) if type is not None: @@ -236,9 +229,8 @@ class Connection(object): return query.all() def resource_delete(self, id): - count = self.model_query(models.Resource).\ - filter_by(id=id).\ - delete(synchronize_session=False) + count = (self.model_query(models.Resource). + filter_by(id=id).delete(synchronize_session=False)) if not count: raise exceptions.ResourceNotFound(id=id) @@ -249,8 +241,8 @@ class Connection(object): return verification def verification_get(self, verification_uuid, session=None): - verification = self.model_query(models.Verification, session=session).\ - filter_by(uuid=verification_uuid).first() + verification = (self.model_query(models.Verification, session=session). + filter_by(uuid=verification_uuid).first()) if not verification: raise exceptions.NotFoundException( "Can't find any verification with following UUID '%s'." % @@ -272,9 +264,9 @@ class Connection(object): return query.all() def verification_delete(self, verification_uuid): - count = self.model_query(models.Verification).\ - filter_by(id=verification_uuid).\ - delete(synchronize_session=False) + count = (self.model_query(models.Verification). + filter_by(id=verification_uuid). + delete(synchronize_session=False)) if not count: raise exceptions.NotFoundException( "Can't find any verification with following UUID '%s'." % @@ -288,8 +280,8 @@ class Connection(object): return result def verification_result_get(self, verification_uuid): - result = self.model_query(models.VerificationResult).\ - filter_by(verification_uuid=verification_uuid).first() + result = (self.model_query(models.VerificationResult). + filter_by(verification_uuid=verification_uuid).first()) if not result: raise exceptions.NotFoundException( "No results for following UUID '%s'." % verification_uuid) diff --git a/rally/db/sqlalchemy/models.py b/rally/db/sqlalchemy/models.py index 6d4e313bb8..c68e345c7b 100644 --- a/rally/db/sqlalchemy/models.py +++ b/rally/db/sqlalchemy/models.py @@ -15,10 +15,12 @@ """ SQLAlchemy models for rally data. """ + +import uuid + import sqlalchemy as sa from sqlalchemy.ext.declarative import declarative_base from sqlalchemy import types -import uuid from rally import consts from rally.db.sqlalchemy import types as sa_types @@ -65,7 +67,7 @@ class Deployment(BASE, RallyBase): completed_at = sa.Column(sa.DateTime) # XXX(akscram): Do we need to explicitly store a name of the # deployment engine? - #engine_name = sa.Column(sa.String(36)) + # engine_name = sa.Column(sa.String(36)) config = sa.Column( sa_types.MutableJSONEncodedDict, diff --git a/rally/deploy/engines/lxc.py b/rally/deploy/engines/lxc.py index 6213d7f6cf..e6ddffd8d3 100644 --- a/rally/deploy/engines/lxc.py +++ b/rally/deploy/engines/lxc.py @@ -13,9 +13,10 @@ # License for the specific language governing permissions and limitations # under the License. -import netaddr import os +import netaddr + from rally.deploy import engine from rally.deploy.serverprovider import provider from rally.deploy.serverprovider.providers import lxc diff --git a/rally/deploy/fuel/fuelclient.py b/rally/deploy/fuel/fuelclient.py index b79a6706b4..f38e5eafef 100644 --- a/rally/deploy/fuel/fuelclient.py +++ b/rally/deploy/fuel/fuelclient.py @@ -15,9 +15,10 @@ import json import re -import requests import time +import requests + from rally.openstack.common import log as logging LOG = logging.getLogger(__name__) diff --git a/rally/deploy/serverprovider/provider.py b/rally/deploy/serverprovider/provider.py index 81f4da9c92..f4500732a7 100644 --- a/rally/deploy/serverprovider/provider.py +++ b/rally/deploy/serverprovider/provider.py @@ -148,6 +148,7 @@ class ProviderFactory(object): @abc.abstractmethod def create_servers(self, image_uuid=None, type_id=None, amount=1): """Create VMs with chosen image. + :param image_uuid: Indetificator of image :param type_id: Vm type identificator :param amount: amount of required VMs diff --git a/rally/deploy/serverprovider/providers/lxc.py b/rally/deploy/serverprovider/providers/lxc.py index 3b23dc73cb..e940669942 100644 --- a/rally/deploy/serverprovider/providers/lxc.py +++ b/rally/deploy/serverprovider/providers/lxc.py @@ -13,12 +13,13 @@ # License for the specific language governing permissions and limitations # under the License. -import netaddr import os import re import StringIO import time +import netaddr + from rally.deploy.serverprovider import provider from rally import exceptions from rally.openstack.common.gettextutils import _ diff --git a/rally/deploy/serverprovider/providers/openstack.py b/rally/deploy/serverprovider/providers/openstack.py index 3a6b3dc774..1d4fc72fde 100644 --- a/rally/deploy/serverprovider/providers/openstack.py +++ b/rally/deploy/serverprovider/providers/openstack.py @@ -13,11 +13,12 @@ # License for the specific language governing permissions and limitations # under the License. -import novaclient.exceptions import os import time import urllib2 +import novaclient.exceptions + from rally.benchmark import utils as benchmark_utils from rally.deploy.serverprovider import provider from rally import exceptions diff --git a/rally/deploy/serverprovider/providers/virsh.py b/rally/deploy/serverprovider/providers/virsh.py index d5c12b1f14..0d7e56c1c0 100644 --- a/rally/deploy/serverprovider/providers/virsh.py +++ b/rally/deploy/serverprovider/providers/virsh.py @@ -13,17 +13,19 @@ # License for the specific language governing permissions and limitations # under the License. -import netaddr import os import subprocess import time import uuid +import netaddr + from rally.deploy.serverprovider import provider class VirshProvider(provider.ProviderFactory): - '''Creates VMs from prebuilt templates. + """Create VMs from prebuilt templates. + config example: "vm_provider": { "type": "VirshProvider", @@ -32,7 +34,7 @@ class VirshProvider(provider.ProviderFactory): "template_user": "ubuntu", # vm user to launch devstack "template_password": "password" # vm password to launch devstack }, - ''' + """ CONFIG_SCHEMA = { 'type': 'object', @@ -59,6 +61,7 @@ class VirshProvider(provider.ProviderFactory): def create_servers(self, image_uuid=None, type_id=None, amount=1): """Create VMs with chosen image. + :param image_uuid: Indetificator of image :param amount: amount of required VMs Returns list of VMs uuids. @@ -66,7 +69,7 @@ class VirshProvider(provider.ProviderFactory): return [self.create_vm(str(uuid.uuid4())) for i in range(amount)] def create_vm(self, vm_name): - '''Clones prebuilt VM template and starts it.''' + """Clone prebuilt VM template and start it.""" virt_url = self._get_virt_connection_url(self.config['connection']) cmd = 'virt-clone --connect=%(url)s -o %(t)s -n %(n)s --auto-clone' % { @@ -87,13 +90,13 @@ class VirshProvider(provider.ProviderFactory): ) def destroy_servers(self): - '''Destroy already created vms.''' + """Destroy already created vms.""" for resource in self.resources.get_all(): self.destroy_vm(resource['info']['name']) self.resources.delete(resource) def destroy_vm(self, vm_name): - '''Destroy single vm and delete all allocated resources.''' + """Destroy single vm and delete all allocated resources.""" print('Destroy VM %s' % vm_name) vconnection = self._get_virt_connection_url(self.config['connection']) @@ -107,7 +110,7 @@ class VirshProvider(provider.ProviderFactory): @staticmethod def _get_virt_connection_url(connection): - '''Formats QEMU connection string from SSH url.''' + """Format QEMU connection string from SSH url.""" return 'qemu+ssh://%s/system' % connection def _determine_vm_ip(self, vm_name): diff --git a/rally/exceptions.py b/rally/exceptions.py index c9852f3c2e..e14dc9aec8 100644 --- a/rally/exceptions.py +++ b/rally/exceptions.py @@ -14,9 +14,10 @@ # under the License. -from oslo.config import cfg import sys +from oslo.config import cfg + from rally.openstack.common.gettextutils import _ from rally.openstack.common import log as logging @@ -144,6 +145,10 @@ class NoSuchConfigField(NotFoundException): msg_fmt = _("There is no field in the task config with name `%(name)s`.") +class NoSuchRole(NotFoundException): + msg_fmt = _("There is no role with name `%(role)s`.") + + class TaskNotFound(NotFoundException): msg_fmt = _("Task with uuid=%(uuid)s not found.") diff --git a/rally/fileutils.py b/rally/fileutils.py index 53bdf688cc..12a4b24fca 100644 --- a/rally/fileutils.py +++ b/rally/fileutils.py @@ -30,8 +30,8 @@ def _read_env_file(path, except_env=None): with open(path, 'r') as env_file: content = env_file.readlines() for line in content: - if except_env is None or \ - not line.startswith("%s=" % except_env): + if except_env is None or not line.startswith("%s=" % + except_env): output.append(line) return output diff --git a/rally/osclients.py b/rally/osclients.py index c91d1fa737..af916b9449 100644 --- a/rally/osclients.py +++ b/rally/osclients.py @@ -13,6 +13,8 @@ # License for the specific language governing permissions and limitations # under the License. +import urlparse + from ceilometerclient import client as ceilometer from cinderclient import client as cinder import glanceclient as glance @@ -23,7 +25,6 @@ from keystoneclient.v2_0 import client as keystone from neutronclient.neutron import client as neutron from novaclient import client as nova from oslo.config import cfg -import urlparse from rally import exceptions diff --git a/rally/sshutils.py b/rally/sshutils.py index 3bf4da5d00..df5dca82fc 100644 --- a/rally/sshutils.py +++ b/rally/sshutils.py @@ -57,12 +57,13 @@ Eventlet: """ -import paramiko import select import socket import StringIO import time +import paramiko + from rally.openstack.common.gettextutils import _ from rally.openstack.common import log as logging diff --git a/rally/verification/verifiers/tempest/config.py b/rally/verification/verifiers/tempest/config.py index 5c323c3272..fd3227ae47 100644 --- a/rally/verification/verifiers/tempest/config.py +++ b/rally/verification/verifiers/tempest/config.py @@ -15,13 +15,14 @@ import datetime import os -from oslo.config import cfg -from six.moves import configparser -from six.moves import http_client as httplib import time import urllib2 import urlparse +from oslo.config import cfg +from six.moves import configparser +from six.moves import http_client as httplib + from rally import db from rally import exceptions from rally.objects import endpoint @@ -184,8 +185,8 @@ class TempestConf(object): if public_net: net_id = public_net[0]['id'] self.conf.set('network', 'public_network_id', net_id) - public_router = neutron.list_routers(network_id= - net_id)['routers'][0] + public_router = neutron.list_routers( + network_id=net_id)['routers'][0] self.conf.set('network', 'public_router_id', public_router['id']) subnet = neutron.list_subnets(network_id=net_id)['subnets'][0] diff --git a/tests/benchmark/context/cleanup/test_cleanup.py b/tests/benchmark/context/cleanup/test_cleanup.py index 14d5742529..4085656b6c 100644 --- a/tests/benchmark/context/cleanup/test_cleanup.py +++ b/tests/benchmark/context/cleanup/test_cleanup.py @@ -16,7 +16,6 @@ import mock from rally.benchmark.context.cleanup import cleanup as cleanup_ctx - from tests import fakes from tests import test diff --git a/tests/benchmark/context/test_quotas.py b/tests/benchmark/context/test_quotas.py index dbc81c6d36..510a8afff1 100644 --- a/tests/benchmark/context/test_quotas.py +++ b/tests/benchmark/context/test_quotas.py @@ -14,9 +14,10 @@ # under the License. import copy +import random + import jsonschema import mock -import random from rally.benchmark.context import quotas from tests import test @@ -74,10 +75,10 @@ class CinderQuotasTestCase(test.TestCase): pass # Currently, no method to delete quotas available in cinder client: # Will be added with https://review.openstack.org/#/c/74841/ - #cinder_quotas = quotas.CinderQuotas(client_mock) - #tenant_id = mock.MagicMock() - #cinder_quotas.delete(tenant_id) - #client_mock.quotas.delete.assert_called_once_with(tenant_id) + # cinder_quotas = quotas.CinderQuotas(client_mock) + # tenant_id = mock.MagicMock() + # cinder_quotas.delete(tenant_id) + # client_mock.quotas.delete.assert_called_once_with(tenant_id) class NeutronQuotasTestCase(test.TestCase): @@ -187,8 +188,8 @@ class QuotasTestCase(test.TestCase): % ctx["config"]["quotas"][service][key]) # Test valid values - ctx["config"]["quotas"][service][key] = \ - random.randint(0, 1000000) + ctx["config"]["quotas"][service][key] = random.randint(0, + 1000000) try: quotas.Quotas.validate(ctx["config"]["quotas"]) except jsonschema.ValidationError: diff --git a/tests/benchmark/context/test_roles.py b/tests/benchmark/context/test_roles.py index bf983475a0..18791a692e 100644 --- a/tests/benchmark/context/test_roles.py +++ b/tests/benchmark/context/test_roles.py @@ -16,6 +16,7 @@ import mock from rally.benchmark.context import roles +from rally import exceptions from tests import fakes from tests import test @@ -71,10 +72,10 @@ class RoleGeneratorTestCase(test.TestCase): ctx = roles.RoleGenerator(self.context) ctx.context["users"] = [{"id": "u1", "tenant_id": "t1"}, {"id": "u2", "tenant_id": "t2"}] - ex = self.assertRaises(Exception, ctx._add_role, + ex = self.assertRaises(exceptions.NoSuchRole, ctx._add_role, mock.MagicMock(), "unknown_role") - expected = "Role 'unknown_role' does not exist in the list of roles" + expected = "There is no role with name `unknown_role`." self.assertEqual(expected, str(ex)) @mock.patch("rally.benchmark.context.roles.osclients") @@ -88,8 +89,8 @@ class RoleGeneratorTestCase(test.TestCase): mock.call("u1", role["id"], tenant="t1"), mock.call("u2", role["id"], tenant="t2"), ] - mock_osclients.Clients().keystone()\ - .roles.remove_user_role.assert_has_calls(calls) + mock_keystone = mock_osclients.Clients().keystone() + mock_keystone.roles.remove_user_role.assert_has_calls(calls) @mock.patch("rally.benchmark.context.roles.osclients") def test_setup_and_cleanup(self, mock_osclients): @@ -101,7 +102,6 @@ class RoleGeneratorTestCase(test.TestCase): ctx.context["users"] = [{"id": "u1", "tenant_id": "t1"}, {"id": "u2", "tenant_id": "t2"}] - #self, user_id, role_id, tenant): ctx.setup() calls = [ mock.call("u1", "r1", tenant="t1"), diff --git a/tests/benchmark/context/test_secgroups.py b/tests/benchmark/context/test_secgroups.py index fec6349007..775a452c6e 100644 --- a/tests/benchmark/context/test_secgroups.py +++ b/tests/benchmark/context/test_secgroups.py @@ -34,9 +34,9 @@ class SecGroupContextTestCase(test.TestCase): self.assertEqual(len(fake_nova.security_groups.list()), 2) self.assertTrue( - secgroup.SSH_GROUP_NAME in - [sg.name for sg in fake_nova.security_groups.list()] - ) + secgroup.SSH_GROUP_NAME in [ + sg.name for sg in fake_nova.security_groups.list() + ]) # run prep again, check that another security group is not created secgroup._prepare_open_secgroup('endpoint') @@ -46,7 +46,7 @@ class SecGroupContextTestCase(test.TestCase): def test_prep_ssh_sec_group_rules(self, mock_osclients): fake_nova = fakes.FakeNovaClient() - #NOTE(hughsaunders) Default security group is precreated + # NOTE(hughsaunders) Default security group is precreated self.assertEqual(len(fake_nova.security_groups.list()), 1) mock_cl = mock.MagicMock() mock_cl.nova.return_value = fake_nova diff --git a/tests/benchmark/context/test_users.py b/tests/benchmark/context/test_users.py index 617cfbaa6e..d332247f23 100644 --- a/tests/benchmark/context/test_users.py +++ b/tests/benchmark/context/test_users.py @@ -14,17 +14,18 @@ # under the License. import itertools -import mock import uuid +import mock + from rally.benchmark.context import users from rally.benchmark import utils from tests import fakes from tests import test -run_concurrent = lambda dummy, cls, f, args: \ - list(itertools.imap(getattr(cls, f), args)) +run_concurrent = (lambda dummy, cls, f, args: list( + itertools.imap(getattr(cls, f), args))) @mock.patch.object(utils, "run_concurrent", run_concurrent) @@ -71,9 +72,9 @@ class UserGeneratorTestCase(test.TestCase): tenant2 = mock.MagicMock() args = (mock.MagicMock(), [tenant1, tenant2]) users.UserGenerator._delete_tenants(args) - mock_osclients.Clients().keystone()\ - .tenants.delete.assert_has_calls([mock.call(tenant1["id"]), - mock.call(tenant2["id"])]) + mock_osclients.Clients().keystone().tenants.delete.assert_has_calls([ + mock.call(tenant1["id"]), + mock.call(tenant2["id"])]) @mock.patch("rally.benchmark.context.users.osclients") def test_delete_users(self, mock_osclients): @@ -81,9 +82,9 @@ class UserGeneratorTestCase(test.TestCase): user2 = mock.MagicMock() args = (mock.MagicMock(), [user1, user2]) users.UserGenerator._delete_users(args) - mock_osclients.Clients().keystone()\ - .users.delete.assert_has_calls([mock.call(user1["id"]), - mock.call(user2["id"])]) + mock_osclients.Clients().keystone().users.delete.assert_has_calls([ + mock.call(user1["id"]), + mock.call(user2["id"])]) @mock.patch("rally.benchmark.context.users.osclients") def test_setup_and_cleanup(self, mock_osclients): diff --git a/tests/benchmark/processing/test_plot.py b/tests/benchmark/processing/test_plot.py index e2ee4a3fb9..96452aa817 100644 --- a/tests/benchmark/processing/test_plot.py +++ b/tests/benchmark/processing/test_plot.py @@ -14,6 +14,7 @@ # under the License. import json + import mock from rally.benchmark.processing import plot diff --git a/tests/benchmark/runners/test_serial.py b/tests/benchmark/runners/test_serial.py index 905a6d6ab0..b802530fad 100644 --- a/tests/benchmark/runners/test_serial.py +++ b/tests/benchmark/runners/test_serial.py @@ -16,7 +16,6 @@ import mock from rally.benchmark.runners import serial - from rally import consts from tests import fakes from tests import test diff --git a/tests/benchmark/scenarios/ceilometer/test_queries.py b/tests/benchmark/scenarios/ceilometer/test_queries.py index 594ee7441b..a031e8f4aa 100644 --- a/tests/benchmark/scenarios/ceilometer/test_queries.py +++ b/tests/benchmark/scenarios/ceilometer/test_queries.py @@ -13,6 +13,7 @@ # under the License. import json + import mock from rally.benchmark.scenarios.ceilometer import queries diff --git a/tests/benchmark/scenarios/glance/test_images.py b/tests/benchmark/scenarios/glance/test_images.py index 476e612172..14eeae1e98 100644 --- a/tests/benchmark/scenarios/glance/test_images.py +++ b/tests/benchmark/scenarios/glance/test_images.py @@ -82,9 +82,9 @@ class GlanceImagesTestCase(test.TestCase): mock_random_name.return_value = "random_name" kwargs = {'fakearg': 'f'} with mock.patch("rally.benchmark.scenarios.glance.utils.time.sleep"): - glance_scenario.\ - create_image_and_boot_instances("cf", "url", "df", - "fid", 5, **kwargs) + glance_scenario.create_image_and_boot_instances("cf", "url", + "df", "fid", + 5, **kwargs) mock_create_image.assert_called_once_with("random_name", "cf", "url", "df", **kwargs) mock_boot_servers.assert_called_once_with("random_name", diff --git a/tests/benchmark/scenarios/glance/test_utils.py b/tests/benchmark/scenarios/glance/test_utils.py index 2509d07d31..8e4cf837ab 100644 --- a/tests/benchmark/scenarios/glance/test_utils.py +++ b/tests/benchmark/scenarios/glance/test_utils.py @@ -90,10 +90,10 @@ class GlanceScenarioTestCase(test.TestCase): scenario = utils.GlanceScenario() scenario._delete_image(self.image) self.image.delete.assert_called_once_with() - self.wait_for_delete.\ - mock.assert_called_once_with(self.image, - update_resource=self.gfm(), - check_interval=1, - timeout=120) + self.wait_for_delete.mock.assert_called_once_with( + self.image, + update_resource=self.gfm(), + check_interval=1, + timeout=120) self._test_atomic_action_timer(scenario.atomic_actions(), 'glance.delete_image') diff --git a/tests/benchmark/scenarios/heat/test_utils.py b/tests/benchmark/scenarios/heat/test_utils.py index 6f50d2d2c6..3c8bd0a562 100644 --- a/tests/benchmark/scenarios/heat/test_utils.py +++ b/tests/benchmark/scenarios/heat/test_utils.py @@ -60,8 +60,9 @@ class HeatScenarioTestCase(test.TestCase): @mock.patch(HEAT_UTILS + '.HeatScenario.clients') def test_create_stack(self, mock_clients): - mock_clients("heat").stacks.create.return_value = \ - {'stack': {'id': 'test_id'}} + mock_clients("heat").stacks.create.return_value = { + 'stack': {'id': 'test_id'} + } mock_clients("heat").stacks.get.return_value = self.stack scenario = utils.HeatScenario() return_stack = scenario._create_stack('stack_name') @@ -79,10 +80,10 @@ class HeatScenarioTestCase(test.TestCase): scenario = utils.HeatScenario() scenario._delete_stack(self.stack) self.stack.delete.assert_called_once_with() - self.wait_for_delete.\ - mock.assert_called_once_with(self.stack, - update_resource=self.gfm(), - check_interval=1, - timeout=3600) + self.wait_for_delete.mock.assert_called_once_with( + self.stack, + update_resource=self.gfm(), + check_interval=1, + timeout=3600) self._test_atomic_action_timer(scenario.atomic_actions(), 'heat.delete_stack') diff --git a/tests/benchmark/scenarios/keystone/test_utils.py b/tests/benchmark/scenarios/keystone/test_utils.py index de4cb6382e..df0a93a3f4 100644 --- a/tests/benchmark/scenarios/keystone/test_utils.py +++ b/tests/benchmark/scenarios/keystone/test_utils.py @@ -17,10 +17,8 @@ import mock from rally.benchmark.scenarios.keystone import utils from tests.benchmark.scenarios import test_utils -from tests import test - from tests import fakes - +from tests import test UTILS = "rally.benchmark.scenarios.keystone.utils." diff --git a/tests/benchmark/scenarios/neutron/test_network.py b/tests/benchmark/scenarios/neutron/test_network.py index df90389959..f6850c4d41 100644 --- a/tests/benchmark/scenarios/neutron/test_network.py +++ b/tests/benchmark/scenarios/neutron/test_network.py @@ -16,7 +16,6 @@ import mock from rally.benchmark.scenarios.neutron import network - from tests import test NEUTRON_NETWORKS = "rally.benchmark.scenarios.neutron.network.NeutronNetworks" diff --git a/tests/benchmark/scenarios/neutron/test_utils.py b/tests/benchmark/scenarios/neutron/test_utils.py index 143c3b579f..0a4a07d854 100644 --- a/tests/benchmark/scenarios/neutron/test_utils.py +++ b/tests/benchmark/scenarios/neutron/test_utils.py @@ -18,7 +18,6 @@ import netaddr from rally.benchmark.scenarios.neutron import utils from tests.benchmark.scenarios import test_utils - from tests import test @@ -99,8 +98,8 @@ class NeutronScenarioTestCase(test.TestCase): # Default options subnet_data = {"network_id": network_id} scenario._create_subnet(network, subnet_data) - mock_clients("neutron")\ - .create_subnet.assert_called_once_with(expected_subnet_data) + mock_clients("neutron").create_subnet.assert_called_once_with( + expected_subnet_data) self._test_atomic_action_timer(scenario.atomic_actions(), "neutron.create_subnet") @@ -111,14 +110,15 @@ class NeutronScenarioTestCase(test.TestCase): subnet_data.update(extras) expected_subnet_data["subnet"].update(extras) scenario._create_subnet(network, subnet_data) - mock_clients("neutron")\ - .create_subnet.assert_called_once_with(expected_subnet_data) + mock_clients("neutron").create_subnet.assert_called_once_with( + expected_subnet_data) @mock.patch(NEUTRON_UTILS + "NeutronScenario.clients") def test_list_subnets(self, mock_clients): subnets = [{"name": "fake1"}, {"name": "fake2"}] - mock_clients("neutron")\ - .list_subnets.return_value = {"subnets": subnets} + mock_clients("neutron").list_subnets.return_value = { + "subnets": subnets + } scenario = utils.NeutronScenario() result = scenario._list_subnets() self.assertEqual(subnets, result) diff --git a/tests/benchmark/scenarios/nova/test_servers.py b/tests/benchmark/scenarios/nova/test_servers.py index 0f379a49a5..36a0eda4d2 100644 --- a/tests/benchmark/scenarios/nova/test_servers.py +++ b/tests/benchmark/scenarios/nova/test_servers.py @@ -244,10 +244,10 @@ class NovaServersTestCase(test.TestCase): @mock.patch("rally.benchmark.scenarios.nova.servers.random.choice") def _verify_boot_server(self, mock_choice, mock_osclients, nic=None, assert_nic=False): - scenario, kwargs, expected_kwargs = \ - self._prepare_boot(mock_osclients=mock_osclients, - mock_choice=mock_choice, - nic=nic, assert_nic=assert_nic) + scenario, kwargs, expected_kwargs = self._prepare_boot( + mock_osclients=mock_osclients, + mock_choice=mock_choice, + nic=nic, assert_nic=assert_nic) scenario.boot_server("img", 0, **kwargs) scenario._boot_server.assert_called_once_with("name", "img", 0, @@ -277,10 +277,10 @@ class NovaServersTestCase(test.TestCase): def test_boot_server_from_volume_random_nic(self, mock_choice, mock_osclients, mock_nova_clients): - scenario, kwargs, expected_kwargs = \ - self._prepare_boot(mock_osclients=mock_osclients, - mock_choice=mock_choice, - nic=None, assert_nic=True) + scenario, kwargs, expected_kwargs = self._prepare_boot( + mock_osclients=mock_osclients, + mock_choice=mock_choice, + nic=None, assert_nic=True) fake_volume = fakes.FakeVolumeManager().create() fake_volume.id = "volume_id" diff --git a/tests/benchmark/scenarios/nova/test_utils.py b/tests/benchmark/scenarios/nova/test_utils.py index 29e20a5e75..94e06b6102 100644 --- a/tests/benchmark/scenarios/nova/test_utils.py +++ b/tests/benchmark/scenarios/nova/test_utils.py @@ -109,12 +109,12 @@ class NovaScenarioTestCase(test.TestCase): mock_clients("nova").images.get.return_value = self.image nova_scenario = utils.NovaScenario() return_image = nova_scenario._create_image(self.server) + check_interval = CONF.benchmark.nova_server_image_create_poll_interval self.wait_for.mock.assert_called_once_with( self.image, update_resource=self.gfm(), is_ready=self.res_is.mock(), - check_interval= - CONF.benchmark.nova_server_image_create_poll_interval, + check_interval=check_interval, timeout=CONF.benchmark.nova_server_image_create_timeout ) self.res_is.mock.assert_has_calls(mock.call('ACTIVE')) @@ -216,17 +216,16 @@ class NovaScenarioTestCase(test.TestCase): self.server1] nova_scenario = utils.NovaScenario() nova_scenario._delete_all_servers() + check_interval = CONF.benchmark.nova_server_delete_poll_interval expected = [ mock.call( self.server, update_resource=self.gfm(), - check_interval= - CONF.benchmark.nova_server_delete_poll_interval, + check_interval=check_interval, timeout=CONF.benchmark.nova_server_delete_timeout ), mock.call( self.server1, update_resource=self.gfm(), - check_interval= - CONF.benchmark.nova_server_delete_poll_interval, + check_interval=check_interval, timeout=CONF.benchmark.nova_server_delete_timeout ) ] @@ -238,10 +237,10 @@ class NovaScenarioTestCase(test.TestCase): nova_scenario = utils.NovaScenario() nova_scenario._delete_image(self.image) self.image.delete.assert_called_once_with() + check_interval = CONF.benchmark.nova_server_image_delete_poll_interval self.wait_for_delete.mock.assert_called_once_with( self.image, update_resource=self.gfm(), - check_interval= - CONF.benchmark.nova_server_image_delete_poll_interval, + check_interval=check_interval, timeout=CONF.benchmark.nova_server_image_delete_timeout ) self._test_atomic_action_timer(nova_scenario.atomic_actions(), diff --git a/tests/benchmark/scenarios/test_base.py b/tests/benchmark/scenarios/test_base.py index 849f5358d8..65fcccf9d1 100644 --- a/tests/benchmark/scenarios/test_base.py +++ b/tests/benchmark/scenarios/test_base.py @@ -13,9 +13,10 @@ # License for the specific language governing permissions and limitations # under the License. -import mock import traceback +import mock + from rally.benchmark.context import base as base_ctx from rally.benchmark.scenarios import base from rally.benchmark import validation @@ -255,8 +256,9 @@ class ScenarioTestCase(test.TestCase): "prefix_") def test_generate_random_name(self): set_by_length = lambda lst: set(map(len, lst)) - len_by_prefix = lambda lst, prefix:\ - len(filter(bool, map(lambda i: i.startswith(prefix), lst))) + len_by_prefix = (lambda lst, prefix: + len(filter(bool, map(lambda i: i.startswith(prefix), + lst)))) range_num = 50 # Defaults diff --git a/tests/benchmark/scenarios/test_utils.py b/tests/benchmark/scenarios/test_utils.py index 11be52a58c..47fb58d209 100644 --- a/tests/benchmark/scenarios/test_utils.py +++ b/tests/benchmark/scenarios/test_utils.py @@ -14,9 +14,9 @@ # License for the specific language governing permissions and limitations # under the License. +from jsonschema import exceptions as schema_exceptions import mock -from jsonschema import exceptions as schema_exceptions from rally.benchmark.scenarios import utils from tests import test diff --git a/tests/benchmark/test_engine.py b/tests/benchmark/test_engine.py index 532d7cb353..d2354ccc0d 100644 --- a/tests/benchmark/test_engine.py +++ b/tests/benchmark/test_engine.py @@ -67,8 +67,8 @@ class BenchmarkEngineTestCase(test.TestCase): def test_validate__wrong_scenarios_name(self, mova_validate): task = mock.MagicMock() eng = engine.BenchmarkEngine(mock.MagicMock(), task) - eng._validate_config_scenarios_name = \ - mock.MagicMock(side_effect=exceptions.NotFoundScenarios) + eng._validate_config_scenarios_name = mock.MagicMock( + side_effect=exceptions.NotFoundScenarios) self.assertRaises(exceptions.InvalidTaskException, eng.validate) self.assertTrue(task.set_failed.called) @@ -78,8 +78,8 @@ class BenchmarkEngineTestCase(test.TestCase): task = mock.MagicMock() eng = engine.BenchmarkEngine(mock.MagicMock(), task) eng._validate_config_scenarios_name = mock.MagicMock() - eng._validate_config_syntax = \ - mock.MagicMock(side_effect=exceptions.InvalidBenchmarkConfig) + eng._validate_config_syntax = mock.MagicMock( + side_effect=exceptions.InvalidBenchmarkConfig) self.assertRaises(exceptions.InvalidTaskException, eng.validate) self.assertTrue(task.set_failed.called) @@ -90,8 +90,8 @@ class BenchmarkEngineTestCase(test.TestCase): eng = engine.BenchmarkEngine(mock.MagicMock(), task) eng._validate_config_scenarios_name = mock.MagicMock() eng._validate_config_syntax = mock.MagicMock() - eng._validate_config_semantic = \ - mock.MagicMock(side_effect=exceptions.InvalidBenchmarkConfig) + eng._validate_config_semantic = mock.MagicMock( + side_effect=exceptions.InvalidBenchmarkConfig) self.assertRaises(exceptions.InvalidTaskException, eng.validate) self.assertTrue(task.set_failed.called) diff --git a/tests/benchmark/test_types.py b/tests/benchmark/test_types.py index 1188e65572..250144dd4b 100644 --- a/tests/benchmark/test_types.py +++ b/tests/benchmark/test_types.py @@ -15,7 +15,6 @@ from rally.benchmark import types from rally import exceptions - from tests import fakes from tests import test @@ -32,23 +31,23 @@ class FlavorResourceTypeTestCase(test.TestCase): def test_transform_by_id(self): resource_config = {"id": 42} - flavor_id = types.FlavorResourceType.transform(clients=self.clients, - resource_config= - resource_config) + flavor_id = types.FlavorResourceType.transform( + clients=self.clients, + resource_config=resource_config) self.assertEqual(flavor_id, 42) def test_transform_by_name(self): resource_config = {"name": "m1.nano"} - flavor_id = types.FlavorResourceType.transform(clients=self.clients, - resource_config= - resource_config) + flavor_id = types.FlavorResourceType.transform( + clients=self.clients, + resource_config=resource_config) self.assertEqual(flavor_id, 42) def test_transform_by_name_to_dest(self): resource_config = {"name": "m1.nano"} - flavor_id = types.FlavorResourceType.transform(clients=self.clients, - resource_config= - resource_config) + flavor_id = types.FlavorResourceType.transform( + clients=self.clients, + resource_config=resource_config) self.assertEqual(flavor_id, 42) def test_transform_by_name_no_match(self): @@ -59,9 +58,9 @@ class FlavorResourceTypeTestCase(test.TestCase): def test_transform_by_regex(self): resource_config = {"regex": "m(1|2)\.nano"} - flavor_id = types.FlavorResourceType.transform(clients=self.clients, - resource_config= - resource_config) + flavor_id = types.FlavorResourceType.transform( + clients=self.clients, + resource_config=resource_config) self.assertEqual(flavor_id, 42) def test_transform_by_regex_no_match(self): @@ -83,23 +82,23 @@ class ImageResourceTypeTestCase(test.TestCase): def test_transform_by_id(self): resource_config = {"id": 100} - image_id = types.ImageResourceType.transform(clients=self.clients, - resource_config= - resource_config) + image_id = types.ImageResourceType.transform( + clients=self.clients, + resource_config=resource_config) self.assertEqual(image_id, 100) def test_transform_by_name(self): resource_config = {"name": "cirros-0.3.1-uec"} - image_id = types.ImageResourceType.transform(clients=self.clients, - resource_config= - resource_config) + image_id = types.ImageResourceType.transform( + clients=self.clients, + resource_config=resource_config) self.assertEqual(image_id, 100) def test_transform_by_name_to_dest(self): resource_config = {"name": "cirros-0.3.1-uec"} - image_id = types.ImageResourceType.transform(clients=self.clients, - resource_config= - resource_config) + image_id = types.ImageResourceType.transform( + clients=self.clients, + resource_config=resource_config) self.assertEqual(image_id, 100) def test_transform_by_name_no_match(self): @@ -110,9 +109,9 @@ class ImageResourceTypeTestCase(test.TestCase): def test_transform_by_regex(self): resource_config = {"regex": "-uec$"} - image_id = types.ImageResourceType.transform(clients=self.clients, - resource_config= - resource_config) + image_id = types.ImageResourceType.transform( + clients=self.clients, + resource_config=resource_config) self.assertEqual(image_id, 100) def test_transform_by_regex_no_match(self): diff --git a/tests/benchmark/test_utils.py b/tests/benchmark/test_utils.py index dfb492c681..7176d35330 100644 --- a/tests/benchmark/test_utils.py +++ b/tests/benchmark/test_utils.py @@ -13,14 +13,14 @@ # License for the specific language governing permissions and limitations # under the License. -import mock - import datetime -from tests import fakes -from tests import test + +import mock from rally.benchmark import utils from rally import exceptions +from tests import fakes +from tests import test class BenchmarkUtilsTestCase(test.TestCase): diff --git a/tests/benchmark/test_validation.py b/tests/benchmark/test_validation.py index 63d787e101..963dc72a1e 100644 --- a/tests/benchmark/test_validation.py +++ b/tests/benchmark/test_validation.py @@ -13,10 +13,10 @@ # License for the specific language governing permissions and limitations # under the License. -import mock import os from glanceclient import exc as glance_exc +import mock from novaclient import exceptions as nova_exc from rally.benchmark import validation diff --git a/tests/cmd/commands/test_deployment.py b/tests/cmd/commands/test_deployment.py index 3554a6c605..eaf7da1a93 100644 --- a/tests/cmd/commands/test_deployment.py +++ b/tests/cmd/commands/test_deployment.py @@ -13,10 +13,11 @@ # License for the specific language governing permissions and limitations # under the License. -import mock import os import uuid +import mock + from rally.cmd.commands import deployment from rally import exceptions from tests import test diff --git a/tests/cmd/commands/test_show.py b/tests/cmd/commands/test_show.py index 74e4c97a59..9a6512c36d 100644 --- a/tests/cmd/commands/test_show.py +++ b/tests/cmd/commands/test_show.py @@ -13,9 +13,10 @@ # License for the specific language governing permissions and limitations # under the License. -import mock import uuid +import mock + from rally.cmd.commands import show from tests import fakes from tests import test diff --git a/tests/cmd/commands/test_task.py b/tests/cmd/commands/test_task.py index d649a3c7cb..83875d59f7 100644 --- a/tests/cmd/commands/test_task.py +++ b/tests/cmd/commands/test_task.py @@ -13,9 +13,10 @@ # License for the specific language governing permissions and limitations # under the License. -import mock import uuid +import mock + from rally.cmd.commands import task from rally import exceptions from tests import test diff --git a/tests/cmd/commands/test_use.py b/tests/cmd/commands/test_use.py index c41de27ce4..9648cd02bd 100644 --- a/tests/cmd/commands/test_use.py +++ b/tests/cmd/commands/test_use.py @@ -13,10 +13,11 @@ # License for the specific language governing permissions and limitations # under the License. -import mock import os import uuid +import mock + from rally.cmd.commands import use from rally.cmd import envutils from rally import exceptions diff --git a/tests/cmd/commands/test_verify.py b/tests/cmd/commands/test_verify.py index ea8fbb2f9c..d31ef0f587 100644 --- a/tests/cmd/commands/test_verify.py +++ b/tests/cmd/commands/test_verify.py @@ -13,9 +13,10 @@ # License for the specific language governing permissions and limitations # under the License. -import mock import uuid +import mock + from rally.cmd.commands import verify from rally import consts from tests import test diff --git a/tests/cmd/test_cliutils.py b/tests/cmd/test_cliutils.py index 8272943a81..b444a20327 100644 --- a/tests/cmd/test_cliutils.py +++ b/tests/cmd/test_cliutils.py @@ -14,7 +14,6 @@ # under the License. from rally.cmd import cliutils - from tests import test diff --git a/tests/cmd/test_envutils.py b/tests/cmd/test_envutils.py index f93e3bd9d6..6c87043d78 100644 --- a/tests/cmd/test_envutils.py +++ b/tests/cmd/test_envutils.py @@ -13,10 +13,11 @@ # License for the specific language governing permissions and limitations # under the License. -import mock import os import StringIO +import mock + from rally.cmd import envutils from rally import exceptions from tests import test @@ -94,7 +95,7 @@ class EnvUtilsTestCase(test.TestCase): @mock.patch.dict(os.environ, values={envutils.ENV_DEPLOYMENT: 'test_deployment_id', - envutils.ENV_TASK: 'test_task_id'}, + envutils.ENV_TASK: 'test_task_id'}, clear=True) @mock.patch('os.path.exists') @mock.patch('rally.cmd.envutils.fileutils.update_env_file') diff --git a/tests/cmd/test_manage.py b/tests/cmd/test_manage.py index 42f2ad5b76..b3b95f70c8 100644 --- a/tests/cmd/test_manage.py +++ b/tests/cmd/test_manage.py @@ -13,10 +13,11 @@ # License for the specific language governing permissions and limitations # under the License. -import mock import sys import uuid +import mock + from rally.cmd import manage from tests import test diff --git a/tests/deploy/engines/test_devstack.py b/tests/deploy/engines/test_devstack.py index 216689a4a1..55bb9278e1 100644 --- a/tests/deploy/engines/test_devstack.py +++ b/tests/deploy/engines/test_devstack.py @@ -13,9 +13,10 @@ # License for the specific language governing permissions and limitations # under the License. +import uuid + import jsonschema import mock -import uuid from rally.deploy.engines import devstack from tests import test diff --git a/tests/deploy/serverprovider/providers/test_lxc.py b/tests/deploy/serverprovider/providers/test_lxc.py index 57899f841a..72ca0dc822 100644 --- a/tests/deploy/serverprovider/providers/test_lxc.py +++ b/tests/deploy/serverprovider/providers/test_lxc.py @@ -163,13 +163,13 @@ class LxcHostTestCase(test.TestCase): self.assertEqual(['name'], self.host.containers) self.host.configure_container.assert_called_once_with('name') - #check with no btrfs + # check with no btrfs self.host._backingstore = '' self.host.create_container('name', 'dist') self.assertEqual(mock.call('lxc-create -n name -t dist'), self.server.ssh.run.mock_calls[1]) - #check release + # check release self.host.create_container('name', 'ubuntu', 'raring') self.host.create_container('name', 'debian', 'woody') expected = [mock.call('lxc-create -n name -t ubuntu -- -r raring'), @@ -184,7 +184,7 @@ class LxcHostTestCase(test.TestCase): ' -o src -n name') self.assertEqual(['name'], self.host.containers) - #check with no btrfs + # check with no btrfs self.host._backingstore = '' self.host.create_clone('name', 'src') self.assertEqual(mock.call('lxc-clone -o src -n name'), diff --git a/tests/deploy/serverprovider/providers/test_openstack.py b/tests/deploy/serverprovider/providers/test_openstack.py index a2bc4a56c7..3ca20dddd6 100644 --- a/tests/deploy/serverprovider/providers/test_openstack.py +++ b/tests/deploy/serverprovider/providers/test_openstack.py @@ -16,7 +16,6 @@ """Tests for OpenStack VM provider.""" import jsonschema - import mock from oslotest import mockpatch diff --git a/tests/deploy/serverprovider/providers/test_virsh.py b/tests/deploy/serverprovider/providers/test_virsh.py index 6384e616f4..41c4164cfa 100644 --- a/tests/deploy/serverprovider/providers/test_virsh.py +++ b/tests/deploy/serverprovider/providers/test_virsh.py @@ -13,11 +13,11 @@ # License for the specific language governing permissions and limitations # under the License. -import jsonschema -import netaddr import os +import jsonschema import mock +import netaddr from oslotest import mockpatch from rally.deploy.serverprovider.providers import virsh diff --git a/tests/deploy/test_engine.py b/tests/deploy/test_engine.py index 5d27be89aa..3c8b01efd0 100644 --- a/tests/deploy/test_engine.py +++ b/tests/deploy/test_engine.py @@ -15,9 +15,10 @@ """Test for deploy engines.""" -import mock import uuid +import mock + from rally import consts from rally import deploy from rally import exceptions diff --git a/tests/deploy/test_multihost.py b/tests/deploy/test_multihost.py index 144b2838db..81077275fd 100644 --- a/tests/deploy/test_multihost.py +++ b/tests/deploy/test_multihost.py @@ -14,9 +14,10 @@ # under the License. -import mock import uuid +import mock + from rally import consts from rally import deploy from tests import fakes diff --git a/tests/fakes.py b/tests/fakes.py index 56410ddb14..21da873138 100644 --- a/tests/fakes.py +++ b/tests/fakes.py @@ -19,12 +19,12 @@ import re import string import uuid -import mock - from ceilometerclient import exc as ceilometer_exc from glanceclient import exc +import mock from neutronclient.common import exceptions as neutron_exceptions from novaclient import exceptions as nova_exceptions + from rally.benchmark.context import base as base_ctx from rally.benchmark.scenarios import base from rally.objects import endpoint @@ -57,6 +57,7 @@ def generate_mac(): def setup_dict(data, required=None, defaults=None): """Setup and validate dict based on mandatory keys and default data. + This function reduces code that constructs dict objects with specific schema (e.g. for API data). @@ -620,8 +621,8 @@ class FakeNeutronClient(object): def add_interface_router(self, router_id, data): subnet_id = data["subnet_id"] - if router_id not in self.__routers\ - or subnet_id not in self.__subnets: + if (router_id not in self.__routers or + subnet_id not in self.__subnets): raise neutron_exceptions.NeutronClientException subnet = self.__subnets[subnet_id] @@ -769,8 +770,8 @@ class FakeNeutronClient(object): def remove_interface_router(self, router_id, data): subnet_id = data["subnet_id"] - if router_id not in self.__routers\ - or subnet_id not in self.__subnets: + if (router_id not in self.__routers + or subnet_id not in self.__subnets): raise neutron_exceptions.NeutronClientException subnet = self.__subnets[subnet_id] diff --git a/tests/objects/test_deploy.py b/tests/objects/test_deploy.py index 5069da7156..6f1738e548 100644 --- a/tests/objects/test_deploy.py +++ b/tests/objects/test_deploy.py @@ -15,9 +15,10 @@ """Tests for db.deploy layer.""" -import mock import uuid +import mock + from rally import consts from rally import objects from tests import test diff --git a/tests/objects/test_task.py b/tests/objects/test_task.py index a09213ccb7..d55e2abad2 100644 --- a/tests/objects/test_task.py +++ b/tests/objects/test_task.py @@ -16,9 +16,10 @@ """Tests for db.task layer.""" import json -import mock import uuid +import mock + from rally import consts from rally import objects from tests import test diff --git a/tests/orchestrator/test_api.py b/tests/orchestrator/test_api.py index b5cdf1ab11..32f0db0d10 100644 --- a/tests/orchestrator/test_api.py +++ b/tests/orchestrator/test_api.py @@ -15,9 +15,10 @@ """ Test for orchestrator. """ -import mock import uuid +import mock + from rally.benchmark.scenarios import base from rally import consts from rally.orchestrator import api diff --git a/tests/test.py b/tests/test.py index a90cd61093..d3e1a1fbb1 100644 --- a/tests/test.py +++ b/tests/test.py @@ -14,7 +14,6 @@ # under the License. import mock - from oslotest import base from rally import db diff --git a/tests/test_fileutils.py b/tests/test_fileutils.py index 9a712f5d24..3091007e5b 100644 --- a/tests/test_fileutils.py +++ b/tests/test_fileutils.py @@ -12,9 +12,11 @@ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. -import mock + import os +import mock + from rally import fileutils from tests import test diff --git a/tests/test_fuelclient.py b/tests/test_fuelclient.py index 980bb4fdba..e3d8ec8c73 100644 --- a/tests/test_fuelclient.py +++ b/tests/test_fuelclient.py @@ -13,12 +13,13 @@ # License for the specific language governing permissions and limitations # under the License. +import copy + +import mock + from rally.deploy.fuel import fuelclient from tests import test -import copy -import mock - class FuelNodeTestCase(test.TestCase): diff --git a/tests/test_osclients.py b/tests/test_osclients.py index 040defe0da..49cecb8601 100644 --- a/tests/test_osclients.py +++ b/tests/test_osclients.py @@ -13,9 +13,8 @@ # License for the specific language governing permissions and limitations # under the License. -import mock - from keystoneclient import exceptions as keystone_exceptions +import mock from oslo.config import cfg from rally import exceptions @@ -49,8 +48,8 @@ class OSClientsTestCase(test.TestCase): @mock.patch("rally.osclients.Clients.keystone") def test_verified_keystone_user_not_admin(self, mock_keystone): mock_keystone.return_value = fakes.FakeKeystoneClient() - mock_keystone.return_value.auth_ref["user"]["roles"] = \ - [{"name": "notadmin"}] + mock_keystone.return_value.auth_ref["user"]["roles"] = [{"name": + "notadmin"}] self.assertRaises(exceptions.InvalidAdminException, self.clients.verified_keystone) diff --git a/tests/test_utils.py b/tests/test_utils.py index 71790dcd20..589aee2bc7 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -16,11 +16,11 @@ """Test for Rally utils.""" from __future__ import print_function - -import mock import sys import time +import mock + from rally import exceptions from rally.openstack.common.gettextutils import _ from rally import utils diff --git a/tests/verification/verifiers/test_config.py b/tests/verification/verifiers/test_config.py index 83773f11ae..dfdae069a7 100644 --- a/tests/verification/verifiers/test_config.py +++ b/tests/verification/verifiers/test_config.py @@ -13,8 +13,9 @@ # License for the specific language governing permissions and limitations # under the License. -import mock import os + +import mock from oslo.config import cfg from six.moves import http_client as httplib @@ -78,10 +79,11 @@ class ConfigTestCase(test.TestCase): service = "test_service" url = "test_url" # mocked at setUp - self.conf_generator.keystoneclient.auth_ref = {"serviceCatalog": - [{"name": service, - "endpoints": - [{"publicURL": url}]}]} + self.conf_generator.keystoneclient.auth_ref = { + "serviceCatalog": [{ + "name": service, + "endpoints": [{"publicURL": url}] + }]} self.assertEqual(self.conf_generator._get_url(service), url) @mock.patch("rally.verification.verifiers.tempest.config.TempestConf" diff --git a/tests/verification/verifiers/test_tempest.py b/tests/verification/verifiers/test_tempest.py index 1f8c526b57..29bf7522d3 100644 --- a/tests/verification/verifiers/test_tempest.py +++ b/tests/verification/verifiers/test_tempest.py @@ -13,9 +13,10 @@ # License for the specific language governing permissions and limitations # under the License. -import mock import os +import mock + from rally.verification.verifiers.tempest import tempest from tests import test diff --git a/tests_ci/test_cli.py b/tests_ci/test_cli.py index 10e9dfcdb0..f1511b8a0e 100644 --- a/tests_ci/test_cli.py +++ b/tests_ci/test_cli.py @@ -14,13 +14,14 @@ # under the License. import ConfigParser -import mock import os import shutil import subprocess import tempfile import unittest +import mock + """Test rally command line interface.