Enable heat_local collector.

This commit is contained in:
Clint Byrum 2013-07-03 17:29:04 -07:00
parent c42f3e46a7
commit a3a93a9130
3 changed files with 21 additions and 4 deletions

View File

@ -39,7 +39,7 @@ opts = [
CONF = cfg.CONF CONF = cfg.CONF
logger = log.getLogger('os-collect-config') logger = log.getLogger('os-collect-config')
COLLECTORS = (ec2, cfn) COLLECTORS = (ec2, cfn, heat_local)
def setup_conf(): def setup_conf():
@ -49,7 +49,7 @@ def setup_conf():
cfn_group = cfg.OptGroup(name='cfn', cfn_group = cfg.OptGroup(name='cfn',
title='CloudFormation API Metadata options') 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') title='Heat Local Metadata options')
CONF.register_group(ec2_group) CONF.register_group(ec2_group)

View File

@ -51,6 +51,7 @@ class Collector(object):
else: else:
final_content = value final_content = value
if not final_content: 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 raise exc.HeatLocalMetadataNotAvailable
return final_content return final_content

View File

@ -19,12 +19,22 @@ import fixtures
import json import json
import os import os
from oslo.config import cfg from oslo.config import cfg
import tempfile
import testtools import testtools
from testtools import matchers from testtools import matchers
from os_collect_config import collect from os_collect_config import collect
from os_collect_config.tests import test_cfn from os_collect_config.tests import test_cfn
from os_collect_config.tests import test_ec2 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): class TestCollect(testtools.TestCase):
@ -58,8 +68,10 @@ class TestCollect(testtools.TestCase):
'0123456789ABCDEF', '0123456789ABCDEF',
'--cfn-secret-access-key', '--cfn-secret-access-key',
'FEDCBA9876543210', 'FEDCBA9876543210',
] ]
fake_metadata = _setup_local_metadata(self)
fake_args.append('--heat_local-path')
fake_args.append(fake_metadata)
self.called_fake_call = False self.called_fake_call = False
def fake_call(args, env, shell): def fake_call(args, env, shell):
@ -102,6 +114,9 @@ class TestCollect(testtools.TestCase):
'--cfn-secret-access-key', '--cfn-secret-access-key',
'FEDCBA9876543210', 'FEDCBA9876543210',
] ]
fake_metadata = _setup_local_metadata(self)
fake_args.append('--heat_local-path')
fake_args.append(fake_metadata)
output = self.useFixture(fixtures.ByteStream('stdout')) output = self.useFixture(fixtures.ByteStream('stdout'))
self.useFixture( self.useFixture(
fixtures.MonkeyPatch('sys.stdout', output.stream)) fixtures.MonkeyPatch('sys.stdout', output.stream))
@ -130,6 +145,7 @@ class TestCollectAll(testtools.TestCase):
cfg.CONF.cfn.path = ['foo.Metadata'] cfg.CONF.cfn.path = ['foo.Metadata']
cfg.CONF.cfn.access_key_id = '0123456789ABCDEF' cfg.CONF.cfn.access_key_id = '0123456789ABCDEF'
cfg.CONF.cfn.secret_access_key = 'FEDCBA9876543210' 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): def _call_collect_all(self, store, requests_impl_map=None):
if requests_impl_map is None: if requests_impl_map is None: