Skip to content

Commit

Permalink
Merge pull request #21801 from kbrock/cloud_volume_snapshot
Browse files Browse the repository at this point in the history
Cloud volume snapshot queue methods
  • Loading branch information
agrare authored Apr 19, 2022
2 parents 035b737 + 77ec690 commit d8c6cf0
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 6 deletions.
4 changes: 4 additions & 0 deletions app/models/cloud_volume.rb
Original file line number Diff line number Diff line change
Expand Up @@ -189,4 +189,8 @@ def raw_safe_delete_volume
def available_vms
raise NotImplementedError, _("available_vms must be implemented in a subclass")
end

def create_volume_snapshot_queue(userid, options = {})
ext_management_system.class_by_ems(:CloudVolumeSnapshot)&.create_snapshot_queue(userid, self, options)
end
end
58 changes: 57 additions & 1 deletion app/models/cloud_volume_snapshot.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,63 @@ def my_zone
self.class.my_zone(ext_management_system)
end

def self.create_snapshot_queue(userid, cloud_volume, options = {})
raise ArgumentError, "Must provide a cloud volume with a provider" if cloud_volume&.ext_management_system.nil?

ext_management_system = cloud_volume.ext_management_system
task_opts = {
:action => "creating volume snapshot in #{ext_management_system.inspect} for #{cloud_volume.inspect} with #{options.inspect}",
:userid => userid
}

queue_opts = {
:class_name => cloud_volume.class.name,
:instance_id => cloud_volume.id,
:method_name => 'create_volume_snapshot',
:role => 'ems_operations',
:queue_name => ext_management_system.queue_name_for_ems_operations,
:zone => my_zone(ext_management_system),
:args => [options]
}

MiqTask.generic_action_with_callback(task_opts, queue_opts)
end

def self.create_snapshot(cloud_volume, options)
raw_create_snapshot(cloud_volume, options)
end

def self.raw_create_snapshot(_cloud_volume, _options)
raise NotImplementedError, _("raw_create_snapshot must be implemented in a subclass")
end

def update_snapshot_queue(userid = "system", options = {})
task_opts = {
:action => "updating volume snapshot #{inspect} in #{ext_management_system.inspect} with #{options.inspect}",
:userid => userid
}

queue_opts = {
:class_name => self.class.name,
:instance_id => id,
:method_name => 'update_snapshot',
:role => 'ems_operations',
:queue_name => ext_management_system.queue_name_for_ems_operations,
:zone => my_zone,
:args => [options]
}

MiqTask.generic_action_with_callback(task_opts, queue_opts)
end

def update_snapshot(options = {})
raw_update_snapshot(options)
end

def raw_update_snapshot(_options = {})
raise NotImplementedError, _("update_snapshot must be implemented in a subclass")
end

# Delete a cloud volume snapshot as a queued task and return the task id. The
# queue name and the queue zone are derived from the EMS. The userid is
# optional and defaults to 'system'.
Expand All @@ -42,7 +99,6 @@ def delete_snapshot_queue(userid = "system", _options = {})
:class_name => self.class.name,
:instance_id => id,
:method_name => 'delete_snapshot',
:priority => MiqQueue::HIGH_PRIORITY,
:role => 'ems_operations',
:queue_name => ext_management_system.queue_name_for_ems_operations,
:zone => my_zone,
Expand Down
9 changes: 4 additions & 5 deletions spec/support/supports_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,10 @@ def stub_supports_not(model, feature = :update, reason = nil)

stub_supports(model, feature, :supported => false)

if reason
receive_reason = receive(:unsupported_reason).with(feature).and_return(reason)
allow(model).to(receive_reason)
allow_any_instance_of(model).to(receive_reason)
end
reason ||= SupportsFeatureMixin.reason_or_default(reason)
receive_reason = receive(:unsupported_reason).with(feature).and_return(reason)
allow(model).to(receive_reason)
allow_any_instance_of(model).to(receive_reason)
end
end
end
Expand Down

0 comments on commit d8c6cf0

Please sign in to comment.