Merge "Remove osclients from runner and scenario signature"

This commit is contained in:
Jenkins
2015-07-15 06:20:56 +00:00
committed by Gerrit Code Review
27 changed files with 209 additions and 268 deletions

View File

@@ -16,7 +16,6 @@ from rally.common.i18n import _
from rally.common import log as logging from rally.common import log as logging
from rally.common import utils as rutils from rally.common import utils as rutils
from rally import consts from rally import consts
from rally import osclients
from rally.plugins.openstack.scenarios.ceilometer import utils as ceilo_utils from rally.plugins.openstack.scenarios.ceilometer import utils as ceilo_utils
from rally.task import context from rally.task import context
@@ -70,26 +69,20 @@ class CeilometerSampleGenerator(context.Context):
counter_type = self.config["counter_type"] counter_type = self.config["counter_type"]
counter_unit = self.config["counter_unit"] counter_unit = self.config["counter_unit"]
counter_volume = self.config["counter_volume"] counter_volume = self.config["counter_volume"]
resources_per_tenant = self.config["resources_per_tenant"]
samples_per_resource = self.config["samples_per_resource"]
for user, tenant_id in rutils.iterate_per_tenants( for user, tenant_id in rutils.iterate_per_tenants(
self.context["users"]): self.context["users"]):
self.context["tenants"][tenant_id]["samples"] = [] self.context["tenants"][tenant_id]["samples"] = []
self.context["tenants"][tenant_id]["resources"] = [] self.context["tenants"][tenant_id]["resources"] = []
clients = osclients.Clients(user["endpoint"]) scenario = ceilo_utils.CeilometerScenario({"user": user})
scenario = ceilo_utils.CeilometerScenario( for i in range(self.config["resources_per_tenant"]):
clients=clients) for j in range(self.config["samples_per_resource"]):
for i in range(resources_per_tenant):
for j in range(samples_per_resource):
try:
sample = scenario._create_sample(counter_name, sample = scenario._create_sample(counter_name,
counter_type, counter_type,
counter_unit, counter_unit,
counter_volume) counter_volume)
self.context["tenants"][tenant_id]["samples"].append( self.context["tenants"][tenant_id]["samples"].append(
sample[0].to_dict()) sample[0].to_dict())
except Exception as err:
LOG.error("Creating a sample failed: %s" % err)
self.context["tenants"][tenant_id]["resources"].append( self.context["tenants"][tenant_id]["resources"].append(
sample[0].resource_id) sample[0].resource_id)

View File

@@ -16,7 +16,6 @@ from rally.common.i18n import _
from rally.common import log as logging from rally.common import log as logging
from rally.common import utils as rutils from rally.common import utils as rutils
from rally import consts from rally import consts
from rally import osclients
from rally.plugins.openstack.context.cleanup import manager as resource_manager from rally.plugins.openstack.context.cleanup import manager as resource_manager
from rally.plugins.openstack.scenarios.glance import utils as glance_utils from rally.plugins.openstack.scenarios.glance import utils as glance_utils
from rally.task import context from rally.task import context
@@ -78,9 +77,7 @@ class ImageGenerator(context.Context):
for user, tenant_id in rutils.iterate_per_tenants( for user, tenant_id in rutils.iterate_per_tenants(
self.context["users"]): self.context["users"]):
current_images = [] current_images = []
clients = osclients.Clients(user["endpoint"]) glance_scenario = glance_utils.GlanceScenario({"user": user})
glance_scenario = glance_utils.GlanceScenario(
clients=clients)
for i in range(images_per_tenant): for i in range(images_per_tenant):
if image_name and i > 0: if image_name and i > 0:
cur_name = image_name + str(i) cur_name = image_name + str(i)

View File

@@ -20,7 +20,6 @@ from rally.common import log as logging
from rally.common import utils as rutils from rally.common import utils as rutils
from rally import consts from rally import consts
from rally import exceptions from rally import exceptions
from rally import osclients
from rally.plugins.openstack.context.cleanup import manager as resource_manager from rally.plugins.openstack.context.cleanup import manager as resource_manager
from rally.plugins.openstack.scenarios.sahara import utils from rally.plugins.openstack.scenarios.sahara import utils
from rally.task import context from rally.task import context
@@ -97,15 +96,18 @@ class SaharaCluster(context.Context):
for user, tenant_id in rutils.iterate_per_tenants( for user, tenant_id in rutils.iterate_per_tenants(
self.context["users"]): self.context["users"]):
clients = osclients.Clients(user["endpoint"])
image_id = self.context["tenants"][tenant_id]["sahara_image"] image_id = self.context["tenants"][tenant_id]["sahara_image"]
floating_ip_pool = self.config.get("floating_ip_pool") floating_ip_pool = self.config.get("floating_ip_pool")
temporary_context = {"tenant": self.context["tenants"][tenant_id]} temporary_context = {
cluster = utils.SaharaScenario( "user": user,
context=temporary_context, clients=clients)._launch_cluster( "tenant": self.context["tenants"][tenant_id]
}
scenario = utils.SaharaScenario(context=temporary_context)
cluster = scenario._launch_cluster(
plugin_name=self.config["plugin_name"], plugin_name=self.config["plugin_name"],
hadoop_version=self.config["hadoop_version"], hadoop_version=self.config["hadoop_version"],
flavor_id=self.config["flavor_id"], flavor_id=self.config["flavor_id"],
@@ -119,14 +121,15 @@ class SaharaCluster(context.Context):
security_groups=self.config.get("security_groups"), security_groups=self.config.get("security_groups"),
node_configs=self.config.get("node_configs"), node_configs=self.config.get("node_configs"),
cluster_configs=self.config.get("cluster_configs"), cluster_configs=self.config.get("cluster_configs"),
enable_anti_affinity=self.config.get( enable_anti_affinity=self.config.get("enable_anti_affinity",
"enable_anti_affinity", False), False),
wait_active=False) wait_active=False
)
self.context["tenants"][tenant_id]["sahara_cluster"] = cluster.id self.context["tenants"][tenant_id]["sahara_cluster"] = cluster.id
# Need to save the client instance to poll for active status # Need to save the client instance to poll for active status
wait_dict[cluster] = clients.sahara() wait_dict[cluster] = scenario.clients("sahara")
bench_utils.wait_for( bench_utils.wait_for(
resource=wait_dict, resource=wait_dict,

View File

@@ -64,19 +64,16 @@ class SaharaImage(context.Context):
def _create_image(self, hadoop_version, image_url, plugin_name, user, def _create_image(self, hadoop_version, image_url, plugin_name, user,
user_name): user_name):
clients = osclients.Clients(user["endpoint"]) scenario = glance_utils.GlanceScenario({"user": user})
scenario = glance_utils.GlanceScenario(clients=clients)
image_name = rutils.generate_random_name(prefix="rally_sahara_image_") image_name = rutils.generate_random_name(prefix="rally_sahara_image_")
image = scenario._create_image(name=image_name, image = scenario._create_image(name=image_name,
container_format="bare", container_format="bare",
image_location=image_url, image_location=image_url,
disk_format="qcow2") disk_format="qcow2")
clients.sahara().images.update_image(image_id=image.id, scenario.clients("sahara").images.update_image(
user_name=user_name, image_id=image.id, user_name=user_name, desc="")
desc="") scenario.clients("sahara").images.update_tags(
clients.sahara().images.update_tags(image_id=image.id, image_id=image.id, new_tags=[plugin_name, hadoop_version])
new_tags=[plugin_name,
hadoop_version])
return image.id return image.id
@rutils.log_task_wrapper(LOG.info, _("Enter context: `Sahara Image`")) @rutils.log_task_wrapper(LOG.info, _("Enter context: `Sahara Image`"))

View File

@@ -82,8 +82,7 @@ class ServerGenerator(context.Context):
self.context["users"]): self.context["users"]):
LOG.debug("Booting servers for user tenant %s " LOG.debug("Booting servers for user tenant %s "
% (user["tenant_id"])) % (user["tenant_id"]))
clients = osclients.Clients(user["endpoint"]) nova_scenario = nova_utils.NovaScenario({"user": user})
nova_scenario = nova_utils.NovaScenario(clients=clients)
LOG.debug("Calling _boot_servers with image_id=%(image_id)s " LOG.debug("Calling _boot_servers with image_id=%(image_id)s "
"flavor_id=%(flavor_id)s " "flavor_id=%(flavor_id)s "

View File

@@ -17,7 +17,6 @@ from rally.common.i18n import _
from rally.common import log as logging from rally.common import log as logging
from rally.common import utils as rutils from rally.common import utils as rutils
from rally import consts from rally import consts
from rally import osclients
from rally.plugins.openstack.context.cleanup import manager as resource_manager from rally.plugins.openstack.context.cleanup import manager as resource_manager
from rally.plugins.openstack.scenarios.heat import utils as heat_utils from rally.plugins.openstack.scenarios.heat import utils as heat_utils
from rally.task import context from rally.task import context
@@ -77,8 +76,7 @@ class StackGenerator(context.Context):
self.config["resources_per_stack"]) self.config["resources_per_stack"])
for user, tenant_id in rutils.iterate_per_tenants( for user, tenant_id in rutils.iterate_per_tenants(
self.context["users"]): self.context["users"]):
heat_scenario = heat_utils.HeatScenario( heat_scenario = heat_utils.HeatScenario({"user": user})
clients=osclients.Clients(user["endpoint"]))
self.context["tenants"][tenant_id]["stacks"] = [] self.context["tenants"][tenant_id]["stacks"] = []
for i in range(self.config["stacks_per_tenant"]): for i in range(self.config["stacks_per_tenant"]):
stack = heat_scenario._create_stack(template) stack = heat_scenario._create_stack(template)

View File

@@ -16,7 +16,6 @@ from rally.common.i18n import _
from rally.common import log as logging from rally.common import log as logging
from rally.common import utils as rutils from rally.common import utils as rutils
from rally import consts from rally import consts
from rally import osclients
from rally.plugins.openstack.context.cleanup import manager as resource_manager from rally.plugins.openstack.context.cleanup import manager as resource_manager
from rally.plugins.openstack.scenarios.cinder import utils as cinder_utils from rally.plugins.openstack.scenarios.cinder import utils as cinder_utils
from rally.task import context from rally.task import context
@@ -59,8 +58,7 @@ class VolumeGenerator(context.Context):
for user, tenant_id in rutils.iterate_per_tenants( for user, tenant_id in rutils.iterate_per_tenants(
self.context["users"]): self.context["users"]):
self.context["tenants"][tenant_id].setdefault("volumes", []) self.context["tenants"][tenant_id].setdefault("volumes", [])
clients = osclients.Clients(user["endpoint"]) cinder_util = cinder_utils.CinderScenario({"user": user})
cinder_util = cinder_utils.CinderScenario(clients=clients)
for i in range(volumes_per_tenant): for i in range(volumes_per_tenant):
rnd_name = scenario_base.Scenario._generate_random_name( rnd_name = scenario_base.Scenario._generate_random_name(
prefix="ctx_rally_volume_") prefix="ctx_rally_volume_")

View File

@@ -155,7 +155,7 @@ class SaharaScenario(base.Scenario):
return None return None
def _setup_floating_ip_pool(self, node_groups, floating_ip_pool): def _setup_floating_ip_pool(self, node_groups, floating_ip_pool):
if consts.Service.NEUTRON in self._clients.services().values(): if consts.Service.NEUTRON in self.clients("services").values():
LOG.debug("Neutron detected as networking backend.") LOG.debug("Neutron detected as networking backend.")
floating_ip_pool_value = self._setup_neutron_floating_ip_pool( floating_ip_pool_value = self._setup_neutron_floating_ip_pool(
floating_ip_pool) floating_ip_pool)
@@ -504,7 +504,7 @@ class SaharaScenario(base.Scenario):
:return: Network id for Neutron or None for Nova Networking. :return: Network id for Neutron or None for Nova Networking.
""" """
if consts.Service.NEUTRON not in self._clients.services().values(): if consts.Service.NEUTRON not in self.clients("services").values():
return None return None
# Taking net id from context. # Taking net id from context.

View File

@@ -26,7 +26,6 @@ from rally.common import log as logging
from rally.common.plugin import plugin from rally.common.plugin import plugin
from rally.common import utils as rutils from rally.common import utils as rutils
from rally import consts from rally import consts
from rally import osclients
from rally.task.scenarios import base as scenario_base from rally.task.scenarios import base as scenario_base
from rally.task import types from rally.task import types
from rally.task import utils from rally.task import utils
@@ -66,10 +65,7 @@ def _run_scenario_once(args):
{"task": context["task"]["uuid"], "iteration": iteration}) {"task": context["task"]["uuid"], "iteration": iteration})
context["iteration"] = iteration context["iteration"] = iteration
scenario = cls( scenario = cls(context=context)
context=context,
admin_clients=osclients.Clients(context["admin"]["endpoint"]),
clients=osclients.Clients(context["user"]["endpoint"]))
error = [] error = []
scenario_output = {"errors": "", "data": {}} scenario_output = {"errors": "", "data": {}}

View File

@@ -25,6 +25,7 @@ from rally.common.plugin import discover
from rally.common import utils from rally.common import utils
from rally import consts from rally import consts
from rally import exceptions from rally import exceptions
from rally import osclients
from rally.task import functional from rally.task import functional
@@ -56,10 +57,18 @@ class Scenario(functional.FunctionalMixin):
RESOURCE_NAME_PREFIX = "rally_" RESOURCE_NAME_PREFIX = "rally_"
RESOURCE_NAME_LENGTH = 10 RESOURCE_NAME_LENGTH = 10
def __init__(self, context=None, admin_clients=None, clients=None): def __init__(self, context=None):
self.context = context self.context = context
self._admin_clients = admin_clients
self._clients = clients # TODO(boris-42): This is going to be inside OpenStackScenario subclass
# so Rally framework won't depend on OpenStack stuff
if context:
if "admin" in context:
self._admin_clients = osclients.Clients(
context["admin"]["endpoint"])
if "user" in context:
self._clients = osclients.Clients(context["user"]["endpoint"])
self._idle_duration = 0 self._idle_duration = 0
self._atomic_actions = costilius.OrderedDict() self._atomic_actions = costilius.OrderedDict()

View File

@@ -20,9 +20,8 @@ from tests.unit import test
class CinderQuotasTestCase(test.TestCase): class CinderQuotasTestCase(test.TestCase):
@mock.patch("rally.plugins.openstack.context." def test_update(self):
"quotas.quotas.osclients.Clients") mock_clients = mock.MagicMock()
def test_update(self, mock_clients):
cinder_quo = cinder_quotas.CinderQuotas(mock_clients) cinder_quo = cinder_quotas.CinderQuotas(mock_clients)
tenant_id = mock.MagicMock() tenant_id = mock.MagicMock()
quotas_values = { quotas_values = {
@@ -34,9 +33,8 @@ class CinderQuotasTestCase(test.TestCase):
mock_clients.cinder().quotas.update.assert_called_once_with( mock_clients.cinder().quotas.update.assert_called_once_with(
tenant_id, **quotas_values) tenant_id, **quotas_values)
@mock.patch("rally.plugins.openstack.context." def test_delete(self):
"quotas.quotas.osclients.Clients") mock_clients = mock.MagicMock()
def test_delete(self, mock_clients):
cinder_quo = cinder_quotas.CinderQuotas(mock_clients) cinder_quo = cinder_quotas.CinderQuotas(mock_clients)
tenant_id = mock.MagicMock() tenant_id = mock.MagicMock()
cinder_quo.delete(tenant_id) cinder_quo.delete(tenant_id)

View File

@@ -24,7 +24,9 @@ CONF = cfg.CONF
CTX = "rally.plugins.openstack.context.sahara" CTX = "rally.plugins.openstack.context.sahara"
class SaharaClusterTestCase(test.TestCase): class SaharaClusterTestCase(test.ScenarioTestCase):
patch_benchmark_utils = False
def setUp(self): def setUp(self):
super(SaharaClusterTestCase, self).setUp() super(SaharaClusterTestCase, self).setUp()
@@ -42,7 +44,7 @@ class SaharaClusterTestCase(test.TestCase):
for j in range(self.users_per_tenant): for j in range(self.users_per_tenant):
self.users_key.append({"id": "%s_%s" % (str(i), str(j)), self.users_key.append({"id": "%s_%s" % (str(i), str(j)),
"tenant_id": str(i), "tenant_id": str(i),
"endpoint": "endpoint"}) "endpoint": mock.MagicMock()})
CONF.set_override("cluster_check_interval", 0, "benchmark") CONF.set_override("cluster_check_interval", 0, "benchmark")
@@ -52,7 +54,7 @@ class SaharaClusterTestCase(test.TestCase):
"config": { "config": {
"users": { "users": {
"tenants": self.tenants_num, "tenants": self.tenants_num,
"users_per_tenant": self.users_per_tenant, "users_per_tenant": self.users_per_tenant
}, },
"sahara_cluster": { "sahara_cluster": {
"flavor_id": "test_flavor", "flavor_id": "test_flavor",
@@ -70,13 +72,9 @@ class SaharaClusterTestCase(test.TestCase):
@mock.patch("%s.sahara_cluster.resource_manager.cleanup" % CTX) @mock.patch("%s.sahara_cluster.resource_manager.cleanup" % CTX)
@mock.patch("%s.sahara_cluster.utils.SaharaScenario._launch_cluster" % CTX, @mock.patch("%s.sahara_cluster.utils.SaharaScenario._launch_cluster" % CTX,
return_value=mock.MagicMock(id=42)) return_value=mock.MagicMock(id=42))
@mock.patch("%s.sahara_cluster.osclients" % CTX) def test_setup_and_cleanup(self, mock_sahara_scenario__launch_cluster,
def test_setup_and_cleanup(
self, mock_osclients, mock_sahara_scenario__launch_cluster,
mock_cleanup): mock_cleanup):
mock_sahara = mock_osclients.Clients(mock.MagicMock()).sahara()
ctx = self.context_without_cluster_keys ctx = self.context_without_cluster_keys
sahara_ctx = sahara_cluster.SaharaCluster(ctx) sahara_ctx = sahara_cluster.SaharaCluster(ctx)
@@ -100,7 +98,7 @@ class SaharaClusterTestCase(test.TestCase):
wait_active=False wait_active=False
)) ))
mock_sahara.clusters.get.side_effect = [ self.clients("sahara").clusters.get.side_effect = [
mock.MagicMock(status="not-active"), mock.MagicMock(status="not-active"),
mock.MagicMock(status="active")] mock.MagicMock(status="active")]
sahara_ctx.setup() sahara_ctx.setup()
@@ -113,11 +111,8 @@ class SaharaClusterTestCase(test.TestCase):
@mock.patch("%s.sahara_cluster.utils.SaharaScenario._launch_cluster" % CTX, @mock.patch("%s.sahara_cluster.utils.SaharaScenario._launch_cluster" % CTX,
return_value=mock.MagicMock(id=42)) return_value=mock.MagicMock(id=42))
@mock.patch("%s.sahara_cluster.osclients" % CTX) def test_setup_and_cleanup_error(self,
def test_setup_and_cleanup_error( mock_sahara_scenario__launch_cluster):
self, mock_osclients, mock_sahara_scenario__launch_cluster):
mock_sahara = mock_osclients.Clients(mock.MagicMock()).sahara()
ctx = self.context_without_cluster_keys ctx = self.context_without_cluster_keys
sahara_ctx = sahara_cluster.SaharaCluster(ctx) sahara_ctx = sahara_cluster.SaharaCluster(ctx)
@@ -141,8 +136,9 @@ class SaharaClusterTestCase(test.TestCase):
wait_active=False wait_active=False
)) ))
mock_sahara.clusters.get.side_effect = [ self.clients("sahara").clusters.get.side_effect = [
mock.MagicMock(status="not-active"), mock.MagicMock(status="not-active"),
mock.MagicMock(status="error")] mock.MagicMock(status="error")
]
self.assertRaises(exceptions.SaharaClusterFailure, sahara_ctx.setup) self.assertRaises(exceptions.SaharaClusterFailure, sahara_ctx.setup)

View File

@@ -25,7 +25,7 @@ BASE_SCN = "rally.task.scenarios"
SCN = "rally.plugins.openstack.scenarios" SCN = "rally.plugins.openstack.scenarios"
class SaharaImageTestCase(test.TestCase): class SaharaImageTestCase(test.ScenarioTestCase):
def setUp(self): def setUp(self):
super(SaharaImageTestCase, self).setUp() super(SaharaImageTestCase, self).setUp()
@@ -42,7 +42,7 @@ class SaharaImageTestCase(test.TestCase):
for j in range(self.users_per_tenant): for j in range(self.users_per_tenant):
self.users_key.append({"id": "%s_%s" % (str(i), str(j)), self.users_key.append({"id": "%s_%s" % (str(i), str(j)),
"tenant_id": str(i), "tenant_id": str(i),
"endpoint": "endpoint"}) "endpoint": mock.MagicMock()})
@property @property
def url_image_context(self): def url_image_context(self):
@@ -87,11 +87,10 @@ class SaharaImageTestCase(test.TestCase):
return_value="sahara_image_42") return_value="sahara_image_42")
@mock.patch("%s.glance.utils.GlanceScenario._create_image" % SCN, @mock.patch("%s.glance.utils.GlanceScenario._create_image" % SCN,
return_value=mock.MagicMock(id=42)) return_value=mock.MagicMock(id=42))
@mock.patch("%s.osclients" % CTX)
@mock.patch("%s.resource_manager.cleanup" % CTX) @mock.patch("%s.resource_manager.cleanup" % CTX)
def test_setup_and_cleanup_url_image( def test_setup_and_cleanup_url_image(self, mock_cleanup,
self, mock_cleanup, mock_osclients, mock_glance_scenario__create_image,
mock_glance_scenario__create_image, mock_generate_random_name): mock_generate_random_name):
ctx = self.url_image_context ctx = self.url_image_context
sahara_ctx = sahara_image.SaharaImage(ctx) sahara_ctx = sahara_image.SaharaImage(ctx)
@@ -117,11 +116,9 @@ class SaharaImageTestCase(test.TestCase):
sahara_ctx.setup() sahara_ctx.setup()
mock_glance_scenario__create_image.assert_has_calls(glance_calls) mock_glance_scenario__create_image.assert_has_calls(glance_calls)
mock_osclients.Clients( self.clients("sahara").images.update_image.assert_has_calls(
mock.MagicMock()).sahara().images.update_image.assert_has_calls(
sahara_update_image_calls) sahara_update_image_calls)
mock_osclients.Clients( self.clients("sahara").images.update_tags.assert_has_calls(
mock.MagicMock()).sahara().images.update_tags.assert_has_calls(
sahara_update_tags_calls) sahara_update_tags_calls)
sahara_ctx.cleanup() sahara_ctx.cleanup()
@@ -131,13 +128,12 @@ class SaharaImageTestCase(test.TestCase):
@mock.patch("%s.glance.utils.GlanceScenario._create_image" % SCN, @mock.patch("%s.glance.utils.GlanceScenario._create_image" % SCN,
return_value=mock.MagicMock(id=42)) return_value=mock.MagicMock(id=42))
@mock.patch("%s.resource_manager.cleanup" % CTX) @mock.patch("%s.resource_manager.cleanup" % CTX)
@mock.patch("%s.osclients" % CTX) @mock.patch("%s.osclients.Clients" % CTX)
def test_setup_and_cleanup_existing_image( def test_setup_and_cleanup_existing_image(
self, mock_osclients, mock_cleanup, self, mock_clients, mock_cleanup,
mock_glance_scenario__create_image): mock_glance_scenario__create_image):
clients = mock_osclients.Clients(mock.MagicMock()) mock_clients.glance.images.get.return_value = mock.MagicMock(
clients.glance().images.get.return_value = mock.MagicMock(
is_public=True) is_public=True)
ctx = self.existing_image_context ctx = self.existing_image_context
@@ -153,25 +149,24 @@ class SaharaImageTestCase(test.TestCase):
sahara_ctx.cleanup() sahara_ctx.cleanup()
self.assertEqual(False, mock_cleanup.called) self.assertEqual(False, mock_cleanup.called)
@mock.patch("%s.osclients" % CTX) @mock.patch("%s.osclients.Clients.glance" % CTX)
def test_check_existing_image(self, mock_osclients): def test_check_existing_image(self, mock_clients_glance):
ctx = self.existing_image_context ctx = self.existing_image_context
sahara_ctx = sahara_image.SaharaImage(ctx) sahara_ctx = sahara_image.SaharaImage(ctx)
sahara_ctx.setup() sahara_ctx.setup()
mock_osclients.glance().images.get.asser_called_once_with("some_id") mock_clients_glance.images.get.asser_called_once_with("some_id")
@mock.patch("%s.osclients" % CTX) @mock.patch("%s.osclients.Clients.glance" % CTX)
def test_check_existing_image_fail(self, mock_osclients): def test_check_existing_private_image_fail(self, mock_clients_glance):
clients = mock_osclients.Clients(mock.MagicMock()) mock_clients_glance.return_value.images.get.return_value = (
clients.glance().images.get.return_value = mock.MagicMock( mock.MagicMock(is_public=False))
is_public=False)
ctx = self.existing_image_context ctx = self.existing_image_context
sahara_ctx = sahara_image.SaharaImage(ctx) sahara_ctx = sahara_image.SaharaImage(ctx)
self.assertRaises(exceptions.BenchmarkSetupFailure, self.assertRaises(exceptions.BenchmarkSetupFailure,
sahara_ctx.setup) sahara_ctx.setup)
clients.glance().images.get.asser_called_once_with("some_id") mock_clients_glance.images.get.asser_called_once_with("some_id")

View File

@@ -18,7 +18,6 @@ import copy
import mock import mock
from rally.plugins.openstack.context import ceilometer from rally.plugins.openstack.context import ceilometer
from tests.unit import fakes
from tests.unit import test from tests.unit import test
CTX = "rally.plugins.openstack.context" CTX = "rally.plugins.openstack.context"
@@ -29,8 +28,8 @@ class CeilometerSampleGeneratorTestCase(test.TestCase):
def _gen_tenants(self, count): def _gen_tenants(self, count):
tenants = {} tenants = {}
for id in range(count): for id_ in range(count):
tenants[str(id)] = dict(name=str(id)) tenants[str(id_)] = {"name": str(id_)}
return tenants return tenants
def _gen_context(self, tenants_count, users_per_tenant, def _gen_context(self, tenants_count, users_per_tenant,
@@ -40,7 +39,7 @@ class CeilometerSampleGeneratorTestCase(test.TestCase):
for id_ in tenants.keys(): for id_ in tenants.keys():
for i in range(users_per_tenant): for i in range(users_per_tenant):
users.append({"id": i, "tenant_id": id_, users.append({"id": i, "tenant_id": id_,
"endpoint": "endpoint"}) "endpoint": mock.MagicMock()})
context = { context = {
"config": { "config": {
"users": { "users": {
@@ -83,41 +82,44 @@ class CeilometerSampleGeneratorTestCase(test.TestCase):
inst = ceilometer.CeilometerSampleGenerator(context) inst = ceilometer.CeilometerSampleGenerator(context)
self.assertEqual(inst.config, context["config"]["ceilometer"]) self.assertEqual(inst.config, context["config"]["ceilometer"])
@mock.patch("%s.ceilometer.osclients" % CTX) @mock.patch("%s.ceilometer.ceilo_utils.CeilometerScenario._create_sample"
def test_setup(self, mock_osclients): % CTX)
fc = fakes.FakeClients() def test_setup(self, mock_ceilometer_scenario__create_sample):
mock_osclients.Clients.return_value = fc
tenants_count = 2 tenants_count = 2
users_per_tenant = 5 users_per_tenant = 2
resources_per_tenant = 5 resources_per_tenant = 2
samples_per_resource = 5 samples_per_resource = 2
tenants, real_context = self._gen_context( tenants, real_context = self._gen_context(
tenants_count, users_per_tenant, tenants_count, users_per_tenant,
resources_per_tenant, samples_per_resource) resources_per_tenant, samples_per_resource)
sample = {
"counter_name": "fake-counter-name",
"counter_type": "fake-counter-type",
"counter_unit": "fake-counter-unit",
"counter_volume": 100,
"resource_id": "fake-resource-id"
}
new_context = copy.deepcopy(real_context) new_context = copy.deepcopy(real_context)
for id_ in tenants.keys(): for id_ in tenants.keys():
new_context["tenants"][id_].setdefault("samples", []) new_context["tenants"][id_].setdefault("samples", [])
new_context["tenants"][id_].setdefault("resources", []) new_context["tenants"][id_].setdefault("resources", [])
for i in range(resources_per_tenant): for i in range(resources_per_tenant):
for j in range(samples_per_resource): for j in range(samples_per_resource):
new_context["tenants"][id_]["samples"].append( new_context["tenants"][id_]["samples"].append(sample)
{"counter_name": "fake-counter-name",
"counter_type": "fake-counter-type",
"counter_unit": "fake-counter-unit",
"counter_volume": 100,
"resource_id": "fake-resource-id"})
new_context["tenants"][id_]["resources"].append( new_context["tenants"][id_]["resources"].append(
"fake-resource-id") sample["resource_id"])
mock_ceilometer_scenario__create_sample.return_value = [
mock.MagicMock(to_dict=lambda: sample, **sample)]
ceilometer_ctx = ceilometer.CeilometerSampleGenerator(real_context) ceilometer_ctx = ceilometer.CeilometerSampleGenerator(real_context)
ceilometer_ctx.setup() ceilometer_ctx.setup()
self.assertEqual(new_context, ceilometer_ctx.context) self.assertEqual(new_context, ceilometer_ctx.context)
@mock.patch("%s.ceilometer.osclients" % CTX) def test_cleanup(self):
def test_cleanup(self, mock_osclients):
tenants, context = self._gen_context(2, 5, 3, 3) tenants, context = self._gen_context(2, 5, 3, 3)
ceilometer_ctx = ceilometer.CeilometerSampleGenerator(context) ceilometer_ctx = ceilometer.CeilometerSampleGenerator(context)
ceilometer_ctx.cleanup() ceilometer_ctx.cleanup()

View File

@@ -26,12 +26,12 @@ CTX = "rally.plugins.openstack.context"
SCN = "rally.plugins.openstack.scenarios" SCN = "rally.plugins.openstack.scenarios"
class ImageGeneratorTestCase(test.TestCase): class ImageGeneratorTestCase(test.ScenarioTestCase):
def _gen_tenants(self, count): def _gen_tenants(self, count):
tenants = {} tenants = {}
for id_ in range(count): for id_ in range(count):
tenants[str(id_)] = dict(name=str(id_)) tenants[str(id_)] = {"name": str(id_)}
return tenants return tenants
@mock.patch("%s.images.context.Context.__init__" % CTX) @mock.patch("%s.images.context.Context.__init__" % CTX)
@@ -67,22 +67,18 @@ class ImageGeneratorTestCase(test.TestCase):
@mock.patch("%s.glance.utils.GlanceScenario._create_image" % SCN, @mock.patch("%s.glance.utils.GlanceScenario._create_image" % SCN,
return_value=fakes.FakeImage(id="uuid")) return_value=fakes.FakeImage(id="uuid"))
@mock.patch("%s.images.osclients" % CTX) def test_setup(self, mock_glance_scenario__create_image):
def test_setup(self, mock_osclients, mock_glance_scenario__create_image):
tenants_count = 2 tenants_count = 2
users_per_tenant = 5 users_per_tenant = 5
images_per_tenant = 5 images_per_tenant = 5
fc = fakes.FakeClients()
mock_osclients.Clients.return_value = fc
tenants = self._gen_tenants(tenants_count) tenants = self._gen_tenants(tenants_count)
users = [] users = []
for id in tenants: for id in tenants:
for i in range(users_per_tenant): for i in range(users_per_tenant):
users.append({"id": i, "tenant_id": id, users.append({"id": i, "tenant_id": id,
"endpoint": "endpoint"}) "endpoint": mock.MagicMock()})
real_context = { real_context = {
"config": { "config": {
@@ -119,9 +115,8 @@ class ImageGeneratorTestCase(test.TestCase):
images_ctx.setup() images_ctx.setup()
self.assertEqual(new_context, real_context) self.assertEqual(new_context, real_context)
@mock.patch("%s.images.osclients" % CTX)
@mock.patch("%s.images.resource_manager.cleanup" % CTX) @mock.patch("%s.images.resource_manager.cleanup" % CTX)
def test_cleanup(self, mock_cleanup, mock_osclients): def test_cleanup(self, mock_cleanup):
tenants_count = 2 tenants_count = 2
users_per_tenant = 5 users_per_tenant = 5

View File

@@ -26,12 +26,12 @@ SCN = "rally.plugins.openstack.scenarios"
TYP = "rally.task.types" TYP = "rally.task.types"
class ServerGeneratorTestCase(test.TestCase): class ServerGeneratorTestCase(test.ScenarioTestCase):
def _gen_tenants(self, count): def _gen_tenants(self, count):
tenants = {} tenants = {}
for id in range(count): for id_ in range(count):
tenants[str(id)] = dict(name=str(id)) tenants[str(id_)] = {"name": str(id_)}
return tenants return tenants
def test_init(self): def test_init(self):
@@ -75,7 +75,7 @@ class ServerGeneratorTestCase(test.TestCase):
for id in tenants.keys(): for id in tenants.keys():
for i in range(users_per_tenant): for i in range(users_per_tenant):
users.append({"id": i, "tenant_id": id, users.append({"id": i, "tenant_id": id,
"endpoint": "endpoint"}) "endpoint": mock.MagicMock()})
real_context = { real_context = {
"config": { "config": {
@@ -103,10 +103,10 @@ class ServerGeneratorTestCase(test.TestCase):
} }
new_context = copy.deepcopy(real_context) new_context = copy.deepcopy(real_context)
for id in new_context["tenants"]: for id_ in new_context["tenants"]:
new_context["tenants"][id].setdefault("servers", []) new_context["tenants"][id_].setdefault("servers", [])
for i in range(servers_per_tenant): for i in range(servers_per_tenant):
new_context["tenants"][id]["servers"].append("uuid") new_context["tenants"][id_]["servers"].append("uuid")
servers_ctx = servers.ServerGenerator(real_context) servers_ctx = servers.ServerGenerator(real_context)
servers_ctx.setup() servers_ctx.setup()
@@ -122,13 +122,13 @@ class ServerGeneratorTestCase(test.TestCase):
tenants = self._gen_tenants(tenants_count) tenants = self._gen_tenants(tenants_count)
users = [] users = []
for id in tenants.keys(): for id_ in tenants.keys():
for i in range(users_per_tenant): for i in range(users_per_tenant):
users.append({"id": i, "tenant_id": id, users.append({"id": i, "tenant_id": id_,
"endpoint": "endpoint"}) "endpoint": "endpoint"})
tenants[id].setdefault("servers", []) tenants[id_].setdefault("servers", [])
for j in range(servers_per_tenant): for j in range(servers_per_tenant):
tenants[id]["servers"].append("uuid") tenants[id_]["servers"].append("uuid")
context = { context = {
"config": { "config": {

View File

@@ -23,7 +23,7 @@ CTX = "rally.plugins.openstack.context"
SCN = "rally.plugins.openstack.scenarios" SCN = "rally.plugins.openstack.scenarios"
class TestStackGenerator(test.TestCase): class TestStackGenerator(test.ScenarioTestCase):
def _gen_tenants(self, count): def _gen_tenants(self, count):
tenants = {} tenants = {}
@@ -47,21 +47,17 @@ class TestStackGenerator(test.TestCase):
@mock.patch("%s.heat.utils.HeatScenario._create_stack" % SCN, @mock.patch("%s.heat.utils.HeatScenario._create_stack" % SCN,
return_value=fakes.FakeStack(id="uuid")) return_value=fakes.FakeStack(id="uuid"))
@mock.patch("%s.stacks.osclients" % CTX) def test_setup(self, mock_heat_scenario__create_stack):
def test_setup(self, mock_osclients, mock_heat_scenario__create_stack):
tenants_count = 2 tenants_count = 2
users_per_tenant = 5 users_per_tenant = 5
stacks_per_tenant = 1 stacks_per_tenant = 1
fc = fakes.FakeClients()
mock_osclients.Clients.return_value = fc
tenants = self._gen_tenants(tenants_count) tenants = self._gen_tenants(tenants_count)
users = [] users = []
for ten_id in tenants: for ten_id in tenants:
for i in range(users_per_tenant): for i in range(users_per_tenant):
users.append({"id": i, "tenant_id": ten_id, users.append({"id": i, "tenant_id": ten_id,
"endpoint": "endpoint"}) "endpoint": mock.MagicMock()})
context = { context = {
"config": { "config": {

View File

@@ -25,12 +25,12 @@ CTX = "rally.plugins.openstack.context"
SCN = "rally.plugins.openstack.scenarios" SCN = "rally.plugins.openstack.scenarios"
class VolumeGeneratorTestCase(test.TestCase): class VolumeGeneratorTestCase(test.ScenarioTestCase):
def _gen_tenants(self, count): def _gen_tenants(self, count):
tenants = {} tenants = {}
for id in range(count): for id_ in range(count):
tenants[str(id)] = dict(name=str(id)) tenants[str(id_)] = {"name": str(id_)}
return tenants return tenants
def test_init(self): def test_init(self):
@@ -48,21 +48,17 @@ class VolumeGeneratorTestCase(test.TestCase):
@mock.patch("%s.cinder.utils.CinderScenario._create_volume" % SCN, @mock.patch("%s.cinder.utils.CinderScenario._create_volume" % SCN,
return_value=fakes.FakeVolume(id="uuid")) return_value=fakes.FakeVolume(id="uuid"))
@mock.patch("%s.volumes.osclients" % CTX) def test_setup(self, mock_cinder_scenario__create_volume):
def test_setup(self, mock_osclients, mock_cinder_scenario__create_volume):
fc = fakes.FakeClients()
mock_osclients.Clients.return_value = fc
tenants_count = 2 tenants_count = 2
users_per_tenant = 5 users_per_tenant = 5
volumes_per_tenant = 5 volumes_per_tenant = 5
tenants = self._gen_tenants(tenants_count) tenants = self._gen_tenants(tenants_count)
users = [] users = []
for id in tenants.keys(): for id_ in tenants.keys():
for i in range(users_per_tenant): for i in range(users_per_tenant):
users.append({"id": i, "tenant_id": id, users.append({"id": i, "tenant_id": id_,
"endpoint": "endpoint"}) "endpoint": mock.MagicMock()})
real_context = { real_context = {
"config": { "config": {
@@ -73,7 +69,7 @@ class VolumeGeneratorTestCase(test.TestCase):
}, },
"volumes": { "volumes": {
"size": 1, "size": 1,
"volumes_per_tenant": 5, "volumes_per_tenant": volumes_per_tenant,
} }
}, },
"admin": { "admin": {
@@ -85,18 +81,17 @@ class VolumeGeneratorTestCase(test.TestCase):
} }
new_context = copy.deepcopy(real_context) new_context = copy.deepcopy(real_context)
for id in tenants.keys(): for id_ in tenants.keys():
new_context["tenants"][id].setdefault("volumes", []) new_context["tenants"][id_].setdefault("volumes", [])
for i in range(volumes_per_tenant): for i in range(volumes_per_tenant):
new_context["tenants"][id]["volumes"].append({"id": "uuid"}) new_context["tenants"][id_]["volumes"].append({"id": "uuid"})
volumes_ctx = volumes.VolumeGenerator(real_context) volumes_ctx = volumes.VolumeGenerator(real_context)
volumes_ctx.setup() volumes_ctx.setup()
self.assertEqual(new_context, real_context) self.assertEqual(new_context, real_context)
@mock.patch("%s.volumes.osclients" % CTX)
@mock.patch("%s.volumes.resource_manager.cleanup" % CTX) @mock.patch("%s.volumes.resource_manager.cleanup" % CTX)
def test_cleanup(self, mock_cleanup, mock_osclients): def test_cleanup(self, mock_cleanup):
tenants_count = 2 tenants_count = 2
users_per_tenant = 5 users_per_tenant = 5
@@ -104,13 +99,13 @@ class VolumeGeneratorTestCase(test.TestCase):
tenants = self._gen_tenants(tenants_count) tenants = self._gen_tenants(tenants_count)
users = [] users = []
for id in tenants.keys(): for id_ in tenants.keys():
for i in range(users_per_tenant): for i in range(users_per_tenant):
users.append({"id": i, "tenant_id": id, users.append({"id": i, "tenant_id": id_,
"endpoint": "endpoint"}) "endpoint": "endpoint"})
tenants[id].setdefault("volumes", []) tenants[id_].setdefault("volumes", [])
for j in range(volumes_per_tenant): for j in range(volumes_per_tenant):
tenants[id]["volumes"].append({"id": "uuid"}) tenants[id_]["volumes"].append({"id": "uuid"})
context = { context = {
"config": { "config": {

View File

@@ -28,6 +28,13 @@ class fake_type(object):
class CinderServersTestCase(test.ScenarioTestCase): class CinderServersTestCase(test.ScenarioTestCase):
def _get_context(self):
return {"user": {"tenant_id": "fake",
"endpoint": mock.MagicMock()},
"tenant": {"id": "fake", "name": "fake",
"volumes": [{"id": "uuid"}],
"servers": [1]}}
def test_create_and_list_volume(self): def test_create_and_list_volume(self):
scenario = volumes.CinderVolumes() scenario = volumes.CinderVolumes()
scenario._create_volume = mock.MagicMock() scenario._create_volume = mock.MagicMock()
@@ -66,10 +73,7 @@ class CinderServersTestCase(test.ScenarioTestCase):
scenario._create_volume.assert_called_once_with(1, fakearg="f") scenario._create_volume.assert_called_once_with(1, fakearg="f")
def test_create_volume_and_modify_metadata(self): def test_create_volume_and_modify_metadata(self):
scenario = volumes.CinderVolumes( scenario = volumes.CinderVolumes(self._get_context())
context={"user": {"tenant_id": "fake"},
"tenant": {"id": "fake", "name": "fake",
"volumes": [{"id": "uuid"}]}})
scenario._set_metadata = mock.Mock() scenario._set_metadata = mock.Mock()
scenario._delete_metadata = mock.Mock() scenario._delete_metadata = mock.Mock()
@@ -130,10 +134,7 @@ class CinderServersTestCase(test.ScenarioTestCase):
def test_create_from_volume_and_delete_volume(self): def test_create_from_volume_and_delete_volume(self):
fake_volume = mock.MagicMock() fake_volume = mock.MagicMock()
vol_size = 1 vol_size = 1
scenario = volumes.CinderVolumes( scenario = volumes.CinderVolumes(self._get_context())
context={"user": {"tenant_id": "fake"},
"tenant": {"id": "fake", "name": "fake",
"volumes": [{"id": "uuid"}]}})
scenario._create_volume = mock.MagicMock(return_value=fake_volume) scenario._create_volume = mock.MagicMock(return_value=fake_volume)
scenario._delete_volume = mock.MagicMock() scenario._delete_volume = mock.MagicMock()
@@ -143,10 +144,7 @@ class CinderServersTestCase(test.ScenarioTestCase):
def test_create_and_delete_snapshot(self): def test_create_and_delete_snapshot(self):
fake_snapshot = mock.MagicMock() fake_snapshot = mock.MagicMock()
scenario = volumes.CinderVolumes( scenario = volumes.CinderVolumes(self._get_context())
context={"user": {"tenant_id": "fake"},
"tenant": {"id": "fake", "name": "fake",
"volumes": [{"id": "uuid"}]}})
scenario._create_snapshot = mock.MagicMock(return_value=fake_snapshot) scenario._create_snapshot = mock.MagicMock(return_value=fake_snapshot)
scenario.sleep_between = mock.MagicMock() scenario.sleep_between = mock.MagicMock()
@@ -161,10 +159,7 @@ class CinderServersTestCase(test.ScenarioTestCase):
def test_create_and_list_snapshots(self): def test_create_and_list_snapshots(self):
fake_snapshot = mock.MagicMock() fake_snapshot = mock.MagicMock()
scenario = volumes.CinderVolumes( scenario = volumes.CinderVolumes(self._get_context())
context={"user": {"tenant_id": "fake"},
"tenant": {"id": "fake", "name": "fake",
"volumes": [{"id": "uuid"}]}})
scenario._create_snapshot = mock.MagicMock(return_value=fake_snapshot) scenario._create_snapshot = mock.MagicMock(return_value=fake_snapshot)
scenario._list_snapshots = mock.MagicMock() scenario._list_snapshots = mock.MagicMock()
@@ -233,12 +228,7 @@ class CinderServersTestCase(test.ScenarioTestCase):
fake_volume = mock.MagicMock() fake_volume = mock.MagicMock()
fake_snapshot = mock.MagicMock() fake_snapshot = mock.MagicMock()
fake_server = mock.MagicMock() fake_server = mock.MagicMock()
scenario = volumes.CinderVolumes(self._get_context())
context = {"user": {"tenant_id": "fake"},
"users": [{"tenant_id": "fake", "users_per_tenant": 1}],
"tenant": {"id": "fake", "name": "fake", "servers": [1]}}
scenario = volumes.CinderVolumes(context)
scenario._attach_volume = mock.MagicMock() scenario._attach_volume = mock.MagicMock()
scenario._detach_volume = mock.MagicMock() scenario._detach_volume = mock.MagicMock()
@@ -268,11 +258,8 @@ class CinderServersTestCase(test.ScenarioTestCase):
fake_volume = mock.MagicMock() fake_volume = mock.MagicMock()
fake_snapshot = mock.MagicMock() fake_snapshot = mock.MagicMock()
fake_server = mock.MagicMock() fake_server = mock.MagicMock()
context = {"user": {"tenant_id": "fake"},
"users": [{"tenant_id": "fake", "users_per_tenant": 1}],
"tenant": {"id": "fake", "name": "fake", "servers": [1]}}
scenario = volumes.CinderVolumes(context) scenario = volumes.CinderVolumes(self._get_context())
scenario._attach_volume = mock.MagicMock() scenario._attach_volume = mock.MagicMock()
scenario._detach_volume = mock.MagicMock() scenario._detach_volume = mock.MagicMock()
@@ -308,12 +295,8 @@ class CinderServersTestCase(test.ScenarioTestCase):
def test_create_nested_snapshots_and_attach_volume(self): def test_create_nested_snapshots_and_attach_volume(self):
fake_volume = mock.MagicMock() fake_volume = mock.MagicMock()
fake_snapshot = mock.MagicMock() fake_snapshot = mock.MagicMock()
fake_server = mock.MagicMock()
scenario = volumes.CinderVolumes( scenario = volumes.CinderVolumes(context=self._get_context())
context={"user": {"tenant_id": "fake"},
"users": [{"tenant_id": "fake", "users_per_tenant": 1}],
"tenant": {"id": "fake", "name": "fake",
"servers": [fake_server.uuid]}})
scenario._attach_volume = mock.MagicMock() scenario._attach_volume = mock.MagicMock()
scenario._detach_volume = mock.MagicMock() scenario._detach_volume = mock.MagicMock()
@@ -338,13 +321,8 @@ class CinderServersTestCase(test.ScenarioTestCase):
fake_volume2 = mock.MagicMock() fake_volume2 = mock.MagicMock()
fake_snapshot1 = mock.MagicMock() fake_snapshot1 = mock.MagicMock()
fake_snapshot2 = mock.MagicMock() fake_snapshot2 = mock.MagicMock()
fake_server = mock.MagicMock()
scenario = volumes.CinderVolumes( scenario = volumes.CinderVolumes(self._get_context())
context={"user": {"tenant_id": "fake"},
"users": [{"tenant_id": "fake", "users_per_tenant": 1}],
"tenant": {"id": "fake", "name": "fake",
"servers": [fake_server.uuid]}})
scenario._attach_volume = mock.MagicMock() scenario._attach_volume = mock.MagicMock()
scenario._detach_volume = mock.MagicMock() scenario._detach_volume = mock.MagicMock()
@@ -373,11 +351,7 @@ class CinderServersTestCase(test.ScenarioTestCase):
fake_snapshot = mock.MagicMock() fake_snapshot = mock.MagicMock()
fake_server = mock.MagicMock() fake_server = mock.MagicMock()
scenario = volumes.CinderVolumes( scenario = volumes.CinderVolumes(self._get_context())
context={"user": {"tenant_id": "fake"},
"users": [{"tenant_id": "fake", "users_per_tenant": 1}],
"tenant": {"id": "fake", "name": "fake",
"servers": [fake_server.uuid]}})
scenario.get_random_server = mock.MagicMock(return_value=fake_server) scenario.get_random_server = mock.MagicMock(return_value=fake_server)
scenario._attach_volume = mock.MagicMock() scenario._attach_volume = mock.MagicMock()

View File

@@ -27,7 +27,10 @@ class KeystoneBasicTestCase(test.TestCase):
@staticmethod @staticmethod
def _get_context(): def _get_context():
return { return {
"user": {"id": "fake_user_id"}, "user": {
"id": "fake_user_id",
"endpoint": mock.MagicMock()
},
"tenant": {"id": "fake_tenant_id"} "tenant": {"id": "fake_tenant_id"}
} }

View File

@@ -20,7 +20,11 @@ class NeutronLoadbalancerv1TestCase(test.TestCase):
def _get_context(self): def _get_context(self):
return { return {
"user": {"id": "fake_user", "tenant_id": "fake_tenant"}, "user": {
"id": "fake_user",
"tenant_id": "fake_tenant",
"endpoint": mock.MagicMock()
},
"tenant": {"id": "fake_tenant", "tenant": {"id": "fake_tenant",
"networks": [{"id": "fake_net", "networks": [{"id": "fake_net",
"subnets": ["fake_subnet"]}]}} "subnets": ["fake_subnet"]}]}}

View File

@@ -109,7 +109,10 @@ class NovaScenarioTestCase(test.ScenarioTestCase):
def test__boot_server_with_ssh(self, mock__generate_random_name): def test__boot_server_with_ssh(self, mock__generate_random_name):
self.clients("nova").servers.create.return_value = self.server self.clients("nova").servers.create.return_value = self.server
nova_scenario = utils.NovaScenario(context={ nova_scenario = utils.NovaScenario(context={
"user": {"secgroup": {"name": "test"}}} "user": {
"secgroup": {"name": "test"},
"endpoint": mock.MagicMock()
}}
) )
return_server = nova_scenario._boot_server("image_id", "flavor_id") return_server = nova_scenario._boot_server("image_id", "flavor_id")
self.mock_wait_for.mock.assert_called_once_with( self.mock_wait_for.mock.assert_called_once_with(
@@ -132,8 +135,11 @@ class NovaScenarioTestCase(test.ScenarioTestCase):
def test__boot_server_with_sec_group(self, mock__generate_random_name): def test__boot_server_with_sec_group(self, mock__generate_random_name):
self.clients("nova").servers.create.return_value = self.server self.clients("nova").servers.create.return_value = self.server
nova_scenario = utils.NovaScenario(context={ nova_scenario = utils.NovaScenario(context={
"user": {"secgroup": {"name": "new"}}} "user": {
) "secgroup": {"name": "new"},
"endpoint": mock.MagicMock()
}
})
return_server = nova_scenario._boot_server( return_server = nova_scenario._boot_server(
"image_id", "flavor_id", "image_id", "flavor_id",
security_groups=["test"]) security_groups=["test"])
@@ -158,7 +164,10 @@ class NovaScenarioTestCase(test.ScenarioTestCase):
mock__generate_random_name): mock__generate_random_name):
self.clients("nova").servers.create.return_value = self.server self.clients("nova").servers.create.return_value = self.server
nova_scenario = utils.NovaScenario(context={ nova_scenario = utils.NovaScenario(context={
"user": {"secgroup": {"name": "test1"}}} "user": {
"secgroup": {"name": "test1"},
"endpoint": mock.MagicMock()
}}
) )
return_server = nova_scenario._boot_server( return_server = nova_scenario._boot_server(
"image_id", "flavor_id", "image_id", "flavor_id",

View File

@@ -24,7 +24,10 @@ class QuotasTestCase(test.ScenarioTestCase):
def setUp(self): def setUp(self):
super(QuotasTestCase, self).setUp() super(QuotasTestCase, self).setUp()
self.context = { self.context = {
"user": {"tenant_id": "fake"}, "user": {
"tenant_id": "fake",
"endpoint": mock.MagicMock()
},
"tenant": {"id": "fake"} "tenant": {"id": "fake"}
} }

View File

@@ -138,10 +138,11 @@ class SaharaScenarioTestCase(test.ScenarioTestCase):
} }
} }
clients = mock.Mock(services=mock.Mock( self.clients("services").values.return_value = [
return_value={"neutron": consts.Service.NEUTRON})) consts.Service.NEUTRON
scenario = utils.SaharaScenario(context=context, ]
clients=clients)
scenario = utils.SaharaScenario(context=context)
mock_processes = { mock_processes = {
"test_plugin": { "test_plugin": {
@@ -231,7 +232,7 @@ class SaharaScenarioTestCase(test.ScenarioTestCase):
def test_launch_cluster_error(self, mock_sahara_consts, def test_launch_cluster_error(self, mock_sahara_consts,
mock__generate_random_name): mock__generate_random_name):
scenario = utils.SaharaScenario(clients=mock.MagicMock()) scenario = utils.SaharaScenario()
mock_processes = { mock_processes = {
"test_plugin": { "test_plugin": {
"test_version": { "test_version": {

View File

@@ -27,7 +27,9 @@ class VMTasksTestCase(test.TestCase):
def setUp(self): def setUp(self):
super(VMTasksTestCase, self).setUp() super(VMTasksTestCase, self).setUp()
self.scenario = vmtasks.VMTasks( self.scenario = vmtasks.VMTasks(
context={"user": {"keypair": {"name": "keypair_name"}}}) context={"user": {"keypair": {"name": "keypair_name"},
"endpoint": mock.MagicMock()}}
)
self.ip = {"id": "foo_id", "ip": "foo_ip", "is_floating": True} self.ip = {"id": "foo_id", "ip": "foo_ip", "is_floating": True}
self.scenario._boot_server_with_fip = mock.Mock( self.scenario._boot_server_with_fip = mock.Mock(
return_value=("foo_server", self.ip)) return_value=("foo_server", self.ip))

View File

@@ -252,20 +252,6 @@ class ScenarioTestCase(test.TestCase):
scenario = base.Scenario(context=ctx) scenario = base.Scenario(context=ctx)
self.assertEqual(ctx, scenario.context) self.assertEqual(ctx, scenario.context)
def test_clients(self):
clients = fakes.FakeClients()
scenario = base.Scenario(clients=clients)
self.assertEqual(clients.nova(), scenario.clients("nova"))
self.assertEqual(clients.glance(), scenario.clients("glance"))
def test_admin_clients(self):
clients = fakes.FakeClients()
scenario = base.Scenario(admin_clients=clients)
self.assertEqual(clients.nova(), scenario.admin_clients("nova"))
self.assertEqual(clients.glance(), scenario.admin_clients("glance"))
def test_scenario_context_are_valid(self): def test_scenario_context_are_valid(self):
scenarios = base.Scenario.list_benchmark_scenarios() scenarios = base.Scenario.list_benchmark_scenarios()

View File

@@ -79,10 +79,7 @@ class ScenarioHelpersTestCase(test.TestCase):
self.assertEqual(expected_context, self.assertEqual(expected_context,
runner._get_scenario_context(context)) runner._get_scenario_context(context))
@mock.patch(BASE + "osclients") def test_run_scenario_once_internal_logic(self):
def test_run_scenario_once_internal_logic(self, mock_osclients):
mock_osclients.Clients.return_value = "cl"
context = runner._get_scenario_context( context = runner._get_scenario_context(
fakes.FakeUserContext({}).context) fakes.FakeUserContext({}).context)
scenario_cls = mock.MagicMock() scenario_cls = mock.MagicMock()
@@ -90,7 +87,7 @@ class ScenarioHelpersTestCase(test.TestCase):
runner._run_scenario_once(args) runner._run_scenario_once(args)
expected_calls = [ expected_calls = [
mock.call(context=context, admin_clients="cl", clients="cl"), mock.call(context=context),
mock.call().test(), mock.call().test(),
mock.call().idle_duration(), mock.call().idle_duration(),
mock.call().idle_duration(), mock.call().idle_duration(),
@@ -99,9 +96,7 @@ class ScenarioHelpersTestCase(test.TestCase):
scenario_cls.assert_has_calls(expected_calls, any_order=True) scenario_cls.assert_has_calls(expected_calls, any_order=True)
@mock.patch(BASE + "rutils.Timer", side_effect=fakes.FakeTimer) @mock.patch(BASE + "rutils.Timer", side_effect=fakes.FakeTimer)
@mock.patch(BASE + "osclients") def test_run_scenario_once_without_scenario_output(self, mock_timer):
def test_run_scenario_once_without_scenario_output(self, mock_osclients,
mock_timer):
context = runner._get_scenario_context( context = runner._get_scenario_context(
fakes.FakeUserContext({}).context) fakes.FakeUserContext({}).context)
args = (1, fakes.FakeScenario, "do_it", context, {}) args = (1, fakes.FakeScenario, "do_it", context, {})
@@ -118,9 +113,7 @@ class ScenarioHelpersTestCase(test.TestCase):
self.assertEqual(expected_result, result) self.assertEqual(expected_result, result)
@mock.patch(BASE + "rutils.Timer", side_effect=fakes.FakeTimer) @mock.patch(BASE + "rutils.Timer", side_effect=fakes.FakeTimer)
@mock.patch(BASE + "osclients") def test_run_scenario_once_with_scenario_output(self, mock_timer):
def test_run_scenario_once_with_scenario_output(self, mock_osclients,
mock_timer):
context = runner._get_scenario_context( context = runner._get_scenario_context(
fakes.FakeUserContext({}).context) fakes.FakeUserContext({}).context)
args = (1, fakes.FakeScenario, "with_output", context, {}) args = (1, fakes.FakeScenario, "with_output", context, {})
@@ -137,8 +130,7 @@ class ScenarioHelpersTestCase(test.TestCase):
self.assertEqual(expected_result, result) self.assertEqual(expected_result, result)
@mock.patch(BASE + "rutils.Timer", side_effect=fakes.FakeTimer) @mock.patch(BASE + "rutils.Timer", side_effect=fakes.FakeTimer)
@mock.patch(BASE + "osclients") def test_run_scenario_once_exception(self, mock_timer):
def test_run_scenario_once_exception(self, mock_osclients, mock_timer):
context = runner._get_scenario_context( context = runner._get_scenario_context(
fakes.FakeUserContext({}).context) fakes.FakeUserContext({}).context)
args = (1, fakes.FakeScenario, "something_went_wrong", context, {}) args = (1, fakes.FakeScenario, "something_went_wrong", context, {})