diff options
author | Thom May <thom@may.lt> | 2015-08-13 14:48:32 +0100 |
---|---|---|
committer | Thom May <thom@may.lt> | 2015-08-13 14:48:32 +0100 |
commit | 178b46fad5949d9e19f5099bc058ed5cb3977235 (patch) | |
tree | a749b82df2d4a923411e4ea97ad3037a015996ce | |
parent | 3a541ab3b26b303fa114df472e9a474a1d92e56c (diff) | |
parent | c55c392c7f517b1582e8470d516406b07b14a7e2 (diff) | |
download | chef-178b46fad5949d9e19f5099bc058ed5cb3977235.tar.gz |
Merge pull request #3329 from juliandunn/ifconfig-target
Use target, not name, if it is specified.
-rw-r--r-- | lib/chef/provider/ifconfig.rb | 4 | ||||
-rw-r--r-- | spec/unit/provider/ifconfig_spec.rb | 24 |
2 files changed, 24 insertions, 4 deletions
diff --git a/lib/chef/provider/ifconfig.rb b/lib/chef/provider/ifconfig.rb index 468e1ec639..7869917307 100644 --- a/lib/chef/provider/ifconfig.rb +++ b/lib/chef/provider/ifconfig.rb @@ -194,7 +194,7 @@ class Chef private def add_command - command = "ifconfig #{@new_resource.device} #{@new_resource.name}" + command = "ifconfig #{@new_resource.device} #{@new_resource.target}" command << " netmask #{@new_resource.mask}" if @new_resource.mask command << " metric #{@new_resource.metric}" if @new_resource.metric command << " mtu #{@new_resource.mtu}" if @new_resource.mtu @@ -202,7 +202,7 @@ class Chef end def enable_command - command = "ifconfig #{@new_resource.device} #{@new_resource.name}" + command = "ifconfig #{@new_resource.device} #{@new_resource.target}" command << " netmask #{@new_resource.mask}" if @new_resource.mask command << " metric #{@new_resource.metric}" if @new_resource.metric command << " mtu #{@new_resource.mtu}" if @new_resource.mtu diff --git a/spec/unit/provider/ifconfig_spec.rb b/spec/unit/provider/ifconfig_spec.rb index d290ab7066..4940f19a45 100644 --- a/spec/unit/provider/ifconfig_spec.rb +++ b/spec/unit/provider/ifconfig_spec.rb @@ -46,7 +46,7 @@ describe Chef::Provider::Ifconfig do allow(@provider).to receive(:shell_out).and_return(@status) @provider.load_current_resource end - it "should track state of ifconfig failure." do + it "should track state of ifconfig failure" do expect(@provider.instance_variable_get("@status").exitstatus).not_to eq(0) end it "should thrown an exception when ifconfig fails" do @@ -68,6 +68,16 @@ describe Chef::Provider::Ifconfig do expect(@new_resource).to be_updated end + it "should set the address to target if specified" do + allow(@provider).to receive(:load_current_resource) + @new_resource.target "172.16.32.2" + command = "ifconfig eth0 172.16.32.2 netmask 255.255.254.0 metric 1 mtu 1500" + expect(@provider).to receive(:run_command).with(:command => command) + + @provider.run_action(:add) + expect(@new_resource).to be_updated + end + it "should not add an interface if it already exists" do allow(@provider).to receive(:load_current_resource) expect(@provider).not_to receive(:run_command) @@ -85,7 +95,7 @@ describe Chef::Provider::Ifconfig do describe Chef::Provider::Ifconfig, "action_enable" do - it "should enable interface if does not exist" do + it "should enable interface if it does not exist" do allow(@provider).to receive(:load_current_resource) @current_resource.inet_addr nil command = "ifconfig eth0 10.0.0.1 netmask 255.255.254.0 metric 1 mtu 1500" @@ -96,6 +106,16 @@ describe Chef::Provider::Ifconfig do expect(@new_resource).to be_updated end + it "should set the address to target if specified" do + allow(@provider).to receive(:load_current_resource) + @new_resource.target "172.16.32.2" + command = "ifconfig eth0 172.16.32.2 netmask 255.255.254.0 metric 1 mtu 1500" + expect(@provider).to receive(:run_command).with(:command => command) + + @provider.run_action(:enable) + expect(@new_resource).to be_updated + end + it "should not enable interface if it already exists" do allow(@provider).to receive(:load_current_resource) expect(@provider).not_to receive(:run_command) |