mirror of
https://github.com/fluent/fluentd-ui.git
synced 2025-08-11 16:57:11 +02:00
Add config test button to running backup
This commit is contained in:
parent
2766ea95fe
commit
3071b3d2c4
28
app/controllers/concerns/setting_history_concern.rb
Normal file
28
app/controllers/concerns/setting_history_concern.rb
Normal 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
|
@ -1,7 +1,5 @@
|
|||||||
class Fluentd::Settings::HistoriesController < ApplicationController
|
class Fluentd::Settings::HistoriesController < ApplicationController
|
||||||
before_action :login_required
|
include SettingHistoryConcern
|
||||||
before_action :find_fluentd
|
|
||||||
before_action :find_backup_file, only: [:show, :reuse, :configtest]
|
|
||||||
|
|
||||||
def index
|
def index
|
||||||
@backup_files = @fluentd.agent.backup_files_in_new_order.map do |file_path|
|
@backup_files = @fluentd.agent.backup_files_in_new_order.map do |file_path|
|
||||||
@ -9,28 +7,14 @@ class Fluentd::Settings::HistoriesController < ApplicationController
|
|||||||
end
|
end
|
||||||
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
|
private
|
||||||
|
|
||||||
def find_backup_file
|
def find_backup_file
|
||||||
#Do not use BackupFile.new(params[:id]) because params[:id] can be any path.
|
#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])
|
@backup_file = Fluentd::SettingArchive::BackupFile.find_by_file_id(@fluentd.agent.config_backup_dir, params[:id])
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def after_dryrun_redirect(flash)
|
||||||
|
redirect_to daemon_setting_history_path(params[:id]), flash: flash
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
@ -1,19 +1,13 @@
|
|||||||
class Fluentd::Settings::RunningBackupController < ApplicationController
|
class Fluentd::Settings::RunningBackupController < ApplicationController
|
||||||
before_action :login_required
|
include SettingHistoryConcern
|
||||||
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
|
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def find_backup_file
|
def find_backup_file
|
||||||
@backup_file = Fluentd::SettingArchive::BackupFile.new(@fluentd.agent.running_config_backup_file)
|
@backup_file = Fluentd::SettingArchive::BackupFile.new(@fluentd.agent.running_config_backup_file)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def after_dryrun_redirect(flash)
|
||||||
|
redirect_to daemon_setting_running_backup_path, flash: flash
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
@ -1,6 +1,11 @@
|
|||||||
- page_title t('.page_title', label: @fluentd.label) do
|
- page_title t('.page_title', label: @fluentd.label)
|
||||||
- if @backup_file.content
|
|
||||||
- link_to reuse_daemon_setting_running_backup_path, method: 'post', class: "btn btn-primary pull-right" do
|
- 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')
|
= icon('fa-pencil')
|
||||||
= t("terms.reuse")
|
= t("terms.reuse")
|
||||||
|
|
||||||
|
@ -73,6 +73,7 @@ Rails.application.routes.draw do
|
|||||||
|
|
||||||
resource :running_backup, only: [:show], module: :settings, controller: :running_backup do
|
resource :running_backup, only: [:show], module: :settings, controller: :running_backup do
|
||||||
post "reuse", action: 'reuse', on: :member, as: 'reuse'
|
post "reuse", action: 'reuse', on: :member, as: 'reuse'
|
||||||
|
post "configtest" , action: "configtest", on: :member, as: "configtest"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -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(I18n.t('messages.config_successfully_copied', brand: 'fluentd') )
|
||||||
page.should have_text(backup_content)
|
page.should have_text(backup_content)
|
||||||
end
|
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
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user