random failures in unit tests with "AttributeError: 'NoneType' object has no attribute 'keys'"

Bug #1397468 reported by Miguel Grinberg
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
OpenStack Heat
Fix Released
Undecided
Miguel Grinberg

Bug Description

I occasionally see the following error in unit testing runs:

    Traceback (most recent call last):
    File "heat/tests/test_validate.py", line 1401, in test_validate_invalid_parameter_in_group
        template = tmpl.HOTemplate20130523(t)
    File "heat/engine/template.py", line 108, in __init__
        self.version = get_version(self.t, _template_classes.keys())
    AttributeError: 'NoneType' object has no attribute 'keys'

This occurs in tests that instantiate a specific Template subclass instead of using Template() and letting the system pick the most appropriate class. There are only three tests in the unit testing suite that do this.

The problem is that the Template() constructor accesses the _template_classes global, but this global variable is created the first time the Template() constructor is invoked directly (i.e. not as a result of constructing a subclass). This creates a race condition in the unit testing suite, depending on the order the tests run the global variable may or may not be initialized by the time these three tests get to run.

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

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

Changed in heat:
assignee: nobody → Miguel Grinberg (miguelgrinberg)
status: New → In Progress
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to heat (master)

Reviewed: https://review.openstack.org/137867
Committed: https://git.openstack.org/cgit/openstack/heat/commit/?id=5e2ee8a42c3791986bfa9d69b7c6032cccb3252c
Submitter: Jenkins
Branch: master

commit 5e2ee8a42c3791986bfa9d69b7c6032cccb3252c
Author: Miguel Grinberg <email address hidden>
Date: Sat Nov 29 00:08:22 2014 +0000

    Populate _template_classes global on first use

    This change ensures that the _template_classes global variable is always
    initialized when the first template is created. This was done when
    instantiating the Template base class, but it was missed when creating an
    instance of any of its subclasses.

    Change-Id: I5edc9f06d6b48bb04e8ed41365823021ef133909
    Closes-Bug: 1397468

Changed in heat:
status: In Progress → Fix Committed
Thierry Carrez (ttx)
Changed in heat:
milestone: none → kilo-1
status: Fix Committed → Fix Released
Thierry Carrez (ttx)
Changed in heat:
milestone: kilo-1 → 2015.1.0
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.