Skip to content

Commit

Permalink
Merge pull request #91 from rknaus/develop_ethernet_features
Browse files Browse the repository at this point in the history
add ethernet speed and lacp port priority support
  • Loading branch information
devrobo committed Sep 6, 2016
2 parents b3355e8 + aa76a93 commit 5cac05b
Show file tree
Hide file tree
Showing 7 changed files with 141 additions and 5 deletions.
14 changes: 14 additions & 0 deletions lib/puppet/provider/eos_ethernet/default.rb
Expand Up @@ -59,6 +59,8 @@ def self.instances
provider_hash[:description] = attrs[:description]
provider_hash[:flowcontrol_send] = attrs[:flowcontrol_send].to_sym
provider_hash[:flowcontrol_receive] = attrs[:flowcontrol_receive].to_sym
provider_hash[:speed] = attrs[:speed]
provider_hash[:lacp_priority] = attrs[:lacp_priority]
arry << new(provider_hash)
end
end
Expand All @@ -72,6 +74,8 @@ def create
if resource[:flowcontrol_send]
self.flowcontrol_receive = resource[:flowcontrol_receive] \
if resource[:flowcontrol_receive]
self.speed = resource[:speed] if resource[:speed]
self.lacp_priority = resource[:lacp_priority] if resource[:lacp_priority]
end

def destroy
Expand Down Expand Up @@ -99,4 +103,14 @@ def flowcontrol_receive=(val)
node.api('interfaces').set_flowcontrol_receive(resource[:name], value: val)
@property_hash[:flowcontrol_receive] = val
end

def speed=(val)
node.api('interfaces').set_speed(resource[:name], value: val)
@property_hash[:speed] = val
end

def lacp_priority=(val)
node.api('interfaces').set_lacp_priority(resource[:name], value: val)
@property_hash[:lacp_priority] = val
end
end
50 changes: 50 additions & 0 deletions lib/puppet/type/eos_ethernet.rb
Expand Up @@ -44,6 +44,8 @@
description => 'To switch2 Ethernet 1/3',
flowcontrol_send => on,
flowcontrol_receive => on,
speed => 'forced 40gfull',
lacp_priority => 0,
}
EOS

Expand Down Expand Up @@ -106,4 +108,52 @@
EOS
newvalues(:on, :off)
end

newproperty(:speed) do
desc <<-EOS
This property configures the interface speed for the specified Ethernet
interface. Valid values for speed are:
* 'default'
* '100full'
* '10full'
* 'auto'
* 'auto 100full'
* 'auto 10full'
* 'auto 40gfull'
* 'forced 10000full'
* 'forced 1000full'
* 'forced 1000half'
* 'forced 100full'
* 'forced 100gfull'
* 'forced 100half'
* 'forced 10full'
* 'forced 10half'
* 'forced 40gfull'
* 'sfp-1000baset auto 100full'
EOS
newvalues('default', '100full', '10full', 'auto', 'auto 100full',
'auto 10full', 'auto 40gfull', 'forced 10000full',
'forced 1000full', 'forced 1000half', 'forced 100full',
'forced 100gfull', 'forced 100half', 'forced 10full',
'forced 10half', 'forced 40gfull', 'sfp-1000baset auto 100full')
end

newproperty(:lacp_priority) do
desc <<-EOS
The lacp_priority property specifies the lacp port priority associated
with the ethernet interface. The configured value must be an integer in
the range of 0 to 65535.
The default value for the lacp_priority setting is 32768
EOS

munge { |value| Integer(value) }

validate do |value|
unless value.to_i.between?(0, 65_535)
fail "value #{value.inspect} must be between 0 and 65535"
end
end
end
end
3 changes: 2 additions & 1 deletion spec/fixtures/ethernet.json
Expand Up @@ -4,6 +4,7 @@
"description": "test interface",
"shutdown": false,
"flowcontrol_send": "on",
"flowcontrol_receive": "on"
"flowcontrol_receive": "on",
"speed": "forced 40gfull"
}
}
6 changes: 5 additions & 1 deletion spec/support/shared_examples_for_types.rb
Expand Up @@ -311,7 +311,11 @@
RSpec.shared_examples 'speed property' do
include_examples 'property'

%w(auto 1g 10g 40g 56g 100g 100m 10m).each do |val|
[:default, '100full', '10full', 'auto', 'auto 100full', 'auto 10full',
'auto 40gfull', 'forced 10000full', 'forced 1000full', 'forced 1000half',
'forced 100full', 'forced 100gfull', 'forced 100half', 'forced 10full',
'forced 10half', 'forced 40gfull',
'sfp-1000baset auto 100full'].each do |val|
it "accepts #{val.inspect}" do
type[attribute] = val
end
Expand Down
44 changes: 42 additions & 2 deletions spec/unit/puppet/provider/eos_ethernet/default_spec.rb
Expand Up @@ -42,6 +42,8 @@
enable: :true,
flowcontrol_send: :on,
flowcontrol_receive: :on,
speed: 'forced 40gfull',
lacp_priority: 0,
provider: described_class.name
}
Puppet::Type.type(:eos_ethernet).new(resource_hash)
Expand Down Expand Up @@ -89,7 +91,9 @@ def ethernet
description: 'test interface',
enable: :true,
flowcontrol_send: :on,
flowcontrol_receive: :on
flowcontrol_receive: :on,
speed: 'forced 40gfull',
lacp_priority: 0
end
end

Expand All @@ -110,6 +114,8 @@ def ethernet
expect(rsrc.provider.enable).to eq(:absent)
expect(rsrc.provider.flowcontrol_send).to eq(:absent)
expect(rsrc.provider.flowcontrol_receive).to eq(:absent)
expect(rsrc.provider.speed).to eq(:absent)
expect(rsrc.provider.lacp_priority).to eq(:absent)
end
end

Expand All @@ -120,6 +126,8 @@ def ethernet
expect(resources['Ethernet1'].provider.enable).to eq :true
expect(resources['Ethernet1'].provider.flowcontrol_send).to eq(:on)
expect(resources['Ethernet1'].provider.flowcontrol_receive).to eq(:on)
expect(resources['Ethernet1'].provider.speed).to eq('forced 40gfull')
expect(resources['Ethernet1'].provider.lacp_priority).to eq(0)
end

it 'does not set the provider instance of the unmanaged resource' do
Expand All @@ -129,6 +137,8 @@ def ethernet
expect(resources['Ethernet2'].provider.flowcontrol_send).to eq(:absent)
expect(resources['Ethernet2'].provider.flowcontrol_receive).to \
eq(:absent)
expect(resources['Ethernet2'].provider.speed).to eq(:absent)
expect(resources['Ethernet2'].provider.lacp_priority).to eq(:absent)
end
end
end
Expand All @@ -143,7 +153,9 @@ def ethernet
set_shutdown: true,
set_description: true,
set_flowcontrol_send: true,
set_flowcontrol_receive: true
set_flowcontrol_receive: true,
set_speed: true,
set_lacp_priority: true,
)
end

Expand All @@ -166,6 +178,16 @@ def ethernet
provider.create
expect(provider.flowcontrol_receive).to eq(:on)
end

it 'sets speed on the resource' do
provider.create
expect(provider.speed).to eq(:'forced 40gfull')
end

it 'sets lacp priority on the resource' do
provider.create
expect(provider.lacp_priority).to eq(0)
end
end

describe '#destroy' do
Expand Down Expand Up @@ -221,5 +243,23 @@ def ethernet
end
end
end

describe '#speed=(value)' do
it 'updates speed in the provider' do
expect(api).to receive(:set_speed)
.with(resource[:name], value: 'auto')
provider.speed = 'auto'
expect(provider.speed).to eq('auto')
end
end

describe '#lacp_priority=(value)' do
it 'updates lacp priority in the provider' do
expect(api).to receive(:set_lacp_priority)
.with(resource[:name], value: 65000)
provider.lacp_priority = 65000
expect(provider.lacp_priority).to eq(65000)
end
end
end
end
4 changes: 3 additions & 1 deletion spec/unit/puppet/provider/eos_ethernet/fixture_ethernet.yaml
Expand Up @@ -4,5 +4,7 @@ Ethernet1:
:description: test interface
:shutdown: false
:flowcontrol_send: 'on'
:flowcontrol_receive: 'on'
:flowcontrol_receive: 'on'
:speed: forced 40gfull
:lacp_priority: 0

25 changes: 25 additions & 0 deletions spec/unit/puppet/type/eos_ethernet_spec.rb
Expand Up @@ -84,4 +84,29 @@
include_examples 'accepts values', [:on, :off]
include_examples 'rejected parameter values'
end

describe 'speed' do
let(:attribute) { :speed }
subject { described_class.attrclass(attribute) }

include_examples 'property'
include_examples '#doc Documentation'
include_examples 'accepts values', ['default', '100full', '10full', 'auto',
'auto 100full', 'auto 10full', 'auto 40gfull', 'forced 10000full',
'forced 1000full', 'forced 1000half', 'forced 100full',
'forced 100gfull', 'forced 100half', 'forced 10full', 'forced 10half',
'forced 40gfull', 'sfp-1000baset auto 100full']
include_examples 'rejects values', [0, 15, '0', '15', { two: :three },
:'abc']
end

describe 'lacp_priority' do
let(:attribute) { :lacp_priority }
subject { described_class.attrclass(attribute) }

include_examples 'property'
include_examples '#doc Documentation'
include_examples 'accepts values without munging', [0, 65535]
include_examples 'rejects values', [[-1], -1, 65536, { two: :three }]
end
end

0 comments on commit 5cac05b

Please sign in to comment.