Skip to content

Commit

Permalink
Merge pull request #152 from miha-plesko/delete_aws_object
Browse files Browse the repository at this point in the history
Support deletion of CloudObjectStoreObject
  • Loading branch information
blomquisg authored Mar 6, 2017
2 parents b65b899 + a7676a4 commit a3d0495
Show file tree
Hide file tree
Showing 4 changed files with 110 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ def process_objects(bucket_id, bucket_object)
def parse_object(object, bucket)
uid = object['key']
{
:type => self.class.object_type,
:ext_management_system => ems,
:ems_ref => "#{bucket.ems_ref}_#{uid}",
:etag => object['etag'],
Expand All @@ -79,5 +80,9 @@ class << self
def container_type
ManageIQ::Providers::Amazon::StorageManager::S3::CloudObjectStoreContainer.name
end

def object_type
ManageIQ::Providers::Amazon::StorageManager::S3::CloudObjectStoreObject.name
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
class ManageIQ::Providers::Amazon::StorageManager::S3::CloudObjectStoreObject < ::CloudObjectStoreObject
supports :delete do
unless ext_management_system
unsupported_reason_add(:delete, _("The Storage Object is not connected to an active %{table}") % {
:table => ui_lookup(:table => "ext_management_systems")
})
end

unless cloud_object_store_container
unsupported_reason_add(:delete, _("The Storage Object is not connected to an active %{table}") % {
:table => ui_lookup(:table => "cloud_object_store_containers")
})
end
end

def provider_object(connection = nil)
connection ||= ext_management_system.connect
connection.bucket(cloud_object_store_container.ems_ref).object(key)
end

def raw_delete
with_provider_object(&:delete)
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ def parse_object(object, bucket_id)
uid = object.key

new_result = {
:type => self.class.object_type,
:ems_ref => "#{bucket_id}_#{uid}",
:etag => object.etag,
:last_modified => object.last_modified,
Expand All @@ -108,5 +109,9 @@ class << self
def container_type
ManageIQ::Providers::Amazon::StorageManager::S3::CloudObjectStoreContainer.name
end

def object_type
ManageIQ::Providers::Amazon::StorageManager::S3::CloudObjectStoreObject.name
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,82 @@
end
end

describe "destructive operations (objects)" do
before do
ems.cloud_object_store_containers << FactoryGirl.create_list(
:aws_bucket_with_objects,
5,
:ext_management_system => ems.s3_storage_manager
)
end

let :bucket do
ems.cloud_object_store_containers.first
end

let :object do
bucket.cloud_object_store_objects.first
end

it "objects's provider_object is of expected type" do
with_aws_stubbed(stub_responses) do
provider_obj = object.provider_object

expect(provider_obj).to_not be_nil
expect(provider_obj.class).to eq(Aws::S3::Object)
end
end

it "object delete triggers remote deletion" do
expect(object).to receive(:with_provider_object)

with_aws_stubbed(stub_responses) do
object.delete_cloud_object_store_object
end
end

it "remove object (trigger)" do
options = {:ids => [object.id], :task => "delete_cloud_object_store_object", :userid => "admin"}

expect { CloudObjectStoreObject.process_tasks(options) }.to change { MiqQueue.count }.by(1)
end

it "remove object (process)" do
with_aws_stubbed(stub_responses) do
# should not remove from MIQ database, we rather rely on refresh
expect { object.delete_cloud_object_store_object }.to change { ems.cloud_object_store_objects.count }.by(0)
end
end

it "object type" do
expect(object.class).to eq(ManageIQ::Providers::Amazon::StorageManager::S3::CloudObjectStoreObject)

o = CloudObjectStoreObject.find(object.id)

expect(o.class).to eq(ManageIQ::Providers::Amazon::StorageManager::S3::CloudObjectStoreObject)
end

it "object with s3 and bucket should support delete" do
with_aws_stubbed(stub_responses) do
expect(object.supports?(:delete)).to be_truthy
end
end

it "object without s3 should not support delete" do
object.ext_management_system = nil
with_aws_stubbed(stub_responses) do
expect(object.supports?(:delete)).to be_falsey
end
end

it "object without bucket should not support delete" do
object.cloud_object_store_container = nil
with_aws_stubbed(stub_responses) do
expect(object.supports?(:delete)).to be_falsey
end
end
end

def refresh_spec
ems.reload

Expand Down

0 comments on commit a3d0495

Please sign in to comment.