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
commit 5d5cc108ba
13 changed files with 119 additions and 134 deletions

View File

@ -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,

View File

@ -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`"))

View File

@ -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.

View File

@ -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)

View File

@ -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)

View File

@ -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")

View File

@ -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()

View File

@ -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"}
}

View File

@ -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"]}]}}

View File

@ -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",

View File

@ -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"}
}

View File

@ -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": {

View File

@ -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))