diff --git a/app/controllers/fluentd/settings/histories_controller.rb b/app/controllers/fluentd/settings/histories_controller.rb index c789a36..a02a622 100644 --- a/app/controllers/fluentd/settings/histories_controller.rb +++ b/app/controllers/fluentd/settings/histories_controller.rb @@ -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 diff --git a/app/views/fluentd/settings/histories/show.html.haml b/app/views/fluentd/settings/histories/show.html.haml index ace0457..27f7899 100644 --- a/app/views/fluentd/settings/histories/show.html.haml +++ b/app/views/fluentd/settings/histories/show.html.haml @@ -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") diff --git a/app/views/shared/_flash.html.haml b/app/views/shared/_flash.html.haml index 3da9db9..be490b7 100644 --- a/app/views/shared/_flash.html.haml +++ b/app/views/shared/_flash.html.haml @@ -8,3 +8,6 @@ - if flash[:info] %p.alert.alert-info =raw flash[:info] + - if flash[:danger] + %p.alert.alert-danger + =raw flash[:danger] diff --git a/config/locales/translation_en.yml b/config/locales/translation_en.yml index de25bf3..a9b6d5a 100644 --- a/config/locales/translation_en.yml +++ b/config/locales/translation_en.yml @@ -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 diff --git a/config/locales/translation_ja.yml b/config/locales/translation_ja.yml index 6d572be..8755c4d 100644 --- a/config/locales/translation_ja.yml +++ b/config/locales/translation_ja.yml @@ -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で見る diff --git a/config/routes.rb b/config/routes.rb index 42ea789..f54dbd4 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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 diff --git a/spec/features/fluentd/setting/hisotries_spec.rb b/spec/features/fluentd/setting/hisotries_spec.rb index a8de6db..e227d71 100644 --- a/spec/features/fluentd/setting/hisotries_spec.rb +++ b/spec/features/fluentd/setting/hisotries_spec.rb @@ -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 } + + type aaaaaaaaaaaa + + 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 } + + type syslog + tag syslog + + CONFIG + + it do + page.should have_css('.alert-success') + page.should_not have_css('.alert-danger') + end + end + end end end