def test_metadata_retrieve_files(self): md_data = { "AWS::CloudFormation::Init": { "config": { "files": { "/tmp/foo": { "content": "bar" } } } } } md_str = json.dumps(md_data) md = cfn_helper.Metadata('teststack', None) with tempfile.NamedTemporaryFile(mode='w+') as default_file: default_file.write(md_str) default_file.flush() self.assertThat(default_file.name, ttm.FileContains(md_str)) self.assertTrue( md.retrieve(default_path=default_file.name, last_path=self.last_file)) self.assertThat(self.last_file, ttm.FileContains(md_str)) self.assertThat(md_data, ttm.Equals(md._metadata)) md = cfn_helper.Metadata('teststack', None) self.assertTrue( md.retrieve(default_path=default_file.name, last_path=self.last_file)) self.assertThat(md_data, ttm.Equals(md._metadata))
def test_cfn_init(self): with tempfile.NamedTemporaryFile(mode='w+') as foo_file: md_data = {"AWS::CloudFormation::Init": {"config": {"files": { foo_file.name: {"content": "bar"}}}}} md = cfn_helper.Metadata('teststack', None) self.assertTrue( md.retrieve(meta_str=md_data, last_path=self.last_file)) md.cfn_init() self.assertThat(foo_file.name, ttm.FileContains('bar'))
def test_smoke(self): output = os.path.join( self.useFixture(fixtures.TempDir()).path, 'output') stdin = io.BytesIO() stdout = io.StringIO() writer = v2.StreamResultToBytes(stdin) writer.startTestRun() writer.status('foo', 'success', set(['tag']), file_name='fred', file_bytes=b'abcdefg', eof=True, mime_type='text/plain') writer.stopTestRun() stdin.seek(0) _to_disk.to_disk(['-d', output], stdin=stdin, stdout=stdout) self.expectThat( os.path.join(output, 'foo/test.json'), matchers.FileContains( '{"details": ["fred"], "id": "foo", "start": null, ' '"status": "success", "stop": null, "tags": ["tag"]}')) self.expectThat(os.path.join(output, 'foo/fred'), matchers.FileContains('abcdefg'))
def test_nova_meta_with_cache(self): meta_in = {"uuid": "f9431d18-d971-434d-9044-5b38f5b4646f", "availability_zone": "nova", "hostname": "as-wikidatabase-4ykioj3lgi57.novalocal", "launch_index": 0, "meta": {}, "public_keys": {"heat_key": "ssh-rsa etc...\n"}, "name": "as-WikiDatabase-4ykioj3lgi57"} md_str = json.dumps(meta_in) md = cfn_helper.Metadata('teststack', None) with tempfile.NamedTemporaryFile(mode='w+') as default_file: default_file.write(md_str) default_file.flush() self.assertThat(default_file.name, ttm.FileContains(md_str)) meta_out = md.get_nova_meta(cache_path=default_file.name) self.assertEqual(meta_in, meta_out)
def write_cache_file(*params, **kwargs): with open(cache_path, 'w+') as cache_file: cache_file.write(md_str) cache_file.flush() self.assertThat(cache_file.name, ttm.FileContains(md_str))