From 6aa7f5fe20e7d347891372f887629bd319714480 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-Fran=C3=A7ois=20Roche?= <jfroche@affinitic.be> Date: Thu, 10 Dec 2020 15:42:05 +0100 Subject: [PATCH] Enable prefix management when using ipaddress Fix the case where we have RedHat, multiple ipaddress and multiple prefix. The interface parameter `ipaddress` is the only option way to define multiple ips. --- manifests/interface.pp | 5 +++- spec/defines/network_interface_spec.rb | 38 ++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/manifests/interface.pp b/manifests/interface.pp index 34b486d..190fdd7 100644 --- a/manifests/interface.pp +++ b/manifests/interface.pp @@ -635,7 +635,10 @@ define network::interface ( default => $peerntp, } case $ipaddr { - '': { $manage_ipaddr = $ipaddress} + '': { + $manage_ipaddr = $ipaddress + $manage_prefix = $prefix + } default: { if $ipaddr =~ /^([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3})\/([0-9]|[1-2][0-9]|3[0-2])$/ { $manage_ipaddr = $1 diff --git a/spec/defines/network_interface_spec.rb b/spec/defines/network_interface_spec.rb index 865b88c..8572a50 100644 --- a/spec/defines/network_interface_spec.rb +++ b/spec/defines/network_interface_spec.rb @@ -102,6 +102,44 @@ describe 'network::interface' do end + context 'Test network:interface on RedHat 7 with multiple IPs, multiple prefix' do + let(:title) { 'eth0' } + let(:node) { 'rspec.example42.com' } + let(:facts) { { :architecture => 'x86_64', :osfamily => 'RedHat', :operatingsystem => 'RedHat', :operatingsystemmajrelease => '7' } } + let(:params) { + { 'enable' => true, + 'ipaddress' => ['192.168.0.1','192.168.0.2'], + 'prefix' => ['24', '32'] + } + } + + it { + is_expected.to contain_file(NIC_CONFIG).with_ensure('present') + } + + it { + is_expected.to contain_file(NIC_CONFIG).with_content(/IPADDR1=\"192.168.0.1\"/) + } + + it { + is_expected.to contain_file(NIC_CONFIG).with_content(/IPADDR2=\"192.168.0.2\"/) + } + + it { + is_expected.to contain_file(NIC_CONFIG).with_content(/ONBOOT=\"yes\"/) + } + + it { + is_expected.to contain_file(NIC_CONFIG).with_content(/PREFIX1=\"24\"/) + } + + it { + is_expected.to contain_file(NIC_CONFIG).with_content(/PREFIX2=\"32\"/) + } + + end + + context 'Test network:interface on RedHat 8 with multiple IP rules' do let(:title) { 'eth0' } let(:node) { 'rspec.example42.com' } -- GitLab