chef 11.10.0-x86-mingw32 → 11.10.2-x86-mingw32

Sign up to get free protection for your applications and to get access to all the features.
@@ -55,12 +55,14 @@ class Chef
55
55
  # Otherwise, we're rocking the regular resource call route.
56
56
  declare_resource(method_symbol, args[0], caller[0], &block)
57
57
  else
58
- super
58
+ begin
59
+ super
60
+ rescue NoMethodError
61
+ raise NoMethodError, "No resource or method named `#{method_symbol}' for #{describe_self_for_error}"
62
+ rescue NameError
63
+ raise NameError, "No resource, method, or local variable named `#{method_symbol}' for #{describe_self_for_error}"
64
+ end
59
65
  end
60
- rescue NoMethodError
61
- raise NoMethodError, "No resource or method named `#{method_symbol}' for #{describe_self_for_error}"
62
- rescue NameError
63
- raise NameError, "No resource, method, or local variable named `#{method_symbol}' for #{describe_self_for_error}"
64
66
  end
65
67
 
66
68
  def has_resource_definition?(name)
@@ -33,7 +33,7 @@ class Chef
33
33
  @file_edited = false
34
34
 
35
35
  raise ArgumentError, "File doesn't exist" unless File.exist? @original_pathname
36
- @contents = File.new(@original_pathname){ |f| f.readlines }
36
+ @contents = File.open(@original_pathname) { |f| f.readlines }
37
37
  end
38
38
 
39
39
  #search the file line by line and match each line with the given regex
@@ -1,4 +1,4 @@
1
- #
1
+ #rc
2
2
  # Author:: Daniel DeLeo (<dan@opscode.com>)
3
3
  # Copyright:: Copyright (c) 2010-2011 Opscode, Inc.
4
4
  # License:: Apache License, Version 2.0
@@ -17,7 +17,7 @@
17
17
 
18
18
  class Chef
19
19
  CHEF_ROOT = File.dirname(File.expand_path(File.dirname(__FILE__)))
20
- VERSION = '11.10.0'
20
+ VERSION = '11.10.2'
21
21
  end
22
22
 
23
23
  # NOTE: the Chef::Version class is defined in version_class.rb
@@ -20,70 +20,82 @@ require 'spec_helper'
20
20
  require 'chef/exceptions'
21
21
 
22
22
  describe Chef::Provider::Ifconfig::Debian do
23
- before do
24
- @node = Chef::Node.new
25
- @cookbook_collection = Chef::CookbookCollection.new([])
26
- @events = Chef::EventDispatch::Dispatcher.new
27
- @run_context = Chef::RunContext.new(@node, @cookbook_collection, @events)
28
- #This new_resource can be called anything --> it is not the same as in ifconfig.rb
29
- @new_resource = Chef::Resource::Ifconfig.new("10.0.0.1", @run_context)
30
- @new_resource.mask "255.255.254.0"
31
- @new_resource.metric "1"
32
- @new_resource.mtu "1500"
33
- @new_resource.device "eth0"
34
- @provider = Chef::Provider::Ifconfig::Debian.new(@new_resource, @run_context)
35
- @current_resource = Chef::Resource::Ifconfig.new("10.0.0.1", @run_context)
36
23
 
37
- status = double("Status", :exitstatus => 0)
38
- @provider.instance_variable_set("@status", status)
39
- @provider.current_resource = @current_resource
40
- @provider.stub(:load_current_resource)
41
- @provider.stub(:run_command)
24
+ let(:run_context) do
25
+ node = Chef::Node.new
26
+ cookbook_collection = Chef::CookbookCollection.new([])
27
+ events = Chef::EventDispatch::Dispatcher.new
28
+ Chef::RunContext.new(node, cookbook_collection, events)
29
+ end
42
30
 
43
- @config_filename_ifaces = "/etc/network/interfaces"
44
- @config_filename_ifcfg = "/etc/network/interfaces.d/ifcfg-#{@new_resource.device}"
31
+ let(:new_resource) do
32
+ new_resource = Chef::Resource::Ifconfig.new("10.0.0.1", run_context)
33
+ new_resource.mask "255.255.254.0"
34
+ new_resource.metric "1"
35
+ new_resource.mtu "1500"
36
+ new_resource.device "eth0"
37
+ new_resource
45
38
  end
46
39
 
40
+ let(:current_resource) { Chef::Resource::Ifconfig.new("10.0.0.1", run_context) }
41
+
42
+ let(:provider) do
43
+ status = double("Status", :exitstatus => 0)
44
+ provider = Chef::Provider::Ifconfig::Debian.new(new_resource, run_context)
45
+ provider.instance_variable_set("@status", status)
46
+ provider.current_resource = current_resource
47
+ allow(provider).to receive(:load_current_resource)
48
+ allow(provider).to receive(:run_command)
49
+ provider
50
+ end
51
+
52
+ let(:config_filename_ifaces) { "/etc/network/interfaces" }
53
+
54
+ let(:config_filename_ifcfg) { "/etc/network/interfaces.d/ifcfg-#{new_resource.device}" }
55
+
47
56
  describe "generate_config for action_add" do
48
- before do
49
- @config_file_ifaces = StringIO.new
50
- @config_file_ifcfg = StringIO.new
51
- FileUtils.should_receive(:cp)
52
- File.should_receive(:new).with(@config_filename_ifaces).and_return(StringIO.new)
53
- File.should_receive(:open).with(@config_filename_ifaces, "w").and_yield(@config_file_ifaces)
54
- File.should_receive(:new).with(@config_filename_ifcfg, "w").and_return(@config_file_ifcfg)
55
- File.should_receive(:exist?).with(@config_filename_ifaces).and_return(true)
56
- end
57
-
58
- it "should create network-scripts directory" do
59
- File.should_receive(:directory?).with(File.dirname(@config_filename_ifcfg)).and_return(false)
60
- Dir.should_receive(:mkdir).with(File.dirname(@config_filename_ifcfg))
61
- @provider.run_action(:add)
62
- end
63
-
64
- it "should write configure network-scripts directory" do
65
- File.should_receive(:directory?).with(File.dirname(@config_filename_ifcfg)).and_return(true)
66
- @provider.run_action(:add)
67
- @config_file_ifaces.string.should match(/^\s*source\s+\/etc\/network\/interfaces[.]d\/[*]\s*$/)
68
- end
69
-
70
- it "should write a network-script" do
71
- File.should_receive(:directory?).with(File.dirname(@config_filename_ifcfg)).and_return(true)
72
- @provider.run_action(:add)
73
- @config_file_ifcfg.string.should match(/^iface eth0 inet static\s*$/)
74
- @config_file_ifcfg.string.should match(/^\s+address 10\.0\.0\.1\s*$/)
75
- @config_file_ifcfg.string.should match(/^\s+netmask 255\.255\.254\.0\s*$/)
76
- end
57
+
58
+ let(:config_file_ifaces) { StringIO.new }
59
+
60
+ let(:config_file_ifcfg) { StringIO.new }
61
+
62
+ before do
63
+ expect(FileUtils).to receive(:cp)
64
+ expect(File).to receive(:open).with(config_filename_ifaces).and_return(StringIO.new)
65
+ expect(File).to receive(:open).with(config_filename_ifaces, "w").and_yield(config_file_ifaces)
66
+ expect(File).to receive(:new).with(config_filename_ifcfg, "w").and_return(config_file_ifcfg)
67
+ expect(File).to receive(:exist?).with(config_filename_ifaces).and_return(true)
68
+ end
69
+
70
+ it "should create network-scripts directory" do
71
+ expect(File).to receive(:directory?).with(File.dirname(config_filename_ifcfg)).and_return(false)
72
+ expect(Dir).to receive(:mkdir).with(File.dirname(config_filename_ifcfg))
73
+ provider.run_action(:add)
74
+ end
75
+
76
+ it "should write configure network-scripts directory" do
77
+ expect(File).to receive(:directory?).with(File.dirname(config_filename_ifcfg)).and_return(true)
78
+ provider.run_action(:add)
79
+ expect(config_file_ifaces.string).to match(/^\s*source\s+\/etc\/network\/interfaces[.]d\/[*]\s*$/)
80
+ end
81
+
82
+ it "should write a network-script" do
83
+ expect(File).to receive(:directory?).with(File.dirname(config_filename_ifcfg)).and_return(true)
84
+ provider.run_action(:add)
85
+ expect(config_file_ifcfg.string).to match(/^iface eth0 inet static\s*$/)
86
+ expect(config_file_ifcfg.string).to match(/^\s+address 10\.0\.0\.1\s*$/)
87
+ expect(config_file_ifcfg.string).to match(/^\s+netmask 255\.255\.254\.0\s*$/)
88
+ end
77
89
  end
78
90
 
79
91
  describe "delete_config for action_delete" do
80
92
 
81
93
  it "should delete network-script if it exists" do
82
- @current_resource.device @new_resource.device
83
- File.should_receive(:exist?).with(@config_filename_ifcfg).and_return(true)
84
- FileUtils.should_receive(:rm_f).with(@config_filename_ifcfg, :verbose => false)
94
+ current_resource.device new_resource.device
95
+ expect(File).to receive(:exist?).with(config_filename_ifcfg).and_return(true)
96
+ expect(FileUtils).to receive(:rm_f).with(config_filename_ifcfg, :verbose => false)
85
97
 
86
- @provider.run_action(:delete)
98
+ provider.run_action(:delete)
87
99
  end
88
100
  end
89
101
  end
@@ -202,6 +202,19 @@ describe Chef::Recipe do
202
202
 
203
203
  end
204
204
 
205
+ describe "when creating a resource that contains an error in the attributes block" do
206
+
207
+ it "does not obfuscate the error source" do
208
+ lambda do
209
+ @recipe.zen_master("klopp") do
210
+ this_method_doesnt_exist
211
+ end
212
+ end.should raise_error(NoMethodError, "undefined method `this_method_doesnt_exist' for Chef::Resource::ZenMaster")
213
+
214
+ end
215
+
216
+ end
217
+
205
218
  describe "resource definitions" do
206
219
  it "should execute defined resources" do
207
220
  crow_define = Chef::ResourceDefinition.new
@@ -20,116 +20,169 @@ require 'spec_helper'
20
20
 
21
21
  describe Chef::Util::FileEdit do
22
22
 
23
- before(:each) do
23
+ let(:starting_content) do
24
+ <<-EOF
25
+ 127.0.0.1 localhost
26
+ 255.255.255.255 broadcasthost
27
+ ::1 localhost
28
+ fe80::1%lo0 localhost
29
+ EOF
30
+ end
31
+
32
+ let(:localhost_replaced) do
33
+ <<-EOF
34
+ 127.0.0.1 replacement
35
+ 255.255.255.255 broadcasthost
36
+ ::1 replacement
37
+ fe80::1%lo0 replacement
38
+ EOF
39
+ end
40
+
41
+ let(:localhost_line_replaced) do
42
+ <<-EOF
43
+ replacement line
44
+ 255.255.255.255 broadcasthost
45
+ replacement line
46
+ replacement line
47
+ EOF
48
+ end
49
+
50
+ let(:localhost_deleted) do
51
+ # sensitive to deliberate trailing whitespace
52
+ "127.0.0.1 \n255.255.255.255 broadcasthost\n::1 \nfe80::1%lo0 \n"
53
+ end
54
+
55
+ let(:localhost_line_deleted) do
56
+ <<-EOF
57
+ 255.255.255.255 broadcasthost
58
+ EOF
59
+ end
60
+
61
+ let(:append_after_all_localhost) do
62
+ <<-EOF
63
+ 127.0.0.1 localhost
64
+ new line inserted
65
+ 255.255.255.255 broadcasthost
66
+ ::1 localhost
67
+ new line inserted
68
+ fe80::1%lo0 localhost
69
+ new line inserted
70
+ EOF
71
+ end
24
72
 
25
- @hosts_content=<<-HOSTS
73
+ let(:append_after_content) do
74
+ <<-EOF
26
75
  127.0.0.1 localhost
27
76
  255.255.255.255 broadcasthost
28
77
  ::1 localhost
29
78
  fe80::1%lo0 localhost
30
- HOSTS
79
+ new line inserted
80
+ EOF
81
+ end
31
82
 
32
- @tempfile = Tempfile.open('file_edit_spec')
33
- @tempfile.write(@hosts_content)
34
- @tempfile.close
35
- @fedit = Chef::Util::FileEdit.new(@tempfile.path)
83
+ let(:target_file) do
84
+ f = Tempfile.open('file_edit_spec')
85
+ f.write(starting_content)
86
+ f.close
87
+ f
36
88
  end
37
89
 
90
+ let(:fedit) { Chef::Util::FileEdit.new(target_file.path) }
91
+
38
92
  after(:each) do
39
- @tempfile && @tempfile.close!
93
+ target_file.close!
40
94
  end
41
95
 
42
96
  describe "initialiize" do
43
97
  it "should create a new Chef::Util::FileEdit object" do
44
- Chef::Util::FileEdit.new(@tempfile.path).should be_kind_of(Chef::Util::FileEdit)
98
+ expect(fedit).to be_instance_of(Chef::Util::FileEdit)
45
99
  end
46
100
 
47
101
  it "should throw an exception if the input file does not exist" do
48
- lambda{Chef::Util::FileEdit.new("nonexistfile")}.should raise_error
102
+ expect{Chef::Util::FileEdit.new("nonexistfile")}.to raise_error(ArgumentError)
49
103
  end
50
104
 
51
- it "should throw an exception if the input file is blank" do
52
- lambda do
53
- Chef::Util::FileEdit.new(File.join(CHEF_SPEC_DATA, "filedit", "blank"))
54
- end.should raise_error
105
+ # CHEF-5018: people have monkey patched this and it has accidentally been broken
106
+ it "should read the contents into memory as an array" do
107
+ expect(fedit.send(:contents)).to be_instance_of(Array)
55
108
  end
56
109
  end
57
110
 
111
+ describe "when the file is blank" do
112
+ let(:hosts_content) { "" }
113
+
114
+ it "should not throw an exception" do
115
+ expect{ fedit }.not_to raise_error
116
+ end
117
+ end
118
+
119
+ def edited_file_contents
120
+ IO.read(target_file.path)
121
+ end
122
+
58
123
  describe "search_file_replace" do
59
124
  it "should accept regex passed in as a string (not Regexp object) and replace the match if there is one" do
60
- @fedit.search_file_replace("localhost", "replacement")
61
- @fedit.write_file
62
- newfile = File.new(@tempfile.path).readlines
63
- newfile[0].should match(/replacement/)
125
+ fedit.search_file_replace("localhost", "replacement")
126
+ fedit.write_file
127
+ expect(edited_file_contents).to eq(localhost_replaced)
64
128
  end
65
129
 
66
130
  it "should accept regex passed in as a Regexp object and replace the match if there is one" do
67
- @fedit.search_file_replace(/localhost/, "replacement")
68
- @fedit.write_file
69
- newfile = File.new(@tempfile.path).readlines
70
- newfile[0].should match(/replacement/)
131
+ fedit.search_file_replace(/localhost/, "replacement")
132
+ fedit.write_file
133
+ expect(edited_file_contents).to eq(localhost_replaced)
71
134
  end
72
135
 
73
136
  it "should do nothing if there isn't a match" do
74
- @fedit.search_file_replace(/pattern/, "replacement")
75
- @fedit.write_file
76
- newfile = File.new(@tempfile.path).readlines
77
- newfile[0].should_not match(/replacement/)
137
+ fedit.search_file_replace(/pattern/, "replacement")
138
+ fedit.write_file
139
+ expect(edited_file_contents).to eq(starting_content)
78
140
  end
79
141
  end
80
142
 
81
143
  describe "search_file_replace_line" do
82
144
  it "should search for match and replace the whole line" do
83
- @fedit.search_file_replace_line(/localhost/, "replacement line")
84
- @fedit.write_file
85
- newfile = File.new(@tempfile.path).readlines
86
- newfile[0].should match(/replacement/)
87
- newfile[0].should_not match(/127/)
145
+ fedit.search_file_replace_line(/localhost/, "replacement line")
146
+ fedit.write_file
147
+ expect(edited_file_contents).to eq(localhost_line_replaced)
88
148
  end
89
149
  end
90
150
 
91
151
  describe "search_file_delete" do
92
152
  it "should search for match and delete the match" do
93
- @fedit.search_file_delete(/localhost/)
94
- @fedit.write_file
95
- newfile = File.new(@tempfile.path).readlines
96
- newfile[0].should_not match(/localhost/)
97
- newfile[0].should match(/127/)
153
+ fedit.search_file_delete(/localhost/)
154
+ fedit.write_file
155
+ expect(edited_file_contents).to eq(localhost_deleted)
98
156
  end
99
157
  end
100
158
 
101
159
  describe "search_file_delete_line" do
102
160
  it "should search for match and delete the matching line" do
103
- @fedit.search_file_delete_line(/localhost/)
104
- @fedit.write_file
105
- newfile = File.new(@tempfile.path).readlines
106
- newfile[0].should_not match(/localhost/)
107
- newfile[0].should match(/broadcasthost/)
161
+ fedit.search_file_delete_line(/localhost/)
162
+ fedit.write_file
163
+ expect(edited_file_contents).to eq(localhost_line_deleted)
108
164
  end
109
165
  end
110
166
 
111
167
  describe "insert_line_after_match" do
112
168
  it "should search for match and insert the given line after the matching line" do
113
- @fedit.insert_line_after_match(/localhost/, "new line inserted")
114
- @fedit.write_file
115
- newfile = File.new(@tempfile.path).readlines
116
- newfile[1].should match(/new/)
169
+ fedit.insert_line_after_match(/localhost/, "new line inserted")
170
+ fedit.write_file
171
+ expect(edited_file_contents).to eq(append_after_all_localhost)
117
172
  end
118
173
  end
119
174
 
120
175
  describe "insert_line_if_no_match" do
121
176
  it "should search for match and insert the given line if no line match" do
122
- @fedit.insert_line_if_no_match(/pattern/, "new line inserted")
123
- @fedit.write_file
124
- newfile = File.new(@tempfile.path).readlines
125
- newfile.last.should match(/new/)
177
+ fedit.insert_line_if_no_match(/pattern/, "new line inserted")
178
+ fedit.write_file
179
+ expect(edited_file_contents).to eq(append_after_content)
126
180
  end
127
181
 
128
182
  it "should do nothing if there is a match" do
129
- @fedit.insert_line_if_no_match(/localhost/, "replacement")
130
- @fedit.write_file
131
- newfile = File.new(@tempfile.path).readlines
132
- newfile[1].should_not match(/replacement/)
183
+ fedit.insert_line_if_no_match(/localhost/, "replacement")
184
+ fedit.write_file
185
+ expect(edited_file_contents).to eq(starting_content)
133
186
  end
134
187
  end
135
188
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chef
3
3
  version: !ruby/object:Gem::Version
4
- version: 11.10.0
4
+ version: 11.10.2
5
5
  prerelease:
6
6
  platform: x86-mingw32
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-02-06 00:00:00.000000000 Z
12
+ date: 2014-02-18 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: mixlib-config