puppet 2.7.20 → 2.7.21

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

Potentially problematic release.


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

Files changed (81) hide show
  1. data/CHANGELOG +226 -0
  2. data/conf/auth.conf +3 -3
  3. data/ext/packaging/README.md +191 -57
  4. data/ext/packaging/spec/spec_helper.rb +2 -2
  5. data/ext/packaging/spec/tasks/00_utils_spec.rb +63 -18
  6. data/ext/packaging/spec/tasks/build_object_spec.rb +171 -0
  7. data/ext/packaging/tasks/00_utils.rake +186 -33
  8. data/ext/packaging/tasks/10_setupvars.rake +94 -65
  9. data/ext/packaging/tasks/20_setupextravars.rake +45 -26
  10. data/ext/packaging/tasks/30_metrics.rake +41 -0
  11. data/ext/packaging/tasks/apple.rake +92 -36
  12. data/ext/packaging/tasks/build.rake +183 -0
  13. data/ext/packaging/tasks/deb.rake +45 -40
  14. data/ext/packaging/tasks/deb_repos.rake +103 -0
  15. data/ext/packaging/tasks/doc.rake +5 -5
  16. data/ext/packaging/tasks/fetch.rake +35 -10
  17. data/ext/packaging/tasks/gem.rake +38 -27
  18. data/ext/packaging/tasks/ips.rake +14 -14
  19. data/ext/packaging/tasks/jenkins.rake +337 -0
  20. data/ext/packaging/tasks/mock.rake +153 -72
  21. data/ext/packaging/tasks/pe_deb.rake +2 -2
  22. data/ext/packaging/tasks/pe_remote.rake +22 -19
  23. data/ext/packaging/tasks/pe_rpm.rake +5 -5
  24. data/ext/packaging/tasks/pe_ship.rake +31 -21
  25. data/ext/packaging/tasks/pe_sign.rake +20 -19
  26. data/ext/packaging/tasks/pe_sles.rake +40 -36
  27. data/ext/packaging/tasks/pe_tar.rake +5 -0
  28. data/ext/packaging/tasks/release.rake +32 -12
  29. data/ext/packaging/tasks/remote_build.rake +141 -83
  30. data/ext/packaging/tasks/retrieve.rake +23 -0
  31. data/ext/packaging/tasks/rpm.rake +11 -19
  32. data/ext/packaging/tasks/rpm_repos.rake +127 -0
  33. data/ext/packaging/tasks/ship.rake +68 -55
  34. data/ext/packaging/tasks/sign.rake +38 -10
  35. data/ext/packaging/tasks/tar.rake +25 -9
  36. data/ext/packaging/tasks/update.rake +2 -2
  37. data/ext/packaging/tasks/version.rake +34 -14
  38. data/ext/packaging/tasks/z_data_dump.rake +33 -0
  39. data/lib/puppet/indirector/catalog/compiler.rb +13 -2
  40. data/lib/puppet/indirector/certificate_status/file.rb +5 -0
  41. data/lib/puppet/indirector/errors.rb +5 -0
  42. data/lib/puppet/indirector/file_bucket_file/file.rb +4 -0
  43. data/lib/puppet/indirector/file_bucket_file/selector.rb +4 -0
  44. data/lib/puppet/indirector/indirection.rb +1 -0
  45. data/lib/puppet/indirector/resource/active_record.rb +3 -0
  46. data/lib/puppet/indirector/resource/ral.rb +4 -0
  47. data/lib/puppet/indirector/resource/store_configs.rb +3 -0
  48. data/lib/puppet/indirector/resource/validator.rb +8 -0
  49. data/lib/puppet/indirector/rest.rb +8 -0
  50. data/lib/puppet/indirector/run/local.rb +4 -0
  51. data/lib/puppet/indirector/terminus.rb +20 -0
  52. data/lib/puppet/network/formats.rb +3 -3
  53. data/lib/puppet/network/handler/master.rb +1 -1
  54. data/lib/puppet/network/handler/report.rb +1 -1
  55. data/lib/puppet/network/http/handler.rb +7 -1
  56. data/lib/puppet/network/http/rack/rest.rb +7 -2
  57. data/lib/puppet/network/http/webrick.rb +1 -0
  58. data/lib/puppet/network/rest_authconfig.rb +1 -1
  59. data/lib/puppet/parser/templatewrapper.rb +17 -17
  60. data/lib/puppet/util/monkey_patches.rb +58 -0
  61. data/lib/puppet/version.rb +1 -1
  62. data/spec/integration/indirector/catalog/compiler_spec.rb +1 -0
  63. data/spec/integration/indirector/catalog/queue_spec.rb +1 -1
  64. data/spec/integration/resource/catalog_spec.rb +1 -0
  65. data/spec/unit/indirector/catalog/compiler_spec.rb +29 -2
  66. data/spec/unit/indirector/indirection_spec.rb +18 -1
  67. data/spec/unit/indirector/terminus_spec.rb +191 -177
  68. data/spec/unit/network/formats_spec.rb +6 -6
  69. data/spec/unit/network/http/handler_spec.rb +25 -0
  70. data/spec/unit/network/http/rack/rest_spec.rb +17 -0
  71. data/spec/unit/network/http/webrick_spec.rb +4 -0
  72. data/spec/unit/network/http_pool_spec.rb +0 -1
  73. data/spec/unit/network/rest_authconfig_spec.rb +16 -1
  74. data/spec/unit/parser/functions/inline_template_spec.rb +13 -0
  75. data/spec/unit/parser/functions/template_spec.rb +15 -0
  76. data/spec/unit/parser/templatewrapper_spec.rb +19 -4
  77. data/spec/unit/ssl/certificate_request_spec.rb +2 -0
  78. data/spec/unit/ssl/host_spec.rb +1 -0
  79. data/spec/unit/util/monkey_patches_spec.rb +12 -0
  80. data/test/language/snippets.rb +1 -1
  81. metadata +13 -2
@@ -5,8 +5,8 @@ require 'rake'
5
5
 
6
6
  SPECDIR = Pathname(__FILE__).dirname
7
7
 
8
- def require_task(name)
8
+ def load_task(name)
9
9
  return false if (@loaded ||= {})[name]
10
- load SPECDIR + '..' + 'tasks' + "#{name}.rake"
10
+ load File.join(SPECDIR, '..', 'tasks', name)
11
11
  @loaded[name] = true
12
12
  end
@@ -1,6 +1,7 @@
1
1
  # -*- ruby -*-
2
2
  require 'spec_helper'
3
- require_task '00_utils'
3
+ load_task '00_utils.rake'
4
+ load_task 'build.rake'
4
5
 
5
6
  describe "00_utils" do
6
7
  TestVersions = {
@@ -8,58 +9,102 @@ describe "00_utils" do
8
9
  :git_describe_version => %w{0.7.0},
9
10
  :get_dash_version => '0.7.0',
10
11
  :get_ips_version => '0.7.0,3.14159-0',
11
- :get_dot_version => '0.7.0'
12
+ :get_dot_version => '0.7.0',
13
+ :get_debversion => '0.7.0-1puppetlabs1',
14
+ :get_rpmversion => '0.7.0',
15
+ :get_rpmrelease => '1',
16
+ :is_rc? => false,
12
17
  },
13
18
  '0.7.0rc1' => {
14
19
  :git_describe_version => %w{0.7.0rc1},
15
20
  :get_dash_version => '0.7.0rc1',
16
21
  :get_ips_version => '0.7.0rc1,3.14159-0',
17
- :get_dot_version => '0.7.0rc1'
22
+ :get_dot_version => '0.7.0rc1',
23
+ :get_debversion => '0.7.0-0.1rc1puppetlabs1',
24
+ :get_rpmversion => '0.7.0',
25
+ :get_rpmrelease => '0.1rc1',
26
+ :is_rc? => true,
18
27
  },
19
28
  '0.7.0-rc1' => {
20
29
  :git_describe_version => %w{0.7.0 rc1},
21
30
  :get_dash_version => '0.7.0-rc1',
22
31
  :get_ips_version => '0.7.0,3.14159-0',
23
- :get_dot_version => '0.7.0.rc1'
32
+ :get_dot_version => '0.7.0.rc1',
33
+ :get_debversion => '0.7.0-0.1rc1puppetlabs1',
34
+ :get_rpmversion => '0.7.0',
35
+ :get_rpmrelease => '0.1rc1',
36
+ :is_rc? => true,
24
37
  },
25
38
  '0.7.0-rc1-63-ge391f55' => {
26
39
  :git_describe_version => %w{0.7.0 rc1 63},
27
40
  :get_dash_version => '0.7.0-rc1-63',
28
41
  :get_ips_version => '0.7.0,3.14159-63',
29
- :get_dot_version => '0.7.0.rc1.63'
42
+ :get_dot_version => '0.7.0.rc1.63',
43
+ :get_debversion => '0.7.0-0.1rc1.63puppetlabs1',
44
+ :get_rpmversion => '0.7.0',
45
+ :get_rpmrelease => '0.1rc1.63',
46
+ :is_rc? => true,
30
47
  },
31
48
  '0.7.0-rc1-63-ge391f55-dirty' => {
32
49
  :git_describe_version => %w{0.7.0 rc1 63 dirty},
33
50
  :get_dash_version => '0.7.0-rc1-63-dirty',
34
51
  :get_ips_version => '0.7.0,3.14159-63-dirty',
35
- :get_dot_version => '0.7.0.rc1.63.dirty'
52
+ :get_dot_version => '0.7.0.rc1.63.dirty',
53
+ :get_debversion => '0.7.0-0.1rc1.63dirtypuppetlabs1',
54
+ :get_rpmversion => '0.7.0',
55
+ :get_rpmrelease => '0.1rc1.63dirty',
56
+ :is_rc? => true,
57
+
36
58
  },
37
59
  '0.7.0-63-ge391f55' => {
38
60
  :git_describe_version => %w{0.7.0 63},
39
61
  :get_dash_version => '0.7.0-63',
40
62
  :get_ips_version => '0.7.0,3.14159-63',
41
- :get_dot_version => '0.7.0.63'
63
+ :get_dot_version => '0.7.0.63',
64
+ :get_debversion => '0.7.0.63-1puppetlabs1',
65
+ :get_rpmversion => '0.7.0.63',
66
+ :get_rpmrelease => '1',
67
+ :is_rc? => false,
68
+
42
69
  },
43
70
  '0.7.0-63-ge391f55-dirty' => {
44
71
  :git_describe_version => %w{0.7.0 63 dirty},
45
72
  :get_dash_version => '0.7.0-63-dirty',
46
73
  :get_ips_version => '0.7.0,3.14159-63-dirty',
47
- :get_dot_version => '0.7.0.63.dirty'
74
+ :get_dot_version => '0.7.0.63.dirty',
75
+ :get_debversion => '0.7.0.63.dirty-1puppetlabs1',
76
+ :get_rpmversion => '0.7.0.63.dirty',
77
+ :get_rpmrelease => '1',
78
+ :is_rc? => false,
48
79
  },
49
80
  }
50
81
 
82
+ before :all do
83
+ @build = Build::BuildInstance.new
84
+ end
85
+
51
86
  TestVersions.keys.sort.each do |input|
52
- results = TestVersions[input]
53
- results.keys.sort_by(&:to_s).each do |method|
54
- it "using #{method} #{input.inspect} becomes #{results[method].inspect}" do
55
- # We have to call the `stub!` alias because we are trying to stub on
56
- # `self`, and in the scope of an rspec block that is overridden to
57
- # return a new double, not to stub a method!
58
- self.stub!(:uname_r) { "3.14159" }
59
- self.stub!(:is_git_repo) { true }
60
- self.should_receive(:run_git_describe_internal).and_return(input)
87
+ describe "Versioning based on #{input}" do
88
+ results = TestVersions[input]
89
+ results.keys.sort_by(&:to_s).each do |method|
90
+ it "using #{method} #{input.inspect} becomes #{results[method].inspect}" do
91
+ # We have to call the `stub!` alias because we are trying to stub on
92
+ # `self`, and in the scope of an rspec block that is overridden to
93
+ # return a new double, not to stub a method!
94
+ @build.release = "1"
61
95
 
62
- self.send(method).should == results[method]
96
+ if method.to_s.include?("deb")
97
+ self.should_receive(:run_git_describe_internal).and_return(input)
98
+ @build.packager = "puppetlabs"
99
+ elsif method.to_s.include?("rpm")
100
+ self.should_receive(:run_git_describe_internal).and_return(input)
101
+ else
102
+ self.stub!(:uname_r) { "3.14159" }
103
+ self.stub!(:is_git_repo) { true }
104
+ self.should_receive(:run_git_describe_internal).and_return(input)
105
+ end
106
+ self.send(method).should == results[method]
107
+ end
63
108
  end
64
109
  end
65
110
  end
@@ -0,0 +1,171 @@
1
+ # -*- ruby -*-
2
+ require 'spec_helper'
3
+ load_task '00_utils.rake'
4
+ load_task 'build.rake'
5
+
6
+ describe Build::BuildInstance do
7
+ Build_Params = [:apt_host,
8
+ :apt_repo_path,
9
+ :apt_repo_url,
10
+ :author,
11
+ :benchmark,
12
+ :build_defaults,
13
+ :build_dmg,
14
+ :build_doc,
15
+ :build_gem,
16
+ :build_ips,
17
+ :build_pe,
18
+ :builder_data_file,
19
+ :certificate_pem,
20
+ :cows,
21
+ :db_table,
22
+ :deb_build_host,
23
+ :debversion,
24
+ :debug,
25
+ :default_cow,
26
+ :default_mock,
27
+ :description,
28
+ :dmg_path,
29
+ :email,
30
+ :files,
31
+ :final_mocks,
32
+ :freight_conf,
33
+ :gem_default_executables,
34
+ :gem_dependencies,
35
+ :gem_description,
36
+ :gem_devel_dependencies,
37
+ :gem_excludes,
38
+ :gem_executables,
39
+ :gem_files,
40
+ :gem_forge_project,
41
+ :gem_name,
42
+ :gem_rdoc_options,
43
+ :gem_require_path,
44
+ :gem_runtime_dependencies,
45
+ :gem_summary,
46
+ :gem_test_files,
47
+ :gemversion,
48
+ :gpg_key,
49
+ :gpg_name,
50
+ :homepage,
51
+ :ips_build_host,
52
+ :ips_host,
53
+ :ips_inter_cert,
54
+ :ips_package_host,
55
+ :ips_path,
56
+ :ips_repo,
57
+ :ips_store,
58
+ :ipsversion,
59
+ :jenkins_build_host,
60
+ :jenkins_packaging_job,
61
+ :jenkins_repo_path,
62
+ :metrics,
63
+ :name,
64
+ :project,
65
+ :origversion,
66
+ :osx_build_host,
67
+ :packager,
68
+ :packaging_repo,
69
+ :packaging_url,
70
+ :pbuild_conf,
71
+ :pe_name,
72
+ :pe_version,
73
+ :pg_major_version,
74
+ :privatekey_pem,
75
+ :random_mockroot,
76
+ :rc_mocks,
77
+ :release,
78
+ :rpm_build_host,
79
+ :rpmrelease,
80
+ :rpmversion,
81
+ :ref,
82
+ :sign_tar,
83
+ :sles_build_host,
84
+ :sles_repo_path,
85
+ :sles_repo_host,
86
+ :sles_arch_repos,
87
+ :summary,
88
+ :tar_excludes,
89
+ :tarball_path,
90
+ :team,
91
+ :version,
92
+ :version_file,
93
+ :yum_host,
94
+ :yum_repo_path]
95
+
96
+ before :each do
97
+ @build = Build::BuildInstance.new
98
+ end
99
+
100
+ describe "#new" do
101
+ Build_Params.each do |param|
102
+ it "should have r/w accessors for #{param}" do
103
+ @build.should respond_to(param)
104
+ @build.should respond_to("#{param.to_s}=")
105
+ end
106
+ end
107
+ end
108
+
109
+ describe "#set_params_from_hash" do
110
+ good_params = { :yum_host => 'foo', :pe_name => 'bar' }
111
+ context "given a valid params hash #{good_params}" do
112
+ it "should set instance variable values for each param" do
113
+ good_params.each do |param, value|
114
+ @build.should_receive(:instance_variable_set).with("@#{param}", value)
115
+ end
116
+ @build.set_params_from_hash(good_params)
117
+ end
118
+ end
119
+
120
+ bad_params = { :foo => 'bar' }
121
+ context "given an invalid params hash #{bad_params}" do
122
+ bad_params.each do |param, value|
123
+ it "should print a warning that param '#{param}' is not valid" do
124
+ @build.should_receive(:warn).with(/No build data parameter found for '#{param}'/)
125
+ @build.set_params_from_hash(bad_params)
126
+ end
127
+
128
+ it "should not try to set instance variable @:#{param}" do
129
+ @build.should_not_receive(:instance_variable_set).with("@#{param}", value)
130
+ @build.set_params_from_hash(bad_params)
131
+ end
132
+ end
133
+ end
134
+
135
+ mixed_params = { :sign_tar => TRUE, :baz => 'qux' }
136
+ context "given a hash with both valid and invalid params" do
137
+ it "should set the valid param" do
138
+ @build.should_receive(:instance_variable_set).with("@sign_tar", TRUE)
139
+ @build.set_params_from_hash(mixed_params)
140
+ end
141
+
142
+ it "should issue a warning that the invalid param is not valid" do
143
+ @build.should_receive(:warn).with(/No build data parameter found for 'baz'/)
144
+ @build.set_params_from_hash(mixed_params)
145
+ end
146
+
147
+ it "should not try to set instance variable @:baz" do
148
+ @build.should_not_receive(:instance_variable_set).with("@baz", "qux")
149
+ @build.set_params_from_hash(mixed_params)
150
+ end
151
+ end
152
+ end
153
+
154
+ describe "#params" do
155
+ it "should return a hash containing keys for all build parameters" do
156
+ params = @build.params
157
+ Build_Params.each { |param| params.has_key?(param).should == TRUE }
158
+ end
159
+ end
160
+
161
+ describe "#params_to_yaml" do
162
+ it "should write a valid yaml file" do
163
+ file = mock('file')
164
+ File.should_receive(:open).with(anything(), 'w').and_yield(file)
165
+ file.should_receive(:puts).with(instance_of(String))
166
+ YAML.should_receive(:load_file).with(file)
167
+ expect { YAML.load_file(file) }.to_not raise_error
168
+ @build.params_to_yaml
169
+ end
170
+ end
171
+ end
@@ -60,14 +60,37 @@ def mv_f(src, dest, options={})
60
60
  mv(src, dest, options.merge(mandatory))
61
61
  end
62
62
 
63
- def git_co(dist)
64
- %x{git reset --hard ; git checkout #{dist}}
63
+ def git_co(ref)
64
+ %x{git reset --hard ; git checkout #{ref}}
65
65
  unless $?.success?
66
- STDERR.puts 'Could not checkout #{dist} git branch to build package from...exiting'
66
+ STDERR.puts "Could not checkout #{ref} git branch to build package from...exiting"
67
67
  exit 1
68
68
  end
69
69
  end
70
70
 
71
+ def git_describe
72
+ %x{git describe}.strip
73
+ end
74
+
75
+ # return the sha of HEAD on the current branch
76
+ def git_sha
77
+ %x{git rev-parse HEAD}.strip
78
+ end
79
+
80
+ # Return the ref type of HEAD on the current branch
81
+ def git_ref_type
82
+ %x{git cat-file -t #{git_describe}}.strip
83
+ end
84
+
85
+ # If HEAD is a tag, return the tag. Otherwise return the sha of HEAD.
86
+ def git_sha_or_tag
87
+ if git_ref_type == "tag"
88
+ git_describe
89
+ else
90
+ git_sha
91
+ end
92
+ end
93
+
71
94
  def get_temp
72
95
  temp = `mktemp -d -t tmpXXXXXX`.strip
73
96
  end
@@ -175,39 +198,37 @@ def get_pwd_version
175
198
  %x{pwd}.strip.split('.')[-1]
176
199
  end
177
200
 
201
+ def get_base_pkg_version
202
+ dash = get_dash_version
203
+ if dash.include?("rc")
204
+ # Grab the rc number
205
+ rc_num = dash.match(/rc(\d)+/)[1]
206
+ ver = dash.sub(/-?rc[0-9]+/, "-0.#{@build.release}rc#{rc_num}").gsub(/(rc[0-9]+)-(\d+)?-?/, '\1.\2')
207
+ else
208
+ ver = dash.gsub('-','.') + "-#{@build.release}"
209
+ end
210
+
211
+ ver.split('-')
212
+ end
213
+
178
214
  def get_debversion
179
- (@version.include?("rc") ? @version.sub(/rc[0-9]+/, '0.1\0') : "#{@version.gsub('-','.')}-1") + "#{@packager}#{get_debrelease}"
215
+ get_base_pkg_version.join('-') << "#{@build.packager}1"
180
216
  end
181
217
 
182
218
  def get_origversion
183
- @debversion.split('-')[0]
219
+ @build.debversion.split('-')[0]
184
220
  end
185
221
 
186
222
  def get_rpmversion
187
- @version.match(/^([0-9.]+)/)[1]
223
+ get_base_pkg_version[0]
188
224
  end
189
225
 
190
- def get_version_file_version
191
- # Match version files containing 'VERSION = "x.x.x"' and just x.x.x
192
- contents = IO.read(@version_file)
193
- if version_string = contents.match(/VERSION =.*/)
194
- version_string.to_s.split()[-1]
195
- else
196
- contents
197
- end
198
- end
199
-
200
- def get_debrelease
226
+ def get_release
201
227
  ENV['RELEASE'] || '1'
202
228
  end
203
229
 
204
230
  def get_rpmrelease
205
- ENV['RELEASE'] ||
206
- if @version.include?("rc")
207
- "0.1" + @version.gsub('-', '_').match(/rc[0-9]+.*/)[0]
208
- else
209
- "1"
210
- end
231
+ get_base_pkg_version[1]
211
232
  end
212
233
 
213
234
  def load_keychain
@@ -218,12 +239,16 @@ def load_keychain
218
239
  end
219
240
  end
220
241
 
242
+ def source_dirty?
243
+ git_describe_version.include?('dirty')
244
+ end
245
+
221
246
  def kill_keychain
222
247
  %x{keychain -k mine}
223
248
  end
224
249
 
225
250
  def start_keychain
226
- keychain = %x{/usr/bin/keychain -q --agents gpg --eval #{@gpg_key}}.chomp
251
+ keychain = %x{/usr/bin/keychain -q --agents gpg --eval #{@build.gpg_key}}.chomp
227
252
  new_env = keychain.match(/(GPG_AGENT_INFO)=([^;]*)/)
228
253
  ENV[new_env[1]] = new_env[2]
229
254
  end
@@ -232,7 +257,7 @@ def gpg_sign_file(file)
232
257
  gpg ||= find_tool('gpg')
233
258
 
234
259
  if gpg
235
- sh "#{gpg} --armor --detach-sign -u #{@gpg_key} #{file}"
260
+ sh "#{gpg} --armor --detach-sign -u #{@build.gpg_key} #{file}"
236
261
  else
237
262
  STDERR.puts "No gpg available. Cannot sign #{file}. Exiting..."
238
263
  exit 1
@@ -259,7 +284,9 @@ def set_cow_envs(cow)
259
284
  end
260
285
  arch = arch.split('.')[0] if arch.include?('.')
261
286
  end
262
-
287
+ if @build.build_pe
288
+ ENV['PE_VER'] = @build.pe_version
289
+ end
263
290
  ENV['DIST'] = dist
264
291
  ENV['ARCH'] = arch
265
292
  end
@@ -268,6 +295,10 @@ def ln(target, name)
268
295
  FileUtils.ln(name, target, :force => true, :verbose => true)
269
296
  end
270
297
 
298
+ def ln_sfT(src, dest)
299
+ sh "ln -sfT #{src} #{dest}"
300
+ end
301
+
271
302
  def git_commit_file(file, message=nil)
272
303
  if has_tool('git') and File.exist?('.git')
273
304
  message ||= "changes"
@@ -322,7 +353,7 @@ end
322
353
 
323
354
  def git_tag(version)
324
355
  begin
325
- sh "git tag -s -u #{@gpg_key} -m '#{version}' #{version}"
356
+ sh "git tag -s -u #{@build.gpg_key} -m '#{version}' #{version}"
326
357
  rescue Exception => e
327
358
  STDERR.puts e
328
359
  STDERR.puts "Unable to tag repo at #{version}"
@@ -337,12 +368,12 @@ end
337
368
  def git_bundle(treeish)
338
369
  temp = get_temp
339
370
  appendix = rand_string
340
- sh "git bundle create #{temp}/#{@name}-#{@version}-#{appendix} #{treeish} --tags"
371
+ sh "git bundle create #{temp}/#{@build.project}-#{@build.version}-#{appendix} #{treeish} --tags"
341
372
  cd temp do
342
- sh "tar -czf #{@name}-#{@version}-#{appendix}.tar.gz #{@name}-#{@version}-#{appendix}"
343
- rm_rf "#{@name}-#{@version}-#{appendix}"
373
+ sh "tar -czf #{@build.project}-#{@build.version}-#{appendix}.tar.gz #{@build.project}-#{@build.version}-#{appendix}"
374
+ rm_rf "#{@build.project}-#{@build.version}-#{appendix}"
344
375
  end
345
- "#{temp}/#{@name}-#{@version}-#{appendix}.tar.gz"
376
+ "#{temp}/#{@build.project}-#{@build.version}-#{appendix}.tar.gz"
346
377
  end
347
378
 
348
379
  # We take a tar argument for cases where `tar` isn't best, e.g. Solaris
@@ -354,8 +385,18 @@ def remote_bootstrap(host, treeish, tar_cmd=nil)
354
385
  tarball_name = File.basename(tarball).gsub('.tar.gz','')
355
386
  rsync_to(tarball, host, '/tmp')
356
387
  appendix = rand_string
357
- sh "ssh -t #{host} '#{tar} -zxvf /tmp/#{tarball_name}.tar.gz -C /tmp/ ; git clone --recursive /tmp/#{tarball_name} /tmp/#{@name}-#{appendix} ; cd /tmp/#{@name}-#{appendix} ; rake package:bootstrap'"
358
- "/tmp/#{@name}-#{appendix}"
388
+ sh "ssh -t #{host} '#{tar} -zxvf /tmp/#{tarball_name}.tar.gz -C /tmp/ ; git clone --recursive /tmp/#{tarball_name} /tmp/#{@build.project}-#{appendix} ; cd /tmp/#{@build.project}-#{appendix} ; rake package:bootstrap'"
389
+ "/tmp/#{@build.project}-#{appendix}"
390
+ end
391
+
392
+ # Given a BuildInstance object and a host, send its params to the host. Return
393
+ # the remote path to the params.
394
+ def remote_buildparams(host, build)
395
+ params_file = build.params_to_yaml
396
+ params_file_name = File.basename(params_file)
397
+ params_dir = rand_string
398
+ rsync_to(params_file, host, "/tmp/#{params_dir}/")
399
+ "/tmp/#{params_dir}/#{params_file_name}"
359
400
  end
360
401
 
361
402
  def is_git_repo
@@ -385,3 +426,115 @@ def empty_dir?(dir)
385
426
  File.exist?(dir) and File.directory?(dir) and Dir["#{dir}/**/*"].empty?
386
427
  end
387
428
 
429
+ def hostname
430
+ require 'socket'
431
+ host = Socket.gethostname
432
+ end
433
+
434
+ # Loop a block up to the number of attempts given, exiting when we receive success
435
+ # or max attempts is reached. Raise an exception unless we've succeeded.
436
+ def retry_on_fail(args, &blk)
437
+ success = FALSE
438
+ if args[:times].respond_to?(:times) and block_given?
439
+ args[:times].times do |i|
440
+ begin
441
+ blk.call
442
+ success = TRUE
443
+ break
444
+ rescue
445
+ puts "An error was encountered evaluating block. Retrying.."
446
+ end
447
+ end
448
+ else
449
+ raise "retry_on_fail requires and arg (:times => x) where x is an Integer/Fixnum, and a block to execute"
450
+ end
451
+ raise "Block failed maximum of #{args[:times]} tries. Exiting.." unless success
452
+ end
453
+
454
+ def deprecate(old_cmd, new_cmd=nil)
455
+ msg = "!! #{old_cmd} is deprecated."
456
+ if new_cmd
457
+ msg << " Please use #{new_cmd} instead."
458
+ end
459
+ STDOUT.puts
460
+ STDOUT.puts(msg)
461
+ STDOUT.puts
462
+ end
463
+
464
+ # Determines if this package is an rc package via the version
465
+ # returned by get_dash_version method.
466
+ # Assumes version strings in the formats:
467
+ # final:
468
+ # '0.7.0'
469
+ # '0.7.0-63'
470
+ # '0.7.0-63-dirty'
471
+ # rc:
472
+ # '0.7.0rc1 (we don't actually use this format anymore, but once did)
473
+ # '0.7.0-rc1'
474
+ # '0.7.0-rc1-63'
475
+ # '0.7.0-rc1-63-dirty'
476
+ def is_rc?
477
+ return TRUE if get_dash_version =~ /^\d+\.\d+\.\d+-*rc\d+/
478
+ FALSE
479
+ end
480
+
481
+ # Utility method to return the dist method if this is a redhat box. We use this
482
+ # in rpm packaging to define a dist macro, and we use it in the pl:fetch task
483
+ # to disable ssl checking for redhat 5 because it has a certs bundle so old by
484
+ # default that it's useless for our purposes.
485
+ def el_version()
486
+ if File.exists?('/etc/fedora-release')
487
+ nil
488
+ elsif File.exists?('/etc/redhat-release')
489
+ return %x{rpm -q --qf \"%{VERSION}\" $(rpm -q --whatprovides /etc/redhat-release )}
490
+ end
491
+ end
492
+
493
+ # Given the path to a yaml file, load the yaml file into an object and return
494
+ # the object.
495
+ def data_from_yaml(file)
496
+ file = File.expand_path(file)
497
+ begin
498
+ input_data = YAML.load_file(file) || {}
499
+ rescue => e
500
+ puts "There was an error loading data from #{file}."
501
+ puts e.backtrace.join("\n")
502
+ exit 1
503
+ end
504
+ input_data
505
+ end
506
+
507
+ # This is fairly absurd. We're implementing curl by shelling out. What do I
508
+ # wish we were doing? Using a sweet ruby wrapper around curl, such as Curb or
509
+ # Curb-fu. However, because we're using clean build systems and trying to
510
+ # make this portable with minimal system requirements, we can't very well
511
+ # depend on libraries that aren't in the ruby standard libaries. We could
512
+ # also do this using Net::HTTP but that set of libraries is a rabbit hole to
513
+ # go down when what we're trying to accomplish is posting multi-part form
514
+ # data that includes file uploads to jenkins. It gets hairy fairly quickly,
515
+ # but, as they say, pull requests accepted.
516
+ #
517
+ # This method takes two arguments
518
+ # 1) String - the URL to post to
519
+ # 2) Array - Ordered array of name=VALUE curl form parameters
520
+ def curl_form_data(uri, form_data=[])
521
+ unless curl = find_tool("curl")
522
+ warn "Couldn't find curl. Curl is required for posting jenkins to trigger a build. Please install curl and try again."
523
+ exit 1
524
+ end
525
+ #
526
+ # Begin constructing the post string.
527
+ # First, assemble the form_data arguments
528
+ #
529
+ post_string = "-i "
530
+ form_data.each do |param|
531
+ post_string << "#{param} "
532
+ end
533
+
534
+ # Add the uri and we're off
535
+ post_string << "#{uri}"
536
+ sh "#{curl} #{post_string}"
537
+ return $?.success?
538
+ end
539
+
540
+