Get rid of undesirable properties.data usage

Remove all undesirable properties.data usages in resource
plugins. This usages can be harmless replaced with self.properties.

Change-Id: Ic8f619adc09fc5a2bd8e5cdb02d058199318b6c9
This commit is contained in:
Peter Razumovsky 2017-03-23 16:01:32 +04:00 committed by Zane Bitter
parent b9120e205e
commit b386d97825
7 changed files with 39 additions and 29 deletions

View File

@ -113,6 +113,14 @@ manipulate when including that resource in a template. Some examples would be:
* The port to listen to on Neutron LBaaS nodes
* The size of a Cinder volume
.. note::
Properties should normally be accessed through self.properties.
This resolves intrinsic functions, provides default values when required
and performs property translation for backward compatible schema changes.
The self.properties.data dict provides access to the raw data supplied by
the user in the template without any of those transformations.
*Attributes* describe runtime state data of the physical resource that the
plug-in can expose to other resources in a Stack. Generally, these aren't
available until the physical resource has been created and is in a usable

View File

@ -11,8 +11,6 @@
# License for the specific language governing permissions and limitations
# under the License.
import copy
from heat.common import exception
from heat.common.i18n import _
from heat.engine import constraints
@ -150,20 +148,20 @@ class CinderQuota(resource.Resource):
if props is None:
props = self.properties
args = copy.copy(props.data)
project = args.pop(self.PROJECT)
kwargs = dict((k, v) for k, v in props.items()
if k != self.PROJECT and v is not None)
# TODO(ricolin): Move this to stack validate stage. In some cases
# we still can't get project or other properties form other resources
# at validate stage.
self.validate_quotas(project, **args)
self.client().quotas.update(project, **args)
self.validate_quotas(props[self.PROJECT], **kwargs)
self.client().quotas.update(props[self.PROJECT], **kwargs)
def handle_delete(self):
self.client().quotas.delete(self.properties[self.PROJECT])
def validate(self):
super(CinderQuota, self).validate()
if len(self.properties.data) == 1:
if sum(1 for p in self.properties.values() if p is not None) <= 1:
raise exception.PropertyUnspecifiedError(self.GIGABYTES,
self.SNAPSHOTS,
self.VOLUMES)

View File

@ -18,7 +18,6 @@ from heat.common import short_id
from heat.common import timeutils as iso8601utils
from heat.engine import attributes
from heat.engine import environment
from heat.engine import function
from heat.engine import properties
from heat.engine.resources import stack_resource
from heat.engine import rsrc_defn
@ -225,10 +224,15 @@ class InstanceGroup(stack_resource.StackResource):
def _get_conf_properties(self):
conf_refid = self.properties[self.LAUNCH_CONFIGURATION_NAME]
conf = self.stack.resource_by_refid(conf_refid)
props = function.resolve(conf.properties.data)
props = dict((k, v) for k, v in conf.properties.items()
if k in conf.properties.data)
for key in [conf.BLOCK_DEVICE_MAPPINGS, conf.NOVA_SCHEDULER_HINTS]:
if props.get(key) is not None:
props[key] = list(dict((k, v) for k, v in prop.items()
if k in conf.properties.data[key][idx])
for idx, prop in enumerate(props[key]))
if 'InstanceId' in props:
props = conf.rebuild_lc_properties(props['InstanceId'])
props['Tags'] = self._tags()
# if the launch configuration is created from an existing instance.
# delete the 'InstanceId' property

View File

@ -20,7 +20,6 @@ from heat.common.i18n import _
from heat.common import template_format
from heat.engine import attributes
from heat.engine import environment
from heat.engine import function
from heat.engine import properties
from heat.engine import resource
from heat.engine import template
@ -199,7 +198,8 @@ class RemoteStack(resource.Resource):
env = environment.Environment(s_data['environment'])
files = s_data['files']
tmpl = template.Template(s_data['template'], env=env, files=files)
props = function.resolve(self.properties.data)
props = dict((k, v) for k, v in self.properties.items()
if k in self.properties.data)
props[self.TEMPLATE] = jsonutils.dumps(tmpl.t)
props[self.PARAMETERS] = env.params

View File

@ -11,8 +11,6 @@
# License for the specific language governing permissions and limitations
# under the License.
import copy
from heat.common import exception
from heat.common.i18n import _
from heat.engine import constraints
@ -135,11 +133,10 @@ class NeutronQuota(neutron.NeutronResource):
if props is None:
props = self.properties
args = copy.copy(props.data)
project = args.pop(self.PROJECT)
body = {"quota": args}
self.client().update_quota(project, body)
kwargs = dict((k, v) for k, v in props.items()
if k != self.PROJECT and v is not None)
body = {"quota": kwargs}
self.client().update_quota(props[self.PROJECT], body)
def handle_delete(self):
if self.resource_id is not None:
@ -148,7 +145,7 @@ class NeutronQuota(neutron.NeutronResource):
def validate(self):
super(NeutronQuota, self).validate()
if len(self.properties.data) == 1:
if sum(1 for p in self.properties.values() if p is not None) <= 1:
raise exception.PropertyUnspecifiedError(
*sorted(set(self.PROPERTIES) - {self.PROJECT}))

View File

@ -11,8 +11,6 @@
# License for the specific language governing permissions and limitations
# under the License.
import copy
from heat.common import exception
from heat.common.i18n import _
from heat.engine import constraints
@ -228,17 +226,16 @@ class NovaQuota(resource.Resource):
if props is None:
props = self.properties
args = copy.copy(props.data)
project = args.pop(self.PROJECT)
self.client().quotas.update(project, **args)
kwargs = dict((k, v) for k, v in props.items()
if k != self.PROJECT and v is not None)
self.client().quotas.update(props.get(self.PROJECT), **kwargs)
def handle_delete(self):
self.client().quotas.delete(self.properties[self.PROJECT])
def validate(self):
super(NovaQuota, self).validate()
if len(self.properties.data) == 1:
if sum(1 for p in self.properties.values() if p is not None) <= 1:
raise exception.PropertyUnspecifiedError(
*sorted(set(self.PROPERTIES) - {self.PROJECT}))

View File

@ -23,7 +23,6 @@ from heat.common.i18n import _
from heat.engine import attributes
from heat.engine.clients import progress
from heat.engine import constraints
from heat.engine import function
from heat.engine import properties
from heat.engine.resources.openstack.neutron import port as neutron_port
from heat.engine.resources.openstack.neutron import subnet
@ -1579,7 +1578,14 @@ class Server(server_base.BaseServer, sh.SchedulerHintsMixin,
def handle_restore(self, defn, restore_data):
image_id = restore_data['resource_data']['snapshot_image_id']
props = function.resolve(self.properties.data)
props = dict((k, v) for k, v in self.properties.items()
if k in self.properties.data)
for key in [self.BLOCK_DEVICE_MAPPING, self.BLOCK_DEVICE_MAPPING_V2,
self.NETWORKS]:
if props.get(key) is not None:
props[key] = list(dict((k, v) for k, v in prop.items()
if v is not None)
for prop in props[key])
props[self.IMAGE] = image_id
return defn.freeze(properties=props)