Skip to content

Commit

Permalink
virtual_ipaddress should be on vrrp interface if use_vmac is set
Browse files Browse the repository at this point in the history
  • Loading branch information
saz committed Jun 26, 2019
1 parent 6b70439 commit 03661fd
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 2 deletions.
52 changes: 52 additions & 0 deletions spec/defines/keepalived_vrrp_instance_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -941,6 +941,58 @@
}
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 => "vrrp250"' do
let(:params) do
mandatory_params.merge(
Expand Down
12 changes: 10 additions & 2 deletions 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 } ] -%>
<%= Array(ip['ip']).collect{|lip| "#{lip} dev #{device} #{attrs.sort_by{ |k,v| k }.entries.join ' '}" }.join("\n ") %>
<%- 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 03661fd

Please sign in to comment.