Allow fallocate_reserve to be a percentage
Add the ability to set the fallocate_reserve value as a percentage. This happens automatically when adding the '%' at the end of the value. Having the ability to set a % of free space rather than a byte value is useful especially when drive sizes are heterogenous. The default for fallocate_reserve has been adjusted to 1%, having the fallocate_reserve set seems sensible for all deploys and percentages are far safer to default than byte values (across drives of any size). Tests added for using fallocate_reserve as a percentage. Duplicate tests for fallocate_reserve have been removed. Docs updated to reflect the fallocate_reserve change. Change-Id: I4aea613a708205c917e81d6b2861396655e73238
This commit is contained in:
@@ -121,8 +121,10 @@ The default is false.
|
|||||||
.IP \fBeventlet_debug\fR
|
.IP \fBeventlet_debug\fR
|
||||||
Debug mode for eventlet library. The default is false.
|
Debug mode for eventlet library. The default is false.
|
||||||
.IP \fBfallocate_reserve\fR
|
.IP \fBfallocate_reserve\fR
|
||||||
You can set fallocate_reserve to the number of bytes you'd like fallocate to
|
You can set fallocate_reserve to the number of bytes or percentage of disk
|
||||||
reserve, whether there is space for the given file size or not. The default is 0.
|
space you'd like fallocate to reserve, whether there is space for the given
|
||||||
|
file size or not. Percentage will be used if the value ends with a '%'.
|
||||||
|
The default is 1%.
|
||||||
.RE
|
.RE
|
||||||
.PD
|
.PD
|
||||||
|
|
||||||
|
@@ -127,8 +127,10 @@ The default is false.
|
|||||||
.IP \fBeventlet_debug\fR
|
.IP \fBeventlet_debug\fR
|
||||||
Debug mode for eventlet library. The default is false.
|
Debug mode for eventlet library. The default is false.
|
||||||
.IP \fBfallocate_reserve\fR
|
.IP \fBfallocate_reserve\fR
|
||||||
You can set fallocate_reserve to the number of bytes you'd like fallocate to
|
You can set fallocate_reserve to the number of bytes or percentage of disk
|
||||||
reserve, whether there is space for the given file size or not. The default is 0.
|
space you'd like fallocate to reserve, whether there is space for the given
|
||||||
|
file size or not. Percentage will be used if the value ends with a '%'.
|
||||||
|
The default is 1%.
|
||||||
.RE
|
.RE
|
||||||
.PD
|
.PD
|
||||||
|
|
||||||
|
@@ -126,8 +126,10 @@ The default is empty.
|
|||||||
.IP \fBeventlet_debug\fR
|
.IP \fBeventlet_debug\fR
|
||||||
Debug mode for eventlet library. The default is false.
|
Debug mode for eventlet library. The default is false.
|
||||||
.IP \fBfallocate_reserve\fR
|
.IP \fBfallocate_reserve\fR
|
||||||
You can set fallocate_reserve to the number of bytes you'd like fallocate to
|
You can set fallocate_reserve to the number of bytes or percentage of disk
|
||||||
reserve, whether there is space for the given file size or not. The default is 0.
|
space you'd like fallocate to reserve, whether there is space for the given
|
||||||
|
file size or not. Percentage will be used if the value ends with a '%'.
|
||||||
|
The default is 1%.
|
||||||
.IP \fBnode_timeout\fR
|
.IP \fBnode_timeout\fR
|
||||||
Request timeout to external services. The default is 3 seconds.
|
Request timeout to external services. The default is 3 seconds.
|
||||||
.IP \fBconn_timeout\fR
|
.IP \fBconn_timeout\fR
|
||||||
|
@@ -489,12 +489,14 @@ log_statsd_sample_rate_factor 1.0
|
|||||||
log_statsd_metric_prefix
|
log_statsd_metric_prefix
|
||||||
eventlet_debug false If true, turn on debug logging for
|
eventlet_debug false If true, turn on debug logging for
|
||||||
eventlet
|
eventlet
|
||||||
fallocate_reserve 0 You can set fallocate_reserve to the
|
fallocate_reserve 1% You can set fallocate_reserve to the
|
||||||
number of bytes you'd like fallocate to
|
number of bytes or percentage of disk
|
||||||
reserve, whether there is space for the
|
space you'd like fallocate to reserve,
|
||||||
given file size or not. This is useful for
|
whether there is space for the given
|
||||||
systems that behave badly when they
|
file size or not. Percentage will be used
|
||||||
completely run out of space; you can
|
if the value ends with a '%'. This is
|
||||||
|
useful for systems that behave badly when
|
||||||
|
they completely run out of space; you can
|
||||||
make the services pretend they're out of
|
make the services pretend they're out of
|
||||||
space early.
|
space early.
|
||||||
conn_timeout 0.5 Time to wait while attempting to connect
|
conn_timeout 0.5 Time to wait while attempting to connect
|
||||||
@@ -809,13 +811,16 @@ log_statsd_default_sample_rate 1.0
|
|||||||
log_statsd_sample_rate_factor 1.0
|
log_statsd_sample_rate_factor 1.0
|
||||||
log_statsd_metric_prefix
|
log_statsd_metric_prefix
|
||||||
eventlet_debug false If true, turn on debug logging for eventlet
|
eventlet_debug false If true, turn on debug logging for eventlet
|
||||||
fallocate_reserve 0 You can set fallocate_reserve to the number of
|
fallocate_reserve 1% You can set fallocate_reserve to the
|
||||||
bytes you'd like fallocate to reserve, whether
|
number of bytes or percentage of disk
|
||||||
there is space for the given file size or not.
|
space you'd like fallocate to reserve,
|
||||||
This is useful for systems that behave badly
|
whether there is space for the given
|
||||||
when they completely run out of space; you can
|
file size or not. Percentage will be used
|
||||||
make the services pretend they're out of space
|
if the value ends with a '%'. This is
|
||||||
early.
|
useful for systems that behave badly when
|
||||||
|
they completely run out of space; you can
|
||||||
|
make the services pretend they're out of
|
||||||
|
space early.
|
||||||
db_preallocation off If you don't mind the extra disk space usage
|
db_preallocation off If you don't mind the extra disk space usage
|
||||||
in overhead, you can turn this on to preallocate
|
in overhead, you can turn this on to preallocate
|
||||||
disk space with SQLite databases to decrease
|
disk space with SQLite databases to decrease
|
||||||
@@ -1024,13 +1029,16 @@ log_statsd_default_sample_rate 1.0
|
|||||||
log_statsd_sample_rate_factor 1.0
|
log_statsd_sample_rate_factor 1.0
|
||||||
log_statsd_metric_prefix
|
log_statsd_metric_prefix
|
||||||
eventlet_debug false If true, turn on debug logging for eventlet
|
eventlet_debug false If true, turn on debug logging for eventlet
|
||||||
fallocate_reserve 0 You can set fallocate_reserve to the number of
|
fallocate_reserve 1% You can set fallocate_reserve to the
|
||||||
bytes you'd like fallocate to reserve, whether
|
number of bytes or percentage of disk
|
||||||
there is space for the given file size or not.
|
space you'd like fallocate to reserve,
|
||||||
This is useful for systems that behave badly
|
whether there is space for the given
|
||||||
when they completely run out of space; you can
|
file size or not. Percentage will be used
|
||||||
make the services pretend they're out of space
|
if the value ends with a '%'. This is
|
||||||
early.
|
useful for systems that behave badly when
|
||||||
|
they completely run out of space; you can
|
||||||
|
make the services pretend they're out of
|
||||||
|
space early.
|
||||||
=============================== ========== =============================================
|
=============================== ========== =============================================
|
||||||
|
|
||||||
[account-server]
|
[account-server]
|
||||||
|
@@ -47,9 +47,10 @@ bind_port = 6002
|
|||||||
#
|
#
|
||||||
# eventlet_debug = false
|
# eventlet_debug = false
|
||||||
#
|
#
|
||||||
# You can set fallocate_reserve to the number of bytes you'd like fallocate to
|
# You can set fallocate_reserve to the number of bytes or percentage of disk
|
||||||
# reserve, whether there is space for the given file size or not.
|
# space you'd like fallocate to reserve, whether there is space for the given
|
||||||
# fallocate_reserve = 0
|
# file size or not. Percentage will be used if the value ends with a '%'.
|
||||||
|
# fallocate_reserve = 1%
|
||||||
|
|
||||||
[pipeline:main]
|
[pipeline:main]
|
||||||
pipeline = healthcheck recon account-server
|
pipeline = healthcheck recon account-server
|
||||||
|
@@ -53,9 +53,10 @@ bind_port = 6001
|
|||||||
#
|
#
|
||||||
# eventlet_debug = false
|
# eventlet_debug = false
|
||||||
#
|
#
|
||||||
# You can set fallocate_reserve to the number of bytes you'd like fallocate to
|
# You can set fallocate_reserve to the number of bytes or percentage of disk
|
||||||
# reserve, whether there is space for the given file size or not.
|
# space you'd like fallocate to reserve, whether there is space for the given
|
||||||
# fallocate_reserve = 0
|
# file size or not. Percentage will be used if the value ends with a '%'.
|
||||||
|
# fallocate_reserve = 1%
|
||||||
|
|
||||||
[pipeline:main]
|
[pipeline:main]
|
||||||
pipeline = healthcheck recon container-server
|
pipeline = healthcheck recon container-server
|
||||||
|
@@ -52,9 +52,10 @@ bind_port = 6000
|
|||||||
#
|
#
|
||||||
# eventlet_debug = false
|
# eventlet_debug = false
|
||||||
#
|
#
|
||||||
# You can set fallocate_reserve to the number of bytes you'd like fallocate to
|
# You can set fallocate_reserve to the number of bytes or percentage of disk
|
||||||
# reserve, whether there is space for the given file size or not.
|
# space you'd like fallocate to reserve, whether there is space for the given
|
||||||
# fallocate_reserve = 0
|
# file size or not. Percentage will be used if the value ends with a '%'.
|
||||||
|
# fallocate_reserve = 1%
|
||||||
#
|
#
|
||||||
# Time to wait while attempting to connect to another backend node.
|
# Time to wait while attempting to connect to another backend node.
|
||||||
# conn_timeout = 0.5
|
# conn_timeout = 0.5
|
||||||
|
@@ -92,9 +92,8 @@ def run_daemon(klass, conf_file, section_name='', once=False, **kwargs):
|
|||||||
if utils.config_true_value(conf.get('disable_fallocate', 'no')):
|
if utils.config_true_value(conf.get('disable_fallocate', 'no')):
|
||||||
utils.disable_fallocate()
|
utils.disable_fallocate()
|
||||||
# set utils.FALLOCATE_RESERVE if desired
|
# set utils.FALLOCATE_RESERVE if desired
|
||||||
reserve = int(conf.get('fallocate_reserve', 0))
|
utils.FALLOCATE_RESERVE, utils.FALLOCATE_IS_PERCENT = \
|
||||||
if reserve > 0:
|
utils.config_fallocate_value(conf.get('fallocate_reserve', '1%'))
|
||||||
utils.FALLOCATE_RESERVE = reserve
|
|
||||||
|
|
||||||
# By default, disable eventlet printing stacktraces
|
# By default, disable eventlet printing stacktraces
|
||||||
eventlet_debug = utils.config_true_value(conf.get('eventlet_debug', 'no'))
|
eventlet_debug = utils.config_true_value(conf.get('eventlet_debug', 'no'))
|
||||||
|
@@ -97,6 +97,9 @@ _libc_accept = None
|
|||||||
# If set to non-zero, fallocate routines will fail based on free space
|
# If set to non-zero, fallocate routines will fail based on free space
|
||||||
# available being at or below this amount, in bytes.
|
# available being at or below this amount, in bytes.
|
||||||
FALLOCATE_RESERVE = 0
|
FALLOCATE_RESERVE = 0
|
||||||
|
# Indicates if FALLOCATE_RESERVE is the percentage of free space (True) or
|
||||||
|
# the number of bytes (False).
|
||||||
|
FALLOCATE_IS_PERCENT = False
|
||||||
|
|
||||||
# Used by hash_path to offer a bit more security when generating hashes for
|
# Used by hash_path to offer a bit more security when generating hashes for
|
||||||
# paths. It simply appends this value to all paths; guessing the hash a path
|
# paths. It simply appends this value to all paths; guessing the hash a path
|
||||||
@@ -453,6 +456,25 @@ def get_trans_id_time(trans_id):
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
def config_fallocate_value(reserve_value):
|
||||||
|
"""
|
||||||
|
Returns fallocate reserve_value as an int or float.
|
||||||
|
Returns is_percent as a boolean.
|
||||||
|
Returns a ValueError on invalid fallocate value.
|
||||||
|
"""
|
||||||
|
try:
|
||||||
|
if str(reserve_value[-1:]) == '%':
|
||||||
|
reserve_value = float(reserve_value[:-1])
|
||||||
|
is_percent = True
|
||||||
|
else:
|
||||||
|
reserve_value = int(reserve_value)
|
||||||
|
is_percent = False
|
||||||
|
except ValueError:
|
||||||
|
raise ValueError('Error: %s is an invalid value for fallocate'
|
||||||
|
'_reserve.' % reserve_value)
|
||||||
|
return reserve_value, is_percent
|
||||||
|
|
||||||
|
|
||||||
class FileLikeIter(object):
|
class FileLikeIter(object):
|
||||||
|
|
||||||
def __init__(self, iterable):
|
def __init__(self, iterable):
|
||||||
@@ -596,7 +618,9 @@ class FallocateWrapper(object):
|
|||||||
if FALLOCATE_RESERVE > 0:
|
if FALLOCATE_RESERVE > 0:
|
||||||
st = os.fstatvfs(fd)
|
st = os.fstatvfs(fd)
|
||||||
free = st.f_frsize * st.f_bavail - length.value
|
free = st.f_frsize * st.f_bavail - length.value
|
||||||
if free <= FALLOCATE_RESERVE:
|
if FALLOCATE_IS_PERCENT:
|
||||||
|
free = (float(free) / float(st.f_frsize * st.f_blocks)) * 100
|
||||||
|
if float(free) <= float(FALLOCATE_RESERVE):
|
||||||
raise OSError(
|
raise OSError(
|
||||||
errno.ENOSPC,
|
errno.ENOSPC,
|
||||||
'FALLOCATE_RESERVE fail %s <= %s' % (free,
|
'FALLOCATE_RESERVE fail %s <= %s' % (free,
|
||||||
|
@@ -897,9 +897,9 @@ def run_wsgi(conf_path, app_section, *args, **kwargs):
|
|||||||
loadapp(conf_path, global_conf=global_conf)
|
loadapp(conf_path, global_conf=global_conf)
|
||||||
|
|
||||||
# set utils.FALLOCATE_RESERVE if desired
|
# set utils.FALLOCATE_RESERVE if desired
|
||||||
reserve = int(conf.get('fallocate_reserve', 0))
|
utils.FALLOCATE_RESERVE, utils.FALLOCATE_IS_PERCENT = \
|
||||||
if reserve > 0:
|
utils.config_fallocate_value(conf.get('fallocate_reserve', '1%'))
|
||||||
utils.FALLOCATE_RESERVE = reserve
|
|
||||||
# redirect errors to logger and close stdio
|
# redirect errors to logger and close stdio
|
||||||
capture_stdio(logger)
|
capture_stdio(logger)
|
||||||
|
|
||||||
|
@@ -2583,6 +2583,7 @@ cluster_dfw1 = http://dfw1.host/v1/
|
|||||||
class StatVFS(object):
|
class StatVFS(object):
|
||||||
f_frsize = 1024
|
f_frsize = 1024
|
||||||
f_bavail = 1
|
f_bavail = 1
|
||||||
|
f_blocks = 100
|
||||||
|
|
||||||
def fstatvfs(fd):
|
def fstatvfs(fd):
|
||||||
return StatVFS()
|
return StatVFS()
|
||||||
@@ -2593,17 +2594,20 @@ cluster_dfw1 = http://dfw1.host/v1/
|
|||||||
fallocate = utils.FallocateWrapper(noop=True)
|
fallocate = utils.FallocateWrapper(noop=True)
|
||||||
utils.os.fstatvfs = fstatvfs
|
utils.os.fstatvfs = fstatvfs
|
||||||
# Want 1023 reserved, have 1024 * 1 free, so succeeds
|
# Want 1023 reserved, have 1024 * 1 free, so succeeds
|
||||||
utils.FALLOCATE_RESERVE = 1023
|
utils.FALLOCATE_RESERVE, utils.FALLOCATE_IS_PERCENT = \
|
||||||
|
utils.config_fallocate_value('1023')
|
||||||
StatVFS.f_frsize = 1024
|
StatVFS.f_frsize = 1024
|
||||||
StatVFS.f_bavail = 1
|
StatVFS.f_bavail = 1
|
||||||
self.assertEqual(fallocate(0, 1, 0, ctypes.c_uint64(0)), 0)
|
self.assertEqual(fallocate(0, 1, 0, ctypes.c_uint64(0)), 0)
|
||||||
# Want 1023 reserved, have 512 * 2 free, so succeeds
|
# Want 1023 reserved, have 512 * 2 free, so succeeds
|
||||||
utils.FALLOCATE_RESERVE = 1023
|
utils.FALLOCATE_RESERVE, utils.FALLOCATE_IS_PERCENT = \
|
||||||
|
utils.config_fallocate_value('1023')
|
||||||
StatVFS.f_frsize = 512
|
StatVFS.f_frsize = 512
|
||||||
StatVFS.f_bavail = 2
|
StatVFS.f_bavail = 2
|
||||||
self.assertEqual(fallocate(0, 1, 0, ctypes.c_uint64(0)), 0)
|
self.assertEqual(fallocate(0, 1, 0, ctypes.c_uint64(0)), 0)
|
||||||
# Want 1024 reserved, have 1024 * 1 free, so fails
|
# Want 1024 reserved, have 1024 * 1 free, so fails
|
||||||
utils.FALLOCATE_RESERVE = 1024
|
utils.FALLOCATE_RESERVE, utils.FALLOCATE_IS_PERCENT = \
|
||||||
|
utils.config_fallocate_value('1024')
|
||||||
StatVFS.f_frsize = 1024
|
StatVFS.f_frsize = 1024
|
||||||
StatVFS.f_bavail = 1
|
StatVFS.f_bavail = 1
|
||||||
exc = None
|
exc = None
|
||||||
@@ -2615,7 +2619,8 @@ cluster_dfw1 = http://dfw1.host/v1/
|
|||||||
'[Errno 28] FALLOCATE_RESERVE fail 1024 <= 1024')
|
'[Errno 28] FALLOCATE_RESERVE fail 1024 <= 1024')
|
||||||
self.assertEqual(err.errno, errno.ENOSPC)
|
self.assertEqual(err.errno, errno.ENOSPC)
|
||||||
# Want 1024 reserved, have 512 * 2 free, so fails
|
# Want 1024 reserved, have 512 * 2 free, so fails
|
||||||
utils.FALLOCATE_RESERVE = 1024
|
utils.FALLOCATE_RESERVE, utils.FALLOCATE_IS_PERCENT = \
|
||||||
|
utils.config_fallocate_value('1024')
|
||||||
StatVFS.f_frsize = 512
|
StatVFS.f_frsize = 512
|
||||||
StatVFS.f_bavail = 2
|
StatVFS.f_bavail = 2
|
||||||
exc = None
|
exc = None
|
||||||
@@ -2627,7 +2632,8 @@ cluster_dfw1 = http://dfw1.host/v1/
|
|||||||
'[Errno 28] FALLOCATE_RESERVE fail 1024 <= 1024')
|
'[Errno 28] FALLOCATE_RESERVE fail 1024 <= 1024')
|
||||||
self.assertEqual(err.errno, errno.ENOSPC)
|
self.assertEqual(err.errno, errno.ENOSPC)
|
||||||
# Want 2048 reserved, have 1024 * 1 free, so fails
|
# Want 2048 reserved, have 1024 * 1 free, so fails
|
||||||
utils.FALLOCATE_RESERVE = 2048
|
utils.FALLOCATE_RESERVE, utils.FALLOCATE_IS_PERCENT = \
|
||||||
|
utils.config_fallocate_value('2048')
|
||||||
StatVFS.f_frsize = 1024
|
StatVFS.f_frsize = 1024
|
||||||
StatVFS.f_bavail = 1
|
StatVFS.f_bavail = 1
|
||||||
exc = None
|
exc = None
|
||||||
@@ -2639,7 +2645,8 @@ cluster_dfw1 = http://dfw1.host/v1/
|
|||||||
'[Errno 28] FALLOCATE_RESERVE fail 1024 <= 2048')
|
'[Errno 28] FALLOCATE_RESERVE fail 1024 <= 2048')
|
||||||
self.assertEqual(err.errno, errno.ENOSPC)
|
self.assertEqual(err.errno, errno.ENOSPC)
|
||||||
# Want 2048 reserved, have 512 * 2 free, so fails
|
# Want 2048 reserved, have 512 * 2 free, so fails
|
||||||
utils.FALLOCATE_RESERVE = 2048
|
utils.FALLOCATE_RESERVE, utils.FALLOCATE_IS_PERCENT = \
|
||||||
|
utils.config_fallocate_value('2048')
|
||||||
StatVFS.f_frsize = 512
|
StatVFS.f_frsize = 512
|
||||||
StatVFS.f_bavail = 2
|
StatVFS.f_bavail = 2
|
||||||
exc = None
|
exc = None
|
||||||
@@ -2652,7 +2659,8 @@ cluster_dfw1 = http://dfw1.host/v1/
|
|||||||
self.assertEqual(err.errno, errno.ENOSPC)
|
self.assertEqual(err.errno, errno.ENOSPC)
|
||||||
# Want 1023 reserved, have 1024 * 1 free, but file size is 1, so
|
# Want 1023 reserved, have 1024 * 1 free, but file size is 1, so
|
||||||
# fails
|
# fails
|
||||||
utils.FALLOCATE_RESERVE = 1023
|
utils.FALLOCATE_RESERVE, utils.FALLOCATE_IS_PERCENT = \
|
||||||
|
utils.config_fallocate_value('1023')
|
||||||
StatVFS.f_frsize = 1024
|
StatVFS.f_frsize = 1024
|
||||||
StatVFS.f_bavail = 1
|
StatVFS.f_bavail = 1
|
||||||
exc = None
|
exc = None
|
||||||
@@ -2665,28 +2673,95 @@ cluster_dfw1 = http://dfw1.host/v1/
|
|||||||
self.assertEqual(err.errno, errno.ENOSPC)
|
self.assertEqual(err.errno, errno.ENOSPC)
|
||||||
# Want 1022 reserved, have 1024 * 1 free, and file size is 1, so
|
# Want 1022 reserved, have 1024 * 1 free, and file size is 1, so
|
||||||
# succeeds
|
# succeeds
|
||||||
utils.FALLOCATE_RESERVE = 1022
|
utils.FALLOCATE_RESERVE, utils.FALLOCATE_IS_PERCENT = \
|
||||||
|
utils.config_fallocate_value('1022')
|
||||||
StatVFS.f_frsize = 1024
|
StatVFS.f_frsize = 1024
|
||||||
StatVFS.f_bavail = 1
|
StatVFS.f_bavail = 1
|
||||||
self.assertEqual(fallocate(0, 1, 0, ctypes.c_uint64(1)), 0)
|
self.assertEqual(fallocate(0, 1, 0, ctypes.c_uint64(1)), 0)
|
||||||
# Want 1023 reserved, have 1024 * 1 free, and file size is 0, so
|
# Want 1% reserved, have 100 bytes * 2/100 free, and file size is
|
||||||
# succeeds
|
# 99, so succeeds
|
||||||
utils.FALLOCATE_RESERVE = 1023
|
utils.FALLOCATE_RESERVE, utils.FALLOCATE_IS_PERCENT = \
|
||||||
StatVFS.f_frsize = 1024
|
utils.config_fallocate_value('1%')
|
||||||
StatVFS.f_bavail = 1
|
StatVFS.f_frsize = 100
|
||||||
self.assertEqual(fallocate(0, 1, 0, ctypes.c_uint64(0)), 0)
|
StatVFS.f_bavail = 2
|
||||||
# Want 1024 reserved, have 1024 * 1 free, and even though
|
StatVFS.f_blocks = 100
|
||||||
# file size is 0, since we're under the reserve, fails
|
self.assertEqual(fallocate(0, 1, 0, ctypes.c_uint64(99)), 0)
|
||||||
utils.FALLOCATE_RESERVE = 1024
|
# Want 2% reserved, have 50 bytes * 2/50 free, and file size is 49,
|
||||||
StatVFS.f_frsize = 1024
|
# so succeeds
|
||||||
StatVFS.f_bavail = 1
|
utils.FALLOCATE_RESERVE, utils.FALLOCATE_IS_PERCENT = \
|
||||||
|
utils.config_fallocate_value('2%')
|
||||||
|
StatVFS.f_frsize = 50
|
||||||
|
StatVFS.f_bavail = 2
|
||||||
|
StatVFS.f_blocks = 50
|
||||||
|
self.assertEqual(fallocate(0, 1, 0, ctypes.c_uint64(49)), 0)
|
||||||
|
# Want 100% reserved, have 100 * 100/100 free, and file size is 0,
|
||||||
|
# so fails.
|
||||||
|
utils.FALLOCATE_RESERVE, utils.FALLOCATE_IS_PERCENT = \
|
||||||
|
utils.config_fallocate_value('100%')
|
||||||
|
StatVFS.f_frsize = 100
|
||||||
|
StatVFS.f_bavail = 100
|
||||||
|
StatVFS.f_blocks = 100
|
||||||
exc = None
|
exc = None
|
||||||
try:
|
try:
|
||||||
fallocate(0, 1, 0, ctypes.c_uint64(0))
|
fallocate(0, 1, 0, ctypes.c_uint64(0))
|
||||||
except OSError as err:
|
except OSError as err:
|
||||||
exc = err
|
exc = err
|
||||||
self.assertEqual(str(exc),
|
self.assertEqual(str(exc),
|
||||||
'[Errno 28] FALLOCATE_RESERVE fail 1024 <= 1024')
|
'[Errno 28] FALLOCATE_RESERVE fail 100.0 <= '
|
||||||
|
'100.0')
|
||||||
|
self.assertEqual(err.errno, errno.ENOSPC)
|
||||||
|
# Want 1% reserved, have 100 * 2/100 free, and file size is 101,
|
||||||
|
# so fails.
|
||||||
|
utils.FALLOCATE_RESERVE, utils.FALLOCATE_IS_PERCENT = \
|
||||||
|
utils.config_fallocate_value('1%')
|
||||||
|
StatVFS.f_frsize = 100
|
||||||
|
StatVFS.f_bavail = 2
|
||||||
|
StatVFS.f_blocks = 100
|
||||||
|
exc = None
|
||||||
|
try:
|
||||||
|
fallocate(0, 1, 0, ctypes.c_uint64(101))
|
||||||
|
except OSError as err:
|
||||||
|
exc = err
|
||||||
|
self.assertEqual(str(exc),
|
||||||
|
'[Errno 28] FALLOCATE_RESERVE fail 0.99 <= 1.0')
|
||||||
|
self.assertEqual(err.errno, errno.ENOSPC)
|
||||||
|
# Want 98% reserved, have 100 bytes * 99/100 free, and file size
|
||||||
|
# is 100, so fails
|
||||||
|
utils.FALLOCATE_RESERVE, utils.FALLOCATE_IS_PERCENT = \
|
||||||
|
utils.config_fallocate_value('98%')
|
||||||
|
StatVFS.f_frsize = 100
|
||||||
|
StatVFS.f_bavail = 99
|
||||||
|
StatVFS.f_blocks = 100
|
||||||
|
exc = None
|
||||||
|
try:
|
||||||
|
fallocate(0, 1, 0, ctypes.c_uint64(100))
|
||||||
|
except OSError as err:
|
||||||
|
exc = err
|
||||||
|
self.assertEqual(str(exc),
|
||||||
|
'[Errno 28] FALLOCATE_RESERVE fail 98.0 <= 98.0')
|
||||||
|
self.assertEqual(err.errno, errno.ENOSPC)
|
||||||
|
# Want 2% reserved, have 1000 bytes * 21/1000 free, and file size
|
||||||
|
# is 999, so succeeds.
|
||||||
|
utils.FALLOCATE_RESERVE, utils.FALLOCATE_IS_PERCENT = \
|
||||||
|
utils.config_fallocate_value('2%')
|
||||||
|
StatVFS.f_frsize = 1000
|
||||||
|
StatVFS.f_bavail = 21
|
||||||
|
StatVFS.f_blocks = 1000
|
||||||
|
self.assertEqual(fallocate(0, 1, 0, ctypes.c_uint64(999)), 0)
|
||||||
|
# Want 2% resereved, have 1000 bytes * 21/1000 free, and file size
|
||||||
|
# is 1000, so fails.
|
||||||
|
utils.FALLOCATE_RESERVE, utils.FALLOCATE_IS_PERCENT = \
|
||||||
|
utils.config_fallocate_value('2%')
|
||||||
|
StatVFS.f_frsize = 1000
|
||||||
|
StatVFS.f_bavail = 21
|
||||||
|
StatVFS.f_blocks = 1000
|
||||||
|
exc = None
|
||||||
|
try:
|
||||||
|
fallocate(0, 1, 0, ctypes.c_uint64(1000))
|
||||||
|
except OSError as err:
|
||||||
|
exc = err
|
||||||
|
self.assertEqual(str(exc),
|
||||||
|
'[Errno 28] FALLOCATE_RESERVE fail 2.0 <= 2.0')
|
||||||
self.assertEqual(err.errno, errno.ENOSPC)
|
self.assertEqual(err.errno, errno.ENOSPC)
|
||||||
finally:
|
finally:
|
||||||
utils.FALLOCATE_RESERVE = orig_FALLOCATE_RESERVE
|
utils.FALLOCATE_RESERVE = orig_FALLOCATE_RESERVE
|
||||||
@@ -2767,6 +2842,44 @@ cluster_dfw1 = http://dfw1.host/v1/
|
|||||||
ts = utils.get_trans_id_time('tx1df4ff4f55ea45f7b2ec2-almostright')
|
ts = utils.get_trans_id_time('tx1df4ff4f55ea45f7b2ec2-almostright')
|
||||||
self.assertEqual(ts, None)
|
self.assertEqual(ts, None)
|
||||||
|
|
||||||
|
def test_config_fallocate_value(self):
|
||||||
|
fallocate_value, is_percent = utils.config_fallocate_value('10%')
|
||||||
|
self.assertEqual(fallocate_value, 10)
|
||||||
|
self.assertTrue(is_percent)
|
||||||
|
fallocate_value, is_percent = utils.config_fallocate_value('10')
|
||||||
|
self.assertEqual(fallocate_value, 10)
|
||||||
|
self.assertFalse(is_percent)
|
||||||
|
try:
|
||||||
|
fallocate_value, is_percent = utils.config_fallocate_value('ab%')
|
||||||
|
except ValueError as err:
|
||||||
|
exc = err
|
||||||
|
self.assertEqual(str(exc), 'Error: ab% is an invalid value for '
|
||||||
|
'fallocate_reserve.')
|
||||||
|
try:
|
||||||
|
fallocate_value, is_percent = utils.config_fallocate_value('ab')
|
||||||
|
except ValueError as err:
|
||||||
|
exc = err
|
||||||
|
self.assertEqual(str(exc), 'Error: ab is an invalid value for '
|
||||||
|
'fallocate_reserve.')
|
||||||
|
try:
|
||||||
|
fallocate_value, is_percent = utils.config_fallocate_value('1%%')
|
||||||
|
except ValueError as err:
|
||||||
|
exc = err
|
||||||
|
self.assertEqual(str(exc), 'Error: 1%% is an invalid value for '
|
||||||
|
'fallocate_reserve.')
|
||||||
|
try:
|
||||||
|
fallocate_value, is_percent = utils.config_fallocate_value('10.0')
|
||||||
|
except ValueError as err:
|
||||||
|
exc = err
|
||||||
|
self.assertEqual(str(exc), 'Error: 10.0 is an invalid value for '
|
||||||
|
'fallocate_reserve.')
|
||||||
|
fallocate_value, is_percent = utils.config_fallocate_value('10.5%')
|
||||||
|
self.assertEqual(fallocate_value, 10.5)
|
||||||
|
self.assertTrue(is_percent)
|
||||||
|
fallocate_value, is_percent = utils.config_fallocate_value('10.000%')
|
||||||
|
self.assertEqual(fallocate_value, 10.000)
|
||||||
|
self.assertTrue(is_percent)
|
||||||
|
|
||||||
def test_tpool_reraise(self):
|
def test_tpool_reraise(self):
|
||||||
with patch.object(utils.tpool, 'execute', lambda f: f()):
|
with patch.object(utils.tpool, 'execute', lambda f: f()):
|
||||||
self.assertTrue(
|
self.assertTrue(
|
||||||
|
Reference in New Issue
Block a user