def test_get_legacy_templates_with_defaults(self): expected_templates = {} for f in FAKES.flavors: if not f.is_public: continue name = f.name.strip().replace(' ', '_').replace('.', '-').lower() expected_templates[f.id] = { 'template_memory': f.ram, 'template_cpu': f.vcpus, 'template_id': 'resource_tpl#%s' % name, 'template_platform': 'amd64', 'template_network': 'private' } self.provider.legacy_occi_os = True with utils.nested( mock.patch.object(self.provider.static, 'get_template_defaults'), mock.patch.object(self.provider.api.flavors, 'list'), ) as (m_get_template_defaults, m_flavors_list): m_get_template_defaults.return_value = {} m_flavors_list.return_value = FAKES.flavors templates = self.provider.get_templates() assert m_get_template_defaults.called self.assert_resources(expected_templates, templates, template="execution_environment.ldif", ignored_fields=["compute_service_name"])
def test_get_templates_with_defaults_from_static(self): expected_templates = {} for f in FAKES.flavors: if not f.is_public: continue expected_templates[f.id] = { 'template_memory': f.ram, 'template_cpu': f.vcpus, 'template_id': 'resource_tpl#%s' % f.id, 'template_platform': 'i686', 'template_network': 'private' } with utils.nested( mock.patch.object(self.provider.static, 'get_template_defaults'), mock.patch.object(self.provider.api.flavors, 'list'), ) as (m_get_template_defaults, m_flavors_list): m_get_template_defaults.return_value = { 'template_platform': 'i686' } m_flavors_list.return_value = FAKES.flavors templates = self.provider.get_templates() assert m_get_template_defaults.called self.assert_resources(expected_templates, templates, template="execution_environment.ldif", ignored_fields=["compute_service_name"])
def test_main(self): with utils.nested( mock.patch.object(cloud_bdii.core, 'parse_opts'), mock.patch('cloud_bdii.core.CloudBDII'), mock.patch('cloud_bdii.core.ComputeBDII'), mock.patch('cloud_bdii.core.StorageBDII') ) as (m0, m1, m2, m3): m0.return_value = None for i in (m1, m2, m3): i = i.return_value i.render.return_value = 'foo' self.assertIsNone(cloud_bdii.core.main()) for i in (m0, m1, m2, m3): assert i.called
def test_load_templates(self): self.opts.template_dir = 'foobar' tpls = ('foo', 'bar') tpl_contents = 'foo %(fobble)s' info = {'fobble': 'burble', 'brongle': 'farbla'} expected = tpl_contents % info bdii = cloud_bdii.core.BaseBDII(self.opts) with utils.nested( mock.patch.object(bdii, 'templates', tpls), mock.patch('cloud_bdii.core.open', mock.mock_open(read_data=tpl_contents), create=True) ) as (m_templates, m_open): bdii.load_templates() for tpl in tpls: m_open.assert_any_call( os.path.join(self.opts.template_dir, '%s.ldif' % tpl), 'r' ) self.assertEqual(expected, bdii._format_template('foo', info))
def test_get_images(self): expected_images = { 'bar id': { 'image_description': None, 'image_name': 'barimage', 'image_os_family': None, 'image_os_name': None, 'image_os_version': None, 'image_platform': 'amd64', 'image_version': None, 'image_marketplace_id': None, 'image_id': 'os_tpl#bar_id' }, 'foo.id': { 'image_description': None, 'image_name': 'fooimage', 'image_os_family': None, 'image_os_name': None, 'image_os_version': None, 'image_platform': 'amd64', 'image_version': None, 'image_marketplace_id': 'http://example.org/', 'image_id': 'os_tpl#foo-id' } } with utils.nested( mock.patch.object(self.provider.static, 'get_image_defaults'), mock.patch.object(self.provider.api.images, 'list'), ) as (m_get_image_defaults, m_images_list): m_get_image_defaults.return_value = {} m_images_list.return_value = FAKES.images images = self.provider.get_images() assert m_get_image_defaults.called self.assert_resources(expected_images, images, template="application_environment.ldif", ignored_fields=["compute_service_name"])
def test_get_info_from_providers(self): cases = ( ( {}, {}, {} ), ( {'foo': 'bar'}, {'bar': 'bazonk'}, {'foo': 'bar', 'bar': 'bazonk'}, ), ( {'foo': 'bar'}, {'foo': 'bazonk'}, {'foo': 'bazonk'}, ), ( {}, {'foo': 'bazonk'}, {'foo': 'bazonk'}, ), ( {'foo': 'bar'}, {}, {'foo': 'bar'}, ), ) bdii = cloud_bdii.core.BaseBDII(self.opts) for s, d, e in cases: with utils.nested( mock.patch.object(bdii.static_provider, 'foomethod'), mock.patch.object(bdii.dynamic_provider, 'foomethod') ) as (m_static, m_dynamic): m_static.return_value = s m_dynamic.return_value = d self.assertEqual(e, bdii._get_info_from_providers('foomethod'))