Esempio n. 1
0
    def test_create_account_metadata(self):
        td = tempfile.mkdtemp()
        try:
            r_md = self.mp.create_account_metadata(td)

            xkey = _xkey(td, utils.METADATA_KEY)
            assert len(_xattrs.keys()) == 1
            assert xkey in _xattrs
            assert _xattr_op_cnt['get'] == 1
            assert _xattr_op_cnt['set'] == 1
            md = deserialize_metadata(_xattrs[xkey])
            assert r_md == md

            for key in self.acct_keys:
                assert key in md, "Expected key %s in %r" % (key, md)
            assert md[utils.X_TYPE] == (utils.ACCOUNT, 0)
            assert md[utils.X_TIMESTAMP] == (utils.normalize_timestamp(
                os.path.getctime(td)), 0)
            assert md[utils.X_PUT_TIMESTAMP] == (utils.normalize_timestamp(
                os.path.getmtime(td)), 0)
            assert md[utils.X_OBJECTS_COUNT] == (0, 0)
            assert md[utils.X_BYTES_USED] == (0, 0)
            assert md[utils.X_CONTAINER_COUNT] == (0, 0)
        finally:
            os.rmdir(td)
Esempio n. 2
0
 def test_get_object_metadata_file(self):
     tf = tempfile.NamedTemporaryFile()
     tf.file.write('123')
     tf.file.flush()
     md = self.mp.get_object_metadata(tf.name)
     for key in self.obj_keys:
         assert key in md, "Expected key %s in %r" % (key, md)
     assert md[utils.X_TYPE] == utils.OBJECT
     assert md[utils.X_OBJECT_TYPE] == utils.FILE
     assert md[utils.X_CONTENT_TYPE] == utils.FILE_TYPE
     assert md[utils.X_CONTENT_LENGTH] == os.path.getsize(tf.name)
     assert md[utils.X_TIMESTAMP] == utils.normalize_timestamp(
         os.path.getctime(tf.name))
     assert md[utils.X_ETAG] == utils._get_etag(tf.name)
Esempio n. 3
0
 def test_get_account_metadata(self):
     def _mock_get_account_details(path):
         c_list = ['123', 'abc']
         c_count = 2
         return c_list, c_count
     orig_gad = utils.get_account_details
     utils.get_account_details = _mock_get_account_details
     td = tempfile.mkdtemp()
     try:
         exp_md = {
             utils.X_TYPE: (utils.ACCOUNT, 0),
             utils.X_TIMESTAMP: (utils.normalize_timestamp(
                 os.path.getctime(td)), 0),
             utils.X_PUT_TIMESTAMP: (utils.normalize_timestamp(
                 os.path.getmtime(td)), 0),
             utils.X_OBJECTS_COUNT: (0, 0),
             utils.X_BYTES_USED: (0, 0),
             utils.X_CONTAINER_COUNT: (2, 0),
         }
         md = utils.get_account_metadata(td)
         assert md == exp_md
     finally:
         utils.get_account_details = orig_gad
         os.rmdir(td)
Esempio n. 4
0
 def test_get_container_metadata(self):
     def _mock_get_container_details(path, mp):
         o_list = ['a', 'b', 'c']
         o_count = 3
         b_used = 47
         return o_list, o_count, b_used
     orig_gcd = utils.get_container_details
     utils.get_container_details = _mock_get_container_details
     td = tempfile.mkdtemp()
     try:
         exp_md = {
             utils.X_TYPE: (utils.CONTAINER, 0),
             utils.X_TIMESTAMP: (utils.normalize_timestamp(
                 os.path.getctime(td)), 0),
             utils.X_PUT_TIMESTAMP: (utils.normalize_timestamp(
                 os.path.getmtime(td)), 0),
             utils.X_OBJECTS_COUNT: (3, 0),
             utils.X_BYTES_USED: (47, 0),
         }
         md = self.mp.get_container_metadata(td)
         assert md == exp_md
     finally:
         utils.get_container_details = orig_gcd
         os.rmdir(td)
Esempio n. 5
0
 def test_get_object_metadata_dir(self):
     td = tempfile.mkdtemp()
     try:
         md = self.mp.get_object_metadata(td)
         for key in self.obj_keys:
             assert key in md, "Expected key %s in %r" % (key, md)
         assert md[utils.X_TYPE] == utils.OBJECT
         assert md[utils.X_OBJECT_TYPE] == utils.DIR_NON_OBJECT
         assert md[utils.X_CONTENT_TYPE] == utils.DIR_TYPE
         assert md[utils.X_CONTENT_LENGTH] == 0
         self.assertEqual(md[utils.X_TIMESTAMP],
                          utils.normalize_timestamp(os.path.getctime(td)))
         assert md[utils.X_ETAG] == hashlib.md5().hexdigest()
     finally:
         os.rmdir(td)
Esempio n. 6
0
    def test_create_object_metadata_file(self):
        tf = tempfile.NamedTemporaryFile()
        tf.file.write('4567')
        tf.file.flush()
        r_md = self.mp.create_object_metadata(tf.name)

        xkey = _xkey(tf.name, utils.METADATA_KEY)
        assert len(_xattrs.keys()) == 1
        assert xkey in _xattrs
        assert _xattr_op_cnt['set'] == 1
        md = deserialize_metadata(_xattrs[xkey])
        self.assertEqual(r_md, md)

        for key in self.obj_keys:
            assert key in md, "Expected key %s in %r" % (key, md)
        assert md[utils.X_TYPE] == utils.OBJECT
        assert md[utils.X_OBJECT_TYPE] == utils.FILE
        assert md[utils.X_CONTENT_TYPE] == utils.FILE_TYPE
        assert md[utils.X_CONTENT_LENGTH] == os.path.getsize(tf.name)
        assert md[utils.X_TIMESTAMP] == utils.normalize_timestamp(
            os.path.getctime(tf.name))
        assert md[utils.X_ETAG] == utils._get_etag(tf.name)
Esempio n. 7
0
    def test_create_object_metadata_dir(self):
        td = tempfile.mkdtemp()
        try:
            r_md = self.mp.create_object_metadata(td)

            xkey = _xkey(td, utils.METADATA_KEY)
            assert len(_xattrs.keys()) == 1
            assert xkey in _xattrs
            assert _xattr_op_cnt['set'] == 1
            md = deserialize_metadata(_xattrs[xkey])
            assert r_md == md

            for key in self.obj_keys:
                assert key in md, "Expected key %s in %r" % (key, md)
            assert md[utils.X_TYPE] == utils.OBJECT
            assert md[utils.X_OBJECT_TYPE] == utils.DIR_NON_OBJECT
            assert md[utils.X_CONTENT_TYPE] == utils.DIR_TYPE
            assert md[utils.X_CONTENT_LENGTH] == 0
            assert md[utils.X_TIMESTAMP] == utils.normalize_timestamp(
                os.path.getctime(td))
            assert md[utils.X_ETAG] == hashlib.md5().hexdigest()
        finally:
            os.rmdir(td)