Esempio n. 1
0
 def test_ubuntu(self):
     self.assertFalse(distribution.os_matches(('Ubuntu', '12.04', 'precise'),
                                              ('Ubuntu', '13.04', 'raring')))
     self.assertTrue(distribution.os_matches(('Ubuntu', '13.04', 'raring'),
                                             ('Ubuntu', '13.04', 'raring')))
     self.assertTrue(distribution.os_matches(('Ubuntu', '12.04', 'precise'),
                                             ('Ubuntu', '12.04', 'precise')))
Esempio n. 2
0
 def test_debian(self):
     self.assertFalse(distribution.os_matches(('debian', '6.0.6', ''),
                                              ('debian', '7.0', '')))
     self.assertTrue(distribution.os_matches(('debian', '6.0.6', ''),
                                             ('debian', '6.0.5', '')))
     self.assertTrue(distribution.os_matches(('debian', '6.0.6', ''),
                                             ('debian', '6.1', '')))
Esempio n. 3
0
def download_network_cached(cache_url, dir_url, software_url, software_root,
                            key, path, logger, signature_certificate_list,
                            download_from_binary_cache_url_blacklist=None):
    """Downloads from a network cache provider

    return True if download succeeded.
    """
    if not LIBNETWORKCACHE_ENABLED:
        return False

    if not(cache_url and dir_url and software_url and software_root):
        return False

    for url in download_from_binary_cache_url_blacklist:
      if software_url.startswith(url):
        return False

    try:
        nc = NetworkcacheClient(cache_url, dir_url,
            signature_certificate_list=signature_certificate_list or None)
    except TypeError:
      logger.warning('Incompatible version of networkcache, not using it.')
      return False

    logger.info('Downloading %s binary from network cache.' % software_url)
    try:
        file_descriptor = None
        json_entry_list = nc.select_generic(key)
        for entry in json_entry_list:
            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()):
                    continue
                if tags.get('software_url') != software_url:
                    continue
                if tags.get('software_root') != software_root:
                    continue
                sha512 = tags.get('sha512')
                file_descriptor = nc.download(sha512)
                break
            except Exception:
                continue
        if file_descriptor is not None:
            f = open(path, 'w+b')
            try:
                shutil.copyfileobj(file_descriptor, f)
            finally:
                f.close()
                file_descriptor.close()
            return True
    except (IOError, DirectoryNotFound) as e:
        logger.info('Failed to download from network cache %s: %s' % \
                                                       (software_url, str(e)))
    return False
Esempio n. 4
0
 def test_centos(self):
     self.assertFalse(distribution.os_matches(('CentOS', '6.3', 'Final'),
                                              ('Ubuntu', '13.04', 'raring')))
     self.assertFalse(distribution.os_matches(('CentOS', '6.3', 'Final'),
                                              ('debian', '6.3', '')))