Don't replace (and log) the same resource entry

Resources may be registered multiple times. This
ensures that logs are only emitted the first time
a resource is registered.

Change-Id: Iedd12d55007ee24ea6ecbe4fe7152ff65ea665b0
This commit is contained in:
Angus Salkeld 2013-12-11 17:04:17 +11:00
parent 700563477c
commit e889b86dae
3 changed files with 47 additions and 1 deletions

View File

@ -197,6 +197,8 @@ class ResourceRegistry(object):
return
if name in registry and isinstance(registry[name], ResourceInfo):
if registry[name] == info:
return
details = {
'path': descriptive_path,
'was': str(registry[name].value),

View File

@ -36,7 +36,7 @@ class HeatTestCase(testtools.TestCase):
super(HeatTestCase, self).setUp()
self.m = mox.Mox()
self.addCleanup(self.m.UnsetStubs)
self.useFixture(fixtures.FakeLogger(level=logging.DEBUG))
self.logger = self.useFixture(fixtures.FakeLogger(level=logging.DEBUG))
scheduler.ENABLE_SLEEP = False
self.useFixture(fixtures.MonkeyPatch(
'heat.common.exception._FATAL_EXCEPTION_FORMAT_ERRORS',

View File

@ -15,6 +15,7 @@
import fixtures
import mock
import os.path
import testscenarios
from oslo.config import cfg
@ -29,6 +30,9 @@ from heat.tests import generic_resource
from heat.tests import common
load_tests = testscenarios.load_tests_apply_scenarios
class EnvironmentTest(common.HeatTestCase):
def setUp(self):
super(EnvironmentTest, self).setUp()
@ -107,6 +111,46 @@ class EnvironmentTest(common.HeatTestCase):
'my_fip').value)
class EnvironmentDuplicateTest(common.HeatTestCase):
scenarios = [
('same', dict(resource_type='test.yaml',
expected_equal=True)),
('diff_temp', dict(resource_type='not.yaml',
expected_equal=False)),
('diff_map', dict(resource_type='OS::SomethingElse',
expected_equal=False)),
('diff_path', dict(resource_type='a/test.yaml',
expected_equal=False)),
]
def test_env_load(self):
env_initial = {u'resource_registry': {
u'OS::Test::Dummy': 'test.yaml'}}
env = environment.Environment()
env.load(env_initial)
info = env.get_resource_info('OS::Test::Dummy', 'something')
replace_log = 'Changing %s from %s to %s' % ('OS::Test::Dummy',
'test.yaml',
self.resource_type)
self.assertNotIn(replace_log, self.logger.output)
env_test = {u'resource_registry': {
u'OS::Test::Dummy': self.resource_type}}
env.load(env_test)
if self.expected_equal:
# should return exactly the same object.
self.assertIs(info, env.get_resource_info('OS::Test::Dummy',
'my_fip'))
self.assertNotIn(replace_log, self.logger.output)
else:
self.assertIn(replace_log, self.logger.output)
self.assertNotEqual(info,
env.get_resource_info('OS::Test::Dummy',
'my_fip'))
class GlobalEnvLoadingTest(common.HeatTestCase):
def test_happy_path(self):