示例#1
0
    def _create_test_files(self, urlopen_mock):
        with unittest.mock.patch('avocado.core.data_dir.settings', self.stg):
            expected_images = [{'name': 'Fedora', 'file': 'Fedora-Cloud-Base-{version}-{build}.{arch}.qcow2',
                                'url': FEDORA_PAGE},
                               {'name': 'JeOS', 'file': 'jeos-{version}-{arch}.qcow2.xz', 'url': JEOS_PAGE},
                               {'name': 'CirrOS', 'file': 'cirros-{version}-{arch}-disk.img', 'url': CIRROS_PAGE}
                               ]
            cache_dir = data_dir.get_cache_dirs()[0]
            providers = [provider() for provider in vmimage_util.list_providers()]

            for provider in providers:
                for image in expected_images:
                    if image['name'] == provider.name:
                        urlread_mocked = unittest.mock.Mock(return_value=image["url"])
                        urlopen_mock.return_value = unittest.mock.Mock(read=urlread_mocked)
                        image['type'] = "vmimage"
                        image['version'] = provider.version
                        image['arch'] = provider.arch
                        image['build'] = "1234"
                        image['file'] = os.path.join(cache_dir, image['file'].format(
                            version=image['version'],
                            build=image['build'],
                            arch=image['arch']))
                        open(image["file"], "w").close()
                        create_metadata_file(image['file'], image)
            return sorted(expected_images, key=lambda i: i['name'])
示例#2
0
    def _create_test_files(self, urlopen_mock):
        with unittest.mock.patch("avocado.core.data_dir.settings", self.stg):
            expected_images = [
                {
                    "name": "Fedora",
                    "file": "Fedora-Cloud-Base-{version}-{build}.{arch}.qcow2",
                    "url": FEDORA_PAGE,
                },
                {
                    "name": "JeOS",
                    "file": "jeos-{version}-{arch}.qcow2.xz",
                    "url": JEOS_PAGE,
                },
                {
                    "name": "CirrOS",
                    "file": "cirros-{version}-{arch}-disk.img",
                    "url": CIRROS_PAGE,
                },
            ]
            cache_dir = self.mapping.get("cache_dirs")[0]
            providers = [provider() for provider in vmimage_util.list_providers()]

            for provider in providers:
                for image in expected_images:
                    if image["name"] == provider.name:
                        urlread_mocked = unittest.mock.Mock(return_value=image["url"])
                        urlopen_mock.return_value = unittest.mock.Mock(
                            read=urlread_mocked
                        )
                        image["type"] = "vmimage"
                        image["version"] = provider.version
                        image["arch"] = provider.arch
                        image["build"] = "1234"
                        image["file"] = os.path.join(
                            cache_dir,
                            image["file"].format(
                                version=image["version"],
                                build=image["build"],
                                arch=image["arch"],
                            ),
                        )
                        open(image["file"], "w", encoding="utf-8").close()
                        create_metadata_file(image["file"], image)
            return sorted(expected_images, key=lambda i: i["name"])