vanagon 0.13.1 → 0.14.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -157,6 +157,20 @@ class Vanagon
157
157
  @project.source_artifacts = source_artifacts
158
158
  end
159
159
 
160
+ # Generate os-specific packaging artifacts (rpm, deb, etc)
161
+ #
162
+ # @param pkg [Boolean] whether or not to output packages
163
+ def generate_packages(pkg)
164
+ @project.generate_packages = pkg
165
+ end
166
+
167
+ # Output os-specific archives containing the binary output
168
+ #
169
+ # @param archive [Boolean] whether or not to output archives
170
+ def generate_archives(archive)
171
+ @project.compiled_archive = archive
172
+ end
173
+
160
174
  # Sets the version for the project based on a git describe of the
161
175
  # directory that holds the configs. Requires that a git tag be present
162
176
  # and reachable from the current commit in that repository.
@@ -286,6 +300,15 @@ class Vanagon
286
300
  @project.retry_count = retry_count
287
301
  end
288
302
 
303
+ # Inherit the settings hash from an upstream project
304
+ #
305
+ # @param upstream_project_name [String] The vanagon project to load settings from
306
+ # @param upstream_git_url [String] The git URL for the vanagon project to load settings from
307
+ # @param upstream_git_branch [String] The git branch for the vanagon project to load settings from
308
+ def inherit_settings(upstream_project_name, upstream_git_url, upstream_git_branch)
309
+ @project.load_upstream_settings(upstream_project_name, upstream_git_url, upstream_git_branch)
310
+ end
311
+
289
312
  # Set a package override. Will call the platform-specific implementation
290
313
  # This will get set in the spec file, deb rules, etc.
291
314
  #
@@ -52,6 +52,7 @@ class Vanagon
52
52
  def http_request(url, type, payload = {}.to_json, header = nil) # rubocop:disable Metrics/AbcSize
53
53
  uri = URI.parse(url)
54
54
  http = Net::HTTP.new(uri.host, uri.port)
55
+ http.use_ssl = true if uri.scheme == 'https'
55
56
 
56
57
  case type.downcase
57
58
  when "get"
@@ -131,7 +132,7 @@ class Vanagon
131
132
  # @param timeout [Integer] number of seconds to run the block before timing out
132
133
  # @return [true] If the block succeeds, true is returned
133
134
  # @raise [Vanagon::Error] if the block fails after the retries are exhausted, an error is raised
134
- def retry_with_timeout(tries = 5, timeout = 1, &blk)
135
+ def retry_with_timeout(tries = 5, timeout = 1, &blk) # rubocop:disable Metrics/AbcSize
135
136
  error = nil
136
137
  tries.to_i.times do
137
138
  Timeout::timeout(timeout.to_i) do
@@ -146,7 +147,9 @@ class Vanagon
146
147
  end
147
148
 
148
149
  message = "Block failed maximum number of #{tries} tries"
149
- message += "\n with error #{error.message}" unless error.nil?
150
+ unless error.nil?
151
+ message += "\n with error #{error.message}" + "\n#{error.backtrace.join("\n")}"
152
+ end
150
153
  message += "\nExiting..."
151
154
  raise error, message unless error.nil?
152
155
  raise Vanagon::Error, "Block failed maximum number of #{tries} tries"
@@ -44,6 +44,23 @@ fi
44
44
  <%- end -%>
45
45
  <%- end -%>
46
46
 
47
+ # Run trigger scripts on install if defined
48
+ if [ $1 = triggered ] && [ -z $2 ]; then
49
+ <%- get_interest_triggers("install").each do |trigger| -%>
50
+ <%= trigger.scripts.join("\n") %>
51
+ <%- end -%>
52
+ : # no trigger scripts provided
53
+ fi
54
+
55
+ # Run trigger scripts on upgrade if defined
56
+ if [ $1 = triggered ]&& [ -n $2 ]; then
57
+ <%- get_interest_triggers("upgrade").each do |trigger| -%>
58
+ <%= trigger.scripts.join("\n") %>
59
+ <%- end -%>
60
+ : # no trigger scripts provided
61
+ fi
62
+
63
+
47
64
  # Run postinstall scripts on install if defined
48
65
  if [ $1 = configure ] && [ -z $2 ] ; then
49
66
  <%= get_postinstall_actions("install") %>
@@ -0,0 +1,11 @@
1
+ <%- get_activate_triggers.each do |trigger| -%>
2
+ activate <%= trigger %>
3
+ <% end -%>
4
+
5
+ <%- get_interest_triggers("install").each do |trigger| -%>
6
+ interest <%= trigger.interest_name %>
7
+ <% end -%>
8
+
9
+ <%- get_interest_triggers("upgrade").each do |trigger| -%>
10
+ interest <%= trigger.interest_name %>
11
+ <% end -%>
@@ -149,11 +149,11 @@ install -d %{buildroot}
149
149
  <%- end -%>
150
150
 
151
151
  # Here we turn all dirs in the file-list into %dir entries to avoid duplicate files
152
- for entry in `cat %{SOURCE1}`; do
152
+ while read entry; do
153
153
  if [ -n "$entry" -a -d "$entry" -a ! -L "$entry" ]; then
154
154
  PATH=/opt/freeware/bin:$PATH sed -i "s|^\($entry\)\$|%dir \1|g" %{SOURCE1}
155
155
  fi
156
- done
156
+ done < %{SOURCE1}
157
157
 
158
158
 
159
159
  %pre
@@ -185,6 +185,22 @@ if [ "$1" -gt 1 ] ; then
185
185
  fi
186
186
 
187
187
 
188
+ <%- get_all_trigger_pkgs.each do |pkg| %>
189
+
190
+ %triggerin -- <%= pkg %>
191
+ # Run scripts on install if defined
192
+ [ $2 = 0 ] || exit 0
193
+ if [ "$1" -eq 1 ] ; then
194
+ <%= get_install_trigger_scripts(pkg) %>
195
+ : # end line
196
+ fi
197
+ elif ["$1" -gt 1 ] ;
198
+ <%= get_upgrade_trigger_scripts(pkg) %>
199
+ : # end line
200
+ fi
201
+ <% end -%>
202
+
203
+
188
204
  %post
189
205
  <%- if @platform.is_aix? || (@platform.is_el? && @platform.os_version.to_i == 4) -%>
190
206
  ## EL-4 and AIX RPM don't have %posttrans, so we'll put them here
@@ -65,6 +65,10 @@ end" }
65
65
  let(:dummy_sha1_sum) { "fdaa03c3f506d7b71635f2c32dfd41b0cc8b904f" }
66
66
  let(:dummy_sha256_sum) { "fd9c922702eb2e2fb26376c959753f0fc167bb6bc99c79262fcff7bcc8b34be1" }
67
67
  let(:dummy_sha512_sum) { "8feda1e9896be618dd6c65120d10afafce93888df8569c598f52285083c23befd1477da5741939d4eae042f822e45ca2e45d8d4d18cf9224b7acaf71d883841e" }
68
+ let(:dummy_md5_url) { "http://example.com/example.tar.gz.md5" }
69
+ let(:dummy_sha1_url) { "http://example.com/example.tar.gz.sha1" }
70
+ let(:dummy_sha256_url) { "http://example.com/example.tar.gz.sha256" }
71
+ let(:dummy_sha512_url) { "http://example.com/example.tar.gz.sha512" }
68
72
 
69
73
  before do
70
74
  allow(platform).to receive(:install).and_return('install')
@@ -80,6 +84,13 @@ end" }
80
84
  expect(comp._component.options[:sum]).to eq(dummy_md5_sum)
81
85
  expect(comp._component.options[:sum_type]).to eq('md5')
82
86
  end
87
+ it "sets md5 url and type correctly" do
88
+ comp = Vanagon::Component::DSL.new('test-fixture', {}, {})
89
+ comp.md5sum(dummy_md5_url)
90
+
91
+ expect(comp._component.options[:sum]).to eq(dummy_md5_url)
92
+ expect(comp._component.options[:sum_type]).to eq('md5')
93
+ end
83
94
  end
84
95
 
85
96
  describe "#sha1sum" do
@@ -90,6 +101,13 @@ end" }
90
101
  expect(comp._component.options[:sum]).to eq(dummy_sha1_sum)
91
102
  expect(comp._component.options[:sum_type]).to eq('sha1')
92
103
  end
104
+ it "sets sha1 url and type correctly" do
105
+ comp = Vanagon::Component::DSL.new('test-fixture', {}, {})
106
+ comp.sha1sum(dummy_sha1_url)
107
+
108
+ expect(comp._component.options[:sum]).to eq(dummy_sha1_url)
109
+ expect(comp._component.options[:sum_type]).to eq('sha1')
110
+ end
93
111
  end
94
112
 
95
113
  describe "#sha256sum" do
@@ -100,6 +118,13 @@ end" }
100
118
  expect(comp._component.options[:sum]).to eq(dummy_sha256_sum)
101
119
  expect(comp._component.options[:sum_type]).to eq('sha256')
102
120
  end
121
+ it "sets sha256 url and type correctly" do
122
+ comp = Vanagon::Component::DSL.new('test-fixture', {}, {})
123
+ comp.sha256sum(dummy_sha256_url)
124
+
125
+ expect(comp._component.options[:sum]).to eq(dummy_sha256_url)
126
+ expect(comp._component.options[:sum_type]).to eq('sha256')
127
+ end
103
128
  end
104
129
 
105
130
  describe "#sha512sum" do
@@ -110,6 +135,13 @@ end" }
110
135
  expect(comp._component.options[:sum]).to eq(dummy_sha512_sum)
111
136
  expect(comp._component.options[:sum_type]).to eq('sha512')
112
137
  end
138
+ it "sets sha512 url and type correctly" do
139
+ comp = Vanagon::Component::DSL.new('test-fixture', {}, {})
140
+ comp.sha512sum(dummy_sha512_url)
141
+
142
+ expect(comp._component.options[:sum]).to eq(dummy_sha512_url)
143
+ expect(comp._component.options[:sum_type]).to eq('sha512')
144
+ end
113
145
  end
114
146
 
115
147
  describe '#load_from_json' do
@@ -337,7 +369,7 @@ end" }
337
369
  end
338
370
 
339
371
  describe '#add_actions' do
340
- it 'adds the corect preinstall action to the component' do
372
+ it 'adds the correct preinstall action to the component' do
341
373
  comp = Vanagon::Component::DSL.new('action-test', {}, dummy_platform_sysv)
342
374
  comp.add_preinstall_action(['install', 'upgrade'], ['chkconfig --list', '/bin/true'])
343
375
  comp.add_preinstall_action('install', 'echo "hello, world"')
@@ -365,6 +397,64 @@ end" }
365
397
  expect { comp.add_preinstall_action([], '/bin/true') }.to raise_error(Vanagon::Error)
366
398
  end
367
399
 
400
+ # trigger spec testing
401
+ it 'adds the correct trigger action to the component' do
402
+ comp = Vanagon::Component::DSL.new('action-test', {}, dummy_platform_sysv)
403
+ comp.add_rpm_install_triggers(['install', 'upgrade'], ['chkconfig --list', '/bin/true'], 'puppet-agent')
404
+ comp.add_rpm_install_triggers('install', 'echo "hello, world"', 'puppet-agent')
405
+ expect(comp._component.install_triggers.count).to eq(2)
406
+ expect(comp._component.install_triggers.first.scripts.count).to eq(2)
407
+ expect(comp._component.install_triggers.first.pkg_state.count).to eq(2)
408
+ expect(comp._component.install_triggers.first.pkg_state.first).to eq('install')
409
+ expect(comp._component.install_triggers.first.pkg_state.last).to eq('upgrade')
410
+ expect(comp._component.install_triggers.first.scripts.first).to eq('chkconfig --list')
411
+ expect(comp._component.install_triggers.first.scripts.last).to eq('/bin/true')
412
+ expect(comp._component.install_triggers.first.pkg).to eq ('puppet-agent')
413
+
414
+ expect(comp._component.install_triggers.last.scripts.count).to eq(1)
415
+ expect(comp._component.install_triggers.last.pkg_state.count).to eq(1)
416
+ expect(comp._component.install_triggers.last.pkg_state.first).to eq('install')
417
+ expect(comp._component.install_triggers.last.scripts.first).to eq('echo "hello, world"')
418
+ expect(comp._component.install_triggers.last.pkg).to eq('puppet-agent')
419
+ end
420
+
421
+ it 'fails with bad install trigger action' do
422
+ comp = Vanagon::Component::DSL.new('action-test', {}, dummy_platform_sysv)
423
+ expect { comp.add_rpm_install_triggers('foo', '/bin/true', 'puppet-agent') }.to raise_error(Vanagon::Error)
424
+ end
425
+
426
+ it 'fails with empty install trigger action' do
427
+ comp = Vanagon::Component::DSL.new('action-test', {}, dummy_platform_sysv)
428
+ expect { comp.add_rpm_install_triggers([], '/bin/true', 'puppet-agent') }.to raise_error(Vanagon::Error)
429
+ end
430
+
431
+ it 'adds debian interest triggers' do
432
+ comp = Vanagon::Component::DSL.new('action-test', {}, '')
433
+ comp.add_debian_interest_triggers(['install', 'upgrade'], ['chkconfig --list', '/bin/true'], 'puppet-agent-interest')
434
+ comp.add_debian_interest_triggers('install', 'echo "hello, world"', 'puppet-agent-interest')
435
+ expect(comp._component.interest_triggers.count).to eq(2)
436
+ expect(comp._component.interest_triggers.first.scripts.count).to eq(2)
437
+ expect(comp._component.interest_triggers.first.pkg_state.count).to eq(2)
438
+ expect(comp._component.interest_triggers.first.pkg_state.first).to eq('install')
439
+ expect(comp._component.interest_triggers.first.pkg_state.last).to eq('upgrade')
440
+ expect(comp._component.interest_triggers.first.scripts.first).to eq('chkconfig --list')
441
+ expect(comp._component.interest_triggers.first.scripts.last).to eq('/bin/true')
442
+ expect(comp._component.interest_triggers.first.interest_name).to eq ('puppet-agent-interest')
443
+
444
+ expect(comp._component.interest_triggers.last.scripts.count).to eq(1)
445
+ expect(comp._component.interest_triggers.last.pkg_state.count).to eq(1)
446
+ expect(comp._component.interest_triggers.last.pkg_state.first).to eq('install')
447
+ expect(comp._component.interest_triggers.last.scripts.first).to eq('echo "hello, world"')
448
+ expect(comp._component.interest_triggers.last.interest_name).to eq('puppet-agent-interest')
449
+ end
450
+
451
+ it 'adds debian activate triggers' do
452
+ comp = Vanagon::Component::DSL.new('action-test', {}, '')
453
+ comp.add_debian_activate_triggers('puppet-agent-activate')
454
+ expect(comp._component.activate_triggers.count).to eq(1)
455
+ expect(comp._component.activate_triggers.first.activate_name).to eq ('puppet-agent-activate')
456
+ end
457
+
368
458
  it 'adds the corect postinstall action to the component' do
369
459
  comp = Vanagon::Component::DSL.new('action-test', {}, dummy_platform_sysv)
370
460
  comp.add_postinstall_action(['install', 'upgrade'], ['chkconfig --list', '/bin/true'])
@@ -393,7 +483,7 @@ end" }
393
483
  expect { comp.add_postinstall_action([], '/bin/true') }.to raise_error(Vanagon::Error)
394
484
  end
395
485
 
396
- it 'adds the corect preremove action to the component' do
486
+ it 'adds the correct preremove action to the component' do
397
487
  comp = Vanagon::Component::DSL.new('action-test', {}, dummy_platform_sysv)
398
488
  comp.add_preremove_action(['removal', 'upgrade'], ['chkconfig --list', '/bin/true'])
399
489
  comp.add_preremove_action('removal', 'echo "hello, world"')
@@ -292,4 +292,88 @@ describe Vanagon::Component::Rules do
292
292
  expect(rule.recipe).to eq(["[ -d /foo/bar ] && rm -r /foo/bar", "[ -e leatherman-unpack ] && rm leatherman-unpack"])
293
293
  end
294
294
  end
295
+
296
+ describe "With `Vanagon::Component.install_only = true`" do
297
+ before do
298
+ component.install_only = true
299
+ end
300
+
301
+ context "the component rule" do
302
+ it "depends on the component-install rule" do
303
+ rule = subject.component_rule
304
+ expect(rule.dependencies).to eq(["leatherman-install"])
305
+ end
306
+ end
307
+
308
+ context "the install rule" do
309
+ let(:rule) { subject.install_rule }
310
+
311
+ it { expect(rule.dependencies).to be_empty }
312
+
313
+ it "does nothing when the install step is empty" do
314
+ expect(rule.recipe.size).to eq 1
315
+ end
316
+
317
+ it "runs all of the install commands when given" do
318
+ component.install = ["make install", "make reallyinstall"]
319
+ expect(rule.recipe.first).to eq(
320
+ [
321
+ "make install",
322
+ "make reallyinstall",
323
+ ].join(" && \\\n")
324
+ )
325
+ end
326
+
327
+ it "sets environment variables before running the install steps" do
328
+ component.install = ["make install", "make reallyinstall"]
329
+ component.environment.merge({"PATH" => "/opt/pl-build-tools/bin:$(PATH)"})
330
+ expect(rule.recipe.first).to eq(
331
+ [
332
+ 'export PATH="/opt/pl-build-tools/bin:$(PATH)"',
333
+ "make install",
334
+ "make reallyinstall"
335
+ ].join(" && \\\n")
336
+ )
337
+ end
338
+
339
+ it_behaves_like "a rule that touches the target file"
340
+ end
341
+
342
+ context "the clean rule" do
343
+ let(:rule) { subject.clean_rule }
344
+
345
+ it { expect(rule.dependencies).to be_empty }
346
+
347
+ it "runs a `make clean` in the build dir" do
348
+ expect(rule.recipe.first).to eq '[ -d /foo/bar ] && cd /foo/bar && /usr/bin/make clean'
349
+ end
350
+
351
+ it "remotes the touch files for the configure, build, and install steps" do
352
+ %w[configure build install].each_with_index do |type, i|
353
+ touchfile = "leatherman-#{type}"
354
+ expect(rule.recipe[i + 1]).to eq "[ -e #{touchfile} ] && rm #{touchfile}"
355
+ end
356
+ end
357
+ end
358
+
359
+ context "the clobber rule" do
360
+ let(:rule) { subject.clobber_rule }
361
+
362
+ it { expect(rule.dependencies).to eq(['leatherman-clean']) }
363
+
364
+ it "removes the source directory and unpack touchfile" do
365
+ expect(rule.recipe).to eq(["[ -d /foo/bar ] && rm -r /foo/bar", "[ -e leatherman-unpack ] && rm leatherman-unpack"])
366
+ end
367
+ end
368
+
369
+ context "the clobber rule" do
370
+ let(:rule) { subject.clobber_rule }
371
+
372
+ it { expect(rule.dependencies).to eq(['leatherman-clean']) }
373
+
374
+ it "removes the source directory and unpack touchfile" do
375
+ expect(rule.recipe).to eq(["[ -d /foo/bar ] && rm -r /foo/bar", "[ -e leatherman-unpack ] && rm leatherman-unpack"])
376
+ end
377
+ end
378
+ end
295
379
  end
@@ -1,7 +1,7 @@
1
1
  require 'vanagon/component/source/git'
2
2
 
3
3
  describe "Vanagon::Component::Source::Http" do
4
- let (:base_url) { 'http://buildsources.delivery.puppetlabs.net' }
4
+ let (:base_url) { 'https://artifactory.delivery.puppetlabs.net/artifactory/generic/buildsources/' }
5
5
  let (:file_base) { 'thing-1.2.3' }
6
6
  let (:tar_filename) { 'thing-1.2.3.tar.gz' }
7
7
  let (:tar_url) { "#{base_url}/#{tar_filename}" }
@@ -2,6 +2,8 @@ require 'vanagon/component/source'
2
2
 
3
3
  describe "Vanagon::Component::Source::Rewrite" do
4
4
  let(:klass) { Vanagon::Component::Source::Rewrite }
5
+ let(:artifactory_url) { "https://artifactory.delivery.puppetlabs.net/artifactory" }
6
+ let(:buildsources_url) { "#{artifactory_url}/generic/buildsources" }
5
7
  before(:each) { klass.rewrite_rules.clear }
6
8
 
7
9
  describe ".parse_and_rewrite" do
@@ -14,10 +16,10 @@ describe "Vanagon::Component::Source::Rewrite" do
14
16
  end
15
17
 
16
18
  it 'replaces the first section of a url with a string if string is given' do
17
- klass.register_rewrite_rule('http', 'http://buildsources.delivery.puppetlabs.net')
19
+ klass.register_rewrite_rule('http', buildsources_url)
18
20
 
19
21
  expect(klass.rewrite('http://things.and.stuff/foo.tar.gz', 'http'))
20
- .to eq('http://buildsources.delivery.puppetlabs.net/foo.tar.gz')
22
+ .to eq("#{buildsources_url}/foo.tar.gz")
21
23
  end
22
24
 
23
25
  it 'applies the rule to the url if a proc is given as the rule' do
@@ -46,10 +48,10 @@ describe "Vanagon::Component::Source::Rewrite" do
46
48
  .to raise_error Vanagon::Error
47
49
  end
48
50
 
49
- before { klass.register_rewrite_rule('http', 'http://buildsources.delivery.puppetlabs.net') }
51
+ before { klass.register_rewrite_rule('http', buildsources_url) }
50
52
  it 'registers the rule for the given protocol' do
51
53
  expect(klass.rewrite_rules)
52
- .to eq({'http' => 'http://buildsources.delivery.puppetlabs.net'})
54
+ .to eq({'http' => buildsources_url})
53
55
  end
54
56
  end
55
57
  end
@@ -70,21 +70,26 @@ describe "Vanagon::Component::Source" do
70
70
 
71
71
  context "takes a HTTP/HTTPS file" do
72
72
  before do
73
- allow_any_instance_of(Vanagon::Component::Source::Http)
74
- .to receive(:valid_url?)
75
- .and_return(true)
76
-
77
73
  allow(Vanagon::Component::Source::Http)
78
74
  .to receive(:valid_url?)
79
- .and_return(true)
75
+ .with(sum)
76
+ .and_return(false)
80
77
  end
81
78
 
82
79
  it "returns an object of the correct type for http:// URLS" do
80
+ allow(Vanagon::Component::Source::Http)
81
+ .to receive(:valid_url?)
82
+ .with(http_url)
83
+ .and_return(true)
83
84
  expect(klass.source(http_url, sum: sum, workdir: workdir, sum_type: "md5").class)
84
85
  .to equal(Vanagon::Component::Source::Http)
85
86
  end
86
87
 
87
88
  it "returns an object of the correct type for https:// URLS" do
89
+ allow(Vanagon::Component::Source::Http)
90
+ .to receive(:valid_url?)
91
+ .with(https_url)
92
+ .and_return(true)
88
93
  expect(klass.source(https_url, sum: sum, workdir: workdir, sum_type: "md5").class)
89
94
  .to equal(Vanagon::Component::Source::Http)
90
95
  end