Change collector interface to return a list
With the new OS::Heat::StructuredDeployment resource, each Metadata section may have multiple "deployments" in it. With this, we will return a list with tuples of key and content to write to the cache. Change-Id: I9f4272b0761e1dfd850bc5a5c6b27a78f126281f Related-Bug: #1295787
This commit is contained in:
parent
86e677a6af
commit
16158684a6
|
@ -126,4 +126,4 @@ class Collector(object):
|
|||
'Sub-key %s does not exist. (%s)' % (subkey, path))
|
||||
raise exc.CfnMetadataNotAvailable
|
||||
final_content.update(value)
|
||||
return final_content
|
||||
return [('cfn', final_content)]
|
||||
|
|
|
@ -124,11 +124,12 @@ def collect_all(collectors, store=False, requests_impl_map=None):
|
|||
continue
|
||||
|
||||
if store:
|
||||
(changed, path) = cache.store(collector, content)
|
||||
any_changed |= changed
|
||||
paths_or_content.append(path)
|
||||
for output_key, output_content in content:
|
||||
(changed, path) = cache.store(output_key, output_content)
|
||||
any_changed |= changed
|
||||
paths_or_content.append(path)
|
||||
else:
|
||||
paths_or_content[collector] = content
|
||||
paths_or_content.update(content)
|
||||
|
||||
if any_changed:
|
||||
cache.store_meta_list('os_config_files', collectors)
|
||||
|
|
|
@ -57,4 +57,4 @@ class Collector(object):
|
|||
|
||||
def collect(self):
|
||||
root_url = '%s/' % (CONF.ec2.metadata_url)
|
||||
return self._fetch_metadata(root_url)
|
||||
return [('ec2', self._fetch_metadata(root_url))]
|
||||
|
|
|
@ -54,4 +54,4 @@ class Collector(object):
|
|||
logger.warn('Local metadata not found (%s)' %
|
||||
cfg.CONF.heat_local.path)
|
||||
raise exc.HeatLocalMetadataNotAvailable
|
||||
return final_content
|
||||
return [('heat_local', final_content)]
|
||||
|
|
|
@ -109,7 +109,9 @@ class TestCfn(testtools.TestCase):
|
|||
|
||||
def test_collect_cfn(self):
|
||||
cfn_md = cfn.Collector(requests_impl=FakeRequests(self)).collect()
|
||||
self.assertThat(cfn_md, matchers.IsInstance(dict))
|
||||
self.assertThat(cfn_md, matchers.IsInstance(list))
|
||||
self.assertEqual('cfn', cfn_md[0][0])
|
||||
cfn_md = cfn_md[0][1]
|
||||
|
||||
for k in ('int1', 'strfoo', 'map_ab'):
|
||||
self.assertIn(k, cfn_md)
|
||||
|
@ -150,7 +152,9 @@ class TestCfn(testtools.TestCase):
|
|||
cfg.CONF.cfn.path = ['foo.Metadata.map_ab']
|
||||
cfn_collect = cfn.Collector(requests_impl=FakeRequests(self))
|
||||
content = cfn_collect.collect()
|
||||
self.assertThat(content, matchers.IsInstance(dict))
|
||||
self.assertThat(content, matchers.IsInstance(list))
|
||||
self.assertEqual('cfn', content[0][0])
|
||||
content = content[0][1]
|
||||
self.assertIn(u'b', content)
|
||||
self.assertEqual(u'banana', content[u'b'])
|
||||
|
||||
|
|
|
@ -92,7 +92,9 @@ class TestEc2(testtools.TestCase):
|
|||
def test_collect_ec2(self):
|
||||
collect.setup_conf()
|
||||
ec2_md = ec2.Collector(requests_impl=FakeRequests).collect()
|
||||
self.assertThat(ec2_md, matchers.IsInstance(dict))
|
||||
self.assertThat(ec2_md, matchers.IsInstance(list))
|
||||
self.assertEqual('ec2', ec2_md[0][0])
|
||||
ec2_md = ec2_md[0][1]
|
||||
|
||||
for k in ('public-ipv4', 'instance-id', 'hostname'):
|
||||
self.assertIn(k, ec2_md)
|
||||
|
|
|
@ -48,7 +48,9 @@ class TestHeatLocal(testtools.TestCase):
|
|||
|
||||
def _call_collect(self, temp_name):
|
||||
cfg.CONF.heat_local.path = [temp_name]
|
||||
return heat_local.Collector().collect()
|
||||
md = heat_local.Collector().collect()
|
||||
self.assertEqual('heat_local', md[0][0])
|
||||
return md[0][1]
|
||||
|
||||
def test_collect_heat_local(self):
|
||||
with tempfile.NamedTemporaryFile() as md:
|
||||
|
|
Loading…
Reference in New Issue