[FIX] fix params in creating floating-ip

As subject, fix the params form of creating-floating-ip.

Change-Id: I37181c3eee66142cea8bfe8688e65eede8b1524e
This commit is contained in:
Hai Shi 2017-02-13 10:15:26 +08:00
parent 9356816683
commit 8d2801eca1
2 changed files with 8 additions and 6 deletions

View File

@ -427,10 +427,10 @@ class NeutronWrapper(NetworkWrapper):
"no external networks found") "no external networks found")
net_id = ext_networks[0]["id"] net_id = ext_networks[0]["id"]
kwargs = {"floatingip": {"floating_network_id": net_id}, kwargs = {"floatingip": {"floating_network_id": net_id,
"tenant_id": tenant_id} "tenant_id": tenant_id}}
if port_id: if port_id:
kwargs["port_id"] = port_id kwargs["floatingip"]["port_id"] = port_id
fip = self.client.create_floatingip(kwargs)["floatingip"] fip = self.client.create_floatingip(kwargs)["floatingip"]
return {"id": fip["id"], "ip": fip["floating_ip_address"]} return {"id": fip["id"], "ip": fip["floating_ip_address"]}

View File

@ -461,16 +461,18 @@ class NeutronWrapperTestCase(test.TestCase):
mock_neutron_wrapper_external_networks.__get__ = ( mock_neutron_wrapper_external_networks.__get__ = (
lambda *args: [{"id": "ext_id"}] lambda *args: [{"id": "ext_id"}]
) )
fip = wrap.create_floating_ip(tenant_id="foo_tenant") fip = wrap.create_floating_ip(tenant_id="foo_tenant",
port_id="port_id")
self.assertEqual(fip, {"id": "fip_id", "ip": "fip_ip"}) self.assertEqual(fip, {"id": "fip_id", "ip": "fip_ip"})
wrap.get_network = mock.Mock( wrap.get_network = mock.Mock(
return_value={"id": "foo_net", "external": True}) return_value={"id": "foo_net", "external": True})
wrap.create_floating_ip(tenant_id="foo_tenant", ext_network="ext_net") wrap.create_floating_ip(tenant_id="foo_tenant", ext_network="ext_net",
port_id="port_id")
wrap.get_network = mock.Mock( wrap.get_network = mock.Mock(
return_value={"id": "foo_net", "external": False}) return_value={"id": "foo_net", "external": False})
wrap.create_floating_ip(tenant_id="foo_tenant") wrap.create_floating_ip(tenant_id="foo_tenant", port_id="port_id")
self.assertRaises(network.NetworkWrapperException, self.assertRaises(network.NetworkWrapperException,
wrap.create_floating_ip, tenant_id="foo_tenant", wrap.create_floating_ip, tenant_id="foo_tenant",