Skip to content

Commit

Permalink
Added extract bundle method to ArtifactBundle
Browse files Browse the repository at this point in the history
  • Loading branch information
ricardogpsf committed Feb 24, 2017
1 parent 60b611f commit 702943d
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -22,6 +22,7 @@ Added full support to Image Streamer Rest API version 300:
- [#174](https://github.com/HewlettPackard/oneview-sdk-ruby/issues/174) I3S - Integration test for Build Plan failing
- [#183](https://github.com/HewlettPackard/oneview-sdk-ruby/issues/183) Image Streamer Client cannot be created with the OneView environment variables
- [#184](https://github.com/HewlettPackard/oneview-sdk-ruby/issues/184) Coveralls badge showing coverage as unknown
- [#195](https://github.com/HewlettPackard/oneview-sdk-ruby/issues/195) Missing endpoint for extract backup in Artifact Bundle

# v4.0.0

Expand Down
5 changes: 5 additions & 0 deletions examples/image-streamer/api300/artifact_bundle.rb
Expand Up @@ -69,6 +69,11 @@
puts "\nUploading backup bundle"
puts OneviewSDK::ImageStreamer::API300::ArtifactBundle.create_backup_from_file!(@client, deployment_group, backup_download_path, 'Backup Bundle')

puts "\nExtracting backup bundle uploaded"
backup = OneviewSDK::ImageStreamer::API300::ArtifactBundle.get_backups(@client).first
puts OneviewSDK::ImageStreamer::API300::ArtifactBundle.extract_backup(@client, deployment_group, backup)
puts 'Backup extracted successfully'

puts "\nDeleting the artifact bundles"
item.delete
item_uploaded.delete
Expand Down
30 changes: 22 additions & 8 deletions lib/oneview-sdk/image-streamer/resource/api300/artifact_bundle.rb
Expand Up @@ -72,7 +72,7 @@ def self.create_backup(client, deployment_group)
client.response_handler(response)
end

# Creates a backup bundle from the zip file
# Creates a backup bundle from the zip file and extract all the artifacts present in the uploaded file
# If there are any artifacts existing, they will be removed before the extract operation.
# @param [OneviewSDK::ImageStreamer::Client] client The client object for the Image Streamer appliance
# @param [String] file_path The file path with file extension
Expand All @@ -97,11 +97,26 @@ def self.create_backup_from_file!(client, deployment_group, file_path, artifact_
# Download the backup bundle
# @param [OneviewSDK::ImageStreamer::Client] client The client object for the Image Streamer appliance
# @param [String] local_drive_path The path where file will be saved
# @param [String] artifact_bundle_backup The backup ArtifactBundle with 'downloadURI'
# @param [ArtifactBundle] bundle_backup The backup ArtifactBundle with 'downloadURI'
# @return [Boolean] true if backup was downloaded
def self.download_backup(client, local_drive_path, artifact_bundle_backup)
raise IncompleteResource, "Missing required attribute 'downloadURI'" unless artifact_bundle_backup['downloadURI']
client.download_file(artifact_bundle_backup['downloadURI'], local_drive_path)
def self.download_backup(client, local_drive_path, bundle_backup)
raise IncompleteResource, "Missing required attribute 'downloadURI'" unless bundle_backup['downloadURI']
client.download_file(bundle_backup['downloadURI'], local_drive_path)
end

# Extracts the existing backup bundle on the appliance and creates all the artifacts.
# If there are any artifacts existing, they will be removed before the extract operation.
# @param [DeploymentGroup] deployment_group The DeploymentGroup with 'name' or 'uri'
# @param [ArtifactBundle] bundle_backup The backup ArtifactBundle with 'uri'
# @return [Boolean] true if backup bundle was extracted
# @raise [OneviewSDK::IncompleteResource] if the client or uri is not set
def self.extract_backup(client, deployment_group, bundle_backup)
ensure_resource!(deployment_group)
raise IncompleteResource, "Missing required attribute 'uri' of backup bundle" unless bundle_backup['uri']
id = bundle_backup['uri'].split('/').last
response = client.rest_put("#{BACKUPS_URI}/#{id}", 'body' => { 'deploymentGroupURI' => deployment_group['uri'] })
client.response_handler(response)
true
end

# Method is not available
Expand All @@ -122,10 +137,9 @@ def update_name(new_name)
true
end

# Extracts the existing backup bundle on the appliance and creates all the artifacts.
# If there are any artifacts existing, they will be removed before the extract operation.
# Extracts the artifact bundle and creates the artifacts on the appliance
# @param [Boolean] force Forces the extract operation even when there are any conflicts
# @return [Boolean] true if backup bundle was extracted
# @return [Boolean] true if artifact bundle was extracted
# @raise [OneviewSDK::IncompleteResource] if the client or uri is not set
def extract(force = true)
ensure_uri
Expand Down
Expand Up @@ -110,4 +110,11 @@
expect { klass.create_backup_from_file!($client_i3s_300, deployment_group, @backup_bundle_file_path, 'BundleBackup') }.not_to raise_error
end
end

describe '::extract_backup' do
it 'should extract the backup created' do
artifact_bundle_backup = klass.get_backups($client_i3s_300).first
expect { klass.extract_backup($client_i3s_300, deployment_group, artifact_bundle_backup) }.not_to raise_error
end
end
end
43 changes: 43 additions & 0 deletions spec/unit/image-streamer/api300/artifact_bundle_spec.rb
Expand Up @@ -291,6 +291,49 @@
end
end

describe '::extract_backup' do
it 'should call rest api correctly' do
deployment_group = OneviewSDK::ImageStreamer::API300::DeploymentGroup.new(@client_i3s_300, uri: '/rest/deployment-groups/1')
artifact_backup = OneviewSDK::ImageStreamer::API300::ArtifactBundle.new(@client_i3s_300, uri: '/rest/artifact-bundles/UUID-1')
expected_params = { 'body' => { 'deploymentGroupURI' => '/rest/deployment-groups/1' } }
fake_response = spy('http_response')
expect(deployment_group).to receive(:retrieve!).and_return(true)
expect(@client_i3s_300).to receive(:rest_put).with('/rest/artifact-bundles/backups/UUID-1', expected_params).and_return(fake_response)
expect(@client_i3s_300).to receive(:response_handler).with(fake_response)

result = described_class.extract_backup(@client_i3s_300, deployment_group, artifact_backup)

expect(result).to eq(true)
end

context 'when bundle backup has not uri' do
it 'should throw IncompleteResource error' do
deployment_group = OneviewSDK::ImageStreamer::API300::DeploymentGroup.new(@client_i3s_300, uri: '/rest/deployment-groups/1')
allow(deployment_group).to receive(:retrieve!).and_return(true)
artifact_backup = OneviewSDK::ImageStreamer::API300::ArtifactBundle.new(@client_i3s_300)

expect do
described_class.extract_backup(@client_i3s_300, deployment_group, artifact_backup)
end.to raise_error(OneviewSDK::IncompleteResource, /Missing required attribute 'uri' of backup bundle/)
end
end

context 'when deployment group can not be retrieved' do
it 'should throw IncompleteResource error' do
deployment_group = OneviewSDK::ImageStreamer::API300::DeploymentGroup.new(@client_i3s_300)
allow(deployment_group).to receive(:retrieve!).and_return(false)
artifact_backup = OneviewSDK::ImageStreamer::API300::ArtifactBundle.new(@client_i3s_300, uri: '/rest/artifact-bundles/UUID-1')

expect do
described_class.extract_backup(@client_i3s_300, deployment_group, artifact_backup)
end.to raise_error(
OneviewSDK::IncompleteResource,
/The resource OneviewSDK::ImageStreamer::API300::DeploymentGroup can not be retrieved. Ensure it can be retrieved./
)
end
end
end

describe '#update' do
it 'should throw unavailable method error' do
expect { artifact_bundle.update }.to raise_error(OneviewSDK::MethodUnavailable)
Expand Down

0 comments on commit 702943d

Please sign in to comment.