Merge pull request #154 from fluent/code_climate

Code climate
This commit is contained in:
uu59 2015-02-04 16:31:24 +09:00
commit 21bbab4a61
5 changed files with 32 additions and 25 deletions

View File

@ -18,22 +18,9 @@ class Fluentd::SettingsController < ApplicationController
def update def update
if params[:dryrun] if params[:dryrun]
if dryrun(params[:config]) handle_dryrun
flash.now[:success] = I18n.t('messages.dryrun_is_passed')
else else
flash.now[:danger] = @fluentd.agent.last_error_message handle_update
end
@config = params[:config]
render "edit"
else
begin
update_config(params[:config])
redirect_to daemon_setting_path(@fluentd)
rescue Fluent::ConfigParseError => e
@config = params[:config]
flash.now[:danger] = e.message
render "edit"
end
end end
end end
@ -48,6 +35,25 @@ class Fluentd::SettingsController < ApplicationController
@config = @fluentd.agent.config @config = @fluentd.agent.config
end end
def handle_dryrun
if dryrun(params[:config])
flash.now[:success] = I18n.t('messages.dryrun_is_passed')
else
flash.now[:danger] = @fluentd.agent.last_error_message
end
@config = params[:config]
render "edit"
end
def handle_update
update_config(params[:config])
redirect_to daemon_setting_path(@fluentd)
rescue Fluent::ConfigParseError => e
@config = params[:config]
flash.now[:danger] = e.message
render "edit"
end
def dryrun(conf) def dryrun(conf)
tmpfile = Tempfile.open("fluentd-test-config") tmpfile = Tempfile.open("fluentd-test-config")
tmpfile.write params[:config] tmpfile.write params[:config]

View File

@ -43,10 +43,7 @@ class Fluentd
end end
def dryrun!(file_path = nil) def dryrun!(file_path = nil)
Bundler.with_clean_env do exec_dryrun("fluentd", file_path)
system("fluentd -q --dry-run #{options_to_argv(config_file: file_path)}", out: File::NULL, err: File::NULL)
raise ::Fluentd::Agent::ConfigError, last_error_message unless $?.exitstatus.zero?
end
end end
def config_syntax_check def config_syntax_check

View File

@ -82,6 +82,13 @@ class Fluentd
private private
def exec_dryrun(command, file_path = nil)
Bundler.with_clean_env do
system("#{command} -q --dry-run #{options_to_argv(config_file: file_path)}", out: File::NULL, err: File::NULL)
raise ::Fluentd::Agent::ConfigError, last_error_message unless $?.exitstatus.zero?
end
end
def backup_config def backup_config
return unless File.exists? config_file return unless File.exists? config_file

View File

@ -17,10 +17,7 @@ class Fluentd
end end
def dryrun!(file_path = nil) def dryrun!(file_path = nil)
Bundler.with_clean_env do exec_dryrun("/usr/sbin/td-agent", file_path)
system("/usr/sbin/td-agent --dry-run #{options_to_argv(config_file: file_path)}", out: File::NULL, err: File::NULL)
raise ::Fluentd::Agent::ConfigError, last_error_message unless $?.exitstatus.zero?
end
end end
case FluentdUI.platform case FluentdUI.platform

View File

@ -38,7 +38,7 @@ describe Plugin do
it { should_not be_valid } it { should_not be_valid }
end end
context "somthing filled is valid" do context "something filled is valid" do
let(:gem_name) { "foobar" } let(:gem_name) { "foobar" }
it { should be_valid } it { should be_valid }
end end
@ -53,7 +53,7 @@ describe Plugin do
it { should_not be_valid } it { should_not be_valid }
end end
context "somthing filled is valid" do context "something filled is valid" do
let(:version) { "0.0.1" } let(:version) { "0.0.1" }
it { should be_valid } it { should be_valid }
end end