コード例 #1
0
 def test_read_metadata(self):
     path = "/tmp/foo/r"
     expected_d = {'a': 'y'}
     xkey = _xkey(path, utils.METADATA_KEY)
     _xattrs[xkey] = serialize_metadata(expected_d)
     res_d = self.mp.read_metadata(path)
     assert res_d == expected_d, "Expected %r, result %r" % \
         (expected_d, res_d)
     assert _xattr_op_cnt['get'] == 1, "%r" % _xattr_op_cnt
コード例 #2
0
 def test_restore_metadata_nochange(self):
     # Initial metadata but no changes
     path = "/tmp/foo/i"
     initial_d = {'a': 'z'}
     xkey = _xkey(path, utils.METADATA_KEY)
     _xattrs[xkey] = serialize_metadata(initial_d)
     res_d = self.mp.restore_metadata(path, {}, initial_d)
     expected_d = {'a': 'z'}
     self.assertEqual(res_d, expected_d,
                      "Expected %r, result %r" % (expected_d, res_d))
     assert _xattr_op_cnt['set'] == 0, "%r" % _xattr_op_cnt
コード例 #3
0
 def test_clean_metadata(self):
     path = "/tmp/foo/c"
     expected_d = {'a': 'y' * 150000}
     expected_p = serialize_metadata(expected_d)
     for i in range(0, 3):
         xkey = _xkey(path, "%s%s" % (utils.METADATA_KEY, i or ''))
         _xattrs[xkey] = expected_p[:utils.MAX_XATTR_SIZE]
         expected_p = expected_p[utils.MAX_XATTR_SIZE:]
     assert not expected_p
     self.mp._clean_metadata(path)
     assert _xattr_op_cnt['remove'] == 4, "%r" % _xattr_op_cnt
コード例 #4
0
 def test_read_metadata_multiple_one_missing(self):
     path = "/tmp/foo/r"
     expected_d = {'a': 'y' * 150000}
     expected_p = serialize_metadata(expected_d)
     for i in range(0, 2):
         xkey = _xkey(path, "%s%s" % (utils.METADATA_KEY, i or ''))
         _xattrs[xkey] = expected_p[:utils.MAX_XATTR_SIZE]
         expected_p = expected_p[utils.MAX_XATTR_SIZE:]
     assert len(expected_p) <= utils.MAX_XATTR_SIZE
     res_d = self.mp.read_metadata(path)
     assert res_d == {}
     assert _xattr_op_cnt['get'] == 3, "%r" % _xattr_op_cnt
コード例 #5
0
 def test_clean_metadata_err(self):
     path = "/tmp/foo/c"
     xkey = _xkey(path, utils.METADATA_KEY)
     _xattrs[xkey] = serialize_metadata({'a': 'y'})
     _xattr_rem_err[xkey] = errno.EOPNOTSUPP
     try:
         self.mp._clean_metadata(path)
     except IOError as e:
         assert e.errno == errno.EOPNOTSUPP
         assert _xattr_op_cnt['remove'] == 1, "%r" % _xattr_op_cnt
     else:
         self.fail("Expected an IOError exception on remove")
コード例 #6
0
    def test_read_cont_metadata(self):
        path = os.path.join(self.td, 'cont')
        md_dir = os.path.join(self.td, 'cont', self.mp.meta_dir)
        md_file = os.path.join(self.td, 'cont', self.mp.meta_dir,
                               self.mp.cont_meta)
        orig_d = {'bar': 'foo'}
        mkdirs(md_dir)
        with open(md_file, 'wt') as f:
            f.write(serialize_metadata(orig_d))

        md = self.mp.read_metadata(path)
        self.assertEqual(orig_d, md)
コード例 #7
0
 def test_read_metadata_multiple(self):
     path = "/tmp/foo/r"
     expected_d = {'a': 'y' * 150000}
     expected_p = serialize_metadata(expected_d)
     for i in range(0, 3):
         xkey = _xkey(path, "%s%s" % (utils.METADATA_KEY, i or ''))
         _xattrs[xkey] = expected_p[:utils.MAX_XATTR_SIZE]
         expected_p = expected_p[utils.MAX_XATTR_SIZE:]
     assert not expected_p
     res_d = self.mp.read_metadata(path)
     assert res_d == expected_d, "Expected %r, result %r" % \
         (expected_d, res_d)
     assert _xattr_op_cnt['get'] == 4, "%r" % _xattr_op_cnt
コード例 #8
0
 def test_read_metadata_err(self):
     path = "/tmp/foo/r"
     expected_d = {'a': 'y'}
     xkey = _xkey(path, utils.METADATA_KEY)
     _xattrs[xkey] = serialize_metadata(expected_d)
     _xattr_get_err[xkey] = errno.EOPNOTSUPP
     try:
         self.mp.read_metadata(path)
     except IOError as e:
         assert e.errno == errno.EOPNOTSUPP
         assert (_xattr_op_cnt['get'] == 1), "%r" % _xattr_op_cnt
     else:
         self.fail("Expected an IOError exception on get")