template-validate fails when using parameters with custom_constraint and default

Bug #1314240 reported by Thomas Spatzier
10
This bug affects 2 people
Affects Status Importance Assigned to Milestone
OpenStack Heat
Fix Released
High
Thomas Spatzier
Icehouse
Fix Released
High
Thomas Spatzier

Bug Description

When using a template with parameters than have both a custom_constraint (e.g. nova.flavor) and a default value, both template-validate and stack-create fail with an exception.

A first look into the code revealed that the rpc context is None in the place where validation of the custom constraint is done (and therefore openstack clients are being used). Seems like the rpc context is not properly propagated in that path.

Steps to reproduce:

Use the template below and then just try a 'heat stack-create' or 'heat template-validate'.

Template:
#######

heat_template_version: 2013-05-23

description: Just a simple test template.

parameters:
  key_name:
    type: string
    description: Name of an existing key pair to use for the instance.
    default: heat_key
  flavor:
    type: string
    description: Flavor for the server to be created.
    default: m1.tiny
    constraints:
      - custom_constraint: nova.flavor
  image:
    type: string
    description: The image to use for the server.

resources:
  my_server:
    type: OS::Nova::Server
    properties:
      key_name: { get_param: key_name }
      image: { get_param: image }
      flavor: { get_param: flavor }

outputs:
  server_ip:
    description: The IP address of the deployed server.
    value: { get_attr: [my_server, networks, private, 0] }

Changed in heat:
assignee: nobody → Thomas Spatzier (thomas-spatzier)
Changed in heat:
status: New → In Progress
Revision history for this message
Openstack Gerrit (openstack-gerrit) wrote : Fix proposed to heat (master)

Fix proposed to branch: master
Review: https://review.openstack.org/91485

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to heat (master)

Reviewed: https://review.openstack.org/91485
Committed: https://git.openstack.org/cgit/openstack/heat/commit/?id=19f83e84269e1aec2d299ada616a4648e00f4333
Submitter: Jenkins
Branch: master

commit 19f83e84269e1aec2d299ada616a4648e00f4333
Author: Thomas Spatzier <email address hidden>
Date: Wed Apr 30 19:18:16 2014 +0200

    Do not validate constraints in schema constructor

    This patch moves validation of constraints out of the constructor of
    schema objects into a separate method that can be invoked on the
    schema objects after creation. This gives us more control over when
    validation shall be invoked.

    This patch fixes an issue with custom constraints that could not be
    validated when having a default value, since they require the RPC
    context to be present. However, the context was not present in the
    places where needed.
    The short-sighted fix would have been to change a lot of method
    signatures to pass the context properly, but that did not seem to be
    really clean. The better fix seemed to be to move validation into
    a separate method that can be invoked with the proper context. This
    will also give us more control on when we do validation, and which
    validation we do.

    This patch
    Closes-Bug: #1314240

    This patch will also enable to fix
    Partial-Bug: #1314401

    For that bug it will be necessary to switch off validation under
    certain conditions, which was not possible before when doing
    validation right in the constructor.

    Change-Id: I19e1fb520551eb42bf36bb380f1cc28c81bbaedd

Changed in heat:
status: In Progress → Fix Committed
Steven Hardy (shardy)
Changed in heat:
importance: Undecided → High
tags: added: icehouse-backport-potential
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to heat (stable/icehouse)

Fix proposed to branch: stable/icehouse
Review: https://review.openstack.org/98785

Revision history for this message
OpenStack Infra (hudson-openstack) wrote :

Fix proposed to branch: stable/icehouse
Review: https://review.openstack.org/99011

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Change abandoned on heat (stable/icehouse)

Change abandoned by Thomas Spatzier (<email address hidden>) on branch: stable/icehouse
Review: https://review.openstack.org/98785

Thierry Carrez (ttx)
Changed in heat:
milestone: none → juno-1
status: Fix Committed → Fix Released
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to heat (stable/icehouse)

Reviewed: https://review.openstack.org/99011
Committed: https://git.openstack.org/cgit/openstack/heat/commit/?id=aa7c0306bcc77320b670e0e15895b4b6b3944250
Submitter: Jenkins
Branch: stable/icehouse

commit aa7c0306bcc77320b670e0e15895b4b6b3944250
Author: Thomas Spatzier <email address hidden>
Date: Wed Apr 30 19:18:16 2014 +0200

    Do not validate constraints in schema constructor

    This patch moves validation of constraints out of the constructor of
    schema objects into a separate method that can be invoked on the
    schema objects after creation. This gives us more control over when
    validation shall be invoked.

    This patch fixes an issue with custom constraints that could not be
    validated when having a default value, since they require the RPC
    context to be present. However, the context was not present in the
    places where needed.
    The short-sighted fix would have been to change a lot of method
    signatures to pass the context properly, but that did not seem to be
    really clean. The better fix seemed to be to move validation into
    a separate method that can be invoked with the proper context. This
    will also give us more control on when we do validation, and which
    validation we do.

    This patch
    Closes-Bug: #1314240

    This patch will also enable to fix
    Partial-Bug: #1314401

    For that bug it will be necessary to switch off validation under
    certain conditions, which was not possible before when doing
    validation right in the constructor.

    Cherry-pick from review https://review.openstack.org/#/c/91485
    (cherry picked from commit 19f83e84269e1aec2d299ada616a4648e00f4333)

    Conflicts:

            heat/engine/parameters.py
            heat/engine/service.py
            heat/tests/test_hot.py

    Change-Id: I19e1fb520551eb42bf36bb380f1cc28c81bbaedd

Thierry Carrez (ttx)
Changed in heat:
milestone: juno-1 → 2014.2
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.