diff --git a/bin/kafo-export-params b/bin/kafo-export-params index 8bc7e0a6..6b702fc9 100755 --- a/bin/kafo-export-params +++ b/bin/kafo-export-params @@ -35,7 +35,7 @@ module Kafo def execute KafoConfigure.logger = Logger.new(STDERR) - c = Configuration.new(config, false) + c = Configuration.new(config, false, logger: KafoConfigure.logger) KafoConfigure.config = c if KafoConfigure.config.parser_cache KafoConfigure.config.parser_cache.force = true if ARGV.include?('--parser-cache') diff --git a/lib/kafo/configuration.rb b/lib/kafo/configuration.rb index d873b7bb..a9b301c3 100644 --- a/lib/kafo/configuration.rb +++ b/lib/kafo/configuration.rb @@ -49,11 +49,11 @@ def self.get_scenario_id(filename) File.basename(filename, '.yaml') end - def initialize(file, persist = true) + def initialize(file, persist = true, logger:) @config_file = file - @persist = persist + @persist = persist configure_application - @logger = KafoConfigure.logger + @logger = logger @answer_file = app[:answer_file] begin @@ -63,8 +63,7 @@ def initialize(file, persist = true) KafoConfigure.exit(:no_answer_file) end - @config_dir = File.dirname(@config_file) - @scenario_id = Configuration.get_scenario_id(@config_file) + @scenario_id = self.class.get_scenario_id(@config_file) end def save_configuration(configuration) @@ -100,7 +99,7 @@ def app configuration = {} end - result = DEFAULT.merge(configuration || {}) + result = DEFAULT.merge(configuration || {}) result[:module_dirs] = result[:modules_dir] || result[:module_dirs] result.delete(:modules_dir) result @@ -135,7 +134,7 @@ def modules end def module(name) - modules.find { |m| m.name == name } + modules.find { |m| m.identifier == name } end def root_dir @@ -242,8 +241,8 @@ def module_enabled?(mod) end def config_header - files = [app[:config_header_file], File.join(gem_root, '/config/config_header.txt')].compact - file = files.find { |f| File.exist?(f) } + files = [app[:config_header_file], File.join(gem_root, '/config/config_header.txt')].compact + file = files.find { |f| File.exist?(f) } @config_header ||= file.nil? ? '' : File.read(file) end diff --git a/lib/kafo/kafo_configure.rb b/lib/kafo/kafo_configure.rb index 41389c75..cc85318c 100644 --- a/lib/kafo/kafo_configure.rb +++ b/lib/kafo/kafo_configure.rb @@ -269,7 +269,7 @@ def request_config_reload def setup_config(conf_file) self.class.config_file = conf_file - self.class.config = Configuration.new(self.class.config_file) + self.class.config = Configuration.new(self.class.config_file, logger: logger) if self.class.config.parser_cache self.class.config.parser_cache.force = true if ARGV.include?('--parser-cache') diff --git a/lib/kafo/scenario_manager.rb b/lib/kafo/scenario_manager.rb index 81cb831b..47d6c30b 100644 --- a/lib/kafo/scenario_manager.rb +++ b/lib/kafo/scenario_manager.rb @@ -220,7 +220,7 @@ def load_and_setup_configuration(config_file) end def load_configuration(config_file) - Configuration.new(config_file) + Configuration.new(config_file, logger: @logger) end private diff --git a/test/kafo/configuration_test.rb b/test/kafo/configuration_test.rb index 85576c1c..d7413373 100644 --- a/test/kafo/configuration_test.rb +++ b/test/kafo/configuration_test.rb @@ -4,8 +4,9 @@ module Kafo describe Configuration do let(:basic_config_file) { ConfigFileFactory.build('basic', BASIC_CONFIGURATION).path } - let(:basic_config) { Kafo::Configuration.new(basic_config_file, false) } - let(:old_config) { Kafo::Configuration.new(basic_config_file, false) } + let(:logger) { Kafo::KafoConfigure.logger } + let(:basic_config) { Kafo::Configuration.new(basic_config_file, false, logger: logger) } + let(:old_config) { Kafo::Configuration.new(basic_config_file, false, logger: logger) } let(:current_dir) { File.expand_path('.') } let(:p_foo) { fake_param('foo', 1) } @@ -33,7 +34,7 @@ module Kafo :answer_file => 'test/fixtures/basic_answers.yaml', :log_dir => log_dir } config_file = ConfigFileFactory.build('log_dir', cfg.to_yaml).path - config = Kafo::Configuration.new(config_file, false) + config = Kafo::Configuration.new(config_file, false, logger: logger) assert_equal File.join(log_dir, 'configuration.log'), config.log_file refute config.log_exists? File.open(config.log_file, 'w') { |f| f.write 'non-empty-log' } @@ -51,14 +52,14 @@ module Kafo it 'takes modules_dir' do cfg = { :modules_dir => './my_modules', :answer_file => 'test/fixtures/basic_answers.yaml'} config_file = ConfigFileFactory.build('modules_dir_single', cfg.to_yaml).path - config = Kafo::Configuration.new(config_file, false) + config = Kafo::Configuration.new(config_file, false, logger: logger) assert_equal [File.join(current_dir, 'my_modules')], config.module_dirs end it 'takes module_dirs' do cfg = { :module_dirs => ['./my_modules','./their_modules'] , :answer_file => 'test/fixtures/basic_answers.yaml'} config_file = ConfigFileFactory.build('module_dirs_plural', cfg.to_yaml).path - config = Kafo::Configuration.new(config_file, false) + config = Kafo::Configuration.new(config_file, false, logger: logger) assert_equal [File.join(current_dir, 'my_modules'), File.join(current_dir, 'their_modules')], config.module_dirs end end diff --git a/test/kafo/execution_environment_test.rb b/test/kafo/execution_environment_test.rb index b9261d4b..8e10baac 100644 --- a/test/kafo/execution_environment_test.rb +++ b/test/kafo/execution_environment_test.rb @@ -3,7 +3,7 @@ module Kafo describe ExecutionEnvironment do let(:config_file) { ConfigFileFactory.build('basic', BASIC_CONFIGURATION).path } - let(:config) { Kafo::Configuration.new(config_file, false) } + let(:config) { Kafo::Configuration.new(config_file, false, logger: Kafo::KafoConfigure.logger) } let(:execution_environment) { ExecutionEnvironment.new(config) } after { FileUtils.rm_rf(execution_environment.directory) } diff --git a/test/kafo/parser_cache_reader_test.rb b/test/kafo/parser_cache_reader_test.rb index 3cacef28..4471561a 100644 --- a/test/kafo/parser_cache_reader_test.rb +++ b/test/kafo/parser_cache_reader_test.rb @@ -59,7 +59,7 @@ module Kafo describe "compatibility with writer" do before do - KafoConfigure.config = Configuration.new(ConfigFileFactory.build('basic', BASIC_CONFIGURATION).path) + KafoConfigure.config = Configuration.new(ConfigFileFactory.build('basic', BASIC_CONFIGURATION).path, logger: Kafo::KafoConfigure.logger) end let(:parser) { TestParser.new(BASIC_MANIFEST) } diff --git a/test/kafo/puppet_command_test.rb b/test/kafo/puppet_command_test.rb index a6e39ddc..da08e2a7 100644 --- a/test/kafo/puppet_command_test.rb +++ b/test/kafo/puppet_command_test.rb @@ -3,7 +3,7 @@ module Kafo describe PuppetModule do before do - KafoConfigure.config = Configuration.new(ConfigFileFactory.build('basic', BASIC_CONFIGURATION).path) + KafoConfigure.config = Configuration.new(ConfigFileFactory.build('basic', BASIC_CONFIGURATION).path, logger: Kafo::KafoConfigure.logger) end let(:pc) { PuppetCommand.new '' } diff --git a/test/kafo/puppet_module_test.rb b/test/kafo/puppet_module_test.rb index 122c634f..348dc1e7 100644 --- a/test/kafo/puppet_module_test.rb +++ b/test/kafo/puppet_module_test.rb @@ -3,7 +3,7 @@ module Kafo describe PuppetModule do before do - KafoConfigure.config = Configuration.new(ConfigFileFactory.build('basic', BASIC_CONFIGURATION).path) + KafoConfigure.config = Configuration.new(ConfigFileFactory.build('basic', BASIC_CONFIGURATION).path, logger: Kafo::KafoConfigure.logger) end let(:parser) { TestParser.new(BASIC_MANIFEST) } diff --git a/test/kafo/scenario_manager_test.rb b/test/kafo/scenario_manager_test.rb index 7995e95c..7b34752d 100644 --- a/test/kafo/scenario_manager_test.rb +++ b/test/kafo/scenario_manager_test.rb @@ -241,7 +241,7 @@ def create_and_load_scenarios(content, filename='default.yaml') describe '#confirm_scenario_change' do let(:basic_config_file) { ConfigFileFactory.build('basic', BASIC_CONFIGURATION).path } - let(:new_config) { Kafo::Configuration.new(basic_config_file, false) } + let(:new_config) { Kafo::Configuration.new(basic_config_file, false, logger: Kafo::KafoConfigure.logger) } before :all do @argv = ARGV @@ -288,8 +288,8 @@ def create_and_load_scenarios(content, filename='default.yaml') describe '#print_scenario_diff' do let(:basic_config_file) { ConfigFileFactory.build('basic', BASIC_CONFIGURATION).path } - let(:new_config) { Kafo::Configuration.new(basic_config_file, false) } - let(:old_config) { Kafo::Configuration.new(basic_config_file, false) } + let(:new_config) { Kafo::Configuration.new(basic_config_file, false, logger: Kafo::KafoConfigure.logger) } + let(:old_config) { Kafo::Configuration.new(basic_config_file, false, logger: Kafo::KafoConfigure.logger) } let(:p_foo) { fake_param('foo', 1) } let(:p_bar) { fake_param('bar', 10) } diff --git a/test/test_helper.rb b/test/test_helper.rb index fc95dd1e..32eb5d73 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -157,10 +157,10 @@ class testing4( class Minitest::Spec before do - Kafo::KafoConfigure.config = Kafo::Configuration.new(ConfigFileFactory.build('basic', BASIC_CONFIGURATION).path) + Kafo::KafoConfigure.logger = Kafo::Logger.new + Kafo::KafoConfigure.config = Kafo::Configuration.new(ConfigFileFactory.build('basic', BASIC_CONFIGURATION).path, logger: Kafo::KafoConfigure.logger) Kafo::KafoConfigure.root_dir = File.dirname(__FILE__) Kafo::KafoConfigure.exit_handler = Kafo::ExitHandler.new - Kafo::KafoConfigure.logger = Kafo::Logger.new Kafo::KafoConfigure.module_dirs = ['test/fixtures/modules'] Kafo::Logging.buffer.clear end @@ -204,7 +204,7 @@ def wont_be_on_stdout(output, *args) end def fake_module(mod_name, params) - OpenStruct.new( { :class_name => mod_name, :name => mod_name, :enabled? => true, :params => params } ).tap do |m| + OpenStruct.new( { :identifier => mod_name, :class_name => mod_name, :name => mod_name.gsub('::', '_'), :enabled? => true, :params => params } ).tap do |m| params.each { |p| p.module = m } end end