Port Senlin and others scenarios to new style

Since current scenario implementation transforms method to class
at runtime, it is reasonable to have class-based scenario
implementation which will be much simpler to use behind the scenes.

This class should be based on Scenario and do not break compatibility.
The only required method is run() which is actually a body of scenario.

This patch contains changes in following groups (scenarios and tests):
/senlin/
/swift/
/tempest/
/vm/
/watcher/
/zaqar/

and modules:

rally/plugins/openstack/context/vm/custom_image.py
tests/unit/test_docstrings.py

Change-Id: Ia7f33d7c279991232286b34abe199d125b92f023
This commit is contained in:
astaroverov 2016-09-01 15:20:15 +03:00
parent c10c5f9c88
commit eb66136085
16 changed files with 400 additions and 296 deletions

View File

@ -153,7 +153,9 @@ class BaseCustomImageGenerator(context.Context):
flavor_id = types.Flavor.transform(
clients=clients, resource_config=self.config["flavor"])
vm_scenario = vmtasks.VMTasks(self.context, clients=clients)
vm_scenario = vmtasks.BootRuncommandDeleteCustomImage(
self.context,
clients=clients)
glance_wrap = glance_wrapper.wrap(admin_clients.glance, self)

View File

@ -16,15 +16,18 @@ from rally.plugins.openstack.scenarios.senlin import utils
from rally.task import validation
class SenlinClusters(utils.SenlinScenario):
"""Benchmark scenarios for Senlin clusters."""
"""Scenarios for Senlin clusters."""
@validation.required_openstack(admin=True)
@validation.required_services(consts.Service.SENLIN)
@validation.required_contexts("profiles")
@scenario.configure(context={"cleanup": ["senlin"]})
def create_and_delete_cluster(self, desired_capacity=0, min_size=0,
max_size=-1, timeout=3600, metadata=None):
@validation.required_openstack(admin=True)
@validation.required_services(consts.Service.SENLIN)
@validation.required_contexts("profiles")
@scenario.configure(context={"cleanup": ["senlin"]},
name="SenlinClusters.create_and_delete_cluster")
class CreateAndDeleteCluster(utils.SenlinScenario):
def run(self, desired_capacity=0, min_size=0,
max_size=-1, timeout=3600, metadata=None):
"""Create a cluster and then delete it.
Measure the "senlin cluster-create" and "senlin cluster-delete"
@ -38,6 +41,7 @@ class SenlinClusters(utils.SenlinScenario):
:param timeout: The timeout value in seconds for cluster creation
:param metadata: A set of key value pairs to associate with the cluster
"""
profile_id = self.context["tenant"]["profile"]
cluster = self._create_cluster(profile_id, desired_capacity,
min_size, max_size, timeout, metadata)

View File

@ -22,15 +22,17 @@ from rally.task import atomic
from rally.task import validation
class SwiftObjects(utils.SwiftScenario):
"""Benchmark scenarios for Swift Objects."""
"""Scenarios for Swift Objects."""
@validation.required_services(consts.Service.SWIFT)
@validation.required_openstack(users=True)
@scenario.configure(context={"cleanup": ["swift"]})
def create_container_and_object_then_list_objects(
self, objects_per_container=1,
object_size=1024, **kwargs):
@validation.required_services(consts.Service.SWIFT)
@validation.required_openstack(users=True)
@scenario.configure(context={"cleanup": ["swift"]},
name="SwiftObjects.create_container"
"_and_object_then_list_objects")
class CreateContainerAndObjectThenListObjects(utils.SwiftScenario):
def run(self, objects_per_container=1, object_size=1024, **kwargs):
"""Create container and objects then list all objects.
:param objects_per_container: int, number of objects to upload
@ -53,12 +55,15 @@ class SwiftObjects(utils.SwiftScenario):
atomic_action=False)
self._list_objects(container_name)
@validation.required_services(consts.Service.SWIFT)
@validation.required_openstack(users=True)
@scenario.configure(context={"cleanup": ["swift"]})
def create_container_and_object_then_delete_all(
self, objects_per_container=1,
object_size=1024, **kwargs):
@validation.required_services(consts.Service.SWIFT)
@validation.required_openstack(users=True)
@scenario.configure(context={"cleanup": ["swift"]},
name="SwiftObjects.create_container"
"_and_object_then_delete_all")
class CreateContainerAndObjectThenDeleteAll(utils.SwiftScenario):
def run(self, objects_per_container=1, object_size=1024, **kwargs):
"""Create container and objects then delete everything created.
:param objects_per_container: int, number of objects to upload
@ -89,12 +94,15 @@ class SwiftObjects(utils.SwiftScenario):
atomic_action=False)
self._delete_container(container_name)
@validation.required_services(consts.Service.SWIFT)
@validation.required_openstack(users=True)
@scenario.configure(context={"cleanup": ["swift"]})
def create_container_and_object_then_download_object(
self, objects_per_container=1,
object_size=1024, **kwargs):
@validation.required_services(consts.Service.SWIFT)
@validation.required_openstack(users=True)
@scenario.configure(context={"cleanup": ["swift"]},
name="SwiftObjects.create_container"
"_and_object_then_download_object")
class CreateContainerAndObjectThenDownloadObject(utils.SwiftScenario):
def run(self, objects_per_container=1, object_size=1024, **kwargs):
"""Create container and objects then download all objects.
:param objects_per_container: int, number of objects to upload
@ -124,11 +132,16 @@ class SwiftObjects(utils.SwiftScenario):
self._download_object(container_name, object_name,
atomic_action=False)
@validation.required_services(consts.Service.SWIFT)
@validation.required_openstack(users=True)
@scenario.configure(context={"swift_objects": {}})
def list_objects_in_containers(self):
@validation.required_services(consts.Service.SWIFT)
@validation.required_openstack(users=True)
@scenario.configure(context={"swift_objects": {}},
name="SwiftObjects.list_objects_in_containers")
class ListObjectsInContainers(utils.SwiftScenario):
def run(self):
"""List objects in all containers."""
containers = self._list_containers()[1]
key_suffix = "container"
@ -139,11 +152,17 @@ class SwiftObjects(utils.SwiftScenario):
for container in containers:
self._list_objects(container["name"], atomic_action=False)
@validation.required_services(consts.Service.SWIFT)
@validation.required_openstack(users=True)
@scenario.configure(context={"swift_objects": {}})
def list_and_download_objects_in_containers(self):
@validation.required_services(consts.Service.SWIFT)
@validation.required_openstack(users=True)
@scenario.configure(context={"swift_objects": {}},
name="SwiftObjects.list_and_"
"download_objects_in_containers")
class ListAndDownloadObjectsInContainers(utils.SwiftScenario):
def run(self):
"""List and download objects in all containers."""
containers = self._list_containers()[1]
list_key_suffix = "container"

View File

@ -19,31 +19,38 @@ from rally.plugins.openstack.scenarios.tempest import utils
from rally.task import validation
class TempestScenario(scenario.OpenStackScenario):
"""Benchmark scenarios that launch Tempest tests."""
"""Scenarios that launch Tempest tests."""
@validation.tempest_tests_exists()
@validation.required_openstack(admin=True)
@scenario.configure(context={"tempest": {}},
name="TempestScenario.single_test")
class SingleTest(scenario.OpenStackScenario):
@validation.tempest_tests_exists()
@validation.required_openstack(admin=True)
@scenario.configure(context={"tempest": {}})
@utils.tempest_log_wrapper
def single_test(self, test_name, log_file, tempest_conf=None):
def run(self, test_name, log_file, tempest_conf=None):
"""Launch a single Tempest test by its name.
:param test_name: name of tempest scenario for launching
:param log_file: name of file for junitxml results
:param tempest_conf: User specified tempest.conf location
"""
if (not test_name.startswith("tempest.api.")
and test_name.split(".")[0] in consts.TempestTestsAPI):
if (not test_name.startswith("tempest.api.") and
test_name.split(".")[0] in consts.TempestTestsAPI):
test_name = "tempest.api." + test_name
self.context["verifier"].run(test_name, log_file=log_file,
tempest_conf=tempest_conf)
@validation.required_openstack(admin=True)
@scenario.configure(context={"tempest": {}})
@validation.required_openstack(admin=True)
@scenario.configure(context={"tempest": {}},
name="TempestScenario.all")
class All(scenario.OpenStackScenario):
@utils.tempest_log_wrapper
def all(self, log_file, tempest_conf=None):
def run(self, log_file, tempest_conf=None):
"""Launch all discovered Tempest tests by their names.
:param log_file: name of file for junitxml results
@ -53,11 +60,15 @@ class TempestScenario(scenario.OpenStackScenario):
self.context["verifier"].run("", log_file=log_file,
tempest_conf=tempest_conf)
@validation.tempest_set_exists()
@validation.required_openstack(admin=True)
@scenario.configure(context={"tempest": {}})
@validation.tempest_set_exists()
@validation.required_openstack(admin=True)
@scenario.configure(context={"tempest": {}},
name="TempestScenario.set")
class Set(scenario.OpenStackScenario):
@utils.tempest_log_wrapper
def set(self, set_name, log_file, tempest_conf=None):
def run(self, set_name, log_file, tempest_conf=None):
"""Launch all Tempest tests from a given set.
:param set_name: set name of tempest scenarios for launching
@ -75,11 +86,15 @@ class TempestScenario(scenario.OpenStackScenario):
self.context["verifier"].run(testr_arg, log_file=log_file,
tempest_conf=tempest_conf)
@validation.tempest_tests_exists()
@validation.required_openstack(admin=True)
@scenario.configure(context={"tempest": {}})
@validation.tempest_tests_exists()
@validation.required_openstack(admin=True)
@scenario.configure(context={"tempest": {}},
name="TempestScenario.list_of_tests")
class ListOfTests(scenario.OpenStackScenario):
@utils.tempest_log_wrapper
def list_of_tests(self, test_names, log_file, tempest_conf=None):
def run(self, test_names, log_file, tempest_conf=None):
"""Launch all Tempest tests from a given list of their names.
:param test_names: list of tempest scenarios for launching
@ -90,10 +105,14 @@ class TempestScenario(scenario.OpenStackScenario):
self.context["verifier"].run(" ".join(test_names), log_file=log_file,
tempest_conf=tempest_conf)
@validation.required_openstack(admin=True)
@scenario.configure(context={"tempest": {}})
@validation.required_openstack(admin=True)
@scenario.configure(context={"tempest": {}},
name="TempestScenario.specific_regex")
class SpecificRegex(scenario.OpenStackScenario):
@utils.tempest_log_wrapper
def specific_regex(self, regex, log_file, tempest_conf=None):
def run(self, regex, log_file, tempest_conf=None):
"""Launch Tempest tests whose names match a given regular expression.
:param regex: regexp to match Tempest test names against

View File

@ -27,46 +27,36 @@ from rally.task import atomic
from rally.task import types
from rally.task import validation
"""Scenarios that are to be run inside VM instances."""
LOG = logging.getLogger(__name__)
class VMTasks(vm_utils.VMScenario):
"""Benchmark scenarios that are to be run inside VM instances."""
@types.convert(image={"type": "glance_image"},
flavor={"type": "nova_flavor"})
@validation.image_valid_on_flavor("flavor", "image")
@validation.valid_command("command")
@validation.number("port", minval=1, maxval=65535, nullable=True,
integer_only=True)
@validation.external_network_exists("floating_network")
@validation.required_services(consts.Service.NOVA, consts.Service.CINDER)
@validation.required_openstack(users=True)
@scenario.configure(context={"cleanup": ["nova", "cinder"],
"keypair": {}, "allow_ssh": {}},
name="VMTasks.boot_runcommand_delete")
class BootRuncommandDelete(vm_utils.VMScenario):
def __init__(self, *args, **kwargs):
super(VMTasks, self).__init__(*args, **kwargs)
super(BootRuncommandDelete, self).__init__(*args, **kwargs)
@types.convert(image={"type": "glance_image"},
flavor={"type": "nova_flavor"})
@validation.image_valid_on_flavor("flavor", "image")
@validation.valid_command("command")
@validation.number("port", minval=1, maxval=65535, nullable=True,
integer_only=True)
@validation.external_network_exists("floating_network")
@validation.required_services(consts.Service.NOVA, consts.Service.CINDER)
@validation.required_openstack(users=True)
@scenario.configure(context={"cleanup": ["nova", "cinder"],
"keypair": {}, "allow_ssh": {}})
def boot_runcommand_delete(self, image, flavor,
username,
password=None,
command=None,
volume_args=None,
floating_network=None,
port=22,
use_floating_ip=True,
force_delete=False,
wait_for_ping=True,
max_log_length=None,
**kwargs):
def run(self, image, flavor, username, password=None, command=None,
volume_args=None, floating_network=None, port=22,
use_floating_ip=True, force_delete=False, wait_for_ping=True,
max_log_length=None, **kwargs):
"""Boot a server, run script specified in command and delete server.
Example Script in samples/tasks/support/instance_dd_test.sh
The script to be executed is provided like command['remote_path'] or
command['local_path'] and interpreter in command['interpreter']
respectively.
:param image: glance image name to use for the vm
:param flavor: VM flavor name
:param username: ssh username on server, str
@ -223,46 +213,60 @@ class VMTasks(vm_utils.VMScenario):
for chart in charts:
self.add_output(**{chart_type: chart})
@types.convert(image={"type": "glance_image"},
flavor={"type": "nova_flavor"})
@validation.number("port", minval=1, maxval=65535, nullable=True,
integer_only=True)
@validation.valid_command("command")
@validation.external_network_exists("floating_network")
@validation.required_services(consts.Service.NOVA, consts.Service.CINDER)
@validation.required_openstack(users=True)
@validation.required_contexts("image_command_customizer")
@scenario.configure(context={"cleanup": ["nova", "cinder"],
"keypair": {}, "allow_ssh": {}})
def boot_runcommand_delete_custom_image(self, **kwargs):
@types.convert(image={"type": "glance_image"},
flavor={"type": "nova_flavor"})
@validation.number("port", minval=1, maxval=65535, nullable=True,
integer_only=True)
@validation.valid_command("command")
@validation.external_network_exists("floating_network")
@validation.required_services(consts.Service.NOVA, consts.Service.CINDER)
@validation.required_openstack(users=True)
@validation.required_contexts("image_command_customizer")
@scenario.configure(context={"cleanup": ["nova", "cinder"],
"keypair": {}, "allow_ssh": {}},
name="VMTasks.boot_runcommand_delete_custom_image")
class BootRuncommandDeleteCustomImage(vm_utils.VMScenario):
def __init__(self, *args, **kwargs):
super(BootRuncommandDeleteCustomImage, self).__init__(*args, **kwargs)
def run(self, **kwargs):
"""Boot a server from a custom image, run a command that outputs JSON.
Example Script in rally-jobs/extra/install_benchmark.sh
"""
return self.boot_runcommand_delete(
boot_runcommand_delete = BootRuncommandDelete(self.context)
return boot_runcommand_delete.run(
image=self.context["tenant"]["custom_image"]["id"], **kwargs)
@scenario.configure(context={"cleanup": ["nova", "heat"],
"keypair": {}, "network": {}})
def runcommand_heat(self, workload, template, files, parameters):
@scenario.configure(context={"cleanup": ["nova", "heat"],
"keypair": {}, "network": {}},
name="VMTasks.runcommand_heat")
class RuncommandHeat(vm_utils.VMScenario):
def __init__(self, *args, **kwargs):
super(RuncommandHeat, self).__init__(*args, **kwargs)
def run(self, workload, template, files, parameters):
"""Run workload on stack deployed by heat.
Workload can be either file or resource:
Workload can be either file or resource:
.. code-block: json
.. code-block: json
{"file": "/path/to/file.sh"}
{"resource": ["package.module", "workload.py"]}
{"file": "/path/to/file.sh"}
{"resource": ["package.module", "workload.py"]}
Also it should contain "username" key.
Also it should contain "username" key.
Given file will be uploaded to `gate_node` and started. This script
should print `key` `value` pairs separated by colon. These pairs will
be presented in results.
Given file will be uploaded to `gate_node` and started. This script
should print `key` `value` pairs separated by colon. These pairs will
be presented in results.
Gate node should be accessible via ssh with keypair `key_name`, so
heat template should accept parameter `key_name`.
Gate node should be accessible via ssh with keypair `key_name`, so
heat template should accept parameter `key_name`.
:param workload: workload to run
:param template: path to heat template file

View File

@ -17,15 +17,18 @@ from rally.task import types
from rally.task import validation
class Watcher(utils.WatcherScenario):
"""Benchmark scenarios for Watcher servers."""
"""Scenarios for Watcher servers."""
@types.convert(strategy={"type": "watcher_strategy"},
goal={"type": "watcher_goal"})
@validation.required_services(consts.Service.WATCHER)
@validation.required_openstack(admin=True)
@scenario.configure(context={"admin_cleanup": ["watcher"]})
def create_audit_template_and_delete(self, goal, strategy, extra=None):
@types.convert(strategy={"type": "watcher_strategy"},
goal={"type": "watcher_goal"})
@validation.required_services(consts.Service.WATCHER)
@validation.required_openstack(admin=True)
@scenario.configure(context={"admin_cleanup": ["watcher"]},
name="Watcher.create_audit_template_and_delete")
class CreateAuditTemplateAndDelete(utils.WatcherScenario):
def run(self, goal, strategy, extra=None):
"""Create audit template and delete it.
:param goal: The goal audit template is based on
@ -39,11 +42,14 @@ class Watcher(utils.WatcherScenario):
audit_template = self._create_audit_template(goal, strategy, extra)
self._delete_audit_template(audit_template.uuid)
@validation.required_services(consts.Service.WATCHER)
@scenario.configure()
def list_audit_templates(self, name=None, goal=None, strategy=None,
limit=None, sort_key=None, sort_dir=None,
detail=False):
@validation.required_services(consts.Service.WATCHER)
@scenario.configure(name="Watcher.list_audit_templates")
class ListAuditTemplates(utils.WatcherScenario):
def run(self, name=None, goal=None, strategy=None,
limit=None, sort_key=None, sort_dir=None,
detail=False):
"""List existing audit templates.
Audit templates are being created by Audit Template Context.
@ -69,10 +75,14 @@ class Watcher(utils.WatcherScenario):
limit=limit, sort_key=sort_key,
sort_dir=sort_dir, detail=detail)
@validation.required_services(consts.Service.WATCHER)
@validation.required_contexts("audit_templates")
@scenario.configure(context={"admin_cleanup": ["watcher"]})
def create_audit_and_delete(self):
@validation.required_services(consts.Service.WATCHER)
@validation.required_contexts("audit_templates")
@scenario.configure(context={"admin_cleanup": ["watcher"]},
name="Watcher.create_audit_and_delete")
class CreateAuditAndDelete(utils.WatcherScenario):
def run(self):
"""Create and delete audit.
Create Audit, wait until whether Audit is in SUCCEEDED state or in

View File

@ -19,14 +19,17 @@ from rally.plugins.openstack import scenario
from rally.plugins.openstack.scenarios.zaqar import utils as zutils
class ZaqarBasic(zutils.ZaqarScenario):
"""Benchmark scenarios for Zaqar."""
"""Scenarios for Zaqar."""
@scenario.configure(context={"cleanup": ["zaqar"]},
name="ZaqarBasic.create_queue")
class CreateQueue(zutils.ZaqarScenario):
@scenario.configure(context={"cleanup": ["zaqar"]})
@logging.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):
def run(self, name_length=None, **kwargs):
"""Create a Zaqar queue with a random name.
:param kwargs: other optional parameters to create queues like
@ -34,12 +37,16 @@ class ZaqarBasic(zutils.ZaqarScenario):
"""
self._queue_create(**kwargs)
@scenario.configure(context={"cleanup": ["zaqar"]})
@scenario.configure(context={"cleanup": ["zaqar"]},
name="ZaqarBasic.producer_consumer")
class ProducerConsumer(zutils.ZaqarScenario):
@logging.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):
def run(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

View File

@ -62,26 +62,26 @@ class BaseCustomImageContextVMTestCase(test.TestCase):
}
})
@mock.patch("%s.vmtasks.VMTasks" % BASE)
@mock.patch("%s.osclients.Clients" % BASE)
@mock.patch("%s.types.GlanceImage.transform" % BASE, return_value="image")
@mock.patch("%s.types.Flavor.transform" % BASE, return_value="flavor")
@mock.patch("rally.plugins.openstack.wrappers.glance.wrap")
@mock.patch("%s.vmtasks.BootRuncommandDeleteCustomImage" % BASE)
def test_create_one_image(
self, mock_glance_wrap, mock_flavor_transform,
mock_glance_image_transform, mock_clients, mock_vm_tasks):
self, mock_scenario, mock_glance_wrap, mock_flavor_transform,
mock_glance_image_transform, mock_clients
):
ip = {"ip": "foo_ip", "id": "foo_id", "is_floating": True}
fake_server = mock.Mock()
fake_image = mock.MagicMock(
to_dict=mock.MagicMock(return_value={"id": "image"}))
mock_vm_scenario = mock_vm_tasks.return_value = mock.MagicMock(
scenario = mock_scenario.return_value = mock.MagicMock(
_create_image=mock.MagicMock(return_value=fake_image),
_boot_server_with_fip=mock.MagicMock(
return_value=(fake_server, ip))
)
generator_ctx = TestImageGenerator(self.context)
generator_ctx._customize_image = mock.MagicMock()
@ -103,47 +103,47 @@ class BaseCustomImageContextVMTestCase(test.TestCase):
mock_glance_image_transform.assert_called_once_with(
clients=mock_clients.return_value,
resource_config={"name": "image"})
mock_vm_tasks.assert_called_once_with(
mock_scenario.assert_called_once_with(
self.context, clients=mock_clients.return_value)
mock_vm_scenario._boot_server_with_fip.assert_called_once_with(
scenario._boot_server_with_fip.assert_called_once_with(
image="image", flavor="flavor",
floating_network="floating",
key_name="keypair_name", security_groups=["secgroup_name"],
userdata=None, foo_arg="foo_value")
mock_vm_scenario._stop_server.assert_called_once_with(fake_server)
scenario._stop_server.assert_called_once_with(fake_server)
generator_ctx._customize_image.assert_called_once_with(
fake_server, ip, user)
mock_vm_scenario._create_image.assert_called_once_with(fake_server)
scenario._create_image.assert_called_once_with(fake_server)
mock_glance_wrap.return_value.set_visibility.assert_called_once_with(
fake_image)
mock_vm_scenario._delete_server_with_fip.assert_called_once_with(
scenario._delete_server_with_fip.assert_called_once_with(
fake_server, ip)
self.assertEqual({"id": "image"}, custom_image)
@mock.patch("%s.vmtasks.VMTasks" % BASE)
@mock.patch("%s.osclients.Clients" % BASE)
@mock.patch("%s.types.GlanceImage.transform" % BASE,
return_value="image")
@mock.patch("%s.types.Flavor.transform" % BASE,
return_value="flavor")
@mock.patch("rally.plugins.openstack.wrappers.glance.wrap")
@mock.patch("%s.vmtasks.BootRuncommandDeleteCustomImage" % BASE)
def test_create_one_image_cleanup(
self, mock_glance_wrap, mock_flavor_transform,
mock_glance_image_transform, mock_clients,
mock_vm_tasks):
self, mock_scenario, mock_glance_wrap, mock_flavor_transform,
mock_glance_image_transform, mock_clients
):
ip = {"ip": "foo_ip", "id": "foo_id", "is_floating": True}
fake_server = mock.Mock()
fake_image = mock.MagicMock(
to_dict=mock.MagicMock(return_value={"id": "image"}))
mock_vm_scenario = mock_vm_tasks.return_value = mock.MagicMock(
scenario = mock_scenario.return_value = mock.MagicMock(
_create_image=mock.MagicMock(return_value=fake_image),
_boot_server_with_fip=mock.MagicMock(
return_value=(fake_server, ip)),
@ -167,7 +167,7 @@ class BaseCustomImageContextVMTestCase(test.TestCase):
generator_ctx._customize_image.assert_called_once_with(
fake_server, ip, user)
mock_vm_scenario._delete_server_with_fip.assert_called_once_with(
scenario._delete_server_with_fip.assert_called_once_with(
fake_server, ip)
@mock.patch("%s.nova_utils.NovaScenario" % BASE)

View File

@ -21,13 +21,12 @@ class SenlinClustersTestCase(test.ScenarioTestCase):
def test_create_and_delete_cluster(self):
mock_cluster = mock.Mock()
self.context["tenant"] = {"profile": "fake_profile_id"}
scenario = clusters.SenlinClusters(self.context)
scenario = clusters.CreateAndDeleteCluster(self.context)
scenario._create_cluster = mock.Mock(return_value=mock_cluster)
scenario._delete_cluster = mock.Mock()
scenario.create_and_delete_cluster(desired_capacity=1, min_size=0,
max_size=3, timeout=60,
metadata={"k2": "v2"})
scenario.run(desired_capacity=1, min_size=0,
max_size=3, timeout=60, metadata={"k2": "v2"})
scenario._create_cluster.assert_called_once_with("fake_profile_id",
1, 0, 3, 60,

View File

@ -24,14 +24,13 @@ from tests.unit import test
class SwiftObjectsTestCase(test.ScenarioTestCase):
def test_create_container_and_object_then_list_objects(self):
scenario = objects.SwiftObjects(self.context)
scenario = objects.CreateContainerAndObjectThenListObjects(
self.context)
scenario._create_container = mock.MagicMock(return_value="AA")
scenario._upload_object = mock.MagicMock()
scenario._list_objects = mock.MagicMock()
scenario.create_container_and_object_then_list_objects(
objects_per_container=5,
object_size=100)
scenario.run(objects_per_container=5, object_size=100)
self.assertEqual(1, scenario._create_container.call_count)
self.assertEqual(5, scenario._upload_object.call_count)
@ -41,16 +40,14 @@ class SwiftObjectsTestCase(test.ScenarioTestCase):
"swift.create_5_objects")
def test_create_container_and_object_then_delete_all(self):
scenario = objects.SwiftObjects(self.context)
scenario = objects.CreateContainerAndObjectThenDeleteAll(self.context)
scenario._create_container = mock.MagicMock(return_value="BB")
scenario._upload_object = mock.MagicMock(
side_effect=[("etaaag", "ooobj_%i" % i) for i in range(3)])
scenario._delete_object = mock.MagicMock()
scenario._delete_container = mock.MagicMock()
scenario.create_container_and_object_then_delete_all(
objects_per_container=3,
object_size=10)
scenario.run(objects_per_container=3, object_size=10)
self.assertEqual(1, scenario._create_container.call_count)
self.assertEqual(3, scenario._upload_object.call_count)
@ -65,15 +62,15 @@ class SwiftObjectsTestCase(test.ScenarioTestCase):
"swift.delete_3_objects")
def test_create_container_and_object_then_download_object(self):
scenario = objects.SwiftObjects(self.context)
scenario = objects.CreateContainerAndObjectThenDownloadObject(
self.context
)
scenario._create_container = mock.MagicMock(return_value="CC")
scenario._upload_object = mock.MagicMock(
side_effect=[("etaaaag", "obbbj_%i" % i) for i in range(2)])
scenario._download_object = mock.MagicMock()
scenario.create_container_and_object_then_download_object(
objects_per_container=2,
object_size=50)
scenario.run(objects_per_container=2, object_size=50)
self.assertEqual(1, scenario._create_container.call_count)
self.assertEqual(2, scenario._upload_object.call_count)
@ -89,12 +86,12 @@ class SwiftObjectsTestCase(test.ScenarioTestCase):
@ddt.data(1, 5)
def test_list_objects_in_containers(self, num_cons):
con_list = [{"name": "cooon_%s" % i} for i in range(num_cons)]
scenario = objects.SwiftObjects()
scenario = objects.ListObjectsInContainers(self.context)
scenario._list_containers = mock.MagicMock(return_value=("header",
con_list))
scenario._list_objects = mock.MagicMock()
scenario.list_objects_in_containers()
scenario.run()
scenario._list_containers.assert_called_once_with()
con_calls = [mock.call(container["name"], atomic_action=False)
for container in con_list]
@ -111,14 +108,14 @@ class SwiftObjectsTestCase(test.ScenarioTestCase):
def test_list_and_download_objects_in_containers(self, num_cons, num_objs):
con_list = [{"name": "connn_%s" % i} for i in range(num_cons)]
obj_list = [{"name": "ooobj_%s" % i} for i in range(num_objs)]
scenario = objects.SwiftObjects()
scenario = objects.ListAndDownloadObjectsInContainers(self.context)
scenario._list_containers = mock.MagicMock(return_value=("header",
con_list))
scenario._list_objects = mock.MagicMock(return_value=("header",
obj_list))
scenario._download_object = mock.MagicMock()
scenario.list_and_download_objects_in_containers()
scenario.run()
scenario._list_containers.assert_called_once_with()
con_calls = [mock.call(container["name"], atomic_action=False)
for container in con_list]
@ -146,13 +143,12 @@ class SwiftObjectsTestCase(test.ScenarioTestCase):
def test_functional_create_container_and_object_then_list_objects(self):
names_list = ["AA", "BB", "CC", "DD"]
scenario = objects.SwiftObjects(self.context)
scenario = objects.CreateContainerAndObjectThenListObjects(
self.context)
scenario.generate_random_name = mock.MagicMock(side_effect=names_list)
scenario._list_objects = mock.MagicMock()
scenario.create_container_and_object_then_list_objects(
objects_per_container=3,
object_size=100)
scenario.run(objects_per_container=3, object_size=100)
scenario._list_objects.assert_called_once_with("AA")
@ -162,14 +158,12 @@ class SwiftObjectsTestCase(test.ScenarioTestCase):
def test_functional_create_container_and_object_then_delete_all(self):
names_list = ["111", "222", "333", "444", "555"]
scenario = objects.SwiftObjects(self.context)
scenario = objects.CreateContainerAndObjectThenDeleteAll(self.context)
scenario.generate_random_name = mock.MagicMock(side_effect=names_list)
scenario._delete_object = mock.MagicMock()
scenario._delete_container = mock.MagicMock()
scenario.create_container_and_object_then_delete_all(
objects_per_container=4,
object_size=240)
scenario.run(objects_per_container=4, object_size=240)
scenario._delete_object.assert_has_calls(
[mock.call("111", name,
@ -184,13 +178,12 @@ class SwiftObjectsTestCase(test.ScenarioTestCase):
def test_functional_create_container_and_object_then_download_object(self):
names_list = ["aaa", "bbb", "ccc", "ddd", "eee", "fff"]
scenario = objects.SwiftObjects(self.context)
scenario = objects.CreateContainerAndObjectThenDownloadObject(
self.context)
scenario.generate_random_name = mock.MagicMock(side_effect=names_list)
scenario._download_object = mock.MagicMock()
scenario.create_container_and_object_then_download_object(
objects_per_container=5,
object_size=750)
scenario.run(objects_per_container=5, object_size=750)
scenario._download_object.assert_has_calls(
[mock.call("aaa", name,

View File

@ -36,8 +36,6 @@ class TempestScenarioTestCase(test.TestCase):
self.context = test.get_test_context()
self.context.update({"verifier": self.verifier,
"tmp_results_dir": "/dev"})
self.scenario = tempest.TempestScenario(self.context)
self.scenario._add_atomic_actions = mock.MagicMock()
def get_tests_launcher_cmd(self, tests):
return ("%(venv)s testr run --subunit --parallel --concurrency 0 "
@ -55,10 +53,13 @@ class TempestScenarioTestCase(test.TestCase):
@mock.patch(TEMPEST_DIR + ".config.TempestResourcesContext")
def test_single_test(self, mock_tempest_resources_context,
mock_subprocess, mock_tempfile, mock_isfile):
scenario = tempest.SingleTest(self.context)
scenario._add_atomic_actions = mock.MagicMock()
mock_tempfile.NamedTemporaryFile().name = "/dev/null"
fake_test = "tempest.api.fake.test"
self.scenario.single_test(test_name=fake_test)
scenario.run(test_name=fake_test)
expected_call = self.get_tests_launcher_cmd([fake_test])
mock_subprocess.check_call.assert_called_once_with(
@ -71,10 +72,13 @@ class TempestScenarioTestCase(test.TestCase):
@mock.patch(TEMPEST_DIR + ".config.TempestResourcesContext")
def test_single_test_negative(self, mock_tempest_resources_context,
mock_subprocess, mock_tempfile, mock_isfile):
scenario = tempest.SingleTest(self.context)
scenario._add_atomic_actions = mock.MagicMock()
mock_tempfile.NamedTemporaryFile().name = "/dev/null"
fake_test = "tempest.api.network"
self.scenario.single_test(test_name=fake_test)
scenario.run(test_name=fake_test)
expected_call = self.get_tests_launcher_cmd([fake_test])
mock_subprocess.check_call.assert_called_once_with(
@ -88,9 +92,12 @@ class TempestScenarioTestCase(test.TestCase):
def test_single_test_without_prefix(self, mock_tempest_resources_context,
mock_subprocess, mock_tempfile,
mock_isfile):
scenario = tempest.SingleTest(self.context)
scenario._add_atomic_actions = mock.MagicMock()
mock_tempfile.NamedTemporaryFile().name = "/dev/null"
self.scenario.single_test("network")
scenario.run("network")
expected_call = self.get_tests_launcher_cmd(["tempest.api.network"])
mock_subprocess.check_call.assert_called_once_with(
@ -103,9 +110,12 @@ class TempestScenarioTestCase(test.TestCase):
@mock.patch(TEMPEST_DIR + ".config.TempestResourcesContext")
def test_all(self, mock_tempest_resources_context,
mock_subprocess, mock_tempfile, mock_isfile):
scenario = tempest.All(self.context)
scenario._add_atomic_actions = mock.MagicMock()
mock_tempfile.NamedTemporaryFile().name = "/dev/null"
self.scenario.all()
scenario.run()
expected_call = self.get_tests_launcher_cmd([])
mock_subprocess.check_call.assert_called_once_with(
@ -118,9 +128,12 @@ class TempestScenarioTestCase(test.TestCase):
@mock.patch(TEMPEST_DIR + ".config.TempestResourcesContext")
def test_set_smoke(self, mock_tempest_resources_context,
mock_subprocess, mock_tempfile, mock_isfile):
scenario = tempest.Set(self.context)
scenario._add_atomic_actions = mock.MagicMock()
mock_tempfile.NamedTemporaryFile().name = "/dev/null"
self.scenario.set("smoke")
scenario.run("smoke")
expected_call = self.get_tests_launcher_cmd(["smoke"])
mock_subprocess.check_call.assert_called_once_with(
@ -133,9 +146,12 @@ class TempestScenarioTestCase(test.TestCase):
@mock.patch(TEMPEST_DIR + ".config.TempestResourcesContext")
def test_set_full(self, mock_tempest_resources_context,
mock_subprocess, mock_tempfile, mock_isfile):
scenario = tempest.Set(self.context)
scenario._add_atomic_actions = mock.MagicMock()
mock_tempfile.NamedTemporaryFile().name = "/dev/null"
self.scenario.set("full")
scenario.run("full")
expected_call = self.get_tests_launcher_cmd([])
mock_subprocess.check_call.assert_called_once_with(
@ -147,6 +163,9 @@ class TempestScenarioTestCase(test.TestCase):
@mock.patch(TEMPEST_DIR + ".config.TempestResourcesContext")
def test_set_from_list(self, mock_tempest_resources_context,
mock_tempfile, mock_isfile):
scenario = tempest.Set(self.context)
scenario._add_atomic_actions = mock.MagicMock()
mock_tempfile.NamedTemporaryFile().name = "/dev/null"
fake_scenarios = ["network", "volume", "baremetal",
@ -155,7 +174,7 @@ class TempestScenarioTestCase(test.TestCase):
"telemetry", "queuing", "orchestration"]
for fake_scenario in fake_scenarios:
with mock.patch(VERIFIER + ".subprocess") as mock_subprocess:
self.scenario.set(fake_scenario)
scenario.run(fake_scenario)
fake_test = "tempest.api." + fake_scenario
expected_call = self.get_tests_launcher_cmd([fake_test])
@ -169,9 +188,12 @@ class TempestScenarioTestCase(test.TestCase):
@mock.patch(TEMPEST_DIR + ".config.TempestResourcesContext")
def test_set_selective(self, mock_tempest_resources_context,
mock_subprocess, mock_tempfile, mock_isfile):
scenario = tempest.Set(self.context)
scenario._add_atomic_actions = mock.MagicMock()
mock_tempfile.NamedTemporaryFile().name = "/dev/null"
self.scenario.set("network")
scenario.run("network")
expected_call = self.get_tests_launcher_cmd(["tempest.api.network"])
mock_subprocess.check_call.assert_called_once_with(
@ -184,10 +206,13 @@ class TempestScenarioTestCase(test.TestCase):
@mock.patch(TEMPEST_DIR + ".config.TempestResourcesContext")
def test_list_of_tests(self, mock_tempest_resources_context,
mock_subprocess, mock_tempfile, mock_isfile):
scenario = tempest.ListOfTests(self.context)
scenario._add_atomic_actions = mock.MagicMock()
mock_tempfile.NamedTemporaryFile().name = "/dev/null"
fake_tests = ["tempest.fake.test1", "tempest.fake.test2"]
self.scenario.list_of_tests(fake_tests)
scenario.run(fake_tests)
expected_call = self.get_tests_launcher_cmd(fake_tests)
mock_subprocess.check_call.assert_called_once_with(
@ -200,10 +225,13 @@ class TempestScenarioTestCase(test.TestCase):
@mock.patch(TEMPEST_DIR + ".config.TempestResourcesContext")
def test_specific_regex(self, mock_tempest_resources_context,
mock_subprocess, mock_tempfile, mock_isfile):
scenario = tempest.SpecificRegex(self.context)
scenario._add_atomic_actions = mock.MagicMock()
mock_tempfile.NamedTemporaryFile().name = "/dev/null"
regex = "tempest.fake.test1"
self.scenario.specific_regex(regex)
scenario.run(regex)
expected_call = self.get_tests_launcher_cmd([regex])
mock_subprocess.check_call.assert_called_once_with(

View File

@ -32,7 +32,7 @@ class TempestLogWrappersTestCase(test.TestCase):
context = test.get_test_context()
context.update({"tmp_results_dir": "/tmp/dir", "verifier": verifier})
self.scenario = tempest.TempestScenario(context)
self.scenario = tempest.SingleTest(context)
self.scenario._add_atomic_actions = mock.MagicMock()
@mock.patch(TS + ".utils.tempfile")
@ -65,7 +65,7 @@ class TempestLogWrappersTestCase(test.TestCase):
total={"time": "0.1"}, tests={})
context = test.get_test_context()
context.update({"tmp_results_dir": "/tmp/dir", "verifier": verifier})
scenario = tempest.TempestScenario(context)
scenario = tempest.SingleTest(context)
target_func = mock.MagicMock()
target_func.__name__ = "target_func"

View File

@ -21,6 +21,9 @@ from rally.plugins.openstack.scenarios.vm import vmtasks
from tests.unit import test
BASE = "rally.plugins.openstack.scenarios.vm.vmtasks"
@ddt.ddt
class VMTasksTestCase(test.ScenarioTestCase):
@ -28,49 +31,50 @@ class VMTasksTestCase(test.ScenarioTestCase):
super(VMTasksTestCase, self).setUp()
self.context.update({"user": {"keypair": {"name": "keypair_name"},
"credential": mock.MagicMock()}})
self.scenario = vmtasks.VMTasks(context=self.context)
def create_env(self, scenario):
self.ip = {"id": "foo_id", "ip": "foo_ip", "is_floating": True}
self.scenario._boot_server_with_fip = mock.Mock(
scenario._boot_server_with_fip = mock.Mock(
return_value=("foo_server", self.ip))
self.scenario._wait_for_ping = mock.Mock()
self.scenario._delete_server_with_fip = mock.Mock()
self.scenario._create_volume = mock.Mock(
scenario._wait_for_ping = mock.Mock()
scenario._delete_server_with_fip = mock.Mock()
scenario._create_volume = mock.Mock(
return_value=mock.Mock(id="foo_volume"))
self.scenario._run_command = mock.MagicMock(
scenario._run_command = mock.MagicMock(
return_value=(0, "{\"foo\": 42}", "foo_err"))
self.scenario.add_output = mock.Mock()
scenario.add_output = mock.Mock()
return scenario
def test_boot_runcommand_delete(self):
self.scenario._run_command = mock.MagicMock(
scenario = self.create_env(vmtasks.BootRuncommandDelete(self.context))
scenario._run_command = mock.MagicMock(
return_value=(0, "{\"foo\": 42}", "foo_err"))
self.scenario.boot_runcommand_delete(
"foo_image", "foo_flavor",
command={"script_file": "foo_script",
"interpreter": "foo_interpreter"},
username="foo_username",
password="foo_password",
use_floating_ip="use_fip",
floating_network="ext_network",
force_delete="foo_force",
volume_args={"size": 16},
foo_arg="foo_value")
scenario.run("foo_image", "foo_flavor",
command={"script_file": "foo_script",
"interpreter": "foo_interpreter"},
username="foo_username",
password="foo_password",
use_floating_ip="use_fip",
floating_network="ext_network",
force_delete="foo_force",
volume_args={"size": 16},
foo_arg="foo_value")
self.scenario._create_volume.assert_called_once_with(
16, imageRef=None)
self.scenario._boot_server_with_fip.assert_called_once_with(
scenario._create_volume.assert_called_once_with(16, imageRef=None)
scenario._boot_server_with_fip.assert_called_once_with(
"foo_image", "foo_flavor", key_name="keypair_name",
use_floating_ip="use_fip", floating_network="ext_network",
block_device_mapping={"vdrally": "foo_volume:::1"},
foo_arg="foo_value")
self.scenario._wait_for_ping.assert_called_once_with("foo_ip")
self.scenario._run_command.assert_called_once_with(
scenario._wait_for_ping.assert_called_once_with("foo_ip")
scenario._run_command.assert_called_once_with(
"foo_ip", 22, "foo_username", "foo_password",
command={"script_file": "foo_script",
"interpreter": "foo_interpreter"})
self.scenario._delete_server_with_fip.assert_called_once_with(
scenario._delete_server_with_fip.assert_called_once_with(
"foo_server", self.ip, force_delete="foo_force")
self.scenario.add_output.assert_called_once_with(
scenario.add_output.assert_called_once_with(
additive={"title": "Command output", "chart_plugin": "Lines",
"data": [["foo", 42.0]]})
@ -93,7 +97,9 @@ class VMTasksTestCase(test.ScenarioTestCase):
@ddt.unpack
def test_boot_runcommand_delete_add_output(self, output,
expected=None, raises=None):
self.scenario._run_command.return_value = output
scenario = self.create_env(vmtasks.BootRuncommandDelete(self.context))
scenario._run_command.return_value = output
kwargs = {"command": {"remote_path": "foo"},
"username": "foo_username",
"password": "foo_password",
@ -103,48 +109,50 @@ class VMTasksTestCase(test.ScenarioTestCase):
"volume_args": {"size": 16},
"foo_arg": "foo_value"}
if raises:
self.assertRaises(raises, self.scenario.boot_runcommand_delete,
self.assertRaises(raises, scenario.run,
"foo_image", "foo_flavor", **kwargs)
self.assertFalse(self.scenario.add_output.called)
self.assertFalse(scenario.add_output.called)
else:
self.scenario.boot_runcommand_delete("foo_image", "foo_flavor",
**kwargs)
scenario.run("foo_image", "foo_flavor", **kwargs)
calls = [mock.call(**kw) for kw in expected]
self.scenario.add_output.assert_has_calls(calls, any_order=True)
scenario.add_output.assert_has_calls(calls, any_order=True)
self.scenario._create_volume.assert_called_once_with(
16, imageRef=None)
self.scenario._boot_server_with_fip.assert_called_once_with(
scenario._create_volume.assert_called_once_with(16, imageRef=None)
scenario._boot_server_with_fip.assert_called_once_with(
"foo_image", "foo_flavor", key_name="keypair_name",
use_floating_ip="use_fip", floating_network="ext_network",
block_device_mapping={"vdrally": "foo_volume:::1"},
foo_arg="foo_value")
self.scenario._run_command.assert_called_once_with(
scenario._run_command.assert_called_once_with(
"foo_ip", 22, "foo_username", "foo_password",
command={"remote_path": "foo"})
self.scenario._delete_server_with_fip.assert_called_once_with(
scenario._delete_server_with_fip.assert_called_once_with(
"foo_server", self.ip, force_delete="foo_force")
def test_boot_runcommand_delete_command_timeouts(self):
self.scenario._run_command.side_effect = exceptions.SSHTimeout()
scenario = self.create_env(vmtasks.BootRuncommandDelete(self.context))
scenario._run_command.side_effect = exceptions.SSHTimeout()
self.assertRaises(exceptions.SSHTimeout,
self.scenario.boot_runcommand_delete,
scenario.run,
"foo_image", "foo_flavor", "foo_interpreter",
"foo_script", "foo_username")
self.scenario._delete_server_with_fip.assert_called_once_with(
scenario._delete_server_with_fip.assert_called_once_with(
"foo_server", self.ip, force_delete=False)
self.assertFalse(self.scenario.add_output.called)
self.assertFalse(scenario.add_output.called)
def test_boot_runcommand_delete_ping_wait_timeouts(self):
self.scenario._wait_for_ping.side_effect = exceptions.TimeoutException(
scenario = self.create_env(vmtasks.BootRuncommandDelete(self.context))
scenario._wait_for_ping.side_effect = exceptions.TimeoutException(
resource_type="foo_resource",
resource_name="foo_name",
resource_id="foo_id",
desired_status="foo_desired_status",
resource_status="foo_resource_status")
exc = self.assertRaises(exceptions.TimeoutException,
self.scenario.boot_runcommand_delete,
scenario.run,
"foo_image", "foo_flavor", "foo_interpreter",
"foo_script", "foo_username",
wait_for_ping=True)
@ -154,22 +162,25 @@ class VMTasksTestCase(test.ScenarioTestCase):
self.assertEqual(exc.kwargs["desired_status"], "foo_desired_status")
self.assertEqual(exc.kwargs["resource_status"], "foo_resource_status")
self.scenario._delete_server_with_fip.assert_called_once_with(
scenario._delete_server_with_fip.assert_called_once_with(
"foo_server", self.ip, force_delete=False)
self.assertFalse(self.scenario.add_output.called)
self.assertFalse(scenario.add_output.called)
@mock.patch("rally.plugins.openstack.scenarios.vm.vmtasks.json")
@mock.patch("%s.json" % BASE)
def test_boot_runcommand_delete_json_fails(self, mock_json):
scenario = self.create_env(vmtasks.BootRuncommandDelete(self.context))
mock_json.loads.side_effect = ValueError()
self.assertRaises(exceptions.ScriptError,
self.scenario.boot_runcommand_delete,
scenario.run,
"foo_image", "foo_flavor", "foo_interpreter",
"foo_script", "foo_username")
self.scenario._delete_server_with_fip.assert_called_once_with(
scenario._delete_server_with_fip.assert_called_once_with(
"foo_server", self.ip, force_delete=False)
self.assertFalse(self.scenario.add_output.called)
self.assertFalse(scenario.add_output.called)
def test_boot_runcommand_delete_custom_image(self):
@mock.patch("%s.BootRuncommandDelete.run" % BASE)
def test_boot_runcommand_delete_custom_image(self, mock_scenario):
context = {
"user": {
"tenant_id": "tenant_id",
@ -179,26 +190,23 @@ class VMTasksTestCase(test.ScenarioTestCase):
"custom_image": {"id": "image_id"}
}
}
scenario = vmtasks.VMTasks(context)
scenario = vmtasks.BootRuncommandDeleteCustomImage(context)
scenario.boot_runcommand_delete = mock.Mock()
scenario.run(flavor="flavor_id",
command={
"script_file": "foo_script",
"interpreter": "bar_interpreter"},
username="username")
scenario.boot_runcommand_delete_custom_image(
flavor="flavor_id",
command={
"script_file": "foo_script",
"interpreter": "bar_interpreter"},
username="username")
scenario.boot_runcommand_delete.assert_called_once_with(
mock_scenario.assert_called_once_with(
image="image_id", flavor="flavor_id", username="username",
command={
"script_file": "foo_script",
"interpreter": "bar_interpreter"}
)
@mock.patch("rally.plugins.openstack.scenarios.vm.vmtasks.heat")
@mock.patch("rally.plugins.openstack.scenarios.vm.vmtasks.sshutils")
@mock.patch("%s.heat" % BASE)
@mock.patch("%s.sshutils" % BASE)
def test_runcommand_heat(self, mock_sshutils, mock_heat):
fake_ssh = mock.Mock()
fake_ssh.execute.return_value = [0, "key:val", ""]
@ -212,14 +220,14 @@ class VMTasksTestCase(test.ScenarioTestCase):
"credential": "ok"},
"tenant": {"networks": [{"router_id": "1"}]}
}
scenario = vmtasks.VMTasks(context)
scenario = vmtasks.RuncommandHeat(context)
scenario.generate_random_name = mock.Mock(return_value="name")
scenario.add_output = mock.Mock()
workload = {"username": "admin",
"resource": ["foo", "bar"]}
scenario.runcommand_heat(workload, "template",
{"file_key": "file_value"},
{"param_key": "param_value"})
scenario.run(workload, "template",
{"file_key": "file_value"},
{"param_key": "param_value"})
expected = {"chart_plugin": "Table",
"data": {"rows": [["key", "val"]],
"cols": ["key", "value"]},

View File

@ -22,12 +22,12 @@ from tests.unit import test
class WatcherTestCase(test.ScenarioTestCase):
def test_create_audit_template_and_delete(self):
scenario = basic.Watcher(self.context)
scenario = basic.CreateAuditTemplateAndDelete(self.context)
audit_template = mock.Mock()
scenario._create_audit_template = mock.MagicMock(
return_value=audit_template)
scenario._delete_audit_template = mock.MagicMock()
scenario.create_audit_template_and_delete("goal", "strategy", {})
scenario.run("goal", "strategy", {})
scenario._create_audit_template.assert_called_once_with("goal",
"strategy",
{})
@ -35,20 +35,20 @@ class WatcherTestCase(test.ScenarioTestCase):
audit_template.uuid)
def test_list_audit_template(self):
scenario = basic.Watcher(self.context)
scenario = basic.ListAuditTemplates(self.context)
scenario._list_audit_templates = mock.MagicMock()
scenario.list_audit_templates()
scenario.run()
scenario._list_audit_templates.assert_called_once_with(
detail=False, goal=None, limit=None, name=None, sort_dir=None,
sort_key=None, strategy=None)
def test_create_audit_and_delete(self):
mock_audit = mock.MagicMock()
scenario = basic.Watcher(self.context)
scenario = basic.CreateAuditAndDelete(self.context)
scenario.context = mock.MagicMock()
scenario._create_audit = mock.MagicMock(return_value=mock_audit)
scenario.sleep_between = mock.MagicMock()
scenario._delete_audit = mock.MagicMock()
scenario.create_audit_and_delete()
scenario.run()
scenario._create_audit.assert_called_once_with(mock.ANY)
scenario._delete_audit.assert_called_once_with(mock_audit)

View File

@ -17,22 +17,23 @@ import mock
from rally.plugins.openstack.scenarios.zaqar import basic
from tests.unit import test
BASE = "rally.plugins.openstack.scenarios.zaqar."
BASIC = BASE + "basic.ZaqarBasic."
BASE = "rally.plugins.openstack.scenarios.zaqar.basic"
class ZaqarBasicTestCase(test.ScenarioTestCase):
@mock.patch(BASIC + "generate_random_name", return_value="fizbit")
def test_create_queue(self, mock_generate_random_name):
scenario = basic.ZaqarBasic(self.context)
@mock.patch("%s.CreateQueue.generate_random_name" % BASE,
return_value="fizbit")
def test_create_queue(self, mock_random_name):
scenario = basic.CreateQueue(self.context)
scenario._queue_create = mock.MagicMock()
scenario.create_queue(fakearg="fake")
scenario.run(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):
scenario = basic.ZaqarBasic(self.context)
@mock.patch("%s.CreateQueue.generate_random_name" % BASE,
return_value="kitkat")
def test_producer_consumer(self, mock_random_name):
scenario = basic.ProducerConsumer(self.context)
messages = [{"body": {"id": idx}, "ttl": 360} for idx
in range(20)]
queue = mock.MagicMock()
@ -42,8 +43,7 @@ class ZaqarBasicTestCase(test.ScenarioTestCase):
scenario._messages_list = mock.MagicMock()
scenario._queue_delete = mock.MagicMock()
scenario.producer_consumer(min_msg_count=20, max_msg_count=20,
fakearg="fake")
scenario.run(min_msg_count=20, max_msg_count=20, fakearg="fake")
scenario._queue_create.assert_called_once_with(fakearg="fake")
scenario._messages_post.assert_called_once_with(queue, messages,

View File

@ -43,9 +43,20 @@ class DocstringsTestCase(test.TestCase):
def test_all_scenarios_have_docstrings(self):
ignored_params = ["self", "scenario_obj"]
for scenario_inst in scenario.Scenario.get_all():
self.assertIsNotNone(scenario_inst.__doc__,
"%s doensn't have a docstring." %
scenario_inst.get_name())
try:
self.assertIsNotNone(scenario_inst.__doc__,
"%s doensn't have a docstring." %
scenario_inst.get_name())
except Exception:
msg = ("'{}.run' doesn't have a docstring. "
"At least class '{}' or method '{}.run' "
"should contain a docstring")
inst_name = scenario_inst.__name__
if scenario_inst.is_classbased:
self.assertIsNotNone(scenario_inst.run.__doc__,
msg.format(inst_name,
inst_name,
inst_name))
doc = info.parse_docstring(scenario_inst.__doc__)
short_description = doc["short_description"]
self.assertIsNotNone(short_description,