chef 10.14.0.beta.3 → 10.14.0.rc.0
Sign up to get free protection for your applications and to get access to all the features.
- data/distro/common/html/chef-client.8.html +4 -6
- data/distro/common/html/chef-expander.8.html +4 -4
- data/distro/common/html/chef-expanderctl.8.html +4 -4
- data/distro/common/html/chef-server-webui.8.html +4 -4
- data/distro/common/html/chef-server.8.html +4 -4
- data/distro/common/html/chef-solo.8.html +4 -4
- data/distro/common/html/chef-solr.8.html +4 -4
- data/distro/common/html/knife-bootstrap.1.html +4 -4
- data/distro/common/html/knife-client.1.html +4 -4
- data/distro/common/html/knife-configure.1.html +5 -5
- data/distro/common/html/knife-cookbook-site.1.html +7 -7
- data/distro/common/html/knife-cookbook.1.html +4 -4
- data/distro/common/html/knife-data-bag.1.html +4 -4
- data/distro/common/html/knife-environment.1.html +4 -4
- data/distro/common/html/knife-exec.1.html +4 -4
- data/distro/common/html/knife-index.1.html +4 -4
- data/distro/common/html/knife-node.1.html +5 -5
- data/distro/common/html/knife-role.1.html +4 -4
- data/distro/common/html/knife-search.1.html +4 -4
- data/distro/common/html/knife-ssh.1.html +5 -5
- data/distro/common/html/knife-status.1.html +4 -4
- data/distro/common/html/knife-tag.1.html +4 -4
- data/distro/common/html/knife.1.html +5 -5
- data/distro/common/html/shef.1.html +4 -4
- data/distro/common/man/man1/knife-bootstrap.1 +1 -1
- data/distro/common/man/man1/knife-client.1 +1 -1
- data/distro/common/man/man1/knife-configure.1 +1 -1
- data/distro/common/man/man1/knife-cookbook-site.1 +1 -1
- data/distro/common/man/man1/knife-cookbook.1 +1 -1
- data/distro/common/man/man1/knife-data-bag.1 +1 -1
- data/distro/common/man/man1/knife-environment.1 +1 -1
- data/distro/common/man/man1/knife-exec.1 +1 -1
- data/distro/common/man/man1/knife-index.1 +1 -1
- data/distro/common/man/man1/knife-node.1 +1 -1
- data/distro/common/man/man1/knife-role.1 +1 -1
- data/distro/common/man/man1/knife-search.1 +1 -1
- data/distro/common/man/man1/knife-ssh.1 +1 -1
- data/distro/common/man/man1/knife-status.1 +1 -1
- data/distro/common/man/man1/knife-tag.1 +1 -1
- data/distro/common/man/man1/knife.1 +5 -5
- data/distro/common/man/man1/shef.1 +1 -1
- data/distro/common/man/man8/chef-client.8 +1 -5
- data/distro/common/man/man8/chef-expander.8 +1 -1
- data/distro/common/man/man8/chef-expanderctl.8 +1 -1
- data/distro/common/man/man8/chef-server-webui.8 +1 -1
- data/distro/common/man/man8/chef-server.8 +1 -1
- data/distro/common/man/man8/chef-solo.8 +1 -1
- data/distro/common/man/man8/chef-solr.8 +1 -1
- data/distro/common/markdown/man1/knife.mkd +2 -2
- data/distro/common/markdown/man8/chef-client.mkd +0 -3
- data/lib/chef/client.rb +13 -3
- data/lib/chef/config.rb +29 -0
- data/lib/chef/environment.rb +5 -2
- data/lib/chef/file_access_control/unix.rb +3 -3
- data/lib/chef/knife.rb +11 -5
- data/lib/chef/knife/bootstrap.rb +9 -5
- data/lib/chef/knife/bootstrap/archlinux-gems.erb +1 -1
- data/lib/chef/knife/bootstrap/centos5-gems.erb +1 -1
- data/lib/chef/knife/bootstrap/chef-full.erb +1 -1
- data/lib/chef/knife/bootstrap/fedora13-gems.erb +1 -1
- data/lib/chef/knife/bootstrap/ubuntu10.04-apt.erb +1 -1
- data/lib/chef/knife/bootstrap/ubuntu10.04-gems.erb +1 -1
- data/lib/chef/knife/bootstrap/ubuntu12.04-gems.erb +1 -1
- data/lib/chef/knife/cookbook_create.rb +24 -1
- data/lib/chef/knife/ssh.rb +14 -2
- data/lib/chef/platform.rb +22 -2
- data/lib/chef/provider/file.rb +9 -3
- data/lib/chef/provider/group/usermod.rb +7 -4
- data/lib/chef/provider/mdadm.rb +3 -3
- data/lib/chef/provider/package/ips.rb +101 -0
- data/lib/chef/provider/package/solaris.rb +21 -12
- data/lib/chef/provider/service/solaris.rb +0 -3
- data/lib/chef/provider/user/dscl.rb +1 -1
- data/lib/chef/providers.rb +1 -0
- data/lib/chef/resource/ips_package.rb +42 -0
- data/lib/chef/resource/package.rb +6 -7
- data/lib/chef/resources.rb +1 -0
- data/lib/chef/rest/auth_credentials.rb +4 -3
- data/lib/chef/scan_access_control.rb +3 -9
- data/lib/chef/shef/ext.rb +22 -0
- data/lib/chef/version.rb +1 -1
- data/spec/functional/knife/cookbook_delete_spec.rb +5 -2
- data/spec/functional/knife/exec_spec.rb +5 -2
- data/spec/functional/knife/ssh_spec.rb +4 -2
- data/spec/functional/resource/link_spec.rb +4 -4
- data/spec/functional/resource/remote_file_spec.rb +17 -1
- data/spec/support/platform_helpers.rb +8 -0
- data/spec/support/shared/functional/securable_resource.rb +2 -2
- data/spec/tiny_server.rb +5 -1
- data/spec/unit/client_spec.rb +24 -0
- data/spec/unit/environment_spec.rb +26 -0
- data/spec/unit/knife/bootstrap_spec.rb +34 -11
- data/spec/unit/knife/config_file_selection_spec.rb +2 -2
- data/spec/unit/knife/configure_spec.rb +6 -0
- data/spec/unit/knife/cookbook_create_spec.rb +20 -0
- data/spec/unit/knife/ssh_spec.rb +145 -0
- data/spec/unit/mixin/command_spec.rb +8 -4
- data/spec/unit/mixin/enforce_ownership_and_permissions_spec.rb +2 -1
- data/spec/unit/mixin/securable_spec.rb +2 -2
- data/spec/unit/provider/file_spec.rb +6 -4
- data/spec/unit/provider/group/usermod_spec.rb +6 -1
- data/spec/unit/provider/link_spec.rb +4 -1
- data/spec/unit/provider/mdadm_spec.rb +10 -13
- data/spec/unit/provider/package/ips_spec.rb +210 -0
- data/spec/unit/provider/package/solaris_spec.rb +6 -4
- data/spec/unit/provider/subversion_spec.rb +2 -2
- data/spec/unit/provider/user/dscl_spec.rb +15 -0
- data/spec/unit/resource/ips_package_spec.rb +43 -0
- data/spec/unit/rest/auth_credentials_spec.rb +36 -14
- data/spec/unit/scan_access_control_spec.rb +20 -0
- metadata +13 -8
@@ -0,0 +1,145 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Bryan McLellan <btm@opscode.com>
|
3
|
+
# Copyright:: Copyright (c) 2012 Opscode, Inc.
|
4
|
+
# License:: Apache License, Version 2.0
|
5
|
+
#
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
# you may not use this file except in compliance with the License.
|
8
|
+
# You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
+
# See the License for the specific language governing permissions and
|
16
|
+
# limitations under the License.
|
17
|
+
#
|
18
|
+
|
19
|
+
require 'spec_helper'
|
20
|
+
require 'net/ssh'
|
21
|
+
require 'net/ssh/multi'
|
22
|
+
|
23
|
+
describe Chef::Knife::Ssh do
|
24
|
+
before(:all) do
|
25
|
+
@original_config = Chef::Config.hash_dup
|
26
|
+
Chef::Config[:client_key] = CHEF_SPEC_DATA + "/ssl/private_key.pem"
|
27
|
+
end
|
28
|
+
|
29
|
+
after(:all) do
|
30
|
+
Chef::Config.configuration = @original_config
|
31
|
+
end
|
32
|
+
|
33
|
+
before do
|
34
|
+
@knife = Chef::Knife::Ssh.new
|
35
|
+
@knife.config = {}
|
36
|
+
@knife.config[:attribute] = "fqdn"
|
37
|
+
@node_foo = Chef::Node.new('foo')
|
38
|
+
@node_foo[:fqdn] = "foo.example.org"
|
39
|
+
@node_bar = Chef::Node.new('foo')
|
40
|
+
@node_bar[:fqdn] = "bar.example.org"
|
41
|
+
end
|
42
|
+
|
43
|
+
describe "#configure_session" do
|
44
|
+
context "manual is set to false (default)" do
|
45
|
+
before do
|
46
|
+
@knife.config[:manual] = false
|
47
|
+
@query = Chef::Search::Query.new
|
48
|
+
end
|
49
|
+
|
50
|
+
def self.should_return_array_of_attributes
|
51
|
+
it "returns an array of the specified attributes if configured" do
|
52
|
+
@knife.config[:attribute] = "ipaddress"
|
53
|
+
@knife.config[:override_attribute] = "ipaddress"
|
54
|
+
@node_foo[:ipaddress] = "10.0.0.1"
|
55
|
+
@node_bar[:ipaddress] = "10.0.0.2"
|
56
|
+
@query.stub!(:search).and_return([[@node_foo, @node_bar]])
|
57
|
+
Chef::Search::Query.stub!(:new).and_return(@query)
|
58
|
+
@knife.should_receive(:session_from_list).with(['10.0.0.1', '10.0.0.2'])
|
59
|
+
@knife.configure_session
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
it "searchs for and returns an array of fqdns" do
|
64
|
+
@query.stub!(:search).and_return([[@node_foo, @node_bar]])
|
65
|
+
Chef::Search::Query.stub!(:new).and_return(@query)
|
66
|
+
@knife.should_receive(:session_from_list).with(['foo.example.org', 'bar.example.org'])
|
67
|
+
@knife.configure_session
|
68
|
+
end
|
69
|
+
|
70
|
+
should_return_array_of_attributes
|
71
|
+
|
72
|
+
context "when cloud hostnames are available" do
|
73
|
+
before do
|
74
|
+
@node_foo[:cloud] = Mash.new
|
75
|
+
@node_bar[:cloud] = Mash.new
|
76
|
+
@node_foo[:cloud][:public_hostname] = "ec2-10-0-0-1.compute-1.amazonaws.com"
|
77
|
+
@node_bar[:cloud][:public_hostname] = "ec2-10-0-0-2.compute-1.amazonaws.com"
|
78
|
+
end
|
79
|
+
|
80
|
+
it "returns an array of cloud public hostnames" do
|
81
|
+
@query.stub!(:search).and_return([[@node_foo, @node_bar]])
|
82
|
+
Chef::Search::Query.stub!(:new).and_return(@query)
|
83
|
+
@knife.should_receive(:session_from_list).with(['ec2-10-0-0-1.compute-1.amazonaws.com', 'ec2-10-0-0-2.compute-1.amazonaws.com'])
|
84
|
+
@knife.configure_session
|
85
|
+
end
|
86
|
+
|
87
|
+
should_return_array_of_attributes
|
88
|
+
end
|
89
|
+
|
90
|
+
it "should raise an error if no host are found" do
|
91
|
+
@query.stub!(:search).and_return([[ ]])
|
92
|
+
Chef::Search::Query.stub!(:new).and_return(@query)
|
93
|
+
@knife.ui.should_receive(:fatal)
|
94
|
+
@knife.should_receive(:exit).with(10)
|
95
|
+
@knife.configure_session
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
context "manual is set to true" do
|
100
|
+
before do
|
101
|
+
@knife.config[:manual] = true
|
102
|
+
end
|
103
|
+
|
104
|
+
it "returns an array of provided values" do
|
105
|
+
@knife.instance_variable_set(:@name_args, ["foo.example.org bar.example.org"])
|
106
|
+
@knife.should_receive(:session_from_list).with(['foo.example.org', 'bar.example.org'])
|
107
|
+
@knife.configure_session
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
describe "#configure_attribute" do
|
113
|
+
before do
|
114
|
+
Chef::Config[:knife][:ssh_attribute] = nil
|
115
|
+
@knife.config[:attribute] = nil
|
116
|
+
end
|
117
|
+
|
118
|
+
it "should return fqdn by default" do
|
119
|
+
@knife.configure_attribute
|
120
|
+
@knife.config[:attribute].should == "fqdn"
|
121
|
+
end
|
122
|
+
|
123
|
+
it "should return the value set in the configuration file" do
|
124
|
+
Chef::Config[:knife][:ssh_attribute] = "magic"
|
125
|
+
@knife.configure_attribute
|
126
|
+
@knife.config[:attribute].should == "magic"
|
127
|
+
end
|
128
|
+
|
129
|
+
it "should return the value set on the command line" do
|
130
|
+
@knife.config[:attribute] = "penguins"
|
131
|
+
@knife.configure_attribute
|
132
|
+
@knife.config[:attribute].should == "penguins"
|
133
|
+
end
|
134
|
+
|
135
|
+
it "should set override_attribute to the value of attribute" do
|
136
|
+
@knife.config[:attribute] = "penguins"
|
137
|
+
@knife.configure_attribute
|
138
|
+
@knife.config[:attribute].should == "penguins"
|
139
|
+
@knife.config[:override_attribute].should == "penguins"
|
140
|
+
end
|
141
|
+
|
142
|
+
end
|
143
|
+
|
144
|
+
end
|
145
|
+
|
@@ -49,7 +49,7 @@ describe Chef::Mixin::Command do
|
|
49
49
|
end
|
50
50
|
|
51
51
|
it "should end when the child process reads from STDIN and a block is given" do
|
52
|
-
lambda {Timeout.timeout(
|
52
|
+
lambda {Timeout.timeout(10) do
|
53
53
|
popen4("ruby -e 'while gets; end'", :waitlast => true) do |pid, stdin, stdout, stderr|
|
54
54
|
(1..5).each { |i| stdin.puts "#{i}" }
|
55
55
|
end
|
@@ -60,7 +60,7 @@ describe Chef::Mixin::Command do
|
|
60
60
|
describe "when a process detaches but doesn't close STDOUT and STDERR [CHEF-584]" do
|
61
61
|
|
62
62
|
it "returns immediately after the first child process exits" do
|
63
|
-
lambda {Timeout.timeout(
|
63
|
+
lambda {Timeout.timeout(10) do
|
64
64
|
pid, stdin,stdout,stderr = nil,nil,nil,nil
|
65
65
|
evil_forker="exit if fork; 10.times { sleep 1}"
|
66
66
|
popen4("ruby -e '#{evil_forker}'") do |pid,stdin,stdout,stderr|
|
@@ -88,8 +88,12 @@ describe Chef::Mixin::Command do
|
|
88
88
|
|
89
89
|
describe "when a process detaches but doesn't close STDOUT and STDERR [CHEF-584]" do
|
90
90
|
it "returns successfully" do
|
91
|
-
# CHEF-2916 might have added a slight delay here, or our CI
|
92
|
-
|
91
|
+
# CHEF-2916 might have added a slight delay here, or our CI
|
92
|
+
# infrastructure is burdened. Bumping timeout from 2 => 4 --
|
93
|
+
# btm
|
94
|
+
# Serdar - During Solaris tests, we've seen that processes
|
95
|
+
# are taking a long time to exit. Bumping timeout now to 10.
|
96
|
+
lambda {Timeout.timeout(10) do
|
93
97
|
evil_forker="exit if fork; 10.times { sleep 1}"
|
94
98
|
run_command(:command => "ruby -e '#{evil_forker}'")
|
95
99
|
end}.should_not raise_error
|
@@ -27,7 +27,8 @@ describe Chef::Mixin::EnforceOwnershipAndPermissions do
|
|
27
27
|
@node.name "make_believe"
|
28
28
|
@events = Chef::EventDispatch::Dispatcher.new
|
29
29
|
@run_context = Chef::RunContext.new(@node, {}, @events)
|
30
|
-
@resource = Chef::Resource::File.new("#{Dir.
|
30
|
+
@resource = Chef::Resource::File.new("#{Dir.mktmpdir}/madeup.txt")
|
31
|
+
FileUtils.touch @resource.path
|
31
32
|
@resource.owner "adam"
|
32
33
|
@provider = Chef::Provider::File.new(@resource, @run_context)
|
33
34
|
@provider.current_resource = @resource
|
@@ -119,11 +119,11 @@ describe Chef::Mixin::Securable do
|
|
119
119
|
end
|
120
120
|
|
121
121
|
after(:all) do
|
122
|
-
|
122
|
+
Chef::Config.configuration = @original_config if @original_config
|
123
123
|
end
|
124
124
|
|
125
125
|
after(:each) do
|
126
|
-
Chef::Config.configuration = @original_config
|
126
|
+
Chef::Config.configuration = @original_config if @original_config
|
127
127
|
end
|
128
128
|
|
129
129
|
it "should not accept a group name or id for group with spaces and multiple backslashes" do
|
@@ -284,12 +284,14 @@ describe Chef::Provider::File do
|
|
284
284
|
@provider.load_current_resource
|
285
285
|
result = @provider.diff_current_from_content "foo baz"
|
286
286
|
# remove the file name info which varies.
|
287
|
-
require 'pp'
|
288
|
-
pp result
|
289
287
|
result.shift(2)
|
290
|
-
|
288
|
+
# Result appearance seems to vary slightly under solaris diff
|
289
|
+
# So we'll compare the second line which is common to both.
|
290
|
+
# Solaris: -1,1 +1,0 @@, "+foo baz"
|
291
|
+
# Linux/Mac: -1,0, +1 @@, "+foo baz"
|
292
|
+
result.length.should == 2
|
293
|
+
result[1].should == "+foo baz"
|
291
294
|
end
|
292
295
|
end
|
293
296
|
end
|
294
297
|
end
|
295
|
-
|
@@ -51,10 +51,15 @@ describe Chef::Provider::Group::Usermod do
|
|
51
51
|
|
52
52
|
before do
|
53
53
|
@new_resource.stub!(:members).and_return(["all", "your", "base"])
|
54
|
+
File.stub!(:exists?).and_return(true)
|
54
55
|
end
|
55
56
|
|
56
57
|
it "should raise an error when setting the entire group directly" do
|
57
|
-
|
58
|
+
@provider.define_resource_requirements
|
59
|
+
@provider.load_current_resource
|
60
|
+
@provider.instance_variable_set("@group_exists", true)
|
61
|
+
@provider.action = :modify
|
62
|
+
lambda { @provider.run_action(@provider.process_resource_requirements) }.should raise_error(Chef::Exceptions::Group, "setting group members directly is not supported by #{@provider.to_s}, must set append true in group")
|
58
63
|
end
|
59
64
|
|
60
65
|
platforms.each do |platform, flags|
|
@@ -47,7 +47,7 @@ describe Chef::Resource::Link do
|
|
47
47
|
lstat = mock("stats", :ino => 5)
|
48
48
|
lstat.stub!(:uid).and_return(501)
|
49
49
|
lstat.stub!(:gid).and_return(501)
|
50
|
-
|
50
|
+
lstat.stub!(:mode).and_return(0777)
|
51
51
|
File.stub!(:lstat).with("#{CHEF_SPEC_DATA}/fofile-link").and_return(lstat)
|
52
52
|
provider.file_class.stub!(:symlink?).with("#{CHEF_SPEC_DATA}/fofile-link").and_return(true)
|
53
53
|
provider.file_class.stub!(:readlink).with("#{CHEF_SPEC_DATA}/fofile-link").and_return("#{CHEF_SPEC_DATA}/fofile")
|
@@ -147,6 +147,7 @@ describe Chef::Resource::Link do
|
|
147
147
|
stat = mock("stats", :ino => 5)
|
148
148
|
stat.stub!(:uid).and_return(501)
|
149
149
|
stat.stub!(:gid).and_return(501)
|
150
|
+
stat.stub!(:mode).and_return(0755)
|
150
151
|
provider.file_class.stub!(:stat).with("#{CHEF_SPEC_DATA}/fofile-link").and_return(stat)
|
151
152
|
|
152
153
|
File.stub!(:exists?).with("#{CHEF_SPEC_DATA}/fofile-link").and_return(true)
|
@@ -178,6 +179,7 @@ describe Chef::Resource::Link do
|
|
178
179
|
stat = mock("stats", :ino => 6)
|
179
180
|
stat.stub!(:uid).and_return(502)
|
180
181
|
stat.stub!(:gid).and_return(502)
|
182
|
+
stat.stub!(:mode).and_return(0644)
|
181
183
|
|
182
184
|
provider.file_class.stub!(:stat).with("#{CHEF_SPEC_DATA}/fofile").and_return(stat)
|
183
185
|
|
@@ -204,6 +206,7 @@ describe Chef::Resource::Link do
|
|
204
206
|
stat = mock("stats", :ino => 5)
|
205
207
|
stat.stub!(:uid).and_return(502)
|
206
208
|
stat.stub!(:gid).and_return(502)
|
209
|
+
stat.stub!(:mode).and_return(0644)
|
207
210
|
|
208
211
|
provider.file_class.stub!(:stat).with("#{CHEF_SPEC_DATA}/fofile").and_return(stat)
|
209
212
|
|
@@ -32,30 +32,27 @@ describe Chef::Provider::Mdadm do
|
|
32
32
|
@new_resource.chunk 256
|
33
33
|
|
34
34
|
@provider = Chef::Provider::Mdadm.new(@new_resource, @run_context)
|
35
|
-
#Chef::Resource::Mdadm.stub!(:new).and_return(@current_resource)
|
36
|
-
|
37
|
-
# @status = mock("Status", :exitstatus => 0)
|
38
|
-
# @provider.stub!(:popen4).and_return(@status)
|
39
|
-
# @stdin = mock("STDIN", :null_object => true)
|
40
|
-
# @stdout = mock("STDOUT", :null_object => true)
|
41
|
-
# @stderr = mock("STDERR", :null_object => true)
|
42
|
-
# @pid = mock("PID", :null_object => true)
|
43
35
|
end
|
44
36
|
|
45
37
|
describe "when determining the current metadevice status" do
|
46
|
-
|
47
38
|
it "should set the current resources mount point to the new resources mount point" do
|
48
|
-
@provider.stub!(:shell_out!).and_return(OpenStruct.new(:
|
49
|
-
@provider.load_current_resource
|
39
|
+
@provider.stub!(:shell_out!).and_return(OpenStruct.new(:status => 0))
|
40
|
+
@provider.load_current_resource
|
50
41
|
@provider.current_resource.name.should == '/dev/md1'
|
51
42
|
@provider.current_resource.raid_device.should == '/dev/md1'
|
52
43
|
end
|
53
44
|
|
54
|
-
it "determines that the metadevice exists when mdadm
|
55
|
-
@provider.stub!(:shell_out!).with("mdadm --detail --
|
45
|
+
it "determines that the metadevice exists when mdadm exit code is zero" do
|
46
|
+
@provider.stub!(:shell_out!).with("mdadm --detail --test /dev/md1", :returns => [0,4]).and_return(OpenStruct.new(:status => 0))
|
56
47
|
@provider.load_current_resource
|
57
48
|
@provider.current_resource.exists.should be_true
|
58
49
|
end
|
50
|
+
|
51
|
+
it "determines that the metadevice does not exist when mdadm exit code is 4" do
|
52
|
+
@provider.stub!(:shell_out!).with("mdadm --detail --test /dev/md1", :returns => [0,4]).and_return(OpenStruct.new(:status => 4))
|
53
|
+
@provider.load_current_resource
|
54
|
+
@provider.current_resource.exists.should be_false
|
55
|
+
end
|
59
56
|
end
|
60
57
|
|
61
58
|
describe "after the metadevice status is known" do
|
@@ -0,0 +1,210 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Bryan McLellan <btm@opscode.com>
|
3
|
+
# Copyright:: Copyright (c) 2012 Opscode, Inc.
|
4
|
+
# License:: Apache License, Version 2.0
|
5
|
+
#
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
# you may not use this file except in compliance with the License.
|
8
|
+
# You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
+
# See the License for the specific language governing permissions and
|
16
|
+
# limitations under the License.
|
17
|
+
#
|
18
|
+
|
19
|
+
require 'spec_helper'
|
20
|
+
require 'ostruct'
|
21
|
+
|
22
|
+
# based on the apt specs
|
23
|
+
|
24
|
+
describe Chef::Provider::Package::Ips do
|
25
|
+
before(:each) do
|
26
|
+
@node = Chef::Node.new
|
27
|
+
@node.cookbook_collection = {}
|
28
|
+
@events = Chef::EventDispatch::Dispatcher.new
|
29
|
+
@run_context = Chef::RunContext.new(@node, {}, @events)
|
30
|
+
@new_resource = Chef::Resource::Package.new("crypto/gnupg", @run_context)
|
31
|
+
@current_resource = Chef::Resource::Package.new("crypto/gnupg", @run_context)
|
32
|
+
Chef::Resource::Package.stub!(:new).and_return(@current_resource)
|
33
|
+
@provider = Chef::Provider::Package::Ips.new(@new_resource, @run_context)
|
34
|
+
|
35
|
+
@stdin = StringIO.new
|
36
|
+
@stderr = StringIO.new
|
37
|
+
@stdout =<<-PKG_STATUS
|
38
|
+
Name: crypto/gnupg
|
39
|
+
Summary: GNU Privacy Guard
|
40
|
+
Description: A complete and free implementation of the OpenPGP Standard as
|
41
|
+
defined by RFC4880.
|
42
|
+
Category: Applications/System Utilities
|
43
|
+
State: Not installed
|
44
|
+
Publisher: solaris
|
45
|
+
Version: 2.0.17
|
46
|
+
Build Release: 5.11
|
47
|
+
Branch: 0.175.0.0.0.2.537
|
48
|
+
Packaging Date: October 19, 2011 09:14:50 AM
|
49
|
+
Size: 8.07 MB
|
50
|
+
FMRI: pkg://solaris/crypto/gnupg@2.0.17,5.11-0.175.0.0.0.2.537:20111019T091450Z
|
51
|
+
PKG_STATUS
|
52
|
+
@pid = 12345
|
53
|
+
@shell_out = OpenStruct.new(:stdout => @stdout,:stdin => @stdin,:stderr => @stderr,:status => @status,:exitstatus => 0)
|
54
|
+
end
|
55
|
+
|
56
|
+
context "when loading current resource" do
|
57
|
+
it "should create a current resource with the name of the new_resource" do
|
58
|
+
@provider.should_receive(:shell_out!).and_return(@shell_out)
|
59
|
+
Chef::Resource::Package.should_receive(:new).and_return(@current_resource)
|
60
|
+
@provider.load_current_resource
|
61
|
+
end
|
62
|
+
|
63
|
+
it "should set the current resources package name to the new resources package name" do
|
64
|
+
@provider.should_receive(:shell_out!).and_return(@shell_out)
|
65
|
+
@current_resource.should_receive(:package_name).with(@new_resource.package_name)
|
66
|
+
@provider.load_current_resource
|
67
|
+
end
|
68
|
+
|
69
|
+
it "should run pkg info with the package name" do
|
70
|
+
@provider.should_receive(:shell_out!).with("pkg info -r #{@new_resource.package_name}").and_return(@shell_out)
|
71
|
+
@provider.load_current_resource
|
72
|
+
end
|
73
|
+
|
74
|
+
it "should set the installed version to nil on the current resource if package state is not installed" do
|
75
|
+
@provider.should_receive(:shell_out!).and_return(@shell_out)
|
76
|
+
@current_resource.should_receive(:version).with(nil).and_return(true)
|
77
|
+
@provider.load_current_resource
|
78
|
+
end
|
79
|
+
|
80
|
+
it "should set the installed version if package has one" do
|
81
|
+
@stdout.replace(<<-INSTALLED)
|
82
|
+
Name: crypto/gnupg
|
83
|
+
Summary: GNU Privacy Guard
|
84
|
+
Description: A complete and free implementation of the OpenPGP Standard as
|
85
|
+
defined by RFC4880.
|
86
|
+
Category: Applications/System Utilities
|
87
|
+
State: Installed
|
88
|
+
Publisher: solaris
|
89
|
+
Version: 2.0.17
|
90
|
+
Build Release: 5.11
|
91
|
+
Branch: 0.175.0.0.0.2.537
|
92
|
+
Packaging Date: October 19, 2011 09:14:50 AM
|
93
|
+
Size: 8.07 MB
|
94
|
+
FMRI: pkg://solaris/crypto/gnupg@2.0.17,5.11-0.175.0.0.0.2.537:20111019T091450Z
|
95
|
+
INSTALLED
|
96
|
+
@provider.should_receive(:shell_out!).and_return(@shell_out)
|
97
|
+
@provider.load_current_resource
|
98
|
+
@current_resource.version.should == "2.0.17"
|
99
|
+
@provider.candidate_version.should eql("2.0.17")
|
100
|
+
end
|
101
|
+
|
102
|
+
it "should return the current resouce" do
|
103
|
+
@provider.should_receive(:shell_out!).and_return(@shell_out)
|
104
|
+
@provider.load_current_resource.should eql(@current_resource)
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
context "when installing a package" do
|
109
|
+
it "should run pkg install with the package name and version" do
|
110
|
+
@provider.should_receive(:run_command_with_systems_locale).with({
|
111
|
+
:command => "pkg install -q crypto/gnupg@2.0.17"
|
112
|
+
})
|
113
|
+
@provider.install_package("crypto/gnupg", "2.0.17")
|
114
|
+
end
|
115
|
+
|
116
|
+
|
117
|
+
it "should run pkg install with the package name and version and options if specified" do
|
118
|
+
@provider.should_receive(:run_command_with_systems_locale).with({
|
119
|
+
:command => "pkg --no-refresh install -q crypto/gnupg@2.0.17"
|
120
|
+
})
|
121
|
+
@new_resource.stub!(:options).and_return("--no-refresh")
|
122
|
+
@provider.install_package("crypto/gnupg", "2.0.17")
|
123
|
+
end
|
124
|
+
|
125
|
+
it "should not contain invalid characters for the version string" do
|
126
|
+
@stdout.replace(<<-PKG_STATUS)
|
127
|
+
Name: security/sudo
|
128
|
+
Summary: sudo - authority delegation tool
|
129
|
+
State: Not Installed
|
130
|
+
Publisher: omnios
|
131
|
+
Version: 1.8.4.1 (1.8.4p1)
|
132
|
+
Build Release: 5.11
|
133
|
+
Branch: 0.151002
|
134
|
+
Packaging Date: April 1, 2012 05:55:52 PM
|
135
|
+
Size: 2.57 MB
|
136
|
+
FMRI: pkg://omnios/security/sudo@1.8.4.1,5.11-0.151002:20120401T175552Z
|
137
|
+
PKG_STATUS
|
138
|
+
@provider.should_receive(:run_command_with_systems_locale).with({
|
139
|
+
:command => "pkg install -q security/sudo@1.8.4.1"
|
140
|
+
})
|
141
|
+
@provider.install_package("security/sudo", "1.8.4.1")
|
142
|
+
end
|
143
|
+
|
144
|
+
it "should not include the human-readable version in the candidate_version" do
|
145
|
+
@stdout.replace(<<-PKG_STATUS)
|
146
|
+
Name: security/sudo
|
147
|
+
Summary: sudo - authority delegation tool
|
148
|
+
State: Not Installed
|
149
|
+
Publisher: omnios
|
150
|
+
Version: 1.8.4.1 (1.8.4p1)
|
151
|
+
Build Release: 5.11
|
152
|
+
Branch: 0.151002
|
153
|
+
Packaging Date: April 1, 2012 05:55:52 PM
|
154
|
+
Size: 2.57 MB
|
155
|
+
FMRI: pkg://omnios/security/sudo@1.8.4.1,5.11-0.151002:20120401T175552Z
|
156
|
+
PKG_STATUS
|
157
|
+
@provider.should_receive(:shell_out!).and_return(@shell_out)
|
158
|
+
@provider.load_current_resource
|
159
|
+
@current_resource.version.should be_nil
|
160
|
+
@provider.candidate_version.should eql("1.8.4.1")
|
161
|
+
end
|
162
|
+
|
163
|
+
context "using the ips_package resource" do
|
164
|
+
before do
|
165
|
+
@new_resource = Chef::Resource::IpsPackage.new("crypto/gnupg", @run_context)
|
166
|
+
@current_resource = Chef::Resource::IpsPackage.new("crypto/gnupg", @run_context)
|
167
|
+
@provider = Chef::Provider::Package::Ips.new(@new_resource, @run_context)
|
168
|
+
end
|
169
|
+
|
170
|
+
context "when accept_license is true" do
|
171
|
+
before do
|
172
|
+
@new_resource.stub!(:accept_license).and_return(true)
|
173
|
+
end
|
174
|
+
|
175
|
+
it "should run pkg install with the --accept flag" do
|
176
|
+
@provider.should_receive(:run_command_with_systems_locale).with({
|
177
|
+
:command => "pkg install -q --accept crypto/gnupg@2.0.17"
|
178
|
+
})
|
179
|
+
@provider.install_package("crypto/gnupg", "2.0.17")
|
180
|
+
end
|
181
|
+
end
|
182
|
+
end
|
183
|
+
end
|
184
|
+
|
185
|
+
context "when upgrading a package" do
|
186
|
+
it "should run pkg install with the package name and version" do
|
187
|
+
@provider.should_receive(:run_command_with_systems_locale).with({
|
188
|
+
:command => "pkg install -q crypto/gnupg@2.0.17"
|
189
|
+
})
|
190
|
+
@provider.upgrade_package("crypto/gnupg", "2.0.17")
|
191
|
+
end
|
192
|
+
end
|
193
|
+
|
194
|
+
context "when uninstalling a package" do
|
195
|
+
it "should run pkg uninstall with the package name and version" do
|
196
|
+
@provider.should_receive(:run_command_with_systems_locale).with({
|
197
|
+
:command => "pkg uninstall -q crypto/gnupg@2.0.17"
|
198
|
+
})
|
199
|
+
@provider.remove_package("crypto/gnupg", "2.0.17")
|
200
|
+
end
|
201
|
+
|
202
|
+
it "should run pkg uninstall with the package name and version and options if specified" do
|
203
|
+
@provider.should_receive(:run_command_with_systems_locale).with({
|
204
|
+
:command => "pkg --no-refresh uninstall -q crypto/gnupg@2.0.17"
|
205
|
+
})
|
206
|
+
@new_resource.stub!(:options).and_return("--no-refresh")
|
207
|
+
@provider.remove_package("crypto/gnupg", "2.0.17")
|
208
|
+
end
|
209
|
+
end
|
210
|
+
end
|