def test_cache_update_from_sis_only(self): ''' Test config from config file and SIS. ''' test_commandline = "--sis_url=http://localhost:8080/sis" cache_config = CacheConfiguration() used_sis = cache_config.update_from_cl(test_commandline.split(" ")) self.assertTrue(used_sis) print "No way to obtain meaningful iop parameters from SIS right now, Skip assertions." return self.assertEquals(300, cache_config.get_torrent_selection_interval()) self.assertEquals(1024, cache_config.get_upload_limit()) self.assertEquals(2048, cache_config.get_download_limit()) self.assertEquals(5, cache_config.get_connection_limit()) self.assertEquals(True, cache_config.establish_remote_connections())
def test_cache_update_from_cl_with_static(self): ''' Test config from config file only. ''' cwd = os.path.dirname(os.path.realpath(__file__)) static_conf_file = os.path.join(cwd, "test_cache_static.conf") if not os.access(static_conf_file, os.F_OK): self.fail("Unable to locate test_cache_static.conf") test_commandline = "--config=%s" % static_conf_file cache_config = CacheConfiguration() used_sis = cache_config.update_from_cl(test_commandline.split(" ")) self.assertFalse(used_sis) self.assertEquals(15, cache_config.get_torrent_selection_interval()) self.assertEquals(500, cache_config.get_max_torrents()) self.assertEquals(1, cache_config.get_min_leechers()) self.assertEquals("test_cache_torrents", cache_config.get_torrent_directory()) self.assertEquals("equal", cache_config.get_rate_management()) self.assertEquals("fifo", cache_config.get_replacement_strategy()) self.assertEquals(0.6, cache_config.get_min_ulfactor()) self.assertEquals(100, cache_config.get_max_downloads()) self.assertEquals(['127.0.0.1/32', '88.158.32.2/16'], cache_config.get_ip_prefixes()) self.assertEquals(20, cache_config.get_rate_interval())
def test_cache_config_from_sis_with_cl_update(self): ''' Test config from command line and SIS server. ''' test_commandline = "--port=4000 --directory=test_cache --torrentdir=test_torrent_dir " + \ "--downlimit=256 --uplimit=256 --spacelimit=4000 --conlimit=20 " + \ "--logfile=test_cache.log --id=34 --neighbour_selection=enable " + \ "--ranking_source=ip_pre --sis_url=http://localhost:8080/sis " + \ "--report_to=http://localhost:8444 --console --loglevel=DEBUG" cache_config = CacheConfiguration() used_sis = cache_config.update_from_cl(test_commandline.split(" ")) self.assertTrue(used_sis) self.assertEquals(4000, cache_config.get_port()) self.assertEquals("test_cache", cache_config.get_directory()) self.assertEquals("test_torrent_dir", cache_config.get_torrent_directory()) self.assertEquals(256, cache_config.get_download_limit()) self.assertEquals(256, cache_config.get_upload_limit()) self.assertEquals(4000, cache_config.get_space_limit()) self.assertEquals(20, cache_config.get_connection_limit()) self.assertEquals("test_cache.log", cache_config.get_logfile()) self.assertEquals(34, cache_config.get_id()) self.assertEquals(constants.NS_MODE_ENABLE, cache_config.get_ns_mode()) self.assertEquals(constants.RS_IP_PRE, cache_config.get_ranking_source()) self.assertEquals("http://localhost:8080/sis", cache_config.get_sis_url()) self.assertEquals("http://localhost:8080/sis/IoPEndpoint", cache_config.get_sis_iop_url()) self.assertEquals("http://localhost:8444", cache_config.get_report_to()) self.assertEquals(True, cache_config.has_cache_console())
ds['seeds_peers'][0], ds['seeds_peers'][1])) print >> sys.stderr,"\n" def on_exit(signal=None, func=None): if not local_reporter == None: local_reporter.write_stats() logger.warn("Session shutdown") session.shutdown() logger.warn("wait some time") time.sleep(1) # wait some time so session can stop gracefully logger.warn("sys exit (session shutdown takes too long?)") sys.exit() #___________________________________________________________________________________________________ # MAIN if __name__ == '__main__': LOG_FILE_NAME = "config/log_iop.conf" print "read logging config from file: ", LOG_FILE_NAME logging.config.fileConfig(LOG_FILE_NAME) cache_config = CacheConfiguration() cache_config.update_from_cl(sys.argv[1:]) if cache_config.get_logfile() is not None: print >>sys.stderr, "Using logfile: %s" % cache_config.get_logfile() common_utils.setup_cache_file_logger(cache_config.get_logfile()) cache = Cache(cache_config) Testbed_utils.set_exit_handler(on_exit) cache.run_forever()