-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcookbook_steps.rb
More file actions
134 lines (116 loc) · 4.7 KB
/
Copy pathcookbook_steps.rb
File metadata and controls
134 lines (116 loc) · 4.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#
# Author:: Adam Jacob (<adam@opscode.com>)
# Author:: Chris Walters (<cw@opscode.com>)
# Copyright:: Copyright (c) 2008 Opscode, Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
Given /^a local cookbook repository$/ do
Dir.mkdir(File.join(tmpdir, 'cookbooks_dir'))
Dir.mkdir(File.join(tmpdir, 'cookbooks_dir', 'cookbooks'))
Dir.mkdir(File.join(tmpdir, 'cookbooks_dir', 'config'))
system("cp #{datadir}/Rakefile #{tmpdir}/cookbooks_dir")
system("cp -r #{datadir}/config/* #{tmpdir}/cookbooks_dir/config")
system("cp -r #{datadir}/cookbooks/* #{tmpdir}/cookbooks_dir/cookbooks")
cleanup_dirs << "#{tmpdir}/cookbooks_dir"
end
Given /^a local cookbook named '(.+)'$/ do |cb|
Dir.mkdir(File.join(tmpdir, 'cookbooks_dir'))
Dir.mkdir(File.join(tmpdir, 'cookbooks_dir', 'cookbooks'))
Dir.mkdir(File.join(tmpdir, 'cookbooks_dir', 'config'))
system("cp #{datadir}/Rakefile #{tmpdir}/cookbooks_dir")
system("cp -r #{datadir}/config/* #{tmpdir}/cookbooks_dir/config")
system("cp -r #{datadir}/cookbooks/#{cb} #{tmpdir}/cookbooks_dir/cookbooks")
cleanup_dirs << "#{tmpdir}/cookbooks_dir"
end
When /^I run the task to generate cookbook metadata for '(.+)'$/ do |cb|
self.cookbook = cb
When('I run the task to generate cookbook metadata')
end
When /^I run the task to generate cookbook metadata$/ do
knife_cmd = File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "chef", "bin", "knife"))
to_run = "#{knife_cmd} cookbook metadata"
if cookbook
to_run += " #{cookbook}"
else
to_run += " -a"
end
to_run += " -o #{File.join(tmpdir, 'cookbooks_dir', 'cookbooks')}"
Dir.chdir(File.join(tmpdir, 'cookbooks_dir', 'cookbooks')) do
self.status = Chef::Mixin::Command.popen4(to_run) do |p, i, o, e|
self.stdout = o.gets(nil)
self.stderr = o.gets(nil)
end
end
end
#####
# Cookbook tarball-specific steps
#####
require 'chef/streaming_cookbook_uploader'
Given /^a cookbook named '(.+?)' is created with '(.*?)'$/ do |cookbook, stash_key|
params = {:name => cookbook}.merge(@stash[stash_key])
response = Chef::StreamingCookbookUploader.post("#{Chef::Config[:chef_server_url]}/cookbooks", rest.client_name, rest.signing_key_filename, params)
response.status.should == 201
end
When /^I delete the cached tarball for '(.*?)'$/ do |cookbook|
path = File.join(server_tmpdir, "cookbook-tarballs", "#{cookbook}.tar.gz")
Chef::Log.debug "Deleting #{path}"
FileUtils.rm_f(path)
end
When /^I create a cookbook(?: named '(.*?)')? with '(.*?)'$/ do |name, stash_key|
payload = { }
payload[:name] = name if name
payload.merge!(@stash[stash_key])
url = "#{Chef::Config[:chef_server_url]}/cookbooks"
payload[:file].rewind if payload[:file].kind_of?(File)
response = Chef::StreamingCookbookUploader.post(url, rest.client_name, rest.signing_key_filename, payload)
store_response response
end
When /^I upload '(.*?)' to cookbook '(.*?)'$/ do |stash_key, cookbook|
payload = @stash[stash_key]
url = "#{Chef::Config[:chef_server_url]}/cookbooks/#{cookbook}/_content"
payload[:file].rewind if payload[:file].kind_of?(File)
response = Chef::StreamingCookbookUploader.put(url, rest.client_name, rest.signing_key_filename, payload)
store_response response
end
When /^I download the '(.*?)' cookbook$/ do |cookbook|
When "I 'GET' the path '/cookbooks/#{cookbook}/_content'"
end
When /^I delete cookbook '(.*?)'$/ do |cookbook|
When "I 'DELETE' the path '/cookbooks/#{cookbook}'"
end
Then /^the response should be a valid tarball$/ do
Tempfile.open('tarball') do |tempfile|
tempfile.write(self.response.to_s)
tempfile.flush()
system("tar", "tzf", tempfile.path).should == true
end
end
Then /^the untarred response should include file '(.+)'$/ do |filepath|
Tempfile.open('tarball') do |tempfile|
tempfile.write(self.response.to_s)
tempfile.flush()
`tar tzf #{tempfile.path}`.split("\n").select{|e| e == filepath}.empty?.should == false
end
end
def store_response(resp)
self.response = resp
Chef::Log.debug "store response: #{resp.inspect}, #{resp.to_s}"
begin
Chef::Log.debug resp.to_s
self.inflated_response = JSON.parse(resp.to_s)
rescue
Chef::Log.debue "failed to convert response to JSON: #{$!.message}"
end
end