Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#141 Fixed Synergy LIG #add_interconnect #143

Merged
merged 2 commits into from
Jan 27, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
- Golden Image
- OS Volumes
- Plan Scripts
- Fixes for API300::Synergy::LogicalInterconnectGroup. See issue [#141](https://github.com/HewlettPackard/oneview-sdk-ruby/issues/141)

# v3.1.0
Added full support to OneView Rest API version 300 for the hardware variants C7000 and Synergy to the already existing features:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ def initialize(client, params = {}, api_ver = nil)
@data['interconnectBaySet'] ||= 1
@data['interconnectMapTemplate'] ||= {}
@data['interconnectMapTemplate']['interconnectMapEntryTemplates'] ||= []
@data['redundancyType'] ||= 'Redundant'
end

# Get the logical interconnect group default settings
Expand Down Expand Up @@ -66,52 +67,52 @@ def add_internal_network(network)
# Adds an interconnect
# @param [Fixnum] bay Bay number
# @param [String] type Interconnect type
# @param [String, OneviewSDK::LogicalDownlink] logical_downlink Name of logical downlink or LogicalDownlink object
# @return [Hash] interconnectMapEntryTemplates entry that was added
# @raise [StandardError] if a invalid type is given then raises an error
def add_interconnect(bay, type, logical_downlink = nil, enclosure_index = 1)
parse_interconnect_map_template(bay, enclosure_index)
@data['interconnectMapTemplate']['interconnectMapEntryTemplates'].each do |entry|
# Default value in case of no specified logical downlink
entry['logicalDownlinkUri'] = nil
if logical_downlink
ld = OneviewSDK::API300::Synergy::LogicalDownlink.find_by(@client, name: logical_downlink).first['uri']
entry['logicalDownlinkUri'] = ld
end
entry['logicalLocation']['locationEntries'].each do |location|
if location['type'] == 'Bay' && location['relativeValue'] == bay
entry['permittedInterconnectTypeUri'] = OneviewSDK::API300::Synergy::Interconnect.get_type(@client, type)['uri']
end
def add_interconnect(bay, type, logical_downlink = nil, enclosure_index = nil)
enclosure_index ||= type.include?('Virtual Connect SE 16Gb FC Module') ? -1 : 1
entry = parse_interconnect_map_template(bay, enclosure_index)
entry['logicalDownlinkUri'] ||= nil # Default value in case of no specified logical downlink
if logical_downlink
ld = logical_downlink if logical_downlink.class < OneviewSDK::Resource
ld ||= OneviewSDK::API300::Synergy::LogicalDownlink.find_by(@client, name: logical_downlink).first
entry['logicalDownlinkUri'] = ld['uri']
end
entry['logicalLocation']['locationEntries'].each do |location|
if location['type'] == 'Bay' && location['relativeValue'] == bay
entry['permittedInterconnectTypeUri'] = OneviewSDK::API300::Synergy::Interconnect.get_type(@client, type)['uri']
end
end
entry
rescue StandardError
raise 'Interconnect type or Logical Downlink not found!'
end

private

# Parse interconnect map template structure for specified bay
# @return the entry that was added (or already existed)
def parse_interconnect_map_template(bay, enclosure_index)
entry = {
'logicalLocation' => {
'locationEntries' => [
{ 'relativeValue' => bay, 'type' => 'Bay' },
{ 'relativeValue' => 1, 'type' => 'Enclosure' }
{ 'relativeValue' => enclosure_index, 'type' => 'Enclosure' }
]
},
'enclosureIndex' => enclosure_index,
'permittedInterconnectTypeUri' => nil
}

# If no interconnect map entry templates exist yet, add the specified entry
first_run = @data['interconnectMapTemplate']['interconnectMapEntryTemplates'].empty?
return @data['interconnectMapTemplate']['interconnectMapEntryTemplates'] << entry if first_run

# Verifies if the bay specified in the entry is already added, otherwise adds it
@data['interconnectMapTemplate']['interconnectMapEntryTemplates'].each do |single_entry|
single_entry['logicalLocation']['locationEntries'].each do |location|
return true if location['type'] == 'Bay' && location['relativeValue'] == bay
end
# Add the interconnect if it is not already specified
@data['interconnectMapTemplate']['interconnectMapEntryTemplates'].each do |temp|
same_bay = temp['logicalLocation']['locationEntries'].include? entry['logicalLocation']['locationEntries'][0]
same_enc = temp['logicalLocation']['locationEntries'].include? entry['logicalLocation']['locationEntries'][1]
return temp if same_bay && same_enc
end
@data['interconnectMapTemplate']['interconnectMapEntryTemplates'] << entry
entry
end
end
end
Expand Down
10 changes: 5 additions & 5 deletions spec/unit/resource/api200/logical_interconnect_group_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

describe '#initialize' do
it 'sets the defaults correctly' do
item = OneviewSDK::LogicalInterconnectGroup.new(@client)
item = described_class.new(@client)
expect(item['enclosureType']).to eq('C7000')
expect(item['state']).to eq('Active')
expect(item['uplinkSets']).to eq([])
Expand All @@ -18,7 +18,7 @@

describe '#add_interconnect' do
before :each do
@item = OneviewSDK::LogicalInterconnectGroup.new(@client)
@item = described_class.new(@client)
@type = 'HP VC FlexFabric-20/40 F8 Module'
end

Expand All @@ -40,7 +40,7 @@

describe '#add_uplink_set' do
it 'adds it to the \'uplinkSets\' data attribute' do
item = OneviewSDK::LogicalInterconnectGroup.new(@client)
item = described_class.new(@client)
uplink = OneviewSDK::UplinkSet.new(@client)
item.add_uplink_set(uplink)
expect(item['uplinkSets'].size).to eq(1)
Expand All @@ -50,7 +50,7 @@

describe '#get_default_settings' do
it 'should get the default settings' do
item = OneviewSDK::LogicalInterconnectGroup.new(@client, uri: '/rest/fake')
item = described_class.new(@client, uri: '/rest/fake')
expect(@client).to receive(:rest_get).with('/rest/logical-interconnect-groups/defaultSettings', item.api_version)
.and_return(FakeResponse.new)
expect(item.get_default_settings).to be
Expand All @@ -59,7 +59,7 @@

describe '#get_settings' do
it 'should get the settings' do
item = OneviewSDK::LogicalInterconnectGroup.new(@client, uri: '/rest/fake')
item = described_class.new(@client, uri: '/rest/fake')
expect(@client).to receive(:rest_get).with('/rest/fake/settings', item.api_version)
.and_return(FakeResponse.new)
expect(item.get_settings).to be
Expand Down
Original file line number Diff line number Diff line change
@@ -1,45 +1,47 @@
require 'spec_helper'

klass = OneviewSDK::API300::Synergy::LogicalInterconnectGroup
RSpec.describe klass do
RSpec.describe OneviewSDK::API300::Synergy::LogicalInterconnectGroup do
include_context 'shared context'

it 'inherits from API200 and does not inherit from LogicalInterconnectGroup' do
it 'inherits from the base API300::Resource class, not API200::LogicalInterconnectGroup' do
expect(described_class).to be < OneviewSDK::API300::Synergy::Resource
expect(klass).not_to be < OneviewSDK::API300::Synergy::LogicalInterconnectGroup
expect(described_class).not_to be < OneviewSDK::API200::LogicalInterconnectGroup
end

describe '#initialize' do
it 'sets the defaults correctly' do
item = klass.new(@client_300)
item = described_class.new(@client_300)
expect(item['enclosureType']).to eq('SY12000')
expect(item['state']).to eq('Active')
expect(item['uplinkSets']).to eq([])
expect(item['type']).to eq('logical-interconnect-groupV300')
expect(item['interconnectMapTemplate']).to eq('interconnectMapEntryTemplates' => [])
expect(item['interconnectMapTemplate']['interconnectMapEntryTemplates']).to be_empty
expect(item['redundancyType']).to eq('Redundant')
end
end

describe '#add_uplink_set' do
it 'adds it to the \'uplinkSets\' data attribute' do
item = klass.new(@client_300)
item = described_class.new(@client_300)
uplink = OneviewSDK::API300::Synergy::UplinkSet.new(@client_300)
item.add_uplink_set(uplink)
expect(item['uplinkSets'].size).to eq(1)
expect(item['uplinkSets'].first).to eq(uplink.data)
end
end

describe '#settings' do
describe '#get_default_settings' do
it 'gets the default settings' do
expect(@client_300).to receive(:rest_get).with('/rest/logical-interconnect-groups/defaultSettings')
.and_return(FakeResponse.new('Default' => 'Settings'))
expect(klass.get_default_settings(@client_300)).to eq('Default' => 'Settings')
expect(described_class.get_default_settings(@client_300)).to eq('Default' => 'Settings')
end
end

describe '#settings' do
it 'gets the current settings' do
item = klass.new(@client_300, uri: '/rest/fake')
item = described_class.new(@client_300, uri: '/rest/fake')
expect(@client_300).to receive(:rest_get).with('/rest/fake/settings', 300)
.and_return(FakeResponse.new('Current' => 'Settings'))
expect(item.get_settings).to eq('Current' => 'Settings')
Expand All @@ -48,28 +50,65 @@

describe '#add_internal_network' do
it 'adds a network' do
item = klass.new(@client_300)
item = described_class.new(@client_300)
network = OneviewSDK::API300::Synergy::EthernetNetwork.new(@client, uri: '/rest/fake')
expect(item.add_internal_network(network)).to be
expect(item['internalNetworkUris']).to eq(['/rest/fake'])
end
end

describe '#add_interconnect' do
before :each do
@item = described_class.new(@client_300)
@type = 'Virtual Connect SE 40Gb F8 Module for Synergy'
@type2 = 'Virtual Connect SE 16Gb FC Module for Synergy'
@interconnect = { 'uri' => '/rest/fake' }
end
it 'adds a valid interconnect type' do
item = klass.new(@client_300)
type = 'Virtual Connect SE 40Gb F8 Module for Synergy'
logical_downlink = OneviewSDK::API300::Synergy::LogicalDownlink.new(@client_300, name: 'LD')
logical_downlink = OneviewSDK::API300::Synergy::LogicalDownlink.new(@client_300, name: 'LD', uri: '/rest/fake')
allow(OneviewSDK::API300::Synergy::LogicalDownlink).to receive(:find_by).with(anything, name: 'LD')
.and_return([logical_downlink])
logical_downlink['uri'] = '/rest/fake'
allow(OneviewSDK::API300::Synergy::Interconnect).to receive(:get_type).with(anything, type)
.and_return('uri' => '/rest/fake')
item.add_interconnect(1, type, 'LD')
expect(item['interconnectMapTemplate']['interconnectMapEntryTemplates'][0]['permittedInterconnectTypeUri'])
allow(OneviewSDK::API300::Synergy::Interconnect).to receive(:get_type).with(anything, @type)
.and_return(@interconnect)
@item.add_interconnect(1, @type, 'LD')
expect(@item['interconnectMapTemplate']['interconnectMapEntryTemplates'][0]['permittedInterconnectTypeUri'])
.to eq('/rest/fake')
expect(@item['interconnectMapTemplate']['interconnectMapEntryTemplates'][0]['logicalDownlinkUri'])
.to eq('/rest/fake')
end

it 'accepts a LogicalDownlink resource as a parameter' do
logical_downlink = OneviewSDK::API300::Synergy::LogicalDownlink.new(@client_300, name: 'LD', uri: '/rest/fake')
allow(OneviewSDK::API300::Synergy::Interconnect).to receive(:get_type).and_return(@interconnect)
@item.add_interconnect(1, @type, logical_downlink)
expect(@item['interconnectMapTemplate']['interconnectMapEntryTemplates'][0]['permittedInterconnectTypeUri'])
.to eq('/rest/fake')
expect(item['interconnectMapTemplate']['interconnectMapEntryTemplates'][0]['logicalDownlinkUri'])
expect(@item['interconnectMapTemplate']['interconnectMapEntryTemplates'][0]['logicalDownlinkUri'])
.to eq('/rest/fake')
end

it 'only adds an interconnect if it is not already added' do
allow(OneviewSDK::API300::Synergy::Interconnect).to receive(:get_type).and_return(@interconnect)
@item.add_interconnect(1, @type)
@item.add_interconnect(1, @type)
expect(@item['interconnectMapTemplate']['interconnectMapEntryTemplates'].size).to eq(1)
end

it 'adds interconnects with the same bay but different enclosureIndex' do
allow(OneviewSDK::API300::Synergy::Interconnect).to receive(:get_type).and_return(@interconnect)
@item.add_interconnect(1, @type, nil, 1)
@item.add_interconnect(1, @type, nil, -1)
expect(@item['interconnectMapTemplate']['interconnectMapEntryTemplates'].size).to eq(2)
end

it 'sets the correct default enclosureIndex for interconnect types' do
allow(OneviewSDK::API300::Synergy::Interconnect).to receive(:get_type).twice.and_return(@interconnect)
@item.add_interconnect(1, @type)
@item.add_interconnect(1, @type2)
templates = @item['interconnectMapTemplate']['interconnectMapEntryTemplates']
expect(templates.size).to eq(2)
expect(templates[0]['enclosureIndex']).to eq(1)
expect(templates[1]['enclosureIndex']).to eq(-1)
end
end
end