本文整理汇总了Python中oio.blob.client.BlobClient.chunk_put方法的典型用法代码示例。如果您正苦于以下问题:Python BlobClient.chunk_put方法的具体用法?Python BlobClient.chunk_put怎么用?Python BlobClient.chunk_put使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类oio.blob.client.BlobClient
的用法示例。
在下文中一共展示了BlobClient.chunk_put方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestRebuilderCrawler
# 需要导入模块: from oio.blob.client import BlobClient [as 别名]
# 或者: from oio.blob.client.BlobClient import chunk_put [as 别名]
class TestRebuilderCrawler(BaseTestCase):
def setUp(self):
super(TestRebuilderCrawler, self).setUp()
self.namespace = self.conf['namespace']
self.account = self.conf['account']
self.gridconf = {"namespace": self.namespace}
self.container_client = ContainerClient(self.gridconf)
self.blob_client = BlobClient()
self.container_name = "TestRebuilderCrawler%d" % int(time.time())
self.container_client.container_create(acct=self.account,
ref=self.container_name)
def _push_content(self, content):
for c in content.chunks:
self.blob_client.chunk_put(c.url, c.get_create_xattr(), c.data)
self.container_client.content_create(acct=content.account,
ref=content.container_name,
path=content.content_name,
size=content.size,
checksum=content.hash,
content_id=content.content_id,
stgpol=content.stgpol,
data=content.get_create_meta2())
def tearDown(self):
super(TestRebuilderCrawler, self).tearDown()
def test_rebuild_chunk(self):
# push a new content
content = TestContent(self.conf, self.account,
self.container_name, "mycontent", "TWOCOPIES")
data = "azerty"
content.add_chunk(data, pos='0', rawx=0)
content.add_chunk(data, pos='0', rawx=1)
self._push_content(content)
# rebuild the first rawx
rebuilder = BlobRebuilderWorker(self.gridconf, None,
self.conf['rawx'][0]['addr'])
rebuilder.chunk_rebuild(content.container_id, content.content_id,
content.chunks[0].id)
# check meta2 information
_, res = self.container_client.content_show(acct=content.account,
ref=content.container_name,
content=content.content_id)
new_chunk_info = None
for c in res:
if (c['url'] != content.chunks[0].url and
c['url'] != content.chunks[1].url):
new_chunk_info = c
new_chunk_id = new_chunk_info['url'].split('/')[-1]
self.assertEqual(new_chunk_info['hash'], content.chunks[0].hash)
self.assertEqual(new_chunk_info['pos'], content.chunks[0].pos)
self.assertEqual(new_chunk_info['size'], content.chunks[0].size)
# check chunk information
meta, stream = self.blob_client.chunk_get(new_chunk_info['url'])
self.assertEqual(meta['content_size'], str(content.chunks[0].size))
self.assertEqual(meta['content_path'], content.content_name)
self.assertEqual(meta['content_cid'], content.container_id)
self.assertEqual(meta['content_id'], content.content_id)
self.assertEqual(meta['chunk_id'], new_chunk_id)
self.assertEqual(meta['chunk_pos'], content.chunks[0].pos)
self.assertEqual(meta['content_version'], content.version)
self.assertEqual(meta['chunk_hash'], content.chunks[0].hash)
self.assertEqual(stream.next(), content.chunks[0].data)
# check rtime flag in rdir
rdir_client = RdirClient(self.gridconf)
res = rdir_client.chunk_fetch(self.conf['rawx'][0]['addr'])
key = (content.container_id, content.content_id, content.chunks[0].id)
for i_container, i_content, i_chunk, i_value in res:
if (i_container, i_content, i_chunk) == key:
check_value = i_value
self.assertIsNotNone(check_value.get('rtime'))
@unittest.skipIf(len(get_config()['rawx']) != 3,
"The number of rawx must be 3")
def test_rebuild_no_spare(self):
# push a new content
content = TestContent(self.conf, self.account,
self.container_name, "mycontent", "THREECOPIES")
data = "azerty"
content.add_chunk(data, pos='0', rawx=0)
content.add_chunk(data, pos='0', rawx=1)
content.add_chunk(data, pos='0', rawx=2)
#.........这里部分代码省略.........
示例2: TestBlobAuditorFunctional
# 需要导入模块: from oio.blob.client import BlobClient [as 别名]
# 或者: from oio.blob.client.BlobClient import chunk_put [as 别名]
class TestBlobAuditorFunctional(BaseTestCase):
def setUp(self):
super(TestBlobAuditorFunctional, self).setUp()
self.namespace = self.conf['namespace']
self.account = self.conf['account']
self.test_dir = self.conf['sds_path']
rawx_num, rawx_path, rawx_addr = self.get_service_url('rawx')
self.rawx = 'http://' + rawx_addr
self.h = hashlib.new('md5')
conf = {"namespace": self.namespace}
self.auditor = BlobAuditorWorker(conf, get_logger(None), None)
self.container_c = ContainerClient(conf)
self.blob_c = BlobClient()
self.ref = random_str(8)
self.container_c.container_create(self.account, self.ref)
self.url_rand = random_id(64)
self.data = random_str(1280)
self.h.update(self.data)
self.hash_rand = self.h.hexdigest().lower()
self.content = TestContent(
random_str(6), len(self.data), self.url_rand, 1)
self.content.id_container = cid_from_name(
self.account, self.ref).upper()
self.chunk = TestChunk(self.content.size, self.url_rand, 0,
self.hash_rand)
self.chunk_url = "%s/%s" % (self.rawx, self.chunk.id_chunk)
self.chunk_proxy = {"hash": self.chunk.md5, "pos": "0",
"size": self.chunk.size,
"url": self.chunk_url}
chunk_meta = {'content_path': self.content.path,
'container_id': self.content.id_container,
'content_chunkmethod': 'plain/nb_copy=3',
'content_policy': 'TESTPOLICY',
'content_id': '0000',
'content_version': 1,
'chunk_id': self.chunk.id_chunk,
'chunk_pos': self.chunk.pos}
self.blob_c.chunk_put(self.chunk_url, chunk_meta, self.data)
self.chunk_path = self.test_dir + '/data/' + self.namespace + \
'-rawx-1/' + self.chunk.id_chunk[0:3] + "/" + self.chunk.id_chunk
self.bad_container_id = '0'*64
def tearDown(self):
super(TestBlobAuditorFunctional, self).tearDown()
try:
self.container_c.content_delete(
self.account, self.ref, self.content.path)
except Exception:
pass
try:
self.container_c.container_destroy(self.account, self.ref)
except Exception:
pass
try:
os.remove(self.chunk_path)
except Exception:
pass
def init_content(self):
self.container_c.content_create(
self.account, self.ref, self.content.path, self.chunk.size,
self.hash_rand, data=[self.chunk_proxy])
def test_chunk_audit(self):
self.init_content()
self.auditor.chunk_audit(self.chunk_path)
def test_content_deleted(self):
self.assertRaises(exc.OrphanChunk, self.auditor.chunk_audit,
self.chunk_path)
def test_container_deleted(self):
self.container_c.container_destroy(self.account, self.ref)
self.assertRaises(exc.OrphanChunk, self.auditor.chunk_audit,
self.chunk_path)
def test_chunk_corrupted(self):
self.init_content()
with open(self.chunk_path, "w") as f:
f.write(random_str(1280))
self.assertRaises(exc.CorruptedChunk, self.auditor.chunk_audit,
self.chunk_path)
#.........这里部分代码省略.........
示例3: TestBlobAuditorFunctional
# 需要导入模块: from oio.blob.client import BlobClient [as 别名]
# 或者: from oio.blob.client.BlobClient import chunk_put [as 别名]
class TestBlobAuditorFunctional(BaseTestCase):
def setUp(self):
super(TestBlobAuditorFunctional, self).setUp()
self.namespace = self.conf['namespace']
self.account = self.conf['account']
self.test_dir = self.conf['sds_path']
self.chars = string.ascii_lowercase + string.ascii_uppercase +\
string.digits
self.chars_id = string.digits + 'ABCDEF'
self.rawx = 'http://' + self.conf["rawx"][0]['addr']
self.h = hashlib.new('md5')
conf = {"namespace": self.namespace}
self.auditor = BlobAuditorWorker(conf, get_logger(None), None)
self.container_c = ContainerClient(conf)
self.blob_c = BlobClient()
self.ref = rand_generator(self.chars, 8)
self.container_c.container_create(self.account, self.ref)
self.url_rand = rand_generator(self.chars_id, 64)
self.data = rand_generator(self.chars, 1280)
self.h.update(self.data)
self.hash_rand = self.h.hexdigest().lower()
self.content = TestContent(
rand_generator(self.chars, 6), len(self.data), self.url_rand, 1)
self.content.id_container = cid_from_name(
self.account, self.ref).upper()
self.chunk = TestChunk(self.content.size, self.url_rand, 0,
self.hash_rand)
self.chunk_url = "%s/%s" % (self.rawx, self.chunk.id_chunk)
self.chunk_proxy = {"hash": self.chunk.md5, "pos": "0",
"size": self.chunk.size,
"url": self.chunk_url}
chunk_meta = {'content_size': self.content.size,
'content_chunksnb': self.content.nb_chunks,
'content_path': self.content.path,
'content_cid': self.content.id_container,
'content_id': '0000',
'content_version': 1,
'chunk_id': self.chunk.id_chunk,
'chunk_pos': self.chunk.pos}
self.blob_c.chunk_put(self.chunk_url, chunk_meta, self.data)
self.chunk_path = self.test_dir + '/data/NS-rawx-1/' +\
self.chunk.id_chunk[0:2] + "/" + self.chunk.id_chunk
self.bad_container_id = '0'*64
def tearDown(self):
super(TestBlobAuditorFunctional, self).tearDown()
try:
self.container_c.content_delete(
self.account, self.ref, self.content.path)
except Exception:
pass
try:
self.container_c.container_destroy(self.account, self.ref)
except Exception:
pass
try:
os.remove(self.chunk_path)
except Exception:
pass
def init_content(self):
self.container_c.content_create(
self.account, self.ref, self.content.path, self.chunk.size,
self.hash_rand, data=[self.chunk_proxy])
def test_chunk_audit(self):
self.init_content()
self.auditor.chunk_audit(self.chunk_path)
def test_content_deleted(self):
self.assertRaises(exc.OrphanChunk, self.auditor.chunk_audit,
self.chunk_path)
def test_container_deleted(self):
self.container_c.container_destroy(self.account, self.ref)
self.assertRaises(exc.OrphanChunk, self.auditor.chunk_audit,
self.chunk_path)
def test_chunk_corrupted(self):
self.init_content()
with open(self.chunk_path, "w") as f:
f.write(rand_generator(self.chars, 1280))
#.........这里部分代码省略.........
示例4: TestBlobAuditorFunctional
# 需要导入模块: from oio.blob.client import BlobClient [as 别名]
# 或者: from oio.blob.client.BlobClient import chunk_put [as 别名]
class TestBlobAuditorFunctional(BaseTestCase):
def setUp(self):
super(TestBlobAuditorFunctional, self).setUp()
self.namespace = self.conf["namespace"]
self.account = self.conf["account"]
self.test_dir = self.conf["sds_path"]
rawx_num, rawx_path, rawx_addr = self.get_service_url("rawx")
self.rawx = "http://" + rawx_addr
self.h = hashlib.new("md5")
conf = {"namespace": self.namespace}
self.auditor = BlobAuditorWorker(conf, get_logger(None), None)
self.container_c = ContainerClient(conf)
self.blob_c = BlobClient()
self.ref = random_str(8)
self.container_c.container_create(self.account, self.ref)
self.url_rand = random_id(64)
self.data = random_str(1280)
self.h.update(self.data)
self.hash_rand = self.h.hexdigest().lower()
self.content = TestContent(random_str(6), len(self.data), self.url_rand, 1)
self.content.id_container = cid_from_name(self.account, self.ref).upper()
self.chunk = TestChunk(self.content.size, self.url_rand, 0, self.hash_rand)
self.chunk_url = "%s/%s" % (self.rawx, self.chunk.id_chunk)
self.chunk_proxy = {"hash": self.chunk.md5, "pos": "0", "size": self.chunk.size, "url": self.chunk_url}
chunk_meta = {
"content_path": self.content.path,
"container_id": self.content.id_container,
"chunk_method": "plain/nb_copy=3",
"policy": "TESTPOLICY",
"id": "0000",
"version": 1,
"chunk_id": self.chunk.id_chunk,
"chunk_pos": self.chunk.pos,
"chunk_hash": self.chunk.md5,
}
self.blob_c.chunk_put(self.chunk_url, chunk_meta, self.data)
self.chunk_path = (
self.test_dir
+ "/data/"
+ self.namespace
+ "-rawx-1/"
+ self.chunk.id_chunk[0:3]
+ "/"
+ self.chunk.id_chunk
)
self.bad_container_id = "0" * 64
def tearDown(self):
super(TestBlobAuditorFunctional, self).tearDown()
try:
self.container_c.content_delete(self.account, self.ref, self.content.path)
except Exception:
pass
try:
self.container_c.container_destroy(self.account, self.ref)
except Exception:
pass
try:
os.remove(self.chunk_path)
except Exception:
pass
def init_content(self):
self.container_c.content_create(
self.account, self.ref, self.content.path, self.chunk.size, self.hash_rand, data=[self.chunk_proxy]
)
def test_chunk_audit(self):
self.init_content()
self.auditor.chunk_audit(self.chunk_path)
def test_content_deleted(self):
self.assertRaises(exc.OrphanChunk, self.auditor.chunk_audit, self.chunk_path)
def test_container_deleted(self):
self.container_c.container_destroy(self.account, self.ref)
self.assertRaises(exc.OrphanChunk, self.auditor.chunk_audit, self.chunk_path)
def test_chunk_corrupted(self):
self.init_content()
with open(self.chunk_path, "w") as f:
f.write(random_str(1280))
#.........这里部分代码省略.........