Add existing_network context
This context lets you use existing networks that have already been created instead of creating new networks with Rally. This is useful when, for instance, you are using Neutron with a dumb router that is not capable of creating new networks on the fly. Change-Id: I3718dba57145c3e64237dcb758cdcf3505e000dd
This commit is contained in:
parent
e5af42ac79
commit
cdc7b6eb01
@ -112,6 +112,21 @@ class NovaNetworkWrapper(NetworkWrapper):
|
||||
cidr = generate_cidr(start_cidr=self.start_cidr)
|
||||
return cidr
|
||||
|
||||
def _marshal_network_object(self, net_obj):
|
||||
"""Convert a Network object to a dict.
|
||||
|
||||
This helps keep return values from the NovaNetworkWrapper
|
||||
compatible with those from NeutronWrapper.
|
||||
|
||||
:param net_obj: The Network object to convert to a dict
|
||||
"""
|
||||
return {"id": net_obj.id,
|
||||
"cidr": net_obj.cidr,
|
||||
"name": net_obj.label,
|
||||
"status": "ACTIVE",
|
||||
"external": False,
|
||||
"tenant_id": net_obj.project_id}
|
||||
|
||||
def create_network(self, tenant_id, **kwargs):
|
||||
"""Create network.
|
||||
|
||||
@ -123,18 +138,14 @@ class NovaNetworkWrapper(NetworkWrapper):
|
||||
label = utils.generate_random_name("rally_net_")
|
||||
network = self.client.networks.create(
|
||||
tenant_id=tenant_id, cidr=cidr, label=label)
|
||||
return {"id": network.id,
|
||||
"cidr": network.cidr,
|
||||
"name": network.label,
|
||||
"status": "ACTIVE",
|
||||
"external": False,
|
||||
"tenant_id": tenant_id}
|
||||
return self._marshal_network_object(network)
|
||||
|
||||
def delete_network(self, network):
|
||||
return self.client.networks.delete(network["id"])
|
||||
|
||||
def list_networks(self):
|
||||
return self.client.networks.list()
|
||||
return [self._marshal_network_object(n)
|
||||
for n in self.client.networks.list()]
|
||||
|
||||
def create_floating_ip(self, ext_network=None, **kwargs):
|
||||
"""Allocate a floating ip from the given nova-network pool
|
||||
|
@ -30,6 +30,8 @@ class NovaNetworkWrapperTestCase(test.TestCase):
|
||||
|
||||
class Net(object):
|
||||
def __init__(self, **kwargs):
|
||||
if "tenant_id" in kwargs:
|
||||
kwargs["project_id"] = kwargs.pop("tenant_id")
|
||||
self.__dict__.update(kwargs)
|
||||
|
||||
def get_wrapper(self, *skip_cidrs, **kwargs):
|
||||
@ -88,9 +90,18 @@ class NovaNetworkWrapperTestCase(test.TestCase):
|
||||
|
||||
def test_list_networks(self):
|
||||
service = self.get_wrapper()
|
||||
service.client.networks.list.return_value = "foo_list"
|
||||
service.client.networks.list.reset_mock()
|
||||
self.assertEqual(service.list_networks(), "foo_list")
|
||||
service.client.networks.list.return_value = [
|
||||
self.Net(id="foo_id", project_id="foo_tenant", cidr="foo_cidr",
|
||||
label="foo_label"),
|
||||
self.Net(id="bar_id", project_id="bar_tenant", cidr="bar_cidr",
|
||||
label="bar_label")]
|
||||
expected = [
|
||||
{"id": "foo_id", "cidr": "foo_cidr", "name": "foo_label",
|
||||
"status": "ACTIVE", "external": False, "tenant_id": "foo_tenant"},
|
||||
{"id": "bar_id", "cidr": "bar_cidr", "name": "bar_label",
|
||||
"status": "ACTIVE", "external": False, "tenant_id": "bar_tenant"}]
|
||||
self.assertEqual(expected, service.list_networks())
|
||||
service.client.networks.list.assert_called_once_with()
|
||||
|
||||
def test__get_floating_ip(self):
|
||||
|
Loading…
Reference in New Issue
Block a user