diff --git a/CHANGELOG.md b/CHANGELOG.md index 8fa7b819f..d59f93996 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,9 +1,12 @@ -## v5.1.2 (Unreleased) +## v5.1.2 #### Notes This release adds the [endpoints-support.md](endpoints-support.md) file to the repository, in order to track implemented endpoints and what is in the scope of this SDK. Also adds the [TESTING.md](TESTING.md) file to the repository, in order to guide the test execution and implementation for this SDK. +#### Bug fixes & Enhancements +- [#285](https://github.com/HewlettPackard/oneview-sdk-ruby/issues/285) Add helper method to set a StorageSystem to a StoragePool of API500 + ## v5.1.1 #### Bug fixes & Enhancements diff --git a/lib/oneview-sdk/resource/api200/storage_pool.rb b/lib/oneview-sdk/resource/api200/storage_pool.rb index b3f2df388..296fa3769 100644 --- a/lib/oneview-sdk/resource/api200/storage_pool.rb +++ b/lib/oneview-sdk/resource/api200/storage_pool.rb @@ -83,8 +83,9 @@ def exists? # Sets the storage system # @param [OneviewSDK::StorageSystem] storage_system + # @raise [OneviewSDK::IncompleteResource] if Storage System not found def set_storage_system(storage_system) - raise IncompleteResource, 'Please set the storage system\'s uri attribute!' unless storage_system['uri'] + raise 'Storage System could not be found!' unless storage_system.retrieve! set('storageSystemUri', storage_system['uri']) end end diff --git a/lib/oneview-sdk/resource/api500/c7000/storage_pool.rb b/lib/oneview-sdk/resource/api500/c7000/storage_pool.rb index a8ff0b584..53ce5bff4 100644 --- a/lib/oneview-sdk/resource/api500/c7000/storage_pool.rb +++ b/lib/oneview-sdk/resource/api500/c7000/storage_pool.rb @@ -96,6 +96,14 @@ def request_refresh update refresh end + + # Sets the storage system + # @param [OneviewSDK::StorageSystem] storage_system + # @raise [OneviewSDK::IncompleteResource] if Storage System not found + def set_storage_system(storage_system) + raise 'Storage System could not be found!' unless storage_system.retrieve! + set('storageSystemUri', storage_system['uri']) + end end end end diff --git a/lib/oneview-sdk/version.rb b/lib/oneview-sdk/version.rb index b39a4f5e7..ebd8f7466 100644 --- a/lib/oneview-sdk/version.rb +++ b/lib/oneview-sdk/version.rb @@ -11,5 +11,5 @@ # Gem version defined here module OneviewSDK - VERSION = '5.1.1'.freeze + VERSION = '5.1.2'.freeze end diff --git a/spec/unit/resource/api200/storage_pool_spec.rb b/spec/unit/resource/api200/storage_pool_spec.rb index 3f11fadd4..f262d2949 100644 --- a/spec/unit/resource/api200/storage_pool_spec.rb +++ b/spec/unit/resource/api200/storage_pool_spec.rb @@ -31,19 +31,29 @@ end describe '#set_storage_system' do + let(:storage_system) { OneviewSDK::StorageSystem.new(@client_200, uri: '/rest/fake') } + it 'sets the storageSystemUri value' do + expect(storage_system).to receive(:retrieve!).and_return(true) item = OneviewSDK::StoragePool.new(@client_200) - item.set_storage_system(OneviewSDK::StorageSystem.new(@client_200, uri: '/rest/fake')) + item.set_storage_system(storage_system) expect(item['storageSystemUri']).to eq('/rest/fake') end it 'requires a storage_system with a uri' do + expect(storage_system).to receive(:retrieve!).and_return(false) item = OneviewSDK::StoragePool.new(@client_200) - expect { item.set_storage_system(OneviewSDK::StorageSystem.new(@client_200)) }.to raise_error(OneviewSDK::IncompleteResource, /Please set/) + expect { item.set_storage_system(storage_system) }.to raise_error(/not be found/) end end describe '#retrieve!' do + let(:storage_system) { OneviewSDK::StorageSystem.new(@client_200, uri: '/rest/fake') } + + before do + allow(storage_system).to receive(:retrieve!).and_return(true) + end + it 'requires the name attribute to be set' do storage_pool = OneviewSDK::StoragePool.new(@client_200) expect { storage_pool.retrieve! }.to raise_error(OneviewSDK::IncompleteResource, /Must set resource name or uri before trying to retrieve!/) @@ -59,14 +69,14 @@ it 'uses the uri attribute when the name is not set' do res = OneviewSDK::StoragePool.new(@client_200, uri: '/rest/fake') - res.set_storage_system(OneviewSDK::StorageSystem.new(@client_200, uri: '/rest/fake')) + res.set_storage_system(storage_system) expect(OneviewSDK::StoragePool).to receive(:find_by).with(@client_200, uri: res['uri'], storageSystemUri: '/rest/fake').and_return([]) expect(res.exists?).to eq(false) end it 'sets the data if the resource is found' do res = OneviewSDK::StoragePool.new(@client_200, name: 'ResourceName') - res.set_storage_system(OneviewSDK::StorageSystem.new(@client_200, uri: '/rest/fake')) + res.set_storage_system(storage_system) allow(OneviewSDK::StoragePool).to receive(:find_by).and_return([ OneviewSDK::StoragePool.new(@client_200, res.data.merge(uri: '/rest/fake', storageSystemUri: '/rest/fake', description: 'Blah')) ]) @@ -78,12 +88,18 @@ it 'returns false when the resource is not found' do allow(OneviewSDK::StoragePool).to receive(:find_by).and_return([]) res = OneviewSDK::StoragePool.new(@client_200, name: 'ResourceName') - res.set_storage_system(OneviewSDK::StorageSystem.new(@client_200, uri: '/rest/fake')) + res.set_storage_system(storage_system) expect(res.retrieve!).to eq(false) end end describe '#exists?' do + let(:storage_system) { OneviewSDK::StorageSystem.new(@client_200, uri: '/rest/fake') } + + before do + allow(storage_system).to receive(:retrieve!).and_return(true) + end + it 'requires the name attribute to be set' do storage_pool = OneviewSDK::StoragePool.new(@client_200) expect { storage_pool.exists? }.to raise_error(OneviewSDK::IncompleteResource, /Must set resource name or uri before trying to exists?/) @@ -96,21 +112,21 @@ it 'uses the uri attribute when the name is not set' do res = OneviewSDK::StoragePool.new(@client_200, uri: '/rest/fake') - res.set_storage_system(OneviewSDK::StorageSystem.new(@client_200, uri: '/rest/fake')) + res.set_storage_system(storage_system) expect(OneviewSDK::StoragePool).to receive(:find_by).with(@client_200, storageSystemUri: '/rest/fake', uri: res['uri']).and_return([]) expect(res.exists?).to eq(false) end it 'returns true when the resource is found' do res = OneviewSDK::StoragePool.new(@client_200, name: 'ResourceName') - res.set_storage_system(OneviewSDK::StorageSystem.new(@client_200, uri: '/rest/fake')) + res.set_storage_system(storage_system) expect(OneviewSDK::StoragePool).to receive(:find_by).with(@client_200, name: res['name'], storageSystemUri: '/rest/fake').and_return([res]) expect(res.exists?).to eq(true) end it 'returns false when the resource is not found' do res = OneviewSDK::StoragePool.new(@client_200, uri: '/rest/fake') - res.set_storage_system(OneviewSDK::StorageSystem.new(@client_200, uri: '/rest/fake')) + res.set_storage_system(storage_system) expect(OneviewSDK::StoragePool).to receive(:find_by).with(@client_200, uri: res['uri'], storageSystemUri: '/rest/fake').and_return([]) expect(res.exists?).to eq(false) end diff --git a/spec/unit/resource/api300/c7000/storage_pool_spec.rb b/spec/unit/resource/api300/c7000/storage_pool_spec.rb index c23569a7a..081b1d12c 100644 --- a/spec/unit/resource/api300/c7000/storage_pool_spec.rb +++ b/spec/unit/resource/api300/c7000/storage_pool_spec.rb @@ -6,142 +6,4 @@ it 'inherits from API200' do expect(described_class).to be < OneviewSDK::API200::StoragePool end - - describe '#initialize' do - it 'sets the defaults correctly' do - pool = OneviewSDK::API300::C7000::StoragePool.new(@client_300) - expect(pool['type']).to eq('StoragePoolV2') - end - end - - describe '#add' do - it 'Should support add' do - pool = OneviewSDK::API300::C7000::StoragePool.new(@client_300, name: 'StoragePool_1') - expect(@client_300).to receive(:rest_post).with( - '/rest/storage-pools', - { 'body' => { 'name' => 'StoragePool_1', 'type' => 'StoragePoolV2' } }, - 300 - ).and_return(FakeResponse.new({})) - pool.add - end - end - - describe '#remove' do - it 'Should support remove' do - pool = OneviewSDK::API300::C7000::StoragePool.new(@client_300, uri: '/rest/storage-pools/100') - expect(@client_300).to receive(:rest_delete).with('/rest/storage-pools/100', {}, 300).and_return(FakeResponse.new({})) - pool.remove - end - end - - describe '#set_storage_system' do - it 'sets the storageSystemUri value' do - item = OneviewSDK::API300::C7000::StoragePool.new(@client_300) - item.set_storage_system(OneviewSDK::API300::C7000::StorageSystem.new(@client_300, uri: '/rest/fake')) - expect(item['storageSystemUri']).to eq('/rest/fake') - end - - it 'requires a storage_system with a uri' do - item = OneviewSDK::API300::C7000::StoragePool.new(@client_300) - expect { item.set_storage_system(OneviewSDK::API300::C7000::StorageSystem.new(@client_300)) } - .to raise_error(OneviewSDK::IncompleteResource, /Please set/) - end - end - - describe '#retrieve!' do - it 'requires the name attribute to be set' do - storage_pool = OneviewSDK::API300::C7000::StoragePool.new(@client_300) - expect { storage_pool.retrieve! }.to raise_error(OneviewSDK::IncompleteResource, /Must set resource name or uri before trying to retrieve!/) - end - - it 'requires the storageSystemUri attribute to be set' do - storage_pool = OneviewSDK::API300::C7000::StoragePool.new(@client_300, name: 'StoragePoolName') - expect { storage_pool.retrieve! }.to raise_error( - OneviewSDK::IncompleteResource, - /Must set resource storageSystemUri before trying to retrieve!/ - ) - end - - it 'uses the uri attribute when the name is not set' do - res = OneviewSDK::API300::C7000::StoragePool.new(@client_300, uri: '/rest/fake') - res.set_storage_system(OneviewSDK::API300::C7000::StorageSystem.new(@client_300, uri: '/rest/fake')) - expect(OneviewSDK::API300::C7000::StoragePool).to receive(:find_by).with(@client_300, uri: res['uri'], storageSystemUri: '/rest/fake') - .and_return([]) - expect(res.exists?).to eq(false) - end - - it 'sets the data if the resource is found' do - res = OneviewSDK::API300::C7000::StoragePool.new(@client_300, name: 'ResourceName') - res.set_storage_system(OneviewSDK::API300::C7000::StorageSystem.new(@client_300, uri: '/rest/fake')) - allow(OneviewSDK::API300::C7000::StoragePool).to receive(:find_by).and_return([ - OneviewSDK::API300::C7000::StoragePool.new( - @client_300, - res.data.merge(uri: '/rest/fake', storageSystemUri: '/rest/fake', description: 'Blah') - ) - ]) - res.retrieve! - expect(res['uri']).to eq('/rest/fake') - expect(res['description']).to eq('Blah') - end - - it 'returns false when the resource is not found' do - allow(OneviewSDK::API300::C7000::StoragePool).to receive(:find_by).and_return([]) - res = OneviewSDK::API300::C7000::StoragePool.new(@client_300, name: 'ResourceName') - res.set_storage_system(OneviewSDK::API300::C7000::StorageSystem.new(@client_300, uri: '/rest/fake')) - expect(res.retrieve!).to eq(false) - end - end - - describe '#exists?' do - it 'requires the name attribute to be set' do - storage_pool = OneviewSDK::API300::C7000::StoragePool.new(@client_300) - expect { storage_pool.exists? }.to raise_error(OneviewSDK::IncompleteResource, /Must set resource name or uri before trying to exists?/) - end - - it 'requires the storageSystemUri attribute to be set' do - storage_pool = OneviewSDK::API300::C7000::StoragePool.new(@client_300, name: 'StoragePoolName') - expect { storage_pool.exists? }.to raise_error(OneviewSDK::IncompleteResource, /Must set resource storageSystemUri before trying to exists?/) - end - - it 'uses the uri attribute when the name is not set' do - res = OneviewSDK::API300::C7000::StoragePool.new(@client_300, uri: '/rest/fake') - res.set_storage_system(OneviewSDK::API300::C7000::StorageSystem.new(@client_300, uri: '/rest/fake')) - expect(OneviewSDK::API300::C7000::StoragePool).to receive(:find_by).with(@client_300, storageSystemUri: '/rest/fake', uri: res['uri']) - .and_return([]) - expect(res.exists?).to eq(false) - end - - it 'returns true when the resource is found' do - res = OneviewSDK::API300::C7000::StoragePool.new(@client_300, name: 'ResourceName') - res.set_storage_system(OneviewSDK::API300::C7000::StorageSystem.new(@client_300, uri: '/rest/fake')) - expect(OneviewSDK::API300::C7000::StoragePool).to receive(:find_by).with(@client_300, name: res['name'], storageSystemUri: '/rest/fake') - .and_return([res]) - expect(res.exists?).to eq(true) - end - - it 'returns false when the resource is not found' do - res = OneviewSDK::API300::C7000::StoragePool.new(@client_300, uri: '/rest/fake') - res.set_storage_system(OneviewSDK::API300::C7000::StorageSystem.new(@client_300, uri: '/rest/fake')) - expect(OneviewSDK::API300::C7000::StoragePool).to receive(:find_by).with(@client_300, uri: res['uri'], storageSystemUri: '/rest/fake') - .and_return([]) - expect(res.exists?).to eq(false) - end - end - - describe 'undefined methods' do - it 'does not allow the create action' do - pool = OneviewSDK::API300::C7000::StoragePool.new(@client_300) - expect { pool.create }.to raise_error(/The method #create is unavailable for this resource/) - end - - it 'does not allow the update action' do - storage_pool = OneviewSDK::API300::C7000::StoragePool.new(@client_300) - expect { storage_pool.update }.to raise_error(OneviewSDK::MethodUnavailable, /The method #update is unavailable for this resource/) - end - - it 'does not allow the delete action' do - pool = OneviewSDK::API300::C7000::StoragePool.new(@client_300) - expect { pool.delete }.to raise_error(/The method #delete is unavailable for this resource/) - end - end end diff --git a/spec/unit/resource/api300/synergy/storage_pool_spec.rb b/spec/unit/resource/api300/synergy/storage_pool_spec.rb index e0cba80b5..e5a060ba0 100644 --- a/spec/unit/resource/api300/synergy/storage_pool_spec.rb +++ b/spec/unit/resource/api300/synergy/storage_pool_spec.rb @@ -6,142 +6,4 @@ it 'inherits from API200' do expect(described_class).to be < OneviewSDK::API200::StoragePool end - - describe '#initialize' do - it 'sets the defaults correctly' do - pool = OneviewSDK::API300::Synergy::StoragePool.new(@client_300) - expect(pool['type']).to eq('StoragePoolV2') - end - end - - describe '#add' do - it 'Should support add' do - pool = OneviewSDK::API300::Synergy::StoragePool.new(@client_300, name: 'StoragePool_1') - expect(@client_300).to receive(:rest_post).with( - '/rest/storage-pools', - { 'body' => { 'name' => 'StoragePool_1', 'type' => 'StoragePoolV2' } }, - 300 - ).and_return(FakeResponse.new({})) - pool.add - end - end - - describe '#remove' do - it 'Should support remove' do - pool = OneviewSDK::API300::Synergy::StoragePool.new(@client_300, uri: '/rest/storage-pools/100') - expect(@client_300).to receive(:rest_delete).with('/rest/storage-pools/100', {}, 300).and_return(FakeResponse.new({})) - pool.remove - end - end - - describe '#set_storage_system' do - it 'sets the storageSystemUri value' do - item = OneviewSDK::API300::Synergy::StoragePool.new(@client_300) - item.set_storage_system(OneviewSDK::API300::Synergy::StorageSystem.new(@client_300, uri: '/rest/fake')) - expect(item['storageSystemUri']).to eq('/rest/fake') - end - - it 'requires a storage_system with a uri' do - item = OneviewSDK::API300::Synergy::StoragePool.new(@client_300) - expect { item.set_storage_system(OneviewSDK::API300::Synergy::StorageSystem.new(@client_300)) } - .to raise_error(OneviewSDK::IncompleteResource, /Please set/) - end - end - - describe '#retrieve!' do - it 'requires the name attribute to be set' do - storage_pool = OneviewSDK::API300::Synergy::StoragePool.new(@client_300) - expect { storage_pool.retrieve! }.to raise_error(OneviewSDK::IncompleteResource, /Must set resource name or uri before trying to retrieve!/) - end - - it 'requires the storageSystemUri attribute to be set' do - storage_pool = OneviewSDK::API300::Synergy::StoragePool.new(@client_300, name: 'StoragePoolName') - expect { storage_pool.retrieve! }.to raise_error( - OneviewSDK::IncompleteResource, - /Must set resource storageSystemUri before trying to retrieve!/ - ) - end - - it 'uses the uri attribute when the name is not set' do - res = OneviewSDK::API300::Synergy::StoragePool.new(@client_300, uri: '/rest/fake') - res.set_storage_system(OneviewSDK::API300::Synergy::StorageSystem.new(@client_300, uri: '/rest/fake')) - expect(OneviewSDK::API300::Synergy::StoragePool).to receive(:find_by).with(@client_300, uri: res['uri'], storageSystemUri: '/rest/fake') - .and_return([]) - expect(res.exists?).to eq(false) - end - - it 'sets the data if the resource is found' do - res = OneviewSDK::API300::Synergy::StoragePool.new(@client_300, name: 'ResourceName') - res.set_storage_system(OneviewSDK::API300::Synergy::StorageSystem.new(@client_300, uri: '/rest/fake')) - allow(OneviewSDK::API300::Synergy::StoragePool).to receive(:find_by).and_return([ - OneviewSDK::API300::Synergy::StoragePool.new( - @client_300, - res.data.merge(uri: '/rest/fake', storageSystemUri: '/rest/fake', description: 'Blah') - ) - ]) - res.retrieve! - expect(res['uri']).to eq('/rest/fake') - expect(res['description']).to eq('Blah') - end - - it 'returns false when the resource is not found' do - allow(OneviewSDK::API300::Synergy::StoragePool).to receive(:find_by).and_return([]) - res = OneviewSDK::API300::Synergy::StoragePool.new(@client_300, name: 'ResourceName') - res.set_storage_system(OneviewSDK::API300::Synergy::StorageSystem.new(@client_300, uri: '/rest/fake')) - expect(res.retrieve!).to eq(false) - end - end - - describe '#exists?' do - it 'requires the name attribute to be set' do - storage_pool = OneviewSDK::API300::Synergy::StoragePool.new(@client_300) - expect { storage_pool.exists? }.to raise_error(OneviewSDK::IncompleteResource, /Must set resource name or uri before trying to exists?/) - end - - it 'requires the storageSystemUri attribute to be set' do - storage_pool = OneviewSDK::API300::Synergy::StoragePool.new(@client_300, name: 'StoragePoolName') - expect { storage_pool.exists? }.to raise_error(OneviewSDK::IncompleteResource, /Must set resource storageSystemUri before trying to exists?/) - end - - it 'uses the uri attribute when the name is not set' do - res = OneviewSDK::API300::Synergy::StoragePool.new(@client_300, uri: '/rest/fake') - res.set_storage_system(OneviewSDK::API300::Synergy::StorageSystem.new(@client_300, uri: '/rest/fake')) - expect(OneviewSDK::API300::Synergy::StoragePool).to receive(:find_by).with(@client_300, storageSystemUri: '/rest/fake', uri: res['uri']) - .and_return([]) - expect(res.exists?).to eq(false) - end - - it 'returns true when the resource is found' do - res = OneviewSDK::API300::Synergy::StoragePool.new(@client_300, name: 'ResourceName') - res.set_storage_system(OneviewSDK::API300::Synergy::StorageSystem.new(@client_300, uri: '/rest/fake')) - expect(OneviewSDK::API300::Synergy::StoragePool).to receive(:find_by).with(@client_300, name: res['name'], storageSystemUri: '/rest/fake') - .and_return([res]) - expect(res.exists?).to eq(true) - end - - it 'returns false when the resource is not found' do - res = OneviewSDK::API300::Synergy::StoragePool.new(@client_300, uri: '/rest/fake') - res.set_storage_system(OneviewSDK::API300::Synergy::StorageSystem.new(@client_300, uri: '/rest/fake')) - expect(OneviewSDK::API300::Synergy::StoragePool).to receive(:find_by).with(@client_300, uri: res['uri'], storageSystemUri: '/rest/fake') - .and_return([]) - expect(res.exists?).to eq(false) - end - end - - describe 'undefined methods' do - it 'does not allow the create action' do - pool = OneviewSDK::API300::Synergy::StoragePool.new(@client_300) - expect { pool.create }.to raise_error(/The method #create is unavailable for this resource/) - end - - it 'does not allow the update action' do - storage_pool = OneviewSDK::API300::Synergy::StoragePool.new(@client_300) - expect { storage_pool.update }.to raise_error(OneviewSDK::MethodUnavailable, /The method #update is unavailable for this resource/) - end - - it 'does not allow the delete action' do - pool = OneviewSDK::API300::Synergy::StoragePool.new(@client_300) - expect { pool.delete }.to raise_error(/The method #delete is unavailable for this resource/) - end - end end diff --git a/spec/unit/resource/api500/c7000/storage_pool_spec.rb b/spec/unit/resource/api500/c7000/storage_pool_spec.rb index bf2a11056..8e25010e7 100644 --- a/spec/unit/resource/api500/c7000/storage_pool_spec.rb +++ b/spec/unit/resource/api500/c7000/storage_pool_spec.rb @@ -126,4 +126,20 @@ target.exists? end end + + describe '#set_storage_system' do + it 'should set the storageSystemUri' do + storage_system = OneviewSDK::API500::C7000::StorageSystem.new(@client_500, uri: '/storage-sytems/1') + expect(storage_system).to receive(:retrieve!).and_return(true) + expect(target['storageSystemUri']).to eq(nil) + target.set_storage_system(storage_system) + expect(target['storageSystemUri']).to eq('/storage-sytems/1') + end + + it 'should throw error when StorageSystem URI is not present' do + storage_system = OneviewSDK::API500::C7000::StorageSystem.new(@client_500) + expect(storage_system).to receive(:retrieve!).and_return(false) + expect { target.set_storage_system(storage_system) }.to raise_error(/not be found/) + end + end end