Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,7 @@ def report_only

# moved this method here so it can be accessed from pxe_server controller as well
# this is a terrible name, it doesn't validate log_depots
# TODO: I think we can move this back to the pxe_server_controller and eliminate all non-pxe code paths
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also not changing this at the moment as I don't want to mess with PXE.

def log_depot_validate
@schedule = nil # setting to nil, since we are using same view for both db_back and log_depot edit
# if zone is selected in tree replace tab#3
Expand Down
14 changes: 5 additions & 9 deletions app/controllers/miq_ae_class_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -803,7 +803,6 @@ def set_method_form_vars
else
_("Editing Automate Method \"%{name}\"") % {:name => @ae_method.name}
end
session[:log_depot_default_verify_status] = false
session[:edit] = @edit
session[:changed] = @changed = false
end
Expand Down Expand Up @@ -1024,14 +1023,11 @@ def form_method_field_changed
end
@edit[:new][:fields][f[1].to_i]['default_value'] = nil
end
if @edit[:default_verify_status] != session[:log_depot_default_verify_status]
session[:log_depot_default_verify_status] = @edit[:default_verify_status]
page << if @edit[:default_verify_status]
"miqValidateButtons('show', 'default_');"
else
"miqValidateButtons('hide', 'default_');"
end
end
page << if @edit[:default_verify_status]
"miqValidateButtons('show', 'default_');"
else
"miqValidateButtons('hide', 'default_');"
end
Copy link
Member Author

@Fryguy Fryguy Oct 31, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I honestly don't understand this code nor why there was anything log_depot related in the miq_ae_class_controller in the first place - feels like a copypaste error.

I did verify that on the AeClass method page, that the Validate button correctly enables/disables itself, and it seems to be working as expected.

page << javascript_for_miq_button_visibility_changed(@changed)
page << "miqSparkle(false)"
end
Expand Down
20 changes: 1 addition & 19 deletions app/controllers/ops_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,12 @@ def display_ae_namespaces
end

OPS_X_BUTTON_ALLOWED_ACTIONS = {
'collect_logs' => :logs_collect,
'collect_current_logs' => :collect_current_logs,
'custom_button' => :custom_buttons,
'delete_server' => :delete_server,
'demote_server' => :demote_server,
'fetch_audit_log' => :fetch_audit_log,
'fetch_log' => :fetch_log,
'fetch_production_log' => :fetch_production_log,
'log_depot_edit' => :log_depot_edit,
'promote_server' => :promote_server,
'rbac_group_add' => :rbac_group_add,
'rbac_group_edit' => :rbac_group_edit,
Expand Down Expand Up @@ -104,11 +101,8 @@ def display_ae_namespaces
'ap_host_edit' => :ap_host_edit,
'ap_vm_edit' => :ap_vm_edit,
'ap_copy' => :ap_copy,
'zone_collect_logs' => :logs_collect,
'zone_collect_current_logs' => :collect_current_logs,
'zone_delete_server' => :delete_server,
'zone_demote_server' => :demote_server,
'zone_log_depot_edit' => :log_depot_edit,
'zone_promote_server' => :promote_server,
'zone_role_start' => :role_start,
'zone_role_suspend' => :role_suspend,
Expand All @@ -124,11 +118,6 @@ def display_ae_namespaces
'schedule_run_now' => :schedule_run_now
}.freeze

def collect_current_logs
assert_privileges("#{x_node.split('-').first == "z" ? "zone_" : ""}collect_current_logs")
logs_collect(:only_current => true)
end

# handle buttons pressed on the center buttons toolbar
def x_button
generic_x_button(OPS_X_BUTTON_ALLOWED_ACTIONS)
Expand Down Expand Up @@ -471,9 +460,6 @@ def set_form_locals
locals[:submit_text] = _("Select Start date and End date to Collect C & U Data")
locals[:no_reset] = true
locals[:no_cancel] = true
elsif @sb[:active_tab] == "diagnostics_collect_logs"
action_url = "log_depot_edit"
record_id = @record && @record.id ? @record.id : "new"
else
action_url = "old_dialogs_update"
record_id = my_server.id
Expand Down Expand Up @@ -592,7 +578,6 @@ def replace_right_cell(options = {})
tree_selected_model if @tree_selected_model.nil?

locals = set_form_locals if @in_a_form
build_supported_depots_for_select

presenter = ExplorerPresenter.new(:active_tree => x_active_tree)

Expand Down Expand Up @@ -626,9 +611,6 @@ def diagnostics_replace_right_cell(nodetype, presenter)
if %w[accordion_select change_tab explorer tree_select].include?(params[:action]) ||
%w[diagnostics_roles_servers diagnostics_servers_roles].include?(@sb[:active_tab])
presenter.replace(:ops_tabs, r[:partial => "all_tabs"])
elsif nodetype == "log_depot_edit"
@right_cell_text = _("Editing Log Depot settings")
presenter.update(:diagnostics_collect_logs, r[:partial => "ops/log_collection"])
else
presenter.update(@sb[:active_tab], r[:partial => "#{@sb[:active_tab]}_tab"])
end
Expand Down Expand Up @@ -791,7 +773,7 @@ def handle_bottom_cell(nodetype, presenter, locals)
if @pages
presenter.hide(:form_buttons_div)
elsif @in_a_form
if ["log_depot_edit", "ze"].include?(nodetype)
if ["ze"].include?(nodetype)
presenter.hide(:form_buttons_div)
else
presenter.update(:form_buttons_div, r[:partial => "layouts/x_edit_buttons", :locals => locals])
Expand Down
147 changes: 1 addition & 146 deletions app/controllers/ops_controller/diagnostics.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,80 +74,6 @@ def pm_refresh_workers
end
alias refresh_workers pm_refresh_workers

def log_depot_edit
assert_privileges("#{@sb[:selected_typ] == "miq_server" ? "" : "zone_"}log_depot_edit")
@record = @sb[:selected_typ].classify.constantize.find(@sb[:selected_server_id])
# @schedule = nil # setting to nil, since we are using same view for both db_back and log_depot edit
case params[:button]
when "cancel"
@in_a_form = false
@edit = session[:edit] = nil
add_flash(_("Edit Log Depot settings was cancelled by the user"))
diagnostics_set_form_vars
replace_right_cell(:nodetype => x_node)
when "save"
if @flash_array
javascript_flash(:spinner_off => true)
return
end

begin
if params[:log_protocol].blank?
@record.log_file_depot.try(:destroy)
else
new_uri = "#{params[:uri_prefix]}://#{params[:uri]}"
raise _("Unsupported log depot protocol: %{protocol}") % {:protocol => params[:log_protocol]} unless FileDepot.supported_depots.key?(params[:log_protocol])

build_supported_depots_for_select
log_protocol = params[:log_protocol]
protocols = FileDepot.supported_depots.map { |k, _v| [k, k.constantize] }.to_h
raise _('Invalid or unsupported file depot type.') unless protocols.key?(log_protocol)

depot = @record.log_file_depot.instance_of?(protocols[log_protocol]) ? @record.log_file_depot : @record.build_log_file_depot(:type => log_protocol)
depot.update(:uri => new_uri, :name => params[:depot_name])
creds = set_credentials
depot.update_authentication(creds) if protocols[log_protocol].try(:requires_credentials?)
@record.save!
end
rescue => bang
add_flash(_("Error during 'Save': %{message}") % {:message => bang.message}, :error)
@changed = true
render :update do |page|
page << javascript_prologue
page.replace_html("diagnostics_collect_logs", :partial => "ops/log_collection")
end
else
add_flash(_("Log Depot Settings were saved"))
@edit = nil
diagnostics_set_form_vars
replace_right_cell(:nodetype => x_node)
end
when "validate"
creds = set_credentials
settings = {
:username => creds[:default][:userid],
:password => creds[:default][:password],
:uri => "#{params[:uri_prefix]}://#{params[:uri]}"
}

begin
log_protocol = params[:log_protocol]
protocols = FileDepot.supported_depots.map { |k, _v| [k, k.constantize] }.to_h
raise _("Unsupported log depot protocol: %{protocol}") % {:protocol => log_protocol} unless protocols.key?(log_protocol)

protocols[log_protocol].validate_settings(settings)
rescue => bang
add_flash(_("Error during 'Validate': %{message}") % {:message => bang.message}, :error)
else
add_flash(_("Log Depot Settings were validated"))
end
javascript_flash(:spinner_off => true)
when nil # Reset or first time in
@in_a_form = true
replace_right_cell(:nodetype => "log_depot_edit")
end
end

# Send the log in text format
def fetch_log
assert_privileges("fetch_log")
Expand Down Expand Up @@ -257,36 +183,6 @@ def cu_repair
end
end

def log_collection_form_fields
assert_privileges("#{@sb[:selected_typ] == "miq_server" ? "" : "zone_"}log_depot_edit")
@record = @sb[:selected_typ].classify.constantize.find(@sb[:selected_server_id])
log_depot = @record.log_file_depot
log_depot_json = log_depot ? build_log_depot_json(log_depot) : build_empty_log_depot_json
render :json => log_depot_json
end

def build_log_depot_json(log_depot)
prefix, uri = log_depot[:uri].to_s.split('://')
klass = @record.log_file_depot.try(:class)

log_depot_json = {:depot_name => log_depot[:name],
:uri => uri,
:uri_prefix => prefix,
:log_userid => log_depot.authentication_userid,
:log_protocol => klass.to_s}
log_depot_json
end

def build_empty_log_depot_json
log_depot_json = {:depot_name => '',
:uri => '',
:uri_prefix => '',
:log_userid => '',
:log_password => '',
:log_protocol => ''}
log_depot_json
end

def diagnostics_server_list
assert_privileges("ops_diagnostics_server_view")

Expand Down Expand Up @@ -376,31 +272,6 @@ def cu_repair_get_form_vars
end
end

# Collect the current logs from the selected zone or server
def logs_collect(options = {})
options[:support_case] = params[:support_case] if params[:support_case]
obj, id = x_node.split("-")
assert_privileges("#{obj == "z" ? "zone_" : ""}collect_logs")
klass = obj == "svr" ? MiqServer : Zone
instance = @selected_server = klass.find(id.to_i)
if !instance.active?
add_flash(_("Cannot start log collection, requires a started server"), :error)
elsif instance.log_collection_active_recently?
add_flash(_("Cannot start log collection, a log collection is already in progress within this scope"), :error)
else
begin
options[:context] = klass.name
instance.synchronize_logs(session[:userid], options)
rescue => bang
add_flash(_("Log collection error returned: %{error_message}") % {:error_message => bang.message}, :error)
else
add_flash(_("Log collection for %{product} %{object_type} %{name} has been initiated") % {:product => Vmdb::Appliance.PRODUCT_NAME, :object_type => klass.name, :name => instance.display_name})
end
end
get_node_info(x_node)
replace_right_cell(:nodetype => x_node)
end

# Reload the selected node and redraw the screen via ajax
def refresh_server_summary
assert_privileges("refresh_server_summary")
Expand Down Expand Up @@ -677,7 +548,7 @@ def diagnostics_set_form_vars
@sb[:selected_typ] = "miq_server"
end
else
@sb[:active_tab] = "diagnostics_collect_logs" # setting it to show collect logs tab as first tab for the servers that are not started
@sb[:active_tab] = "diagnostics_summary" # setting it to summary tab as first tab for the servers that are not started
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not entirely sure how to test this as I can't figure out how the code hits this else condition.

@record = @selected_server = MiqServer.find(x_node.split("-").last.to_i)
@sb[:selected_server_id] = @selected_server.id
@sb[:selected_typ] = "miq_server"
Expand Down Expand Up @@ -726,20 +597,4 @@ def diagnostics_get_info
diagnostics_set_form_vars
end
end

def build_supported_depots_for_select
not_supported_depots = %w[FileDepotS3 FileDepotSwift]
supported_depots = FileDepot.supported_depots.reject { |model, _desc| not_supported_depots.include?(model) }
@uri_prefixes = supported_depots.keys.map { |model| [model, model.constantize.uri_prefix] }.to_h
@supported_depots_for_select = {'' => _('<No Depot>')}.merge(supported_depots)
end

def set_credentials
creds = {}
if params[:log_userid]
log_password = params[:log_password] || @record.log_file_depot.authentication_password
creds[:default] = {:userid => params[:log_userid], :password => log_password}
end
creds
end
end
3 changes: 3 additions & 0 deletions app/controllers/ops_controller/settings/schedules.rb
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,9 @@ def schedule_disable
schedule_toggle(false)
end

# TODO: I think we can drop this now that log collection is dropped, however, PXE needs FileDepot validation, and
# I'm not sure if this method is also used by PXE validation. Note that application_controller has a log_depot_validate
# as well, which might be the one used for PXE. By extension, build_uri_settings can probably also be dropped.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Leaving this TODO in here for now, and I will handle this in a follow up. I don't want to mess with the PXE path and overcomplicate this PR.

def log_depot_validate
assert_privileges("schedule_admin")

Expand Down
15 changes: 0 additions & 15 deletions app/helpers/application_helper/button/collect_logs.rb

This file was deleted.

7 changes: 0 additions & 7 deletions app/helpers/application_helper/button/log_depot_edit.rb

This file was deleted.

This file was deleted.

15 changes: 0 additions & 15 deletions app/helpers/application_helper/button/zone_collect_logs.rb

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -57,34 +57,6 @@ class ApplicationHelper::Toolbar::DiagnosticsServerCenter < ApplicationHelper::T
:klass => ApplicationHelper::Button::DiagnosticsProductionLogs),
])
button_group('ldap_domain_vmdb', [
select(
:server_collect_logs_choice,
nil,
N_('Collect Logs'),
N_('Collect'),
:items => [
button(
:collect_current_logs,
'fa fa-filter fa-lg',
N_('Collect the current logs from the selected Server'),
N_('Collect current logs'),
:klass => ApplicationHelper::Button::CollectLogs
),
button(
:collect_logs,
'fa fa-filter fa-lg',
N_('Collect all logs from the selected Server'),
N_('Collect all logs'),
:klass => ApplicationHelper::Button::CollectLogs
),
]
),
button(
:log_depot_edit,
'pficon pficon-edit fa-lg',
N_('Edit the Log Depot settings for the selected Server'),
N_('Edit'),
:klass => ApplicationHelper::Button::LogDepotEdit),
select(
:restart_vmdb_choice,
nil,
Expand Down
Loading