Пример #1
0
 def test_consistency(self):
     # Test the upload and download consistency:
     print "Test consistency of upload and download."
     tempfilepath = self.setting.mirrordir + "/" + tempfilename
     # Copy infile to tempfile in mirror dir:
     shutil.copyfile(infilename, tempfilepath)
     filesize = os.path.getsize(tempfilepath)
     # Upload tempfile:
     metadata = common.FileMetadata(tempfilename, filesize, self.setting.totalnode, self.setting.coding)
     workflow.uploadFile(self.setting, metadata)
     print "Upload finishes."
     # Clean temporary directories:
     clean.cleanAll()
     print "Clean finishes."
     # Download tempfile:
     metadata = common.FileMetadata(tempfilename, 0, self.setting.totalnode, self.setting.coding)
     workflow.downloadFile(self.setting, metadata)
     print "Download finishes."
     # Copy tempfile to outfile:
     shutil.copyfile(tempfilepath, outfilename)
     # Clean data in cloud and temporary directories:
     metadata = common.FileMetadata(tempfilename, 0, self.setting.totalnode, self.setting.coding)
     workflow.deleteFile(self.setting, metadata)
     clean.cleanAll()
     # Check if infile is same as outfile:
     print "test file difference"
     self.assertEqual(filecmp.cmp(infilename, outfilename), 1)
     # Delete outfile:
     os.unlink(outfilename)
Пример #2
0
 def test_consistency(self):
     #Test the upload and download consistency:
     print "Test consistency of upload and download."
     tempfilepath = self.setting.mirrordir + "/" + tempfilename
     #Copy infile to tempfile in mirror dir:
     shutil.copyfile(infilename, tempfilepath)
     filesize = os.path.getsize(tempfilepath)
     #Upload tempfile:
     metadata = common.FileMetadata(tempfilename, filesize,
                                    self.setting.totalnode,
                                    self.setting.coding)
     workflow.uploadFile(self.setting, metadata)
     print "Upload finishes."
     #Clean temporary directories:
     clean.cleanAll()
     print "Clean finishes."
     #Download tempfile:
     metadata = common.FileMetadata(tempfilename, 0, self.setting.totalnode,
                                    self.setting.coding)
     workflow.downloadFile(self.setting, metadata)
     print "Download finishes."
     #Copy tempfile to outfile:
     shutil.copyfile(tempfilepath, outfilename)
     #Clean data in cloud and temporary directories:
     metadata = common.FileMetadata(tempfilename, 0, self.setting.totalnode,
                                    self.setting.coding)
     workflow.deleteFile(self.setting, metadata)
     clean.cleanAll()
     #Check if infile is same as outfile:
     print "test file difference"
     self.assertEqual(filecmp.cmp(infilename, outfilename), 1)
     #Delete outfile:
     os.unlink(outfilename)
Пример #3
0
 def unlink(self, path):
     '''Remove file.'''
     setting = common.Setting()
     setting.read(
         self.settingpath
     )  #cq update setting before unlink. repair operation may change setting.cfg
     filename = path[path.index("/") + 1:]
     metadata = common.FileMetadata(filename, 0, setting.totalnode,
                                    setting.coding)
     #Delete chunks and metadata of the file on cloud:
     workflow.deleteFile(setting, metadata)
     #Delete in chunkdir:
     #Delete chunks:
     for chunk in metadata.chunkInfo:
         if chunk.chunktype != 'replica':
             try:
                 os.unlink(setting.chunkdir + "/" + chunk.chunkpath)
             except:
                 pass
     #Delete big-chunks:
     for bigchunk in metadata.fileNodeInfo:
         try:
             os.unlink(setting.chunkdir + "/" + bigchunk.bigchunkpath)
         except:
             pass
     if setting.coding == 'replication':
         try:
             os.unlink(setting.chunkdir + '/' + metadata.filename +
                       '.node0')
         except:
             pass
     #Delete in metadatadir:
     try:
         if setting.coding != 'replication':  #cq there is no .meta file in replication
             os.unlink(setting.metadatadir + "/" + filename + ".meta")
         os.unlink(setting.metadatadir + "/" + filename + ".metadata")
     except:
         pass
     #Delete file in mirror dir
     os.unlink("." + path)
Пример #4
0
 def unlink(self, path):
     '''Remove file.'''
     setting = common.Setting()
     setting.read(self.settingpath)#cq update setting before unlink. repair operation may change setting.cfg
     filename = path[path.index("/")+1:]
     metadata = common.FileMetadata(filename,0,setting.totalnode,setting.coding)
     #Delete chunks and metadata of the file on cloud:
     workflow.deleteFile(setting, metadata)
     #Delete in chunkdir:
     #Delete chunks:
     for chunk in metadata.chunkInfo:
         if chunk.chunktype != 'replica':
             try:
                 os.unlink(setting.chunkdir + "/" + chunk.chunkpath)
             except:
                 pass
     #Delete big-chunks:        
     for bigchunk in metadata.fileNodeInfo:
         try:
             os.unlink(setting.chunkdir + "/" + bigchunk.bigchunkpath)
         except:
             pass
     if setting.coding == 'replication':
         try:
             os.unlink(setting.chunkdir + '/' + metadata.filename + '.node0')
         except:
             pass
     #Delete in metadatadir:
     try:
         if setting.coding != 'replication':   #cq there is no .meta file in replication
             os.unlink(setting.metadatadir + "/" + filename + ".meta")
         os.unlink(setting.metadatadir + "/" + filename + ".metadata")
     except:
         pass
     #Delete file in mirror dir
     os.unlink("." + path)