Skip to content

Commit baee3d0

Browse files
committed
Merge branch 'master' into cabeca/chef-208
2 parents 7475001 + 65d1a6c commit baee3d0

12 files changed

Lines changed: 209 additions & 30 deletions

File tree

chef-server-slice/Rakefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ Rake::GemPackageTask.new(spec) do |pkg|
4747
end
4848

4949
desc "Install the gem"
50-
task :install do
50+
task :install => :package do
5151
sh %{sudo gem install pkg/#{GEM_NAME}-#{CHEF_SERVER_VERSION} --no-rdoc --no-ri}
5252
end
5353

chef-server-slice/config/init.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
# code and views.
2222
#
2323

24-
merb_gems_version = "1.0.10"
24+
merb_gems_version = "> 1.0"
2525
dependency "merb-haml", merb_gems_version
2626
dependency "merb-assets", merb_gems_version
2727
dependency "merb-helpers", merb_gems_version

chef-server/bin/chef-server

100644100755
File mode changed.

chef-server/config/dependencies.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# dependencies are generated using a strict version, don't forget to edit the dependency versions when upgrading.
2-
merb_gems_version = "1.0.10"
2+
merb_gems_version = "> 1.0"
33

44
# For more information about each component, please read http://wiki.merbivore.com/faqs/merb_components
55
dependency "merb-core", merb_gems_version

chef/lib/chef/config.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ class Config
6363
:remotefile_url => "http://localhost:4000",
6464
:search_url => "http://localhost:4000",
6565
:couchdb_database => "chef",
66+
:couchdb_version => nil,
6667
:openid_store_couchdb => false,
6768
:openid_cstore_couchdb => false,
6869
:openid_store_path => "/var/chef/openid/db",

chef/lib/chef/couchdb.rb

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,11 @@
2525
class Chef
2626
class CouchDB
2727
include Chef::Mixin::ParamsValidate
28-
28+
2929
def initialize(url=nil)
3030
url ||= Chef::Config[:couchdb_url]
3131
@rest = Chef::REST.new(url)
32+
Chef::Config[:couchdb_version] ||= @rest.run_request(:GET, URI.parse(@rest.url + "/"), false, 10, false)["version"].gsub(/-.+/,"").to_f
3233
end
3334

3435
def create_db
@@ -119,9 +120,9 @@ def list(view, inflate=false)
119120
}
120121
)
121122
if inflate
122-
@rest.get_rest("#{Chef::Config[:couchdb_database]}/_view/#{view}/all")
123+
@rest.get_rest(view_uri(view, "all"))
123124
else
124-
@rest.get_rest("#{Chef::Config[:couchdb_database]}/_view/#{view}/all_id")
125+
@rest.get_rest(view_uri(view, "all_id"))
125126
end
126127
end
127128

@@ -145,9 +146,19 @@ def has_key?(obj_type, name)
145146
end
146147

147148
private
148-
def safe_name(name)
149-
name.gsub(/\./, "_")
149+
150+
def safe_name(name)
151+
name.gsub(/\./, "_")
152+
end
153+
154+
def view_uri(design, view)
155+
case Chef::Config[:couchdb_version]
156+
when 0.9
157+
"#{Chef::Config[:couchdb_database]}/_design/#{design}/_view/#{view}"
158+
when 0.8
159+
"#{Chef::Config[:couchdb_database]}/_view/#{design}/#{view}"
150160
end
161+
end
151162

152163
end
153164
end

chef/lib/chef/provider/file.rb

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,12 @@ def negative_complement(big)
3737
end
3838
big
3939
end
40+
41+
def octal_mode(mode)
42+
((mode.respond_to?(:oct) ? mode.oct : mode.to_i) & 007777)
43+
end
4044

41-
private :negative_complement
45+
private :negative_complement, :octal_mode
4246

4347
def load_current_resource
4448
@current_resource = Chef::Resource::File.new(@new_resource.name)
@@ -47,7 +51,7 @@ def load_current_resource
4751
cstats = ::File.stat(@current_resource.path)
4852
@current_resource.owner(cstats.uid)
4953
@current_resource.group(cstats.gid)
50-
@current_resource.mode("%o" % (cstats.mode & 007777))
54+
@current_resource.mode(octal_mode(cstats.mode))
5155
@current_resource.checksum(checksum(@current_resource.path))
5256
end
5357
@current_resource
@@ -104,17 +108,17 @@ def set_group
104108
def compare_mode
105109
case @new_resource.mode
106110
when /^\d+$/, Integer
107-
real_mode = sprintf("%o" % (@new_resource.mode & 007777))
108-
real_mode.to_i == @current_resource.mode.to_i
111+
octal_mode(@new_resource.mode) == octal_mode(@current_resource.mode)
109112
else
110113
false
111114
end
112115
end
113116

114117
def set_mode
115118
unless compare_mode && @new_resource.mode != nil
116-
Chef::Log.info("Setting mode to #{sprintf("%o" % (@new_resource.mode & 007777))} for #{@new_resource}")
117-
::File.chmod(@new_resource.mode.to_i, @new_resource.path)
119+
Chef::Log.info("Setting mode to #{sprintf("%o" % octal_mode(@new_resource.mode))} for #{@new_resource}")
120+
# CHEF-174, bad mojo around treating integers as octal. If a string is passed, we try to do the "right" thing
121+
::File.chmod(octal_mode(@new_resource.mode), @new_resource.path)
118122
@new_resource.updated = true
119123
end
120124
end
@@ -125,9 +129,9 @@ def action_create
125129
::File.open(@new_resource.path, "w+") { |f| }
126130
@new_resource.updated = true
127131
end
128-
set_owner if @new_resource.owner != nil
129-
set_group if @new_resource.group != nil
130-
set_mode if @new_resource.mode != nil
132+
set_owner unless @new_resource.owner.nil?
133+
set_group unless @new_resource.group.nil?
134+
set_mode unless @new_resource.mode.nil?
131135
end
132136

133137
def action_create_if_missing

chef/lib/chef/resource/file.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def mode(arg=nil)
5959
set_or_return(
6060
:mode,
6161
arg,
62-
:regex => /^\d{3,4}$/
62+
:regex => /^0?\d{3,4}$/
6363
)
6464
end
6565

@@ -81,4 +81,4 @@ def path(arg=nil)
8181

8282
end
8383
end
84-
end
84+
end

chef/spec/unit/couchdb_spec.rb

Lines changed: 87 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,26 @@
1919
require File.expand_path(File.join(File.dirname(__FILE__), "..", "spec_helper"))
2020

2121
describe Chef::CouchDB, "new" do
22+
before do
23+
@mock_rest = mock("Chef::REST", :null_object => true)
24+
@mock_rest.stub!(:run_request).and_return({"couchdb" => "Welcome", "version" =>"0.9.0"})
25+
@mock_rest.stub!(:url).and_return("http://localhost:5984")
26+
Chef::REST.stub!(:new).and_return(@mock_rest)
27+
end
28+
2229
it "should create a new Chef::REST object from the default url" do
2330
Chef::Config[:couchdb_url] = "http://monkey"
24-
Chef::REST.should_receive(:new).with("http://monkey").and_return(true)
31+
Chef::REST.should_receive(:new).with("http://monkey")
2532
Chef::CouchDB.new
2633
end
2734

2835
it "should create a new Chef::REST object from a provided url" do
29-
Chef::REST.should_receive(:new).with("http://monkeypants").and_return(true)
36+
Chef::REST.should_receive(:new).with("http://monkeypants")
3037
Chef::CouchDB.new("http://monkeypants")
38+
end
39+
40+
it "should parse the CouchDB version number" do
41+
3142
end
3243
end
3344

@@ -185,18 +196,42 @@ def do_delete(rev=nil)
185196

186197
describe Chef::CouchDB, "list" do
187198
before(:each) do
188-
@mock_rest = mock("Chef::REST", :null_object => true)
199+
@mock_rest = mock("Chef::REST", :null_object => true, :url => "http://monkeypants")
189200
Chef::REST.stub!(:new).and_return(@mock_rest)
201+
@couch = Chef::CouchDB.new("http://monkeypants")
202+
Chef::Config.stub!(:[]).with(:couchdb_database).and_return("chef")
190203
end
191204

192-
it "should get the view for all objects if inflate is true" do
193-
@mock_rest.should_receive(:get_rest).with("chef/_view/node/all").and_return(true)
194-
Chef::CouchDB.new.list("node", true)
205+
describe "on couchdb 0.8" do
206+
before do
207+
Chef::Config.stub!(:[]).with(:couchdb_version).and_return(0.8)
208+
end
209+
210+
it "should get the view for all objects if inflate is true" do
211+
@mock_rest.should_receive(:get_rest).with("chef/_view/node/all").and_return(true)
212+
@couch.list("node", true)
213+
end
214+
215+
it "should get the view for just the object id's if inflate is false" do
216+
@mock_rest.should_receive(:get_rest).with("chef/_view/node/all_id").and_return(true)
217+
@couch.list("node", false)
218+
end
195219
end
196-
197-
it "should get the view for just the object id's if inflate is false" do
198-
@mock_rest.should_receive(:get_rest).with("chef/_view/node/all_id").and_return(true)
199-
Chef::CouchDB.new.list("node", false)
220+
221+
describe "on couchdb 0.9" do
222+
before do
223+
Chef::Config.stub!(:[]).with(:couchdb_version).and_return(0.9)
224+
end
225+
226+
it "should get the view for all objects if inflate is true" do
227+
@mock_rest.should_receive(:get_rest).with("chef/_design/node/_view/all").and_return(true)
228+
@couch.list("node", true)
229+
end
230+
231+
it "should get the view for just the object id's if inflate is false" do
232+
@mock_rest.should_receive(:get_rest).with("chef/_design/node/_view/all_id").and_return(true)
233+
@couch.list("node", false)
234+
end
200235
end
201236
end
202237

@@ -216,3 +251,45 @@ def do_delete(rev=nil)
216251
Chef::CouchDB.new.has_key?("node", "bob").should eql(false)
217252
end
218253
end
254+
255+
describe Chef::CouchDB, "safe_name" do
256+
before do
257+
@couchdb = mock("Chef::CouchDB", :null_object => true)
258+
Chef::CouchDB.stub!(:new).and_return(@couchdb)
259+
end
260+
261+
it "should convert the name to a safe name" do
262+
@couchdb.should_receive(:safe_name).with("asdf.lol.com").and_return("asdf_lol_com")
263+
@couchdb.safe_name("asdf.lol.com")
264+
end
265+
end
266+
267+
describe Chef::CouchDB, "view_uri" do
268+
before do
269+
@couchdb = mock("Chef::CouchDB", :null_object => true)
270+
Chef::CouchDB.stub!(:new).and_return(@couchdb)
271+
Chef::Config.stub!(:[]).with(:couchdb_database).and_return("chef")
272+
end
273+
274+
describe "on couchdb 0.8" do
275+
before do
276+
Chef::Config.stub!(:[]).with(:couchdb_version).and_return(0.8)
277+
end
278+
279+
it "should output an appropriately formed view URI" do
280+
@couchdb.should_receive(:view_uri).with("nodes", "all").and_return("chef/_view/nodes/all")
281+
@couchdb.view_uri("nodes", "all")
282+
end
283+
end
284+
285+
describe "on couchdb 0.9" do
286+
before do
287+
Chef::Config.stub!(:[]).with(:couchdb_version).and_return(0.9)
288+
end
289+
290+
it "should output an appropriately formed view URI" do
291+
@couchdb.should_receive(:view_uri).with("nodes", "all").and_return("chef/_design/nodes/_view/all")
292+
@couchdb.view_uri("nodes", "all")
293+
end
294+
end
295+
end
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
#
2+
# Cookbook Name:: files
3+
# Recipe:: default
4+
#
5+
# Copyright 2009, Opscode
6+
#
7+
# Licensed under the Apache License, Version 2.0 (the "License");
8+
# you may not use this file except in compliance with the License.
9+
# You may obtain a copy of the License at
10+
#
11+
# http://www.apache.org/licenses/LICENSE-2.0
12+
#
13+
# Unless required by applicable law or agreed to in writing, software
14+
# distributed under the License is distributed on an "AS IS" BASIS,
15+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
# See the License for the specific language governing permissions and
17+
# limitations under the License.
18+
#
19+
20+
file "#{node[:tmpdir]}/octal0644.txt" do
21+
owner 'nobody'
22+
mode 0644
23+
action :create
24+
end
25+
26+
file "#{node[:tmpdir]}/octal2644.txt" do
27+
owner 'nobody'
28+
mode 02644
29+
action :create
30+
end
31+
32+
file "#{node[:tmpdir]}/decimal644.txt" do
33+
owner 'nobody'
34+
mode 644
35+
action :create
36+
end
37+
38+
file "#{node[:tmpdir]}/decimal2644.txt" do
39+
owner 'nobody'
40+
mode 2644
41+
action :create
42+
end
43+
44+
file "#{node[:tmpdir]}/string644.txt" do
45+
owner 'nobody'
46+
mode "644"
47+
action :create
48+
end
49+
50+
file "#{node[:tmpdir]}/string0644.txt" do
51+
owner 'nobody'
52+
mode "0644"
53+
action :create
54+
end
55+
56+
file "#{node[:tmpdir]}/string2644.txt" do
57+
owner 'nobody'
58+
mode "2644"
59+
action :create
60+
end
61+

0 commit comments

Comments
 (0)