def test_removexattr(self): setxattr(self.tmpfn, 'user.test', b'123') a = getxattr(self.tmpfn, 'user.test') assert a == b'123' removexattr(self.tmpfn, 'user.test') a = getxattr(self.tmpfn, 'user.test') assert a is None
def test_removexattr(self): setxattr(self.tmpfn, TestParams.USER_TEST, b'123') a = getxattr(self.tmpfn, TestParams.USER_TEST) assert a == b'123' removexattr(self.tmpfn, TestParams.USER_TEST) a = getxattr(self.tmpfn, TestParams.USER_TEST) assert a is None
def gen_upload_files(self): if not os.path.isdir(self.root): return for logname in listdir_by_creation(self.root): path = os.path.join(self.root, logname) try: names = os.listdir(path) except OSError: continue if any(name.endswith(".lock") for name in names): continue for name in sorted(names, key=self.get_upload_sort): key = os.path.join(logname, name) fn = os.path.join(path, name) # skip files already uploaded try: is_uploaded = getxattr(fn, UPLOAD_ATTR_NAME) except OSError: cloudlog.event("uploader_getxattr_failed", exc=self.last_exc, key=key, fn=fn) is_uploaded = True # deleter could have deleted if is_uploaded: continue yield (name, key, fn)
def test_upload_files_in_create_order(self): f_paths = list() seg1_nums = [0, 1, 2, 10, 20] for i in seg1_nums: self.seg_dir = self.seg_format.format(i) f_paths += self.gen_files() seg2_nums = [5, 50, 51] for i in seg2_nums: self.seg_dir = self.seg_format2.format(i) f_paths += self.gen_files() self.start_thread() # allow enough time that files could upload twice if there is a bug in the logic time.sleep(5) self.join_thread() self.assertFalse( len(log_handler.upload_order) < len(f_paths), "Some files failed to upload") self.assertFalse( len(log_handler.upload_order) > len(f_paths), "Some files were uploaded twice") for f_path in f_paths: self.assertTrue(getxattr(f_path, uploader.UPLOAD_ATTR_NAME), "All files not uploaded") exp_order = self.gen_order(seg1_nums, seg2_nums) self.assertTrue(log_handler.upload_order == exp_order, "Files uploaded in wrong order")
def test_upload(self): self.gen_files(lock=False) self.start_thread() # allow enough time that files could upload twice if there is a bug in the logic time.sleep(5) self.join_thread() exp_order = self.gen_order([self.seg_num], []) self.assertTrue( len(log_handler.upload_ignored) == 0, "Some files were ignored") self.assertFalse( len(log_handler.upload_order) < len(exp_order), "Some files failed to upload") self.assertFalse( len(log_handler.upload_order) > len(exp_order), "Some files were uploaded twice") for f_path in exp_order: self.assertTrue( getxattr(os.path.join(self.root, f_path), uploader.UPLOAD_ATTR_NAME), "All files not uploaded") self.assertTrue(log_handler.upload_order == exp_order, "Files uploaded in wrong order")
def test_no_upload_with_lock_file(self): f_paths = self.gen_files(lock=True) self.start_thread() # allow enough time that files should have been uploaded if they would be uploaded time.sleep(5) self.join_thread() for f_path in f_paths: self.assertFalse(getxattr(f_path, uploader.UPLOAD_ATTR_NAME), "File upload when locked")
def test_upload_ignored(self): self.set_ignore() f_paths = self.gen_files(lock=False) self.start_thread() # allow enough time that files could upload twice if there is a bug in the logic time.sleep(5) self.join_thread() self.assertTrue(len(log_handler.upload_order) == 0, "Some files were not ignored") self.assertFalse(len(log_handler.upload_ignored) < len(f_paths), "Some files failed to ignore") self.assertFalse(len(log_handler.upload_ignored) > len(f_paths), "Some files were ignored twice") for f_path in f_paths: self.assertTrue(getxattr(f_path, uploader.UPLOAD_ATTR_NAME), "All files not ignored") exp_order = self.gen_order([self.seg_num], []) self.assertTrue(log_handler.upload_ignored == exp_order, "Files ignored in wrong order")
def test_setxattr(self): setxattr(self.tmpfn, 'user.test', b'123') a = getxattr(self.tmpfn, 'user.test') assert a == b'123'
def test_getxattr_none(self): a = getxattr(self.tmpfn, 'user.test') assert a is None
def test_getxattr_none(self): a = getxattr(self.tmpfn, TestParams.USER_TEST) assert a is None