def tearDown(self): TestAsServer.tearDown(self) time.sleep(1) try: shutil.rmtree(self.scandir) except: pass
def setUpPreSession(self): TestAsServer.setUpPreSession(self) self.destdir = os.path.join(os.getcwdu(),"dest") try: shutil.rmtree(self.destdir) except: pass os.mkdir(self.destdir) # Create tree with 6 chunks self.chunks = [] for i in range(0,6+1): chunk = chr(i) * 1024 self.chunks.append(chunk) self.hashes = {} self.hashes[(7,7)] = '\x00' * 20 for i in range(0,6+1): hash = sha(self.chunks[i]).digest() self.hashes[(i,i)] = hash self.hashes[(0,1)] = sha(self.hashes[(0,0)]+self.hashes[(1,1)]).digest() self.hashes[(2,3)] = sha(self.hashes[(2,2)]+self.hashes[(3,3)]).digest() self.hashes[(4,5)] = sha(self.hashes[(4,4)]+self.hashes[(5,5)]).digest() self.hashes[(6,7)] = sha(self.hashes[(6,6)]+self.hashes[(7,7)]).digest() self.hashes[(0,3)] = sha(self.hashes[(0,1)]+self.hashes[(2,3)]).digest() self.hashes[(4,7)] = sha(self.hashes[(4,5)]+self.hashes[(6,7)]).digest() self.hashes[(0,7)] = sha(self.hashes[(0,3)]+self.hashes[(4,7)]).digest()
def setUpPreSession(self): TestAsServer.setUpPreSession(self) #self.cmdport = None self.httpport = None self.scandir = "seeder2" self.progress = True self.setUpScanDir() try: shutil.rmtree(self.scandir) except: pass os.mkdir(self.scandir) # Create content for i in range(len(self.filelist)): fn = self.filelist[i][0] s = self.filelist[i][1] f = open(fn, "wb") data = '#' * s f.write(data) f.close() # Pre hash check and checkpoint them sdef = SwiftDef() sdef.add_content(fn) sdef.finalize(self.binpath) self.filelist[i][2] = sdef.get_id() # save roothash for i in range(len(self.filelist)): print >> sys.stderr, "test: Configured from filelist", binascii.hexlify( self.filelist[i][2])
def setUpPreSession(self): TestAsServer.setUpPreSession(self) #self.cmdport = None self.httpport = None self.scandir = "seeder2" self.progress = True self.setUpScanDir() try: shutil.rmtree(self.scandir) except: pass os.mkdir(self.scandir) # Create content for i in range(len(self.filelist)): fn = self.filelist[i][0] s = self.filelist[i][1] f = open(fn,"wb") data = '#' * s f.write(data) f.close() # Pre hash check and checkpoint them sdef = SwiftDef() sdef.add_content(fn) sdef.finalize(self.binpath) self.filelist[i][2] = sdef.get_id() # save roothash for i in range(len(self.filelist)): print >>sys.stderr,"test: Configured from filelist",binascii.hexlify(self.filelist[i][2])
def setUpPostSession(self): TestAsServer.setUpPostSession(self) #CMD = "START tswift:/"+binascii.hexlify(self.swarmid)+" "+self.destdir+"\r\n" CMD = "START tswift://127.0.0.1:"+str(self.listenport)+"/"+binascii.hexlify(self.swarmid)+" "+self.destdir+"\r\n" self.cmdsock.send(CMD) self.urlprefix = "http://127.0.0.1:"+str(self.httpport)+"/"+binascii.hexlify(self.swarmid)
def tearDown(self): # Wait 30+ second such that zerostate cleanup code gets covered. time.sleep(self.exitwait) TestAsServer.tearDown(self) try: shutil.rmtree(self.zerosdir) except: print_exc()
def tearDown(self): TestAsServer.tearDown(self) try: os.remove(self.livesourceinput) except: pass try: os.remove(self.filename) except: pass
def setUpPostSession(self): TestAsServer.setUpPostSession(self) #CMD = "START tswift:/"+binascii.hexlify(self.swarmid)+" "+self.destdir+"\r\n" CMD = "START tswift://127.0.0.1:" + str( self.listenport) + "/" + binascii.hexlify( self.swarmid) + " " + self.destdir + "\r\n" self.cmdsock.send(CMD) self.urlprefix = "http://127.0.0.1:" + str( self.httpport) + "/" + binascii.hexlify(self.swarmid)
def setUpPreSession(self): TestAsServer.setUpPreSession(self) self.cond = Condition() self.peer1port = 1234 self.peer1 = UDPListener(self, self.peer1port) self.peer1.start() self.destdir = "." self.udpsendport = random.randint(14001, 14999) # time.sleep(2) # let server threads start
def setUpPreSession(self): TestAsServer.setUpPreSession(self) self.cond = Condition() self.peer1port = 1234 self.peer1 = UDPListener(self,self.peer1port) self.peer1.start() self.destdir = "." self.udpsendport = random.randint(14001,14999) # time.sleep(2) # let server threads start
def setUpPreSession(self): TestAsServer.setUpPreSession(self) self.destdir = '.' f = open("liveinput.dat", "wb") self.nchunks = 1017 for i in range(0, self.nchunks): data = chr((ord('a') + i) % 256) * 1024 f.write(data) f.close() self.livesourceinput = "liveinput.dat" self.filename = "storage.dat"
def setUpPostSession(self): TestAsServer.setUpPostSession(self) f = open(self.urlfilename, "rb") swarmurl = f.read() f.close() swarmurl = swarmurl.strip() idx = swarmurl.find("/") if idx == -1: self.assertFalse(True) else: liveswarmidhex = swarmurl[idx + 1:] print >> sys.stderr, "test: SwarmID <" + liveswarmidhex + ">" self.liveswarmid = binascii.unhexlify(liveswarmidhex)
def setUpPreSession(self): TestAsServer.setUpPreSession(self) self.destdir = '.' f = open("liveinput.dat","wb") self.nchunks = 1017 for i in range(0,self.nchunks): data = chr((ord('a')+i)%256) * 1024 f.write(data) f.close() self.livesourceinput = "liveinput.dat" self.filename = "storage.dat"
def setUpPostSession(self): TestAsServer.setUpPostSession(self) f = open(self.urlfilename,"rb") swarmurl = f.read() f.close() swarmurl = swarmurl.strip() idx = swarmurl.find("/") if idx == -1: self.assertFalse(True) else: liveswarmidhex = swarmurl[idx+1:] print >>sys.stderr,"test: SwarmID <"+liveswarmidhex+">" self.liveswarmid = binascii.unhexlify(liveswarmidhex)
def setUpPreSession(self): TestAsServer.setUpPreSession(self) self.destdir = '.' f = open("liveinput.dat", "wb") self.nchunks = 1017 for i in range(0, self.nchunks): data = chr((ord('0') + i) % 256) * 1024 f.write(data) f.close() self.livesourceinput = "liveinput.dat" self.filename = "storage.dat" self.urlfilename = "swarm.url" self.livesigalg = ord(POPT_LSA_ECDSAP256SHA256) self.debug = True
def setUpPreSession(self): TestAsServer.setUpPreSession(self) self.destdir = '.' f = open("liveinput.dat","wb") self.nchunks = 1017 for i in range(0,self.nchunks): data = chr((ord('0')+i)%256) * 1024 f.write(data) f.close() self.livesourceinput = "liveinput.dat" self.filename = "storage.dat" self.urlfilename = "swarm.url" self.livesigalg = ord(POPT_LSA_ECDSAP256SHA256) self.debug = True
def setUpPreSession(self): TestAsServer.setUpPreSession(self) self.destdir = tempfile.mkdtemp() print >> sys.stderr, "test: destdir is", self.destdir self.setUpFileList() idx = self.filelist[0][0].find("/") specprefix = self.filelist[0][0][0:idx] prefixdir = os.path.join(self.destdir, specprefix) os.mkdir(prefixdir) sdef = SwiftDef() # Create content for fn, s in self.filelist: osfn = fn.replace("/", os.sep) fullpath = os.path.join(self.destdir, osfn) f = open(fullpath, "wb") data = fn[len(specprefix) + 1] * s f.write(data) f.close() sdef.add_content(fullpath, fn) self.specfn = sdef.finalize(self.binpath, destdir=self.destdir) f = open(self.specfn, "rb") self.spec = f.read() f.close() self.swarmid = sdef.get_id() print >> sys.stderr, "test: setUpPreSession: roothash is", binascii.hexlify( self.swarmid) self.mfdestfn = os.path.join(self.destdir, binascii.hexlify(self.swarmid)) shutil.copyfile(self.specfn, self.mfdestfn) shutil.copyfile(self.specfn + ".mhash", self.mfdestfn + ".mhash") shutil.copyfile(self.specfn + ".mbinmap", self.mfdestfn + ".mbinmap")
def setUpPreSession(self): TestAsServer.setUpPreSession(self) self.httpport = None self.zerosdir = os.path.join(os.getcwd(), "zeros2") self.exitwait = 36 self.progress = True self.setUpZerosDir() try: shutil.rmtree(self.zerosdir) except: pass os.mkdir(self.zerosdir) # Create content for i in range(len(self.filelist)): fn = self.filelist[i][0] s = self.filelist[i][1] f = open(fn, "wb") data = '#' * s f.write(data) f.close() # Pre hash check and checkpoint them sdef = SwiftDef() sdef.add_content(fn) sdef.finalize(self.binpath) self.filelist[i][2] = sdef.get_id() # save roothash # Hack: now copy to <roothash>[.mhash|.mbinmap] files such that zerostate works for i in range(len(self.filelist)): print >> sys.stderr, "test: Configuring", binascii.hexlify( self.filelist[i][2]) srcfile = self.filelist[i][0] dstfile = os.path.join(self.zerosdir, binascii.hexlify(self.filelist[i][2])) shutil.copyfile(srcfile, dstfile) shutil.copyfile(srcfile + ".mhash", dstfile + ".mhash") shutil.copyfile(srcfile + ".mbinmap", dstfile + ".mbinmap")
def setUpPreSession(self): TestAsServer.setUpPreSession(self) self.destdir = tempfile.mkdtemp() print >>sys.stderr,"test: destdir is",self.destdir self.setUpFileList() idx = self.filelist[0][0].find("/") specprefix = self.filelist[0][0][0:idx] prefixdir = os.path.join(self.destdir,specprefix) os.mkdir(prefixdir) sdef = SwiftDef() # Create content for fn,s in self.filelist: osfn = fn.replace("/",os.sep) fullpath = os.path.join(self.destdir,osfn) f = open(fullpath,"wb") data = fn[len(specprefix)+1] * s f.write(data) f.close() sdef.add_content(fullpath,fn) self.specfn = sdef.finalize(self.binpath,destdir=self.destdir) f = open(self.specfn,"rb") self.spec = f.read() f.close() self.swarmid = sdef.get_id() print >>sys.stderr,"test: setUpPreSession: roothash is",binascii.hexlify(self.swarmid) self.mfdestfn = os.path.join(self.destdir,binascii.hexlify(self.swarmid)) shutil.copyfile(self.specfn,self.mfdestfn) shutil.copyfile(self.specfn+".mhash",self.mfdestfn+".mhash") shutil.copyfile(self.specfn+".mbinmap",self.mfdestfn+".mbinmap")
def setUpPreSession(self): TestAsServer.setUpPreSession(self) self.httpport = None self.zerosdir = os.path.join(os.getcwd(),"zeros2") self.exitwait = 36 self.progress = True self.setUpZerosDir() try: shutil.rmtree(self.zerosdir) except: pass os.mkdir(self.zerosdir) # Create content for i in range(len(self.filelist)): fn = self.filelist[i][0] s = self.filelist[i][1] f = open(fn,"wb") data = '#' * s f.write(data) f.close() # Pre hash check and checkpoint them sdef = SwiftDef() sdef.add_content(fn) sdef.finalize(self.binpath) self.filelist[i][2] = sdef.get_id() # save roothash # Hack: now copy to <roothash>[.mhash|.mbinmap] files such that zerostate works for i in range(len(self.filelist)): print >>sys.stderr,"test: Configuring",binascii.hexlify(self.filelist[i][2]) srcfile = self.filelist[i][0] dstfile = os.path.join(self.zerosdir,binascii.hexlify(self.filelist[i][2])) shutil.copyfile(srcfile,dstfile) shutil.copyfile(srcfile+".mhash",dstfile+".mhash") shutil.copyfile(srcfile+".mbinmap",dstfile+".mbinmap")
def setUpPreSession(self): TestAsServer.setUpPreSession(self) self.destdir = os.path.join(os.getcwdu(), "dest") try: shutil.rmtree(self.destdir) except: pass os.mkdir(self.destdir) # Create tree with 6 chunks self.chunks = [] for i in range(0, 6 + 1): chunk = chr(i) * 1024 self.chunks.append(chunk) self.hashes = {} self.hashes[(7, 7)] = '\x00' * 20 for i in range(0, 6 + 1): hash = sha(self.chunks[i]).digest() self.hashes[(i, i)] = hash self.hashes[(0, 1)] = sha(self.hashes[(0, 0)] + self.hashes[(1, 1)]).digest() self.hashes[(2, 3)] = sha(self.hashes[(2, 2)] + self.hashes[(3, 3)]).digest() self.hashes[(4, 5)] = sha(self.hashes[(4, 4)] + self.hashes[(5, 5)]).digest() self.hashes[(6, 7)] = sha(self.hashes[(6, 6)] + self.hashes[(7, 7)]).digest() self.hashes[(0, 3)] = sha(self.hashes[(0, 1)] + self.hashes[(2, 3)]).digest() self.hashes[(4, 7)] = sha(self.hashes[(4, 5)] + self.hashes[(6, 7)]).digest() self.hashes[(0, 7)] = sha(self.hashes[(0, 3)] + self.hashes[(4, 7)]).digest()
def setUpPreSession(self): TestAsServer.setUpPreSession(self) self.statshttpport = 8091
def setUpPostSession(self): TestAsServer.setUpPostSession(self)
def tearDown(self): TestAsServer.tearDown(self)
def setUpPostSession(self): TestAsServer.setUpPostSession(self) time.sleep(2)