Skip to content

Commit f61e19c

Browse files
committed
implements #2027
1 parent 44e9945 commit f61e19c

2 files changed

Lines changed: 13 additions & 4 deletions

File tree

libcloud/compute/drivers/openstack.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4325,8 +4325,9 @@ def ex_attach_floating_ip_to_node(self, node, ip, port_id=None):
43254325
return False
43264326
if not port_id:
43274327
ports = self.ex_get_node_ports(node)
4328-
port_id = ports[0].id
4329-
if ports:
4328+
if ports:
4329+
port_id = ports[0].id
4330+
if port_id:
43304331
# Set to the first node port
43314332
resp = self.network_connection.request(
43324333
"/v2.0/floatingips/%s" % ip_id,

libcloud/test/compute/test_openstack.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1677,10 +1677,8 @@ def test_ex_attach_floating_ip_to_node(self):
16771677
node = self.driver.create_node(name="racktest", image=image, size=size)
16781678
node.id = 4242
16791679
ip = "42.42.42.42"
1680-
port_id = 'ce531f90-199f-48c0-816c-13e38010b442'
16811680

16821681
self.assertTrue(self.driver.ex_attach_floating_ip_to_node(node, ip))
1683-
self.assertTrue(self.driver.ex_attach_floating_ip_to_node(node, ip, port_id))
16841682

16851683
def test_detach_floating_ip_from_node(self):
16861684
image = NodeImage(id=11, name="Ubuntu 8.10 (intrepid)", driver=self.driver)
@@ -2549,6 +2547,16 @@ def test_ex_delete_floating_ip(self):
25492547
ip = OpenStack_1_1_FloatingIpAddress("foo-bar-id", "42.42.42.42", None)
25502548
self.assertTrue(self.driver.ex_delete_floating_ip(ip))
25512549

2550+
def test_ex_attach_floating_ip_to_node(self):
2551+
image = NodeImage(id=11, name="Ubuntu 8.10 (intrepid)", driver=self.driver)
2552+
size = NodeSize(1, "256 slice", None, None, None, None, driver=self.driver)
2553+
node = self.driver.create_node(name="racktest", image=image, size=size)
2554+
node.id = 4242
2555+
ip = "42.42.42.42"
2556+
port_id = 'ce531f90-199f-48c0-816c-13e38010b442'
2557+
2558+
self.assertTrue(self.driver.ex_attach_floating_ip_to_node(node, ip, port_id))
2559+
25522560

25532561
class OpenStack_1_1_FactoryMethodTests(OpenStack_1_1_Tests):
25542562
should_list_locations = False

0 commit comments

Comments
 (0)