chef 0.8.10 → 0.8.14

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of chef might be problematic. Click here for more details.

Files changed (105) hide show
  1. data/bin/chef-client +2 -2
  2. data/bin/chef-solo +1 -2
  3. data/bin/knife +1 -2
  4. data/bin/shef +2 -5
  5. data/lib/chef.rb +11 -7
  6. data/lib/chef/application.rb +25 -20
  7. data/lib/chef/application/client.rb +12 -7
  8. data/lib/chef/application/knife.rb +7 -1
  9. data/lib/chef/application/solo.rb +1 -1
  10. data/lib/chef/applications.rb +4 -0
  11. data/lib/chef/cache/checksum.rb +7 -6
  12. data/lib/chef/certificate.rb +2 -2
  13. data/lib/chef/client.rb +28 -4
  14. data/lib/chef/config.rb +4 -3
  15. data/lib/chef/cookbook_loader.rb +6 -1
  16. data/lib/chef/daemon.rb +2 -0
  17. data/lib/chef/data_bag_item.rb +2 -1
  18. data/lib/chef/exceptions.rb +5 -0
  19. data/lib/chef/file_cache.rb +18 -18
  20. data/lib/chef/index_queue/indexable.rb +5 -3
  21. data/lib/chef/knife.rb +45 -13
  22. data/lib/chef/knife/client_list.rb +1 -1
  23. data/lib/chef/knife/client_show.rb +1 -1
  24. data/lib/chef/knife/configure.rb +47 -36
  25. data/lib/chef/knife/cookbook_list.rb +1 -1
  26. data/lib/chef/knife/cookbook_metadata.rb +22 -27
  27. data/lib/chef/knife/cookbook_metadata_from_file.rb +40 -0
  28. data/lib/chef/knife/cookbook_show.rb +2 -2
  29. data/lib/chef/knife/cookbook_site_download.rb +57 -0
  30. data/lib/chef/knife/cookbook_site_list.rb +55 -0
  31. data/lib/chef/knife/cookbook_site_search.rb +50 -0
  32. data/lib/chef/knife/cookbook_site_show.rb +56 -0
  33. data/lib/chef/knife/cookbook_site_vendor.rb +114 -0
  34. data/lib/chef/knife/cookbook_test.rb +103 -0
  35. data/lib/chef/knife/cookbook_upload.rb +29 -38
  36. data/lib/chef/knife/data_bag_edit.rb +1 -1
  37. data/lib/chef/knife/data_bag_list.rb +2 -2
  38. data/lib/chef/knife/data_bag_show.rb +1 -1
  39. data/lib/chef/knife/ec2_instance_data.rb +1 -1
  40. data/lib/chef/knife/index_rebuild.rb +2 -2
  41. data/lib/chef/knife/node_from_file.rb +1 -1
  42. data/lib/chef/knife/node_list.rb +2 -2
  43. data/lib/chef/knife/node_run_list_add.rb +1 -1
  44. data/lib/chef/knife/node_run_list_remove.rb +1 -1
  45. data/lib/chef/knife/node_show.rb +1 -1
  46. data/lib/chef/knife/rackspace_server_create.rb +156 -0
  47. data/lib/chef/knife/rackspace_server_delete.rb +57 -0
  48. data/lib/chef/knife/rackspace_server_list.rb +59 -0
  49. data/lib/chef/knife/role_from_file.rb +1 -1
  50. data/lib/chef/knife/role_list.rb +1 -1
  51. data/lib/chef/knife/role_show.rb +1 -1
  52. data/lib/chef/knife/search.rb +1 -1
  53. data/lib/chef/knife/ssh.rb +21 -4
  54. data/lib/chef/knife/terremark_server_create.rb +152 -0
  55. data/lib/chef/knife/terremark_server_delete.rb +87 -0
  56. data/lib/chef/knife/terremark_server_list.rb +77 -0
  57. data/lib/chef/mixin/command.rb +11 -9
  58. data/lib/chef/mixin/params_validate.rb +1 -1
  59. data/lib/chef/mixin/recipe_definition_dsl_core.rb +4 -1
  60. data/lib/chef/mixin/template.rb +6 -5
  61. data/lib/chef/mixin/xml_escape.rb +3 -3
  62. data/lib/chef/mixins.rb +16 -0
  63. data/lib/chef/node.rb +53 -52
  64. data/lib/chef/openid_registration.rb +0 -1
  65. data/lib/chef/platform.rb +171 -137
  66. data/lib/chef/provider.rb +2 -2
  67. data/lib/chef/provider/cron.rb +22 -22
  68. data/lib/chef/provider/deploy/revision.rb +5 -1
  69. data/lib/chef/provider/erl_call.rb +2 -2
  70. data/lib/chef/provider/file.rb +44 -23
  71. data/lib/chef/provider/group/dscl.rb +6 -4
  72. data/lib/chef/provider/mdadm.rb +0 -4
  73. data/lib/chef/provider/mount/mount.rb +20 -8
  74. data/lib/chef/provider/package.rb +1 -1
  75. data/lib/chef/provider/package/freebsd.rb +22 -18
  76. data/lib/chef/provider/package/rubygems.rb +7 -10
  77. data/lib/chef/provider/remote_directory.rb +15 -0
  78. data/lib/chef/provider/remote_file.rb +73 -50
  79. data/lib/chef/provider/script.rb +10 -8
  80. data/lib/chef/provider/service/windows.rb +129 -0
  81. data/lib/chef/provider/subversion.rb +1 -1
  82. data/lib/chef/provider/template.rb +51 -50
  83. data/lib/chef/providers.rb +80 -0
  84. data/lib/chef/recipe.rb +2 -4
  85. data/lib/chef/resource.rb +21 -7
  86. data/lib/chef/resource/cron.rb +14 -5
  87. data/lib/chef/resource/deploy.rb +52 -45
  88. data/lib/chef/resource/execute.rb +1 -1
  89. data/lib/chef/resource/file.rb +16 -8
  90. data/lib/chef/resource/mount.rb +1 -1
  91. data/lib/chef/resource/remote_directory.rb +19 -10
  92. data/lib/chef/resource/scm.rb +23 -16
  93. data/lib/chef/resource/service.rb +10 -1
  94. data/lib/chef/resources.rb +60 -0
  95. data/lib/chef/rest.rb +234 -189
  96. data/lib/chef/rest/auth_credentials.rb +78 -0
  97. data/lib/chef/{application/server.rb → rest/cookie_jar.rb} +18 -6
  98. data/lib/chef/rest/rest_request.rb +151 -0
  99. data/lib/chef/role.rb +38 -46
  100. data/lib/chef/streaming_cookbook_uploader.rb +8 -2
  101. data/lib/chef/tasks/chef_repo.rake +14 -4
  102. data/lib/chef/util/file_edit.rb +0 -1
  103. data/lib/chef/webui_user.rb +0 -1
  104. metadata +46 -9
  105. data/distro/suse/etc/init.d/chef-client +0 -121
@@ -0,0 +1,55 @@
1
+ #
2
+ # Author:: Adam Jacob (<adam@opscode.com>)
3
+ # Copyright:: Copyright (c) 2009 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 'chef/knife'
20
+
21
+ class Chef
22
+ class Knife
23
+ class CookbookSiteList < Knife
24
+
25
+ banner "Sub-Command: cookbook site list (options)"
26
+
27
+ option :with_uri,
28
+ :short => "-w",
29
+ :long => "--with-uri",
30
+ :description => "Show corresponding URIs"
31
+
32
+ def run
33
+ output(format_list_for_display(get_cookbook_list))
34
+ end
35
+
36
+ def get_cookbook_list(items=10, start=0, cookbook_collection={})
37
+ cookbooks_url = "http://cookbooks.opscode.com/api/v1/cookbooks?items=#{items}&start=#{start}"
38
+ cr = rest.get_rest(cookbooks_url)
39
+ cr["items"].each do |cookbook|
40
+ cookbook_collection[cookbook["cookbook_name"]] = cookbook
41
+ end
42
+ new_start = start + cr["items"].length
43
+ if new_start < cr["total"]
44
+ get_cookbook_list(items, new_start, cookbook_collection)
45
+ else
46
+ cookbook_collection
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
52
+
53
+
54
+
55
+
@@ -0,0 +1,50 @@
1
+ # Author:: Adam Jacob (<adam@opscode.com>)
2
+ # Copyright:: Copyright (c) 2009 Opscode, Inc.
3
+ # License:: Apache License, Version 2.0
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+ #
17
+
18
+ require 'chef/knife'
19
+
20
+ class Chef
21
+ class Knife
22
+ class CookbookSiteSearch < Knife
23
+
24
+ banner "Sub-Command: cookbook site search QUERY (options)"
25
+
26
+ def run
27
+ output(search_cookbook(name_args[0]))
28
+ end
29
+
30
+ def search_cookbook(query, items=10, start=0, cookbook_collection={})
31
+ cookbooks_url = "http://cookbooks.opscode.com/api/v1/search?q=#{query}&items=#{items}&start=#{start}"
32
+ cr = rest.get_rest(cookbooks_url)
33
+ cr["items"].each do |cookbook|
34
+ cookbook_collection[cookbook["cookbook_name"]] = cookbook
35
+ end
36
+ new_start = start + cr["items"].length
37
+ if new_start < cr["total"]
38
+ search_cookbook(query, items, new_start, cookbook_collection)
39
+ else
40
+ cookbook_collection
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
46
+
47
+
48
+
49
+
50
+
@@ -0,0 +1,56 @@
1
+ # Author:: Adam Jacob (<adam@opscode.com>)
2
+ # Copyright:: Copyright (c) 2009 Opscode, Inc.
3
+ # License:: Apache License, Version 2.0
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+ #
17
+
18
+ require 'chef/knife'
19
+
20
+ class Chef
21
+ class Knife
22
+ class CookbookSiteShow < Knife
23
+
24
+ banner "Sub-Command: cookbook site show COOKBOOK [VERSION] (options)"
25
+
26
+ def run
27
+ case @name_args.length
28
+ when 1
29
+ cookbook_data = rest.get_rest("http://cookbooks.opscode.com/api/v1/cookbooks/#{@name_args[0]}")
30
+ when 2
31
+ cookbook_data = rest.get_rest("http://cookbooks.opscode.com/api/v1/cookbooks/#{@name_args[0]}/versions/#{name_args[1].gsub('.', '_')}")
32
+ end
33
+ output(format_for_display(cookbook_data))
34
+ end
35
+
36
+ def get_cookbook_list(items=10, start=0, cookbook_collection={})
37
+ cookbooks_url = "http://cookbooks.opscode.com/api/v1/cookbooks?items=#{items}&start=#{start}"
38
+ cr = rest.get_rest(cookbooks_url)
39
+ cr["items"].each do |cookbook|
40
+ cookbook_collection[cookbook["cookbook_name"]] = cookbook
41
+ end
42
+ new_start = start + cr["items"].length
43
+ if new_start < cr["total"]
44
+ get_cookbook_list(items, new_start, cookbook_collection)
45
+ else
46
+ cookbook_collection
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
52
+
53
+
54
+
55
+
56
+
@@ -0,0 +1,114 @@
1
+ #
2
+ # Author:: Adam Jacob (<adam@opscode.com>)
3
+ # Copyright:: Copyright (c) 2010 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 'chef/knife'
20
+ require 'chef/cookbook/metadata'
21
+
22
+ class Chef
23
+ class Knife
24
+ class CookbookSiteVendor < Knife
25
+
26
+ banner "Sub-Command: cookbook site vendor COOKBOOK [VERSION] (options)"
27
+
28
+ option :deps,
29
+ :short => "-d",
30
+ :long => "--dependencies",
31
+ :boolean => true,
32
+ :description => "Grab dependencies automatically"
33
+
34
+ def run
35
+ vendor_path = File.join(Chef::Config[:cookbook_path].first)
36
+ cookbook_path = File.join(vendor_path, name_args[0])
37
+ upstream_file = File.join(vendor_path, "#{name_args[0]}.tar.gz")
38
+ branch_name = "chef-vendor-#{name_args[0]}"
39
+
40
+ download = Chef::Knife::CookbookSiteDownload.new
41
+ download.config[:file] = upstream_file
42
+ download.name_args = name_args
43
+ download.run
44
+
45
+ Chef::Log.info("Checking out the master branch.")
46
+ Chef::Mixin::Command.run_command(:command => "git checkout master", :cwd => vendor_path)
47
+ Chef::Log.info("Checking the status of the vendor branch.")
48
+ status, branch_output, branch_error = Chef::Mixin::Command.output_of_command("git branch --no-color | grep #{branch_name}", :cwd => vendor_path)
49
+ if branch_output =~ /#{branch_name}$/m
50
+ Chef::Log.info("Vendor branch found.")
51
+ Chef::Mixin::Command.run_command(:command => "git checkout #{branch_name}", :cwd => vendor_path)
52
+ else
53
+ Chef::Log.info("Creating vendor branch.")
54
+ Chef::Mixin::Command.run_command(:command => "git checkout -b #{branch_name}", :cwd => vendor_path)
55
+ end
56
+ Chef::Log.info("Removing pre-existing version.")
57
+ Chef::Mixin::Command.run_command(:command => "rm -r #{cookbook_path}", :cwd => vendor_path) if File.directory?(cookbook_path)
58
+ Chef::Log.info("Uncompressing #{name_args[0]} version #{download.version}.")
59
+ Chef::Mixin::Command.run_command(:command => "tar zxvf #{upstream_file}", :cwd => vendor_path)
60
+ Chef::Mixin::Command.run_command(:command => "rm #{upstream_file}", :cwd => vendor_path)
61
+ Chef::Log.info("Adding changes.")
62
+ Chef::Mixin::Command.run_command(:command => "git add #{name_args[0]}", :cwd => vendor_path)
63
+
64
+ Chef::Log.info("Committing changes.")
65
+ changes = true
66
+ begin
67
+ Chef::Mixin::Command.run_command(:command => "git commit -a -m 'Import #{name_args[0]} version #{download.version}'", :cwd => vendor_path)
68
+ rescue Chef::Exceptions::Exec => e
69
+ Chef::Log.warn("Checking out the master branch.")
70
+ Chef::Log.warn("No changes from current vendor #{name_args[0]}")
71
+ Chef::Mixin::Command.run_command(:command => "git checkout master", :cwd => vendor_path)
72
+ changes = false
73
+ end
74
+
75
+ if changes
76
+ Chef::Log.info("Creating tag chef-vendor-#{name_args[0]}-#{download.version}.")
77
+ Chef::Mixin::Command.run_command(:command => "git tag -f chef-vendor-#{name_args[0]}-#{download.version}", :cwd => vendor_path)
78
+ Chef::Log.info("Checking out the master branch.")
79
+ Chef::Mixin::Command.run_command(:command => "git checkout master", :cwd => vendor_path)
80
+ Chef::Log.info("Merging changes from #{name_args[0]} version #{download.version}.")
81
+
82
+ Dir.chdir(vendor_path) do
83
+ if system("git merge #{branch_name}")
84
+ Chef::Log.info("Cookbook #{name_args[0]} version #{download.version} successfully vendored!")
85
+ else
86
+ Chef::Log.error("You have merge conflicts - please resolve manually!")
87
+ Chef::Log.error("(Hint: cd #{vendor_path}; git status)")
88
+ exit 1
89
+ end
90
+ end
91
+ end
92
+
93
+ if config[:deps]
94
+ md = Chef::Cookbook::Metadata.new
95
+ md.from_file(File.join(cookbook_path, "metadata.rb"))
96
+ md.dependencies.each do |cookbook, version_list|
97
+ # Doesn't do versions.. yet
98
+ nv = Chef::Knife::CookbookSiteVendor.new
99
+ nv.config = config
100
+ nv.name_args = [ cookbook ]
101
+ nv.run
102
+ end
103
+ end
104
+ end
105
+
106
+ end
107
+ end
108
+ end
109
+
110
+
111
+
112
+
113
+
114
+
@@ -0,0 +1,103 @@
1
+ #
2
+ #
3
+ # Author:: Adam Jacob (<adam@opscode.com>)
4
+ # Author:: Matthew Kent (<mkent@magoazul.com>)
5
+ # Copyright:: Copyright (c) 2009 Opscode, Inc.
6
+ # Copyright:: Copyright (c) 2010 Matthew Kent
7
+ # License:: Apache License, Version 2.0
8
+ #
9
+ # Licensed under the Apache License, Version 2.0 (the "License");
10
+ # you may not use this file except in compliance with the License.
11
+ # You may obtain a copy of the License at
12
+ #
13
+ # http://www.apache.org/licenses/LICENSE-2.0
14
+ #
15
+ # Unless required by applicable law or agreed to in writing, software
16
+ # distributed under the License is distributed on an "AS IS" BASIS,
17
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18
+ # See the License for the specific language governing permissions and
19
+ # limitations under the License.
20
+ #
21
+ require 'chef/knife'
22
+ require 'chef/cache/checksum'
23
+
24
+ class Chef
25
+ class Knife
26
+ class CookbookTest < Knife
27
+
28
+ banner "Sub-Command: cookbook test [COOKBOOKS...] (options)"
29
+
30
+ option :cookbook_path,
31
+ :short => "-o PATH:PATH",
32
+ :long => "--cookbook-path PATH:PATH",
33
+ :description => "A colon-separated path to look for cookbooks in",
34
+ :proc => lambda { |o| o.split(":") }
35
+
36
+ option :all,
37
+ :short => "-a",
38
+ :long => "--all",
39
+ :description => "Test all cookbooks, rather than just a single cookbook"
40
+
41
+ def run
42
+ if config[:cookbook_path]
43
+ Chef::Config[:cookbook_path] = config[:cookbook_path]
44
+ else
45
+ config[:cookbook_path] = Chef::Config[:cookbook_path]
46
+ end
47
+
48
+ if config[:all]
49
+ cl = Chef::CookbookLoader.new
50
+ cl.each do |cookbook|
51
+ test_cookbook(cookbook.name.to_s)
52
+ end
53
+ else
54
+ @name_args.each do |cb|
55
+ test_cookbook(cb)
56
+ end
57
+ end
58
+ end
59
+
60
+ def test_cookbook(cookbook)
61
+ Chef::Log.info("Running syntax check on #{cookbook}")
62
+ Array(config[:cookbook_path]).reverse.each do |path|
63
+ cookbook_dir = File.expand_path(File.join(path, cookbook))
64
+ test_ruby(cookbook_dir)
65
+ test_templates(cookbook_dir)
66
+ end
67
+ end
68
+
69
+ def test_ruby(cookbook_dir)
70
+ cache = Chef::Cache::Checksum.instance
71
+ Dir[File.join(cookbook_dir, '**', '*.rb')].each do |ruby_file|
72
+ key = cache.generate_key(ruby_file, "chef-test")
73
+ fstat = File.stat(ruby_file)
74
+
75
+ if cache.lookup_checksum(key, fstat)
76
+ Chef::Log.info("No change in checksum of #{ruby_file}")
77
+ else
78
+ Chef::Log.info("Testing #{ruby_file} for syntax errors...")
79
+ Chef::Mixin::Command.run_command(:command => "ruby -c #{ruby_file}", :output_on_failure => true)
80
+ cache.generate_checksum(key, ruby_file, fstat)
81
+ end
82
+ end
83
+ end
84
+
85
+ def test_templates(cookbook_dir)
86
+ cache = Chef::Cache::Checksum.instance
87
+ Dir[File.join(cookbook_dir, '**', '*.erb')].each do |erb_file|
88
+ key = cache.generate_key(erb_file, "chef-test")
89
+ fstat = File.stat(erb_file)
90
+
91
+ if cache.lookup_checksum(key, fstat)
92
+ Chef::Log.info("No change in checksum of #{erb_file}")
93
+ else
94
+ Chef::Log.info("Testing template #{erb_file} for syntax errors...")
95
+ Chef::Mixin::Command.run_command(:command => "sh -c 'erubis -x #{erb_file} | ruby -c'", :output_on_failure => true)
96
+ cache.generate_checksum(key, erb_file, fstat)
97
+ end
98
+ end
99
+ end
100
+
101
+ end
102
+ end
103
+ end
@@ -7,9 +7,9 @@
7
7
  # Licensed under the Apache License, Version 2.0 (the "License");
8
8
  # you may not use this file except in compliance with the License.
9
9
  # You may obtain a copy of the License at
10
- #
10
+ #
11
11
  # http://www.apache.org/licenses/LICENSE-2.0
12
- #
12
+ #
13
13
  # Unless required by applicable law or agreed to in writing, software
14
14
  # distributed under the License is distributed on an "AS IS" BASIS,
15
15
  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -19,7 +19,6 @@
19
19
 
20
20
  require 'chef/knife'
21
21
  require 'chef/streaming_cookbook_uploader'
22
- require 'chef/cache/checksum'
23
22
 
24
23
  class Chef
25
24
  class Knife
@@ -38,14 +37,16 @@ class Chef
38
37
  :long => "--all",
39
38
  :description => "Upload all cookbooks, rather than just a single cookbook"
40
39
 
41
- def run
40
+ def run
41
+ Chef::Log.debug "Uploading cookbooks from #{config[:cookbook_path]}"
42
+
42
43
  if config[:cookbook_path]
43
44
  Chef::Config[:cookbook_path] = config[:cookbook_path]
44
45
  else
45
46
  config[:cookbook_path] = Chef::Config[:cookbook_path]
46
47
  end
47
48
 
48
- if config[:all]
49
+ if config[:all]
49
50
  cl = Chef::CookbookLoader.new
50
51
  cl.each do |cookbook|
51
52
  Chef::Log.info("** #{cookbook.name.to_s} **")
@@ -58,28 +59,21 @@ class Chef
58
59
  end
59
60
  end
60
61
  end
61
-
62
- def test_ruby(cookbook_dir)
63
- Dir[File.join(cookbook_dir, '**', '*.rb')].each do |ruby_file|
64
- Chef::Log.info("Testing #{ruby_file} for syntax errors...")
65
- Chef::Mixin::Command.run_command(:command => "ruby -c #{ruby_file}")
66
- end
67
- end
68
-
69
- def test_templates(cookbook_dir)
70
- Dir[File.join(cookbook_dir, '**', '*.erb')].each do |erb_file|
71
- Chef::Log.info("Testing template #{erb_file} for syntax errors...")
72
- Chef::Mixin::Command.run_command(:command => "sh -c 'erubis -x #{erb_file} | ruby -c'")
73
- end
74
- end
75
62
 
76
63
  def upload_cookbook(cookbook_name)
64
+ # Syntax check all cookbook paths rather than tmp_cookbook_dir as to
65
+ # take advantage of the existing cache used/generated by knife cookbook
66
+ # test.
67
+ check = Chef::Knife::CookbookTest.new
68
+ check.config[:cookbook_path] = config[:cookbook_path]
69
+ check.name_args = [ cookbook_name ]
70
+ check.run
77
71
 
78
72
  if cookbook_name =~ /^#{File::SEPARATOR}/
79
- child_folders = cookbook_name
73
+ child_folders = cookbook_name
80
74
  cookbook_name = File.basename(cookbook_name)
81
75
  else
82
- child_folders = config[:cookbook_path].inject([]) do |r, e|
76
+ child_folders = config[:cookbook_path].inject([]) do |r, e|
83
77
  r << File.join(e, cookbook_name)
84
78
  r
85
79
  end
@@ -98,26 +92,23 @@ class Chef
98
92
 
99
93
  Chef::Log.debug("Staging at #{tmp_cookbook_dir}")
100
94
 
101
- found_cookbook = false
95
+ found_cookbook = false
102
96
 
103
97
  child_folders.each do |file_path|
104
98
  if File.directory?(file_path)
105
- found_cookbook = true
99
+ found_cookbook = true
106
100
  Chef::Log.info("Copying from #{file_path} to #{tmp_cookbook_dir}")
107
- FileUtils.cp_r(file_path, tmp_cookbook_dir, :remove_destination => true)
101
+ FileUtils.cp_r(file_path, tmp_cookbook_dir, :remove_destination => true, :preserve => true)
108
102
  else
109
103
  Chef::Log.info("Nothing to copy from #{file_path}")
110
104
  end
111
- end
105
+ end
112
106
 
113
107
  unless found_cookbook
114
108
  Chef::Log.fatal("Could not find cookbook #{cookbook_name}!")
115
109
  exit 17
116
110
  end
117
111
 
118
- test_ruby(tmp_cookbook_dir)
119
- test_templates(tmp_cookbook_dir)
120
-
121
112
  # First, generate metadata
122
113
  kcm = Chef::Knife::CookbookMetadata.new
123
114
  kcm.config[:cookbook_path] = [ tmp_cookbook_dir ]
@@ -144,32 +135,32 @@ class Chef
144
135
 
145
136
  if cookbook_uploaded
146
137
  Chef::StreamingCookbookUploader.put(
147
- "#{Chef::Config[:chef_server_url]}/cookbooks/#{cookbook_name}/_content",
148
- Chef::Config[:node_name],
149
- Chef::Config[:client_key],
138
+ "#{Chef::Config[:chef_server_url]}/cookbooks/#{cookbook_name}/_content",
139
+ Chef::Config[:node_name],
140
+ Chef::Config[:client_key],
150
141
  {
151
- :file => File.new(tarball_name),
142
+ :file => File.new(tarball_name),
152
143
  :name => cookbook_name
153
144
  }
154
145
  )
155
146
  else
156
147
  Chef::StreamingCookbookUploader.post(
157
- "#{Chef::Config[:chef_server_url]}/cookbooks",
158
- Chef::Config[:node_name],
159
- Chef::Config[:client_key],
148
+ "#{Chef::Config[:chef_server_url]}/cookbooks",
149
+ Chef::Config[:node_name],
150
+ Chef::Config[:client_key],
160
151
  {
161
- :file => File.new(tarball_name),
152
+ :file => File.new(tarball_name),
162
153
  :name => cookbook_name
163
154
  }
164
155
  )
165
156
  end
166
157
  Chef::Log.info("Upload complete!")
167
158
  Chef::Log.debug("Removing local tarball at #{tarball_name}")
168
- FileUtils.rm_rf tarball_name
159
+ FileUtils.rm_rf tarball_name
169
160
  Chef::Log.debug("Removing local staging directory at #{tmp_cookbook_dir}")
170
161
  FileUtils.rm_rf tmp_cookbook_dir
171
162
  end
172
-
163
+
173
164
  end
174
165
  end
175
166
  end