Merge "Make disk property of flavor default"

This commit is contained in:
Jenkins 2015-04-10 03:13:41 +00:00 committed by Gerrit Code Review
commit dcfbd2dd0b
2 changed files with 65 additions and 3 deletions

View File

@ -51,9 +51,9 @@ class NovaFlavor(resource.Resource):
), ),
DISK: properties.Schema( DISK: properties.Schema(
properties.Schema.INTEGER, properties.Schema.INTEGER,
_('Size of local disk in GB. Set the value to 0 to remove limit ' _('Size of local disk in GB. The "0" size is a special case that '
'on disk size.'), 'uses the native base image size as the size of the ephemeral '
required=True, 'root volume.'),
default=0 default=0
), ),
SWAP: properties.Schema( SWAP: properties.Schema(

View File

@ -13,6 +13,8 @@
import itertools import itertools
import json import json
import os
import sys
import uuid import uuid
import mock import mock
@ -25,9 +27,11 @@ from heat.common import short_id
from heat.common import timeutils from heat.common import timeutils
from heat.engine import attributes from heat.engine import attributes
from heat.engine.cfn import functions as cfn_funcs from heat.engine.cfn import functions as cfn_funcs
from heat.engine import constraints
from heat.engine import dependencies from heat.engine import dependencies
from heat.engine import environment from heat.engine import environment
from heat.engine import parser from heat.engine import parser
from heat.engine import properties
from heat.engine import resource from heat.engine import resource
from heat.engine import resources from heat.engine import resources
from heat.engine import rsrc_defn from heat.engine import rsrc_defn
@ -1140,6 +1144,64 @@ class ResourceTest(common.HeatTestCase):
}, env=self.env) }, env=self.env)
self._test_skip_validation_if_custom_constraint(tmpl) self._test_skip_validation_if_custom_constraint(tmpl)
def test_no_resource_properties_required_default(self):
"""Test that there is no required properties with default value
Check all resources if they have properties with required flag and
default value because it is ambiguous.
"""
env = environment.Environment({}, user_env=False)
resources._load_global_environment(env)
# change loading mechanism for resources that require template files
mod_dir = os.path.dirname(sys.modules[__name__].__file__)
project_dir = os.path.abspath(os.path.join(mod_dir, '../../'))
template_path = os.path.join(project_dir, 'etc', 'heat', 'templates')
tri_db_instance = env.get_resource_info(
'AWS::RDS::DBInstance',
registry_type=environment.TemplateResourceInfo)
tri_db_instance.template_name = tri_db_instance.template_name.replace(
'/etc/heat/templates', template_path)
tri_alarm = env.get_resource_info(
'AWS::CloudWatch::Alarm',
registry_type=environment.TemplateResourceInfo)
tri_alarm.template_name = tri_alarm.template_name.replace(
'/etc/heat/templates', template_path)
def _validate_property_schema(prop_name, prop, res_name):
if isinstance(prop, properties.Schema) and prop.implemented:
ambiguous = (prop.default is not None) and prop.required
self.assertFalse(ambiguous,
"The definition of the property '{0}' "
"in resource '{1}' is ambiguous: it "
"has default value and required flag. "
"Please delete one of these options."
.format(prop_name, res_name))
if prop.schema is not None:
if isinstance(prop.schema, constraints.AnyIndexDict):
_validate_property_schema(
prop_name,
prop.schema.value,
res_name)
else:
for nest_prop_name, nest_prop in six.iteritems(
prop.schema):
_validate_property_schema(nest_prop_name,
nest_prop,
res_name)
resource_types = env.get_types()
for res_type in resource_types:
res_class = env.get_class(res_type)
if hasattr(res_class, "properties_schema"):
for property_schema_name, property_schema in six.iteritems(
res_class.properties_schema):
_validate_property_schema(
property_schema_name, property_schema,
res_class.__name__)
class ResourceAdoptTest(common.HeatTestCase): class ResourceAdoptTest(common.HeatTestCase):
def setUp(self): def setUp(self):