Skip to content

Commit

Permalink
Merge pull request #186 from saz/use_vmac_vrrp_interface
Browse files Browse the repository at this point in the history
virtual_ipaddress should be on vrrp interface if use_vmac is set
  • Loading branch information
bastelfreak authored Sep 25, 2019
2 parents fb2ca2c + 916f600 commit 5ab0d63
Show file tree
Hide file tree
Showing 2 changed files with 147 additions and 3 deletions.
132 changes: 130 additions & 2 deletions spec/defines/keepalived_vrrp_instance_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -925,10 +925,85 @@
}
end

describe 'with use_vmac' do
describe 'with use_vmac and virtual_ipaddress as string' do
let(:params) do
mandatory_params.merge(
use_vmac: true
use_vmac: true,
virtual_ipaddress: '192.168.1.1'
)
end

it { is_expected.to create_keepalived__vrrp__instance('_NAME_') }
it {
is_expected.to \
contain_concat__fragment('keepalived.conf_vrrp_instance__NAME_').with(
'content' => %r{use_vmac}
)
is_expected.to \
contain_concat__fragment('keepalived.conf_vrrp_instance__NAME_').with(
'content' => %r{^\s+192.168.1.1$}
)
}
end

describe 'with use_vmac and virtual_ipaddress as hash' do
let(:params) do
mandatory_params.merge(
use_vmac: true,
virtual_ipaddress: { 'ip' => '192.168.1.1' }
)
end

it { is_expected.to create_keepalived__vrrp__instance('_NAME_') }
it {
is_expected.to \
contain_concat__fragment('keepalived.conf_vrrp_instance__NAME_').with(
'content' => %r{use_vmac}
)
is_expected.to \
contain_concat__fragment('keepalived.conf_vrrp_instance__NAME_').with(
'content' => %r{^\s+192.168.1.1$}
)
}
end

describe 'with use_vmac and virtual_ipaddress as array of hashes and array of ips' do
let(:params) do
mandatory_params.merge(
use_vmac: true,
virtual_ipaddress_int: '_VALUE_',
virtual_ipaddress: [{ 'ip' => '192.168.1.1' },
{ 'ip' => ['192.168.1.2', '192.168.1.3'] }]
)
end

it { is_expected.to create_keepalived__vrrp__instance('_NAME_') }
it {
is_expected.to \
contain_concat__fragment('keepalived.conf_vrrp_instance__NAME_').with(
'content' => %r{use_vmac}
)
is_expected.to \
contain_concat__fragment('keepalived.conf_vrrp_instance__NAME_').with(
'content' => %r{^\s+192.168.1.1$}
)
is_expected.to \
contain_concat__fragment('keepalived.conf_vrrp_instance__NAME_').with(
'content' => %r{^\s+192.168.1.2$}
)
is_expected.to \
contain_concat__fragment('keepalived.conf_vrrp_instance__NAME_').with(
'content' => %r{^\s+192.168.1.3$}
)
}
end

describe 'with use_vmac, virtual_ipaddress as hash and virtual_ipaddress_excluded as hash' do
let(:params) do
mandatory_params.merge(
use_vmac: true,
virtual_ipaddress: { 'ip' => '192.168.1.1' },
virtual_ipaddress_excluded: { 'ip' => '192.168.2.1' }
)
end

Expand All @@ -938,6 +1013,59 @@
contain_concat__fragment('keepalived.conf_vrrp_instance__NAME_').with(
'content' => %r{use_vmac}
)
is_expected.to \
contain_concat__fragment('keepalived.conf_vrrp_instance__NAME_').with(
'content' => %r{^\s+192.168.1.1$}
)
is_expected.to \
contain_concat__fragment('keepalived.conf_vrrp_instance__NAME_').with(
'content' => %r{^\s+192.168.2.1$}
)
}
end

describe 'with use_vmac and virtual_ipaddress as array of hashes and array of ips' do
let(:params) do
mandatory_params.merge(
use_vmac: true,
virtual_ipaddress_int: '_VALUE_',
virtual_ipaddress: [{ 'ip' => '192.168.1.1' },
{ 'ip' => ['192.168.1.2', '192.168.1.3'] }],
virtual_ipaddress_excluded: [{ 'ip' => '192.168.2.1' },
{ 'ip' => ['192.168.2.2', '192.168.2.3'] }]
)
end

it { is_expected.to create_keepalived__vrrp__instance('_NAME_') }
it {
is_expected.to \
contain_concat__fragment('keepalived.conf_vrrp_instance__NAME_').with(
'content' => %r{use_vmac}
)
is_expected.to \
contain_concat__fragment('keepalived.conf_vrrp_instance__NAME_').with(
'content' => %r{^\s+192.168.1.1$}
)
is_expected.to \
contain_concat__fragment('keepalived.conf_vrrp_instance__NAME_').with(
'content' => %r{^\s+192.168.1.2$}
)
is_expected.to \
contain_concat__fragment('keepalived.conf_vrrp_instance__NAME_').with(
'content' => %r{^\s+192.168.1.3$}
)
is_expected.to \
contain_concat__fragment('keepalived.conf_vrrp_instance__NAME_').with(
'content' => %r{^\s+192.168.2.1$}
)
is_expected.to \
contain_concat__fragment('keepalived.conf_vrrp_instance__NAME_').with(
'content' => %r{^\s+192.168.2.2$}
)
is_expected.to \
contain_concat__fragment('keepalived.conf_vrrp_instance__NAME_').with(
'content' => %r{^\s+192.168.2.3$}
)
}
end

Expand Down
18 changes: 17 additions & 1 deletion templates/vrrp_instance.erb
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,17 @@ vrrp_instance <%= @_name %> {
<%- if ip.class == Hash -%>
<%- device = ip['dev'] || @virtual_ipaddress_int || @interface -%>
<%- attrs = Hash[ ip.select { |k,v| ['label', 'brd', 'scope'].include? k } ] -%>
<%- if @use_vmac -%>
<%= Array(ip['ip']).collect{|lip| "#{lip}" }.join("\n ") %>
<%- else -%>
<%= Array(ip['ip']).collect{|lip| "#{lip} dev #{device} #{attrs.sort_by{ |k,v| k }.entries.join ' '}" }.join("\n ") %>
<%- end -%>
<%- else -%>
<%- if @use_vmac -%>
<%= ip %>
<%- else -%>
<%= ip %> dev <%= @virtual_ipaddress_int || @interface %>
<%- end -%>
<%- end -%>
<%- end -%>
}
Expand All @@ -136,9 +144,17 @@ vrrp_instance <%= @_name %> {
<%- if ip.class == Hash -%>
<%- device = ip['dev'] || @virtual_ipaddress_int || @interface -%>
<%- attrs = Hash[ ip.select { |k,v| ['label', 'brd', 'scope'].include? k } ] -%>
<%- if @use_vmac -%>
<%= Array(ip['ip']).collect{|lip| "#{lip}" }.join("\n ") %>
<%- else -%>
<%= Array(ip['ip']).collect{|lip| "#{lip} dev #{device} #{attrs.sort_by{ |k,v| k }.entries.join ' '}" }.join("\n ") %>
<%- end -%>
<%- else -%>
<%= ip %> dev <%= @virtual_ipaddress_int || @interface %>
<%- if @use_vmac -%>
<%= ip %>
<%- else -%>
<%= ip %> dev <%= @virtual_ipaddress_int || @interface %>
<%- end -%>
<%- end -%>
<%- end -%>
}
Expand Down

0 comments on commit 5ab0d63

Please sign in to comment.