Project

General

Profile

« Previous | Next » 

Revision 6b4b489f

Added by Ori Rabin over 8 years ago

fixes #10832 - separating lookup keys into puppet and variable

View differences:

test/unit/classification_test.rb
test "#enc should return default value of class parameters without lookup_values" do
env = FactoryGirl.create(:environment)
pc = FactoryGirl.create(:puppetclass, :environments => [env])
lkey = FactoryGirl.create(:lookup_key, :as_smart_class_param, :puppetclass => pc, :override => true, :default_value => 'test')
lkey = FactoryGirl.create(:puppetclass_lookup_key, :as_smart_class_param, :puppetclass => pc, :override => true, :default_value => 'test')
assert_equal({pc.name => {lkey.key => lkey.default_value}}, get_classparam(env, pc).enc)
end
test "#enc should return override value of class parameters" do
env = FactoryGirl.create(:environment)
pc = FactoryGirl.create(:puppetclass, :environments => [env])
lkey = FactoryGirl.create(:lookup_key, :as_smart_class_param, :with_override, :puppetclass => pc)
lkey = FactoryGirl.create(:puppetclass_lookup_key, :as_smart_class_param, :with_override, :puppetclass => pc)
classparam = get_classparam(env, pc)
classparam.expects(:attr_to_value).with('comment').returns('override')
assert_equal({pc.name => {lkey.key => 'overridden value'}}, classparam.enc)
......
test "#values_hash should contain element's name" do
env = FactoryGirl.create(:environment)
pc = FactoryGirl.create(:puppetclass, :environments => [env])
lkey = FactoryGirl.create(:lookup_key, :as_smart_class_param, :with_override, :puppetclass => pc)
lkey = FactoryGirl.create(:puppetclass_lookup_key, :as_smart_class_param, :with_override, :puppetclass => pc)
classparam = Classification::ClassParam.new
classparam.expects(:environment_id).returns(env.id)
classparam.expects(:puppetclass_ids).returns(Array.wrap(pc).map(&:id))
......
test "#values_hash should treat yaml and json parameters as string" do
env = FactoryGirl.create(:environment)
pc = FactoryGirl.create(:puppetclass, :environments => [env])
yaml_lkey = FactoryGirl.create(:lookup_key, :as_smart_class_param, :with_override,
yaml_lkey = FactoryGirl.create(:puppetclass_lookup_key, :as_smart_class_param, :with_override,
:puppetclass => pc, :key_type => 'yaml', :default_value => '',
:overrides => {"comment=override" => 'a: b'})
json_lkey = FactoryGirl.create(:lookup_key, :as_smart_class_param, :with_override,
json_lkey = FactoryGirl.create(:puppetclass_lookup_key, :as_smart_class_param, :with_override,
:puppetclass => pc, :key_type => 'json', :default_value => '',
:overrides => {"comment=override" => '{"a": "b"}'})
classparam = Classification::ClassParam.new
......
test "#value_of_key should correctly typecast JSON and YAML default values" do
env = FactoryGirl.create(:environment)
pc = FactoryGirl.create(:puppetclass, :environments => [env])
yaml_lkey = FactoryGirl.create(:lookup_key, :as_smart_class_param,
yaml_lkey = FactoryGirl.create(:puppetclass_lookup_key, :as_smart_class_param,
:puppetclass => pc, :key_type => 'yaml', :default_value => 'a: b')
json_lkey = FactoryGirl.create(:lookup_key, :as_smart_class_param,
json_lkey = FactoryGirl.create(:puppetclass_lookup_key, :as_smart_class_param,
:puppetclass => pc, :key_type => 'json', :default_value => '{"a": "b"}')
classparam = Classification::ClassParam.new
......
end
test 'smart class parameter of array with avoid_duplicates should return lookup_value array without duplicates' do
key = FactoryGirl.create(:lookup_key, :as_smart_class_param,
key = FactoryGirl.create(:puppetclass_lookup_key, :as_smart_class_param,
:override => true, :key_type => 'array', :merge_overrides => true,
:default_value => [], :path => "organization\nlocation", :avoid_duplicates => true,
:puppetclass => puppetclasses(:one))
......
end
test 'smart class parameter of array without avoid_duplicates should return lookup_value array with duplicates' do
key = FactoryGirl.create(:lookup_key, :as_smart_class_param,
key = FactoryGirl.create(:puppetclass_lookup_key, :as_smart_class_param,
:override => true, :key_type => 'array', :merge_overrides => true,
:default_value => [], :path => "organization\nlocation",
:puppetclass => puppetclasses(:one))
......
end
test 'smart class parameter of hash with merge_overrides should return lookup_value hash with array of elements' do
key = FactoryGirl.create(:lookup_key, :as_smart_class_param,
key = FactoryGirl.create(:puppetclass_lookup_key, :as_smart_class_param,
:override => true, :key_type => 'hash', :merge_overrides => true,
:default_value => {}, :path => "organization\nlocation",
:puppetclass => puppetclasses(:one))
......
end
test 'smart class parameter of hash with merge_overrides should return lookup_value hash with one element' do
key = FactoryGirl.create(:lookup_key, :as_smart_class_param,
key = FactoryGirl.create(:puppetclass_lookup_key, :as_smart_class_param,
:override => true, :key_type => 'hash', :merge_overrides => true,
:default_value => {}, :path => "organization\nos\nlocation",
:puppetclass => puppetclasses(:one))
......
end
test 'smart class parameter of hash with merge_overrides and priority should obey priority' do
key = FactoryGirl.create(:lookup_key, :as_smart_class_param,
key = FactoryGirl.create(:puppetclass_lookup_key, :as_smart_class_param,
:override => true, :key_type => 'hash', :merge_overrides => true,
:default_value => {}, :path => "organization\nos\nlocation",
:puppetclass => puppetclasses(:one))
......
end
test 'smart class parameter of hash with merge_overrides and priority should return lookup_value hash with array of elements' do
key = FactoryGirl.create(:lookup_key, :as_smart_class_param,
key = FactoryGirl.create(:puppetclass_lookup_key, :as_smart_class_param,
:override => true, :key_type => 'hash', :merge_overrides => true,
:default_value => {}, :path => "organization\nos\nlocation",
:puppetclass => puppetclasses(:one))
......
end
test 'smart variable of array with avoid_duplicates should return lookup_value array without duplicates' do
key = FactoryGirl.create(:lookup_key, :key_type => 'array', :merge_overrides => true,
key = FactoryGirl.create(:variable_lookup_key, :key_type => 'array', :merge_overrides => true,
:default_value => [], :path => "organization\nlocation", :avoid_duplicates => true,
:puppetclass => puppetclasses(:one))
as_admin do
LookupValue.create! :lookup_key_id => key.id,
:match => "location=#{taxonomies(:location1)}",
:value => ['test'],
:use_puppet_default => false
:value => ['test']
end
value2 = as_admin do
LookupValue.create! :lookup_key_id => key.id,
:match => "organization=#{taxonomies(:organization1)}",
:value => ['test'],
:use_puppet_default => false
:value => ['test']
end
key.reload
......
end
test 'smart variable of array without avoid_duplicates should return lookup_value array with duplicates' do
key = FactoryGirl.create(:lookup_key, :key_type => 'array', :merge_overrides => true,
key = FactoryGirl.create(:variable_lookup_key, :key_type => 'array', :merge_overrides => true,
:default_value => [], :path => "organization\nlocation",
:puppetclass => puppetclasses(:one))
value = as_admin do
LookupValue.create! :lookup_key_id => key.id,
:match => "location=#{taxonomies(:location1)}",
:value => ['test'],
:use_puppet_default => false
:value => ['test']
end
value2 = as_admin do
LookupValue.create! :lookup_key_id => key.id,
:match => "organization=#{taxonomies(:organization1)}",
:value => ['test'],
:use_puppet_default => false
:value => ['test']
end
key.reload
......
end
test 'smart variable of hash in hash with merge_overrides should return lookup_value hash with array of elements' do
key = FactoryGirl.create(:lookup_key, :key_type => 'hash', :merge_overrides => true,
key = FactoryGirl.create(:variable_lookup_key, :key_type => 'hash', :merge_overrides => true,
:default_value => {}, :path => "organization\nlocation",
:puppetclass => puppetclasses(:one))
as_admin do
LookupValue.create! :lookup_key_id => key.id,
:match => "location=#{taxonomies(:location1)}",
:value => {:example => {:a => 'test'}},
:use_puppet_default => false
:value => {:example => {:a => 'test'}}
end
as_admin do
LookupValue.create! :lookup_key_id => key.id,
:match => "organization=#{taxonomies(:organization1)}",
:value => {:example => {:b => 'test2'}},
:use_puppet_default => false
:value => {:example => {:b => 'test2'}}
end
key.reload
......
end
test 'smart variable of hash with merge_overrides and priority should obey priority' do
key = FactoryGirl.create(:lookup_key, :key_type => 'hash', :merge_overrides => true,
key = FactoryGirl.create(:variable_lookup_key, :key_type => 'hash', :merge_overrides => true,
:default_value => {}, :path => "organization\nos\nlocation",
:puppetclass => puppetclasses(:one))
as_admin do
LookupValue.create! :lookup_key_id => key.id,
:match => "location=#{taxonomies(:location1)}",
:value => {:a => 'test'},
:use_puppet_default => false
:value => {:a => 'test'}
end
as_admin do
LookupValue.create! :lookup_key_id => key.id,
:match => "organization=#{taxonomies(:organization1)}",
:value => {:example => {:b => 'test2'}},
:use_puppet_default => false
:value => {:example => {:b => 'test2'}}
end
as_admin do
LookupValue.create! :lookup_key_id => key.id,
:match => "os=#{operatingsystems(:redhat)}",
:value => {:example => {:b => 'test3'}},
:use_puppet_default => false
:value => {:example => {:b => 'test3'}}
end
key.reload
......
end
test 'smart variable of hash with merge_overrides and priority should return lookup_value hash with array of elements' do
key = FactoryGirl.create(:lookup_key, :key_type => 'hash', :merge_overrides => true,
key = FactoryGirl.create(:variable_lookup_key, :key_type => 'hash', :merge_overrides => true,
:default_value => {}, :path => "organization\nos\nlocation",
:puppetclass => puppetclasses(:one))
as_admin do
LookupValue.create! :lookup_key_id => key.id,
:match => "location=#{taxonomies(:location1)}",
:value => {:example => {:a => 'test'}},
:use_puppet_default => false
:value => {:example => {:a => 'test'}}
LookupValue.create! :lookup_key_id => key.id,
:match => "organization=#{taxonomies(:organization1)}",
:value => {:example => {:b => 'test2'}},
:use_puppet_default => false
:value => {:example => {:b => 'test2'}}
LookupValue.create! :lookup_key_id => key.id,
:match => "os=#{operatingsystems(:redhat)}",
:value => {:example => {:a => 'test3'}},
:use_puppet_default => false
:value => {:example => {:a => 'test3'}}
end
key.reload
......
end
test 'smart variable of hash without merge_default should not merge with default value' do
key = FactoryGirl.create(:lookup_key, :key_type => 'hash', :merge_overrides => true,
key = FactoryGirl.create(:variable_lookup_key, :key_type => 'hash', :merge_overrides => true,
:default_value => {:default => 'example'}, :path => "organization\nos\nlocation",
:puppetclass => puppetclasses(:one))
as_admin do
LookupValue.create! :lookup_key_id => key.id,
:match => "organization=#{taxonomies(:organization1)}",
:value => {:a => 'test2'},
:use_puppet_default => false
:value => {:a => 'test2'}
end
key.reload
......
end
test 'smart class parameter of hash with merge_overrides and merge_default should return merge all values' do
key = FactoryGirl.create(:lookup_key, :as_smart_class_param,
key = FactoryGirl.create(:puppetclass_lookup_key, :as_smart_class_param,
:override => true, :key_type => 'hash', :merge_overrides => true, :merge_default => true,
:default_value => { :default => 'default' }, :path => "organization\nlocation",
:puppetclass => puppetclasses(:one))
......
end
test "#enc should not return class parameters when default value should use puppet default" do
lkey = FactoryGirl.create(:lookup_key, :as_smart_class_param, :with_override, :with_use_puppet_default,
lkey = FactoryGirl.create(:puppetclass_lookup_key, :as_smart_class_param, :with_override, :with_use_puppet_default,
:puppetclass => puppetclasses(:one))
enc = classification.enc
assert enc['base'][lkey.key].nil?
end
test "#enc should not return class parameters when lookup_value should use puppet default" do
lkey = FactoryGirl.create(:lookup_key, :as_smart_class_param, :with_override, :with_use_puppet_default,
lkey = FactoryGirl.create(:puppetclass_lookup_key, :as_smart_class_param, :with_override, :with_use_puppet_default,
:puppetclass => puppetclasses(:one), :path => "location")
as_admin do
LookupValue.create! :lookup_key_id => lkey.id,
......
end
test "#enc should return class parameters when default value and lookup_values should not use puppet default" do
lkey = FactoryGirl.create(:lookup_key, :as_smart_class_param, :with_override, :use_puppet_default => false,
lkey = FactoryGirl.create(:puppetclass_lookup_key, :as_smart_class_param, :with_override, :use_puppet_default => false,
:puppetclass => puppetclasses(:one), :path => "location")
lvalue = as_admin do
LookupValue.create! :lookup_key_id => lkey.id,
......
end
test "#enc should not return class parameters when merged lookup_values and default are all using puppet default" do
key = FactoryGirl.create(:lookup_key, :as_smart_class_param, :use_puppet_default => true,
key = FactoryGirl.create(:puppetclass_lookup_key, :as_smart_class_param, :use_puppet_default => true,
:override => true, :key_type => 'hash', :merge_overrides => true,
:default_value => {}, :path => "organization\nos\nlocation",
:puppetclass => puppetclasses(:one))
......
FactoryGirl.create(:setting,
:name => 'host_group_matchers_inheritance',
:value => true)
key = FactoryGirl.create(:lookup_key, :as_smart_class_param, :use_puppet_default => true,
key = FactoryGirl.create(:puppetclass_lookup_key, :as_smart_class_param, :use_puppet_default => true,
:override => true, :key_type => 'string', :merge_overrides => false,
:path => "organization\nhostgroup\nlocation",
:puppetclass => puppetclasses(:two))
......
FactoryGirl.create(:setting,
:name => 'host_group_matchers_inheritance',
:value => true)
key = FactoryGirl.create(:lookup_key, :as_smart_class_param, :use_puppet_default => true,
key = FactoryGirl.create(:puppetclass_lookup_key, :as_smart_class_param, :use_puppet_default => true,
:override => true, :key_type => 'string', :merge_overrides => false,
:path => "organization\nhostgroup\nlocation",
:puppetclass => puppetclasses(:two))
......
end
test 'enc should return correct values for multi-key matchers' do
key = FactoryGirl.create(:lookup_key, :as_smart_class_param,
key = FactoryGirl.create(:puppetclass_lookup_key, :as_smart_class_param,
:override => true, :key_type => 'string', :default_value => '',
:path => "organization\norganization,location\nlocation",
:puppetclass => puppetclasses(:one))
......
end
test 'enc should return correct values for multi-key matchers' do
key = FactoryGirl.create(:lookup_key, :as_smart_class_param, :use_puppet_default => true,
key = FactoryGirl.create(:puppetclass_lookup_key, :as_smart_class_param, :use_puppet_default => true,
:override => true, :key_type => 'string', :merge_overrides => false,
:path => "hostgroup,organization\nlocation",
:puppetclass => puppetclasses(:two))
......
end
test 'smart class parameter should accept string with erb for arrays and evaluate it properly' do
key = FactoryGirl.create(:lookup_key, :as_smart_class_param,
key = FactoryGirl.create(:puppetclass_lookup_key, :as_smart_class_param,
:override => true, :key_type => 'array', :merge_overrides => false,
:default_value => '<%= [1,2] %>', :path => "organization\nos\nlocation",
:puppetclass => puppetclasses(:one))
......
host = classification.send(:host)
host.update_attributes(:hostgroup => hostgroup)
key = FactoryGirl.create(:lookup_key, :as_smart_class_param, :with_use_puppet_default,
key = FactoryGirl.create(:puppetclass_lookup_key, :as_smart_class_param, :with_use_puppet_default,
:override => true, :key_type => 'string', :merge_overrides => false,
:path => "hostgroup,organization\nlocation",
:puppetclass => puppetclasses(:two))
......
end
test 'smart class parameter with erb values is validated after erb is evaluated' do
key = FactoryGirl.create(:lookup_key, :as_smart_class_param,
key = FactoryGirl.create(:puppetclass_lookup_key, :as_smart_class_param,
:override => true, :key_type => 'string', :merge_overrides => false,
:default_value => '<%= "a" %>', :path => "organization\nos\nlocation",
:puppetclass => puppetclasses(:one),

Also available in: Unified diff