Skip to content

Commit e65ed54

Browse files
authored
Merge pull request #241 from cloudify-cosmo/floating-ip-fixes
another fix
2 parents a398cd6 + a5a1bbf commit e65ed54

File tree

4 files changed

+22
-16
lines changed

4 files changed

+22
-16
lines changed

CHANGELOG.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
2.9.0:
22
- Add Support for backup/restore actions.
3+
- Fix bug in server-port-floating-ip handling.
34
2.8.2:
45
- Add attach operation for server-port in order to support heal for server with floating ip.
56
2.8.1:

blueprints/server-networks.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ tosca_definitions_version: cloudify_dsl_1_3
22

33
imports:
44
- http://www.getcloudify.org/spec/cloudify/4.3.1/types.yaml
5-
- http://www.getcloudify.org/spec/openstack-plugin/2.8.2/plugin.yaml
5+
- ../plugin.yaml
66

77
inputs:
88

cinder_plugin/tests/test_volume.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -480,12 +480,6 @@ def test_list_volumes(self, cinder_m):
480480
volume_ctx.instance.runtime_properties
481481
)
482482

483-
@mock.patch('openstack_plugin_common.CinderClientWithSugar')
484-
def test_creation_validation(self, cinder_m):
485-
volume_ctx, volume_id = self._simple_volume_ctx()
486-
487-
volume.creation_validation(ctx=volume_ctx)
488-
489483
@mock.patch('openstack_plugin_common.CinderClientWithSugar')
490484
@mock.patch('time.sleep', mock.Mock())
491485
def test_delete_snapshot(self, cinder_m):

neutron_plugin/port.py

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
set_neutron_runtime_properties,
3535
create_object_dict,
3636
COMMON_RUNTIME_PROPERTIES_KEYS,
37+
OPENSTACK_ID_PROPERTY,
3738
is_external_relationship_not_conditionally_created)
3839

3940
from neutron_plugin.network import NETWORK_OPENSTACK_TYPE
@@ -42,6 +43,7 @@
4243
from openstack_plugin_common.floatingip import get_server_floating_ip
4344

4445
PORT_OPENSTACK_TYPE = 'port'
46+
PORT_ADDRESS_REL_TYPE = 'cloudify.openstack.port_connected_to_floating_ip'
4547

4648
# Runtime properties
4749
FIXED_IP_ADDRESS_PROPERTY = 'fixed_ip_address' # the fixed ip address
@@ -111,25 +113,34 @@ def attach(nova_client, neutron_client, **kwargs):
111113
'external port and server are being used')
112114
return
113115

114-
port_id = get_openstack_id(ctx.target)
115116
server_id = get_openstack_id(ctx.source)
117+
port_id = get_openstack_id(ctx.target)
116118
port = neutron_client.show_port(port_id)
119+
server = nova_client.servers.get(server_id)
117120
network = neutron_client.show_network(port['port']['network_id'])
118121
network_name = network['network']['name']
119-
server = nova_client.servers.get(server_id)
120-
server_floating_ip = get_server_floating_ip(neutron_client, server_id)
121-
floating_ip = server_floating_ip['floating_ip_address']
122+
123+
floating_ip_address = None
124+
for target in ctx.target.instance.relationships:
125+
if target.type == PORT_ADDRESS_REL_TYPE:
126+
target_instance = target.target.instance
127+
floatingip_id = \
128+
target_instance.runtime_properties[OPENSTACK_ID_PROPERTY]
129+
floating_ip = neutron_client.show_floatingip(floatingip_id)
130+
floating_ip_address = \
131+
floating_ip['floatingip']['floating_ip_address']
132+
122133
server_addresses = \
123134
[addr['addr'] for addr in server.addresses[network_name]]
124135

125-
if server_floating_ip and floating_ip not in server_addresses:
126-
ctx.logger.info('We will attach floating ip {0} to server'
127-
.format(server_floating_ip['floating_ip_address']))
128-
server.add_floating_ip(server_floating_ip['floating_ip_address'])
136+
if floating_ip_address and floating_ip_address not in server_addresses:
137+
ctx.logger.info('We will attach floating ip {0} to server {1}'
138+
.format(floating_ip_address, server_id))
139+
server.add_floating_ip(floating_ip_address)
129140
return ctx.operation.retry(
130141
message='Waiting for the floating ip {0} to '
131142
'attach to server {1}..'
132-
.format(server_floating_ip['floating_ip_address'],
143+
.format(floating_ip_address,
133144
server_id),
134145
retry_after=10)
135146
change = {

0 commit comments

Comments
 (0)