diff --git a/examples/image-streamer/api300/build_plan.rb b/examples/image-streamer/build_plan.rb similarity index 77% rename from examples/image-streamer/api300/build_plan.rb rename to examples/image-streamer/build_plan.rb index 1ba8378a3..f4767266a 100644 --- a/examples/image-streamer/api300/build_plan.rb +++ b/examples/image-streamer/build_plan.rb @@ -10,6 +10,13 @@ # specific language governing permissions and limitations under the License. require_relative '../../_client_i3s' # Gives access to @client +# Supported APIs: +# - 300, 500, 600 + +# Resources that can be created according to parameters: +# api_version = 300 & variant = Synergy to OneviewSDK::ImageStreamer::API300::BuildPlan +# api_version = 500 & variant = Synergy to OneviewSDK::ImageStreamer::API500::BuildPlan +# api_version = 600 & variant = Synergy to OneviewSDK::ImageStreamer::API600::BuildPlan # Example: Create a build plan for an API300 Image Streamer # NOTE: This will create three build plans with the following names 'Build_Plan_1', 'Build_Plan_2' and 'Build_Plan_3', then delete them. @@ -21,12 +28,13 @@ name: 'Build_Plan_1', oeBuildPlanType: 'Deploy' } - -plan_script = OneviewSDK::ImageStreamer::API300::PlanScript.find_by(@client, name: @plan_script1_name).first -plan_script2 = OneviewSDK::ImageStreamer::API300::PlanScript.find_by(@client, name: @plan_script2_name).first +plan_script_class = OneviewSDK::ImageStreamer.resource_named('PlanScript', @client.api_version) +plan_script = plan_script_class.find_by(@client, name: @plan_script1_name).first +plan_script2 = plan_script_class.find_by(@client, name: @plan_script2_name).first custom_attributes = JSON.parse(plan_script2['customAttributes']) custom_attributes.replace([custom_attributes[0].merge('type' => 'String')]) +build_plan_class = OneviewSDK::ImageStreamer.resource_named('BuildPlan', @client.api_version) build_step = [ { serialNumber: '1', @@ -59,14 +67,14 @@ } # Creating a build plan -item = OneviewSDK::ImageStreamer::API300::BuildPlan.new(@client, options) +item = build_plan_class.new(@client, options) puts "\n#Creating a build plan with name #{options[:name]}." item.create! item.retrieve! puts "\n#Build plan with name #{item['name']} and uri #{item['uri']} created successfully." # Creating a build plan with build steps -item2 = OneviewSDK::ImageStreamer::API300::BuildPlan.new(@client, options2) +item2 = build_plan_class.new(@client, options2) puts "\n#Creating a build plan with name #{options2[:name]}." item2.create! @@ -74,7 +82,7 @@ puts "\n#Build plan with name #{item2['name']} and uri #{item2['uri']} created successfully." # Creating a build plan with custom attributes -item3 = OneviewSDK::ImageStreamer::API300::BuildPlan.new(@client, options3) +item3 = build_plan_class.new(@client, options3) puts "\n#Creating a build plan with name #{options3[:name]}." item3.create! @@ -82,18 +90,18 @@ puts "\n#Build plan with name #{item3['name']} and uri #{item3['uri']} created successfully." # List all builds -list = OneviewSDK::ImageStreamer::API300::BuildPlan.get_all(@client) +list = build_plan_class.get_all(@client) puts "\n#Listing all:" list.each { |p| puts " #{p['name']}" } id = list.first['uri'] # Gets a build plan by id puts "\n#Gets a build plan by id #{id}:" -item4 = OneviewSDK::ImageStreamer::API300::BuildPlan.find_by(@client, uri: id).first +item4 = build_plan_class.find_by(@client, uri: id).first puts "\n#Build Plan with id #{item4['uri']} was found." # Updates a build plan -item5 = OneviewSDK::ImageStreamer::API300::BuildPlan.find_by(@client, name: 'Build_Plan_1').first +item5 = build_plan_class.find_by(@client, name: 'Build_Plan_1').first puts "\n#Updating a build plan with id #{item5['uri']} and name #{item5['name']}:" item5['name'] = 'Build_Plan_Updated' item5.update diff --git a/examples/image-streamer/api300/deployment_plan.rb b/examples/image-streamer/deployment_plan.rb similarity index 68% rename from examples/image-streamer/api300/deployment_plan.rb rename to examples/image-streamer/deployment_plan.rb index 3e2b0fdaf..b5df660c5 100644 --- a/examples/image-streamer/api300/deployment_plan.rb +++ b/examples/image-streamer/deployment_plan.rb @@ -1,4 +1,4 @@ -# (C) Copyright 2017 Hewlett Packard Enterprise Development LP +# (C) Copyright 2018 Hewlett Packard Enterprise Development LP # # Licensed under the Apache License, Version 2.0 (the "License"); # You may not use this file except in compliance with the License. @@ -10,15 +10,25 @@ # specific language governing permissions and limitations under the License. require_relative '../../_client_i3s' # Gives access to @client +# Supported APIs: +# - 300, 500, 600 -# Example: Create a deployment plan for an API300 Image Streamer +# Resources that can be created according to parameters: +# api_version = 300 & variant = Synergy to OneviewSDK::ImageStreamer::API300::DeploymentPlan +# api_version = 500 & variant = Synergy to OneviewSDK::ImageStreamer::API500::DeploymentPlan +# api_version = 600 & variant = Synergy to OneviewSDK::ImageStreamer::API600::DeploymentPlan + +# Example: Create a deployment plan for an Image Streamer # NOTE: This will create a deployment plan named 'Deployment_Plan_1', then delete it. # NOTE: You'll need to add the following instance variables to the _client_i3s.rb file with valid URIs for your environment: # @build_plan_name +# @golden_image_name +build_plan_class = OneviewSDK::ImageStreamer.resource_named('BuildPlan', @client.api_version) +build_plan = build_plan_class.find_by(@client, name: @build_plan_name).first +golden_image_class = OneviewSDK::ImageStreamer.resource_named('GoldenImage', @client.api_version) +golden_image = golden_image_class.find_by(@client, name: @golden_image_name).first -build_plan = OneviewSDK::ImageStreamer::API300::BuildPlan.find_by(@client, name: @build_plan_name).first -golden_image = OneviewSDK::ImageStreamer::API300::GoldenImage.find_by(@client, name: @golden_image_name).first - +deployment_plan_class = OneviewSDK::ImageStreamer.resource_named('DeploymentPlan', @client.api_version) options = { name: 'Deployment_Plan_1', description: 'AnyDescription', @@ -35,33 +45,33 @@ } # Creating a deployment plan -item = OneviewSDK::ImageStreamer::API300::DeploymentPlan.new(@client, options) +item = deployment_plan_class.new(@client, options) puts "\n#Creating a deployment plan with name #{options[:name]}." item.create! item.retrieve! puts "\n#Deployment plan with name #{item['name']} and uri #{item['uri']} created successfully." # Creating a deployment plan with a golden image -item2 = OneviewSDK::ImageStreamer::API300::DeploymentPlan.new(@client, options2) +item2 = deployment_plan_class.new(@client, options2) puts "\n#Creating a deployment plan with a golden image and name #{options2[:name]}." item2.create! item2.retrieve! puts "\n#Deployment plan with name #{item2['name']} and golden image with uri #{item2['goldenImageURI']} created successfully." # List all deployments -list = OneviewSDK::ImageStreamer::API300::DeploymentPlan.get_all(@client) +list = deployment_plan_class.get_all(@client) puts "\n#Listing all:" list.each { |p| puts " #{p['name']}" } id = list.first['uri'] # Gets a deployment plan by id puts "\n#Gets a deployment plan by id #{id}:" -item3 = OneviewSDK::ImageStreamer::API300::DeploymentPlan.find_by(@client, uri: id).first +item3 = deployment_plan_class.find_by(@client, uri: id).first puts "\n#Deployment Plan with uri #{item3['uri']} was found." # Gets a deployment plan by name puts "\n#Gets a deployment plan by name #{options[:name]}:" -item4 = OneviewSDK::ImageStreamer::API300::DeploymentPlan.find_by(@client, name: options[:name]).first +item4 = deployment_plan_class.find_by(@client, name: options[:name]).first puts "\n#Deployment Plan with name #{item4['uri']} was found." # Updates a deployment plan diff --git a/examples/image-streamer/api300/golden_image.rb b/examples/image-streamer/golden_image.rb similarity index 74% rename from examples/image-streamer/api300/golden_image.rb rename to examples/image-streamer/golden_image.rb index c1c9f2ab1..ff0746b6b 100644 --- a/examples/image-streamer/api300/golden_image.rb +++ b/examples/image-streamer/golden_image.rb @@ -10,16 +10,27 @@ # specific language governing permissions and limitations under the License. require_relative '../../_client_i3s' # Gives access to @client +# Supported APIs: +# - 300, 500, 600 -# Example: Create a golden image for an API300 Image Streamer +# Resources that can be created according to parameters: +# api_version = 300 & variant = Synergy to OneviewSDK::ImageStreamer::API300::GoldenImage +# api_version = 500 & variant = Synergy to OneviewSDK::ImageStreamer::API500::GoldenImage +# api_version = 600 & variant = Synergy to OneviewSDK::ImageStreamer::API600::GoldenImage + +# Example: Create a golden image for an Image Streamer # NOTE: This will create a golden images named 'Golden_Image_1' and 'Golden_Image_2', and then, it will delete them. # NOTE: You'll need to add the following instance variables to the _client_i3s.rb file with valid URIs for your environment: # @golden_image_download_path # @golden_image_upload_path # @golden_image_log_path +os_volume_class = OneviewSDK::ImageStreamer.resource_named('OSVolume', @client.api_version) +os_volume = os_volume_class.find_by(@client, {}).first + +build_plan_class = OneviewSDK::ImageStreamer.resource_named('BuildPlan', @client.api_version) +build_plan = build_plan_class.find_by(@client, oeBuildPlanType: 'capture').first -os_volume = OneviewSDK::ImageStreamer::API300::OSVolume.find_by(@client, {}).first -build_plan = OneviewSDK::ImageStreamer::API300::BuildPlan.find_by(@client, oeBuildPlanType: 'capture').first +golden_image_class = OneviewSDK::ImageStreamer.resource_named('GoldenImage', @client.api_version) options = { type: 'GoldenImage', @@ -29,7 +40,7 @@ } # Creating a golden image -item = OneviewSDK::ImageStreamer::API300::GoldenImage.new(@client, options) +item = golden_image_class.new(@client, options) item.set_os_volume(os_volume) item.set_build_plan(build_plan) puts "\n#Creating a golden image with name #{options[:name]}." @@ -38,19 +49,19 @@ puts "\n#Golden Image with name #{item['name']} and uri #{item['uri']} created successfully." # List all golden images -list = OneviewSDK::ImageStreamer::API300::GoldenImage.get_all(@client) +list = golden_image_class.get_all(@client) puts "\n#Listing all:" list.each { |p| puts " #{p['name']}" } id = list.first['uri'] # Gets a golden image by id puts "\n#Gets a golden image by id #{id}:" -item2 = OneviewSDK::ImageStreamer::API300::GoldenImage.find_by(@client, uri: id).first +item2 = golden_image_class.find_by(@client, uri: id).first puts "\n#Golden Image with id #{item2['uri']} was found." # Gets a golden image by name puts "\n#Gets a golden image by name #{options[:name]}:" -item3 = OneviewSDK::ImageStreamer::API300::GoldenImage.find_by(@client, name: options[:name]).first +item3 = golden_image_class.find_by(@client, name: options[:name]).first puts "\n#Golden Image with name #{item2['name']} was found." # Updates a golden image @@ -69,7 +80,7 @@ puts "\nAdds a golden image resource from the file that is uploaded from a local drive" options2 = { name: 'Golden_Image_2', description: 'Any_Description' } puts "\nAdding a golden image with name #{options2[:name]}." -item4 = OneviewSDK::ImageStreamer::API300::GoldenImage.add(@client, @golden_image_upload_path, options2) +item4 = golden_image_class.add(@client, @golden_image_upload_path, options2) puts "\nGolden Image with uri #{item4['uri']} and name #{item4['name']} added successfully." # Downloads the content of the selected golden image diff --git a/examples/image-streamer/api300/os_volume.rb b/examples/image-streamer/os_volume.rb similarity index 67% rename from examples/image-streamer/api300/os_volume.rb rename to examples/image-streamer/os_volume.rb index 853a2c09d..4e5a7b76f 100644 --- a/examples/image-streamer/api300/os_volume.rb +++ b/examples/image-streamer/os_volume.rb @@ -10,19 +10,26 @@ # specific language governing permissions and limitations under the License. require_relative '../../_client_i3s' # Gives access to @client +# Supported APIs: +# - 300, 500, 600 -# Example: Os Volume for an API300 Image Streamer -# NOTE: You must have one os volume. +# Resources that can be created according to parameters: +# api_version = 300 & variant = Synergy to OneviewSDK::ImageStreamer::API300::OSVolume +# api_version = 500 & variant = Synergy to OneviewSDK::ImageStreamer::API500::OSVolume +# api_version = 600 & variant = Synergy to OneviewSDK::ImageStreamer::API600::OSVolume +# Example: Os Volume for an Image Streamer +# NOTE: You must have one os volume. +os_volume_class = OneviewSDK::ImageStreamer.resource_named('OSVolume', @client.api_version) # List all os volume -list = OneviewSDK::ImageStreamer::API300::OSVolume.get_all(@client) +list = os_volume_class.get_all(@client) puts "\n#Listing all:" list.each { |p| puts " #{p['name']}" } id = list.first['uri'] # Gets an os volume by id puts "\n#Gets an os volume by id #{id}:" -item2 = OneviewSDK::ImageStreamer::API300::OSVolume.find_by(@client, uri: id).first +item2 = os_volume_class.find_by(@client, uri: id).first puts "\n#Os Volume with id #{item2['uri']} was found." diff --git a/examples/image-streamer/plan_script.rb b/examples/image-streamer/plan_script.rb index f814a8366..6e6e44986 100644 --- a/examples/image-streamer/plan_script.rb +++ b/examples/image-streamer/plan_script.rb @@ -16,8 +16,8 @@ # Resources that can be created according to parameters: # api_version = 300 & variant = Synergy to OneviewSDK::ImageStreamer::API300::PlanScript -# api_version = 500 & variant = Synergy to OneviewSDK::ImageStreamer::API300::PlanScript -# api_version = 600 & variant = Synergy to OneviewSDK::ImageStreamer::API300::PlanScript +# api_version = 500 & variant = Synergy to OneviewSDK::ImageStreamer::API500::PlanScript +# api_version = 600 & variant = Synergy to OneviewSDK::ImageStreamer::API600::PlanScript # Example: Create a plan script for an Image Streamer # NOTE: This will create a plan script named 'Plan_Script_1', then delete it. diff --git a/lib/oneview-sdk/image-streamer/resource/api500/build_plan.rb b/lib/oneview-sdk/image-streamer/resource/api500/build_plan.rb new file mode 100644 index 000000000..c4d6696ff --- /dev/null +++ b/lib/oneview-sdk/image-streamer/resource/api500/build_plan.rb @@ -0,0 +1,22 @@ +# (C) Copyright 2018 Hewlett Packard Enterprise Development LP +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# You may not use this file except in compliance with the License. +# You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software distributed +# under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR +# CONDITIONS OF ANY KIND, either express or implied. See the License for the specific +# language governing permissions and limitations under the License. + +require_relative 'resource' + +module OneviewSDK + module ImageStreamer + module API500 + # Build Plan resource implementation for Image Streamer + class BuildPlan < OneviewSDK::ImageStreamer::API300::BuildPlan + end + end + end +end diff --git a/lib/oneview-sdk/image-streamer/resource/api600/build_plan.rb b/lib/oneview-sdk/image-streamer/resource/api600/build_plan.rb new file mode 100644 index 000000000..d6eee9ef3 --- /dev/null +++ b/lib/oneview-sdk/image-streamer/resource/api600/build_plan.rb @@ -0,0 +1,22 @@ +# (C) Copyright 2018 Hewlett Packard Enterprise Development LP +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# You may not use this file except in compliance with the License. +# You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software distributed +# under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR +# CONDITIONS OF ANY KIND, either express or implied. See the License for the specific +# language governing permissions and limitations under the License. + +require_relative 'resource' + +module OneviewSDK + module ImageStreamer + module API600 + # Build Plan resource implementation for Image Streamer + class BuildPlan < OneviewSDK::ImageStreamer::API500::BuildPlan + end + end + end +end diff --git a/spec/integration/image-streamer/api500/build_plan/create_spec.rb b/spec/integration/image-streamer/api500/build_plan/create_spec.rb new file mode 100644 index 000000000..b052fe9b1 --- /dev/null +++ b/spec/integration/image-streamer/api500/build_plan/create_spec.rb @@ -0,0 +1,106 @@ +# (C) Copyright 2018 Hewlett Packard Enterprise Development LP +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# You may not use this file except in compliance with the License. +# You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software distributed +# under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR +# CONDITIONS OF ANY KIND, either express or implied. See the License for the +# specific language governing permissions and limitations under the License. + +require 'spec_helper' + +klass = OneviewSDK::ImageStreamer::API500::BuildPlan +RSpec.describe klass, integration_i3s: true, type: CREATE, sequence: i3s_seq(klass) do + include_context 'integration i3s api500 context' + + describe '#create' do + it 'creates a build plan' do + options = { + name: BUILD_PLAN1_NAME, + oeBuildPlanType: 'deploy' + } + + item = klass.new($client_i3s_500, options) + expect { item.create! }.not_to raise_error + item.retrieve! + expect(item['uri']).to be + expect(item['name']).to eq(options[:name]) + expect(item['oeBuildPlanType']).to eq(options[:oeBuildPlanType]) + end + + it 'creates a build plan with capture type' do + options = { + name: BUILD_PLAN2_NAME, + oeBuildPlanType: 'capture' + } + + item = klass.new($client_i3s_500, options) + expect { item.create! }.not_to raise_error + item.retrieve! + expect(item['uri']).to be + expect(item['name']).to eq(options[:name]) + expect(item['oeBuildPlanType']).to eq(options[:oeBuildPlanType]) + end + + it 'creates a build plan with build step' do + plan_script = OneviewSDK::ImageStreamer::API500::PlanScript.find_by($client_i3s_500, name: PLAN_SCRIPT1_NAME).first + + build_step = [ + { + serialNumber: '1', + parameters: 'anystring', + planScriptName: PLAN_SCRIPT1_NAME, + planScriptUri: plan_script['uri'] + } + ] + + options = { + name: BUILD_PLAN3_NAME, + oeBuildPlanType: 'deploy', + buildStep: build_step + } + + item = klass.new($client_i3s_500, options) + expect(item['buildStep']).to eq(build_step) + + expect { item.create! }.not_to raise_error + item.retrieve! + expect(item['uri']).to be + expect(item['name']).to eq(options[:name]) + expect(item['oeBuildPlanType']).to eq(options[:oeBuildPlanType]) + end + + it 'creates a build plan with build step and custom attributes' do + plan_script = OneviewSDK::ImageStreamer::API500::PlanScript.find_by($client_i3s_500, name: PLAN_SCRIPT2_NAME).first + + custom_attributes = JSON.parse(plan_script['customAttributes']) + custom_attributes.replace([custom_attributes[0].merge('type' => 'String')]) + + build_step = [ + { + serialNumber: '1', + parameters: 'anystring', + planScriptName: PLAN_SCRIPT2_NAME, + planScriptUri: plan_script['uri'] + } + ] + + options = { + name: BUILD_PLAN4_NAME, + oeBuildPlanType: 'deploy', + buildStep: build_step, + customAttributes: custom_attributes + } + + item = klass.new($client_i3s_500, options) + expect { item.create! }.not_to raise_error + item.retrieve! + expect(item['uri']).to be + expect(item['name']).to eq(options[:name]) + expect(item['oeBuildPlanType']).to eq(options[:oeBuildPlanType]) + expect(item['customAttributes']).not_to be_empty + end + end +end diff --git a/spec/integration/image-streamer/api500/build_plan/delete_spec.rb b/spec/integration/image-streamer/api500/build_plan/delete_spec.rb new file mode 100644 index 000000000..313b0d23f --- /dev/null +++ b/spec/integration/image-streamer/api500/build_plan/delete_spec.rb @@ -0,0 +1,38 @@ +# (C) Copyright 2018 Hewlett Packard Enterprise Development LP +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# You may not use this file except in compliance with the License. +# You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software distributed +# under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR +# CONDITIONS OF ANY KIND, either express or implied. See the License for the +# specific language governing permissions and limitations under the License. + +require 'spec_helper' + +klass = OneviewSDK::ImageStreamer::API500::BuildPlan +RSpec.describe klass, integration_i3s: true, type: DELETE, sequence: i3s_rseq(klass) do + include_context 'integration i3s api500 context' + + describe '#delete' do + it 'removes all build plans' do + item = klass.find_by($client_i3s_500, name: BUILD_PLAN1_NAME).first + item2 = klass.find_by($client_i3s_500, name: BUILD_PLAN2_NAME).first + item3 = klass.find_by($client_i3s_500, name: BUILD_PLAN3_NAME).first + item4 = klass.find_by($client_i3s_500, name: BUILD_PLAN4_NAME).first + expect(item).to be + expect(item2).to be + expect(item3).to be + expect(item4).to be + expect { item.delete }.not_to raise_error + expect(item.retrieve!).to eq(false) + expect { item2.delete }.not_to raise_error + expect(item2.retrieve!).to eq(false) + expect { item3.delete }.not_to raise_error + expect(item3.retrieve!).to eq(false) + expect { item4.delete }.not_to raise_error + expect(item4.retrieve!).to eq(false) + end + end +end diff --git a/spec/integration/image-streamer/api500/build_plan/update_spec.rb b/spec/integration/image-streamer/api500/build_plan/update_spec.rb new file mode 100644 index 000000000..0872b7a38 --- /dev/null +++ b/spec/integration/image-streamer/api500/build_plan/update_spec.rb @@ -0,0 +1,32 @@ +# (C) Copyright 2018 Hewlett Packard Enterprise Development LP +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# You may not use this file except in compliance with the License. +# You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software distributed +# under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR +# CONDITIONS OF ANY KIND, either express or implied. See the License for the +# specific language governing permissions and limitations under the License. + +require 'spec_helper' + +klass = OneviewSDK::ImageStreamer::API500::BuildPlan +RSpec.describe klass, integration_i3s: true, type: UPDATE do + include_context 'integration i3s api500 context' + + describe '#update' do + it 'updates the name of the build plan' do + item = klass.find_by($client_i3s_500, name: BUILD_PLAN1_NAME).first + expect(item).to be + item['name'] = BUILD_PLAN1_NAME_UPDATED + expect { item.update }.not_to raise_error + item.retrieve! + expect(item['name']).to eq(BUILD_PLAN1_NAME_UPDATED) + item['name'] = BUILD_PLAN1_NAME + expect { item.update }.not_to raise_error + item.retrieve! + expect(item['name']).to eq(BUILD_PLAN1_NAME) + end + end +end diff --git a/spec/integration/image-streamer/api600/build_plan/create_spec.rb b/spec/integration/image-streamer/api600/build_plan/create_spec.rb new file mode 100644 index 000000000..92712f53e --- /dev/null +++ b/spec/integration/image-streamer/api600/build_plan/create_spec.rb @@ -0,0 +1,106 @@ +# (C) Copyright 2018 Hewlett Packard Enterprise Development LP +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# You may not use this file except in compliance with the License. +# You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software distributed +# under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR +# CONDITIONS OF ANY KIND, either express or implied. See the License for the +# specific language governing permissions and limitations under the License. + +require 'spec_helper' + +klass = OneviewSDK::ImageStreamer::API600::BuildPlan +RSpec.describe klass, integration_i3s: true, type: CREATE, sequence: i3s_seq(klass) do + include_context 'integration i3s api600 context' + + describe '#create' do + it 'creates a build plan' do + options = { + name: BUILD_PLAN1_NAME, + oeBuildPlanType: 'deploy' + } + + item = klass.new($client_i3s_600, options) + expect { item.create! }.not_to raise_error + item.retrieve! + expect(item['uri']).to be + expect(item['name']).to eq(options[:name]) + expect(item['oeBuildPlanType']).to eq(options[:oeBuildPlanType]) + end + + it 'creates a build plan with capture type' do + options = { + name: BUILD_PLAN2_NAME, + oeBuildPlanType: 'capture' + } + + item = klass.new($client_i3s_600, options) + expect { item.create! }.not_to raise_error + item.retrieve! + expect(item['uri']).to be + expect(item['name']).to eq(options[:name]) + expect(item['oeBuildPlanType']).to eq(options[:oeBuildPlanType]) + end + + it 'creates a build plan with build step' do + plan_script = OneviewSDK::ImageStreamer::API600::PlanScript.find_by($client_i3s_600, name: PLAN_SCRIPT1_NAME).first + + build_step = [ + { + serialNumber: '1', + parameters: 'anystring', + planScriptName: PLAN_SCRIPT1_NAME, + planScriptUri: plan_script['uri'] + } + ] + + options = { + name: BUILD_PLAN3_NAME, + oeBuildPlanType: 'deploy', + buildStep: build_step + } + + item = klass.new($client_i3s_600, options) + expect(item['buildStep']).to eq(build_step) + + expect { item.create! }.not_to raise_error + item.retrieve! + expect(item['uri']).to be + expect(item['name']).to eq(options[:name]) + expect(item['oeBuildPlanType']).to eq(options[:oeBuildPlanType]) + end + + it 'creates a build plan with build step and custom attributes' do + plan_script = OneviewSDK::ImageStreamer::API600::PlanScript.find_by($client_i3s_600, name: PLAN_SCRIPT2_NAME).first + + custom_attributes = JSON.parse(plan_script['customAttributes']) + custom_attributes.replace([custom_attributes[0].merge('type' => 'String')]) + + build_step = [ + { + serialNumber: '1', + parameters: 'anystring', + planScriptName: PLAN_SCRIPT2_NAME, + planScriptUri: plan_script['uri'] + } + ] + + options = { + name: BUILD_PLAN4_NAME, + oeBuildPlanType: 'deploy', + buildStep: build_step, + customAttributes: custom_attributes + } + + item = klass.new($client_i3s_600, options) + expect { item.create! }.not_to raise_error + item.retrieve! + expect(item['uri']).to be + expect(item['name']).to eq(options[:name]) + expect(item['oeBuildPlanType']).to eq(options[:oeBuildPlanType]) + expect(item['customAttributes']).not_to be_empty + end + end +end diff --git a/spec/integration/image-streamer/api600/build_plan/delete_spec.rb b/spec/integration/image-streamer/api600/build_plan/delete_spec.rb new file mode 100644 index 000000000..cc60bba84 --- /dev/null +++ b/spec/integration/image-streamer/api600/build_plan/delete_spec.rb @@ -0,0 +1,38 @@ +# (C) Copyright 2018 Hewlett Packard Enterprise Development LP +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# You may not use this file except in compliance with the License. +# You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software distributed +# under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR +# CONDITIONS OF ANY KIND, either express or implied. See the License for the +# specific language governing permissions and limitations under the License. + +require 'spec_helper' + +klass = OneviewSDK::ImageStreamer::API600::BuildPlan +RSpec.describe klass, integration_i3s: true, type: DELETE, sequence: i3s_rseq(klass) do + include_context 'integration i3s api600 context' + + describe '#delete' do + it 'removes all build plans' do + item = klass.find_by($client_i3s_600, name: BUILD_PLAN1_NAME).first + item2 = klass.find_by($client_i3s_600, name: BUILD_PLAN2_NAME).first + item3 = klass.find_by($client_i3s_600, name: BUILD_PLAN3_NAME).first + item4 = klass.find_by($client_i3s_600, name: BUILD_PLAN4_NAME).first + expect(item).to be + expect(item2).to be + expect(item3).to be + expect(item4).to be + expect { item.delete }.not_to raise_error + expect(item.retrieve!).to eq(false) + expect { item2.delete }.not_to raise_error + expect(item2.retrieve!).to eq(false) + expect { item3.delete }.not_to raise_error + expect(item3.retrieve!).to eq(false) + expect { item4.delete }.not_to raise_error + expect(item4.retrieve!).to eq(false) + end + end +end diff --git a/spec/integration/image-streamer/api600/build_plan/update_spec.rb b/spec/integration/image-streamer/api600/build_plan/update_spec.rb new file mode 100644 index 000000000..08fbcb194 --- /dev/null +++ b/spec/integration/image-streamer/api600/build_plan/update_spec.rb @@ -0,0 +1,32 @@ +# (C) Copyright 2018 Hewlett Packard Enterprise Development LP +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# You may not use this file except in compliance with the License. +# You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software distributed +# under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR +# CONDITIONS OF ANY KIND, either express or implied. See the License for the +# specific language governing permissions and limitations under the License. + +require 'spec_helper' + +klass = OneviewSDK::ImageStreamer::API600::BuildPlan +RSpec.describe klass, integration_i3s: true, type: UPDATE do + include_context 'integration i3s api600 context' + + describe '#update' do + it 'updates the name of the build plan' do + item = klass.find_by($client_i3s_600, name: BUILD_PLAN1_NAME).first + expect(item).to be + item['name'] = BUILD_PLAN1_NAME_UPDATED + expect { item.update }.not_to raise_error + item.retrieve! + expect(item['name']).to eq(BUILD_PLAN1_NAME_UPDATED) + item['name'] = BUILD_PLAN1_NAME + expect { item.update }.not_to raise_error + item.retrieve! + expect(item['name']).to eq(BUILD_PLAN1_NAME) + end + end +end diff --git a/spec/unit/image-streamer/resource/api500/build_plan_spec.rb b/spec/unit/image-streamer/resource/api500/build_plan_spec.rb new file mode 100644 index 000000000..828fd3c43 --- /dev/null +++ b/spec/unit/image-streamer/resource/api500/build_plan_spec.rb @@ -0,0 +1,9 @@ +require 'spec_helper' + +klass = OneviewSDK::ImageStreamer::API500::BuildPlan +RSpec.describe klass do + include_context 'shared context' + it 'inherits from API300' do + expect(described_class).to be < OneviewSDK::ImageStreamer::API300::BuildPlan + end +end diff --git a/spec/unit/image-streamer/resource/api600/build_plan_spec.rb b/spec/unit/image-streamer/resource/api600/build_plan_spec.rb new file mode 100644 index 000000000..7dc955959 --- /dev/null +++ b/spec/unit/image-streamer/resource/api600/build_plan_spec.rb @@ -0,0 +1,9 @@ +require 'spec_helper' + +klass = OneviewSDK::ImageStreamer::API600::BuildPlan +RSpec.describe klass do + include_context 'shared context' + it 'inherits from API500' do + expect(described_class).to be < OneviewSDK::ImageStreamer::API500::BuildPlan + end +end