未验证 提交 077d0fc0 编写于 作者: L Lukáš Doktor

Merging pull request 1250

* https://github.com/avocado-framework/avocado:
  Use asset fetcher for KernelBuild download()
  avocado.core.test add cache_dirs as part of Test API
......@@ -281,6 +281,18 @@ class Test(unittest.TestCase):
def srcdir(self):
return utils_path.init_dir(self.workdir, 'src')
@data_structures.LazyProperty
def cache_dirs(self):
"""
Returns a list of cache directories as set in config file.
"""
cache_dirs = settings.get_value('datadir.paths', 'cache_dirs',
key_type=list, default=[])
datadir_cache = os.path.join(data_dir.get_data_dir(), 'cache')
if datadir_cache not in cache_dirs:
cache_dirs.append(datadir_cache)
return cache_dirs
def __str__(self):
return str(self.name)
......@@ -625,11 +637,8 @@ class Test(unittest.TestCase):
fetched (optional)
:returns: asset file local path
"""
cache_dirs = settings.get_value('datadir.paths', 'cache_dirs',
key_type=list, default=[])
cache_dirs.append(os.path.join(data_dir.get_data_dir(), 'cache'))
return asset.Asset(name, asset_hash, algorithm, locations,
cache_dirs).fetch()
self.cache_dirs).fetch()
class SimpleTest(Test):
......
......@@ -21,7 +21,7 @@ import logging
import tempfile
from distutils.version import LooseVersion
from . import download, archive, build
from . import asset, archive, build
log = logging.getLogger('avocado.test')
......@@ -35,13 +35,15 @@ class KernelBuild(object):
URL = 'https://www.kernel.org/pub/linux/kernel/v3.x/'
SOURCE = 'linux-{version}.tar.gz'
def __init__(self, version, config_path=None, work_dir=None):
def __init__(self, version, config_path=None, work_dir=None,
data_dirs=None):
"""
Creates an instance of :class:`KernelBuild`.
:param version: kernel version ("3.19.8").
:param config_path: path to config file.
:param work_dir: work directory.
:param data_dirs: list of directories to keep the downloaded kernel
:return: None.
"""
self.version = version
......@@ -49,6 +51,10 @@ class KernelBuild(object):
if work_dir is None:
work_dir = tempfile.mkdtemp(prefix='avocado_' + __name__)
self.work_dir = work_dir
if data_dirs is not None:
self.data_dirs = data_dirs
else:
self.data_dirs = [self.work_dir]
self.build_dir = os.path.join(self.work_dir, 'build')
if not os.path.isdir(self.build_dir):
os.makedirs(self.build_dir)
......@@ -64,20 +70,16 @@ class KernelBuild(object):
"""
self.kernel_file = self.SOURCE.format(version=self.version)
full_url = self.URL + self.SOURCE.format(version=self.version)
path = os.path.join(self.work_dir, self.kernel_file)
if os.path.isfile(path):
log.info("File '%s' exists, will not download!", path)
else:
log.info("Downloading '%s'...", full_url)
download.url_download(full_url, path)
self.asset_path = asset.Asset(full_url, asset_hash=None,
algorithm=None, locations=None,
cache_dirs=self.data_dirs).fetch()
def uncompress(self):
"""
Uncompress kernel source.
"""
log.info("Uncompressing tarball")
path = os.path.join(self.work_dir, self.kernel_file)
archive.extract(path, self.work_dir)
archive.extract(self.asset_path, self.work_dir)
def configure(self):
"""
......
......@@ -24,7 +24,8 @@ class LinuxBuildTest(Test):
self.linux_build = kernel.KernelBuild(kernel_version,
linux_config,
self.srcdir)
self.srcdir,
self.cache_dirs)
self.linux_build.download()
self.linux_build.uncompress()
self.linux_build.configure()
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册