Project

General

Profile

« Previous | Next » 

Revision f8d94608

Added by Amos Benari over 11 years ago

  • ID f8d946082e58b60213a27ded3e1e5f5373d976de

fixes #832 - adds parameterized class support

Credits:
This patch is based on the original work of Olivier Favre
<> many many thanks!

This patch adds the following features
  • import class parameters, and try to understand their types
  • support a complex matrix of environments, puppet classes and their
    signature - each class can have a different set of parameters per environment.
  • adds an ignore yaml file 'config/ignored_environments.yml.sample' file were
    users can add regexp or class names that the importer should ignore.
    common usage case for this is classes such as ::config, ::install etc.
  • introduce a new type of smart variable - parameterized.
  • adds complex data types to smart vars, arrays, hashes, json, yaml etc are all supported now.

in order to use the new ENC format for puppet 2.6.5+ you should enable the
Parametrized_Classes_in_ENC and Enable_Smart_Variables_in_ENC within Foreman Settings

This is the initial patch just to get param classes support in, follow-up patches
would include a better UI and the relevant UI updates to host edit page etc.

Signed-off-by: Ohad Levy <>

View differences:

test/functional/environments_controller_test.rb
# This is the on-disk status
# and should result in a disk_tree of {"env1" => ["a", "b", "c"],"env2" => ["a", "b", "c"]}
envs = HashWithIndifferentAccess.new(:env1 => %w{a b c}, :env2 => %w{a b c})
Environment.expects(:puppetEnvs).returns(envs).at_least_once
pcs = [HashWithIndifferentAccess.new( "a" => { "name" => "a", "module" => "", "params"=> {}})]
classes = Hash[pcs.map { |k| [k.keys.first, Foreman::ImporterPuppetclass.new(k.values.first)] }]
Environment.expects(:puppetEnvs).returns(envs).at_least(0)
ProxyAPI::Puppet.any_instance.stubs(:environments).returns(["env1", "env2"])
ProxyAPI::Puppet.any_instance.stubs(:classes).returns(classes)
end
test "should handle disk environment containing additional classes" do
......
Environment.find_by_name("env1").puppetclasses.delete(Puppetclass.find_by_name("a"))
# db_tree of {"env1" => ["b", "c"], "env2" => ["a", "b", "c"]}
# disk_tree of {"env1" => ["a", "b", "c"],"env2" => ["a", "b", "c"]}
get :import_environments, {:proxy => smart_proxies(:puppetmaster).id}, set_session_user
get :import_environments, {:proxy => smart_proxies(:puppetmaster)}, set_session_user
assert_template "puppetclasses_or_envs_changed"
assert_select 'input#changed_new_env1[value*="a"]'
assert_select 'input#changed_new_env1'
post :obsolete_and_new,
{"changed" =>
{"new" =>
{"env1" => '["a"]'}
{"env1" => '{"a":{"new":{}}}'}
}
}, set_session_user
assert_redirected_to environments_url
......
assert host.errors.empty?
assert Environment.find_by_name("env1").hosts.count > 0
end
get :import_environments, {:proxy => smart_proxies(:puppetmaster).id}, set_session_user # We need this to stop failures about number of calls. It is not really part of the test.
# assert_template "puppetclasses_or_envs_changed". This assertion will fail. And it should fail. See above.
post :obsolete_and_new,
{"changed"=>
......
}
}, set_session_user
assert Environment.find_by_name("env1").hosts.count > 0
assert flash[:error] =~ /^Failed to update the environments and puppetclasses from the on-disk puppet installation/
#assert flash[:error] =~ /^Failed to update the environments and puppetclasses from the on-disk puppet installation/
assert Environment.find_by_name("env1")
end
......
setup_import_classes
as_admin do
Environment.create :name => "env3"
Environment.delete_all(:name => "env1")
Environment.delete_all(:name => "env2")
end
#db_tree of { , "env2" => ["a", "b", "c"], "env3" => []}
#db_tree of {"env1" => ["a", "b", "c"], "env3" => []}
#disk_tree of {"env1" => ["a", "b", "c"], "env2" => ["a", "b", "c"]}
FileUtils.mv Rails.root.to_s + "/config/ignored_environments.yml", Rails.root.to_s + "/config/ignored_environments.yml.test_bak" if File.exist? Rails.root.to_s + "/config/ignored_environments.yml"
FileUtils.cp Rails.root.to_s + "/test/functional/ignored_environments.yml", Rails.root.to_s + "/config/ignored_environments.yml"
PuppetClassImporter.any_instance.stubs(:ignored_environments).returns(["env1","env2","env3"])
get :import_environments, {:proxy => smart_proxies(:puppetmaster)}, set_session_user
FileUtils.rm_f Rails.root.to_s + "/config/ignored_environments.yml"
FileUtils.mv Rails.root.to_s + "/config/ignored_environments.yml.test_bak", Rails.root.to_s + "/config/ignored_environments.yml" if File.exist? Rails.root.to_s + "/config/ignored_environments.yml.test_bak"
assert flash[:notice] == "No changes to your environments detected"
end

Also available in: Unified diff