Add config test button to running backup

This commit is contained in:
uu59 2015-01-14 17:55:30 +09:00
parent 2766ea95fe
commit 3071b3d2c4
6 changed files with 83 additions and 35 deletions

View File

@ -0,0 +1,28 @@
module SettingHistoryConcern
extend ActiveSupport::Concern
included do
before_action :login_required
before_action :find_fluentd
before_action :find_backup_file, only: [:show, :reuse, :configtest]
end
def show
end
def reuse
@fluentd.agent.config_write @backup_file.content
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
after_dryrun_redirect(flash)
end
end

View File

@ -1,7 +1,5 @@
class Fluentd::Settings::HistoriesController < ApplicationController
before_action :login_required
before_action :find_fluentd
before_action :find_backup_file, only: [:show, :reuse, :configtest]
include SettingHistoryConcern
def index
@backup_files = @fluentd.agent.backup_files_in_new_order.map do |file_path|
@ -9,28 +7,14 @@ class Fluentd::Settings::HistoriesController < ApplicationController
end
end
def show
end
def reuse
@fluentd.agent.config_write @backup_file.content
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
#Do not use BackupFile.new(params[:id]) because params[:id] can be any path.
@backup_file = Fluentd::SettingArchive::BackupFile.find_by_file_id(@fluentd.agent.config_backup_dir, params[:id])
end
def after_dryrun_redirect(flash)
redirect_to daemon_setting_history_path(params[:id]), flash: flash
end
end

View File

@ -1,19 +1,13 @@
class Fluentd::Settings::RunningBackupController < ApplicationController
before_action :login_required
before_action :find_fluentd
before_action :find_backup_file, only: [:show, :reuse]
def show
end
def reuse
@fluentd.agent.config_write @backup_file.content
redirect_to daemon_setting_path, flash: { success: t('messages.config_successfully_copied', brand: fluentd_ui_brand) }
end
include SettingHistoryConcern
private
def find_backup_file
@backup_file = Fluentd::SettingArchive::BackupFile.new(@fluentd.agent.running_config_backup_file)
end
def after_dryrun_redirect(flash)
redirect_to daemon_setting_running_backup_path, flash: flash
end
end

View File

@ -1,6 +1,11 @@
- page_title t('.page_title', label: @fluentd.label) do
- if @backup_file.content
- link_to reuse_daemon_setting_running_backup_path, method: 'post', class: "btn btn-primary pull-right" do
- page_title t('.page_title', label: @fluentd.label)
- if @backup_file.content
%p{class: "pull-right"}
= link_to configtest_daemon_setting_running_backup_path, method: 'post', class: "btn btn-default" do
= icon('fa-legal')
= t("terms.configtest")
= link_to reuse_daemon_setting_running_backup_path, method: 'post', class: "btn btn-primary" do
= icon('fa-pencil')
= t("terms.reuse")

View File

@ -73,6 +73,7 @@ Rails.application.routes.draw do
resource :running_backup, only: [:show], module: :settings, controller: :running_backup do
post "reuse", action: 'reuse', on: :member, as: 'reuse'
post "configtest" , action: "configtest", on: :member, as: "configtest"
end
end
end

View File

@ -43,6 +43,42 @@ describe "running_backup", stub: :daemon do
page.should have_text(I18n.t('messages.config_successfully_copied', brand: 'fluentd') )
page.should have_text(backup_content)
end
describe "configtest" do
let(:backup_content){ config }
let(:daemon) { build(:fluentd, variant: "fluentd_gem") } # To use fluentd_gem for real dry-run checking
before do
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
end