Skip to content

Commit e180d71

Browse files
authored
Merge pull request #905 from ananace/modules-7024
(MODULES-7024) Add 20-octet MAC addresses
2 parents aa13b7a + 3f1ea8d commit e180d71

4 files changed

Lines changed: 20 additions & 1 deletion

File tree

lib/puppet/parser/functions/is_mac_address.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ module Puppet::Parser::Functions
1414
mac = arguments[0]
1515

1616
return true if %r{^[a-f0-9]{1,2}(:[a-f0-9]{1,2}){5}$}i =~ mac
17+
return true if %r{^[a-f0-9]{1,2}(:[a-f0-9]{1,2}){19}$}i =~ mac
1718
return false
1819
end
1920
end

spec/acceptance/is_mac_address_spec.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,20 @@
2929
expect(r.stdout).to match(%r{Notice: output correct})
3030
end
3131
end
32+
33+
pp3 = <<-DOC
34+
$a = '80:00:02:09:fe:80:00:00:00:00:00:00:00:24:65:ff:ff:91:a3:12'
35+
$b = true
36+
$o = is_mac_address($a)
37+
if $o == $b {
38+
notify { 'output correct': }
39+
}
40+
DOC
41+
it 'is_mac_addresss a 20-octet mac' do
42+
apply_manifest(pp3, :catch_failures => true) do |r|
43+
expect(r.stdout).to match(%r{Notice: output correct})
44+
end
45+
end
3246
end
3347
describe 'failure' do
3448
it 'handles improper argument counts'

spec/functions/is_mac_address_spec.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
it { is_expected.to run.with_params([], []).and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) }
77
it { is_expected.to run.with_params('00:a0:1f:12:7f:a0').and_return(true) }
88
it { is_expected.to run.with_params('00:A0:1F:12:7F:A0').and_return(true) }
9+
it { is_expected.to run.with_params('80:00:02:09:fe:80:00:00:00:00:00:00:00:24:65:ff:ff:91:a3:12').and_return(true) }
910
it { is_expected.to run.with_params('00:00:00:00:00:0g').and_return(false) }
1011
it { is_expected.to run.with_params('').and_return(false) }
1112
it { is_expected.to run.with_params('one').and_return(false) }

types/mac.pp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
# A type for a MAC address
2-
type Stdlib::MAC = Pattern[/^([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})$/]
2+
type Stdlib::MAC = Pattern[
3+
/^([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})$/,
4+
/^([0-9A-Fa-f]{2}[:-]){19}([0-9A-Fa-f]{2})$/
5+
]

0 commit comments

Comments
 (0)