Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add queue_name to VmOrTemplate::Operations::Snapshot queue methods #19616

Merged
merged 10 commits into from
Dec 11, 2019
18 changes: 16 additions & 2 deletions app/models/vm_or_template/operations/snapshot.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,25 +77,35 @@ def remove_evm_snapshot(snapshot_id)
raw_remove_snapshot(snapshot_id)
end

# Remove a snapshot as a queued operation and return the queue object. The
# queue name and the queue zone are derived from the EMS. The snapshot id
# is mandatory, while a task id is optional.
#
def remove_snapshot_queue(snapshot_id, task_id = nil)
MiqQueue.put_unless_exists(
:class_name => self.class.name,
:instance_id => id,
:method_name => 'remove_snapshot',
:args => [snapshot_id],
:role => "ems_operations",
:role => 'ems_operations',
:queue_name => queue_name_for_ems_operations,
:zone => my_zone,
:task_id => task_id
)
end

# Remove a evm snapshot as a queued operation and return the queue object. The
# queue name and the queue zone are derived from the EMS. The snapshot id
# is mandatory, while a task id is optional.
#
def remove_evm_snapshot_queue(snapshot_id, task_id = nil)
MiqQueue.put_unless_exists(
:class_name => self.class.name,
:instance_id => id,
:method_name => 'remove_evm_snapshot',
:args => [snapshot_id],
:role => "ems_operations",
:role => 'ems_operations',
:queue_name => queue_name_for_ems_operations,
:zone => my_zone,
:task_id => task_id
)
Expand Down Expand Up @@ -132,6 +142,9 @@ def remove_all_snapshots
raw_remove_all_snapshots
end

# Remove all snapshots as a queued task and return the task id. The queue
# name and the queue zone are derived from the EMS. The userid is mandatory.
#
def remove_all_snapshots_queue(userid)
task_opts = {
:name => "Removing all snapshots for #{name}",
Expand All @@ -144,6 +157,7 @@ def remove_all_snapshots_queue(userid)
:instance_id => id,
:role => 'ems_operations',
:zone => ext_management_system.my_zone,
:queue_name => ext_management_system.queue_name_for_ems_operations,
:args => []
}

Expand Down
58 changes: 58 additions & 0 deletions spec/models/vm_or_template/operations/snapshot_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
RSpec.describe VmOrTemplate::Operations::Snapshot do
before { EvmSpecHelper.local_miq_server }
after(:context) { MiqQueue.delete_all }

let(:user) { FactoryBot.create(:user, :userid => 'test') }
let(:ems) { FactoryBot.create(:ems_vmware) }
let(:vm) { FactoryBot.create(:vm_vmware, :ext_management_system => ems) }
let(:snapshots) { FactoryBot.create_list(:snapshot, 2, :vm_or_template => vm) }

context "queued methods" do
it 'queues as expected in remove_snapshot_queue' do
queue = vm.remove_snapshot_queue(snapshots.first.id)

expect(queue).to have_attributes(
:class_name => vm.class.name,
:method_name => 'remove_snapshot',
:role => 'ems_operations',
:queue_name => vm.queue_name_for_ems_operations,
:zone => vm.my_zone,
:args => [snapshots.first.id],
:task_id => nil
)
end

it 'queues as expected with remove_evm_snapshot_queue' do
queue = vm.remove_evm_snapshot_queue(snapshots.first.id)

expect(queue).to have_attributes(
:class_name => vm.class.name,
:method_name => 'remove_evm_snapshot',
:role => 'ems_operations',
:queue_name => vm.queue_name_for_ems_operations,
:zone => vm.my_zone,
:args => [snapshots.first.id],
:task_id => nil
)
end

it 'queues an update task with remove_all_snapshots_queue' do
task_id = vm.remove_all_snapshots_queue(user.userid)

expect(MiqTask.find(task_id)).to have_attributes(
:name => "Removing all snapshots for #{vm.name}",
:state => "Queued",
:status => "Ok"
)

expect(MiqQueue.where(:class_name => vm.class.name).first).to have_attributes(
:class_name => vm.class.name,
:method_name => 'remove_all_snapshots',
:role => 'ems_operations',
:queue_name => ems.queue_name_for_ems_operations,
:zone => ems.my_zone,
:args => []
)
end
end
end