Implement new random name generator for remaining scenario plugins

This switches all remaining scenarios to using the new consistent
random name generator. Keystone scenarios were switched in a previous
commit.

Implements blueprint: consistent-resource-names
Change-Id: I4d7defc328a516e7f84744c9a0fcaeb3b5f94d0c
This commit is contained in:
Chris St. Pierre 2015-10-16 07:46:52 -05:00
parent 0f8c2185e4
commit ff779b7176
58 changed files with 377 additions and 500 deletions

View File

@ -1,8 +1,7 @@
---
ZaqarBasic.create_queue:
-
args:
name_length: 10
args: {}
runner:
type: "constant"
times: 100
@ -14,7 +13,6 @@
ZaqarBasic.producer_consumer:
-
args:
name_length: 10
min_msg_count: 50
max_msg_count: 200
runner:

View File

@ -18,9 +18,11 @@ from neutronclient.common import exceptions as neutron_exceptions
from saharaclient.api import base as saharaclient_base
from rally.common import log as logging
from rally.common import utils
from rally.plugins.openstack.context.cleanup import base
from rally.plugins.openstack import scenario
from rally.plugins.openstack.scenarios.fuel import utils as futils
from rally.plugins.openstack.scenarios.keystone import utils as kutils
from rally.plugins.openstack.scenarios.nova import utils as nova_utils
from rally.plugins.openstack.wrappers import keystone as keystone_wrapper
LOG = logging.getLogger(__name__)
@ -126,7 +128,8 @@ class NovaFloatingIpsBulk(SynchronizedDeletion, base.ResourceManager):
def list(self):
return [floating_ip for floating_ip in self._manager().list()
if floating_ip.pool.startswith("rally_fip_pool_")]
if utils.name_matches_object(floating_ip.pool,
nova_utils.NovaScenario)]
@base.resource("nova", "networks", order=next(_nova_order),
@ -135,7 +138,9 @@ class NovaNetworks(SynchronizedDeletion, base.ResourceManager):
def list(self):
return [net for net in self._manager().list()
if net.label.startswith("rally_novanet")]
if (utils.name_matches_object(net.label,
nova_utils.NovaScenario) or
net.label.startswith("rally_novanet"))]
# EC2
@ -567,8 +572,7 @@ class FuelEnvironment(base.ResourceManager):
def list(self):
return [env for env in self._manager().list()
if env["name"].startswith(
scenario.OpenStackScenario.RESOURCE_NAME_PREFIX)]
if utils.name_matches_object(env["name"], futils.FuelScenario)]
# KEYSTONE

View File

@ -86,8 +86,7 @@ class ImageGenerator(context.Context):
image = glance_scenario._create_image(
image_container, image_url, image_type,
name=cur_name, prefix="rally_ctx_image_",
min_ram=self.config.get("min_ram", 0),
name=cur_name, min_ram=self.config.get("min_ram", 0),
min_disk=self.config.get("min_disk", 0))
current_images.append(image.id)

View File

@ -155,7 +155,6 @@ class BaseCustomImageGenerator(context.Context):
vm_scenario = vmtasks.VMTasks(self.context, clients=clients)
server, fip = vm_scenario._boot_server_with_fip(
name=self.generate_random_name(),
image=image_id, flavor=flavor_id,
floating_network=self.config.get("floating_network"),
userdata=self.config.get("userdata"),

View File

@ -24,6 +24,10 @@ configure = scenario.configure
class OpenStackScenario(scenario.Scenario):
"""Base class for all OpenStack scenarios."""
# TODO(stpierre): this is still used by some cleanup routines;
# remove it when they're using the new random name generator
RESOURCE_NAME_PREFIX = "rally_"
def __init__(self, context=None, admin_clients=None, clients=None):
super(OpenStackScenario, self).__init__(context)
if context:

View File

@ -20,15 +20,13 @@ from rally.task import utils as bench_utils
class CeilometerScenario(scenario.OpenStackScenario):
"""Base class for Ceilometer scenarios with basic atomic actions."""
RESOURCE_NAME_PREFIX = "rally_ceilometer_"
def _get_alarm_dict(self, **kwargs):
"""Prepare and return an alarm dict for creating an alarm.
:param kwargs: optional parameters to create alarm
:returns: alarm dictionary used to create an alarm
"""
alarm_id = self._generate_random_name()
alarm_id = self.generate_random_name()
alarm = {"alarm_id": alarm_id,
"name": alarm_id,
"description": "Test Alarm"}
@ -205,11 +203,10 @@ class CeilometerScenario(scenario.OpenStackScenario):
def _create_meter(self, **kwargs):
"""Create a new meter.
:param name_length: Length of meter name to be generated
:param kwargs: Contains the optional attributes for meter creation
:returns: Newly created meter
"""
name = self._generate_random_name()
name = self.generate_random_name()
samples = self.clients("ceilometer").samples.create(
counter_name=name, **kwargs)
return samples[0]
@ -262,8 +259,7 @@ class CeilometerScenario(scenario.OpenStackScenario):
"counter_unit": counter_unit,
"counter_volume": counter_volume,
"resource_id": resource_id if resource_id
else self._generate_random_name(
prefix="rally_resource_")})
else self.generate_random_name()})
return self.clients("ceilometer").samples.create(**kwargs)
@atomic.action_timer("ceilometer.query_samples")

View File

@ -52,8 +52,6 @@ CONF.register_opts(CINDER_BENCHMARK_OPTS, group=benchmark_group)
class CinderScenario(scenario.OpenStackScenario):
"""Base class for Cinder scenarios with basic atomic actions."""
RESOURCE_NAME_PREFIX = "rally_volume_"
@atomic.action_timer("cinder.list_volumes")
def _list_volumes(self, detailed=True):
"""Returns user volumes list."""
@ -80,9 +78,9 @@ class CinderScenario(scenario.OpenStackScenario):
for i in range(sets):
metadata = {}
for j in range(set_size):
key = self._generate_random_name()
key = self.generate_random_name()
keys.append(key)
metadata[key] = self._generate_random_name()
metadata[key] = self.generate_random_name()
self.clients("cinder").volumes.set_metadata(volume, metadata)
return keys
@ -130,7 +128,7 @@ class CinderScenario(scenario.OpenStackScenario):
:returns: Created volume object
"""
kwargs["display_name"] = kwargs.get("display_name",
self._generate_random_name())
self.generate_random_name())
if isinstance(size, dict):
size = random.randint(size["min"], size["max"])
@ -152,17 +150,15 @@ class CinderScenario(scenario.OpenStackScenario):
def _update_volume(self, volume, **update_volume_args):
"""Update name and description for this volume
This atomic function updates volume display name and description
This atomic function updates volume information. The volume
display name is always changed, and additional update
arguments may also be specified.
:param volume: volume object
:param update_volume_args: dict, contains values to be updated.
"""
kwargs = {}
kwargs["display_name"] = update_volume_args.get(
"display_name", self._generate_random_name("_"))
kwargs["display_description"] = update_volume_args.get(
"display_description", self._generate_random_name("_"))
self.clients("cinder").volumes.update(volume, **kwargs)
update_volume_args["display_name"] = self.generate_random_name()
self.clients("cinder").volumes.update(volume, **update_volume_args)
@atomic.action_timer("cinder.delete_volume")
def _delete_volume(self, volume):
@ -224,7 +220,7 @@ class CinderScenario(scenario.OpenStackScenario):
ami, ari, aki, vhd, vmdk, raw, qcow2, vdi and iso
:returns: Returns created image object
"""
resp, img = volume.upload_to_image(force, self._generate_random_name(),
resp, img = volume.upload_to_image(force, self.generate_random_name(),
container_format, disk_format)
# NOTE (e0ne): upload_to_image changes volume status to uploading so
# we need to wait until it will be available.
@ -261,7 +257,7 @@ class CinderScenario(scenario.OpenStackScenario):
:returns: Created snapshot object
"""
kwargs["display_name"] = kwargs.get("display_name",
self._generate_random_name())
self.generate_random_name())
kwargs["force"] = force
snapshot = self.clients("cinder").volume_snapshots.create(volume_id,
**kwargs)

View File

@ -21,8 +21,6 @@ from rally.task import atomic
class DesignateScenario(scenario.OpenStackScenario):
"""Base class for Designate scenarios with basic atomic actions."""
RESOURCE_NAME_PREFIX = "rally_"
@atomic.action_timer("designate.create_domain")
def _create_domain(self, domain=None):
"""Create domain.
@ -33,7 +31,7 @@ class DesignateScenario(scenario.OpenStackScenario):
domain = domain or {}
domain.setdefault("email", "root@random.name")
domain.setdefault("name", "%s.name." % self._generate_random_name())
domain["name"] = "%s.name." % self.generate_random_name()
return self.clients("designate").domains.create(domain)
@atomic.action_timer("designate.list_domains")
@ -63,8 +61,8 @@ class DesignateScenario(scenario.OpenStackScenario):
"""
record = record or {}
record.setdefault("type", "A")
record.setdefault("name", "%s.%s" % (self._generate_random_name(),
domain["name"]))
record["name"] = "%s.%s" % (self.generate_random_name(),
domain["name"])
record.setdefault("data", "10.0.0.1")
client = self.clients("designate")
@ -102,7 +100,7 @@ class DesignateScenario(scenario.OpenStackScenario):
"""
server = server or {}
server.setdefault("name", "name.%s." % self._generate_random_name())
server["name"] = "name.%s." % self.generate_random_name()
return self.admin_clients("designate").servers.create(server)
@atomic.action_timer("designate.list_servers")

View File

@ -120,18 +120,14 @@ class FuelScenario(scenario.OpenStackScenario):
@atomic.action_timer("fuel.list_environments")
def _list_environments(self):
return [env for env in self.admin_clients("fuel").environment.list()
if env["name"].startswith(
scenario.OpenStackScenario.RESOURCE_NAME_PREFIX)]
return self.admin_clients("fuel").environment.list()
@atomic.action_timer("fuel.create_environment")
def _create_environment(self, release_id=1,
network_provider="neutron",
deployment_mode="ha_compact",
net_segment_type="vlan"):
name = self._generate_random_name(
prefix=scenario.OpenStackScenario.RESOURCE_NAME_PREFIX)
name = self.generate_random_name()
env = self.admin_clients("fuel").environment.create(
name, release_id, network_provider, deployment_mode,
net_segment_type)

View File

@ -24,9 +24,6 @@ from rally.task import validation
class GlanceImages(utils.GlanceScenario, nova_utils.NovaScenario):
"""Benchmark scenarios for Glance images."""
RESOURCE_NAME_PREFIX = "rally_image_"
RESOURCE_NAME_LENGTH = 16
@types.set(image_location=types.FilePathOrUrlType)
@validation.required_services(consts.Service.GLANCE)
@validation.required_openstack(users=True)

View File

@ -60,7 +60,7 @@ class GlanceScenario(scenario.OpenStackScenario):
@atomic.action_timer("glance.create_image")
def _create_image(self, container_format, image_location, disk_format,
name=None, prefix=None, length=None, **kwargs):
**kwargs):
"""Create a new image.
:param container_format: container format of image. Acceptable
@ -68,18 +68,12 @@ class GlanceScenario(scenario.OpenStackScenario):
:param image_location: image file location
:param disk_format: disk format of image. Acceptable formats:
ami, ari, aki, vhd, vmdk, raw, qcow2, vdi, and iso
:param name: string used to name the image
:param prefix: prefix of generated image name if name not specified
ignore if name specified
:param length: length of autometic generated part in image name
ignore if name specified
:param kwargs: optional parameters to create image
:returns: image object
"""
name = name or self._generate_random_name(prefix, length)
kw = {
"name": name,
"name": self.generate_random_name(),
"container_format": container_format,
"disk_format": disk_format,
}

View File

@ -24,9 +24,6 @@ from rally.task import validation
class HeatStacks(utils.HeatScenario):
"""Benchmark scenarios for Heat stacks."""
RESOURCE_NAME_PREFIX = "rally_stack_"
RESOURCE_NAME_LENGTH = 7
@types.set(template_path=types.FileType, files=types.FileTypeDict)
@validation.required_services(consts.Service.HEAT)
@validation.required_openstack(users=True)

View File

@ -128,7 +128,7 @@ class HeatScenario(scenario.OpenStackScenario):
:returns: object of stack
"""
stack_name = self._generate_random_name(prefix="rally_stack_")
stack_name = self.generate_random_name()
kw = {
"stack_name": stack_name,
"disable_rollback": True,

View File

@ -17,8 +17,6 @@ import string
from oslo_config import cfg
from rally.common import utils
from rally.plugins.openstack import scenario
from rally.task import atomic
@ -38,6 +36,20 @@ CONF.register_opts(IRONIC_BENCHMARK_OPTS, group=benchmark_group)
class IronicScenario(scenario.OpenStackScenario):
"""Base class for Ironic scenarios with basic atomic actions."""
# NOTE(stpierre): Ironic has two name checkers. The new-style
# checker, in API v1.10+, is quite relaxed and will Just Work with
# the default random name pattern. (See
# https://bugs.launchpad.net/ironic/+bug/1434376.) The old-style
# checker *claims* to implement RFCs 952 and 1123, but it doesn't
# actually. (See https://bugs.launchpad.net/ironic/+bug/1468508
# for details.) The default RESOURCE_NAME_FORMAT works fine for
# the new-style checker, but the old-style checker only allows
# underscores after the first dot, for reasons that I'm sure are
# entirely obvious, so we have to supply a bespoke format for
# Ironic names.
RESOURCE_NAME_FORMAT = "s-rally-XXXXXXXX-XXXXXXXX"
RESOURCE_NAME_ALLOWED_CHARACTERS = string.ascii_lowercase + string.digits
@atomic.action_timer("ironic.create_node")
def _create_node(self, **kwargs):
"""Create node immediately.
@ -45,17 +57,7 @@ class IronicScenario(scenario.OpenStackScenario):
:param kwargs: optional parameters to create image
:returns: node object
"""
if "name" not in kwargs:
# NOTE(rvasilets): can't use _generate_random_name() because
# ironic have specific format for node name.
# Check that the supplied hostname conforms to:
# * http://en.wikipedia.org/wiki/Hostname
# * http://tools.ietf.org/html/rfc952
# * http://tools.ietf.org/html/rfc1123
# or the name could be just uuid.
kwargs["name"] = utils.generate_random_name(
prefix="rally", choice=string.ascii_lowercase + string.digits)
kwargs["name"] = self.generate_random_name()
return self.admin_clients("ironic").node.create(**kwargs)
@atomic.action_timer("ironic.list_nodes")

View File

@ -13,6 +13,7 @@
# License for the specific language governing permissions and limitations
# under the License.
from rally.common import utils as rutils
from rally import consts
from rally.plugins.openstack import scenario
from rally.plugins.openstack.scenarios.manila import utils
@ -64,6 +65,9 @@ class ManilaShares(utils.ManilaScenario):
@validation.required_services(consts.Service.MANILA)
@validation.required_openstack(users=True)
@scenario.configure(context={"cleanup": ["manila"]})
@rutils.log_deprecated_args(
"The 'name' argument to create_and_delete_service will be ignored",
"1.1.2", ["name"], once=True)
def create_share_network_and_delete(self,
neutron_net_id=None,
neutron_subnet_id=None,
@ -75,14 +79,12 @@ class ManilaShares(utils.ManilaScenario):
:param neutron_net_id: ID of Neutron network
:param neutron_subnet_id: ID of Neutron subnet
:param nova_net_id: ID of Nova network
:param name: share network name
:param description: share network description
"""
share_network = self._create_share_network(
neutron_net_id=neutron_net_id,
neutron_subnet_id=neutron_subnet_id,
nova_net_id=nova_net_id,
name=name,
description=description,
)
self._delete_share_network(share_network)
@ -90,6 +92,9 @@ class ManilaShares(utils.ManilaScenario):
@validation.required_services(consts.Service.MANILA)
@validation.required_openstack(users=True)
@scenario.configure(context={"cleanup": ["manila"]})
@rutils.log_deprecated_args(
"The 'name' argument to create_and_delete_service will be ignored",
"1.1.2", ["name"], once=True)
def create_share_network_and_list(self,
neutron_net_id=None,
neutron_subnet_id=None,
@ -103,7 +108,6 @@ class ManilaShares(utils.ManilaScenario):
:param neutron_net_id: ID of Neutron network
:param neutron_subnet_id: ID of Neutron subnet
:param nova_net_id: ID of Nova network
:param name: share network name
:param description: share network description
:param detailed: defines either to return detailed list of
objects or not.
@ -114,7 +118,6 @@ class ManilaShares(utils.ManilaScenario):
neutron_net_id=neutron_net_id,
neutron_subnet_id=neutron_subnet_id,
nova_net_id=nova_net_id,
name=name,
description=description,
)
self._list_share_networks(
@ -138,6 +141,9 @@ class ManilaShares(utils.ManilaScenario):
@validation.required_services(consts.Service.MANILA)
@validation.required_openstack(users=True)
@scenario.configure(context={"cleanup": ["manila"]})
@rutils.log_deprecated_args(
"The 'name' argument to create_and_delete_service will be ignored",
"1.1.2", ["name"], once=True)
def create_security_service_and_delete(self, security_service_type,
dns_ip=None, server=None,
domain=None, user=None,
@ -152,7 +158,6 @@ class ManilaShares(utils.ManilaScenario):
:param domain: security service domain
:param user: security identifier used by tenant
:param password: password used by user
:param name: security service name
:param description: security service description
"""
security_service = self._create_security_service(
@ -162,7 +167,6 @@ class ManilaShares(utils.ManilaScenario):
domain=domain,
user=user,
password=password,
name=name,
description=description,
)
self._delete_security_service(security_service)

View File

@ -84,7 +84,7 @@ class ManilaScenario(scenario.OpenStackScenario):
kwargs["share_network"] = share_networks[index]
if not kwargs.get("name"):
kwargs["name"] = self._generate_random_name()
kwargs["name"] = self.generate_random_name()
share = self.clients("manila").shares.create(
share_proto, size, **kwargs)
@ -129,22 +129,20 @@ class ManilaScenario(scenario.OpenStackScenario):
@atomic.action_timer("manila.create_share_network")
def _create_share_network(self, neutron_net_id=None,
neutron_subnet_id=None,
nova_net_id=None, name=None, description=None):
nova_net_id=None, description=None):
"""Create share network.
:param neutron_net_id: ID of Neutron network
:param neutron_subnet_id: ID of Neutron subnet
:param nova_net_id: ID of Nova network
:param name: share network name
:param description: share network description
:returns: instance of :class:`ShareNetwork`
"""
name = name or self._generate_random_name()
share_network = self.clients("manila").share_networks.create(
neutron_net_id=neutron_net_id,
neutron_subnet_id=neutron_subnet_id,
nova_net_id=nova_net_id,
name=name,
name=self.generate_random_name(),
description=description)
return share_network
@ -192,7 +190,7 @@ class ManilaScenario(scenario.OpenStackScenario):
@atomic.action_timer("manila.create_security_service")
def _create_security_service(self, security_service_type, dns_ip=None,
server=None, domain=None, user=None,
password=None, name=None, description=None):
password=None, description=None):
"""Create security service.
'Security service' is data container in Manila that stores info
@ -206,7 +204,6 @@ class ManilaScenario(scenario.OpenStackScenario):
:param domain: security service domain
:param user: security identifier used by tenant
:param password: password used by user
:param name: security service name
:param description: security service description
:returns: instance of :class:`SecurityService`
"""
@ -217,7 +214,7 @@ class ManilaScenario(scenario.OpenStackScenario):
domain=domain,
user=user,
password=password,
name=name,
name=self.generate_random_name(),
description=description)
return security_service

View File

@ -36,7 +36,7 @@ class MistralScenario(scenario.OpenStackScenario):
:returns: workbook object
"""
definition = yaml.safe_load(definition)
definition["name"] = self._generate_random_name(definition["name"])
definition["name"] = self.generate_random_name()
definition = yaml.safe_dump(definition)
return self.clients("mistral").workbooks.create(definition)

View File

@ -52,14 +52,14 @@ class MuranoScenario(scenario.OpenStackScenario):
return self.clients("murano").environments.list()
@atomic.action_timer("murano.create_environment")
def _create_environment(self, env_name=None):
def _create_environment(self):
"""Create environment.
:param env_name: String used to name environment
:returns: Environment instance
"""
env_name = env_name or self._generate_random_name()
env_name = self.generate_random_name()
return self.clients("murano").environments.create({"name": env_name})
@atomic.action_timer("murano.delete_environment")
@ -99,7 +99,7 @@ class MuranoScenario(scenario.OpenStackScenario):
app_id = str(uuid.uuid4())
data = {"?": {"id": app_id,
"type": full_package_name},
"name": self._generate_random_name("rally_")}
"name": self.generate_random_name()}
return self.clients("murano").services.post(
environment_id=environment.id, path="/", data=data,

View File

@ -26,8 +26,6 @@ LOG = logging.getLogger(__name__)
class NeutronScenario(scenario.OpenStackScenario):
"""Base class for Neutron scenarios with basic atomic actions."""
RESOURCE_NAME_PREFIX = "rally_net_"
RESOURCE_NAME_LENGTH = 16
SUBNET_IP_VERSION = 4
# TODO(rkiran): modify in case LBaaS-v2 requires
LB_METHOD = "ROUND_ROBIN"
@ -61,7 +59,7 @@ class NeutronScenario(scenario.OpenStackScenario):
:returns: None; kwargs is modified in situ.
"""
if "name" in kwargs:
kwargs["name"] = self._generate_random_name()
kwargs["name"] = self.generate_random_name()
LOG.warning(_("Cannot set name of %(type)s %(id)s explicitly; "
"setting to random string %(name)s") %
{"type": list(resource.keys())[0],
@ -89,7 +87,7 @@ class NeutronScenario(scenario.OpenStackScenario):
:param network_create_args: dict, POST /v2.0/networks request options
:returns: neutron network dict
"""
network_create_args.setdefault("name", self._generate_random_name())
network_create_args["name"] = self.generate_random_name()
return self.clients("neutron").create_network(
{"network": network_create_args})
@ -143,8 +141,7 @@ class NeutronScenario(scenario.OpenStackScenario):
network_wrapper.generate_cidr(start_cidr=start_cidr))
subnet_create_args["network_id"] = network_id
subnet_create_args.setdefault(
"name", self._generate_random_name("rally_subnet_"))
subnet_create_args["name"] = self.generate_random_name()
subnet_create_args.setdefault("ip_version", self.SUBNET_IP_VERSION)
return self.clients("neutron").create_subnet(
@ -185,8 +182,7 @@ class NeutronScenario(scenario.OpenStackScenario):
:param router_create_args: POST /v2.0/routers request options
:returns: neutron router dict
"""
router_create_args.setdefault(
"name", self._generate_random_name("rally_router_"))
router_create_args["name"] = self.generate_random_name()
if external_gw:
for network in self._list_networks():
@ -237,8 +233,7 @@ class NeutronScenario(scenario.OpenStackScenario):
:returns: neutron port dict
"""
port_create_args["network_id"] = network["network"]["id"]
port_create_args.setdefault(
"name", self._generate_random_name("rally_port_"))
port_create_args["name"] = self.generate_random_name()
return self.clients("neutron").create_port({"port": port_create_args})
@atomic.action_timer("neutron.list_ports")
@ -323,7 +318,7 @@ class NeutronScenario(scenario.OpenStackScenario):
"""
args = {"lb_method": self.LB_METHOD,
"protocol": self.LB_PROTOCOL,
"name": self._generate_random_name("rally_pool_"),
"name": self.generate_random_name(),
"subnet_id": subnet_id}
args.update(pool_create_args)
return self.clients("neutron").create_pool({"pool": args})
@ -382,7 +377,7 @@ class NeutronScenario(scenario.OpenStackScenario):
"""
args = {"protocol": self.LB_PROTOCOL,
"protocol_port": self.LB_PROTOCOL_PORT,
"name": self._generate_random_name("rally_vip_"),
"name": self.generate_random_name(),
"pool_id": pool["pool"]["id"],
"subnet_id": pool["pool"]["subnet_id"]}
args.update(vip_create_args)

View File

@ -32,8 +32,6 @@ class NovaSecurityGroupException(exceptions.RallyException):
class NovaSecGroup(utils.NovaScenario):
"""Benchmark scenarios for Nova security groups."""
RESOURCE_NAME_PREFIX = "rally_novasecgrp_"
@validation.required_parameters("security_group_count",
"rules_per_security_group")
@validation.required_services(consts.Service.NOVA)

View File

@ -33,9 +33,6 @@ class NovaServers(utils.NovaScenario,
cinder_utils.CinderScenario):
"""Benchmark scenarios for Nova servers."""
RESOURCE_NAME_PREFIX = "rally_novaserver_"
RESOURCE_NAME_LENGTH = 16
@types.set(image=types.ImageResourceType,
flavor=types.FlavorResourceType)
@validation.image_valid_on_flavor("flavor", "image")
@ -642,6 +639,6 @@ class NovaServers(utils.NovaScenario,
"""
server = self._boot_server(image, flavor, **kwargs)
address = network_wrapper.wrap(
self.clients, self.context["task"]).create_floating_ip(
self.clients, self.task).create_floating_ip(
tenant_id=server.tenant_id)
self._associate_floating_ip(server, address["ip"])

View File

@ -108,7 +108,7 @@ class NovaScenario(scenario.OpenStackScenario):
@atomic.action_timer("nova.boot_server")
def _boot_server(self, image_id, flavor_id,
auto_assign_nic=False, name=None, **kwargs):
auto_assign_nic=False, **kwargs):
"""Boot a server.
Returns when the server is actually booted and in "ACTIVE" state.
@ -119,11 +119,10 @@ class NovaScenario(scenario.OpenStackScenario):
:param image_id: int, image ID for server creation
:param flavor_id: int, flavor ID for server creation
:param auto_assign_nic: bool, whether or not to auto assign NICs
:param name: str, server name
:param kwargs: other optional parameters to initialize the server
:returns: nova Server instance
"""
server_name = name or self._generate_random_name()
server_name = self.generate_random_name()
secgroup = self.context.get("user", {}).get("secgroup")
if secgroup:
if "security_groups" not in kwargs:
@ -485,7 +484,7 @@ class NovaScenario(scenario.OpenStackScenario):
:returns: Created keypair name
"""
keypair_name = self._generate_random_name(prefix="rally_keypair_")
keypair_name = self.generate_random_name()
keypair = self.clients("nova").keypairs.create(keypair_name, **kwargs)
return keypair.name
@ -503,8 +502,8 @@ class NovaScenario(scenario.OpenStackScenario):
self.clients("nova").keypairs.delete(keypair_name)
@atomic.action_timer("nova.boot_servers")
def _boot_servers(self, image_id, flavor_id, requests, name_prefix=None,
instances_amount=1, auto_assign_nic=False, **kwargs):
def _boot_servers(self, image_id, flavor_id, requests, instances_amount=1,
auto_assign_nic=False, **kwargs):
"""Boot multiple servers.
Returns when all the servers are actually booted and are in the
@ -513,22 +512,18 @@ class NovaScenario(scenario.OpenStackScenario):
:param image_id: ID of the image to be used for server creation
:param flavor_id: ID of the flavor to be used for server creation
:param requests: Number of booting requests to perform
:param name_prefix: The prefix to use while naming the created servers.
The rest of the server names will be '_<number>'
:param instances_amount: Number of instances to boot per each request
:param auto_assign_nic: bool, whether or not to auto assign NICs
:param kwargs: other optional parameters to initialize the servers
:returns: List of created server objects
"""
if not name_prefix:
name_prefix = self._generate_random_name()
if auto_assign_nic and not kwargs.get("nics", False):
nic = self._pick_random_nic()
if nic:
kwargs["nics"] = nic
name_prefix = self.generate_random_name()
for i in range(requests):
self.clients("nova").servers.create("%s_%d" % (name_prefix, i),
image_id, flavor_id,
@ -538,8 +533,8 @@ class NovaScenario(scenario.OpenStackScenario):
# NOTE(msdubov): Nova python client returns only one server even when
# min_count > 1, so we have to rediscover all the
# created servers manually.
servers = filter(lambda server: server.name.startswith(name_prefix),
self.clients("nova").servers.list())
servers = [s for s in self.clients("nova").servers.list()
if s.name.startswith(name_prefix)]
time.sleep(CONF.benchmark.nova_server_boot_prepoll_delay)
servers = [utils.wait_for(
server,
@ -760,7 +755,7 @@ class NovaScenario(scenario.OpenStackScenario):
with atomic.ActionTimer(self, "nova.create_%s_security_groups" %
security_group_count):
for i in range(security_group_count):
sg_name = self._generate_random_name()
sg_name = self.generate_random_name()
sg = self.clients("nova").security_groups.create(sg_name,
sg_name)
security_groups.append(sg)
@ -790,8 +785,8 @@ class NovaScenario(scenario.OpenStackScenario):
with atomic.ActionTimer(self, "nova.update_%s_security_groups" %
len(security_groups)):
for sec_group in security_groups:
sg_new_name = self._generate_random_name()
sg_new_desc = self._generate_random_name()
sg_new_name = self.generate_random_name()
sg_new_desc = self.generate_random_name()
self.clients("nova").security_groups.update(sec_group.id,
sg_new_name,
sg_new_desc)
@ -816,7 +811,7 @@ class NovaScenario(scenario.OpenStackScenario):
def _create_floating_ips_bulk(self, ip_range, **kwargs):
"""Create floating IPs by range."""
ip_range = network_wrapper.generate_cidr(start_cidr=ip_range)
pool_name = self._generate_random_name(prefix="rally_fip_pool_")
pool_name = self.generate_random_name()
return self.admin_clients("nova").floating_ips_bulk.create(
ip_range=ip_range, pool=pool_name, **kwargs)
@ -852,7 +847,7 @@ class NovaScenario(scenario.OpenStackScenario):
:param ip_range: IP range in CIDR notation to create
"""
net_label = self._generate_random_name(prefix="rally_novanet")
net_label = self.generate_random_name()
ip_range = network_wrapper.generate_cidr(start_cidr=ip_range)
return self.admin_clients("nova").networks.create(
label=net_label, cidr=ip_range, **kwargs)

View File

@ -45,7 +45,7 @@ class SaharaJob(utils.SaharaScenario):
mains = self.context["tenant"]["sahara_mains"]
libs = self.context["tenant"]["sahara_libs"]
name = self._generate_random_name(prefix="job_")
name = self.generate_random_name()
job = self.clients("sahara").jobs.create(name=name,
type=job_type,
description="",

View File

@ -58,8 +58,6 @@ CONF.register_opts(SAHARA_BENCHMARK_OPTS, group=benchmark_group)
class SaharaScenario(scenario.OpenStackScenario):
"""Base class for Sahara scenarios with basic atomic actions."""
RESOURCE_NAME_LENGTH = 20
@atomic.action_timer("sahara.list_node_group_templates")
def _list_node_group_templates(self):
"""Return user Node Group Templates list."""
@ -76,7 +74,7 @@ class SaharaScenario(scenario.OpenStackScenario):
the plugin
:returns: The created Template
"""
name = self._generate_random_name(prefix="master-ngt-")
name = self.generate_random_name()
return self.clients("sahara").node_group_templates.create(
name=name,
@ -97,7 +95,7 @@ class SaharaScenario(scenario.OpenStackScenario):
the plugin
:returns: The created Template
"""
name = self._generate_random_name(prefix="worker-ngt-")
name = self.generate_random_name()
return self.clients("sahara").node_group_templates.create(
name=name,
@ -354,7 +352,7 @@ class SaharaScenario(scenario.OpenStackScenario):
aa_processes = (sahara_consts.ANTI_AFFINITY_PROCESSES[plugin_name]
[hadoop_version])
name = self._generate_random_name(prefix="sahara-cluster-")
name = self.generate_random_name()
cluster_object = self.clients("sahara").clusters.create(
name=name,
@ -458,11 +456,10 @@ class SaharaScenario(scenario.OpenStackScenario):
raise exceptions.RallyException(
_("Swift Data Sources are not implemented yet"))
url = (url_prefix.rstrip("/") + "/%s" %
self._generate_random_name(length=10))
url = url_prefix.rstrip("/") + "/%s" % self.generate_random_name()
return self.clients("sahara").data_sources.create(
name=self._generate_random_name(prefix="out_"),
name=self.generate_random_name(),
description="",
data_source_type=ds_type,
url=url)

View File

@ -33,10 +33,9 @@ class SwiftScenario(scenario.OpenStackScenario):
**kwargs)
@atomic.optional_action_timer("swift.create_container")
def _create_container(self, container_name=None, public=False, **kwargs):
"""Create a new container with given name.
def _create_container(self, public=False, **kwargs):
"""Create a new container.
:param container_name: str, name of the container to create
:param public: bool, set container as public
:param atomic_action: bool, enable create container to be
tracked as an atomic action. added and
@ -50,9 +49,7 @@ class SwiftScenario(scenario.OpenStackScenario):
kwargs.setdefault("headers", {})
kwargs["headers"].setdefault("X-Container-Read", ".r:*,.rlistings")
if container_name is None:
container_name = self._generate_random_name(
prefix="rally_container_")
container_name = self.generate_random_name()
self.clients("swift").put_container(container_name, **kwargs)
return container_name
@ -89,13 +86,11 @@ class SwiftScenario(scenario.OpenStackScenario):
**kwargs)
@atomic.optional_action_timer("swift.upload_object")
def _upload_object(self, container_name, content, object_name=None,
**kwargs):
def _upload_object(self, container_name, content, **kwargs):
"""Upload content to a given container.
:param container_name: str, name of the container to upload object to
:param content: file stream, content to upload
:param object_name: str, name of the object to upload
:param atomic_action: bool, enable upload object to be tracked
as an atomic action. added and handled
by the optional_action_timer() decorator
@ -103,8 +98,7 @@ class SwiftScenario(scenario.OpenStackScenario):
:returns: tuple, (etag and object name)
"""
if object_name is None:
object_name = self._generate_random_name(prefix="rally_object_")
object_name = self.generate_random_name()
return (self.clients("swift").put_object(container_name, object_name,
content, **kwargs),

View File

@ -128,8 +128,7 @@ class VMScenario(nova_utils.NovaScenario, cinder_utils.CinderScenario):
internal_network = list(server.networks)[0]
fixed_ip = server.addresses[internal_network][0]["addr"]
fip = network_wrapper.wrap(self.clients,
self.context["task"]).create_floating_ip(
fip = network_wrapper.wrap(self.clients, self.task).create_floating_ip(
ext_network=floating_network,
tenant_id=server.tenant_id, fixed_ip=fixed_ip)
@ -146,7 +145,7 @@ class VMScenario(nova_utils.NovaScenario, cinder_utils.CinderScenario):
self._dissociate_floating_ip(server, fip["ip"],
atomic_action=False)
network_wrapper.wrap(
self.clients, self.context["task"]).delete_floating_ip(
self.clients, self.task).delete_floating_ip(
fip["id"],
wait=True)

View File

@ -14,42 +14,44 @@
import random
from rally.common import utils
from rally.plugins.openstack import scenario
from rally.plugins.openstack.scenarios.zaqar import utils as zutils
from rally.task import validation
class ZaqarBasic(zutils.ZaqarScenario):
"""Benchmark scenarios for Zaqar."""
@validation.number("name_length", minval=10)
@scenario.configure(context={"cleanup": ["zaqar"]})
def create_queue(self, name_length=10, **kwargs):
@utils.log_deprecated_args(
"The 'name_length' argument to create_queue is ignored",
"0.1.2", ["name_length"], once=True)
def create_queue(self, name_length=None, **kwargs):
"""Create a Zaqar queue with a random name.
:param name_length: length of generated (random) part of name
:param kwargs: other optional parameters to create queues like
"metadata"
"""
self._queue_create(name_length=name_length, **kwargs)
self._queue_create(**kwargs)
@validation.number("name_length", minval=10)
@scenario.configure(context={"cleanup": ["zaqar"]})
def producer_consumer(self, name_length=10,
@utils.log_deprecated_args(
"The 'name_length' argument to producer_consumer is ignored",
"0.1.2", ["name_length"], once=True)
def producer_consumer(self, name_length=None,
min_msg_count=50, max_msg_count=200, **kwargs):
"""Serial message producer/consumer.
Creates a Zaqar queue with random name, sends a set of messages
and then retrieves an iterator containing those.
:param name_length: length of generated (random) part of name
:param min_msg_count: min number of messages to be posted
:param max_msg_count: max number of messages to be posted
:param kwargs: other optional parameters to create queues like
"metadata"
"""
queue = self._queue_create(name_length=name_length, **kwargs)
queue = self._queue_create(**kwargs)
msg_count = random.randint(min_msg_count, max_msg_count)
messages = [{"body": {"id": idx}, "ttl": 360} for idx
in range(msg_count)]

View File

@ -20,15 +20,14 @@ class ZaqarScenario(scenario.OpenStackScenario):
"""Base class for Zaqar scenarios with basic atomic actions."""
@atomic.action_timer("zaqar.create_queue")
def _queue_create(self, name_length=10, **kwargs):
def _queue_create(self, **kwargs):
"""Create a Zaqar queue with random name.
:param name_length: length of generated (random) part of name
:param kwargs: other optional parameters to create queues like
"metadata"
:returns: Zaqar queue instance
"""
name = self._generate_random_name(length=name_length)
name = self.generate_random_name()
return self.clients("zaqar").queue(name, **kwargs)
@atomic.action_timer("zaqar.delete_queue")

View File

@ -100,11 +100,6 @@ class Scenario(plugin.Plugin,
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.
"""
# NOTE(stpierre): Old random name generator parameters, to be
# removed in a subsequent commit
RESOURCE_NAME_PREFIX = "rally_"
RESOURCE_NAME_LENGTH = 10
RESOURCE_NAME_FORMAT = "s_rally_XXXXXXXX_XXXXXXXX"
def __init__(self, context=None):
@ -113,14 +108,6 @@ class Scenario(plugin.Plugin,
self.task = self.context.get("task", {})
self._idle_duration = 0
@classmethod
def _generate_random_name(cls, prefix=None, length=None):
# NOTE(stpierre): Old random name generator function, to be
# removed in a subsequent commit
prefix = cls.RESOURCE_NAME_PREFIX if prefix is None else prefix
length = length or cls.RESOURCE_NAME_LENGTH
return utils.generate_random_name(prefix, length)
@staticmethod
def _validate_helper(validators, clients, config, deployment):
for validator in validators:

View File

@ -1,9 +1,7 @@
{
"ZaqarBasic.create_queue": [
{
"args": {
"name_length": 10
},
"args": {},
"runner": {
"type": "constant",
"times": 100,

View File

@ -1,8 +1,7 @@
---
ZaqarBasic.create_queue:
-
args:
name_length: 10
args: {}
runner:
type: "constant"
times: 100

View File

@ -2,7 +2,6 @@
"ZaqarBasic.producer_consumer": [
{
"args": {
"name_length": 10,
"min_msg_count": 50,
"max_msg_count": 200
},

View File

@ -2,10 +2,9 @@
ZaqarBasic.producer_consumer:
-
args:
name_length: 10
min_msg_count: 50
max_msg_count: 200
runner:
type: "constant"
times: 100
concurrency: 10
concurrency: 10

View File

@ -150,11 +150,15 @@ class NovaFloatingIpsBulkTestCase(test.TestCase):
self.assertEqual(ip_range.raw_resource.address, ip_range.id())
@mock.patch("%s.base.ResourceManager._manager" % BASE)
def test_list(self, mock_resource_manager__manager):
@mock.patch("rally.common.utils.name_matches_object")
def test_list(self, mock_name_matches_object,
mock_resource_manager__manager):
ip_range = [mock.MagicMock(), mock.MagicMock(), mock.MagicMock()]
ip_range[0].pool = "a"
ip_range[1].pool = "rally_fip_pool_a"
ip_range[2].pool = "rally_fip_pool_b"
mock_name_matches_object.side_effect = (lambda n, o:
n.startswith("rally"))
mock_resource_manager__manager().list.return_value = ip_range
self.assertEqual(ip_range[1:], resources.NovaFloatingIpsBulk().list())
@ -163,10 +167,15 @@ class NovaFloatingIpsBulkTestCase(test.TestCase):
class NovaNetworksTestCase(test.TestCase):
@mock.patch("%s.base.ResourceManager._manager" % BASE)
def test_list(self, mock_resource_manager__manager):
@mock.patch("rally.common.utils.name_matches_object")
def test_list(self, mock_name_matches_object,
mock_resource_manager__manager):
network = [mock.Mock(label="a"), mock.Mock(label="rally_novanet_a"),
mock.Mock(label="rally_novanet_b")]
mock_name_matches_object.side_effect = (lambda n, o:
n.startswith("rally"))
mock_resource_manager__manager.return_value.list.return_value = network
self.assertEqual(network[1:], resources.NovaNetworks().list())
mock_resource_manager__manager().list.assert_called_once_with()
@ -611,9 +620,13 @@ class FuelEnvironmentTestCase(test.TestCase):
mock__manager.return_value.get.assert_called_with(fres.id.return_value)
@mock.patch("%s.FuelEnvironment._manager" % BASE)
def test_list(self, mock__manager):
@mock.patch("rally.common.utils.name_matches_object")
def test_list(self, mock_name_matches_object, mock__manager):
envs = [{"name": "rally_one"}, {"name": "rally_two"},
{"name": "three"}]
mock__manager.return_value.list.return_value = envs
mock_name_matches_object.side_effect = (
lambda n, o: n.startswith("rally_"))
fres = resources.FuelEnvironment()
self.assertEqual(envs[:-1], fres.list())

View File

@ -85,7 +85,6 @@ class BaseCustomImageContextVMTestCase(test.TestCase):
generator_ctx = TestImageGenerator(self.context)
generator_ctx._customize_image = mock.MagicMock()
generator_ctx.generate_random_name = mock.Mock()
user = {
"endpoint": "endpoint",
@ -107,7 +106,6 @@ class BaseCustomImageContextVMTestCase(test.TestCase):
mock_vm_scenario._boot_server_with_fip.assert_called_once_with(
image="image", flavor="flavor",
name=generator_ctx.generate_random_name.return_value,
floating_network="floating",
key_name="keypair_name", security_groups=["secgroup_name"],
userdata=None, foo_arg="foo_value")

View File

@ -45,7 +45,7 @@ class CeilometerScenarioTestCase(test.ScenarioTestCase):
def test__create_alarm(self):
alarm_dict = {"alarm_id": "fake-alarm-id"}
orig_alarm_dict = copy.copy(alarm_dict)
self.scenario._generate_random_name = mock.Mock()
self.scenario.generate_random_name = mock.Mock()
self.assertEqual(self.scenario._create_alarm("fake-meter-name", 100,
alarm_dict),
self.clients("ceilometer").alarms.create.return_value)
@ -54,7 +54,7 @@ class CeilometerScenarioTestCase(test.ScenarioTestCase):
threshold=100,
description="Test Alarm",
alarm_id="fake-alarm-id",
name=self.scenario._generate_random_name.return_value)
name=self.scenario.generate_random_name.return_value)
# ensure that _create_alarm() doesn't modify the alarm dict as
# a side-effect
self.assertDictEqual(alarm_dict, orig_alarm_dict)
@ -199,12 +199,12 @@ class CeilometerScenarioTestCase(test.ScenarioTestCase):
"ceilometer.get_stats")
def test__create_meter(self):
self.scenario._generate_random_name = mock.Mock()
self.scenario.generate_random_name = mock.Mock()
self.assertEqual(
self.scenario._create_meter(fakearg="fakearg"),
self.clients("ceilometer").samples.create.return_value[0])
self.clients("ceilometer").samples.create.assert_called_once_with(
counter_name=self.scenario._generate_random_name.return_value,
counter_name=self.scenario.generate_random_name.return_value,
fakearg="fakearg")
self._test_atomic_action_timer(self.scenario.atomic_actions(),
"ceilometer.create_meter")
@ -239,7 +239,7 @@ class CeilometerScenarioTestCase(test.ScenarioTestCase):
"ceilometer.query_samples")
def test__create_sample_no_resource_id(self):
self.scenario._generate_random_name = mock.Mock()
self.scenario.generate_random_name = mock.Mock()
created_sample = self.scenario._create_sample("test-counter-name",
"test-counter-type",
"test-counter-unit",
@ -252,7 +252,7 @@ class CeilometerScenarioTestCase(test.ScenarioTestCase):
counter_type="test-counter-type",
counter_unit="test-counter-unit",
counter_volume="test-counter-volume",
resource_id=self.scenario._generate_random_name.return_value)
resource_id=self.scenario.generate_random_name.return_value)
self._test_atomic_action_timer(self.scenario.atomic_actions(),
"ceilometer.create_sample")

View File

@ -131,9 +131,12 @@ class CinderScenarioTestCase(test.ScenarioTestCase):
fake_volume = mock.MagicMock()
volume_update_args = {"display_name": "_updated",
"display_description": "_updated"}
self.scenario.generate_random_name = mock.Mock()
self.scenario._update_volume(fake_volume, **volume_update_args)
self.clients("cinder").volumes.update.assert_called_once_with(
fake_volume, display_name="_updated",
fake_volume,
display_name=self.scenario.generate_random_name.return_value,
display_description="_updated")
self._test_atomic_action_timer(self.scenario.atomic_actions(),
"cinder.update_volume")
@ -197,7 +200,7 @@ class CinderScenarioTestCase(test.ScenarioTestCase):
volume.upload_to_image.return_value = (None, image)
self.clients("cinder").images.get.return_value = image
self.scenario._generate_random_name = mock.Mock(
self.scenario.generate_random_name = mock.Mock(
return_value="test_vol")
self.scenario._upload_volume_to_image(volume, False,
"container", "disk")

View File

@ -14,6 +14,7 @@
# License for the specific language governing permissions and limitations
# under the License.
import ddt
import mock
from rally.plugins.openstack.scenarios.designate import utils
@ -22,6 +23,7 @@ from tests.unit import test
DESIGNATE_UTILS = "rally.plugins.openstack.scenarios.designate.utils."
@ddt.ddt
class DesignateScenarioTestCase(test.ScenarioTestCase):
def setUp(self):
@ -29,34 +31,25 @@ class DesignateScenarioTestCase(test.ScenarioTestCase):
self.domain = mock.Mock()
self.server = mock.Mock()
@mock.patch("rally.common.utils.generate_random_name")
def test_create_domain(self, mock_generate_random_name):
scenario = utils.DesignateScenario()
@ddt.data(
{},
{"email": "root@zone.name"})
def test_create_domain(self, domain_data):
random_name = "foo"
explicit_name = "bar.io."
email = "root@zone.name"
mock_generate_random_name.return_value = random_name
scenario = utils.DesignateScenario(context=self.context)
scenario.generate_random_name = mock.Mock(return_value=random_name)
self.clients("designate").domains.create.return_value = self.domain
expected = {"email": "root@random.name"}
expected.update(domain_data)
expected["name"] = "%s.name." % random_name
# Check that the defaults / randoms are used if nothing is specified
domain = scenario._create_domain()
domain = scenario._create_domain(domain_data)
self.clients("designate").domains.create.assert_called_once_with(
{"email": "root@random.name", "name": "%s.name." % random_name})
expected)
self.assertEqual(self.domain, domain)
self._test_atomic_action_timer(scenario.atomic_actions(),
"designate.create_domain")
self.clients("designate").domains.create.reset_mock()
# Check that when specifying zone defaults are not used...
data = {"email": email, "name": explicit_name}
domain = scenario._create_domain(data)
self.clients("designate").domains.create.assert_called_once_with(data)
self.assertEqual(self.domain, domain)
def test_list_domains(self):
scenario = utils.DesignateScenario(context=self.context)
return_domains_list = scenario._list_domains()
@ -73,36 +66,28 @@ class DesignateScenarioTestCase(test.ScenarioTestCase):
self._test_atomic_action_timer(scenario.atomic_actions(),
"designate.delete_domain")
@mock.patch("rally.common.utils.generate_random_name")
def test_create_record(self, mock_generate_random_name):
scenario = utils.DesignateScenario()
@ddt.data(
{},
{"data": "127.0.0.1"})
def test_create_record(self, record_data):
random_name = "foo"
domain_name = "zone.name."
random_record_name = "%s.%s" % (random_name, domain_name)
mock_generate_random_name.return_value = random_name
scenario = utils.DesignateScenario(context=self.context)
domain = {"name": domain_name, "id": "123"}
record_name = "%s.%s" % (random_name, domain_name)
# Create with randoms (name and type)
scenario._create_record(domain)
scenario = utils.DesignateScenario(context=self.context)
scenario.generate_random_name = mock.Mock(return_value=random_name)
expected = {"type": "A", "data": "10.0.0.1"}
expected.update(record_data)
expected["name"] = record_name
scenario._create_record(domain, record=record_data)
self.clients("designate").records.create.assert_called_once_with(
domain["id"],
{"name": random_record_name, "type": "A", "data": "10.0.0.1"})
domain["id"], expected)
self._test_atomic_action_timer(scenario.atomic_actions(),
"designate.create_record")
self.clients("designate").records.create.reset_mock()
# Specify name
record = {"name": "www.zone.name.", "type": "ASD"}
scenario._create_record(domain, record)
self.clients("designate").records.create.assert_called_once_with(
domain["id"], record)
def test_list_records(self):
scenario = utils.DesignateScenario(context=self.context)
return_records_list = scenario._list_records("123")
@ -127,14 +112,13 @@ class DesignateScenarioTestCase(test.ScenarioTestCase):
self.clients("designate").records.delete.assert_called_once_with(
domain_id, record_id)
@mock.patch("rally.common.utils.generate_random_name")
def test_create_server(self, mock_generate_random_name):
def test_create_server(self):
scenario = utils.DesignateScenario(context=self.context)
random_name = "foo"
scenario.generate_random_name = mock.Mock(return_value=random_name)
explicit_name = "bar.io."
mock_generate_random_name.return_value = random_name
self.admin_clients(
"designate").servers.create.return_value = self.server

View File

@ -160,11 +160,10 @@ class FuelClientTestCase(test.TestCase):
class FuelScenarioTestCase(test.ScenarioTestCase):
def test__list_environments(self):
self.admin_clients("fuel").environment.list.return_value = [
{"name": "some_name1"}, {"name": "rally_name2"}]
scenario = utils.FuelScenario(self.context)
self.assertEqual([{"name": "rally_name2"}],
scenario._list_environments())
self.assertEqual(
scenario._list_environments(),
self.admin_clients("fuel").environment.list.return_value)
self.admin_clients("fuel").environment.list.assert_called_once_with()
self._test_atomic_action_timer(scenario.atomic_actions(),
"fuel.list_environments")
@ -175,17 +174,14 @@ class FuelScenarioTestCase(test.ScenarioTestCase):
fuel_scenario = utils.FuelScenario()
fuel_scenario.admin_clients = self.admin_clients
fuel_scenario._generate_random_name = mock.Mock(
return_value="random_name")
fuel_scenario.generate_random_name = mock.Mock()
result = fuel_scenario._create_environment()
self.assertEqual(
self.admin_clients("fuel").environment.create.return_value["id"],
result)
fuel_scenario._generate_random_name.assert_called_once_with(
prefix=fuel_scenario.RESOURCE_NAME_PREFIX)
tmp_mck = self.admin_clients("fuel").environment.create
tmp_mck.assert_called_once_with(
fuel_scenario._generate_random_name.return_value, 1, "neutron",
fuel_scenario.generate_random_name.return_value, 1, "neutron",
"ha_compact", "vlan")
def test__delete_environment(self):

View File

@ -24,14 +24,14 @@ GLANCE_IMAGES = "rally.plugins.openstack.scenarios.glance.images.GlanceImages"
class GlanceImagesTestCase(test.ScenarioTestCase):
@mock.patch(GLANCE_IMAGES + "._generate_random_name")
@mock.patch(GLANCE_IMAGES + ".generate_random_name")
@mock.patch(GLANCE_IMAGES + "._list_images")
@mock.patch(GLANCE_IMAGES + "._create_image")
def test_create_and_list_image(self, mock__create_image,
mock__list_images,
mock__generate_random_name):
mock_generate_random_name):
glance_scenario = images.GlanceImages(self.context)
mock__generate_random_name.return_value = "test-rally-image"
mock_generate_random_name.return_value = "test-rally-image"
glance_scenario.create_and_list_image("cf", "url", "df",
fakearg="f")
mock__create_image.assert_called_once_with(
@ -44,16 +44,16 @@ class GlanceImagesTestCase(test.ScenarioTestCase):
glance_scenario.list_images()
mock__list_images.assert_called_once_with()
@mock.patch(GLANCE_IMAGES + "._generate_random_name")
@mock.patch(GLANCE_IMAGES + ".generate_random_name")
@mock.patch(GLANCE_IMAGES + "._delete_image")
@mock.patch(GLANCE_IMAGES + "._create_image")
def test_create_and_delete_image(
self, mock__create_image, mock__delete_image,
mock__generate_random_name):
mock_generate_random_name):
glance_scenario = images.GlanceImages(self.context)
fake_image = object()
mock__create_image.return_value = fake_image
mock__generate_random_name.return_value = "test-rally-image"
mock_generate_random_name.return_value = "test-rally-image"
glance_scenario.create_and_delete_image("cf", "url", "df",
fakearg="f")

View File

@ -30,13 +30,13 @@ class HeatStacksTestCase(test.ScenarioTestCase):
self.default_files = ["dummy_file.yaml"]
self.default_environment = {"env": "dummy_env"}
@mock.patch(HEAT_STACKS + "._generate_random_name")
@mock.patch(HEAT_STACKS + ".generate_random_name")
@mock.patch(HEAT_STACKS + "._list_stacks")
@mock.patch(HEAT_STACKS + "._create_stack")
def test_create_and_list_stack(self, mock__create_stack, mock__list_stacks,
mock__generate_random_name):
mock_generate_random_name):
heat_scenario = stacks.HeatStacks(self.context)
mock__generate_random_name.return_value = "test-rally-stack"
mock_generate_random_name.return_value = "test-rally-stack"
heat_scenario.create_and_list_stack(
template_path=self.default_template,
parameters=self.default_parameters,
@ -68,16 +68,16 @@ class HeatStacksTestCase(test.ScenarioTestCase):
self._test_atomic_action_timer(
heat_scenario.atomic_actions(), "heat.list_events_of_1_stacks")
@mock.patch(HEAT_STACKS + "._generate_random_name")
@mock.patch(HEAT_STACKS + ".generate_random_name")
@mock.patch(HEAT_STACKS + "._delete_stack")
@mock.patch(HEAT_STACKS + "._create_stack")
def test_create_and_delete_stack(
self, mock__create_stack, mock__delete_stack,
mock__generate_random_name):
mock_generate_random_name):
heat_scenario = stacks.HeatStacks(self.context)
fake_stack = object()
mock__create_stack.return_value = fake_stack
mock__generate_random_name.return_value = "test-rally-stack"
mock_generate_random_name.return_value = "test-rally-stack"
heat_scenario.create_and_delete_stack(
template_path=self.default_template,
parameters=self.default_parameters,
@ -112,17 +112,17 @@ class HeatStacksTestCase(test.ScenarioTestCase):
mock__delete_stack.assert_called_once_with(
mock__create_stack.return_value)
@mock.patch(HEAT_STACKS + "._generate_random_name")
@mock.patch(HEAT_STACKS + ".generate_random_name")
@mock.patch(HEAT_STACKS + "._delete_stack")
@mock.patch(HEAT_STACKS + "._update_stack")
@mock.patch(HEAT_STACKS + "._create_stack")
def test_create_update_delete_stack(
self, mock__create_stack, mock__update_stack, mock__delete_stack,
mock__generate_random_name):
mock_generate_random_name):
heat_scenario = stacks.HeatStacks(self.context)
fake_stack = object()
mock__create_stack.return_value = fake_stack
mock__generate_random_name.return_value = "test-rally-stack"
mock_generate_random_name.return_value = "test-rally-stack"
heat_scenario.create_update_delete_stack(
template_path=self.default_template,
parameters=self.default_parameters,

View File

@ -23,16 +23,16 @@ IRONIC_UTILS = "rally.plugins.openstack.scenarios.ironic.utils"
class IronicScenarioTestCase(test.ScenarioTestCase):
@mock.patch("rally.common.utils.generate_random_name")
def test__create_node(self, mock_generate_random_name):
mock_generate_random_name.return_value = "rally_fake_random_string"
def test__create_node(self):
self.admin_clients("ironic").node.create.return_value = "fake_node"
scenario = utils.IronicScenario(self.context)
scenario.generate_random_name = mock.Mock()
create_node = scenario._create_node(fake_param="foo")
self.assertEqual("fake_node", create_node)
self.admin_clients("ironic").node.create.assert_called_once_with(
fake_param="foo", name="rally_fake_random_string")
fake_param="foo", name=scenario.generate_random_name.return_value)
self._test_atomic_action_timer(scenario.atomic_actions(),
"ironic.create_node")

View File

@ -65,13 +65,11 @@ class ManilaSharesTestCase(test.ScenarioTestCase):
@ddt.data(
{},
{"name": "foo_name"},
{"description": "foo_description"},
{"neutron_net_id": "foo_neutron_net_id"},
{"neutron_subnet_id": "foo_neutron_subnet_id"},
{"nova_net_id": "foo_nova_net_id"},
{"name": "foo_name",
"description": "foo_description",
{"description": "foo_description",
"neutron_net_id": "foo_neutron_net_id",
"neutron_subnet_id": "foo_neutron_subnet_id",
"nova_net_id": "foo_nova_net_id"},
@ -82,7 +80,6 @@ class ManilaSharesTestCase(test.ScenarioTestCase):
scenario._create_share_network = mock.MagicMock(return_value=fake_sn)
scenario._delete_share_network = mock.MagicMock()
expected_params = {
"name": None,
"description": None,
"neutron_net_id": None,
"neutron_subnet_id": None,
@ -98,13 +95,11 @@ class ManilaSharesTestCase(test.ScenarioTestCase):
@ddt.data(
{},
{"name": "foo_name"},
{"description": "foo_description"},
{"neutron_net_id": "foo_neutron_net_id"},
{"neutron_subnet_id": "foo_neutron_subnet_id"},
{"nova_net_id": "foo_nova_net_id"},
{"name": "foo_name",
"description": "foo_description",
{"description": "foo_description",
"neutron_net_id": "foo_neutron_net_id",
"neutron_subnet_id": "foo_neutron_subnet_id",
"nova_net_id": "foo_nova_net_id"},
@ -114,7 +109,6 @@ class ManilaSharesTestCase(test.ScenarioTestCase):
scenario._create_share_network = mock.MagicMock()
scenario._list_share_networks = mock.MagicMock()
expected_create_params = {
"name": params.get("name"),
"description": params.get("description"),
"neutron_net_id": params.get("neutron_net_id"),
"neutron_subnet_id": params.get("neutron_subnet_id"),
@ -151,8 +145,7 @@ class ManilaSharesTestCase(test.ScenarioTestCase):
@ddt.data(
{"security_service_type": "fake_type"},
{"name": "foo_name",
"security_service_type": "fake_type",
{"security_service_type": "fake_type",
"dns_ip": "fake_dns_ip",
"server": "fake_server",
"domain": "fake_domain",
@ -173,7 +166,6 @@ class ManilaSharesTestCase(test.ScenarioTestCase):
"domain": params.get("domain"),
"user": params.get("user"),
"password": params.get("password"),
"name": params.get("name"),
"description": params.get("description"),
}

View File

@ -31,7 +31,6 @@ class ManilaScenarioTestCase(test.ScenarioTestCase):
self.scenario = utils.ManilaScenario(self.context)
def test__create_share(self):
fake_name = "fake_name"
fake_share = mock.Mock()
self.clients("manila").shares.create.return_value = fake_share
self.scenario.context = {
@ -43,12 +42,12 @@ class ManilaScenarioTestCase(test.ScenarioTestCase):
}
self.scenario.context["tenant"][consts.SHARE_NETWORKS_CONTEXT_NAME][
"sn_iterator"] = iter((0, ))
self.scenario._generate_random_name = mock.Mock(return_value=fake_name)
self.scenario.generate_random_name = mock.Mock()
self.scenario._create_share("nfs")
self.clients("manila").shares.create.assert_called_once_with(
"nfs", 1, name=fake_name,
"nfs", 1, name=self.scenario.generate_random_name.return_value,
share_network=self.scenario.context["tenant"][
consts.SHARE_NETWORKS_CONTEXT_NAME]["share_networks"][0])
@ -93,24 +92,24 @@ class ManilaScenarioTestCase(test.ScenarioTestCase):
detailed=params.get("detailed", True),
search_opts=params.get("search_opts", None))
@ddt.data(None, "", "SomeName")
def test__create_share_network(self, name):
def test__create_share_network(self):
fake_sn = mock.Mock()
self.scenario._generate_random_name = mock.Mock()
self.scenario.generate_random_name = mock.Mock()
self.clients("manila").share_networks.create.return_value = fake_sn
data = {
"neutron_net_id": "fake_neutron_net_id",
"neutron_subnet_id": "fake_neutron_subnet_id",
"nova_net_id": "fake_nova_net_id",
"name": name or self.scenario._generate_random_name.return_value,
"description": "fake_description",
}
expected = dict(data)
expected["name"] = self.scenario.generate_random_name.return_value
result = self.scenario._create_share_network(**data)
self.assertEqual(fake_sn, result)
self.clients("manila").share_networks.create.assert_called_once_with(
**data)
**expected)
@mock.patch(BM_UTILS + "wait_for_status")
def test__delete_share_network(self, mock_wait_for_status):
@ -166,6 +165,7 @@ class ManilaScenarioTestCase(test.ScenarioTestCase):
def test__create_security_service(self, ss_type):
fake_ss = mock.Mock()
self.clients("manila").security_services.create.return_value = fake_ss
self.scenario.generate_random_name = mock.Mock()
data = {
"security_service_type": ss_type,
"dns_ip": "fake_dns_ip",
@ -173,11 +173,11 @@ class ManilaScenarioTestCase(test.ScenarioTestCase):
"domain": "fake_domain",
"user": "fake_user",
"password": "fake_password",
"name": "fake_name",
"description": "fake_description",
}
expected = dict(data)
expected["type"] = expected.pop("security_service_type")
expected["name"] = self.scenario.generate_random_name.return_value
result = self.scenario._create_security_service(**data)

View File

@ -53,14 +53,14 @@ class MuranoEnvironmentsTestCase(test.ScenarioTestCase):
@mock.patch(MURANO_SCENARIO + "._create_session")
@mock.patch(MURANO_SCENARIO + "._delete_environment")
@mock.patch(MURANO_SCENARIO + "._create_environment")
@mock.patch(MURANO_SCENARIO + "._generate_random_name")
@mock.patch(MURANO_SCENARIO + ".generate_random_name")
def test_create_and_delete_environment(
self, mock__generate_random_name, mock__create_environment,
self, mock_generate_random_name, mock__create_environment,
mock__delete_environment, mock__create_session):
scenario = environments.MuranoEnvironments(self.context)
fake_environment = mock.Mock(id="fake_id")
mock__create_environment.return_value = fake_environment
mock__generate_random_name.return_value = "foo"
mock_generate_random_name.return_value = "foo"
scenario.create_and_delete_environment()
mock__create_environment.assert_called_once_with()
mock__create_session.assert_called_once_with(fake_environment.id)

View File

@ -34,12 +34,16 @@ class MuranoScenarioTestCase(test.ScenarioTestCase):
"murano.list_environments")
def test_create_environments(self):
mock_create = mock.Mock(return_value="foo_env")
self.clients("murano").environments.create = mock_create
self.clients("murano").environments.create = mock.Mock()
scenario = utils.MuranoScenario(context=self.context)
create_env = scenario._create_environment("env_name")
self.assertEqual("foo_env", create_env)
mock_create.assert_called_once_with({"name": "env_name"})
scenario.generate_random_name = mock.Mock()
create_env = scenario._create_environment()
self.assertEqual(
create_env,
self.clients("murano").environments.create.return_value)
self.clients("murano").environments.create.assert_called_once_with(
{"name": scenario.generate_random_name.return_value})
self._test_atomic_action_timer(scenario.atomic_actions(),
"murano.create_environment")

View File

@ -489,7 +489,7 @@ class NeutronNetworksTestCase(test.ScenarioTestCase):
mock__delete_router.assert_has_calls(
[mock.call(router)] * subnets_per_network)
@mock.patch(NEUTRON_NETWORKS + "._generate_random_name")
@mock.patch(NEUTRON_NETWORKS + ".generate_random_name")
@mock.patch(NEUTRON_NETWORKS + "._list_ports")
@mock.patch(NEUTRON_NETWORKS + "._create_port")
@mock.patch(NEUTRON_NETWORKS + "._create_network")
@ -497,9 +497,9 @@ class NeutronNetworksTestCase(test.ScenarioTestCase):
mock__create_network,
mock__create_port,
mock__list_ports,
mock__generate_random_name):
mock_generate_random_name):
scenario = network.NeutronNetworks(self.context)
mock__generate_random_name.return_value = "random-name"
mock_generate_random_name.return_value = "random-name"
net = {"network": {"id": "fake-id"}}
mock__create_network.return_value = net
ports_per_network = 10
@ -530,7 +530,7 @@ class NeutronNetworksTestCase(test.ScenarioTestCase):
[mock.call(net, {"allocation_pools": []})] * ports_per_network)
mock__list_ports.assert_called_once_with()
@mock.patch(NEUTRON_NETWORKS + "._generate_random_name")
@mock.patch(NEUTRON_NETWORKS + ".generate_random_name")
@mock.patch(NEUTRON_NETWORKS + "._update_port")
@mock.patch(NEUTRON_NETWORKS + "._create_port", return_value={
"port": {
@ -545,9 +545,9 @@ class NeutronNetworksTestCase(test.ScenarioTestCase):
mock__create_network,
mock__create_port,
mock__update_port,
mock__generate_random_name):
mock_generate_random_name):
scenario = network.NeutronNetworks(self.context)
mock__generate_random_name.return_value = "random-name"
mock_generate_random_name.return_value = "random-name"
ports_per_network = 10
port_update_args = {
@ -586,7 +586,7 @@ class NeutronNetworksTestCase(test.ScenarioTestCase):
[mock.call(mock__create_port.return_value, port_update_args)
] * ports_per_network)
@mock.patch(NEUTRON_NETWORKS + "._generate_random_name")
@mock.patch(NEUTRON_NETWORKS + ".generate_random_name")
@mock.patch(NEUTRON_NETWORKS + "._delete_port")
@mock.patch(NEUTRON_NETWORKS + "._create_port")
@mock.patch(NEUTRON_NETWORKS + "._create_network")
@ -594,9 +594,9 @@ class NeutronNetworksTestCase(test.ScenarioTestCase):
mock__create_network,
mock__create_port,
mock__delete_port,
mock__generate_random_name):
mock_generate_random_name):
scenario = network.NeutronNetworks(self.context)
mock__generate_random_name.return_value = "random-name"
mock_generate_random_name.return_value = "random-name"
net = {"network": {"id": "fake-id"}}
mock__create_network.return_value = net
ports_per_network = 10

View File

@ -62,11 +62,11 @@ class NeutronScenarioTestCase(test.ScenarioTestCase):
neutron_scenario._list_networks.assert_called_once_with(
atomic_action=False)
@mock.patch(NEUTRON_UTILS + "NeutronScenario._generate_random_name")
def test_create_network(self, mock__generate_random_name):
def test_create_network(self):
neutron_scenario = utils.NeutronScenario(self.context)
random_name = "random_name"
mock__generate_random_name.return_value = random_name
neutron_scenario.generate_random_name = mock.Mock(
return_value=random_name)
self.clients("neutron").create_network.return_value = self.network
network_data = {"admin_state_up": False}
@ -96,11 +96,11 @@ class NeutronScenarioTestCase(test.ScenarioTestCase):
def test_update_network(self):
scenario = utils.NeutronScenario(context=self.context)
scenario._generate_random_name = mock.Mock()
scenario.generate_random_name = mock.Mock()
expected_network = {
"network": {
"name": scenario._generate_random_name.return_value,
"name": scenario.generate_random_name.return_value,
"admin_state_up": False,
"fakearg": "fake"
}
@ -128,10 +128,9 @@ class NeutronScenarioTestCase(test.ScenarioTestCase):
self._test_atomic_action_timer(scenario.atomic_actions(),
"neutron.delete_network")
@mock.patch(NEUTRON_UTILS + "NeutronScenario._generate_random_name",
return_value="test_subnet")
def test_create_subnet(self, mock__generate_random_name):
def test_create_subnet(self):
scenario = utils.NeutronScenario(self.context)
scenario.generate_random_name = mock.Mock(return_value="test_subnet")
network_id = "fake-id"
start_cidr = "192.168.0.0/24"
@ -141,7 +140,7 @@ class NeutronScenarioTestCase(test.ScenarioTestCase):
"network_id": network_id,
"cidr": start_cidr,
"ip_version": scenario.SUBNET_IP_VERSION,
"name": mock__generate_random_name.return_value
"name": scenario.generate_random_name.return_value
}
}
@ -176,10 +175,10 @@ class NeutronScenarioTestCase(test.ScenarioTestCase):
def test_update_subnet(self):
scenario = utils.NeutronScenario(context=self.context)
scenario._generate_random_name = mock.Mock()
scenario.generate_random_name = mock.Mock()
expected_subnet = {
"subnet": {
"name": scenario._generate_random_name.return_value,
"name": scenario.generate_random_name.return_value,
"enable_dhcp": False,
"fakearg": "fake"
}
@ -207,11 +206,11 @@ class NeutronScenarioTestCase(test.ScenarioTestCase):
self._test_atomic_action_timer(scenario.atomic_actions(),
"neutron.delete_subnet")
@mock.patch(NEUTRON_UTILS + "NeutronScenario._generate_random_name")
def test_create_router_default(self, mock__generate_random_name):
@mock.patch(NEUTRON_UTILS + "NeutronScenario.generate_random_name")
def test_create_router(self, mock_generate_random_name):
scenario = utils.NeutronScenario(self.context)
router = mock.Mock()
mock__generate_random_name.return_value = "random_name"
mock_generate_random_name.return_value = "random_name"
self.clients("neutron").create_router.return_value = router
# Default options
@ -222,13 +221,13 @@ class NeutronScenarioTestCase(test.ScenarioTestCase):
self._test_atomic_action_timer(scenario.atomic_actions(),
"neutron.create_router")
@mock.patch(NEUTRON_UTILS + "NeutronScenario._generate_random_name")
def test_create_router_with_ext_gw(self, mock__generate_random_name):
@mock.patch(NEUTRON_UTILS + "NeutronScenario.generate_random_name")
def test_create_router_with_ext_gw(self, mock_generate_random_name):
scenario = utils.NeutronScenario()
router = mock.Mock()
external_network = [{"id": "ext-net", "router:external": True}]
scenario._list_networks = mock.Mock(return_value=external_network)
mock__generate_random_name.return_value = "random_name"
mock_generate_random_name.return_value = "random_name"
self.clients("neutron").create_router.return_value = router
# External_gw options
@ -242,14 +241,14 @@ class NeutronScenarioTestCase(test.ScenarioTestCase):
self._test_atomic_action_timer(scenario.atomic_actions(),
"neutron.create_router")
@mock.patch(NEUTRON_UTILS + "NeutronScenario._generate_random_name")
@mock.patch(NEUTRON_UTILS + "NeutronScenario.generate_random_name")
def test_create_router_with_ext_gw_but_no_ext_net(
self, mock__generate_random_name):
self, mock_generate_random_name):
scenario = utils.NeutronScenario()
router = mock.Mock()
external_network = [{"id": "ext-net", "router:external": False}]
scenario._list_networks = mock.Mock(return_value=external_network)
mock__generate_random_name.return_value = "random_name"
mock_generate_random_name.return_value = "random_name"
self.clients("neutron").create_router.return_value = router
# External_gw options with no external networks in list_networks()
@ -285,11 +284,11 @@ class NeutronScenarioTestCase(test.ScenarioTestCase):
def test_update_router(self):
scenario = utils.NeutronScenario(context=self.context)
scenario._generate_random_name = mock.Mock()
scenario.generate_random_name = mock.Mock()
expected_router = {
"router": {
"name": scenario._generate_random_name.return_value,
"name": scenario.generate_random_name.return_value,
"admin_state_up": False,
"fakearg": "fake"
}
@ -342,14 +341,14 @@ class NeutronScenarioTestCase(test.ScenarioTestCase):
def test_create_port(self):
scenario = utils.NeutronScenario(self.context)
scenario._generate_random_name = mock.Mock()
scenario.generate_random_name = mock.Mock()
net_id = "network-id"
net = {"network": {"id": net_id}}
expected_port_args = {
"port": {
"network_id": net_id,
"name": scenario._generate_random_name.return_value
"name": scenario.generate_random_name.return_value
}
}
@ -380,11 +379,11 @@ class NeutronScenarioTestCase(test.ScenarioTestCase):
def test_update_port(self):
scenario = utils.NeutronScenario(context=self.context)
scenario._generate_random_name = mock.Mock()
scenario.generate_random_name = mock.Mock()
expected_port = {
"port": {
"name": scenario._generate_random_name.return_value,
"name": scenario.generate_random_name.return_value,
"admin_state_up": False,
"fakearg": "fake"
}
@ -502,11 +501,11 @@ class NeutronScenarioTestCase(test.ScenarioTestCase):
def test_update_pool(self):
scenario = utils.NeutronScenario(context=self.context)
scenario._generate_random_name = mock.Mock()
scenario.generate_random_name = mock.Mock()
expected_pool = {
"pool": {
"name": scenario._generate_random_name.return_value,
"name": scenario.generate_random_name.return_value,
"admin_state_up": False,
"fakearg": "fake"
}
@ -557,10 +556,10 @@ class NeutronScenarioTestCase(test.ScenarioTestCase):
def test_update_v1_vip(self):
scenario = utils.NeutronScenario()
scenario._generate_random_name = mock.Mock(return_value="random_name")
scenario.generate_random_name = mock.Mock(return_value="random_name")
expected_vip = {
"vip": {
"name": scenario._generate_random_name.return_value,
"name": scenario.generate_random_name.return_value,
"admin_state_up": False
}
}
@ -656,7 +655,7 @@ class NeutronLoadbalancerScenarioTestCase(test.ScenarioTestCase):
pool = {"pool": {"id": "pool-id"}}
pool_create_args = pool_create_args or {}
if pool_create_args.get("name") is None:
neutron_scenario._generate_random_name = mock.Mock(
neutron_scenario.generate_random_name = mock.Mock(
return_value="random_name")
self.clients("neutron").create_pool.return_value = pool
args = {"lb_method": "ROUND_ROBIN", "protocol": "HTTP",
@ -680,12 +679,12 @@ class NeutronLoadbalancerScenarioTestCase(test.ScenarioTestCase):
)
@ddt.unpack
def test__create_v1_vip(self, vip_create_args=None):
neutron_scenario = utils.NeutronScenario()
neutron_scenario = utils.NeutronScenario(self.context)
vip = {"vip": {"id": "vip-id"}}
pool = {"pool": {"id": "pool-id", "subnet_id": "subnet-id"}}
vip_create_args = vip_create_args or {}
if vip_create_args.get("name") is None:
neutron_scenario._generate_random_name = mock.Mock(
neutron_scenario.generate_random_name = mock.Mock(
return_value="random_name")
self.clients("neutron").create_vip.return_value = vip
args = {"protocol_port": 80, "protocol": "HTTP", "name": "random_name",

View File

@ -23,7 +23,7 @@ class NovaKeypairTestCase(test.ScenarioTestCase):
def test_create_and_list_keypairs(self):
scenario = keypairs.NovaKeypair(self.context)
scenario._generate_random_name = mock.MagicMock(return_value="name")
scenario.generate_random_name = mock.MagicMock(return_value="name")
scenario._create_keypair = mock.MagicMock(return_value="foo_keypair")
scenario._list_keypairs = mock.MagicMock()
@ -34,7 +34,7 @@ class NovaKeypairTestCase(test.ScenarioTestCase):
def test_create_and_delete_keypair(self):
scenario = keypairs.NovaKeypair(self.context)
scenario._generate_random_name = mock.MagicMock(return_value="name")
scenario.generate_random_name = mock.MagicMock(return_value="name")
scenario._create_keypair = mock.MagicMock(return_value="foo_keypair")
scenario._delete_keypair = mock.MagicMock()
@ -45,7 +45,7 @@ class NovaKeypairTestCase(test.ScenarioTestCase):
def test_boot_and_delete_server_with_keypair(self):
scenario = keypairs.NovaKeypair(self.context)
scenario._generate_random_name = mock.MagicMock(return_value="name")
scenario.generate_random_name = mock.MagicMock(return_value="name")
scenario._create_keypair = mock.MagicMock(return_value="foo_keypair")
scenario._boot_server = mock.MagicMock(return_value="foo_server")
scenario._delete_server = mock.MagicMock()

View File

@ -109,7 +109,7 @@ class NovaSecurityGroupTestCase(test.ScenarioTestCase):
return_value=sg_list)
nova_scenario._create_rules_for_security_group = mock.MagicMock()
nova_scenario._boot_server = mock.MagicMock(return_value=fake_server)
nova_scenario._generate_random_name = mock.MagicMock(
nova_scenario.generate_random_name = mock.MagicMock(
return_value="name")
nova_scenario._delete_server = mock.MagicMock()
nova_scenario._delete_security_groups = mock.MagicMock()
@ -124,7 +124,7 @@ class NovaSecurityGroupTestCase(test.ScenarioTestCase):
fakearg="fakearg")
nova_scenario._create_security_groups.assert_called_once_with(
security_group_count)
self.assertEqual(1, nova_scenario._generate_random_name.call_count)
nova_scenario.generate_random_name.assert_called_once_with()
nova_scenario._create_rules_for_security_group.assert_called_once_with(
sg_list, rules_per_security_group)
nova_scenario._boot_server.assert_called_once_with(
@ -145,7 +145,7 @@ class NovaSecurityGroupTestCase(test.ScenarioTestCase):
return_value=fake_secgroups)
nova_scenario._create_rules_for_security_group = mock.MagicMock()
nova_scenario._boot_server = mock.MagicMock(return_value=fake_server)
nova_scenario._generate_random_name = mock.MagicMock(
nova_scenario.generate_random_name = mock.MagicMock(
return_value="name")
nova_scenario._delete_server = mock.MagicMock()
nova_scenario._delete_security_groups = mock.MagicMock()
@ -162,7 +162,7 @@ class NovaSecurityGroupTestCase(test.ScenarioTestCase):
nova_scenario._create_security_groups.assert_called_once_with(
security_group_count)
self.assertEqual(1, nova_scenario._generate_random_name.call_count)
nova_scenario.generate_random_name.assert_called_once_with()
nova_scenario._create_rules_for_security_group.assert_called_once_with(
fake_secgroups, rules_per_security_group)
nova_scenario._boot_server.assert_called_once_with(

View File

@ -32,7 +32,7 @@ class NovaServersTestCase(test.ScenarioTestCase):
fake_server = mock.MagicMock()
scenario = servers.NovaServers(self.context)
scenario._boot_server = mock.MagicMock(return_value=fake_server)
scenario._generate_random_name = mock.MagicMock(return_value="name")
scenario.generate_random_name = mock.MagicMock(return_value="name")
scenario._rescue_server = mock.MagicMock()
scenario._unrescue_server = mock.MagicMock()
scenario._delete_server = mock.MagicMock()
@ -56,7 +56,7 @@ class NovaServersTestCase(test.ScenarioTestCase):
fake_server = mock.MagicMock()
scenario = servers.NovaServers(self.context)
scenario._boot_server = mock.MagicMock(return_value=fake_server)
scenario._generate_random_name = mock.MagicMock(return_value="name")
scenario.generate_random_name = mock.MagicMock(return_value="name")
scenario._start_server = mock.MagicMock()
scenario._stop_server = mock.MagicMock()
scenario._delete_server = mock.MagicMock()
@ -85,7 +85,7 @@ class NovaServersTestCase(test.ScenarioTestCase):
scenario._delete_server = mock.MagicMock()
scenario._reboot_server = mock.MagicMock()
scenario._stop_and_start_server = mock.MagicMock()
scenario._generate_random_name = mock.MagicMock(return_value="name")
scenario.generate_random_name = mock.MagicMock(return_value="name")
scenario.boot_and_bounce_server("img", 1, actions=actions)
scenario._boot_server.assert_called_once_with("img", 1)
@ -158,7 +158,7 @@ class NovaServersTestCase(test.ScenarioTestCase):
scenario._soft_reboot_server = mock.MagicMock()
scenario._boot_server = mock.MagicMock(return_value=fake_server)
scenario._delete_server = mock.MagicMock()
scenario._generate_random_name = mock.MagicMock(return_value="name")
scenario.generate_random_name = mock.MagicMock(return_value="name")
scenario.boot_and_bounce_server("img", 1, actions=actions)
@ -187,7 +187,7 @@ class NovaServersTestCase(test.ScenarioTestCase):
fake_server = object()
scenario = servers.NovaServers(self.context)
scenario._generate_random_name = mock.MagicMock(return_value="name")
scenario.generate_random_name = mock.MagicMock(return_value="name")
scenario._boot_server = mock.MagicMock(return_value=fake_server)
scenario._delete_server = mock.MagicMock()
scenario.sleep_between = mock.MagicMock()
@ -220,7 +220,7 @@ class NovaServersTestCase(test.ScenarioTestCase):
def test_boot_and_list_server(self):
scenario = servers.NovaServers(self.context)
scenario._generate_random_name = mock.MagicMock(return_value="name")
scenario.generate_random_name = mock.MagicMock(return_value="name")
scenario._boot_server = mock.MagicMock()
scenario._list_servers = mock.MagicMock()
@ -234,7 +234,7 @@ class NovaServersTestCase(test.ScenarioTestCase):
fake_server = object()
scenario = servers.NovaServers(self.context)
scenario._generate_random_name = mock.MagicMock(return_value="name")
scenario.generate_random_name = mock.MagicMock(return_value="name")
scenario._boot_server = mock.MagicMock(return_value=fake_server)
scenario._suspend_server = mock.MagicMock()
scenario._resume_server = mock.MagicMock()
@ -254,7 +254,7 @@ class NovaServersTestCase(test.ScenarioTestCase):
fake_server = object()
scenario = servers.NovaServers(self.context)
scenario._generate_random_name = mock.MagicMock(return_value="name")
scenario.generate_random_name = mock.MagicMock(return_value="name")
scenario._boot_server = mock.MagicMock(return_value=fake_server)
scenario._pause_server = mock.MagicMock()
scenario._unpause_server = mock.MagicMock()
@ -298,7 +298,7 @@ class NovaServersTestCase(test.ScenarioTestCase):
fake_server = object()
scenario = servers.NovaServers(self.context)
scenario._boot_server = mock.MagicMock(return_value=fake_server)
scenario._generate_random_name = mock.MagicMock(return_value="name")
scenario.generate_random_name = mock.MagicMock(return_value="name")
scenario.sleep_between = mock.MagicMock()
scenario._delete_server = mock.MagicMock()
@ -324,7 +324,7 @@ class NovaServersTestCase(test.ScenarioTestCase):
scenario = servers.NovaServers(self.context)
scenario._boot_server = mock.MagicMock(return_value=fake_server)
scenario._generate_random_name = mock.MagicMock(return_value="name")
scenario.generate_random_name = mock.MagicMock(return_value="name")
kwargs = {"fakearg": "f"}
expected_kwargs = {"fakearg": "f"}
@ -358,7 +358,7 @@ class NovaServersTestCase(test.ScenarioTestCase):
fake_image.id = "image_id"
scenario = servers.NovaServers(self.context)
scenario._generate_random_name = mock.MagicMock(return_value="name")
scenario.generate_random_name = mock.MagicMock(return_value="name")
scenario._boot_server = mock.MagicMock(return_value=fake_server)
scenario._create_image = mock.MagicMock(return_value=fake_image)
scenario._delete_server = mock.MagicMock()
@ -383,7 +383,7 @@ class NovaServersTestCase(test.ScenarioTestCase):
to_flavor = mock.MagicMock()
scenario = servers.NovaServers(self.context)
scenario._generate_random_name = mock.MagicMock(return_value="name")
scenario.generate_random_name = mock.MagicMock(return_value="name")
scenario._boot_server = mock.MagicMock(return_value=fake_server)
scenario._resize_confirm = mock.MagicMock()
scenario._resize_revert = mock.MagicMock()
@ -410,7 +410,7 @@ class NovaServersTestCase(test.ScenarioTestCase):
fake_server = mock.MagicMock()
scenario = servers.NovaServers(self.context)
scenario._generate_random_name = mock.MagicMock(return_value="name")
scenario.generate_random_name = mock.MagicMock(return_value="name")
scenario._boot_server = mock.MagicMock(return_value=fake_server)
scenario.sleep_between = mock.MagicMock()
scenario._find_host_to_migrate = mock.MagicMock(
@ -437,7 +437,7 @@ class NovaServersTestCase(test.ScenarioTestCase):
fake_server = mock.MagicMock()
scenario = servers.NovaServers(self.context)
scenario._generate_random_name = mock.MagicMock(return_value="name")
scenario.generate_random_name = mock.MagicMock(return_value="name")
scenario._boot_server = mock.MagicMock(return_value=fake_server)
scenario.sleep_between = mock.MagicMock()
scenario._find_host_to_migrate = mock.MagicMock(
@ -517,7 +517,7 @@ class NovaServersTestCase(test.ScenarioTestCase):
fake_server = mock.MagicMock()
scenario = servers.NovaServers(self.context)
scenario._generate_random_name = mock.MagicMock(return_value="name")
scenario.generate_random_name = mock.MagicMock(return_value="name")
scenario._boot_server = mock.MagicMock(return_value=fake_server)
scenario._stop_server = mock.MagicMock()
scenario._migrate = mock.MagicMock()

View File

@ -101,7 +101,7 @@ class NovaScenarioTestCase(test.ScenarioTestCase):
context.setdefault("config", {})
nova_scenario = utils.NovaScenario(context=context)
nova_scenario._generate_random_name = mock.Mock()
nova_scenario.generate_random_name = mock.Mock()
nova_scenario._pick_random_nic = mock.Mock()
if kwargs is None:
kwargs = {}
@ -134,7 +134,7 @@ class NovaScenarioTestCase(test.ScenarioTestCase):
expected_kwargs["security_groups"] = list(expected_secgroups)
self.clients("nova").servers.create.assert_called_once_with(
nova_scenario._generate_random_name.return_value,
nova_scenario.generate_random_name.return_value,
"image_id", "flavor_id", **expected_kwargs)
self._test_atomic_action_timer(nova_scenario.atomic_actions(),
"nova.boot_server")
@ -440,22 +440,21 @@ class NovaScenarioTestCase(test.ScenarioTestCase):
@ddt.data(
{"requests": 1},
{"requests": 25},
{"requests": 2, "name_prefix": "foo", "instances_amount": 100,
"auto_assign_nic": True, "fakearg": "fake"},
{"requests": 2, "instances_amount": 100, "auto_assign_nic": True,
"fakearg": "fake"},
{"auto_assign_nic": True, "nics": [{"net-id": "foo"}]},
{"auto_assign_nic": False, "nics": [{"net-id": "foo"}]})
@ddt.unpack
def test__boot_servers(self, image_id="image", flavor_id="flavor",
requests=1, name_prefix=None, instances_amount=1,
requests=1, instances_amount=1,
auto_assign_nic=False, **kwargs):
servers = [mock.Mock() for i in range(instances_amount)]
self.clients("nova").servers.list.return_value = servers
scenario = utils.NovaScenario(context=self.context)
scenario._generate_random_name = mock.Mock()
scenario.generate_random_name = mock.Mock()
scenario._pick_random_nic = mock.Mock()
scenario._boot_servers(image_id, flavor_id, requests,
name_prefix=name_prefix,
instances_amount=instances_amount,
auto_assign_nic=auto_assign_nic,
**kwargs)
@ -464,13 +463,12 @@ class NovaScenarioTestCase(test.ScenarioTestCase):
if auto_assign_nic and "nics" not in kwargs:
expected_kwargs["nics"] = scenario._pick_random_nic.return_value
if name_prefix is None:
name_prefix = scenario._generate_random_name.return_value
create_calls = [
mock.call("%s_%d" % (name_prefix, i), image_id, flavor_id,
min_count=instances_amount, max_count=instances_amount,
**expected_kwargs)
mock.call(
"%s_%d" % (scenario.generate_random_name.return_value, i),
image_id, flavor_id,
min_count=instances_amount, max_count=instances_amount,
**expected_kwargs)
for i in range(requests)]
self.clients("nova").servers.create.assert_has_calls(create_calls)
@ -661,7 +659,7 @@ class NovaScenarioTestCase(test.ScenarioTestCase):
def test__create_security_groups(self):
nova_scenario = utils.NovaScenario(context=self.context)
nova_scenario._generate_random_name = mock.MagicMock()
nova_scenario.generate_random_name = mock.MagicMock()
security_group_count = 5
@ -670,7 +668,7 @@ class NovaScenarioTestCase(test.ScenarioTestCase):
self.assertEqual(security_group_count, len(sec_groups))
self.assertEqual(security_group_count,
nova_scenario._generate_random_name.call_count)
nova_scenario.generate_random_name.call_count)
self.assertEqual(
security_group_count,
self.clients("nova").security_groups.create.call_count)
@ -697,7 +695,7 @@ class NovaScenarioTestCase(test.ScenarioTestCase):
(rules_per_security_group * len(fake_secgroups)))
def test__update_security_groups(self):
nova_scenario = utils.NovaScenario()
nova_scenario = utils.NovaScenario(context=self.context)
fake_secgroups = [fakes.FakeSecurityGroup(None, None, 1, "uuid1"),
fakes.FakeSecurityGroup(None, None, 2, "uuid2")]
nova_scenario._update_security_groups(fake_secgroups)
@ -841,7 +839,7 @@ class NovaScenarioTestCase(test.ScenarioTestCase):
self.admin_clients("nova").networks.create.return_value = (fake_net)
nova_scenario = utils.NovaScenario()
nova_scenario._generate_random_name = mock.Mock(
nova_scenario.generate_random_name = mock.Mock(
return_value="rally_novanet_fake")
return_netlabel = nova_scenario._create_network(fake_cidr,

View File

@ -34,12 +34,8 @@ class SaharaJobTestCase(test.ScenarioTestCase):
CONF.set_override("sahara_cluster_check_interval", 0, "benchmark")
CONF.set_override("sahara_job_check_interval", 0, "benchmark")
@mock.patch("rally.common.utils.generate_random_name",
return_value="job_42")
@mock.patch(SAHARA_JOB + "._run_job_execution")
def test_create_launch_job_java(self, mock__run_job_execution,
mock_generate_random_name):
def test_create_launch_job_java(self, mock__run_job_execution):
self.clients("sahara").jobs.create.return_value = mock.MagicMock(
id="42")
@ -53,6 +49,7 @@ class SaharaJobTestCase(test.ScenarioTestCase):
}
})
jobs_scenario = jobs.SaharaJob(self.context)
jobs_scenario.generate_random_name = mock.Mock(return_value="job_42")
jobs_scenario.create_launch_job(
job_type="java",
@ -60,7 +57,7 @@ class SaharaJobTestCase(test.ScenarioTestCase):
job_idx=0
)
self.clients("sahara").jobs.create.assert_called_once_with(
name=mock_generate_random_name.return_value,
name=jobs_scenario.generate_random_name.return_value,
type="java",
description="",
mains=["main_42"],
@ -76,15 +73,11 @@ class SaharaJobTestCase(test.ScenarioTestCase):
job_idx=0
)
@mock.patch("rally.common.utils.generate_random_name",
return_value="job_42")
@mock.patch(SAHARA_JOB + "._run_job_execution")
@mock.patch(SAHARA_JOB + "._create_output_ds",
return_value=mock.MagicMock(id="out_42"))
def test_create_launch_job_pig(self, mock__create_output_ds,
mock__run_job_execution,
mock_generate_random_name):
mock__run_job_execution):
self.clients("sahara").jobs.create.return_value = mock.MagicMock(
id="42")
@ -98,13 +91,15 @@ class SaharaJobTestCase(test.ScenarioTestCase):
}
})
jobs_scenario = jobs.SaharaJob(self.context)
jobs_scenario.generate_random_name = mock.Mock(return_value="job_42")
jobs_scenario.create_launch_job(
job_type="pig",
configs={"conf_key": "conf_val"},
job_idx=0
)
self.clients("sahara").jobs.create.assert_called_once_with(
name=mock_generate_random_name.return_value,
name=jobs_scenario.generate_random_name.return_value,
type="pig",
description="",
mains=["main_42"],
@ -120,12 +115,8 @@ class SaharaJobTestCase(test.ScenarioTestCase):
job_idx=0
)
@mock.patch("rally.common.utils.generate_random_name",
return_value="job_42")
@mock.patch(SAHARA_JOB + "._run_job_execution")
def test_create_launch_job_sequence(self, mock__run_job_execution,
mock_generate_random_name):
def test_create_launch_job_sequence(self, mock__run_job_execution):
self.clients("sahara").jobs.create.return_value = mock.MagicMock(
id="42")
@ -139,6 +130,8 @@ class SaharaJobTestCase(test.ScenarioTestCase):
}
})
jobs_scenario = jobs.SaharaJob(self.context)
jobs_scenario.generate_random_name = mock.Mock(return_value="job_42")
jobs_scenario.create_launch_job_sequence(
jobs=[
{
@ -150,7 +143,7 @@ class SaharaJobTestCase(test.ScenarioTestCase):
}])
jobs_create_call = mock.call(
name=mock_generate_random_name.return_value,
name=jobs_scenario.generate_random_name.return_value,
type="java",
description="",
mains=["main_42"],
@ -176,14 +169,11 @@ class SaharaJobTestCase(test.ScenarioTestCase):
job_idx=1)]
)
@mock.patch("rally.common.utils.generate_random_name",
return_value="job_42")
@mock.patch(SAHARA_JOB + "._run_job_execution")
@mock.patch(SAHARA_JOB + "._scale_cluster")
def test_create_launch_job_sequence_with_scaling(
self, mock__scale_cluster, mock__run_job_execution,
mock_generate_random_name):
def test_create_launch_job_sequence_with_scaling(self,
mock__scale_cluster,
mock__run_job_execution):
self.clients("sahara").jobs.create.return_value = mock.MagicMock(
id="42")
self.clients("sahara").clusters.get.return_value = mock.MagicMock(
@ -199,6 +189,8 @@ class SaharaJobTestCase(test.ScenarioTestCase):
}
})
jobs_scenario = jobs.SaharaJob(self.context)
jobs_scenario.generate_random_name = mock.Mock(return_value="job_42")
jobs_scenario.create_launch_job_sequence_with_scaling(
jobs=[
{
@ -211,7 +203,7 @@ class SaharaJobTestCase(test.ScenarioTestCase):
deltas=[1, -1])
jobs_create_call = mock.call(
name=mock_generate_random_name.return_value,
name=jobs_scenario.generate_random_name.return_value,
type="java",
description="",
mains=["main_42"],

View File

@ -55,12 +55,12 @@ class SaharaScenarioTestCase(test.ScenarioTestCase):
self._test_atomic_action_timer(scenario.atomic_actions(),
"sahara.list_node_group_templates")
@mock.patch(SAHARA_UTILS + ".SaharaScenario._generate_random_name",
@mock.patch(SAHARA_UTILS + ".SaharaScenario.generate_random_name",
return_value="random_name")
@mock.patch(SAHARA_UTILS + ".sahara_consts")
def test_create_node_group_templates(
self, mock_sahara_consts,
mock__generate_random_name):
mock_generate_random_name):
scenario = utils.SaharaScenario(self.context)
mock_processes = {
@ -121,11 +121,11 @@ class SaharaScenarioTestCase(test.ScenarioTestCase):
self._test_atomic_action_timer(scenario.atomic_actions(),
"sahara.delete_node_group_template")
@mock.patch(SAHARA_UTILS + ".SaharaScenario._generate_random_name",
@mock.patch(SAHARA_UTILS + ".SaharaScenario.generate_random_name",
return_value="random_name")
@mock.patch(SAHARA_UTILS + ".sahara_consts")
def test_launch_cluster(self, mock_sahara_consts,
mock__generate_random_name):
mock_generate_random_name):
self.context.update({
"tenant": {
@ -226,11 +226,11 @@ class SaharaScenarioTestCase(test.ScenarioTestCase):
self._test_atomic_action_timer(scenario.atomic_actions(),
"sahara.launch_cluster")
@mock.patch(SAHARA_UTILS + ".SaharaScenario._generate_random_name",
@mock.patch(SAHARA_UTILS + ".SaharaScenario.generate_random_name",
return_value="random_name")
@mock.patch(SAHARA_UTILS + ".sahara_consts")
def test_launch_cluster_with_proxy(self, mock_sahara_consts,
mock__generate_random_name):
mock_generate_random_name):
context = {
"tenant": {
@ -344,11 +344,11 @@ class SaharaScenarioTestCase(test.ScenarioTestCase):
self._test_atomic_action_timer(scenario.atomic_actions(),
"sahara.launch_cluster")
@mock.patch(SAHARA_UTILS + ".SaharaScenario._generate_random_name",
@mock.patch(SAHARA_UTILS + ".SaharaScenario.generate_random_name",
return_value="random_name")
@mock.patch(SAHARA_UTILS + ".sahara_consts")
def test_launch_cluster_error(self, mock_sahara_consts,
mock__generate_random_name):
mock_generate_random_name):
scenario = utils.SaharaScenario(self.context)
mock_processes = {
@ -433,9 +433,9 @@ class SaharaScenarioTestCase(test.ScenarioTestCase):
self._test_atomic_action_timer(scenario.atomic_actions(),
"sahara.delete_cluster")
@mock.patch(SAHARA_UTILS + ".SaharaScenario._generate_random_name",
@mock.patch(SAHARA_UTILS + ".SaharaScenario.generate_random_name",
return_value="42")
def test_create_output_ds(self, mock__generate_random_name):
def test_create_output_ds(self, mock_generate_random_name):
self.context.update({
"sahara_output_conf": {
"output_type": "hdfs",
@ -453,9 +453,9 @@ class SaharaScenarioTestCase(test.ScenarioTestCase):
url="hdfs://test_out/42"
)
@mock.patch(SAHARA_UTILS + ".SaharaScenario._generate_random_name",
@mock.patch(SAHARA_UTILS + ".SaharaScenario.generate_random_name",
return_value="42")
def test_create_output_ds_swift(self, mock__generate_random_name):
def test_create_output_ds_swift(self, mock_generate_random_name):
self.context.update({
"sahara_output_conf": {
"output_type": "swift",

View File

@ -88,7 +88,7 @@ class SwiftObjectsTestCase(test.ScenarioTestCase):
names_list = ["AA", "BB", "CC", "DD"]
scenario = objects.SwiftObjects(self.context)
scenario._generate_random_name = mock.MagicMock(side_effect=names_list)
scenario.generate_random_name = mock.MagicMock(side_effect=names_list)
scenario._list_objects = mock.MagicMock()
scenario.create_container_and_object_then_list_objects(
@ -104,7 +104,7 @@ class SwiftObjectsTestCase(test.ScenarioTestCase):
names_list = ["111", "222", "333", "444", "555"]
scenario = objects.SwiftObjects(self.context)
scenario._generate_random_name = mock.MagicMock(side_effect=names_list)
scenario.generate_random_name = mock.MagicMock(side_effect=names_list)
scenario._delete_object = mock.MagicMock()
scenario._delete_container = mock.MagicMock()
@ -126,7 +126,7 @@ class SwiftObjectsTestCase(test.ScenarioTestCase):
names_list = ["aaa", "bbb", "ccc", "ddd", "eee", "fff"]
scenario = objects.SwiftObjects(self.context)
scenario._generate_random_name = mock.MagicMock(side_effect=names_list)
scenario.generate_random_name = mock.MagicMock(side_effect=names_list)
scenario._download_object = mock.MagicMock()
scenario.create_container_and_object_then_download_object(

View File

@ -13,6 +13,7 @@
# License for the specific language governing permissions and limitations
# under the License.
import ddt
import mock
from rally.plugins.openstack.scenarios.swift import utils
@ -38,62 +39,31 @@ class SwiftScenarioTestCase(test.ScenarioTestCase):
self._test_atomic_action_timer(scenario.atomic_actions(),
"swift.list_containers")
def test__create_container(self):
container_name = mock.MagicMock()
scenario = utils.SwiftScenario()
@ddt.data(
{},
{"headers": {"X-fake-name": "fake-value"}},
{"public": False,
"headers": {"X-fake-name": "fake-value"}},
{"public": False})
@ddt.unpack
def test__create_container(self, public=True, kwargs=None, headers=None):
if kwargs is None:
kwargs = {"fakearg": "fake"}
if headers is None:
headers = {}
scenario = utils.SwiftScenario(self.context)
scenario.generate_random_name = mock.MagicMock()
# name + public=True + kw
self.assertEqual(container_name,
scenario._create_container(container_name,
public=True, fargs="f"))
kw = {"headers": {"X-Container-Read": ".r:*,.rlistings"}, "fargs": "f"}
container = scenario._create_container(public=public,
headers=headers,
**kwargs)
self.assertEqual(container,
scenario.generate_random_name.return_value)
kwargs["headers"] = headers
kwargs["headers"]["X-Container-Read"] = ".r:*,.rlistings"
self.clients("swift").put_container.assert_called_once_with(
container_name,
**kw)
# name + public=True + additional header + kw
self.clients("swift").put_container.reset_mock()
self.assertEqual(container_name,
scenario._create_container(container_name,
public=True,
headers={"X-fake-name":
"fake-value"},
fargs="f"))
kw = {"headers": {"X-Container-Read": ".r:*,.rlistings",
"X-fake-name": "fake-value"}, "fargs": "f"}
self.clients("swift").put_container.assert_called_once_with(
container_name,
**kw)
# name + public=False + additional header + kw
self.clients("swift").put_container.reset_mock()
self.assertEqual(container_name,
scenario._create_container(container_name,
public=False,
headers={"X-fake-name":
"fake-value"},
fargs="f"))
kw = {"headers": {"X-fake-name": "fake-value"}, "fargs": "f"}
self.clients("swift").put_container.assert_called_once_with(
container_name,
**kw)
# name + kw
self.clients("swift").put_container.reset_mock()
self.assertEqual(container_name,
scenario._create_container(container_name, fargs="f"))
kw = {"fargs": "f"}
self.clients("swift").put_container.assert_called_once_with(
container_name,
**kw)
# kw
scenario._generate_random_name = mock.MagicMock(
return_value=container_name)
self.clients("swift").put_container.reset_mock()
self.assertEqual(container_name,
scenario._create_container(fargs="f"))
kw = {"fargs": "f"}
self.clients("swift").put_container.assert_called_once_with(
container_name,
**kw)
self.assertEqual(1, scenario._generate_random_name.call_count)
scenario.generate_random_name.return_value,
**kwargs)
self._test_atomic_action_timer(scenario.atomic_actions(),
"swift.create_container")
@ -131,33 +101,21 @@ class SwiftScenarioTestCase(test.ScenarioTestCase):
def test__upload_object(self):
container_name = mock.MagicMock()
object_name = mock.MagicMock()
content = mock.MagicMock()
etag = mock.MagicMock()
self.clients("swift").put_object.return_value = etag
scenario = utils.SwiftScenario(self.context)
scenario.generate_random_name = mock.MagicMock()
# container + content + name + kw
self.assertEqual((etag, object_name),
scenario._upload_object(container_name, content,
object_name=object_name,
fargs="f"))
kw = {"fargs": "f"}
self.clients("swift").put_object.assert_called_once_with(
container_name, object_name,
content, **kw)
# container + content + kw
scenario._generate_random_name = mock.MagicMock(
return_value=object_name)
self.clients("swift").put_object.reset_mock()
self.assertEqual((etag, object_name),
self.assertEqual((etag, scenario.generate_random_name.return_value),
scenario._upload_object(container_name, content,
fargs="f"))
kw = {"fargs": "f"}
self.clients("swift").put_object.assert_called_once_with(
container_name, object_name,
container_name, scenario.generate_random_name.return_value,
content, **kw)
self.assertEqual(1, scenario._generate_random_name.call_count)
self.assertEqual(1, scenario.generate_random_name.call_count)
self._test_atomic_action_timer(scenario.atomic_actions(),
"swift.upload_object")

View File

@ -23,15 +23,15 @@ BASIC = BASE + "basic.ZaqarBasic."
class ZaqarBasicTestCase(test.ScenarioTestCase):
@mock.patch(BASIC + "_generate_random_name", return_value="fizbit")
def test_create_queue(self, mock__generate_random_name):
@mock.patch(BASIC + "generate_random_name", return_value="fizbit")
def test_create_queue(self, mock_generate_random_name):
scenario = basic.ZaqarBasic(self.context)
scenario._queue_create = mock.MagicMock()
scenario.create_queue(name_length=10)
scenario._queue_create.assert_called_once_with(name_length=10)
scenario.create_queue(fakearg="fake")
scenario._queue_create.assert_called_once_with(fakearg="fake")
@mock.patch(BASIC + "_generate_random_name", return_value="kitkat")
def test_producer_consumer(self, mock__generate_random_name):
@mock.patch(BASIC + "generate_random_name", return_value="kitkat")
def test_producer_consumer(self, mock_generate_random_name):
scenario = basic.ZaqarBasic(self.context)
messages = [{"body": {"id": idx}, "ttl": 360} for idx
in range(20)]
@ -42,10 +42,10 @@ class ZaqarBasicTestCase(test.ScenarioTestCase):
scenario._messages_list = mock.MagicMock()
scenario._queue_delete = mock.MagicMock()
scenario.producer_consumer(name_length=10, min_msg_count=20,
max_msg_count=20)
scenario.producer_consumer(min_msg_count=20, max_msg_count=20,
fakearg="fake")
scenario._queue_create.assert_called_once_with(name_length=10)
scenario._queue_create.assert_called_once_with(fakearg="fake")
scenario._messages_post.assert_called_once_with(queue, messages,
20, 20)
scenario._messages_list.assert_called_once_with(queue)

View File

@ -23,14 +23,15 @@ UTILS = "rally.plugins.openstack.scenarios.zaqar.utils."
class ZaqarScenarioTestCase(test.ScenarioTestCase):
@mock.patch(UTILS + "ZaqarScenario._generate_random_name",
@mock.patch(UTILS + "ZaqarScenario.generate_random_name",
return_value="kitkat")
def test_queue_create(self, mock__generate_random_name):
def test_queue_create(self, mock_generate_random_name):
scenario = utils.ZaqarScenario(self.context)
result = scenario._queue_create(name_length=10)
result = scenario._queue_create(fakearg="fakearg")
self.assertEqual(self.clients("zaqar").queue.return_value, result)
self.clients("zaqar").queue.assert_called_once_with("kitkat")
self.clients("zaqar").queue.assert_called_once_with("kitkat",
fakearg="fakearg")
self._test_atomic_action_timer(scenario.atomic_actions(),
"zaqar.create_queue")