本文整理汇总了Python中oio.container.client.ContainerClient.container_create方法的典型用法代码示例。如果您正苦于以下问题:Python ContainerClient.container_create方法的具体用法?Python ContainerClient.container_create怎么用?Python ContainerClient.container_create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类oio.container.client.ContainerClient
的用法示例。
在下文中一共展示了ContainerClient.container_create方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestAccountClient
# 需要导入模块: from oio.container.client import ContainerClient [as 别名]
# 或者: from oio.container.client.ContainerClient import container_create [as 别名]
class TestAccountClient(BaseTestCase):
def setUp(self):
super(TestAccountClient, self).setUp()
self.account_id = "test_account_%f" % time.time()
self.account_client = AccountClient(self.conf)
self.container_client = ContainerClient(self.conf)
self.account_client.account_create(self.account_id)
self.container_client.container_create(acct=self.account_id, ref="container1")
self.container_client.container_create(acct=self.account_id, ref="container2")
time.sleep(0.5) # ensure container event have been processed
def test_containers_list(self):
resp = self.account_client.containers_list(self.account_id)
self.assertEquals(resp["containers"], 2)
self.assertEqual(resp["listing"], [["container1", 0, 0, 0], ["container2", 0, 0, 0]])
resp = self.account_client.containers_list(self.account_id, limit=1)
self.assertEquals(resp["containers"], 2)
self.assertEqual(resp["listing"], [["container1", 0, 0, 0]])
resp = self.account_client.containers_list(self.account_id, marker="container1", limit=1)
self.assertEquals(resp["containers"], 2)
self.assertEqual(resp["listing"], [["container2", 0, 0, 0]])
resp = self.account_client.containers_list(self.account_id, marker="container2", limit=1)
self.assertEquals(resp["containers"], 2)
self.assertEqual(resp["listing"], [])
示例2: TestFilters
# 需要导入模块: from oio.container.client import ContainerClient [as 别名]
# 或者: from oio.container.client.ContainerClient import container_create [as 别名]
class TestFilters(BaseTestCase):
def setUp(self):
with mock.patch('oio.container.client.gen_headers',
gen_headers_mock):
super(TestFilters, self).setUp()
self.account = self.conf['account']
self.namespace = self.conf['namespace']
self.chunk_size = self.conf['chunk_size']
self.gridconf = {'namespace': self.namespace}
self.content_factory = ContentFactory(self.gridconf)
self.container_name = 'TestFilter%f' % time.time()
self.blob_client = BlobClient()
self.container_client = ContainerClient(self.gridconf)
self.container_client.container_create(acct=self.account,
ref=self.container_name)
self.container_id = cid_from_name(self.account,
self.container_name).upper()
self.stgpol = "SINGLE"
def _new_content(self, data, path):
old_content = self.content_factory.new(self.container_id, path,
len(data), self.stgpol)
old_content.create(StringIO.StringIO(data))
return self.content_factory.get(self.container_id,
old_content.content_id)
def test_slave_and_admin(self):
if not os.getenv("SLAVE"):
self.skipTest("must be in slave mode")
data = random_data(10)
path = 'test_slave'
try:
self._new_content(data, path)
self.assertTrue(None)
except ClientException as e:
print str(e)
self.assertTrue(str(e).find('NS slave!') != -1)
with mock.patch('oio.container.client.gen_headers', gen_headers_mock):
content = self._new_content(data, path)
content.delete()
def test_worm_and_admin(self):
if not os.getenv("WORM"):
self.skipTest("must be in worm mode")
data = random_data(10)
path = 'test_worm'
content = self._new_content(data, path)
try:
content.delete()
self.assertTrue(None)
except ClientException as e:
self.assertTrue(str(e).find('NS wormed!') != -1)
downloaded_data = ''.join(content.fetch())
self.assertEqual(downloaded_data, data)
with mock.patch('oio.container.client.gen_headers', gen_headers_mock):
content.delete()
示例3: TestAccountClient
# 需要导入模块: from oio.container.client import ContainerClient [as 别名]
# 或者: from oio.container.client.ContainerClient import container_create [as 别名]
class TestAccountClient(BaseTestCase):
def setUp(self):
super(TestAccountClient, self).setUp()
self.account_id = "test_account_%f" % time.time()
self.account_client = AccountClient(self.conf)
self.container_client = ContainerClient(self.conf)
retry = 3
for i in range(retry+1):
try:
self.account_client.account_create(self.account_id)
break
except ClientException:
if i < retry:
time.sleep(2)
else:
raise
self.container_client.container_create(acct=self.account_id,
ref="container1")
self.container_client.container_create(acct=self.account_id,
ref="container2")
time.sleep(.5) # ensure container event have been processed
def test_containers_list(self):
resp = self.account_client.containers_list(self.account_id)
self.assertEquals(resp["containers"], 2)
self.assertEqual(resp["listing"], [
["container1", 0, 0, 0],
["container2", 0, 0, 0]
])
resp = self.account_client.containers_list(self.account_id, limit=1)
self.assertEquals(resp["containers"], 2)
self.assertEqual(resp["listing"], [
["container1", 0, 0, 0]
])
resp = self.account_client.containers_list(self.account_id,
marker="container1",
limit=1)
self.assertEquals(resp["containers"], 2)
self.assertEqual(resp["listing"], [
["container2", 0, 0, 0]
])
resp = self.account_client.containers_list(self.account_id,
marker="container2",
limit=1)
self.assertEquals(resp["containers"], 2)
self.assertEqual(resp["listing"], [])
示例4: TestStorageTierer
# 需要导入模块: from oio.container.client import ContainerClient [as 别名]
# 或者: from oio.container.client.ContainerClient import container_create [as 别名]
class TestStorageTierer(BaseTestCase):
def setUp(self):
super(TestStorageTierer, self).setUp()
self.namespace = self.conf['namespace']
self.test_account = "test_storage_tiering_%f" % time.time()
self.gridconf = {"namespace": self.namespace,
"container_fetch_limit": 2,
"content_fetch_limit": 2,
"account": self.test_account,
"outdated_threshold": 0,
"new_policy": "RAIN"}
self.content_factory = ContentFactory(self.gridconf)
self.container_client = ContainerClient(self.gridconf)
self._populate()
def _populate(self):
self.container_0_name = "container_empty"
self.container_0_id = cid_from_name(
self.test_account, self.container_0_name)
self.container_client.container_create(
acct=self.test_account, ref=self.container_0_name)
self.container_1_name = "container_with_1_content"
self.container_1_id = cid_from_name(
self.test_account, self.container_1_name)
self.container_client.container_create(
acct=self.test_account, ref=self.container_1_name)
self.container_1_content_0_name = "container_1_content_0"
self.container_1_content_0 = self._new_content(
self.container_1_id, self.container_1_content_0_name, "SINGLE")
self.container_2_name = "container_with_2_contents"
self.container_2_id = cid_from_name(
self.test_account, self.container_2_name)
self.container_client.container_create(
acct=self.test_account, ref=self.container_2_name)
self.container_2_content_0_name = "container_2_content_0"
self.container_2_content_0 = self._new_content(
self.container_2_id, self.container_2_content_0_name, "SINGLE")
self.container_2_content_1_name = "container_2_content_1"
self.container_2_content_1 = self._new_content(
self.container_2_id, self.container_2_content_1_name, "TWOCOPIES")
def _new_content(self, container_id, content_name, stgpol):
data = random_data(10)
content = self.content_factory.new(container_id, content_name,
len(data), stgpol)
content.upload(StringIO.StringIO(data))
return content
def tearDown(self):
super(TestStorageTierer, self).tearDown()
def test_iter_container_list(self):
worker = StorageTiererWorker(self.gridconf, Mock())
gen = worker._list_containers()
self.assertEqual(gen.next(), self.container_0_name)
self.assertEqual(gen.next(), self.container_1_name)
self.assertEqual(gen.next(), self.container_2_name)
self.assertRaises(StopIteration, gen.next)
def test_iter_content_list_outdated_threshold_0(self):
self.gridconf["outdated_threshold"] = 0
worker = StorageTiererWorker(self.gridconf, Mock())
gen = worker._list_contents()
self.assertEqual(gen.next(), (
self.container_1_id, self.container_1_content_0.content_id))
self.assertEqual(gen.next(), (
self.container_2_id, self.container_2_content_0.content_id))
self.assertEqual(gen.next(), (
self.container_2_id, self.container_2_content_1.content_id))
self.assertRaises(StopIteration, gen.next)
def test_iter_content_list_outdated_threshold_9999999999(self):
self.gridconf["outdated_threshold"] = 9999999999
worker = StorageTiererWorker(self.gridconf, Mock())
gen = worker._list_contents()
self.assertRaises(StopIteration, gen.next)
def test_iter_content_list_outdated_threshold_2(self):
# add a new content created after the three previous contents
now = int(time.time())
time.sleep(2)
self._new_content(self.container_2_id, "titi", "TWOCOPIES")
self.gridconf["outdated_threshold"] = 2
worker = StorageTiererWorker(self.gridconf, Mock())
with mock.patch('oio.crawler.storage_tierer.time.time',
mock.MagicMock(return_value=now+2)):
gen = worker._list_contents()
self.assertEqual(gen.next(), (
self.container_1_id, self.container_1_content_0.content_id))
self.assertEqual(gen.next(), (
self.container_2_id, self.container_2_content_0.content_id))
self.assertEqual(gen.next(), (
self.container_2_id, self.container_2_content_1.content_id))
self.assertRaises(StopIteration, gen.next)
def test_iter_content_list_skip_good_policy(self):
#.........这里部分代码省略.........
示例5: TestContentFactory
# 需要导入模块: from oio.container.client import ContainerClient [as 别名]
# 或者: from oio.container.client.ContainerClient import container_create [as 别名]
class TestContentFactory(BaseTestCase):
def setUp(self):
super(TestContentFactory, self).setUp()
self.namespace = self.conf['namespace']
self.chunk_size = self.conf['chunk_size']
self.gridconf = {"namespace": self.namespace}
self.content_factory = ContentFactory(self.gridconf)
self.container_name = "TestContentFactory%f" % time.time()
self.blob_client = BlobClient()
self.container_client = ContainerClient(self.gridconf)
self.container_client.container_create(acct=self.account,
ref=self.container_name)
self.container_id = cid_from_name(self.account,
self.container_name).upper()
def tearDown(self):
super(TestContentFactory, self).tearDown()
def test_extract_datasec(self):
self.content_factory.ns_info = {
"data_security": {
"DUPONETWO": "DUP:distance=1|nb_copy=2",
"RAIN": "RAIN:k=6|m=2|algo=liber8tion"
},
"storage_policy": {
"RAIN": "NONE:RAIN:NONE",
"SINGLE": "NONE:NONE:NONE",
"TWOCOPIES": "NONE:DUPONETWO:NONE"
}
}
ds_type, ds_args = self.content_factory._extract_datasec("RAIN")
self.assertEqual(ds_type, "RAIN")
self.assertEqual(ds_args, {
"k": "6",
"m": "2",
"algo": "liber8tion"
})
ds_type, ds_args = self.content_factory._extract_datasec("SINGLE")
self.assertEqual(ds_type, "DUP")
self.assertEqual(ds_args, {
"nb_copy": "1",
"distance": "0"
})
ds_type, ds_args = self.content_factory._extract_datasec("TWOCOPIES")
self.assertEqual(ds_type, "DUP")
self.assertEqual(ds_args, {
"nb_copy": "2",
"distance": "1"
})
self.assertRaises(InconsistentContent,
self.content_factory._extract_datasec,
"UnKnOwN")
def test_get_rain(self):
meta = {
"chunk-method": "plain/rain?algo=liber8tion&k=6&m=2",
"ctime": "1450176946",
"deleted": "False",
"hash": "E952A419957A6E405BFC53EC65483F73",
"hash-method": "md5",
"id": "3FA2C4A1ED2605005335A276890EC458",
"length": "658",
"mime-type": "application/octet-stream",
"name": "tox.ini",
"policy": "RAIN",
"version": "1450176946676289"
}
chunks = [
{
"url": "http://127.0.0.1:6012/A0A0",
"pos": "0.p0", "size": 512,
"hash": "E7D4E4AD460971CA2E3141F2102308D4"},
{
"url": "http://127.0.0.1:6010/A01",
"pos": "0.1", "size": 146,
"hash": "760AB5DA7C51A3654F1CA622687CD6C3"},
{
"url": "http://127.0.0.1:6011/A00",
"pos": "0.0", "size": 512,
"hash": "B1D08B86B8CAA90A2092CCA0DF9201DB"},
{
"url": "http://127.0.0.1:6013/A0A1",
"pos": "0.p1", "size": 512,
"hash": "DA9D7F72AEEA5791565724424CE45C16"}
]
self.content_factory.container_client.content_show = Mock(
return_value=(meta, chunks))
c = self.content_factory.get("xxx_container_id", "xxx_content_id")
self.assertEqual(type(c), RainContent)
self.assertEqual(c.content_id, "3FA2C4A1ED2605005335A276890EC458")
self.assertEqual(c.length, 658)
self.assertEqual(c.path, "tox.ini")
self.assertEqual(c.version, "1450176946676289")
self.assertEqual(c.algo, "liber8tion")
self.assertEqual(c.k, 6)
self.assertEqual(c.m, 2)
#.........这里部分代码省略.........
示例6: TestDupContent
# 需要导入模块: from oio.container.client import ContainerClient [as 别名]
# 或者: from oio.container.client.ContainerClient import container_create [as 别名]
class TestDupContent(BaseTestCase):
def setUp(self):
super(TestDupContent, self).setUp()
if len(self.conf['rawx']) < 3:
self.skipTest("Not enough rawx. "
"Dup tests needs more than 2 rawx to run")
self.namespace = self.conf['namespace']
self.account = self.conf['account']
self.chunk_size = self.conf['chunk_size']
self.gridconf = {"namespace": self.namespace}
self.content_factory = ContentFactory(self.gridconf)
self.container_client = ContainerClient(self.gridconf)
self.blob_client = BlobClient()
self.container_name = "TestDupContent%f" % time.time()
self.container_client.container_create(acct=self.account,
ref=self.container_name)
self.container_id = cid_from_name(self.account,
self.container_name).upper()
def tearDown(self):
super(TestDupContent, self).tearDown()
def _test_upload(self, stgpol, data_size):
data = random_data(data_size)
content = self.content_factory.new(self.container_id, "titi",
len(data), stgpol)
self.assertEqual(type(content), DupContent)
content.upload(StringIO.StringIO(data))
meta, chunks = self.container_client.content_show(
cid=self.container_id, content=content.content_id)
chunks = ChunksHelper(chunks)
self.assertEqual(meta['hash'], md5_data(data))
self.assertEqual(meta['length'], str(len(data)))
self.assertEqual(meta['policy'], stgpol)
self.assertEqual(meta['name'], "titi")
metachunk_nb = int(math.ceil(float(len(data)) / self.chunk_size))
if metachunk_nb == 0:
metachunk_nb = 1 # special case for empty content
if stgpol == "THREECOPIES":
nb_copy = 3
elif stgpol == "TWOCOPIES":
nb_copy = 2
elif stgpol == "SINGLE":
nb_copy = 1
self.assertEqual(len(chunks), metachunk_nb * nb_copy)
for pos in range(metachunk_nb):
chunks_at_pos = chunks.filter(pos=pos)
self.assertEqual(len(chunks_at_pos), nb_copy)
data_begin = pos * self.chunk_size
data_end = pos * self.chunk_size + self.chunk_size
chunk_hash = md5_data(data[data_begin:data_end])
for chunk in chunks_at_pos:
meta, stream = self.blob_client.chunk_get(chunk.url)
self.assertEqual(md5_stream(stream), chunk_hash)
self.assertEqual(meta['content_size'], str(len(data)))
self.assertEqual(meta['content_path'], "titi")
self.assertEqual(meta['content_cid'], self.container_id)
self.assertEqual(meta['content_id'], meta['content_id'])
self.assertEqual(meta['chunk_id'], chunk.id)
self.assertEqual(meta['chunk_pos'], str(pos))
self.assertEqual(meta['chunk_hash'], chunk_hash)
def test_twocopies_upload_0_byte(self):
self._test_upload("TWOCOPIES", 0)
def test_twocopies_upload_1_byte(self):
self._test_upload("TWOCOPIES", 1)
def test_twocopies_upload_chunksize_bytes(self):
self._test_upload("TWOCOPIES", self.chunk_size)
def test_twocopies_upload_chunksize_plus_1_bytes(self):
self._test_upload("TWOCOPIES", self.chunk_size + 1)
def test_single_upload_0_byte(self):
self._test_upload("SINGLE", 0)
def test_single_upload_chunksize_plus_1_bytes(self):
self._test_upload("SINGLE", self.chunk_size + 1)
def test_chunks_cleanup_when_upload_failed(self):
data = random_data(2 * self.chunk_size)
content = self.content_factory.new(self.container_id, "titi",
len(data), "TWOCOPIES")
self.assertEqual(type(content), DupContent)
# set bad url for position 1
for chunk in content.chunks.filter(pos=1):
chunk.url = "http://127.0.0.1:9/DEADBEEF"
#.........这里部分代码省略.........
示例7: TestRebuilderCrawler
# 需要导入模块: from oio.container.client import ContainerClient [as 别名]
# 或者: from oio.container.client.ContainerClient import container_create [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)
#.........这里部分代码省略.........
示例8: TestBlobAuditorFunctional
# 需要导入模块: from oio.container.client import ContainerClient [as 别名]
# 或者: from oio.container.client.ContainerClient import container_create [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))
#.........这里部分代码省略.........
示例9: TestContentFactory
# 需要导入模块: from oio.container.client import ContainerClient [as 别名]
# 或者: from oio.container.client.ContainerClient import container_create [as 别名]
class TestContentFactory(BaseTestCase):
def setUp(self):
super(TestContentFactory, self).setUp()
self.namespace = self.conf['namespace']
self.chunk_size = self.conf['chunk_size']
self.gridconf = {"namespace": self.namespace}
self.content_factory = ContentFactory(self.gridconf)
self.container_name = "TestContentFactory%f" % time.time()
self.container_client = ContainerClient(self.gridconf)
self.container_client.container_create(acct=self.account,
ref=self.container_name)
self.container_id = cid_from_name(self.account,
self.container_name).upper()
def tearDown(self):
super(TestContentFactory, self).tearDown()
def test_extract_datasec(self):
self.content_factory.ns_info = {
"data_security": {
"DUPONETWO": "DUP:distance=1|nb_copy=2",
"RAIN": "RAIN:k=6|m=2|algo=liber8tion"
},
"storage_policy": {
"RAIN": "NONE:RAIN:NONE",
"SINGLE": "NONE:NONE:NONE",
"TWOCOPIES": "NONE:DUPONETWO:NONE"
}
}
ds_type, ds_args = self.content_factory._extract_datasec("RAIN")
self.assertEqual(ds_type, "RAIN")
self.assertEqual(ds_args, {
"k": "6",
"m": "2",
"algo": "liber8tion"
})
ds_type, ds_args = self.content_factory._extract_datasec("SINGLE")
self.assertEqual(ds_type, "DUP")
self.assertEqual(ds_args, {
"nb_copy": "1",
"distance": "0"
})
ds_type, ds_args = self.content_factory._extract_datasec("TWOCOPIES")
self.assertEqual(ds_type, "DUP")
self.assertEqual(ds_args, {
"nb_copy": "2",
"distance": "1"
})
self.assertRaises(InconsistentContent,
self.content_factory._extract_datasec,
"UnKnOwN")
def test_get_rain(self):
meta = {
"chunk-method": "plain/rain?algo=liber8tion&k=6&m=2",
"ctime": "1450176946",
"deleted": "False",
"hash": "E952A419957A6E405BFC53EC65483F73",
"hash-method": "md5",
"id": "3FA2C4A1ED2605005335A276890EC458",
"length": "658",
"mime-type": "application/octet-stream",
"name": "tox.ini",
"policy": "RAIN",
"version": "1450176946676289"
}
chunks = [
{
"url": "http://127.0.0.1:6012/A0A0",
"pos": "0.p0", "size": 512,
"hash": "E7D4E4AD460971CA2E3141F2102308D4"},
{
"url": "http://127.0.0.1:6010/A01",
"pos": "0.1", "size": 146,
"hash": "760AB5DA7C51A3654F1CA622687CD6C3"},
{
"url": "http://127.0.0.1:6011/A00",
"pos": "0.0", "size": 512,
"hash": "B1D08B86B8CAA90A2092CCA0DF9201DB"},
{
"url": "http://127.0.0.1:6013/A0A1",
"pos": "0.p1", "size": 512,
"hash": "DA9D7F72AEEA5791565724424CE45C16"}
]
self.content_factory.container_client.content_show = Mock(
return_value=(meta, chunks))
c = self.content_factory.get("xxx_container_id", "xxx_content_id")
self.assertEqual(type(c), RainContent)
self.assertEqual(c.content_id, "3FA2C4A1ED2605005335A276890EC458")
self.assertEqual(c.length, 658)
self.assertEqual(c.path, "tox.ini")
self.assertEqual(c.version, "1450176946676289")
self.assertEqual(c.algo, "liber8tion")
self.assertEqual(c.k, 6)
self.assertEqual(c.m, 2)
self.assertEqual(len(c.chunks), 4)
#.........这里部分代码省略.........
示例10: TestBlobAuditorFunctional
# 需要导入模块: from oio.container.client import ContainerClient [as 别名]
# 或者: from oio.container.client.ContainerClient import container_create [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)
#.........这里部分代码省略.........
示例11: TestRainContent
# 需要导入模块: from oio.container.client import ContainerClient [as 别名]
# 或者: from oio.container.client.ContainerClient import container_create [as 别名]
class TestRainContent(BaseTestCase):
def setUp(self):
super(TestRainContent, self).setUp()
if len(self.conf['rawx']) < 12:
self.skipTest("Not enough rawx. "
"Rain tests needs more than 12 rawx to run")
self.namespace = self.conf['namespace']
self.account = self.conf['account']
self.chunk_size = self.conf['chunk_size']
self.gridconf = {"namespace": self.namespace}
self.content_factory = ContentFactory(self.gridconf)
self.container_client = ContainerClient(self.gridconf)
self.blob_client = BlobClient()
self.container_name = "TestRainContent%f" % time.time()
self.container_client.container_create(acct=self.account,
ref=self.container_name)
self.container_id = cid_from_name(self.account,
self.container_name).upper()
def tearDown(self):
super(TestRainContent, self).tearDown()
def _test_upload(self, data_size):
data = random_data(data_size)
content = self.content_factory.new(self.container_id, "titi",
len(data), "RAIN")
k = 6
m = 2
self.assertEqual(type(content), RainContent)
content.upload(StringIO.StringIO(data))
meta, chunks = self.container_client.content_show(
cid=self.container_id, content=content.content_id)
chunks = ChunksHelper(chunks)
self.assertEqual(meta['hash'], md5_data(data))
self.assertEqual(meta['length'], str(len(data)))
self.assertEqual(meta['policy'], "RAIN")
self.assertEqual(meta['name'], "titi")
metachunk_nb = int(math.ceil(float(len(data)) / self.chunk_size))
if metachunk_nb == 0:
metachunk_nb = 1 # special case for empty content
nb_chunks_min = metachunk_nb * (1 + m)
nb_chunks_max = metachunk_nb * (k + m)
self.assertGreaterEqual(len(chunks), nb_chunks_min)
self.assertLessEqual(len(chunks), nb_chunks_max)
for metapos in range(metachunk_nb):
chunks_at_pos = content.chunks.filter(metapos=metapos)
data_chunks_at_pos = chunks_at_pos.filter(is_parity=False)
parity_chunks_at_pos = chunks_at_pos.filter(is_parity=True)
self.assertEquals(len(data_chunks_at_pos) >= 1, True)
self.assertEquals(len(data_chunks_at_pos) <= k, True)
self.assertEqual(len(parity_chunks_at_pos), m)
for chunk in chunks_at_pos:
meta, stream = self.blob_client.chunk_get(chunk.url)
self.assertEqual(md5_stream(stream), chunk.hash)
self.assertEqual(meta['content_size'], str(len(data)))
self.assertEqual(meta['content_path'], "titi")
self.assertEqual(meta['content_cid'], self.container_id)
self.assertEqual(meta['content_id'], meta['content_id'])
self.assertEqual(meta['chunk_id'], chunk.id)
self.assertEqual(meta['chunk_pos'], chunk.pos)
self.assertEqual(meta['chunk_hash'], chunk.hash)
data_begin = metapos * self.chunk_size
data_end = metapos * self.chunk_size + self.chunk_size
target_metachunk_hash = md5_data(data[data_begin:data_end])
metachunk_hash = hashlib.md5()
for chunk in data_chunks_at_pos:
meta, stream = self.blob_client.chunk_get(chunk.url)
for d in stream:
metachunk_hash.update(d)
self.assertEqual(metachunk_hash.hexdigest().upper(),
target_metachunk_hash)
def test_upload_0_byte(self):
self._test_upload(0)
def test_upload_1_byte(self):
self._test_upload(1)
def test_upload_chunksize_bytes(self):
self._test_upload(self.chunk_size)
def test_upload_chunksize_plus_1_bytes(self):
self._test_upload(self.chunk_size + 1)
def test_chunks_cleanup_when_upload_failed(self):
data = random_data(2 * self.chunk_size)
content = self.content_factory.new(self.container_id, "titi",
len(data), "RAIN")
self.assertEqual(type(content), RainContent)
#.........这里部分代码省略.........
示例12: TestECContent
# 需要导入模块: from oio.container.client import ContainerClient [as 别名]
# 或者: from oio.container.client.ContainerClient import container_create [as 别名]
class TestECContent(BaseTestCase):
def setUp(self):
super(TestECContent, self).setUp()
if len(self.conf['services']['rawx']) < 12:
self.skipTest("Not enough rawx. "
"EC tests needs at least 12 rawx to run")
self.namespace = self.conf['namespace']
self.account = self.conf['account']
self.chunk_size = self.conf['chunk_size']
self.gridconf = {"namespace": self.namespace}
self.content_factory = ContentFactory(self.gridconf)
self.container_client = ContainerClient(self.gridconf)
self.blob_client = BlobClient()
self.container_name = "TestECContent%f" % time.time()
self.container_client.container_create(acct=self.account,
ref=self.container_name)
self.container_id = cid_from_name(self.account,
self.container_name).upper()
self.content = random_str(64)
self.stgpol = "EC"
self.size = 1024*1024 + 320
self.k = 6
self.m = 3
def tearDown(self):
super(TestECContent, self).tearDown()
def random_chunks(self, nb):
l = random.sample(xrange(self.k + self.m), nb)
return ["0.%s" % i for i in l]
def _test_create(self, data_size):
# generate random test data
data = random_data(data_size)
# using factory create new EC content
content = self.content_factory.new(
self.container_id, self.content, len(data), self.stgpol)
# verify the factory gave us an ECContent
self.assertEqual(type(content), ECContent)
# perform the content creation
content.create(StringIO(data))
meta, chunks = self.container_client.content_show(
cid=self.container_id, content=content.content_id)
# verify metadata
chunks = ChunksHelper(chunks)
self.assertEqual(meta['hash'], md5_data(data))
self.assertEqual(meta['length'], str(len(data)))
self.assertEqual(meta['policy'], self.stgpol)
self.assertEqual(meta['name'], self.content)
metachunk_nb = int(math.ceil(float(len(data)) / self.chunk_size)) \
if len(data) != 0 else 1
# verify each metachunk
for metapos in range(metachunk_nb):
chunks_at_pos = content.chunks.filter(metapos=metapos)
for chunk in chunks_at_pos:
meta, stream = self.blob_client.chunk_get(chunk.url)
self.assertEqual(meta['metachunk_size'], str(chunk.size))
self.assertEqual(meta['metachunk_hash'], chunk.checksum)
self.assertEqual(meta['content_path'], self.content)
self.assertEqual(meta['container_id'], self.container_id)
self.assertEqual(meta['content_id'], meta['content_id'])
self.assertEqual(meta['chunk_id'], chunk.id)
self.assertEqual(meta['chunk_pos'], chunk.pos)
self.assertEqual(meta['chunk_hash'], md5_stream(stream))
def test_create_0_byte(self):
self._test_create(0)
def test_create_1_byte(self):
self._test_create(1)
def test_create(self):
self._test_create(DAT_LEGIT_SIZE)
def _test_rebuild(self, data_size, broken_pos_list):
# generate test data
data = os.urandom(data_size)
# create initial content
old_content = self.content_factory.new(
self.container_id, self.content, len(data), self.stgpol)
# verify factory work as intended
self.assertEqual(type(old_content), ECContent)
# perform initial content creation
old_content.create(StringIO(data))
uploaded_content = self.content_factory.get(self.container_id,
old_content.content_id)
# break the content
old_info = {}
for pos in broken_pos_list:
old_info[pos] = {}
#.........这里部分代码省略.........
示例13: TestBlobAuditorFunctional
# 需要导入模块: from oio.container.client import ContainerClient [as 别名]
# 或者: from oio.container.client.ContainerClient import container_create [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))
#.........这里部分代码省略.........