simp-rake-helpers 5.6.2 → 5.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (32) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +10 -0
  3. data/lib/simp/packer/iso_vars_json.rb +87 -0
  4. data/lib/simp/rake/build/auto.rb +6 -31
  5. data/lib/simp/rake/helpers/assets/rpm_spec/simp6.spec +36 -8
  6. data/lib/simp/rake/helpers/assets/rpm_spec/simpdefault.spec +36 -8
  7. data/lib/simp/rake/helpers/version.rb +1 -1
  8. data/spec/acceptance/00_pkg_rpm_custom_scriptlets_spec.rb +19 -3
  9. data/spec/acceptance/10_pkg_rpm_spec.rb +52 -8
  10. data/spec/acceptance/20_pkg_rpm_upgrade_spec.rb +223 -0
  11. data/spec/acceptance/files/mock_packages/simp-adapter/usr/local/sbin/simp_rpm_helper +334 -245
  12. data/spec/acceptance/files/package_upgrades/pupmod-simp-testpackage-1.0/CHANGELOG +2 -0
  13. data/spec/acceptance/files/package_upgrades/pupmod-simp-testpackage-1.0/Rakefile +3 -0
  14. data/spec/acceptance/files/package_upgrades/pupmod-simp-testpackage-1.0/build/rpm_metadata/requires +2 -0
  15. data/spec/acceptance/files/package_upgrades/pupmod-simp-testpackage-1.0/data/os/CentOS.yaml +2 -0
  16. data/spec/acceptance/files/package_upgrades/pupmod-simp-testpackage-1.0/data/os/RedHat.yaml +2 -0
  17. data/spec/acceptance/files/package_upgrades/pupmod-simp-testpackage-1.0/hiera.yaml +14 -0
  18. data/spec/acceptance/files/package_upgrades/pupmod-simp-testpackage-1.0/manifests/init.pp +2 -0
  19. data/spec/acceptance/files/package_upgrades/pupmod-simp-testpackage-1.0/metadata.json +37 -0
  20. data/spec/acceptance/files/package_upgrades/pupmod-simp-testpackage-2.0/CHANGELOG +5 -0
  21. data/spec/acceptance/files/package_upgrades/pupmod-simp-testpackage-2.0/Rakefile +3 -0
  22. data/spec/acceptance/files/package_upgrades/pupmod-simp-testpackage-2.0/build/rpm_metadata/requires +2 -0
  23. data/spec/acceptance/files/package_upgrades/pupmod-simp-testpackage-2.0/data/os/CentOS.yaml +2 -0
  24. data/spec/acceptance/files/package_upgrades/pupmod-simp-testpackage-2.0/data/os/RedHat.yaml +2 -0
  25. data/spec/acceptance/files/package_upgrades/pupmod-simp-testpackage-2.0/hiera.yaml +14 -0
  26. data/spec/acceptance/files/package_upgrades/pupmod-simp-testpackage-2.0/manifests/init.pp +3 -0
  27. data/spec/acceptance/files/package_upgrades/pupmod-simp-testpackage-2.0/metadata.json +37 -0
  28. data/spec/acceptance/nodesets/default.yml +7 -8
  29. data/spec/acceptance/support/pkg_rpm_helpers.rb +2 -2
  30. data/spec/lib/simp/packer/iso_vars_json_spec.rb +65 -0
  31. metadata +29 -5
  32. data/spec/acceptance/20_pkg_rpm_safely_upgrading_obsolete_modules_spec.rb +0 -175
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 81eff52b592008f011ce1cbf7906a2de2b5a0b1a
4
- data.tar.gz: 8b23f1eee1426b3966dcfdd5497c12842393f54c
3
+ metadata.gz: 8a8658433c3ae0b91d796125582eab9ce67ce0e7
4
+ data.tar.gz: 82920a327f2f34bb31a3e1ba1abbbd8f71b06fc4
5
5
  SHA512:
6
- metadata.gz: b95308bf18a70abc0ed3e6c9c1141a2d93657ead6538b0d3672b23653ca1b80af049a9639d32022137d1a51ffa06f7de4e3c2ffe5e168a45442ebf7b5748ac4c
7
- data.tar.gz: c9d08045244a15fdd38c5ee09d1600a0d17a3dea637273fba9b3a8dcf9a1e381cfc2165da69e45f635c16bcf016596664c1e2927cd094fc725d439e45bc27277
6
+ metadata.gz: 011655550ccfafa645a3dc4f0b4160c7413c5a487f1739fe66dd9481e408bc1a6c9ea029d626784cde2a4371795120200d8d900582d147ca6f8edec60a8a9739
7
+ data.tar.gz: 8ad330b2c6af2373c750123d5ff6765426b98644bca04e0b449c855296320862f34bb0614650166042232ee1e758a369a5798a5b5daba00248e0ff8a0b13e49f
data/CHANGELOG.md CHANGED
@@ -1,3 +1,13 @@
1
+ ### 5.7.0 / 2018-12-05
2
+ * Move use of simp_rpm_helper from %post to %postrans, to fix
3
+ a bug in which files that should have been removed from the old
4
+ version during RPM upgrade are copied.
5
+
6
+ ### 5.6.3 / 2018-10-30
7
+ * Add information about the distribution OS to the simp-packer `vars.json`.
8
+ * Add builder version information to the simp-packer `vars.json`.
9
+ * Refactor writing the vars.json to its own method.
10
+
1
11
  ### 5.6.2 / 2018-10-02
2
12
  * Refactor 'dev' GPG signing key logic into `Simp::LocalGpgSigningKey`
3
13
  * Add acceptance tests for GPG logic and `rake pkg:signrpms`
@@ -0,0 +1,87 @@
1
+ require 'simp/rake/helpers/version'
2
+ require 'digest'
3
+ require 'json'
4
+
5
+ module Simp
6
+ module Packer
7
+ # Write a `vars.json` file to accompany a SIMP ISO
8
+ class IsoVarsJson
9
+ # SemVer data version of file
10
+ #
11
+ # (Starting at 1.0.0, because earlier formats didn't include versions)
12
+ VARS_FORMAT_VERSION = '1.0.0'.freeze
13
+
14
+ # @param file [String] path to iso file
15
+ # @param target_release [String] SIMP release to build (e.g., '6.X')
16
+ # This is a key from the build's `release_mappings.yaml` in simp-core
17
+ # @param target_data [Hash] Unpacked hash of isos and metadata
18
+ # The metadata is in the format returned by
19
+ # Simp::Build::ReleaseMapper#autoscan_unpack_list
20
+ # @param opts [Hash] extra options
21
+ def initialize(iso, target_release, target_data, opts = {})
22
+ @iso = iso
23
+ @target_release = target_release
24
+ @target_data = target_data
25
+ @opts = opts
26
+ @opts[:silent] ||= false
27
+ end
28
+
29
+ # Returns a SHA256 checksum of iso file
30
+ # @param file [String] path to file
31
+ # @return [String] SHA256 sum of ISO
32
+ def sha256sum(file)
33
+ unless @opts[:silent]
34
+ puts
35
+ puts '=' * 80
36
+ puts "#### Checksumming (SHA256) #{file}..."
37
+ puts '=' * 80
38
+ puts
39
+ end
40
+
41
+ Digest::SHA256.file(file).hexdigest
42
+ end
43
+
44
+ # Returns a versioned vars.json data structure
45
+ # @return [Hash] vars data structure
46
+ def data
47
+ sum = sha256sum(@iso)
48
+ box_distro_release = "SIMP-#{@target_release}-#{@target_data['flavor']}-#{@target_data['os_version']}"
49
+ {
50
+ 'simp_vars_version' => VARS_FORMAT_VERSION,
51
+ 'box_simp_release' => @target_release,
52
+ 'box_distro_release' => box_distro_release,
53
+ 'iso_url' => @iso,
54
+ 'iso_checksum' => sum,
55
+ 'iso_checksum_type' => 'sha256',
56
+ 'new_password' => 'suP3rP@ssw0r!suP3rP@ssw0r!suP3rP@ssw0r!',
57
+ 'output_directory' => './OUTPUT',
58
+ 'dist_os_flavor' => @target_data['flavor'],
59
+ 'dist_os_version' => @target_data['os_version'],
60
+ 'dist_os_maj_version' => @target_data['os_version'].split('.').first,
61
+ 'dist_source_isos' => @target_data['isos'].map { |x| File.basename(x) }.join(':'),
62
+ 'git_commit' => %x(git rev-parse --verify HEAD).strip,
63
+ 'packer_src_type' => 'simp-iso',
64
+ 'iso_builder' => 'rubygem-simp-rake-helpers',
65
+ 'iso_builder_version' => Simp::Rake::Helpers::VERSION
66
+ }
67
+ end
68
+
69
+ # Write data to a vars.json file for simp-packer to use
70
+ #
71
+ # @param file [String] path to vars.json file to write
72
+ # (Defaults to the same path as the .iso, with a `.json` extension)
73
+ def write(vars_file = @iso.sub(%r{.iso$}, '.json'))
74
+ unless @opts[:silent]
75
+ puts
76
+ puts '=' * 80
77
+ puts '#### Writing packer vars data to:'
78
+ puts " '#{vars_file}'"
79
+ puts '=' * 80
80
+ puts
81
+ end
82
+
83
+ File.open(vars_file, 'w') { |f| f.puts data.to_json }
84
+ end
85
+ end
86
+ end
87
+ end
@@ -4,6 +4,7 @@ require 'simp/rake'
4
4
  require 'json'
5
5
  require 'simp/rake/build/constants'
6
6
  require 'simp/rake/helpers'
7
+ require 'simp/packer/iso_vars_json'
7
8
 
8
9
  include Simp::Rake
9
10
 
@@ -102,7 +103,7 @@ module Simp::Rake::Build
102
103
  - SIMP_BUILD_staging_dir => Path to stage big build assets
103
104
  [Default: './SIMP_ISO_STAGING']
104
105
  - SIMP_BUILD_rm_staging_dir => 'no' do not forcibly remove the staging dir before starting
105
- - SIMP_BUILD_overlay => 'no' uses an existing DVD overlay if found
106
+ - SIMP_BUILD_overlay => 'no' uses an existing DVD overlay if found
106
107
  - SIMP_BUILD_force_dirty => 'yes' tries to checks out subrepos even if dirty
107
108
  - SIMP_BUILD_docs => 'yes' builds & includes documentation
108
109
  - SIMP_BUILD_checkout => 'no' will skip the git repo checkouts
@@ -113,7 +114,6 @@ module Simp::Rake::Build
113
114
  - SIMP_BUILD_iso_name => Renames the output ISO filename [Default: false]
114
115
  - SIMP_BUILD_iso_tag => Appended to the output ISO's filename [Default: false]
115
116
  - SIMP_BUILD_verbose => 'yes' enables verbose reporting. [Default: 'no']
116
- - SIMP_BUILD_packer_vars => Write a packer vars.json to go with this ISO [Default: 'yes']
117
117
  - SIMP_BUILD_signing_key => The name of the GPG key to use to sign packages. [Default: 'dev']
118
118
  EOM
119
119
 
@@ -139,7 +139,6 @@ module Simp::Rake::Build
139
139
  target_release = args[:release]
140
140
  do_checksum = (args.do_checksum = ~ /^$/ ? 'false' : args.do_checksum)
141
141
  key_name = args[:key_name]
142
- do_packer_vars = ENV.fetch('SIMP_BUILD_packer_vars', 'yes') == 'yes'
143
142
  verbose = ENV.fetch('SIMP_BUILD_verbose', 'no') == 'yes'
144
143
  prompt = ENV.fetch('SIMP_BUILD_prompt', 'yes') != 'no'
145
144
  method = ENV.fetch('SIMP_BUILD_puppetfile','tracking')
@@ -412,34 +411,8 @@ module Simp::Rake::Build
412
411
  FileUtils.mkdir_p File.dirname(iso), :verbose => verbose
413
412
  FileUtils.mv(@simp_output_iso, iso, :verbose => verbose)
414
413
 
415
- # write vars.json for packer build
416
- # --------------------------------------
417
- vars_file = iso.sub(/.iso$/, '.json')
418
- puts
419
- puts '='*80
420
- puts "#### Checksumming #{iso}..."
421
- puts '='*80
422
- puts
423
-
424
- sum = `sha256sum "#{iso}"`.split(/ +/).first
425
-
426
- puts
427
- puts '='*80
428
- puts "#### Writing packer data to:"
429
- puts " '#{vars_file}'"
430
- puts '='*80
431
- puts
432
- box_distro_release = "SIMP-#{target_release}-#{File.basename(target_data['isos'].first).sub(/\.iso$/,'').sub(/-x86_64/,'')}"
433
- packer_vars = {
434
- 'box_simp_release' => target_release,
435
- 'box_distro_release' => box_distro_release,
436
- 'iso_url' => iso,
437
- 'iso_checksum' => sum,
438
- 'iso_checksum_type' => 'sha256',
439
- 'new_password' => 'suP3rP@ssw0r!suP3rP@ssw0r!suP3rP@ssw0r!',
440
- 'output_directory' => './OUTPUT',
441
- }
442
- File.open(vars_file, 'w'){|f| f.puts packer_vars.to_json }
414
+ var_json = Simp::Packer::IsoVarsJson.new(iso, target_release, target_data, {})
415
+ var_json.write
443
416
 
444
417
  puts
445
418
  puts '='*80
@@ -557,6 +530,8 @@ module Simp::Rake::Build
557
530
  end
558
531
  FileUtils.mkdir_p staging_dir, :verbose => verbose
559
532
  end
533
+
534
+
560
535
  end
561
536
  end
562
537
  end
@@ -328,10 +328,10 @@ URL: %{lua: print(module_source)}
328
328
  BuildRoot: %{_tmppath}/%{package_name}-%{version}-%{release}-buildroot
329
329
  BuildArch: noarch
330
330
 
331
- Requires(pre): simp-adapter >= 0.0.1
332
- Requires(preun): simp-adapter >= 0.0.1
333
- Requires(preun): simp-adapter >= 0.0.1
334
- Requires(postun): simp-adapter >= 0.0.1
331
+ Requires(pre): simp-adapter >= 0.1.1
332
+ Requires(preun): simp-adapter >= 0.1.1
333
+ Requires(preun): simp-adapter >= 0.1.1
334
+ Requires(posttrans): simp-adapter >= 0.1.1
335
335
 
336
336
  %{lua: print(module_requires)}
337
337
 
@@ -485,11 +485,14 @@ mkdir -p %{buildroot}/%{prefix}
485
485
  -- This function should be called last
486
486
  --
487
487
  function declare_default_scriptlets(custom_content_table, declared_scriptlets_table)
488
+ local marker_dir = '%{_localstatedir}/lib/rpm-state/simp-adapter'
489
+ local marker_file = marker_dir..'/rpm_status$1.'..module_name
490
+
491
+
488
492
  local DEFAULT_SCRIPTLETS = {
489
- ['pre'] = {upgrade = 2},
490
- ['post'] = {upgrade = 2},
491
- ['preun'] = {upgrade = 0},
492
- ['postun'] = {upgrade = 0}
493
+ ['pre'] = {upgrade = 2, custom='mkdir -p '..marker_dir..'\ntouch '..marker_file..'\n'},
494
+ ['preun'] = {upgrade = 0, custom=''},
495
+ ['postun'] = {upgrade = 0, custom=''}
493
496
  }
494
497
  local rpm_dir = rpm.expand('%{prefix}/' .. module_name)
495
498
 
@@ -498,6 +501,7 @@ mkdir -p %{buildroot}/%{prefix}
498
501
  '# (default scriptlet for SIMP 6.x)\n'..
499
502
  '# when $1 = 1, this is an install\n'..
500
503
  '# when $1 = '.. data.upgrade ..', this is an upgrade\n'..
504
+ data.custom ..
501
505
  'if [ -x /usr/local/sbin/simp_rpm_helper ] ; then\n'..
502
506
  ' /usr/local/sbin/simp_rpm_helper --rpm_dir='..
503
507
  rpm_dir.." --rpm_section='"..name.."' --rpm_status=$1\n"..
@@ -506,6 +510,30 @@ mkdir -p %{buildroot}/%{prefix}
506
510
 
507
511
  define_custom_content(content, custom_content_table, declared_scriptlets_table)
508
512
  end
513
+
514
+ local install_marker_file = marker_dir..'/rpm_status1.'..module_name
515
+ local upgrade_marker_file = marker_dir..'/rpm_status2.'..module_name
516
+ local posttrans_content = ('%posttrans\n'..
517
+ '# (default scriptlet for SIMP 6.x)\n'..
518
+ '# Marker file is created in %pre and only exists for installs or upgrades\n'..
519
+ "# when marker file is prepended with 'rpm_status1.', this is an install\n"..
520
+ "# when marker file is prepended with 'rpm_status2.', this is an upgrade\n"..
521
+ 'if [ -e '..install_marker_file..' ] ; then\n'..
522
+ ' rm '..install_marker_file..'\n'..
523
+ ' if [ -x /usr/local/sbin/simp_rpm_helper ] ; then\n'..
524
+ ' /usr/local/sbin/simp_rpm_helper --rpm_dir='..
525
+ rpm_dir.." --rpm_section='posttrans' --rpm_status=1\n"..
526
+ ' fi\n'..
527
+ 'elif [ -e '..upgrade_marker_file..' ] ; then\n'..
528
+ ' rm '..upgrade_marker_file..'\n'..
529
+ ' if [ -x /usr/local/sbin/simp_rpm_helper ] ; then\n'..
530
+ ' /usr/local/sbin/simp_rpm_helper --rpm_dir='..
531
+ rpm_dir.." --rpm_section='posttrans' --rpm_status=2\n"..
532
+ ' fi\n'..
533
+ 'fi\n\n'
534
+ )
535
+
536
+ define_custom_content(posttrans_content, custom_content_table, declared_scriptlets_table)
509
537
  end
510
538
 
511
539
 
@@ -328,10 +328,10 @@ URL: %{lua: print(module_source)}
328
328
  BuildRoot: %{_tmppath}/%{package_name}-%{version}-%{release}-buildroot
329
329
  BuildArch: noarch
330
330
 
331
- Requires(pre): simp-adapter >= 0.0.1
332
- Requires(preun): simp-adapter >= 0.0.1
333
- Requires(preun): simp-adapter >= 0.0.1
334
- Requires(postun): simp-adapter >= 0.0.1
331
+ Requires(pre): simp-adapter >= 0.1.1
332
+ Requires(preun): simp-adapter >= 0.1.1
333
+ Requires(preun): simp-adapter >= 0.1.1
334
+ Requires(posttrans): simp-adapter >= 0.1.1
335
335
 
336
336
  %{lua: print(module_requires)}
337
337
 
@@ -485,11 +485,14 @@ mkdir -p %{buildroot}/%{prefix}
485
485
  -- This function should be called last
486
486
  --
487
487
  function declare_default_scriptlets(custom_content_table, declared_scriptlets_table)
488
+ local marker_dir = '%{_localstatedir}/lib/rpm-state/simp-adapter'
489
+ local marker_file = marker_dir..'/rpm_status$1.'..module_name
490
+
491
+
488
492
  local DEFAULT_SCRIPTLETS = {
489
- ['pre'] = {upgrade = 2},
490
- ['post'] = {upgrade = 2},
491
- ['preun'] = {upgrade = 0},
492
- ['postun'] = {upgrade = 0}
493
+ ['pre'] = {upgrade = 2, custom='mkdir -p '..marker_dir..'\ntouch '..marker_file..'\n'},
494
+ ['preun'] = {upgrade = 0, custom=''},
495
+ ['postun'] = {upgrade = 0, custom=''}
493
496
  }
494
497
  local rpm_dir = rpm.expand('%{prefix}/' .. module_name)
495
498
 
@@ -498,6 +501,7 @@ mkdir -p %{buildroot}/%{prefix}
498
501
  '# (default scriptlet for SIMP 6.x)\n'..
499
502
  '# when $1 = 1, this is an install\n'..
500
503
  '# when $1 = '.. data.upgrade ..', this is an upgrade\n'..
504
+ data.custom ..
501
505
  'if [ -x /usr/local/sbin/simp_rpm_helper ] ; then\n'..
502
506
  ' /usr/local/sbin/simp_rpm_helper --rpm_dir='..
503
507
  rpm_dir.." --rpm_section='"..name.."' --rpm_status=$1\n"..
@@ -506,6 +510,30 @@ mkdir -p %{buildroot}/%{prefix}
506
510
 
507
511
  define_custom_content(content, custom_content_table, declared_scriptlets_table)
508
512
  end
513
+
514
+ local install_marker_file = marker_dir..'/rpm_status1.'..module_name
515
+ local upgrade_marker_file = marker_dir..'/rpm_status2.'..module_name
516
+ local posttrans_content = ('%posttrans\n'..
517
+ '# (default scriptlet for SIMP 6.x)\n'..
518
+ '# Marker file is created in %pre and only exists for installs or upgrades\n'..
519
+ "# when marker file is prepended with 'rpm_status1.', this is an install\n"..
520
+ "# when marker file is prepended with 'rpm_status2.', this is an upgrade\n"..
521
+ 'if [ -e '..install_marker_file..' ] ; then\n'..
522
+ ' rm '..install_marker_file..'\n'..
523
+ ' if [ -x /usr/local/sbin/simp_rpm_helper ] ; then\n'..
524
+ ' /usr/local/sbin/simp_rpm_helper --rpm_dir='..
525
+ rpm_dir.." --rpm_section='posttrans' --rpm_status=1\n"..
526
+ ' fi\n'..
527
+ 'elif [ -e '..upgrade_marker_file..' ] ; then\n'..
528
+ ' rm '..upgrade_marker_file..'\n'..
529
+ ' if [ -x /usr/local/sbin/simp_rpm_helper ] ; then\n'..
530
+ ' /usr/local/sbin/simp_rpm_helper --rpm_dir='..
531
+ rpm_dir.." --rpm_section='posttrans' --rpm_status=2\n"..
532
+ ' fi\n'..
533
+ 'fi\n\n'
534
+ )
535
+
536
+ define_custom_content(posttrans_content, custom_content_table, declared_scriptlets_table)
509
537
  end
510
538
 
511
539
 
@@ -2,5 +2,5 @@ module Simp; end
2
2
  module Simp::Rake; end
3
3
 
4
4
  class Simp::Rake::Helpers
5
- VERSION = '5.6.2'
5
+ VERSION = '5.7.0'
6
6
  end
@@ -18,7 +18,7 @@ shared_examples_for 'an RPM generator with customized scriptlets' do
18
18
  expect(scriptlets.keys.sort).to eq [
19
19
  'pretrans',
20
20
  'preinstall',
21
- 'postinstall',
21
+ 'posttrans',
22
22
  'preuninstall',
23
23
  'postuninstall',
24
24
  ].sort
@@ -34,8 +34,8 @@ shared_examples_for 'an RPM generator with customized scriptlets' do
34
34
  "echo 'I override the default %%pre section provided by the spec file.'"
35
35
  )
36
36
 
37
- comment '...remaining default scriptlets call simp_rpm_helper with correct arguments'
38
- expected_simp_rpm_helper_scriptlets = scriptlet_label_map.select{|k,v| %w(post preun postun).include? v }
37
+ comment '...default preun postun scriptlets call simp_rpm_helper with correct arguments'
38
+ expected_simp_rpm_helper_scriptlets = scriptlet_label_map.select{|k,v| %w(preun postun).include? v }
39
39
  expected_simp_rpm_helper_scriptlets.each do |rpm_label, simp_helper_label|
40
40
  expected = <<EOM
41
41
  if [ -x /usr/local/sbin/simp_rpm_helper ] ; then
@@ -44,6 +44,22 @@ fi
44
44
  EOM
45
45
  expect(scriptlets[rpm_label][:bare_content]).to eq(expected.strip)
46
46
  end
47
+
48
+ comment '...default posttrans scriptlet calls simp_rpm_helper with correct arguments'
49
+ expected = <<EOM
50
+ if [ -e %{_localstatedir}/lib/rpm-state/simp-adapter/rpm_status1.testpackage ] ; then
51
+ rm %{_localstatedir}/lib/rpm-state/simp-adapter/rpm_status1.testpackage
52
+ if [ -x /usr/local/sbin/simp_rpm_helper ] ; then
53
+ /usr/local/sbin/simp_rpm_helper --rpm_dir=/usr/share/simp/modules/testpackage --rpm_section='posttrans' --rpm_status=1
54
+ fi
55
+ elif [ -e %{_localstatedir}/lib/rpm-state/simp-adapter/rpm_status2.testpackage ] ; then
56
+ rm %{_localstatedir}/lib/rpm-state/simp-adapter/rpm_status2.testpackage
57
+ if [ -x /usr/local/sbin/simp_rpm_helper ] ; then
58
+ /usr/local/sbin/simp_rpm_helper --rpm_dir=/usr/share/simp/modules/testpackage --rpm_section='posttrans' --rpm_status=2
59
+ fi
60
+ fi
61
+ EOM
62
+ expect(scriptlets['posttrans'][:bare_content]).to eq(expected.strip)
47
63
  end
48
64
  end
49
65
 
@@ -135,14 +135,58 @@ describe 'rake pkg:rpm' do
135
135
  comment 'produces RPM with a sourced CHANGELOG'
136
136
  on host, %(rpm --changelog -qp #{testpackage_rpm} | grep -q Stallman)
137
137
 
138
- comment 'produces RPM with appropriate pre/post/preun/postun'
139
- result = on host, %(rpm -qp --scripts #{testpackage_rpm})
140
- scriptlets = result.stdout.scan( %r{^.*?scriptlet.*?/usr/local/sbin/simp_rpm_helper --rpm_dir=/usr/share/simp/modules/testpackage.*?fi$}m )
141
-
142
- expect( scriptlets.grep( %r{\Apreinstall scriptlet.* /usr/local/sbin/simp_rpm_helper --rpm_dir=/usr/share/simp/modules/testpackage --rpm_section='pre' --rpm_status=\$1}m )).not_to be_empty
143
- expect( scriptlets.grep( %r{\Apostinstall scriptlet.* /usr/local/sbin/simp_rpm_helper --rpm_dir=/usr/share/simp/modules/testpackage --rpm_section='post' --rpm_status=\$1}m )).not_to be_empty
144
- expect( scriptlets.grep( %r{\Apreuninstall scriptlet.* /usr/local/sbin/simp_rpm_helper --rpm_dir=/usr/share/simp/modules/testpackage --rpm_section='preun' --rpm_status=\$1}m )).not_to be_empty
145
- expect( scriptlets.grep( %r{\Apostuninstall scriptlet.* /usr/local/sbin/simp_rpm_helper --rpm_dir=/usr/share/simp/modules/testpackage --rpm_section='postun' --rpm_status=\$1}m )).not_to be_empty
138
+ comment 'produces RPM with appropriate pre/preun/postun/posttrans'
139
+ scriptlets = rpm_scriptlets_for(host, testpackage_rpm)
140
+
141
+ comment '...the expected scriptlet types are present'
142
+ expect(scriptlets.keys.sort).to eq [
143
+ 'preinstall',
144
+ 'preuninstall',
145
+ 'postuninstall',
146
+ 'posttrans',
147
+ ].sort
148
+
149
+ comment '...default preinstall scriptlet'
150
+ expected =<<-EOM
151
+ mkdir -p %{_localstatedir}/lib/rpm-state/simp-adapter
152
+ touch %{_localstatedir}/lib/rpm-state/simp-adapter/rpm_status$1.testpackage
153
+ if [ -x /usr/local/sbin/simp_rpm_helper ] ; then
154
+ /usr/local/sbin/simp_rpm_helper --rpm_dir=/usr/share/simp/modules/testpackage --rpm_section='pre' --rpm_status=$1
155
+ fi
156
+ EOM
157
+ expect(scriptlets['preinstall'][:bare_content]).to eq( expected.strip )
158
+
159
+ comment '...default preuninstall scriptlet'
160
+ expected =<<-EOM
161
+ if [ -x /usr/local/sbin/simp_rpm_helper ] ; then
162
+ /usr/local/sbin/simp_rpm_helper --rpm_dir=/usr/share/simp/modules/testpackage --rpm_section='preun' --rpm_status=$1
163
+ fi
164
+ EOM
165
+ expect(scriptlets['preuninstall'][:bare_content]).to eq( expected.strip )
166
+
167
+ comment '...default postuninstall scriptlet'
168
+ expected =<<-EOM
169
+ if [ -x /usr/local/sbin/simp_rpm_helper ] ; then
170
+ /usr/local/sbin/simp_rpm_helper --rpm_dir=/usr/share/simp/modules/testpackage --rpm_section='postun' --rpm_status=$1
171
+ fi
172
+ EOM
173
+ expect(scriptlets['postuninstall'][:bare_content]).to eq( expected.strip )
174
+
175
+ comment '...default posttrans scriptlet'
176
+ expected =<<-EOM
177
+ if [ -e %{_localstatedir}/lib/rpm-state/simp-adapter/rpm_status1.testpackage ] ; then
178
+ rm %{_localstatedir}/lib/rpm-state/simp-adapter/rpm_status1.testpackage
179
+ if [ -x /usr/local/sbin/simp_rpm_helper ] ; then
180
+ /usr/local/sbin/simp_rpm_helper --rpm_dir=/usr/share/simp/modules/testpackage --rpm_section='posttrans' --rpm_status=1
181
+ fi
182
+ elif [ -e %{_localstatedir}/lib/rpm-state/simp-adapter/rpm_status2.testpackage ] ; then
183
+ rm %{_localstatedir}/lib/rpm-state/simp-adapter/rpm_status2.testpackage
184
+ if [ -x /usr/local/sbin/simp_rpm_helper ] ; then
185
+ /usr/local/sbin/simp_rpm_helper --rpm_dir=/usr/share/simp/modules/testpackage --rpm_section='posttrans' --rpm_status=2
186
+ fi
187
+ fi
188
+ EOM
189
+ expect(scriptlets['posttrans'][:bare_content]).to eq( expected.strip )
146
190
  end
147
191
 
148
192
  it_should_behave_like 'an RPM generator with edge cases'