Fix RouterInterface properties validation

get_attr on a non-created resource returns an empty string
(rather than None). We should pass validation in this case.

Change-Id: I5a1d651cc7dc46162140210ebeacaa7519111c91
Closes-bug: 1451819
This commit is contained in:
Oleksii Chuprykov 2015-05-05 09:31:16 -04:00
parent 1ad9f9f186
commit 0fbb16e6fc
2 changed files with 29 additions and 1 deletions

View File

@ -328,7 +328,7 @@ class RouterInterface(neutron.NeutronResource):
if value and deprecated_value:
raise exception.ResourcePropertyConflict(key,
deprecated_key)
if not value and not deprecated_value:
if value is None and deprecated_value is None:
return False
return True

View File

@ -21,6 +21,7 @@ import six
from heat.common import exception
from heat.common import template_format
from heat.engine import properties
from heat.engine.resources.openstack.neutron import router
from heat.engine import rsrc_defn
from heat.engine import scheduler
@ -864,3 +865,30 @@ class NeutronRouterTest(common.HeatTestCase):
rsrc = self.create_router(t, stack, 'router')
self.assertIsNone(scheduler.TaskRunner(rsrc.delete)())
self.m.VerifyAll()
def test_validate_depr_keys_required_both(self):
data = {'router_id': '1234',
'router': 'abc'}
p = properties.Properties(router.RouterInterface.properties_schema,
data)
self.assertRaises(
exception.ResourcePropertyConflict,
router.RouterInterface._validate_deprecated_keys,
p, 'router', 'router_id')
def test_validate_depr_keys_required_neither(self):
data = {}
p = properties.Properties(router.RouterInterface.properties_schema,
data)
res = router.RouterInterface._validate_deprecated_keys(
p, 'router', 'router_id')
self.assertFalse(res)
def test_validate_depr_keys_required_one(self):
data = {'router_id': ''}
p = properties.Properties(router.RouterInterface.properties_schema,
data)
res = router.RouterInterface._validate_deprecated_keys(
p, 'router', 'router_id')
self.assertTrue(res)