From 16f8ff744d8b6326eee96ad8d353830f8fbfe152 Mon Sep 17 00:00:00 2001 From: Yair Fried Date: Wed, 17 Jun 2015 13:18:10 +0300 Subject: [PATCH] [Floating IP] Remove port creation on fip creation NeutronWrapper creates a private port when creating a floating IP. This is bad because: 1. It doesn't make any sense to attach a fip to a standalone port. 2. The method associate_floating_ip() is always called and associates the fip with a real server. 3. Rally consumes an extra port/ip from the tenant/network. Change-Id: I932cdf707f6041df4eef8fcd6074ac069678de7b Closes-Bug: #1465690 --- rally/plugins/openstack/scenarios/vm/utils.py | 2 +- rally/plugins/openstack/wrappers/network.py | 17 ++++------------- .../openstack/scenarios/vm/test_utils.py | 2 +- .../plugins/openstack/wrappers/test_network.py | 5 +---- 4 files changed, 7 insertions(+), 19 deletions(-) diff --git a/rally/plugins/openstack/scenarios/vm/utils.py b/rally/plugins/openstack/scenarios/vm/utils.py index 898aa2af0b..c1b75a4b11 100644 --- a/rally/plugins/openstack/scenarios/vm/utils.py +++ b/rally/plugins/openstack/scenarios/vm/utils.py @@ -101,7 +101,7 @@ class VMScenario(base.Scenario): fixed_ip = server.addresses[internal_network][0]["addr"] fip = network_wrapper.wrap(self.clients).create_floating_ip( - ext_network=floating_network, int_network=internal_network, + ext_network=floating_network, tenant_id=server.tenant_id, fixed_ip=fixed_ip) self._associate_floating_ip(server, fip["ip"], fixed_address=fixed_ip) diff --git a/rally/plugins/openstack/wrappers/network.py b/rally/plugins/openstack/wrappers/network.py index c4e79523a0..308169b3fa 100644 --- a/rally/plugins/openstack/wrappers/network.py +++ b/rally/plugins/openstack/wrappers/network.py @@ -320,12 +320,11 @@ class NeutronWrapper(NetworkWrapper): kwargs["name"] = utils.generate_random_name("rally_port_") return self.client.create_port({"port": kwargs})["port"] - def create_floating_ip(self, ext_network=None, int_network=None, + def create_floating_ip(self, ext_network=None, tenant_id=None, port_id=None, **kwargs): """Create Neutron floating IP. :param ext_network: floating network name or dict - :param int_network: fixed network name or dict :param tenant_id str tenant id :param port_id: str port id :param **kwargs: for compatibility, not used here @@ -351,18 +350,10 @@ class NeutronWrapper(NetworkWrapper): "no external networks found") net_id = ext_networks[0]["id"] - if not port_id: - if type(int_network) is dict: - port_id = self.create_port(int_network["id"])["id"] - elif int_network: - int_net = self.get_network(name=int_network) - if int_net["external"]: - raise NetworkWrapperException("Network is external: %s" - % int_network) - port_id = self.create_port(int_net["id"])["id"] kwargs = {"floatingip": {"floating_network_id": net_id}, - "tenant_id": tenant_id, - "port_id": port_id} + "tenant_id": tenant_id} + if port_id: + kwargs["port_id"] = port_id fip = self.client.create_floatingip(kwargs)["floatingip"] return {"id": fip["id"], "ip": fip["floating_ip_address"]} diff --git a/tests/unit/plugins/openstack/scenarios/vm/test_utils.py b/tests/unit/plugins/openstack/scenarios/vm/test_utils.py index 31233a3375..cfd325348d 100644 --- a/tests/unit/plugins/openstack/scenarios/vm/test_utils.py +++ b/tests/unit/plugins/openstack/scenarios/vm/test_utils.py @@ -280,7 +280,7 @@ class VMScenarioTestCase(test.TestCase): mock_wrap.assert_called_once_with(scenario.clients) netwrap.create_floating_ip.assert_called_once_with( - ext_network="bar_network", int_network="foo_net", + ext_network="bar_network", tenant_id="foo_tenant", fixed_ip="foo_ip") scenario._associate_floating_ip.assert_called_once_with( diff --git a/tests/unit/plugins/openstack/wrappers/test_network.py b/tests/unit/plugins/openstack/wrappers/test_network.py index d875f17359..6cfb4d7a2f 100644 --- a/tests/unit/plugins/openstack/wrappers/test_network.py +++ b/tests/unit/plugins/openstack/wrappers/test_network.py @@ -394,14 +394,11 @@ class NeutronWrapperTestCase(test.TestCase): wrap.get_network = mock.Mock( return_value={"id": "foo_net", "external": True}) - self.assertRaises(network.NetworkWrapperException, - wrap.create_floating_ip, tenant_id="foo_tenant", - int_network="int_net") wrap.create_floating_ip(tenant_id="foo_tenant", ext_network="ext_net") wrap.get_network = mock.Mock( return_value={"id": "foo_net", "external": False}) - wrap.create_floating_ip(tenant_id="foo_tenant", int_network="int_net") + wrap.create_floating_ip(tenant_id="foo_tenant") self.assertRaises(network.NetworkWrapperException, wrap.create_floating_ip, tenant_id="foo_tenant",