Using Neutron names in Sahara
Sahara Cluster benchmarks and Cluster context now works with Neutron network name. A resource type added to handle name to id conversion. Some minor improvements are also done to test and context classes. Change-Id: I8e567747c28630bc7c1efeb834947bf778c03e49
This commit is contained in:
parent
3230a3a89b
commit
2ed0cf0266
@ -18,6 +18,7 @@ from oslo.config import cfg
|
||||
from rally.benchmark.context import base
|
||||
from rally.benchmark.context.cleanup import utils as cleanup_utils
|
||||
from rally.benchmark.scenarios.sahara import utils
|
||||
from rally.benchmark import types
|
||||
from rally.benchmark import utils as bench_utils
|
||||
from rally.openstack.common import log as logging
|
||||
from rally import osclients
|
||||
@ -43,7 +44,7 @@ class SaharaCluster(base.Context):
|
||||
"type": "string"
|
||||
},
|
||||
"hadoop_version": {
|
||||
"enum": ["1.2.1", "2.3.0", "2.4.1"]
|
||||
"type": "string",
|
||||
},
|
||||
"node_count": {
|
||||
"type": "integer",
|
||||
@ -55,7 +56,7 @@ class SaharaCluster(base.Context):
|
||||
"floating_ip_pool": {
|
||||
"type": "string",
|
||||
},
|
||||
"neutron_net_id": {
|
||||
"neutron_net": {
|
||||
"type": "string",
|
||||
},
|
||||
"volumes_per_node": {
|
||||
@ -96,6 +97,24 @@ class SaharaCluster(base.Context):
|
||||
|
||||
image_id = self.context["sahara_images"][tenant_id]
|
||||
|
||||
neutron_net = self.config.get("neutron_net")
|
||||
if not neutron_net:
|
||||
# Skipping fixed network config
|
||||
neutron_net_id = None
|
||||
else:
|
||||
network_cfg = {"name": neutron_net}
|
||||
neutron_net_id = (types.NeutronNetworkResourceType
|
||||
.transform(clients, network_cfg))
|
||||
|
||||
floating_ip_pool = self.config.get("floating_ip_pool")
|
||||
if not floating_ip_pool:
|
||||
# Skipping floating network config
|
||||
floating_ip_pool_id = None
|
||||
else:
|
||||
network_cfg = {"name": floating_ip_pool}
|
||||
floating_ip_pool_id = (types.NeutronNetworkResourceType
|
||||
.transform(clients, network_cfg))
|
||||
|
||||
cluster = utils.SaharaScenario(
|
||||
context=self.context, clients=clients)._launch_cluster(
|
||||
plugin_name=self.config["plugin_name"],
|
||||
@ -103,8 +122,8 @@ class SaharaCluster(base.Context):
|
||||
flavor_id=self.config["flavor_id"],
|
||||
node_count=self.config["node_count"],
|
||||
image_id=image_id,
|
||||
floating_ip_pool=self.config.get("floating_ip_pool"),
|
||||
neutron_net_id=self.config.get("neutron_net_id"),
|
||||
floating_ip_pool=floating_ip_pool_id,
|
||||
neutron_net_id=neutron_net_id,
|
||||
volumes_per_node=self.config.get("volumes_per_node"),
|
||||
volumes_size=self.config.get("volumes_size", 1),
|
||||
node_configs=self.config.get("node_configs"),
|
||||
|
@ -25,7 +25,9 @@ LOG = logging.getLogger(__name__)
|
||||
|
||||
class SaharaClusters(utils.SaharaScenario):
|
||||
|
||||
@types.set(flavor=types.FlavorResourceType)
|
||||
@types.set(flavor=types.FlavorResourceType,
|
||||
neutron_net=types.NeutronNetworkResourceType,
|
||||
floating_ip_pool=types.NeutronNetworkResourceType)
|
||||
@validation.flavor_exists('flavor')
|
||||
@validation.required_contexts("users", "sahara_image")
|
||||
@validation.number("node_count", minval=2, integer_only=True)
|
||||
@ -34,7 +36,7 @@ class SaharaClusters(utils.SaharaScenario):
|
||||
@base.scenario(context={"cleanup": ["sahara"]})
|
||||
def create_and_delete_cluster(self, flavor, node_count, plugin_name,
|
||||
hadoop_version, floating_ip_pool=None,
|
||||
neutron_net_id=None, volumes_per_node=None,
|
||||
neutron_net=None, volumes_per_node=None,
|
||||
volumes_size=None, node_configs=None,
|
||||
cluster_configs=None):
|
||||
"""Test the Sahara Cluster launch and delete commands.
|
||||
@ -52,7 +54,7 @@ class SaharaClusters(utils.SaharaScenario):
|
||||
IPs will be allocated. Sahara will determine automatically how to treat
|
||||
this depending on it's own configurations. Defaults to None because in
|
||||
some cases Sahara may work w/o Floating IPs.
|
||||
:param neutron_net_id: The id of a Neutron network that
|
||||
:param neutron_net: The id or name of a Neutron network that
|
||||
will be used for fixed IPs. This parameter is ignored when Nova Network
|
||||
is set up.
|
||||
:param volumes_per_node: The number of Cinder volumes that will be
|
||||
@ -76,7 +78,7 @@ class SaharaClusters(utils.SaharaScenario):
|
||||
plugin_name=plugin_name,
|
||||
hadoop_version=hadoop_version,
|
||||
floating_ip_pool=floating_ip_pool,
|
||||
neutron_net_id=neutron_net_id,
|
||||
neutron_net_id=neutron_net,
|
||||
volumes_per_node=volumes_per_node,
|
||||
volumes_size=volumes_size,
|
||||
node_configs=node_configs,
|
||||
|
@ -189,7 +189,7 @@ class SaharaScenario(base.Scenario):
|
||||
:param floating_ip_pool: The floating ip pool name from which Floating
|
||||
IPs will be allocated
|
||||
:param neutron_net_id: The network id to allocate Fixed IPs
|
||||
from when Neutron is enabled for networking
|
||||
from, when Neutron is enabled for networking
|
||||
:param volumes_per_node: The number of Cinder volumes that will be
|
||||
attached to every cluster node
|
||||
:param volumes_size: The size of each Cinder volume in GB
|
||||
@ -251,7 +251,6 @@ class SaharaScenario(base.Scenario):
|
||||
# cluster_configs parameter can override it
|
||||
merged_cluster_configs = self._merge_configs(replication_config,
|
||||
cluster_configs)
|
||||
|
||||
cluster_object = self.clients("sahara").clusters.create(
|
||||
name=name,
|
||||
plugin_name=plugin_name,
|
||||
|
@ -177,3 +177,28 @@ class VolumeTypeResourceType(ResourceType):
|
||||
volume_types.list(),
|
||||
typename='volume_type')
|
||||
return resource_id
|
||||
|
||||
|
||||
class NeutronNetworkResourceType(ResourceType):
|
||||
|
||||
@classmethod
|
||||
def transform(cls, clients, resource_config):
|
||||
"""Transform the resource config to id.
|
||||
|
||||
:param clients: openstack admin client handles
|
||||
:param resource_config: scenario config with `id`, `name` or `regex`
|
||||
|
||||
:returns: id matching resource
|
||||
"""
|
||||
resource_id = resource_config.get('id')
|
||||
if resource_id:
|
||||
return resource_id
|
||||
else:
|
||||
neutronclient = clients.neutron()
|
||||
for net in neutronclient.list_networks()["networks"]:
|
||||
if net["name"] == resource_config.get("name"):
|
||||
return net["id"]
|
||||
|
||||
raise exceptions.InvalidScenarioArgument(
|
||||
"Neutron network with name '{name}' not found".format(
|
||||
name=resource_config.get("name")))
|
@ -22,7 +22,7 @@ SAHARA_CLUSTERS = "rally.benchmark.scenarios.sahara.clusters.SaharaClusters"
|
||||
SAHARA_UTILS = 'rally.benchmark.scenarios.sahara.utils'
|
||||
|
||||
|
||||
class SaharaNodeGroupTemplatesTestCase(test.TestCase):
|
||||
class SaharaClustersTestCase(test.TestCase):
|
||||
|
||||
@mock.patch(SAHARA_CLUSTERS + "._delete_cluster")
|
||||
@mock.patch(SAHARA_CLUSTERS + "._launch_cluster",
|
||||
|
@ -169,6 +169,38 @@ class VolumeTypeResourceTypeTestCase(test.TestCase):
|
||||
self.clients, resource_config)
|
||||
|
||||
|
||||
class NeutronNetworkResourceTypeTestCase(test.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(NeutronNetworkResourceTypeTestCase, self).setUp()
|
||||
self.clients = fakes.FakeClients()
|
||||
net1_data = {"network": {
|
||||
"name": "net1"
|
||||
}}
|
||||
network1 = self.clients.neutron().create_network(net1_data)
|
||||
self.net1_id = network1["network"]["id"]
|
||||
|
||||
def test_transform_by_id(self):
|
||||
resource_config = {"id": self.net1_id}
|
||||
network_id = types.NeutronNetworkResourceType.transform(
|
||||
clients=self.clients,
|
||||
resource_config=resource_config)
|
||||
self.assertEqual(network_id, self.net1_id)
|
||||
|
||||
def test_transform_by_name(self):
|
||||
resource_config = {"name": "net1"}
|
||||
network_id = types.NeutronNetworkResourceType.transform(
|
||||
clients=self.clients,
|
||||
resource_config=resource_config)
|
||||
self.assertEqual(network_id, self.net1_id)
|
||||
|
||||
def test_transform_by_name_no_match(self):
|
||||
resource_config = {"name": "nomatch-1"}
|
||||
self.assertRaises(exceptions.InvalidScenarioArgument,
|
||||
types.NeutronNetworkResourceType.transform,
|
||||
self.clients, resource_config)
|
||||
|
||||
|
||||
class PreprocessTestCase(test.TestCase):
|
||||
|
||||
@mock.patch("rally.benchmark.types.base.Scenario.meta")
|
||||
|
Loading…
Reference in New Issue
Block a user