Merge "Convert cgroups memory limits to bytes"

This commit is contained in:
Jenkins 2016-03-17 13:52:10 +00:00 committed by Gerrit Code Review
commit cfc4f64408
2 changed files with 19 additions and 8 deletions

View File

@ -5,14 +5,25 @@ module CgroupsSettings
# value is valid if value has integer type or
# matches with pattern: %percent, min_value, max_value
def self.handle_value(group, value)
return value if value.is_a?(Numeric)
if group == 'memory' and value.match(/%(\d+), (\d+), (\d+)/)
percent, min, max = value.scan(/%(\d+), (\d+), (\d+)/).flatten.map { |i| i.to_i }
total_memory = Facter.value(:memorysize_mb)
res = (total_memory.to_f / 100.0) * percent.to_f
return [min, max, res].sort[1]
# transform value in megabytes to bytes for memory limits
return handle_memory(value) if group == 'memory'
# keep it as it is for others
return value if value.is_a?(Integer)
end
def self.handle_memory(value)
return mb_to_bytes(value) if value.is_a?(Integer)
if value.is_a?(String) and value.match(/%(\d+), (\d+), (\d+)/)
percent, min, max = value.scan(/%(\d+), (\d+), (\d+)/).flatten.map { |i| i.to_i }
total_memory = Facter.value(:memorysize_mb)
res = (total_memory.to_f / 100.0) * percent.to_f
return mb_to_bytes([min, max, res].sort[1])
end
end
def self.mb_to_bytes(value)
return value * 1024 * 1024
end
end
Puppet::Parser::Functions::newfunction(:prepare_cgroups_hash, :type => :rvalue, :arity => 1, :doc => <<-EOS

View File

@ -36,7 +36,7 @@ describe Puppet::Parser::Functions.function(:prepare_cgroups_hash) do
'blkio.test' => 800
},
'memory' => {
'memory.soft_limit_in_bytes' => 700
'memory.soft_limit_in_bytes' => 700 * 1024 * 1024
},
},
'keystone' => {
@ -72,7 +72,7 @@ describe Puppet::Parser::Functions.function(:prepare_cgroups_hash) do
{
'neutron' => {
'memory' => {
'memory.soft_limit_in_bytes' => 512
'memory.soft_limit_in_bytes' => 512 * 1024 * 1024
}
}
}