def test_update_available(self): """Update.newversion available should find update""" updater = update.Update( "1.3.0", self.tempdir, functions.gen_full_tahoe_uri(self.tahoe_node_uri, self.config["script_uri"]) ) self.assertFalse(updater.new_version_available()) del updater updater = update.Update( "1.1.0", self.tempdir, functions.gen_full_tahoe_uri(self.tahoe_node_uri, self.config["script_uri"]) ) self.assertTrue(updater.new_version_available())
def test_update_available(self): """Update.newversion available should find update""" updater = update.Update( '1.3.0', self.tempdir, functions.gen_full_tahoe_uri(self.tahoe_node_uri, self.config['script_uri'])) self.assertFalse(updater.new_version_available()) del updater updater = update.Update( '1.1.0', self.tempdir, functions.gen_full_tahoe_uri(self.tahoe_node_uri, self.config['script_uri'])) self.assertTrue(updater.new_version_available())
def test_introducer_list(self): """should sync or merge introducer lists""" dead_intros = """ pb://vj2ezdq6bu5uxbciqcoo65tay2nkfqdg@uzrf37svuqf37vd57jtwywddeufm4hkrsbtwkjde7kbtfqxx4t6q.b32.i2p/introducer pb://j3omzqrjgcsr7mwzrkekjxxyvt7jeah5@yk3f75mhhllmhwksfecunudu4bxlowlb5tt4ajrqiieo4xfybnia.b32.i2p/introducer pb://vysqjw7x7hfiuozjsggpd5lmyj35pggu@iyawu4w66gd2356vguey2veyn7jbpyzqgpmb74wd2gxzvkuzbxya.b32.i2p/introducer pb://yb6j4bb5r5r2gco5vrhbtv6pjwzkgzdi@fuynpbna7k4usuvlibzah2jn3fs2dxgovqeucyszghkqnaf6atwq.b32.i2p:0/introducer pb://6y2vv5gnnd4lrw2mv4rehxfzapgdmebq@abaihqkysj6celuk6k6rmfnqjscf4uvl5nxrs4v7ykqjiarb4ydq.b32.i2p/introducer""" with open(os.path.join(self.tahoe_node_dir, "introducers"), "w") as intro: intro.writelines(dead_intros.strip()) p = introducers.Introducers( self.tahoe_node_dir, functions.gen_full_tahoe_uri(self.tahoe_node_uri, self.config["list_uri"]), 2 ) p.run_action("sync") with open(os.path.join(self.tahoe_node_dir, "introducers"), "w+") as intro: introfile = intro.read() self.assertIsNotNone(introfile) r = re.search(r"Removed introducer:", str(self.capture.getvalue())) self.assertTrue(r) # assertNotRegex not in python2.6 with open(os.path.join(self.tahoe_node_dir, "introducers"), "w") as intro: intro.writelines(dead_intros) p.run_action("merge") # write the dead introducers above to a file, then merge. To pass the # resultant introducer list should be larger than what we started with. with open(os.path.join(self.tahoe_node_dir, "introducers"), "r") as intro: count = len(intro.readlines()) self.assertGreater(count, 5)
def test_fetch_news(self): """ Test news fetching.""" web_static_dir = os.path.join(self.tahoe_node_dir, 'static') n = news.News( self.tahoe_node_dir, web_static_dir, self.tahoe_node_uri, functions.gen_full_tahoe_uri(self.tahoe_node_uri, self.config['news_uri']), 0) self.assertTrue(n.run_action())
def test_download_update(self): """should download update files""" updater = update.Update( "1.1.0", self.tempdir, functions.gen_full_tahoe_uri(self.tahoe_node_uri, self.config["script_uri"]) ) self.assertTrue(updater.run_action("download", "zip")) self.assertTrue(updater.run_action("download", "deb")) self.assertTrue(updater.run_action("download", "tar")) self.assertTrue(updater.run_action("download", "exe")) self.assertTrue(updater.run_action("download", "py2exe")) with self.assertRaises(ValueError): (updater.run_action("download", ""))
def test_fetch_news(self): """ Test news fetching.""" web_static_dir = os.path.join(self.tahoe_node_dir, "static") n = news.News( self.tahoe_node_dir, web_static_dir, self.tahoe_node_uri, functions.gen_full_tahoe_uri(self.tahoe_node_uri, self.config["news_uri"]), 0, ) self.assertTrue(n.run_action())
def test_download_update(self): """should download update files""" updater = update.Update( '1.1.0', self.tempdir, functions.gen_full_tahoe_uri(self.tahoe_node_uri, self.config['script_uri'])) self.assertTrue(updater.run_action('download', 'zip')) self.assertTrue(updater.run_action('download', 'deb')) self.assertTrue(updater.run_action('download', 'tar')) self.assertTrue(updater.run_action('download', 'exe')) self.assertTrue(updater.run_action('download', 'py2exe')) with self.assertRaises(ValueError): (updater.run_action('download', ''))
def run_action(self): shares = self.dl_sharelist() sharelist = json.loads(shares).keys() # shuffle() to even out chances of all shares to get repaired random.shuffle(list(sharelist)) for uri in sharelist: sharename = json.loads(shares)[uri]['name'] repair_uri = gen_full_tahoe_uri(self.tahoe_node_url, uri) mode = json.loads(shares)[uri]['mode'] if mode == 'deep-check': self.deep_check(sharename, repair_uri, mode) elif mode == 'one-check': self.one_check(sharename, repair_uri, mode) elif mode.startswith('level-check '): self.level_check(sharename, repair_uri, mode) else: print("ERROR: Unknown repair mode: '%s'." % mode, file=sys.stderr) return if self.verbosity > 0: print('Repairs have completed (unhealthy: %d).' % self.unhealthy)
def test_introducer_list(self): """should sync or merge introducer lists""" dead_intros = """ pb://vj2ezdq6bu5uxbciqcoo65tay2nkfqdg@uzrf37svuqf37vd57jtwywddeufm4hkrsbtwkjde7kbtfqxx4t6q.b32.i2p/introducer pb://j3omzqrjgcsr7mwzrkekjxxyvt7jeah5@yk3f75mhhllmhwksfecunudu4bxlowlb5tt4ajrqiieo4xfybnia.b32.i2p/introducer pb://vysqjw7x7hfiuozjsggpd5lmyj35pggu@iyawu4w66gd2356vguey2veyn7jbpyzqgpmb74wd2gxzvkuzbxya.b32.i2p/introducer pb://yb6j4bb5r5r2gco5vrhbtv6pjwzkgzdi@fuynpbna7k4usuvlibzah2jn3fs2dxgovqeucyszghkqnaf6atwq.b32.i2p:0/introducer pb://6y2vv5gnnd4lrw2mv4rehxfzapgdmebq@abaihqkysj6celuk6k6rmfnqjscf4uvl5nxrs4v7ykqjiarb4ydq.b32.i2p/introducer""" with open(os.path.join(self.tahoe_node_dir, 'introducers'), 'w') as intro: intro.writelines(dead_intros.strip()) p = introducers.Introducers( self.tahoe_node_dir, functions.gen_full_tahoe_uri(self.tahoe_node_uri, self.config['list_uri']), 2) p.run_action('sync') with open(os.path.join(self.tahoe_node_dir, 'introducers'), 'w+') as intro: introfile = intro.read() self.assertIsNotNone(introfile) r = re.search(r'Removed introducer:', str(self.capture.getvalue())) self.assertTrue(r) # assertNotRegex not in python2.6 with open(os.path.join(self.tahoe_node_dir, 'introducers'), 'w') as intro: intro.writelines(dead_intros) p.run_action('merge') # write the dead introducers above to a file, then merge. To pass the # resultant introducer list should be larger than what we started with. with open(os.path.join(self.tahoe_node_dir, 'introducers'), 'r') as intro: count = len(intro.readlines()) self.assertGreater(count, 5)
def main(): """Main function: run selected actions.""" proxy_support = ProxyHandler({}) opener = build_opener(proxy_support) install_opener(opener) # Parse config files and command line arguments opts = parse_args(sys.argv) # ACTION PARSING AND EXECUTION # ============================ if opts.version: print('grid-updates version: %s.' % __version__) sys.exit(0) # Run actions allowed to root, then exit if is_root() and not os.access(opts.tahoe_node_dir, os.W_OK): print("WARN: You're running grid-updates as root. Only certain actions " "will be available.") if opts.patch_ui or opts.undo_patch_ui: if not opts.tahoe_node_url: print("WARN: --node-url not specified. Defaulting to http://127.0.0.1:3456") tahoe_node_url = 'http://127.0.0.1:3456' else: tahoe_node_url = opts.tahoe_node_url webui = PatchWebUI(__patch_version__, tahoe_node_url, opts.verbosity) if opts.patch_ui: webui.run_action('patch', 'None') elif opts.undo_patch_ui: webui.run_action('undo', 'None') else: print("ERROR: Only --patch-tahoe & --undo-patch-tahoe are legal actions for the root account.", file=sys.stderr) sys.exit(1) sys.exit(0) # Check for at least 1 mandatory option if (not opts.merge and not opts.sync and not opts.news and not opts.repair and not opts.check_version and not opts.download_update and not opts.patch_ui and not opts.undo_patch_ui and not opts.news_source_file): print('ERROR: You need to specify an action. Please see %s --help.' % sys.argv[0], file=sys.stderr) sys.exit(2) # conflicting options if opts.merge and opts.sync: print('ERROR: --merge-introducers & --sync-introducers are ' 'mutually exclusive actions.', file=sys.stderr) sys.exit(2) # Check Tahoe node dir validity if os.access(opts.tahoe_node_dir, os.W_OK): web_static_dir = find_web_static_dir(opts.tahoe_node_dir) if not web_static_dir: sys.exit(1) else: print("ERROR: Need write access to", opts.tahoe_node_dir, file=sys.stderr) sys.exit(1) tahoe_node_url = set_tahoe_node_url(opts.tahoe_node_url, opts.tahoe_node_dir) if not tahoe_node_url.startswith('http://'): tahoe_node_url = 'http://' + tahoe_node_url if opts.verbosity > 2: print('DEBUG: tahoe_node_url is: %s.' % tahoe_node_url) if proxy_configured(): print("WARNING: Found (and unset) the 'http_proxy' variable.") # generate URI dictionary uri_dict = {'list': (opts.list_uri, gen_full_tahoe_uri( tahoe_node_url, opts.list_uri)), 'news': (opts.news_uri, gen_full_tahoe_uri( tahoe_node_url, opts.news_uri)), 'script': (opts.script_uri, gen_full_tahoe_uri( tahoe_node_url, opts.script_uri)), 'repairlist': (opts.repairlist_uri, gen_full_tahoe_uri( tahoe_node_url, opts.repairlist_uri)) } # Check URI validity for uri in list(uri_dict.values()): if not re.match('^URI:', uri[0]): print( "'%s' is not a valid Tahoe URI. Aborting." % uri[0]) sys.exit(1) if opts.verbosity > 2: print("DEBUG: Tahoe node dir is:", opts.tahoe_node_dir) # Run actions # ----------- if opts.merge or opts.sync: intlist = Introducers(opts.tahoe_node_dir, uri_dict['list'][1], opts.verbosity) if opts.sync: intlist.run_action('sync') elif opts.merge: intlist.run_action('merge') if opts.news: news = News(opts.tahoe_node_dir, web_static_dir, tahoe_node_url, uri_dict['news'][1], opts.verbosity) news.run_action() if opts.check_version or opts.download_update: update = Update(__version__, opts.output_dir, uri_dict['script'][1], opts.verbosity) if opts.check_version: update.run_action('check') elif opts.download_update: update.run_action('download', opts.update_format) webui_patch = PatchWebUI(__patch_version__, tahoe_node_url, opts.verbosity) webui_patch.patch_update_available() if opts.patch_ui or opts.undo_patch_ui: webui = PatchWebUI(__patch_version__, tahoe_node_url, opts.verbosity) if opts.patch_ui: webui.run_action('patch', web_static_dir) elif opts.undo_patch_ui: webui.run_action('undo', web_static_dir) if opts.news_source_file: mknews = MakeNews(opts.verbosity) mknews.run_action(opts.news_source_file, opts.output_dir) if opts.repair: repairlist = repairs.RepairList(tahoe_node_url, uri_dict['repairlist'][1], opts.verbosity) repairlist.run_action()
def test_repairs(self): repairlist = repairs.RepairList( self.tahoe_node_uri, functions.gen_full_tahoe_uri(self.tahoe_node_uri, self.config["repairlist_uri"]), 2 ) repairlist.run_action()
def test_repairs(self): repairlist = repairs.RepairList( self.tahoe_node_uri, functions.gen_full_tahoe_uri(self.tahoe_node_uri, self.config['repairlist_uri']), 2) repairlist.run_action()