Skip to content

Commit

Permalink
added test for erroneous vlan configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
Davide Ferrari committed Mar 27, 2015
1 parent a0ed4c4 commit a3ece2f
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/puppet/provider/network_config/interfaces.rb
Original file line number Diff line number Diff line change
Expand Up @@ -294,8 +294,8 @@ def self.format_file(filename, providers)
stanza << "vlan-raw-device #{provider.options["vlan-raw-device"]}"
else
vlan_range_regex = %r[\d{1,3}|40[0-9][0-5]]
if ! provider.name.match(%r[\A([a-z]+\d+)(?::\d+|\.#{vlan_range_regex})\Z])
raise Puppet::Error, "Interface #{provider.name}: missing vlan-raw-device or wrong VLAN ID in the iface name "
if ! provider.name.match(%r[\A([a-z]+\d+)(?::\d+|\.#{vlan_range_regex})\Z])
raise Puppet::Error, "Interface #{provider.name}: missing vlan-raw-device or wrong VLAN ID in the iface name"
end
end
end
Expand Down
23 changes: 23 additions & 0 deletions spec/unit/provider/network_config/interfaces_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,22 @@ def fixture_data(file)
)
end

let(:vlan10_provider) do
stub('vlan10_provider',
:name => "vlan10",
:ensure => :present,
:onboot => true,
:hotplug => true,
:family => "inet",
:method => "dhcp",
:ipaddress => nil,
:netmask => nil,
:mtu => nil,
:mode => :vlan,
:options => {}
)
end

let(:eth1_4500_provider) do
stub('eth1_4500_provider',
:name => "eth1.4500",
Expand Down Expand Up @@ -341,6 +357,13 @@ def fixture_data(file)
end
end

describe "writing wrong vlanNN iface blocks" do
let(:content) { described_class.format_file('', [vlan10_provider]) }
it "should fail with missing vlan-raw-device" do
expect { content }.to raise_error(Puppet::Error, /Interface vlan10: missing vlan-raw-device or wrong VLAN ID in the iface name/)
end
end

describe "writing the options section" do
let(:content) { described_class.format_file('', [eth1_provider]) }

Expand Down

0 comments on commit a3ece2f

Please sign in to comment.