1
0
mirror of https://github.com/ARM-software/workload-automation.git synced 2025-02-20 11:58:55 +00:00

framework/getters: fix http getter APK resolution

Fully matching an APK resource requires the file to be present locally,
so that its metadata can be queries. HTTP getter was matching against a
remote path so the match was failing.

The matching now happens in two stages == first partial path-only
matches are established. Secondly, all partial matches are downloaded
and final match occurs against downloaded files.
This commit is contained in:
Sergei Trofimov 2017-10-10 11:32:52 +01:00
parent 5f7c64b089
commit 1daec4f2c5

View File

@ -71,6 +71,14 @@ def get_generic_resource(resource, files):
return matches[0]
def get_path_matches(resource, files):
matches = []
for f in files:
if resource.match_path(f):
matches.append(f)
return matches
def get_from_location(basepath, resource):
if resource.kind == 'file':
path = os.path.join(basepath, resource.path)
@ -204,10 +212,15 @@ class Http(ResourceGetter):
return # TODO: add support for unowned resources
if not self.index:
self.index = self.fetch_index()
asset = self.resolve_resource(resource)
if not asset:
return
return self.download_asset(asset, resource.owner.name)
if resource.kind == 'apk':
# APKs must always be downloaded to run ApkInfo for version
# information.
return self.resolve_apk(resource)
else:
asset = self.resolve_resource(resource)
if not asset:
return
return self.download_asset(asset, resource.owner.name)
def fetch_index(self):
if not self.url:
@ -251,6 +264,20 @@ class Http(ResourceGetter):
auth = None
return requests.get(url, auth=auth, stream=stream)
def resolve_apk(self, resource):
assets = self.index.get(resource.owner.name, {})
if not assets:
return None
asset_map = {a['path']: a for a in assets}
paths = get_path_matches(resource, asset_map.keys())
local_paths = []
for path in paths:
local_paths.append(self.download_asset(asset_map[path],
resource.owner.name))
for path in local_paths:
if resource.match(path):
return path
def resolve_resource(self, resource):
# pylint: disable=too-many-branches,too-many-locals
assets = self.index.get(resource.owner.name, {})
@ -258,13 +285,7 @@ class Http(ResourceGetter):
return {}
asset_map = {a['path']: a for a in assets}
if resource.kind in ['apk', 'jar', 'revent']:
if resource.kind == 'apk' and resource.version:
# TODO: modify the index format to attach version info to the
# APK entries.
msg = 'Versions of APKs cannot be fetched over HTTP at this time'
self.logger.warning(msg)
return {}
if resource.kind in ['jar', 'revent']:
path = get_generic_resource(resource, asset_map.keys())
if path:
return asset_map[path]