Merge "Remove osclients from runner and scenario signature"
This commit is contained in:
@@ -16,7 +16,6 @@ from rally.common.i18n import _
|
||||
from rally.common import log as logging
|
||||
from rally.common import utils as rutils
|
||||
from rally import consts
|
||||
from rally import osclients
|
||||
from rally.plugins.openstack.scenarios.ceilometer import utils as ceilo_utils
|
||||
from rally.task import context
|
||||
|
||||
@@ -70,26 +69,20 @@ class CeilometerSampleGenerator(context.Context):
|
||||
counter_type = self.config["counter_type"]
|
||||
counter_unit = self.config["counter_unit"]
|
||||
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(
|
||||
self.context["users"]):
|
||||
self.context["tenants"][tenant_id]["samples"] = []
|
||||
self.context["tenants"][tenant_id]["resources"] = []
|
||||
clients = osclients.Clients(user["endpoint"])
|
||||
scenario = ceilo_utils.CeilometerScenario(
|
||||
clients=clients)
|
||||
for i in range(resources_per_tenant):
|
||||
for j in range(samples_per_resource):
|
||||
try:
|
||||
sample = scenario._create_sample(counter_name,
|
||||
counter_type,
|
||||
counter_unit,
|
||||
counter_volume)
|
||||
self.context["tenants"][tenant_id]["samples"].append(
|
||||
sample[0].to_dict())
|
||||
except Exception as err:
|
||||
LOG.error("Creating a sample failed: %s" % err)
|
||||
scenario = ceilo_utils.CeilometerScenario({"user": user})
|
||||
for i in range(self.config["resources_per_tenant"]):
|
||||
for j in range(self.config["samples_per_resource"]):
|
||||
sample = scenario._create_sample(counter_name,
|
||||
counter_type,
|
||||
counter_unit,
|
||||
counter_volume)
|
||||
self.context["tenants"][tenant_id]["samples"].append(
|
||||
sample[0].to_dict())
|
||||
|
||||
self.context["tenants"][tenant_id]["resources"].append(
|
||||
sample[0].resource_id)
|
||||
|
||||
|
@@ -16,7 +16,6 @@ from rally.common.i18n import _
|
||||
from rally.common import log as logging
|
||||
from rally.common import utils as rutils
|
||||
from rally import consts
|
||||
from rally import osclients
|
||||
from rally.plugins.openstack.context.cleanup import manager as resource_manager
|
||||
from rally.plugins.openstack.scenarios.glance import utils as glance_utils
|
||||
from rally.task import context
|
||||
@@ -78,9 +77,7 @@ class ImageGenerator(context.Context):
|
||||
for user, tenant_id in rutils.iterate_per_tenants(
|
||||
self.context["users"]):
|
||||
current_images = []
|
||||
clients = osclients.Clients(user["endpoint"])
|
||||
glance_scenario = glance_utils.GlanceScenario(
|
||||
clients=clients)
|
||||
glance_scenario = glance_utils.GlanceScenario({"user": user})
|
||||
for i in range(images_per_tenant):
|
||||
if image_name and i > 0:
|
||||
cur_name = image_name + str(i)
|
||||
|
@@ -20,7 +20,6 @@ from rally.common import log as logging
|
||||
from rally.common import utils as rutils
|
||||
from rally import consts
|
||||
from rally import exceptions
|
||||
from rally import osclients
|
||||
from rally.plugins.openstack.context.cleanup import manager as resource_manager
|
||||
from rally.plugins.openstack.scenarios.sahara import utils
|
||||
from rally.task import context
|
||||
@@ -97,36 +96,40 @@ class SaharaCluster(context.Context):
|
||||
|
||||
for user, tenant_id in rutils.iterate_per_tenants(
|
||||
self.context["users"]):
|
||||
clients = osclients.Clients(user["endpoint"])
|
||||
|
||||
image_id = self.context["tenants"][tenant_id]["sahara_image"]
|
||||
|
||||
floating_ip_pool = self.config.get("floating_ip_pool")
|
||||
|
||||
temporary_context = {"tenant": self.context["tenants"][tenant_id]}
|
||||
cluster = utils.SaharaScenario(
|
||||
context=temporary_context, clients=clients)._launch_cluster(
|
||||
plugin_name=self.config["plugin_name"],
|
||||
hadoop_version=self.config["hadoop_version"],
|
||||
flavor_id=self.config["flavor_id"],
|
||||
workers_count=self.config["workers_count"],
|
||||
image_id=image_id,
|
||||
floating_ip_pool=floating_ip_pool,
|
||||
volumes_per_node=self.config.get("volumes_per_node"),
|
||||
volumes_size=self.config.get("volumes_size", 1),
|
||||
auto_security_group=self.config.get("auto_security_group",
|
||||
True),
|
||||
security_groups=self.config.get("security_groups"),
|
||||
node_configs=self.config.get("node_configs"),
|
||||
cluster_configs=self.config.get("cluster_configs"),
|
||||
enable_anti_affinity=self.config.get(
|
||||
"enable_anti_affinity", False),
|
||||
wait_active=False)
|
||||
temporary_context = {
|
||||
"user": user,
|
||||
"tenant": self.context["tenants"][tenant_id]
|
||||
}
|
||||
scenario = utils.SaharaScenario(context=temporary_context)
|
||||
|
||||
cluster = scenario._launch_cluster(
|
||||
plugin_name=self.config["plugin_name"],
|
||||
hadoop_version=self.config["hadoop_version"],
|
||||
flavor_id=self.config["flavor_id"],
|
||||
workers_count=self.config["workers_count"],
|
||||
image_id=image_id,
|
||||
floating_ip_pool=floating_ip_pool,
|
||||
volumes_per_node=self.config.get("volumes_per_node"),
|
||||
volumes_size=self.config.get("volumes_size", 1),
|
||||
auto_security_group=self.config.get("auto_security_group",
|
||||
True),
|
||||
security_groups=self.config.get("security_groups"),
|
||||
node_configs=self.config.get("node_configs"),
|
||||
cluster_configs=self.config.get("cluster_configs"),
|
||||
enable_anti_affinity=self.config.get("enable_anti_affinity",
|
||||
False),
|
||||
wait_active=False
|
||||
)
|
||||
|
||||
self.context["tenants"][tenant_id]["sahara_cluster"] = cluster.id
|
||||
|
||||
# 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(
|
||||
resource=wait_dict,
|
||||
|
@@ -64,19 +64,16 @@ class SaharaImage(context.Context):
|
||||
|
||||
def _create_image(self, hadoop_version, image_url, plugin_name, user,
|
||||
user_name):
|
||||
clients = osclients.Clients(user["endpoint"])
|
||||
scenario = glance_utils.GlanceScenario(clients=clients)
|
||||
scenario = glance_utils.GlanceScenario({"user": user})
|
||||
image_name = rutils.generate_random_name(prefix="rally_sahara_image_")
|
||||
image = scenario._create_image(name=image_name,
|
||||
container_format="bare",
|
||||
image_location=image_url,
|
||||
disk_format="qcow2")
|
||||
clients.sahara().images.update_image(image_id=image.id,
|
||||
user_name=user_name,
|
||||
desc="")
|
||||
clients.sahara().images.update_tags(image_id=image.id,
|
||||
new_tags=[plugin_name,
|
||||
hadoop_version])
|
||||
scenario.clients("sahara").images.update_image(
|
||||
image_id=image.id, user_name=user_name, desc="")
|
||||
scenario.clients("sahara").images.update_tags(
|
||||
image_id=image.id, new_tags=[plugin_name, hadoop_version])
|
||||
return image.id
|
||||
|
||||
@rutils.log_task_wrapper(LOG.info, _("Enter context: `Sahara Image`"))
|
||||
|
@@ -82,8 +82,7 @@ class ServerGenerator(context.Context):
|
||||
self.context["users"]):
|
||||
LOG.debug("Booting servers for user tenant %s "
|
||||
% (user["tenant_id"]))
|
||||
clients = osclients.Clients(user["endpoint"])
|
||||
nova_scenario = nova_utils.NovaScenario(clients=clients)
|
||||
nova_scenario = nova_utils.NovaScenario({"user": user})
|
||||
|
||||
LOG.debug("Calling _boot_servers with image_id=%(image_id)s "
|
||||
"flavor_id=%(flavor_id)s "
|
||||
|
@@ -17,7 +17,6 @@ from rally.common.i18n import _
|
||||
from rally.common import log as logging
|
||||
from rally.common import utils as rutils
|
||||
from rally import consts
|
||||
from rally import osclients
|
||||
from rally.plugins.openstack.context.cleanup import manager as resource_manager
|
||||
from rally.plugins.openstack.scenarios.heat import utils as heat_utils
|
||||
from rally.task import context
|
||||
@@ -77,8 +76,7 @@ class StackGenerator(context.Context):
|
||||
self.config["resources_per_stack"])
|
||||
for user, tenant_id in rutils.iterate_per_tenants(
|
||||
self.context["users"]):
|
||||
heat_scenario = heat_utils.HeatScenario(
|
||||
clients=osclients.Clients(user["endpoint"]))
|
||||
heat_scenario = heat_utils.HeatScenario({"user": user})
|
||||
self.context["tenants"][tenant_id]["stacks"] = []
|
||||
for i in range(self.config["stacks_per_tenant"]):
|
||||
stack = heat_scenario._create_stack(template)
|
||||
|
@@ -16,7 +16,6 @@ from rally.common.i18n import _
|
||||
from rally.common import log as logging
|
||||
from rally.common import utils as rutils
|
||||
from rally import consts
|
||||
from rally import osclients
|
||||
from rally.plugins.openstack.context.cleanup import manager as resource_manager
|
||||
from rally.plugins.openstack.scenarios.cinder import utils as cinder_utils
|
||||
from rally.task import context
|
||||
@@ -59,8 +58,7 @@ class VolumeGenerator(context.Context):
|
||||
for user, tenant_id in rutils.iterate_per_tenants(
|
||||
self.context["users"]):
|
||||
self.context["tenants"][tenant_id].setdefault("volumes", [])
|
||||
clients = osclients.Clients(user["endpoint"])
|
||||
cinder_util = cinder_utils.CinderScenario(clients=clients)
|
||||
cinder_util = cinder_utils.CinderScenario({"user": user})
|
||||
for i in range(volumes_per_tenant):
|
||||
rnd_name = scenario_base.Scenario._generate_random_name(
|
||||
prefix="ctx_rally_volume_")
|
||||
|
@@ -155,7 +155,7 @@ class SaharaScenario(base.Scenario):
|
||||
return None
|
||||
|
||||
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.")
|
||||
floating_ip_pool_value = self._setup_neutron_floating_ip_pool(
|
||||
floating_ip_pool)
|
||||
@@ -504,7 +504,7 @@ class SaharaScenario(base.Scenario):
|
||||
: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
|
||||
|
||||
# Taking net id from context.
|
||||
|
@@ -26,7 +26,6 @@ from rally.common import log as logging
|
||||
from rally.common.plugin import plugin
|
||||
from rally.common import utils as rutils
|
||||
from rally import consts
|
||||
from rally import osclients
|
||||
from rally.task.scenarios import base as scenario_base
|
||||
from rally.task import types
|
||||
from rally.task import utils
|
||||
@@ -66,10 +65,7 @@ def _run_scenario_once(args):
|
||||
{"task": context["task"]["uuid"], "iteration": iteration})
|
||||
|
||||
context["iteration"] = iteration
|
||||
scenario = cls(
|
||||
context=context,
|
||||
admin_clients=osclients.Clients(context["admin"]["endpoint"]),
|
||||
clients=osclients.Clients(context["user"]["endpoint"]))
|
||||
scenario = cls(context=context)
|
||||
|
||||
error = []
|
||||
scenario_output = {"errors": "", "data": {}}
|
||||
|
@@ -25,6 +25,7 @@ from rally.common.plugin import discover
|
||||
from rally.common import utils
|
||||
from rally import consts
|
||||
from rally import exceptions
|
||||
from rally import osclients
|
||||
from rally.task import functional
|
||||
|
||||
|
||||
@@ -56,10 +57,18 @@ class Scenario(functional.FunctionalMixin):
|
||||
RESOURCE_NAME_PREFIX = "rally_"
|
||||
RESOURCE_NAME_LENGTH = 10
|
||||
|
||||
def __init__(self, context=None, admin_clients=None, clients=None):
|
||||
def __init__(self, context=None):
|
||||
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._atomic_actions = costilius.OrderedDict()
|
||||
|
||||
|
@@ -20,9 +20,8 @@ from tests.unit import test
|
||||
|
||||
class CinderQuotasTestCase(test.TestCase):
|
||||
|
||||
@mock.patch("rally.plugins.openstack.context."
|
||||
"quotas.quotas.osclients.Clients")
|
||||
def test_update(self, mock_clients):
|
||||
def test_update(self):
|
||||
mock_clients = mock.MagicMock()
|
||||
cinder_quo = cinder_quotas.CinderQuotas(mock_clients)
|
||||
tenant_id = mock.MagicMock()
|
||||
quotas_values = {
|
||||
@@ -34,9 +33,8 @@ class CinderQuotasTestCase(test.TestCase):
|
||||
mock_clients.cinder().quotas.update.assert_called_once_with(
|
||||
tenant_id, **quotas_values)
|
||||
|
||||
@mock.patch("rally.plugins.openstack.context."
|
||||
"quotas.quotas.osclients.Clients")
|
||||
def test_delete(self, mock_clients):
|
||||
def test_delete(self):
|
||||
mock_clients = mock.MagicMock()
|
||||
cinder_quo = cinder_quotas.CinderQuotas(mock_clients)
|
||||
tenant_id = mock.MagicMock()
|
||||
cinder_quo.delete(tenant_id)
|
||||
|
@@ -24,7 +24,9 @@ CONF = cfg.CONF
|
||||
CTX = "rally.plugins.openstack.context.sahara"
|
||||
|
||||
|
||||
class SaharaClusterTestCase(test.TestCase):
|
||||
class SaharaClusterTestCase(test.ScenarioTestCase):
|
||||
|
||||
patch_benchmark_utils = False
|
||||
|
||||
def setUp(self):
|
||||
super(SaharaClusterTestCase, self).setUp()
|
||||
@@ -42,7 +44,7 @@ class SaharaClusterTestCase(test.TestCase):
|
||||
for j in range(self.users_per_tenant):
|
||||
self.users_key.append({"id": "%s_%s" % (str(i), str(j)),
|
||||
"tenant_id": str(i),
|
||||
"endpoint": "endpoint"})
|
||||
"endpoint": mock.MagicMock()})
|
||||
|
||||
CONF.set_override("cluster_check_interval", 0, "benchmark")
|
||||
|
||||
@@ -52,7 +54,7 @@ class SaharaClusterTestCase(test.TestCase):
|
||||
"config": {
|
||||
"users": {
|
||||
"tenants": self.tenants_num,
|
||||
"users_per_tenant": self.users_per_tenant,
|
||||
"users_per_tenant": self.users_per_tenant
|
||||
},
|
||||
"sahara_cluster": {
|
||||
"flavor_id": "test_flavor",
|
||||
@@ -70,12 +72,8 @@ class SaharaClusterTestCase(test.TestCase):
|
||||
@mock.patch("%s.sahara_cluster.resource_manager.cleanup" % CTX)
|
||||
@mock.patch("%s.sahara_cluster.utils.SaharaScenario._launch_cluster" % CTX,
|
||||
return_value=mock.MagicMock(id=42))
|
||||
@mock.patch("%s.sahara_cluster.osclients" % CTX)
|
||||
def test_setup_and_cleanup(
|
||||
self, mock_osclients, mock_sahara_scenario__launch_cluster,
|
||||
mock_cleanup):
|
||||
|
||||
mock_sahara = mock_osclients.Clients(mock.MagicMock()).sahara()
|
||||
def test_setup_and_cleanup(self, mock_sahara_scenario__launch_cluster,
|
||||
mock_cleanup):
|
||||
|
||||
ctx = self.context_without_cluster_keys
|
||||
sahara_ctx = sahara_cluster.SaharaCluster(ctx)
|
||||
@@ -100,7 +98,7 @@ class SaharaClusterTestCase(test.TestCase):
|
||||
wait_active=False
|
||||
))
|
||||
|
||||
mock_sahara.clusters.get.side_effect = [
|
||||
self.clients("sahara").clusters.get.side_effect = [
|
||||
mock.MagicMock(status="not-active"),
|
||||
mock.MagicMock(status="active")]
|
||||
sahara_ctx.setup()
|
||||
@@ -113,11 +111,8 @@ class SaharaClusterTestCase(test.TestCase):
|
||||
|
||||
@mock.patch("%s.sahara_cluster.utils.SaharaScenario._launch_cluster" % CTX,
|
||||
return_value=mock.MagicMock(id=42))
|
||||
@mock.patch("%s.sahara_cluster.osclients" % CTX)
|
||||
def test_setup_and_cleanup_error(
|
||||
self, mock_osclients, mock_sahara_scenario__launch_cluster):
|
||||
|
||||
mock_sahara = mock_osclients.Clients(mock.MagicMock()).sahara()
|
||||
def test_setup_and_cleanup_error(self,
|
||||
mock_sahara_scenario__launch_cluster):
|
||||
|
||||
ctx = self.context_without_cluster_keys
|
||||
sahara_ctx = sahara_cluster.SaharaCluster(ctx)
|
||||
@@ -141,8 +136,9 @@ class SaharaClusterTestCase(test.TestCase):
|
||||
wait_active=False
|
||||
))
|
||||
|
||||
mock_sahara.clusters.get.side_effect = [
|
||||
self.clients("sahara").clusters.get.side_effect = [
|
||||
mock.MagicMock(status="not-active"),
|
||||
mock.MagicMock(status="error")]
|
||||
mock.MagicMock(status="error")
|
||||
]
|
||||
|
||||
self.assertRaises(exceptions.SaharaClusterFailure, sahara_ctx.setup)
|
||||
|
@@ -25,7 +25,7 @@ BASE_SCN = "rally.task.scenarios"
|
||||
SCN = "rally.plugins.openstack.scenarios"
|
||||
|
||||
|
||||
class SaharaImageTestCase(test.TestCase):
|
||||
class SaharaImageTestCase(test.ScenarioTestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(SaharaImageTestCase, self).setUp()
|
||||
@@ -42,7 +42,7 @@ class SaharaImageTestCase(test.TestCase):
|
||||
for j in range(self.users_per_tenant):
|
||||
self.users_key.append({"id": "%s_%s" % (str(i), str(j)),
|
||||
"tenant_id": str(i),
|
||||
"endpoint": "endpoint"})
|
||||
"endpoint": mock.MagicMock()})
|
||||
|
||||
@property
|
||||
def url_image_context(self):
|
||||
@@ -87,11 +87,10 @@ class SaharaImageTestCase(test.TestCase):
|
||||
return_value="sahara_image_42")
|
||||
@mock.patch("%s.glance.utils.GlanceScenario._create_image" % SCN,
|
||||
return_value=mock.MagicMock(id=42))
|
||||
@mock.patch("%s.osclients" % CTX)
|
||||
@mock.patch("%s.resource_manager.cleanup" % CTX)
|
||||
def test_setup_and_cleanup_url_image(
|
||||
self, mock_cleanup, mock_osclients,
|
||||
mock_glance_scenario__create_image, mock_generate_random_name):
|
||||
def test_setup_and_cleanup_url_image(self, mock_cleanup,
|
||||
mock_glance_scenario__create_image,
|
||||
mock_generate_random_name):
|
||||
|
||||
ctx = self.url_image_context
|
||||
sahara_ctx = sahara_image.SaharaImage(ctx)
|
||||
@@ -117,11 +116,9 @@ class SaharaImageTestCase(test.TestCase):
|
||||
|
||||
sahara_ctx.setup()
|
||||
mock_glance_scenario__create_image.assert_has_calls(glance_calls)
|
||||
mock_osclients.Clients(
|
||||
mock.MagicMock()).sahara().images.update_image.assert_has_calls(
|
||||
self.clients("sahara").images.update_image.assert_has_calls(
|
||||
sahara_update_image_calls)
|
||||
mock_osclients.Clients(
|
||||
mock.MagicMock()).sahara().images.update_tags.assert_has_calls(
|
||||
self.clients("sahara").images.update_tags.assert_has_calls(
|
||||
sahara_update_tags_calls)
|
||||
|
||||
sahara_ctx.cleanup()
|
||||
@@ -131,13 +128,12 @@ class SaharaImageTestCase(test.TestCase):
|
||||
@mock.patch("%s.glance.utils.GlanceScenario._create_image" % SCN,
|
||||
return_value=mock.MagicMock(id=42))
|
||||
@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(
|
||||
self, mock_osclients, mock_cleanup,
|
||||
self, mock_clients, mock_cleanup,
|
||||
mock_glance_scenario__create_image):
|
||||
|
||||
clients = mock_osclients.Clients(mock.MagicMock())
|
||||
clients.glance().images.get.return_value = mock.MagicMock(
|
||||
mock_clients.glance.images.get.return_value = mock.MagicMock(
|
||||
is_public=True)
|
||||
|
||||
ctx = self.existing_image_context
|
||||
@@ -153,25 +149,24 @@ class SaharaImageTestCase(test.TestCase):
|
||||
sahara_ctx.cleanup()
|
||||
self.assertEqual(False, mock_cleanup.called)
|
||||
|
||||
@mock.patch("%s.osclients" % CTX)
|
||||
def test_check_existing_image(self, mock_osclients):
|
||||
@mock.patch("%s.osclients.Clients.glance" % CTX)
|
||||
def test_check_existing_image(self, mock_clients_glance):
|
||||
|
||||
ctx = self.existing_image_context
|
||||
sahara_ctx = sahara_image.SaharaImage(ctx)
|
||||
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)
|
||||
def test_check_existing_image_fail(self, mock_osclients):
|
||||
@mock.patch("%s.osclients.Clients.glance" % CTX)
|
||||
def test_check_existing_private_image_fail(self, mock_clients_glance):
|
||||
|
||||
clients = mock_osclients.Clients(mock.MagicMock())
|
||||
clients.glance().images.get.return_value = mock.MagicMock(
|
||||
is_public=False)
|
||||
mock_clients_glance.return_value.images.get.return_value = (
|
||||
mock.MagicMock(is_public=False))
|
||||
|
||||
ctx = self.existing_image_context
|
||||
sahara_ctx = sahara_image.SaharaImage(ctx)
|
||||
self.assertRaises(exceptions.BenchmarkSetupFailure,
|
||||
sahara_ctx.setup)
|
||||
|
||||
clients.glance().images.get.asser_called_once_with("some_id")
|
||||
mock_clients_glance.images.get.asser_called_once_with("some_id")
|
||||
|
@@ -18,7 +18,6 @@ import copy
|
||||
import mock
|
||||
|
||||
from rally.plugins.openstack.context import ceilometer
|
||||
from tests.unit import fakes
|
||||
from tests.unit import test
|
||||
|
||||
CTX = "rally.plugins.openstack.context"
|
||||
@@ -29,8 +28,8 @@ class CeilometerSampleGeneratorTestCase(test.TestCase):
|
||||
|
||||
def _gen_tenants(self, count):
|
||||
tenants = {}
|
||||
for id in range(count):
|
||||
tenants[str(id)] = dict(name=str(id))
|
||||
for id_ in range(count):
|
||||
tenants[str(id_)] = {"name": str(id_)}
|
||||
return tenants
|
||||
|
||||
def _gen_context(self, tenants_count, users_per_tenant,
|
||||
@@ -40,7 +39,7 @@ class CeilometerSampleGeneratorTestCase(test.TestCase):
|
||||
for id_ in tenants.keys():
|
||||
for i in range(users_per_tenant):
|
||||
users.append({"id": i, "tenant_id": id_,
|
||||
"endpoint": "endpoint"})
|
||||
"endpoint": mock.MagicMock()})
|
||||
context = {
|
||||
"config": {
|
||||
"users": {
|
||||
@@ -83,41 +82,44 @@ class CeilometerSampleGeneratorTestCase(test.TestCase):
|
||||
inst = ceilometer.CeilometerSampleGenerator(context)
|
||||
self.assertEqual(inst.config, context["config"]["ceilometer"])
|
||||
|
||||
@mock.patch("%s.ceilometer.osclients" % CTX)
|
||||
def test_setup(self, mock_osclients):
|
||||
fc = fakes.FakeClients()
|
||||
mock_osclients.Clients.return_value = fc
|
||||
|
||||
@mock.patch("%s.ceilometer.ceilo_utils.CeilometerScenario._create_sample"
|
||||
% CTX)
|
||||
def test_setup(self, mock_ceilometer_scenario__create_sample):
|
||||
tenants_count = 2
|
||||
users_per_tenant = 5
|
||||
resources_per_tenant = 5
|
||||
samples_per_resource = 5
|
||||
users_per_tenant = 2
|
||||
resources_per_tenant = 2
|
||||
samples_per_resource = 2
|
||||
|
||||
tenants, real_context = self._gen_context(
|
||||
tenants_count, users_per_tenant,
|
||||
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)
|
||||
for id_ in tenants.keys():
|
||||
new_context["tenants"][id_].setdefault("samples", [])
|
||||
new_context["tenants"][id_].setdefault("resources", [])
|
||||
for i in range(resources_per_tenant):
|
||||
for j in range(samples_per_resource):
|
||||
new_context["tenants"][id_]["samples"].append(
|
||||
{"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_]["samples"].append(sample)
|
||||
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.setup()
|
||||
self.assertEqual(new_context, ceilometer_ctx.context)
|
||||
|
||||
@mock.patch("%s.ceilometer.osclients" % CTX)
|
||||
def test_cleanup(self, mock_osclients):
|
||||
def test_cleanup(self):
|
||||
tenants, context = self._gen_context(2, 5, 3, 3)
|
||||
ceilometer_ctx = ceilometer.CeilometerSampleGenerator(context)
|
||||
ceilometer_ctx.cleanup()
|
||||
|
@@ -26,12 +26,12 @@ CTX = "rally.plugins.openstack.context"
|
||||
SCN = "rally.plugins.openstack.scenarios"
|
||||
|
||||
|
||||
class ImageGeneratorTestCase(test.TestCase):
|
||||
class ImageGeneratorTestCase(test.ScenarioTestCase):
|
||||
|
||||
def _gen_tenants(self, count):
|
||||
tenants = {}
|
||||
for id_ in range(count):
|
||||
tenants[str(id_)] = dict(name=str(id_))
|
||||
tenants[str(id_)] = {"name": str(id_)}
|
||||
return tenants
|
||||
|
||||
@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,
|
||||
return_value=fakes.FakeImage(id="uuid"))
|
||||
@mock.patch("%s.images.osclients" % CTX)
|
||||
def test_setup(self, mock_osclients, mock_glance_scenario__create_image):
|
||||
def test_setup(self, mock_glance_scenario__create_image):
|
||||
|
||||
tenants_count = 2
|
||||
users_per_tenant = 5
|
||||
images_per_tenant = 5
|
||||
|
||||
fc = fakes.FakeClients()
|
||||
mock_osclients.Clients.return_value = fc
|
||||
|
||||
tenants = self._gen_tenants(tenants_count)
|
||||
users = []
|
||||
for id in tenants:
|
||||
for i in range(users_per_tenant):
|
||||
users.append({"id": i, "tenant_id": id,
|
||||
"endpoint": "endpoint"})
|
||||
"endpoint": mock.MagicMock()})
|
||||
|
||||
real_context = {
|
||||
"config": {
|
||||
@@ -119,9 +115,8 @@ class ImageGeneratorTestCase(test.TestCase):
|
||||
images_ctx.setup()
|
||||
self.assertEqual(new_context, real_context)
|
||||
|
||||
@mock.patch("%s.images.osclients" % 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
|
||||
users_per_tenant = 5
|
||||
|
@@ -26,12 +26,12 @@ SCN = "rally.plugins.openstack.scenarios"
|
||||
TYP = "rally.task.types"
|
||||
|
||||
|
||||
class ServerGeneratorTestCase(test.TestCase):
|
||||
class ServerGeneratorTestCase(test.ScenarioTestCase):
|
||||
|
||||
def _gen_tenants(self, count):
|
||||
tenants = {}
|
||||
for id in range(count):
|
||||
tenants[str(id)] = dict(name=str(id))
|
||||
for id_ in range(count):
|
||||
tenants[str(id_)] = {"name": str(id_)}
|
||||
return tenants
|
||||
|
||||
def test_init(self):
|
||||
@@ -75,7 +75,7 @@ class ServerGeneratorTestCase(test.TestCase):
|
||||
for id in tenants.keys():
|
||||
for i in range(users_per_tenant):
|
||||
users.append({"id": i, "tenant_id": id,
|
||||
"endpoint": "endpoint"})
|
||||
"endpoint": mock.MagicMock()})
|
||||
|
||||
real_context = {
|
||||
"config": {
|
||||
@@ -103,10 +103,10 @@ class ServerGeneratorTestCase(test.TestCase):
|
||||
}
|
||||
|
||||
new_context = copy.deepcopy(real_context)
|
||||
for id in new_context["tenants"]:
|
||||
new_context["tenants"][id].setdefault("servers", [])
|
||||
for id_ in new_context["tenants"]:
|
||||
new_context["tenants"][id_].setdefault("servers", [])
|
||||
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.setup()
|
||||
@@ -122,13 +122,13 @@ class ServerGeneratorTestCase(test.TestCase):
|
||||
|
||||
tenants = self._gen_tenants(tenants_count)
|
||||
users = []
|
||||
for id in tenants.keys():
|
||||
for id_ in tenants.keys():
|
||||
for i in range(users_per_tenant):
|
||||
users.append({"id": i, "tenant_id": id,
|
||||
users.append({"id": i, "tenant_id": id_,
|
||||
"endpoint": "endpoint"})
|
||||
tenants[id].setdefault("servers", [])
|
||||
tenants[id_].setdefault("servers", [])
|
||||
for j in range(servers_per_tenant):
|
||||
tenants[id]["servers"].append("uuid")
|
||||
tenants[id_]["servers"].append("uuid")
|
||||
|
||||
context = {
|
||||
"config": {
|
||||
|
@@ -23,7 +23,7 @@ CTX = "rally.plugins.openstack.context"
|
||||
SCN = "rally.plugins.openstack.scenarios"
|
||||
|
||||
|
||||
class TestStackGenerator(test.TestCase):
|
||||
class TestStackGenerator(test.ScenarioTestCase):
|
||||
|
||||
def _gen_tenants(self, count):
|
||||
tenants = {}
|
||||
@@ -47,21 +47,17 @@ class TestStackGenerator(test.TestCase):
|
||||
|
||||
@mock.patch("%s.heat.utils.HeatScenario._create_stack" % SCN,
|
||||
return_value=fakes.FakeStack(id="uuid"))
|
||||
@mock.patch("%s.stacks.osclients" % CTX)
|
||||
def test_setup(self, mock_osclients, mock_heat_scenario__create_stack):
|
||||
def test_setup(self, mock_heat_scenario__create_stack):
|
||||
tenants_count = 2
|
||||
users_per_tenant = 5
|
||||
stacks_per_tenant = 1
|
||||
|
||||
fc = fakes.FakeClients()
|
||||
mock_osclients.Clients.return_value = fc
|
||||
|
||||
tenants = self._gen_tenants(tenants_count)
|
||||
users = []
|
||||
for ten_id in tenants:
|
||||
for i in range(users_per_tenant):
|
||||
users.append({"id": i, "tenant_id": ten_id,
|
||||
"endpoint": "endpoint"})
|
||||
"endpoint": mock.MagicMock()})
|
||||
|
||||
context = {
|
||||
"config": {
|
||||
|
@@ -25,12 +25,12 @@ CTX = "rally.plugins.openstack.context"
|
||||
SCN = "rally.plugins.openstack.scenarios"
|
||||
|
||||
|
||||
class VolumeGeneratorTestCase(test.TestCase):
|
||||
class VolumeGeneratorTestCase(test.ScenarioTestCase):
|
||||
|
||||
def _gen_tenants(self, count):
|
||||
tenants = {}
|
||||
for id in range(count):
|
||||
tenants[str(id)] = dict(name=str(id))
|
||||
for id_ in range(count):
|
||||
tenants[str(id_)] = {"name": str(id_)}
|
||||
return tenants
|
||||
|
||||
def test_init(self):
|
||||
@@ -48,21 +48,17 @@ class VolumeGeneratorTestCase(test.TestCase):
|
||||
|
||||
@mock.patch("%s.cinder.utils.CinderScenario._create_volume" % SCN,
|
||||
return_value=fakes.FakeVolume(id="uuid"))
|
||||
@mock.patch("%s.volumes.osclients" % CTX)
|
||||
def test_setup(self, mock_osclients, mock_cinder_scenario__create_volume):
|
||||
fc = fakes.FakeClients()
|
||||
mock_osclients.Clients.return_value = fc
|
||||
|
||||
def test_setup(self, mock_cinder_scenario__create_volume):
|
||||
tenants_count = 2
|
||||
users_per_tenant = 5
|
||||
volumes_per_tenant = 5
|
||||
|
||||
tenants = self._gen_tenants(tenants_count)
|
||||
users = []
|
||||
for id in tenants.keys():
|
||||
for id_ in tenants.keys():
|
||||
for i in range(users_per_tenant):
|
||||
users.append({"id": i, "tenant_id": id,
|
||||
"endpoint": "endpoint"})
|
||||
users.append({"id": i, "tenant_id": id_,
|
||||
"endpoint": mock.MagicMock()})
|
||||
|
||||
real_context = {
|
||||
"config": {
|
||||
@@ -73,7 +69,7 @@ class VolumeGeneratorTestCase(test.TestCase):
|
||||
},
|
||||
"volumes": {
|
||||
"size": 1,
|
||||
"volumes_per_tenant": 5,
|
||||
"volumes_per_tenant": volumes_per_tenant,
|
||||
}
|
||||
},
|
||||
"admin": {
|
||||
@@ -85,18 +81,17 @@ class VolumeGeneratorTestCase(test.TestCase):
|
||||
}
|
||||
|
||||
new_context = copy.deepcopy(real_context)
|
||||
for id in tenants.keys():
|
||||
new_context["tenants"][id].setdefault("volumes", [])
|
||||
for id_ in tenants.keys():
|
||||
new_context["tenants"][id_].setdefault("volumes", [])
|
||||
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.setup()
|
||||
self.assertEqual(new_context, real_context)
|
||||
|
||||
@mock.patch("%s.volumes.osclients" % 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
|
||||
users_per_tenant = 5
|
||||
@@ -104,13 +99,13 @@ class VolumeGeneratorTestCase(test.TestCase):
|
||||
|
||||
tenants = self._gen_tenants(tenants_count)
|
||||
users = []
|
||||
for id in tenants.keys():
|
||||
for id_ in tenants.keys():
|
||||
for i in range(users_per_tenant):
|
||||
users.append({"id": i, "tenant_id": id,
|
||||
users.append({"id": i, "tenant_id": id_,
|
||||
"endpoint": "endpoint"})
|
||||
tenants[id].setdefault("volumes", [])
|
||||
tenants[id_].setdefault("volumes", [])
|
||||
for j in range(volumes_per_tenant):
|
||||
tenants[id]["volumes"].append({"id": "uuid"})
|
||||
tenants[id_]["volumes"].append({"id": "uuid"})
|
||||
|
||||
context = {
|
||||
"config": {
|
||||
|
@@ -28,6 +28,13 @@ class fake_type(object):
|
||||
|
||||
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):
|
||||
scenario = volumes.CinderVolumes()
|
||||
scenario._create_volume = mock.MagicMock()
|
||||
@@ -66,10 +73,7 @@ class CinderServersTestCase(test.ScenarioTestCase):
|
||||
scenario._create_volume.assert_called_once_with(1, fakearg="f")
|
||||
|
||||
def test_create_volume_and_modify_metadata(self):
|
||||
scenario = volumes.CinderVolumes(
|
||||
context={"user": {"tenant_id": "fake"},
|
||||
"tenant": {"id": "fake", "name": "fake",
|
||||
"volumes": [{"id": "uuid"}]}})
|
||||
scenario = volumes.CinderVolumes(self._get_context())
|
||||
scenario._set_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):
|
||||
fake_volume = mock.MagicMock()
|
||||
vol_size = 1
|
||||
scenario = volumes.CinderVolumes(
|
||||
context={"user": {"tenant_id": "fake"},
|
||||
"tenant": {"id": "fake", "name": "fake",
|
||||
"volumes": [{"id": "uuid"}]}})
|
||||
scenario = volumes.CinderVolumes(self._get_context())
|
||||
scenario._create_volume = mock.MagicMock(return_value=fake_volume)
|
||||
scenario._delete_volume = mock.MagicMock()
|
||||
|
||||
@@ -143,10 +144,7 @@ class CinderServersTestCase(test.ScenarioTestCase):
|
||||
|
||||
def test_create_and_delete_snapshot(self):
|
||||
fake_snapshot = mock.MagicMock()
|
||||
scenario = volumes.CinderVolumes(
|
||||
context={"user": {"tenant_id": "fake"},
|
||||
"tenant": {"id": "fake", "name": "fake",
|
||||
"volumes": [{"id": "uuid"}]}})
|
||||
scenario = volumes.CinderVolumes(self._get_context())
|
||||
|
||||
scenario._create_snapshot = mock.MagicMock(return_value=fake_snapshot)
|
||||
scenario.sleep_between = mock.MagicMock()
|
||||
@@ -161,10 +159,7 @@ class CinderServersTestCase(test.ScenarioTestCase):
|
||||
|
||||
def test_create_and_list_snapshots(self):
|
||||
fake_snapshot = mock.MagicMock()
|
||||
scenario = volumes.CinderVolumes(
|
||||
context={"user": {"tenant_id": "fake"},
|
||||
"tenant": {"id": "fake", "name": "fake",
|
||||
"volumes": [{"id": "uuid"}]}})
|
||||
scenario = volumes.CinderVolumes(self._get_context())
|
||||
|
||||
scenario._create_snapshot = mock.MagicMock(return_value=fake_snapshot)
|
||||
scenario._list_snapshots = mock.MagicMock()
|
||||
@@ -233,12 +228,7 @@ class CinderServersTestCase(test.ScenarioTestCase):
|
||||
fake_volume = mock.MagicMock()
|
||||
fake_snapshot = 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._detach_volume = mock.MagicMock()
|
||||
@@ -268,11 +258,8 @@ class CinderServersTestCase(test.ScenarioTestCase):
|
||||
fake_volume = mock.MagicMock()
|
||||
fake_snapshot = 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._detach_volume = mock.MagicMock()
|
||||
@@ -308,12 +295,8 @@ class CinderServersTestCase(test.ScenarioTestCase):
|
||||
def test_create_nested_snapshots_and_attach_volume(self):
|
||||
fake_volume = mock.MagicMock()
|
||||
fake_snapshot = mock.MagicMock()
|
||||
fake_server = mock.MagicMock()
|
||||
scenario = volumes.CinderVolumes(
|
||||
context={"user": {"tenant_id": "fake"},
|
||||
"users": [{"tenant_id": "fake", "users_per_tenant": 1}],
|
||||
"tenant": {"id": "fake", "name": "fake",
|
||||
"servers": [fake_server.uuid]}})
|
||||
|
||||
scenario = volumes.CinderVolumes(context=self._get_context())
|
||||
|
||||
scenario._attach_volume = mock.MagicMock()
|
||||
scenario._detach_volume = mock.MagicMock()
|
||||
@@ -338,13 +321,8 @@ class CinderServersTestCase(test.ScenarioTestCase):
|
||||
fake_volume2 = mock.MagicMock()
|
||||
fake_snapshot1 = mock.MagicMock()
|
||||
fake_snapshot2 = mock.MagicMock()
|
||||
fake_server = mock.MagicMock()
|
||||
|
||||
scenario = volumes.CinderVolumes(
|
||||
context={"user": {"tenant_id": "fake"},
|
||||
"users": [{"tenant_id": "fake", "users_per_tenant": 1}],
|
||||
"tenant": {"id": "fake", "name": "fake",
|
||||
"servers": [fake_server.uuid]}})
|
||||
scenario = volumes.CinderVolumes(self._get_context())
|
||||
|
||||
scenario._attach_volume = mock.MagicMock()
|
||||
scenario._detach_volume = mock.MagicMock()
|
||||
@@ -373,11 +351,7 @@ class CinderServersTestCase(test.ScenarioTestCase):
|
||||
fake_snapshot = mock.MagicMock()
|
||||
fake_server = mock.MagicMock()
|
||||
|
||||
scenario = volumes.CinderVolumes(
|
||||
context={"user": {"tenant_id": "fake"},
|
||||
"users": [{"tenant_id": "fake", "users_per_tenant": 1}],
|
||||
"tenant": {"id": "fake", "name": "fake",
|
||||
"servers": [fake_server.uuid]}})
|
||||
scenario = volumes.CinderVolumes(self._get_context())
|
||||
|
||||
scenario.get_random_server = mock.MagicMock(return_value=fake_server)
|
||||
scenario._attach_volume = mock.MagicMock()
|
||||
|
@@ -27,7 +27,10 @@ class KeystoneBasicTestCase(test.TestCase):
|
||||
@staticmethod
|
||||
def _get_context():
|
||||
return {
|
||||
"user": {"id": "fake_user_id"},
|
||||
"user": {
|
||||
"id": "fake_user_id",
|
||||
"endpoint": mock.MagicMock()
|
||||
},
|
||||
"tenant": {"id": "fake_tenant_id"}
|
||||
}
|
||||
|
||||
|
@@ -20,7 +20,11 @@ class NeutronLoadbalancerv1TestCase(test.TestCase):
|
||||
|
||||
def _get_context(self):
|
||||
return {
|
||||
"user": {"id": "fake_user", "tenant_id": "fake_tenant"},
|
||||
"user": {
|
||||
"id": "fake_user",
|
||||
"tenant_id": "fake_tenant",
|
||||
"endpoint": mock.MagicMock()
|
||||
},
|
||||
"tenant": {"id": "fake_tenant",
|
||||
"networks": [{"id": "fake_net",
|
||||
"subnets": ["fake_subnet"]}]}}
|
||||
|
@@ -109,7 +109,10 @@ class NovaScenarioTestCase(test.ScenarioTestCase):
|
||||
def test__boot_server_with_ssh(self, mock__generate_random_name):
|
||||
self.clients("nova").servers.create.return_value = self.server
|
||||
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")
|
||||
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):
|
||||
self.clients("nova").servers.create.return_value = self.server
|
||||
nova_scenario = utils.NovaScenario(context={
|
||||
"user": {"secgroup": {"name": "new"}}}
|
||||
)
|
||||
"user": {
|
||||
"secgroup": {"name": "new"},
|
||||
"endpoint": mock.MagicMock()
|
||||
}
|
||||
})
|
||||
return_server = nova_scenario._boot_server(
|
||||
"image_id", "flavor_id",
|
||||
security_groups=["test"])
|
||||
@@ -158,7 +164,10 @@ class NovaScenarioTestCase(test.ScenarioTestCase):
|
||||
mock__generate_random_name):
|
||||
self.clients("nova").servers.create.return_value = self.server
|
||||
nova_scenario = utils.NovaScenario(context={
|
||||
"user": {"secgroup": {"name": "test1"}}}
|
||||
"user": {
|
||||
"secgroup": {"name": "test1"},
|
||||
"endpoint": mock.MagicMock()
|
||||
}}
|
||||
)
|
||||
return_server = nova_scenario._boot_server(
|
||||
"image_id", "flavor_id",
|
||||
|
@@ -24,7 +24,10 @@ class QuotasTestCase(test.ScenarioTestCase):
|
||||
def setUp(self):
|
||||
super(QuotasTestCase, self).setUp()
|
||||
self.context = {
|
||||
"user": {"tenant_id": "fake"},
|
||||
"user": {
|
||||
"tenant_id": "fake",
|
||||
"endpoint": mock.MagicMock()
|
||||
},
|
||||
"tenant": {"id": "fake"}
|
||||
}
|
||||
|
||||
|
@@ -138,10 +138,11 @@ class SaharaScenarioTestCase(test.ScenarioTestCase):
|
||||
}
|
||||
}
|
||||
|
||||
clients = mock.Mock(services=mock.Mock(
|
||||
return_value={"neutron": consts.Service.NEUTRON}))
|
||||
scenario = utils.SaharaScenario(context=context,
|
||||
clients=clients)
|
||||
self.clients("services").values.return_value = [
|
||||
consts.Service.NEUTRON
|
||||
]
|
||||
|
||||
scenario = utils.SaharaScenario(context=context)
|
||||
|
||||
mock_processes = {
|
||||
"test_plugin": {
|
||||
@@ -231,7 +232,7 @@ class SaharaScenarioTestCase(test.ScenarioTestCase):
|
||||
def test_launch_cluster_error(self, mock_sahara_consts,
|
||||
mock__generate_random_name):
|
||||
|
||||
scenario = utils.SaharaScenario(clients=mock.MagicMock())
|
||||
scenario = utils.SaharaScenario()
|
||||
mock_processes = {
|
||||
"test_plugin": {
|
||||
"test_version": {
|
||||
|
@@ -27,7 +27,9 @@ class VMTasksTestCase(test.TestCase):
|
||||
def setUp(self):
|
||||
super(VMTasksTestCase, self).setUp()
|
||||
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.scenario._boot_server_with_fip = mock.Mock(
|
||||
return_value=("foo_server", self.ip))
|
||||
|
@@ -252,20 +252,6 @@ class ScenarioTestCase(test.TestCase):
|
||||
scenario = base.Scenario(context=ctx)
|
||||
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):
|
||||
scenarios = base.Scenario.list_benchmark_scenarios()
|
||||
|
||||
|
@@ -79,10 +79,7 @@ class ScenarioHelpersTestCase(test.TestCase):
|
||||
self.assertEqual(expected_context,
|
||||
runner._get_scenario_context(context))
|
||||
|
||||
@mock.patch(BASE + "osclients")
|
||||
def test_run_scenario_once_internal_logic(self, mock_osclients):
|
||||
mock_osclients.Clients.return_value = "cl"
|
||||
|
||||
def test_run_scenario_once_internal_logic(self):
|
||||
context = runner._get_scenario_context(
|
||||
fakes.FakeUserContext({}).context)
|
||||
scenario_cls = mock.MagicMock()
|
||||
@@ -90,7 +87,7 @@ class ScenarioHelpersTestCase(test.TestCase):
|
||||
runner._run_scenario_once(args)
|
||||
|
||||
expected_calls = [
|
||||
mock.call(context=context, admin_clients="cl", clients="cl"),
|
||||
mock.call(context=context),
|
||||
mock.call().test(),
|
||||
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)
|
||||
|
||||
@mock.patch(BASE + "rutils.Timer", side_effect=fakes.FakeTimer)
|
||||
@mock.patch(BASE + "osclients")
|
||||
def test_run_scenario_once_without_scenario_output(self, mock_osclients,
|
||||
mock_timer):
|
||||
def test_run_scenario_once_without_scenario_output(self, mock_timer):
|
||||
context = runner._get_scenario_context(
|
||||
fakes.FakeUserContext({}).context)
|
||||
args = (1, fakes.FakeScenario, "do_it", context, {})
|
||||
@@ -118,9 +113,7 @@ class ScenarioHelpersTestCase(test.TestCase):
|
||||
self.assertEqual(expected_result, result)
|
||||
|
||||
@mock.patch(BASE + "rutils.Timer", side_effect=fakes.FakeTimer)
|
||||
@mock.patch(BASE + "osclients")
|
||||
def test_run_scenario_once_with_scenario_output(self, mock_osclients,
|
||||
mock_timer):
|
||||
def test_run_scenario_once_with_scenario_output(self, mock_timer):
|
||||
context = runner._get_scenario_context(
|
||||
fakes.FakeUserContext({}).context)
|
||||
args = (1, fakes.FakeScenario, "with_output", context, {})
|
||||
@@ -137,8 +130,7 @@ class ScenarioHelpersTestCase(test.TestCase):
|
||||
self.assertEqual(expected_result, result)
|
||||
|
||||
@mock.patch(BASE + "rutils.Timer", side_effect=fakes.FakeTimer)
|
||||
@mock.patch(BASE + "osclients")
|
||||
def test_run_scenario_once_exception(self, mock_osclients, mock_timer):
|
||||
def test_run_scenario_once_exception(self, mock_timer):
|
||||
context = runner._get_scenario_context(
|
||||
fakes.FakeUserContext({}).context)
|
||||
args = (1, fakes.FakeScenario, "something_went_wrong", context, {})
|
||||
|
Reference in New Issue
Block a user