Commit a9956d0a authored by Léo-Paul Géneau's avatar Léo-Paul Géneau 👾

cli: include "machine" in compatibility check

parent d00851cd
......@@ -74,6 +74,10 @@ def looks_like_md5(s):
return re.match('[0-9a-f]{32}', s)
def ostuple(jsondict):
srdict = json.loads(jsondict)
return (srdict['machine'],) + ast.literal_eval(srdict['os'])
def do_lookup(logger, cache_dir, software_url):
if looks_like_md5(software_url):
md5 = software_url
......@@ -100,15 +104,13 @@ def do_lookup(logger, cache_dir, software_url):
logger.info('Object found in cache, but has no binary entries.')
return 0
ostable = sorted(ast.literal_eval(json.loads(entry[0])['os']) for entry in entries)
pt = prettytable.PrettyTable(['distribution', 'version', 'id', 'compatible?'])
ostable = sorted(ostuple(entry[0]) for entry in entries)
linux_distribution = distribution_tuple()
pt = prettytable.PrettyTable(['machine', 'distribution', 'version', 'id', 'compatible?'])
for os in ostable:
compatible = 'yes' if networkcache.os_matches(os, linux_distribution) else 'no'
pt.add_row([os[0], os[1], os[2], compatible])
compatible = 'yes' if networkcache.is_compatible(os[0], os[1:]) else 'no'
pt.add_row([os[0], os[1], os[2], os[3], compatible])
meta = json.loads(entries[0][0])
logger.info('Software URL: %s', meta['software_url'])
......
......@@ -53,6 +53,10 @@ def fallback_call(function):
return wrapper
def is_compatible(machine, os):
return machine == platform.machine() and os_matches(os, distribution_tuple())
@fallback_call
def download_network_cached(cache_url, dir_url, software_url, software_root,
key, path, logger, signature_certificate_list,
......@@ -86,10 +90,7 @@ def download_network_cached(cache_url, dir_url, software_url, software_root,
json_information, _ = entry
try:
tags = json.loads(json_information)
if tags.get('machine') != platform.machine():
continue
if not os_matches(ast.literal_eval(tags.get('os')),
distribution_tuple()):
if not is_compatible(tags.get('machine'), ast.literal_eval(tags.get('os'))):
continue
if tags.get('software_url') != software_url:
continue
......
......@@ -85,13 +85,13 @@ class TestCliCache(CliMixin):
self.logger.info.assert_any_call('Software URL: %s',
u'https://lab.nexedi.com/nexedi/slapos/raw/1.0.102/software/slaprunner/software.cfg')
self.logger.info.assert_any_call('MD5: %s', 'cccdc51a07e8c575c880f2d70dd4d458')
self.logger.info.assert_any_call(u'------------------------------------------')
self.logger.info.assert_any_call(u' distribution version id compatible? ')
self.logger.info.assert_any_call(u'------------------------------------------')
self.logger.info.assert_any_call(u' CentOS Linux 7.5.1804 Core no ')
self.logger.info.assert_any_call(u' Ubuntu 18.04 bionic no ')
self.logger.info.assert_any_call(u'--------------------------------------------------')
self.logger.info.assert_any_call(u' machine distribution version id compatible? ')
self.logger.info.assert_any_call(u'--------------------------------------------------')
self.logger.info.assert_any_call(u' x86_64 CentOS Linux 7.5.1804 Core no ')
self.logger.info.assert_any_call(u' x86_64 Ubuntu 18.04 bionic no ')
# Omit some lines as it may fail depending of the OS
self.logger.info.assert_any_call(u'------------------------------------------')
self.logger.info.assert_any_call(u'--------------------------------------------------')
def test_uncached_binary(self):
self.assertEqual(10, cache_do_lookup(
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment