Skip to content

Commit

Permalink
Merge pull request #286 from HewlettPackard/enhacement/added_helper_m…
Browse files Browse the repository at this point in the history
…ethod_to_storage_pool

Added helper method to add StorageSystem to StoragePool of API500
  • Loading branch information
ricardogpsf authored Oct 11, 2017
2 parents 234a414 + 7714c70 commit 48f8684
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 287 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
3 changes: 2 additions & 1 deletion lib/oneview-sdk/resource/api200/storage_pool.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions lib/oneview-sdk/resource/api500/c7000/storage_pool.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/oneview-sdk/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@

# Gem version defined here
module OneviewSDK
VERSION = '5.1.1'.freeze
VERSION = '5.1.2'.freeze
end
32 changes: 24 additions & 8 deletions spec/unit/resource/api200/storage_pool_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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!/)
Expand All @@ -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'))
])
Expand All @@ -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?/)
Expand All @@ -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
Expand Down
138 changes: 0 additions & 138 deletions spec/unit/resource/api300/c7000/storage_pool_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Loading

0 comments on commit 48f8684

Please sign in to comment.