Add additional validation for fip properties

Additional validation to throw an eror if fixed IP is specified
without the port id.

If you intend to associate the floating IP with a fixed IP during
create/update, then you must indicate the identifier of the
internal port.

Change-Id: I99eb0f2949d93a8619fc03cd4c8861133afaf9ae
This commit is contained in:
Rabi Mishra 2015-04-16 19:26:58 +05:30
parent ce3f1d299c
commit fdb23e93c4
3 changed files with 22 additions and 0 deletions

View File

@ -368,6 +368,10 @@ class ResourcePropertyConflict(HeatException):
super(ResourcePropertyConflict, self).__init__(**kwargs)
class ResourcePropertyDependency(HeatException):
msg_fmt = _('%(prop1)s cannot be specified without %(prop2)s.')
class PropertyUnspecifiedError(HeatException):
msg_fmt = _('At least one of the following properties '
'must be specified: %(props)s')

View File

@ -180,6 +180,11 @@ class FloatingIP(neutron.NeutronResource):
super(FloatingIP, self).validate()
self._validate_depr_property_required(
self.properties, self.FLOATING_NETWORK, self.FLOATING_NETWORK_ID)
# fixed_ip_address cannot be specified without a port_id
if self.properties.get(self.PORT_ID) is None and self.properties.get(
self.FIXED_IP_ADDRESS) is not None:
raise exception.ResourcePropertyDependency(
prop1=self.FIXED_IP_ADDRESS, prop2=self.PORT_ID)
def handle_create(self):
props = self.prepare_properties(

View File

@ -128,6 +128,19 @@ class NeutronFloatingIPTest(common.HeatTestCase):
self.m.StubOutWithMock(neutronV20,
'find_resourceid_by_name_or_id')
def test_floating_ip_validate(self):
t = template_format.parse(neutron_floating_no_assoc_template)
stack = utils.parse_stack(t)
fip = stack['floating_ip']
self.assertIsNone(fip.validate())
del t['resources']['floating_ip']['properties']['port_id']
t['resources']['floating_ip']['properties'][
'fixed_ip_address'] = '10.0.0.12'
stack = utils.parse_stack(t)
fip = stack['floating_ip']
self.assertRaises(exception.ResourcePropertyDependency,
fip.validate)
def test_floating_ip_router_interface(self):
t = template_format.parse(neutron_floating_template)
del t['resources']['gateway']