def test_collect_ec2_collected(self, cd): cd.return_value = None collect.setup_conf() cache_dir = self.useFixture(fixtures.TempDir()) self.addCleanup(cfg.CONF.reset) cfg.CONF.set_override('cachedir', cache_dir.path) ec2_path = os.path.join(cache_dir.path, 'ec2.json') with open(ec2_path, 'w') as f: json.dump(META_DATA, f) collect_ec2 = ec2.Collector(requests_impl=FakeFailRequests) self.assertEqual([('ec2', META_DATA)], collect_ec2.collect())
def test_collect_ec2_invalid_cache(self, cd): cd.return_value = None collect.setup_conf() cache_dir = self.useFixture(fixtures.TempDir()) self.addCleanup(cfg.CONF.reset) cfg.CONF.set_override('cachedir', cache_dir.path) ec2_path = os.path.join(cache_dir.path, 'ec2.json') with open(ec2_path, 'w') as f: f.write('') ec2_md = ec2.Collector(requests_impl=FakeRequests).collect() self.assertEqual([('ec2', META_DATA_RESOLVED)], ec2_md)
def test_collect_ec2(self): collect.setup_conf() ec2_md = ec2.Collector(requests_impl=FakeRequests).collect() 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) self.assertEqual(ec2_md[k], META_DATA[k]) self.assertEqual(ec2_md['block-device-mapping']['ami'], 'vda') # SSH keys are special cases self.assertEqual( {'0': {'openssh-key': 'ssh-rsa AAAAAAAAABBBBBBBBCCCCCCCC'}}, ec2_md['public-keys']) self.assertEqual('', self.log.output)
def test_collect_config_drive(self, cd): cd.return_value.get_metadata.return_value = META_DATA_RESOLVED collect.setup_conf() ec2_md = ec2.Collector(requests_impl=FakeFailRequests).collect() self.assertEqual([('ec2', META_DATA_RESOLVED)], ec2_md) self.assertEqual('', self.log.output)
def test_collect_ec2_fail(self, cd): cd.return_value = None collect.setup_conf() collect_ec2 = ec2.Collector(requests_impl=FakeFailRequests) self.assertRaises(exc.Ec2MetadataNotAvailable, collect_ec2.collect) self.assertIn('Forbidden', self.log.output)
def test_collect_ec2(self, cd): cd.return_value = None collect.setup_conf() ec2_md = ec2.Collector(requests_impl=FakeRequests).collect() self.assertEqual([('ec2', META_DATA_RESOLVED)], ec2_md) self.assertEqual('', self.log.output)