From a3a93a91303028fc986115797ddca1242c2bbaca Mon Sep 17 00:00:00 2001 From: Clint Byrum Date: Wed, 3 Jul 2013 17:29:04 -0700 Subject: [PATCH] Enable heat_local collector. --- os_collect_config/collect.py | 4 ++-- os_collect_config/heat_local.py | 3 ++- os_collect_config/tests/test_collect.py | 18 +++++++++++++++++- 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/os_collect_config/collect.py b/os_collect_config/collect.py index d30c58d..57fc1fa 100644 --- a/os_collect_config/collect.py +++ b/os_collect_config/collect.py @@ -39,7 +39,7 @@ opts = [ CONF = cfg.CONF logger = log.getLogger('os-collect-config') -COLLECTORS = (ec2, cfn) +COLLECTORS = (ec2, cfn, heat_local) def setup_conf(): @@ -49,7 +49,7 @@ def setup_conf(): cfn_group = cfg.OptGroup(name='cfn', title='CloudFormation API Metadata options') - heat_local_group = cfg.OptGroup(name='heat-local', + heat_local_group = cfg.OptGroup(name='heat_local', title='Heat Local Metadata options') CONF.register_group(ec2_group) diff --git a/os_collect_config/heat_local.py b/os_collect_config/heat_local.py index 9d00a52..c3f37a6 100644 --- a/os_collect_config/heat_local.py +++ b/os_collect_config/heat_local.py @@ -51,6 +51,7 @@ class Collector(object): else: final_content = value if not final_content: - logger.warn('Local metadata not found') + logger.warn('Local metadata not found (%s)' % + cfg.CONF.heat_local.path) raise exc.HeatLocalMetadataNotAvailable return final_content diff --git a/os_collect_config/tests/test_collect.py b/os_collect_config/tests/test_collect.py index 16f816e..f5e6d87 100644 --- a/os_collect_config/tests/test_collect.py +++ b/os_collect_config/tests/test_collect.py @@ -19,12 +19,22 @@ import fixtures import json import os from oslo.config import cfg +import tempfile import testtools from testtools import matchers from os_collect_config import collect from os_collect_config.tests import test_cfn from os_collect_config.tests import test_ec2 +from os_collect_config.tests import test_heat_local + + +def _setup_local_metadata(test_case): + test_case.useFixture(fixtures.NestedTempfile()) + local_md = tempfile.NamedTemporaryFile(delete=False) + local_md.write(json.dumps(test_heat_local.META_DATA)) + local_md.flush() + return local_md.name class TestCollect(testtools.TestCase): @@ -58,8 +68,10 @@ class TestCollect(testtools.TestCase): '0123456789ABCDEF', '--cfn-secret-access-key', 'FEDCBA9876543210', - ] + fake_metadata = _setup_local_metadata(self) + fake_args.append('--heat_local-path') + fake_args.append(fake_metadata) self.called_fake_call = False def fake_call(args, env, shell): @@ -102,6 +114,9 @@ class TestCollect(testtools.TestCase): '--cfn-secret-access-key', 'FEDCBA9876543210', ] + fake_metadata = _setup_local_metadata(self) + fake_args.append('--heat_local-path') + fake_args.append(fake_metadata) output = self.useFixture(fixtures.ByteStream('stdout')) self.useFixture( fixtures.MonkeyPatch('sys.stdout', output.stream)) @@ -130,6 +145,7 @@ class TestCollectAll(testtools.TestCase): cfg.CONF.cfn.path = ['foo.Metadata'] cfg.CONF.cfn.access_key_id = '0123456789ABCDEF' cfg.CONF.cfn.secret_access_key = 'FEDCBA9876543210' + cfg.CONF.heat_local.path = [_setup_local_metadata(self)] def _call_collect_all(self, store, requests_impl_map=None): if requests_impl_map is None: