diff --git a/CHANGELOG.md b/CHANGELOG.md index 9c7528bf0..a7b1f117c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/examples/image-streamer/api300/artifact_bundle.rb b/examples/image-streamer/api300/artifact_bundle.rb index 36f955968..3d116b62f 100644 --- a/examples/image-streamer/api300/artifact_bundle.rb +++ b/examples/image-streamer/api300/artifact_bundle.rb @@ -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 diff --git a/lib/oneview-sdk/image-streamer/resource/api300/artifact_bundle.rb b/lib/oneview-sdk/image-streamer/resource/api300/artifact_bundle.rb index bffcf5af5..73718e33e 100644 --- a/lib/oneview-sdk/image-streamer/resource/api300/artifact_bundle.rb +++ b/lib/oneview-sdk/image-streamer/resource/api300/artifact_bundle.rb @@ -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 @@ -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 @@ -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 diff --git a/spec/integration/image-streamer/api300/artifact_bundle/create_spec.rb b/spec/integration/image-streamer/api300/artifact_bundle/create_spec.rb index ed73931e0..468c1eb99 100644 --- a/spec/integration/image-streamer/api300/artifact_bundle/create_spec.rb +++ b/spec/integration/image-streamer/api300/artifact_bundle/create_spec.rb @@ -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 diff --git a/spec/unit/image-streamer/api300/artifact_bundle_spec.rb b/spec/unit/image-streamer/api300/artifact_bundle_spec.rb index 0d2da613d..99173a5a4 100644 --- a/spec/unit/image-streamer/api300/artifact_bundle_spec.rb +++ b/spec/unit/image-streamer/api300/artifact_bundle_spec.rb @@ -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)