Merge pull request #168 from fluent/config_parse_also_configtest

Fix configtest/update behaviors are mismatched
This commit is contained in:
uu59 2015-04-02 13:01:56 +09:00
commit 0af36393ae
2 changed files with 56 additions and 2 deletions

View File

@ -37,7 +37,12 @@ class Fluentd::SettingsController < ApplicationController
def handle_dryrun def handle_dryrun
if dryrun(params[:config]) if dryrun(params[:config])
begin
parse_config(params[:config])
flash.now[:success] = I18n.t('messages.dryrun_is_passed') flash.now[:success] = I18n.t('messages.dryrun_is_passed')
rescue Fluent::ConfigParseError => e
flash.now[:danger] = e.message
end
else else
flash.now[:danger] = @fluentd.agent.log.last_error_message flash.now[:danger] = @fluentd.agent.log.last_error_message
end end
@ -46,6 +51,7 @@ class Fluentd::SettingsController < ApplicationController
end end
def handle_update def handle_update
parse_config(params[:config])
update_config(params[:config]) update_config(params[:config])
redirect_to daemon_setting_path(@fluentd) redirect_to daemon_setting_path(@fluentd)
rescue Fluent::ConfigParseError => e rescue Fluent::ConfigParseError => e
@ -61,8 +67,12 @@ class Fluentd::SettingsController < ApplicationController
@fluentd.agent.dryrun(tmpfile.path) @fluentd.agent.dryrun(tmpfile.path)
end end
def parse_config(conf)
# V1Parser.parse could raise exception
Fluent::Config::V1Parser.parse(conf, @fluentd.config_file, File.dirname(@fluentd.config_file), binding)
end
def update_config(conf) def update_config(conf)
Fluent::Config::V1Parser.parse(conf, @fluentd.config_file)
@fluentd.agent.config_write conf @fluentd.agent.config_write conf
@fluentd.agent.restart if @fluentd.agent.running? @fluentd.agent.restart if @fluentd.agent.running?
end end

View File

@ -47,4 +47,48 @@ describe 'setting', stub: :daemon do
current_path.should == '/daemon/setting' current_path.should == '/daemon/setting'
page.should have_css('pre', text: 'YET ANOTHER CONFIG') page.should have_css('pre', text: 'YET ANOTHER CONFIG')
end end
describe "config" do
before do
daemon.agent.config_write conf
click_link I18n.t('terms.edit')
end
context "plain config" do
let(:conf) { <<-'CONF' }
<source>
type forward
</source>
CONF
it 'configtest' do
click_button I18n.t('terms.configtest')
page.should have_css('.alert-success')
end
it "update & restart check" do
click_button I18n.t('terms.update')
daemon.agent.config.gsub("\r\n", "\n").should == conf # CodeMirror exchange \n -> \r\n
end
end
context "embedded config" do
let(:conf) { <<-'CONF' }
<source>
type forward
id "foo#{Time.now.to_s}"
</source>
CONF
it 'configtest' do
click_button I18n.t('terms.configtest')
page.should have_css('.alert-success')
end
it "update & restart check" do
click_button I18n.t('terms.update')
daemon.agent.config.gsub("\r\n", "\n").should == conf # CodeMirror exchange \n -> \r\n
end
end
end
end end