Beispiel #1
0
    def test_get_templates_with_defaults(self):
        expected_templates = {}
        url = 'http://schemas.openstack.org/template/resource'
        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': '%s#%s' % (url, f.id),
                'template_platform': 'amd64',
                '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 = {}
            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="compute_bdii.ldif",
                              ignored_fields=[
                                  "compute_service_name", "image_name",
                                  "image_os_family", "image_os_name",
                                  "image_os_version", "image_platform",
                                  "image_version"
                              ])
    def test_get_images(self):
        # XXX move this to a custom class?
        # XXX add docker information
        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': 'http://schemas.openstack.org/template/os#bar_id',
                'image_native_id': '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': 'http://schemas.openstack.org/template/os#foo-id',
                'image_native_id': 'foo.id',
            },
            'baz id': {
                'image_description': None,
                'image_name': 'bazimage',
                'image_os_family': None,
                'image_os_name': None,
                'image_os_version': None,
                'image_platform': 'amd64',
                'image_version': None,
                'image_marketplace_id': None,
                'image_id': 'http://schemas.openstack.org/template/os#baz_id',
                'image_native_id': 'baz id',
                'docker_id': 'sha1:xxxxxxxxxxxxxxxxxxxxxxxxxx',
                'docker_tag': 'latest',
                'docker_name': 'test/image'
            }
        }

        with utils.nested(
                mock.patch.object(self.provider.static, 'get_image_defaults'),
                mock.patch.object(self.provider.glance.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="compute.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_info.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'))
Beispiel #4
0
    def test_get_images(self):
        # XXX move this to a custom class?
        # XXX add docker information
        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': 'http://schemas.openstack.org/template/os#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': 'http://schemas.openstack.org/template/os#foo-id'
            },
            'baz id': {
                'image_description': None,
                'image_name': 'bazimage',
                'image_os_family': None,
                'image_os_name': None,
                'image_os_version': None,
                'image_platform': 'amd64',
                'image_version': None,
                'image_marketplace_id': None,
                'image_id': 'http://schemas.openstack.org/template/os#baz_id',
                'docker_id': 'sha1:xxxxxxxxxxxxxxxxxxxxxxxxxx',
                'docker_tag': 'latest',
                'docker_name': 'test/image'
            }
        }

        with utils.nested(
                mock.patch.object(self.provider.static, 'get_image_defaults'),
                mock.patch.object(self.provider.glance.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="compute.ldif",
                              ignored_fields=["compute_service_name"])
Beispiel #5
0
    def test_load_templates(self):
        self.opts.template_dir = "foobar"
        tpls = ("foo", "bar")
        expected_tpls = {
            "foo": "foobar/foo.%s" % self.opts.template_extension,
            "bar": "foobar/bar.%s" % self.opts.template_extension,
        }

        bdii = cloud_info.core.BaseBDII(self.opts)
        with utils.nested(mock.patch.object(bdii, "templates", tpls)):
            bdii.load_templates()
            templates_files = bdii.__dict__["templates_files"]
            self.assertEqual(templates_files, expected_tpls)
    def test_load_templates(self):
        self.opts.template_dir = 'foobar'
        tpls = ('foo', 'bar')
        expected_tpls = {
            'foo': 'foobar/foo.%s' % self.opts.template_extension,
            'bar': 'foobar/bar.%s' % self.opts.template_extension
        }

        bdii = cloud_info.core.BaseBDII(self.opts)
        with utils.nested(mock.patch.object(bdii, 'templates', tpls)):
            bdii.load_templates()
            templates_files = bdii.__dict__['templates_files']
            self.assertEqual(templates_files, expected_tpls)
    def test_load_templates(self):
        self.opts.template_dir = 'foobar'
        tpls = ('foo', 'bar')
        expected_tpls = {
            'foo': 'foobar/foo.%s' % self.opts.template_extension,
            'bar': 'foobar/bar.%s' % self.opts.template_extension
        }

        bdii = cloud_info.core.BaseBDII(self.opts)
        with utils.nested(
                mock.patch.object(bdii, 'templates', tpls)):
            bdii.load_templates()
            templates_files = bdii.__dict__['templates_files']
            self.assertEqual(templates_files, expected_tpls)
    def test_main(self):
        with utils.nested(
                mock.patch.object(cloud_info.core, 'parse_opts'),
                mock.patch('cloud_info.core.CloudBDII'),
                mock.patch('cloud_info.core.ComputeBDII'),
                mock.patch('cloud_info.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_info.core.main())

            for i in (m0, m1, m2, m3):
                assert i.called
Beispiel #9
0
    def test_get_private_templates(self):
        """Tests that only private templates/flavors are returned"""
        expected_templates = {}
        url = 'http://schemas.openstack.org/template/resource'
        for f in FAKES.flavors:
            if f.is_public:
                continue

            expected_templates[f.id] = {
                'template_memory': f.ram,
                'template_cpu': f.vcpus,
                'template_id': '%s#%s' % (url, f.id),
                'template_platform': 'i686',
                'template_network': 'private',
                'template_disk': f.disk,
            }

        self.provider.select_flavors = 'private'
        with utils.nested(
                mock.patch.object(self.provider.static,
                                  'get_template_defaults'),
                mock.patch.object(self.provider.nova.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

        # Extract required fields from compute.ldif template excluding fields
        # extracted that are not related to the flavors
        self.assert_resources(
            expected_templates,
            templates,
            template="compute.ldif",
            ignored_fields=[
                "compute_service_name", "compute_hypervisor",
                "compute_api_authn_method", "compute_total_ram",
                "image_marketplace_id", "compute_middleware_developer",
                "compute_production_level", "compute_production_level",
                "compute_api_type", "compute_api_endpoint_technology",
                "compute_api_version", "compute_endpoint_url",
                "compute_service_production_level", "compute_capabilities",
                "compute_total_cores", "compute_middleware",
                "compute_hypervisor_version", "compute_middleware_version",
                "image_description", "image_id", "image_name", "image_version"
            ])
Beispiel #10
0
    def test_format_template(self):
        self.opts.template_dir = "foobar"
        tpl_contents = 'foo ${attributes["fobble"]}'
        tpl_files = {
            "foo": "foobar/foo.%s" % self.opts.template_extension,
            "bar": "foobar/bar.%s" % self.opts.template_extension,
        }
        info = {"fobble": "burble", "brongle": "farbla"}
        expected = "foo burble"

        bdii = cloud_info.core.BaseBDII(self.opts)
        with utils.nested(
            mock.patch.object(bdii, "templates_files", tpl_files),
            mock.patch("mako.util.open", mock.mock_open(read_data=tpl_contents), create=True),
        ):
            self.assertEqual(expected, bdii._format_template("foo", info))
Beispiel #11
0
    def test_main(self):
        with utils.nested(
            mock.patch.object(cloud_info.core, "parse_opts"),
            mock.patch("cloud_info.core.CloudBDII"),
            mock.patch("cloud_info.core.ComputeBDII"),
            mock.patch("cloud_info.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_info.core.main())

            for i in (m0, m1, m2, m3):
                assert i.called
    def test_format_template(self):
        self.opts.template_dir = 'foobar'
        tpl_contents = 'foo ${attributes["fobble"]}'
        tpl_files = {
            'foo': 'foobar/foo.%s' % self.opts.template_extension,
            'bar': 'foobar/bar.%s' % self.opts.template_extension
        }
        info = {'fobble': 'burble', 'brongle': 'farbla'}
        expected = 'foo burble'

        bdii = cloud_info.core.BaseBDII(self.opts)
        with utils.nested(
                mock.patch.object(bdii, 'templates_files', tpl_files),
                mock.patch('mako.util.open',
                           mock.mock_open(read_data=tpl_contents),
                           create=True)):
            self.assertEqual(expected, bdii._format_template('foo', info))
    def test_format_template(self):
        self.opts.template_dir = 'foobar'
        tpl_contents = 'foo ${attributes["fobble"]}'
        tpl_files = {
            'foo': 'foobar/foo.%s' % self.opts.template_extension,
            'bar': 'foobar/bar.%s' % self.opts.template_extension
        }
        info = {'fobble': 'burble', 'brongle': 'farbla'}
        expected = 'foo burble'

        bdii = cloud_info.core.BaseBDII(self.opts)
        with utils.nested(
                mock.patch.object(bdii, 'templates_files', tpl_files),
                mock.patch('mako.util.open',
                           mock.mock_open(read_data=tpl_contents), create=True)
        ):
            self.assertEqual(expected, bdii._format_template('foo', info))
    def test_get_legacy_templates_with_defaults_from_static(self):
        expected_templates = {}
        url = 'http://schemas.openstack.org/template/resource'
        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': '%s#%s' % (url, name),
                'template_native_id': "%s" % f.name,
                'template_platform': 'i686',
                'template_network': 'private',
                'template_disk': f.disk,
                'template_ephemeral': f.ephemeral,
            }

        self.provider.legacy_occi_os = True
        with utils.nested(
                mock.patch.object(self.provider.static,
                                  'get_template_defaults'),
                mock.patch.object(self.provider.nova.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="compute.ldif",
                              ignored_fields=[
                                  "compute_service_name",
                                  "image_name",
                                  "image_os_family",
                                  "image_os_name",
                                  "image_os_version",
                                  "image_platform",
                                  "image_version"
                              ])
Beispiel #15
0
    def test_get_legacy_templates_with_defaults_from_static(self):
        expected_templates = {}
        url = 'http://schemas.openstack.org/template/resource'
        for f in FAKES.flavors:
            name = f.name.strip().replace(' ', '_').replace('.', '-').lower()
            expected_templates[f.id] = {
                'template_memory': f.ram,
                'template_cpu': f.vcpus,
                'template_id': '%s#%s' % (url, name),
                'template_platform': 'i686',
                'template_network': 'private',
                'template_disk': f.disk,
            }

        self.provider.legacy_occi_os = True
        with utils.nested(
                mock.patch.object(self.provider.static,
                                  'get_template_defaults'),
                mock.patch.object(self.provider.nova.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="compute.ldif",
            ignored_fields=[
                "compute_api_type", "compute_api_version",
                "compute_api_endpoint_technology", "compute_capabilities",
                "compute_endpoint_url", "compute_hypervisor",
                "compute_hypervisor_version", "compute_middleware",
                "compute_middleware_developer", "compute_middleware_version",
                "compute_production_level", "compute_api_authn_method",
                "compute_service_name", "compute_service_production_level",
                "compute_total_cores", "compute_total_ram", "image_id",
                "image_name", "image_version", "image_description",
                "image_marketplace_id"
            ])
Beispiel #16
0
    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_info.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"))
    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_info.core.BaseBDII(self.opts)

        for s, d, e in cases:
            with utils.nested(
                mock.patch.object(bdii.static_provider, 'method'),
                mock.patch.object(bdii.dynamic_provider, 'method')
            ) as (m_static, m_dynamic):
                m_static.return_value = s
                m_dynamic.return_value = d

                self.assertEqual(e, bdii._get_info_from_providers('method'))
Beispiel #18
0
    def test_get_templates_with_defaults_from_static(self):
        expected_templates = {}
        url = 'http://schemas.openstack.org/template/resource'
        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': '%s#%s' % (url, 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="compute_bdii.ldif",
                              ignored_fields=[
                                  "compute_service_name",
                                  "image_name",
                                  "image_os_family",
                                  "image_os_name",
                                  "image_os_version",
                                  "image_platform",
                                  "image_version"
                              ])