Add configtest button for config history page

This commit is contained in:
uu59 2015-01-14 16:06:54 +09:00
parent 46a4ef60c2
commit a1579e186e
7 changed files with 65 additions and 3 deletions

View File

@ -1,7 +1,7 @@
class Fluentd::Settings::HistoriesController < ApplicationController
before_action :login_required
before_action :find_fluentd
before_action :find_backup_file, only: [:show, :reuse]
before_action :find_backup_file, only: [:show, :reuse, :configtest]
def index
@backup_files = @fluentd.agent.backup_files_in_new_order.map do |file_path|
@ -17,6 +17,16 @@ class Fluentd::Settings::HistoriesController < ApplicationController
redirect_to daemon_setting_path, flash: { success: t('messages.config_successfully_copied', brand: fluentd_ui_brand) }
end
def configtest
@fluentd.config_file = @backup_file.file_path
if @fluentd.agent.dryrun
flash = { success: t('messages.dryrun_is_passed') }
else
flash = { danger: @fluentd.agent.log_tail(1).first }
end
redirect_to daemon_setting_history_path(params[:id]), flash: flash
end
private
def find_backup_file

View File

@ -1,5 +1,10 @@
- page_title t('.page_title', label: @fluentd.label) do
- link_to reuse_daemon_setting_history_path(id: @backup_file.file_id), method: 'post', class: "btn btn-primary pull-right" do
- page_title t('.page_title', label: @fluentd.label)
%p{class: "pull-right"}
= link_to configtest_daemon_setting_history_path(id: @backup_file.file_id), method: "post", class: "btn btn-default" do
= icon('fa-legal')
= t("terms.configtest")
= link_to reuse_daemon_setting_history_path(id: @backup_file.file_id), method: 'post', class: "btn btn-primary" do
= icon('fa-pencil')
= t("terms.reuse")

View File

@ -8,3 +8,6 @@
- if flash[:info]
%p.alert.alert-info
=raw flash[:info]
- if flash[:danger]
%p.alert.alert-danger
=raw flash[:danger]

View File

@ -13,6 +13,7 @@ en:
fluentd_status_stopped: Stopped
config_successfully_copied: "Config has been copied successfully. Please restart %{brand} to use the new config"
note_updating_success: "Note successfully updated."
dryrun_is_passed: Success without errors.
terms: &terms
name: Name
@ -64,6 +65,7 @@ en:
backup_time: Backed up at
note: Note
reuse: reuse
configtest: config test
plugins:
view_on_rubygems_org: View on rubygems.org

View File

@ -13,6 +13,7 @@ ja:
fluentd_status_stopped: 停止中
config_successfully_copied: "設定をコピーしました。反映させるには、 %{brand}を再起動してください。"
note_updating_success: "メモを更新しました。"
dryrun_is_passed: 使用可能です
terms: &terms
name: アカウント名
@ -64,6 +65,7 @@ ja:
backup_time: バックアップ日時
note: メモ
reuse: 再利用
configtest: 設定テスト
plugins:
view_on_rubygems_org: rubygems.orgで見る

View File

@ -66,6 +66,7 @@ Rails.application.routes.draw do
resources :histories, only: [:index, :show], module: :settings, controller: :histories do
post "reuse", action: 'reuse', on: :member, as: 'reuse'
post "configtest" , action: "configtest", on: :member, as: "configtest"
end
resources :notes, only: [:update], module: :settings, controller: :notes

View File

@ -44,5 +44,44 @@ describe "histories", stub: :daemon do
page.should have_text(I18n.t('messages.config_successfully_copied', brand: 'fluentd') )
page.should have_text(last_backup_file.content)
end
describe "configtest" do
let(:daemon) { build(:fluentd, variant: "fluentd_gem") } # To use fluentd_gem for real dry-run checking
before do
daemon.agent.config_write config
daemon.agent.config_write "# dummy"
backup = Fluentd::SettingArchive::BackupFile.new(daemon.agent.backup_files_in_new_order.first)
visit "/daemon/setting/histories/#{backup.file_id}"
click_link I18n.t("terms.configtest")
end
context "invalid configfile" do
let(:config) { <<-CONFIG }
<source>
type aaaaaaaaaaaa
</source>
CONFIG
it do
page.should_not have_css('.alert-success')
page.should have_css('.alert-danger')
page.should have_text(%Q|Unknown input plugin 'aaaaaaaaaaaa'|)
end
end
context "valid configfile" do
let(:config) { <<-CONFIG }
<source>
type syslog
tag syslog
</source>
CONFIG
it do
page.should have_css('.alert-success')
page.should_not have_css('.alert-danger')
end
end
end
end
end