本文整理汇总了Python中oslo_utils.units.Ki方法的典型用法代码示例。如果您正苦于以下问题:Python units.Ki方法的具体用法?Python units.Ki怎么用?Python units.Ki使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类oslo_utils.units
的用法示例。
在下文中一共展示了units.Ki方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_available_resources
# 需要导入模块: from oslo_utils import units [as 别名]
# 或者: from oslo_utils.units import Ki [as 别名]
def get_available_resources(self):
"""Retrieve resource information.
This method is called when zun-compute launches, and
as part of a periodic task that records the results in the DB.
:returns: dictionary containing resource info
"""
data = {}
numa_topo_obj = self.get_host_numa_topology()
data['numa_topology'] = numa_topo_obj
meminfo = self.get_host_mem()
(mem_total, mem_free, mem_ava, mem_used) = meminfo
data['mem_total'] = mem_total // units.Ki
data['mem_free'] = mem_free // units.Ki
data['mem_available'] = mem_ava // units.Ki
data['mem_used'] = mem_used // units.Ki
disk_total, disk_reserved = self.get_total_disk_for_container()
data['disk_total'] = disk_total - disk_reserved
disk_quota_supported = self.node_support_disk_quota()
data['disk_quota_supported'] = disk_quota_supported
data['enable_cpu_pinning'] = CONF.compute.enable_cpu_pinning
return data
示例2: test_add_with_verifier
# 需要导入模块: from oslo_utils import units [as 别名]
# 或者: from oslo_utils.units import Ki [as 别名]
def test_add_with_verifier(self):
"""Test that 'verifier.update' is called when verifier is provided."""
verifier = mock.MagicMock(name='mock_verifier')
self.config(filesystem_store_chunk_size=units.Ki,
group='glance_store')
self.store.configure()
image_id = str(uuid.uuid4())
file_size = units.Ki # 1K
file_contents = b"*" * file_size
image_file = six.BytesIO(file_contents)
self.store.add(image_id, image_file, file_size, self.hash_algo,
verifier=verifier)
verifier.update.assert_called_with(file_contents)
示例3: _do_test_add_write_failure
# 需要导入模块: from oslo_utils import units [as 别名]
# 或者: from oslo_utils.units import Ki [as 别名]
def _do_test_add_write_failure(self, errno, exception):
filesystem.ChunkedFile.CHUNKSIZE = units.Ki
image_id = str(uuid.uuid4())
file_size = 5 * units.Ki # 5K
file_contents = b"*" * file_size
path = os.path.join(self.test_dir, image_id)
image_file = six.BytesIO(file_contents)
with mock.patch.object(builtins, 'open') as popen:
e = IOError()
e.errno = errno
popen.side_effect = e
self.assertRaises(exception,
self.store.add,
image_id, image_file, 0, self.hash_algo)
self.assertFalse(os.path.exists(path))
示例4: test_add_cleanup_on_read_failure
# 需要导入模块: from oslo_utils import units [as 别名]
# 或者: from oslo_utils.units import Ki [as 别名]
def test_add_cleanup_on_read_failure(self):
"""
Tests the partial image file is cleaned up after a read
failure.
"""
filesystem.ChunkedFile.CHUNKSIZE = units.Ki
image_id = str(uuid.uuid4())
file_size = 5 * units.Ki # 5K
file_contents = b"*" * file_size
path = os.path.join(self.test_dir, image_id)
image_file = six.BytesIO(file_contents)
def fake_Error(size):
raise AttributeError()
with mock.patch.object(image_file, 'read') as mock_read:
mock_read.side_effect = fake_Error
self.assertRaises(AttributeError,
self.store.add,
image_id, image_file, 0, self.hash_algo)
self.assertFalse(os.path.exists(path))
示例5: test_delete
# 需要导入模块: from oslo_utils import units [as 别名]
# 或者: from oslo_utils.units import Ki [as 别名]
def test_delete(self):
"""
Test we can delete an existing image in the filesystem store
"""
# First add an image
image_id = str(uuid.uuid4())
file_size = 5 * units.Ki # 5K
file_contents = b"*" * file_size
image_file = six.BytesIO(file_contents)
loc, size, checksum, multihash, _ = self.store.add(
image_id, image_file, file_size, self.hash_algo)
# Now check that we can delete it
uri = "file:///%s/%s" % (self.test_dir, image_id)
loc = location.get_location_from_uri(uri, conf=self.conf)
self.store.delete(loc)
self.assertRaises(exceptions.NotFound, self.store.get, loc)
示例6: setUp
# 需要导入模块: from oslo_utils import units [as 别名]
# 或者: from oslo_utils.units import Ki [as 别名]
def setUp(self):
"""Establish a clean test environment."""
super(TestStore, self).setUp()
rbd_store.rados = MockRados
rbd_store.rbd = MockRBD
self.store = rbd_store.Store(self.conf)
self.store.configure()
self.store.chunk_size = 2
self.called_commands_actual = []
self.called_commands_expected = []
self.store_specs = {'pool': 'fake_pool',
'image': 'fake_image',
'snapshot': 'fake_snapshot'}
self.location = rbd_store.StoreLocation(self.store_specs,
self.conf)
# Provide enough data to get more than one chunk iteration.
self.data_len = 3 * units.Ki
self.data_iter = six.BytesIO(b'*' * self.data_len)
self.hash_algo = 'sha256'
示例7: test_add_already_existing
# 需要导入模块: from oslo_utils import units [as 别名]
# 或者: from oslo_utils.units import Ki [as 别名]
def test_add_already_existing(self):
"""
Tests that adding an image with an existing identifier
raises an appropriate exception
"""
filesystem.ChunkedFile.CHUNKSIZE = units.Ki
image_id = str(uuid.uuid4())
file_size = 5 * units.Ki # 5K
file_contents = b"*" * file_size
image_file = six.BytesIO(file_contents)
location, size, checksum, metadata = self.store.add(image_id,
image_file,
file_size)
self.assertEqual(u"file1", metadata["store"])
image_file = six.BytesIO(b"nevergonnamakeit")
self.assertRaises(exceptions.Duplicate,
self.store.add,
image_id, image_file, 0)
示例8: _do_test_add_write_failure
# 需要导入模块: from oslo_utils import units [as 别名]
# 或者: from oslo_utils.units import Ki [as 别名]
def _do_test_add_write_failure(self, errno, exception):
filesystem.ChunkedFile.CHUNKSIZE = units.Ki
image_id = str(uuid.uuid4())
file_size = 5 * units.Ki # 5K
file_contents = b"*" * file_size
path = os.path.join(self.test_dir, image_id)
image_file = six.BytesIO(file_contents)
with mock.patch.object(builtins, 'open') as popen:
e = IOError()
e.errno = errno
popen.side_effect = e
self.assertRaises(exception,
self.store.add,
image_id, image_file, 0)
self.assertFalse(os.path.exists(path))
示例9: test_delete
# 需要导入模块: from oslo_utils import units [as 别名]
# 或者: from oslo_utils.units import Ki [as 别名]
def test_delete(self):
"""Test we can delete an existing image in the filesystem store."""
# First add an image
image_id = str(uuid.uuid4())
file_size = 5 * units.Ki # 5K
file_contents = b"*" * file_size
image_file = six.BytesIO(file_contents)
loc, size, checksum, metadata = self.store.add(image_id,
image_file,
file_size)
self.assertEqual(u"file1", metadata["store"])
# Now check that we can delete it
uri = "file:///%s/%s" % (self.test_dir, image_id)
loc = location.get_location_from_uri_and_backend(uri, "file1",
conf=self.conf)
self.store.delete(loc)
self.assertRaises(exceptions.NotFound, self.store.get, loc)
示例10: test_add_w_image_size_zero_to_different_backend
# 需要导入模块: from oslo_utils import units [as 别名]
# 或者: from oslo_utils.units import Ki [as 别名]
def test_add_w_image_size_zero_to_different_backend(self):
"""Assert that correct size is returned even though 0 was provided."""
self.store = rbd_store.Store(self.conf, backend="ceph2")
self.store.configure()
self.called_commands_actual = []
self.called_commands_expected = []
self.store_specs = {'pool': 'fake_pool_1',
'image': 'fake_image_1',
'snapshot': 'fake_snapshot_1'}
self.location = rbd_store.StoreLocation(self.store_specs,
self.conf)
# Provide enough data to get more than one chunk iteration.
self.data_len = 3 * units.Ki
self.data_iter = six.BytesIO(b'*' * self.data_len)
self.store.chunk_size = units.Ki
with mock.patch.object(rbd_store.rbd.Image, 'resize') as resize:
with mock.patch.object(rbd_store.rbd.Image, 'write') as write:
ret = self.store.add('fake_image_id', self.data_iter, 0)
self.assertTrue(resize.called)
self.assertTrue(write.called)
self.assertEqual(ret[1], self.data_len)
self.assertEqual("ceph2", ret[3]['store'])
示例11: get_share_quota
# 需要导入模块: from oslo_utils import units [as 别名]
# 或者: from oslo_utils.units import Ki [as 别名]
def get_share_quota(self, share_id):
command = ['quota', 'list', self.fs_name, share_id]
output, err = self._execute(command)
quota = Quota(output)
if quota.limit is None:
return None
if quota.limit_unit == 'TB':
return quota.limit * units.Ki
elif quota.limit_unit == 'GB':
return quota.limit
else:
msg = _("Share %s does not support quota values "
"below 1G.") % share_id
LOG.error(msg)
raise exception.HNASBackendException(msg=msg)
示例12: __init__
# 需要导入模块: from oslo_utils import units [as 别名]
# 或者: from oslo_utils.units import Ki [as 别名]
def __init__(self, data):
if data:
items = data.split()
self.id = items[0]
self.label = items[1]
self.evs = items[2]
self.size = float(items[3])
self.size_measure = items[4]
if self.size_measure == 'TB':
self.size = self.size * units.Ki
if items[5:7] == ["Not", "mounted"]:
self.mounted = False
else:
self.mounted = True
self.used = float(items[5])
self.used_measure = items[6]
if self.used_measure == 'TB':
self.used = self.used * units.Ki
self.dedupe = 'dedupe enabled' in data
示例13: test_get_memory_info
# 需要导入模块: from oslo_utils import units [as 别名]
# 或者: from oslo_utils.units import Ki [as 别名]
def test_get_memory_info(self):
self._hostops._hostutils.get_memory_info.return_value = (2 * units.Ki,
1 * units.Ki)
response = self._hostops._get_memory_info()
self._hostops._hostutils.get_memory_info.assert_called_once_with()
self.assertEqual((2, 1, 1), response)
示例14: test_bytes_per_sec_to_iops
# 需要导入模块: from oslo_utils import units [as 别名]
# 或者: from oslo_utils.units import Ki [as 别名]
def test_bytes_per_sec_to_iops(self):
no_bytes = 15 * units.Ki
expected_iops = 2
resulted_iops = self._volumeops.bytes_per_sec_to_iops(no_bytes)
self.assertEqual(expected_iops, resulted_iops)
示例15: test_cinder_get
# 需要导入模块: from oslo_utils import units [as 别名]
# 或者: from oslo_utils.units import Ki [as 别名]
def test_cinder_get(self):
expected_size = 5 * units.Ki
expected_file_contents = b"*" * expected_size
volume_file = six.BytesIO(expected_file_contents)
fake_client = FakeObject(auth_token=None, management_url=None)
fake_volume_uuid = str(uuid.uuid4())
fake_volume = mock.MagicMock(id=fake_volume_uuid,
metadata={'image_size': expected_size},
status='available')
fake_volume.manager.get.return_value = fake_volume
fake_volumes = FakeObject(get=lambda id: fake_volume)
@contextlib.contextmanager
def fake_open(client, volume, mode):
self.assertEqual('rb', mode)
yield volume_file
with mock.patch.object(cinder.Store, 'get_cinderclient') as mock_cc, \
mock.patch.object(self.store, '_open_cinder_volume',
side_effect=fake_open):
mock_cc.return_value = FakeObject(client=fake_client,
volumes=fake_volumes)
uri = "cinder://%s" % fake_volume_uuid
loc = location.get_location_from_uri(uri, conf=self.conf)
(image_file, image_size) = self.store.get(loc,
context=self.context)
expected_num_chunks = 2
data = b""
num_chunks = 0
for chunk in image_file:
num_chunks += 1
data += chunk
self.assertEqual(expected_num_chunks, num_chunks)
self.assertEqual(expected_file_contents, data)