Merge "Add existing_network context"

This commit is contained in:
Jenkins 2015-08-18 22:56:39 +00:00 committed by Gerrit Code Review
commit c6efbf7c0c
2 changed files with 31 additions and 9 deletions

View File

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

View File

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