From 62e85f394a2b0068297114ec862de4336fa57c13 Mon Sep 17 00:00:00 2001 From: Tim Smith Date: Mon, 19 Oct 2020 11:29:29 -0700 Subject: Test ifconfig in Test Kitchen and add examples to the resource We lacked an actual test of this resource. Let's see if it works. Signed-off-by: Tim Smith --- .../cookbooks/end_to_end/recipes/_ifconfig.rb | 13 +++++ .../cookbooks/end_to_end/recipes/linux.rb | 1 + lib/chef/resource/ifconfig.rb | 59 ++++++++++++++++++++-- 3 files changed, 69 insertions(+), 4 deletions(-) create mode 100644 kitchen-tests/cookbooks/end_to_end/recipes/_ifconfig.rb diff --git a/kitchen-tests/cookbooks/end_to_end/recipes/_ifconfig.rb b/kitchen-tests/cookbooks/end_to_end/recipes/_ifconfig.rb new file mode 100644 index 0000000000..149b2cb65c --- /dev/null +++ b/kitchen-tests/cookbooks/end_to_end/recipes/_ifconfig.rb @@ -0,0 +1,13 @@ +execute "create virtual interface for testing" do + command "ifconfig eth0:0 123.123.22.22" +end + +ifconfig "33.33.33.80" do + bootproto "dhcp" + device "eth0:0" +end + +ifconfig "Set eth1 to DHCP" do + device "eth0:0" + bootproto "dhcp" +end \ No newline at end of file diff --git a/kitchen-tests/cookbooks/end_to_end/recipes/linux.rb b/kitchen-tests/cookbooks/end_to_end/recipes/linux.rb index 0d560b09bd..8991cf1594 100644 --- a/kitchen-tests/cookbooks/end_to_end/recipes/linux.rb +++ b/kitchen-tests/cookbooks/end_to_end/recipes/linux.rb @@ -123,6 +123,7 @@ include_recipe "::_ohai_hint" include_recipe "::_openssl" include_recipe "::_tests" include_recipe "::_mount" +include_recipe "::_ifconfig" # at the moment these do not run properly in docker # we need to investigate if this is a snap on docker issue or a chef issue diff --git a/lib/chef/resource/ifconfig.rb b/lib/chef/resource/ifconfig.rb index ed62ab5952..729658690d 100644 --- a/lib/chef/resource/ifconfig.rb +++ b/lib/chef/resource/ifconfig.rb @@ -21,16 +21,67 @@ require_relative "../resource" class Chef class Resource - # @example set a static ip on eth1 - # ifconfig '33.33.33.80' do - # device 'eth1' - # end class Ifconfig < Chef::Resource unified_mode true provides :ifconfig description "Use the **ifconfig** resource to manage interfaces on Unix and Linux systems." + examples <<~DOC + **Configure a network interface with a static IP** + + ```ruby + ifconfig '33.33.33.80' do + device 'eth1' + end + ``` + + will create the following interface configuration: + + ``` + iface eth1 inet static + address 33.33.33.80 + ``` + + **Specify a boot protocol** + + ```ruby + ifconfig '192.186.0.1' do + device 'eth0' + end + ``` + + **Configure an interface to use DHCP** + + ```ruby + ifconfig 'Set eth1 to DHCP' do + device 'eth1' + bootproto 'dhcp' + end + ``` + + will create the following interface configuration: + + ``` + iface eth1 inet dhcp + ``` + + **Update a static IP address with a boot protocol** + + ```ruby + ifconfig "33.33.33.80" do + bootproto "dhcp" + device "eth1" + end + ``` + + will update the interface configuration from static to dhcp: + + ``` + iface eth1 inet dhcp + address 33.33.33.80 + ``` + DOC state_attrs :inet_addr, :mask -- cgit v1.2.1