Move format of all memory limits to the *_in_bytes limits

Some memory limits has boolean or percentage values. In this case
they should set on its own format, what done by default in cgroups.
Format "total%, max, min" should be obtained only for limits which
value is count of bytes.

Change-Id: I701d6388ef66950f90388f0ad3fa16c6fb862c95
Closes-bug: 1561909
This commit is contained in:
Valeriy Sakharov 2016-03-25 14:38:15 +03:00
parent 17aa0666a9
commit 514e982707
2 changed files with 34 additions and 4 deletions

View File

@ -4,9 +4,9 @@ module CgroupsSettings
require 'facter'
# value is valid if value has integer type or
# matches with pattern: %percent, min_value, max_value
def self.handle_value(group, value)
# transform value in megabytes to bytes for memory limits
return handle_memory(value) if group == 'memory'
def self.handle_value(option, value)
# transform value in megabytes to bytes for limits of memory
return handle_memory(value) if option.to_s.end_with? "_in_bytes"
# keep it as it is for others
return value if value.is_a?(Integer)
end
@ -71,7 +71,7 @@ Puppet::Parser::Functions::newfunction(:prepare_cgroups_hash, :type => :rvalue,
hash_settings.each do |group, options|
raise("'#{service}': group '#{group}' options is not a HASH instance") unless options.is_a?(Hash)
options.each do |option, value|
options[option] = CgroupsSettings.handle_value(group, value)
options[option] = CgroupsSettings.handle_value(option, value)
raise("'#{service}': group '#{group}': option '#{option}' has wrong value") if options[option].nil?
end
end

View File

@ -192,6 +192,36 @@ describe Puppet::Parser::Functions.function(:prepare_cgroups_hash) do
end
context "converting memory to megabytes only for bytes value" do
let(:sample) {
{
'neutron' => '{"memory":{"memory.swappiness": 10}}',
'nova' => '{"hugetlb":{"hugetlb.16GB.limit_in_bytes": 10}}'
}
}
let(:result) {
{
'neutron' => {
'memory' => {
'memory.swappiness' => 10
}
},
'nova' => {
'hugetlb' => {
'hugetlb.16GB.limit_in_bytes' => 10 * 1024 * 1024
}
}
}
}
it 'should convert memory values only for bytes values' do
should run.with_params(sample).and_return(result)
end
end
context "service's cgroup settings are not a HASH" do
let(:sample) {