Merge "Don't support floating ip if only specify 'network'"
This commit is contained in:
commit
c8b2f2bcaa
@ -36,6 +36,7 @@ class ServerNetworkMixin(object):
|
||||
port = network.get(self.NETWORK_PORT)
|
||||
subnet = network.get(self.NETWORK_SUBNET)
|
||||
fixed_ip = network.get(self.NETWORK_FIXED_IP)
|
||||
floating_ip = network.get(self.NETWORK_FLOATING_IP)
|
||||
|
||||
if net_id is None and port is None and subnet is None:
|
||||
msg = _('One of the properties "%(id)s", "%(port_id)s" '
|
||||
@ -58,6 +59,18 @@ class ServerNetworkMixin(object):
|
||||
"/".join([self.NETWORKS, self.NETWORK_FIXED_IP]),
|
||||
"/".join([self.NETWORKS, self.NETWORK_PORT]))
|
||||
|
||||
# if user only specifies network and floating ip, floating ip
|
||||
# can't be associated as the the neutron port isn't created/managed
|
||||
# by heat
|
||||
if floating_ip is not None and self.is_using_neutron():
|
||||
if net_id is not None and port is None and subnet is None:
|
||||
msg = _('Property "%(fip)s" is not supported if only '
|
||||
'"%(net)s" is specified, because the corresponding '
|
||||
'port can not be retrieved.'
|
||||
) % dict(fip=self.NETWORK_FLOATING_IP,
|
||||
net=self.NETWORK_ID)
|
||||
raise exception.StackValidationFailed(message=msg)
|
||||
|
||||
def _validate_belonging_subnet_to_net(self, network):
|
||||
if network.get(self.NETWORK_PORT) is None and self.is_using_neutron():
|
||||
net = self._get_network_id(network)
|
||||
|
@ -1195,6 +1195,31 @@ class ServersTest(common.HeatTestCase):
|
||||
'server "%s".') % server.name,
|
||||
six.text_type(ex))
|
||||
|
||||
def test_server_validate_with_network_floating_ip(self):
|
||||
stack_name = 'srv_net_floating_ip'
|
||||
(tmpl, stack) = self._setup_test_stack(stack_name)
|
||||
# create a server with 'uuid' and 'network' properties
|
||||
tmpl['Resources']['WebServer']['Properties']['networks'] = (
|
||||
[{'floating_ip': '172.24.4.14',
|
||||
'network': '6b1688bb-18a0-4754-ab05-19daaedc5871'}])
|
||||
self.patchobject(nova.NovaClientPlugin, '_create',
|
||||
return_value=self.fc)
|
||||
resource_defns = tmpl.resource_definitions(stack)
|
||||
server = servers.Server('server_validate_net_floating_ip',
|
||||
resource_defns['WebServer'], stack)
|
||||
self.patchobject(glance.GlanceClientPlugin, 'get_image',
|
||||
return_value=self.mock_image)
|
||||
self.patchobject(nova.NovaClientPlugin, 'get_flavor',
|
||||
return_value=self.mock_flavor)
|
||||
self.patchobject(neutron.NeutronClientPlugin,
|
||||
'find_resourceid_by_name_or_id')
|
||||
ex = self.assertRaises(exception.StackValidationFailed,
|
||||
server.validate)
|
||||
self.assertIn(_('Property "floating_ip" is not supported if '
|
||||
'only "network" is specified, because the '
|
||||
'corresponding port can not be retrieved.'),
|
||||
six.text_type(ex))
|
||||
|
||||
def test_server_validate_with_port_fixed_ip(self):
|
||||
stack_name = 'srv_net'
|
||||
(tmpl, stack) = self._setup_test_stack(stack_name)
|
||||
|
Loading…
Reference in New Issue
Block a user