Skip to content

Commit

Permalink
Remove DatabaseBackup
Browse files Browse the repository at this point in the history
  • Loading branch information
NickLaMuro committed Sep 1, 2021
1 parent b3aa135 commit e61e544
Show file tree
Hide file tree
Showing 9 changed files with 2 additions and 435 deletions.
99 changes: 0 additions & 99 deletions app/models/database_backup.rb

This file was deleted.

5 changes: 0 additions & 5 deletions app/models/miq_region.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ class MiqRegion < ApplicationRecord
has_many :metric_rollups, :as => :resource # Destroy will be handled by purger
has_many :vim_performance_states, :as => :resource # Destroy will be handled by purger

virtual_has_many :database_backups, :class_name => "DatabaseBackup"
virtual_has_many :ext_management_systems, :class_name => "ExtManagementSystem"
virtual_has_many :hosts, :class_name => "Host"
virtual_has_many :storages, :class_name => "Storage"
Expand Down Expand Up @@ -34,10 +33,6 @@ class MiqRegion < ApplicationRecord

PERF_ROLLUP_CHILDREN = [:ext_management_systems, :storages]

def database_backups
DatabaseBackup.in_region(region_number)
end

def ext_management_systems
ExtManagementSystem.in_region(region_number)
end
Expand Down
58 changes: 2 additions & 56 deletions app/models/miq_schedule.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class MiqSchedule < ApplicationRecord

validates :name, :uniqueness_when_changed => {:scope => [:userid, :resource_type]}
validates :name, :description, :resource_type, :run_at, :presence => true
validate :validate_run_at, :validate_file_depot
validate :validate_run_at

before_save :set_start_time_and_prod_default

Expand Down Expand Up @@ -41,7 +41,7 @@ class MiqSchedule < ApplicationRecord

SYSTEM_SCHEDULE_CLASSES = %w(MiqReport MiqAlert MiqWidget).freeze
VALID_INTERVAL_UNITS = %w(minutely hourly daily weekly monthly once).freeze
ALLOWED_CLASS_METHOD_ACTIONS = %w(db_backup db_gc automation_request).freeze
ALLOWED_CLASS_METHOD_ACTIONS = %w(automation_request).freeze
IMPORT_CLASS_NAMES = %w[MiqSchedule].freeze

default_value_for :userid, "system"
Expand Down Expand Up @@ -247,37 +247,10 @@ def action_automation_request(_klass, _at)
AutomationRequest.create_from_scheduled_task(user, filter[:uri_parts], parameters)
end

def action_db_backup(klass, _at)
self.sched_action ||= {}
self.sched_action[:options] ||= {}
self.sched_action[:options][:userid] = userid
opts = self.sched_action[:options]
opts[:file_depot_id] = file_depot.id
opts[:miq_schedule_id] = id
queue_opts = {:class_name => klass.name, :method_name => "backup", :args => [opts], :role => "database_operations",
:msg_timeout => ::Settings.task.active_task_timeout.to_i_with_method}
task_opts = {:action => "Database backup", :userid => self.sched_action[:options][:userid]}
MiqTask.generic_action_with_callback(task_opts, queue_opts)
end

def action_db_gc(klass, _at)
self.sched_action ||= {}
self.sched_action[:options] ||= {}
self.sched_action[:options][:userid] = userid
opts = self.sched_action[:options]
queue_opts = {:class_name => klass.name, :method_name => "gc", :args => [opts], :role => "database_operations"}
task_opts = {:action => "Database GC", :userid => self.sched_action[:options][:userid]}
MiqTask.generic_action_with_callback(task_opts, queue_opts)
end

def run_automation_request
action_automation_request(AutomationRequest, nil)
end

def run_adhoc_db_backup
action_db_backup(DatabaseBackup, nil)
end

def action_evaluate_alert(obj, _at)
MiqAlert.evaluate_queue(obj)
_log.info("Action [#{name}] has been run for target type: [#{obj.class}] with name: [#{obj.name}]")
Expand Down Expand Up @@ -325,33 +298,6 @@ def validate_run_at
end
end

def validate_file_depot # TODO: Do we need this if the validations are on the FileDepot classes?
if self.sched_action.kind_of?(Hash) && self.sched_action[:method] == "db_backup" && file_depot
errors.add(:file_depot, "is missing credentials") if !file_depot.uri.to_s.starts_with?("nfs") && file_depot.missing_credentials?
errors.add(:file_depot, "is missing uri") if file_depot.uri.blank?
end
end

def verify_file_depot(params) # TODO: This logic belongs in the UI, not sure where
depot_class = FileDepot.supported_protocols[params[:uri_prefix]]
depot = file_depot.class.name == depot_class ? file_depot : build_file_depot(:type => depot_class)
depot.name = params[:name]
uri = params[:uri]
api_port = params[:swift_api_port]
depot.aws_region = params[:aws_region]
depot.openstack_region = params[:openstack_region]
depot.keystone_api_version = params[:keystone_api_version]
depot.v3_domain_ident = params[:v3_domain_ident]
depot.security_protocol = params[:security_protocol]
depot.uri = api_port.blank? ? uri : depot.merged_uri(URI(uri), api_port)
if params[:save]
file_depot.save!
file_depot.update_authentication(:default => {:userid => params[:username], :password => params[:password]}) if (params[:username] || params[:password]) && depot.class.requires_credentials?
elsif depot.class.requires_credentials?
depot.verify_credentials(nil, params)
end
end

def next_interval_time
unless self.valid? || errors[:run_at].blank?
_log.warn("Invalid schedule [#{id}] [#{name}]: #{Array.wrap(errors[:run_at]).join(", ")}")
Expand Down
1 change: 0 additions & 1 deletion config/replication_exclude_tables.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
- conditions_miq_policies
- custom_buttons
- customization_specs
- database_backups
- event_logs
- external_urls
- file_depots
Expand Down
4 changes: 0 additions & 4 deletions db/fixtures/miq_event_definition_events.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,6 @@
description: Server High DB Disk Usage
event_type: Default
set_type: evm_operations
- name: evm_server_db_backup_low_space
description: Server Database Backup Insufficient Space
event_type: Default
set_type: evm_operations
- name: evm_worker_start
description: Worker Started
event_type: Default
Expand Down
5 changes: 0 additions & 5 deletions spec/factories/database_backup.rb

This file was deleted.

47 changes: 0 additions & 47 deletions spec/models/database_backup_spec.rb

This file was deleted.

12 changes: 0 additions & 12 deletions spec/models/miq_schedule_filter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,6 @@
:sched_action => {:method => "vm_scan"},
:miq_search_id => @search.id
)

# DB Baskup Schedule
@db_backup = FactoryBot.create(:miq_schedule,
:resource_type => "DatabaseBackup",
:sched_action => {:method => "db_backup"}
)
end

context "for a scheduled report" do
Expand Down Expand Up @@ -88,11 +82,5 @@
expect(targets.length).to eq(1)
expect(targets.first.name).to eq("Test VM 2")
end

it "should get the the DatabaseBackup class for a scheduled DB Backup" do
targets = @db_backup.get_targets
expect(targets.length).to eq(1)
expect(targets.first.name).to eq("DatabaseBackup")
end
end
end
Loading

0 comments on commit e61e544

Please sign in to comment.