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
if params[:dryrun]
if dryrun(params[:config])
flash.now[:success] = I18n.t('messages.dryrun_is_passed')
handle_dryrun
else
flash.now[:danger] = @fluentd.agent.last_error_message
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
handle_update
end
end
@ -48,6 +35,25 @@ class Fluentd::SettingsController < ApplicationController
@config = @fluentd.agent.config
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)
tmpfile = Tempfile.open("fluentd-test-config")
tmpfile.write params[:config]

View File

@ -43,10 +43,7 @@ class Fluentd
end
def dryrun!(file_path = nil)
Bundler.with_clean_env do
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
exec_dryrun("fluentd", file_path)
end
def config_syntax_check

View File

@ -82,6 +82,13 @@ class Fluentd
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
return unless File.exists? config_file

View File

@ -17,10 +17,7 @@ class Fluentd
end
def dryrun!(file_path = nil)
Bundler.with_clean_env do
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
exec_dryrun("/usr/sbin/td-agent", file_path)
end
case FluentdUI.platform

View File

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