poise-languages 1.1.0 → 1.2.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a83f0d87752ae0d05c9559e572dcc877b4ff6383
4
- data.tar.gz: 4d97ce1203bdbe9f54d070d2942be3ebdae14ad7
3
+ metadata.gz: f4a05fa47de317277eae76e90f0e2f8fd4f03d72
4
+ data.tar.gz: e3c4ef2901a9c2ccb9f0467334389060533448e2
5
5
  SHA512:
6
- metadata.gz: 364248c8d0541ec0f3fe00db0f9c260129214cf467008b5f77b19988a4c06d60a0aafef8698c7d190383ebb000b3a58f03b76f05ad01cdc2ef46d8d4d67df32c
7
- data.tar.gz: 54c6bf4cfbce36e651b265f32c818f78ef1c5df358a2402fb26eb060a30df2820a9c467202836d005fd3ffe5fef9e4e5bd2bcded9df550f9cce5d32d17ddd8fe
6
+ metadata.gz: dce25fe02f0b2c9c66764c19d1278d95262b0a2ae7aa2ff865a223baa21f6acc97df83ef22cd1e438e378ca9043f2bfca19d522c24e63be5818cae7394142557
7
+ data.tar.gz: b0ec72f8eda800c9a0a0423920c5bd704697af0c4561431d3e30e14e471b495b9b240e6e2aa288b5f1fc38c19203d27a9e859ff9577ee8d16a97032f3e2d1cc5
data/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # Changelog
2
2
 
3
+ ## v1.2.0
4
+
5
+ * Support for installing development headers with SCL providers.
6
+ * Add `PoiseLanguages::Utils.shelljoin` for encoding command arrays with some
7
+ bash metadata characters allowed.
8
+ * [#1](https://github.com/poise/poise-languages/pull/1) – Fix typo in gemspec.
9
+
3
10
  ## v1.1.0
4
11
 
5
12
  * Add helpers for installing from static archives.
@@ -24,9 +24,12 @@ module PoiseLanguages
24
24
 
25
25
  def install_scl_package
26
26
  pkg = scl_package
27
- poise_languages_scl pkg[:name] do
27
+ poise_languages_scl options[:package_name] || pkg[:name] do
28
+ action :upgrade if options[:package_upgrade]
29
+ dev_package options[:dev_package] == true ? pkg[:devel_name] : options[:dev_package]
28
30
  parent new_resource
29
31
  url pkg[:url]
32
+ version options[:package_version]
30
33
  end
31
34
  end
32
35
 
@@ -83,6 +86,23 @@ module PoiseLanguages
83
86
  !!find_scl_package(node, version)
84
87
  end
85
88
 
89
+ # Set some default inversion provider options. Package name can't get
90
+ # a default value here because that would complicate the handling of
91
+ # {system_package_candidates}.
92
+ #
93
+ # @api private
94
+ def default_inversion_options(node, resource)
95
+ super.merge({
96
+ # Install dev headers?
97
+ dev_package: true,
98
+ # Manual overrides for package name and/or version.
99
+ package_name: nil,
100
+ package_version: nil,
101
+ # Set to true to use action :upgrade on system packages.
102
+ package_upgrade: false,
103
+ })
104
+ end
105
+
86
106
  def find_scl_package(node, version)
87
107
  pkg = scl_packages.find {|p| p[:version].start_with?(version) }
88
108
  return unless pkg
@@ -97,8 +117,8 @@ module PoiseLanguages
97
117
  @scl_packages ||= []
98
118
  end
99
119
 
100
- def scl_package(version, name, urls)
101
- scl_packages << {version: version, name: name, urls: urls}
120
+ def scl_package(version, name, devel_name=nil, urls)
121
+ scl_packages << {version: version, name: name, devel_name: devel_name, urls: urls}
102
122
  end
103
123
 
104
124
  def included(klass)
@@ -33,16 +33,18 @@ module PoiseLanguages
33
33
  class Resource < Chef::Resource
34
34
  include Poise
35
35
  provides(:poise_languages_scl)
36
- actions(:install, :uninstall)
36
+ actions(:install, :upgrade, :uninstall)
37
37
 
38
38
  # @!attribute package_name
39
39
  # Name of the SCL package for the language.
40
40
  # @return [String]
41
41
  attribute(:package_name, kind_of: String, name_attribute: true)
42
+ attribute(:dev_package, kind_of: [String, NilClass])
42
43
  # @!attribute url
43
44
  # URL to the SCL repository package for the language.
44
45
  # @return [String]
45
46
  attribute(:url, kind_of: String, required: true)
47
+ attribute(:version, kind_of: [String, NilClass])
46
48
  # @!attribute parent
47
49
  # Resource for the language runtime. Used only for messages.
48
50
  # @return [Chef::Resource]
@@ -66,7 +68,22 @@ module PoiseLanguages
66
68
  notifying_block do
67
69
  install_scl_utils
68
70
  install_scl_repo_package
69
- install_scl_package
71
+ flush_yum_cache
72
+ install_scl_package(:install)
73
+ install_scl_devel_package(:install) if new_resource.dev_package
74
+ end
75
+ end
76
+
77
+ # The `upgrade` action for the `poise_languages_scl` resource.
78
+ #
79
+ # @return [void]
80
+ def action_upgrade
81
+ notifying_block do
82
+ install_scl_utils
83
+ install_scl_repo_package
84
+ flush_yum_cache
85
+ install_scl_package(:upgrade)
86
+ install_scl_devel_package(:upgrade) if new_resource.dev_package
70
87
  end
71
88
  end
72
89
 
@@ -77,7 +94,9 @@ module PoiseLanguages
77
94
  notifying_block do
78
95
  uninstall_scl_utils
79
96
  uninstall_scl_repo_package
97
+ uninstall_scl_devel_package if new_resource.dev_package
80
98
  uninstall_scl_package
99
+ flush_yum_cache
81
100
  end
82
101
  end
83
102
 
@@ -95,9 +114,25 @@ module PoiseLanguages
95
114
  end
96
115
  end
97
116
 
98
- def install_scl_package
117
+ def flush_yum_cache
118
+ ruby_block 'flush_yum_cache' do
119
+ block do
120
+ # Equivalent to flush_cache after: true
121
+ Chef::Provider::Package::Yum::YumCache.instance.reload
122
+ end
123
+ end
124
+ end
125
+
126
+ def install_scl_package(action)
99
127
  yum_package new_resource.package_name do
100
- flush_cache before: true
128
+ action action
129
+ version new_resource.version
130
+ end
131
+ end
132
+
133
+ def install_scl_devel_package(action)
134
+ yum_package new_resource.dev_package do
135
+ action action
101
136
  end
102
137
  end
103
138
 
@@ -114,9 +149,11 @@ module PoiseLanguages
114
149
  end
115
150
 
116
151
  def uninstall_scl_package
117
- install_scl_package.tap do |r|
118
- r.action(:remove)
119
- end
152
+ install_scl_package(:remove)
153
+ end
154
+
155
+ def uninstall_scl_devel_package
156
+ install_scl_devel_package(:remove)
120
157
  end
121
158
 
122
159
  end
@@ -24,6 +24,25 @@ module PoiseLanguages
24
24
  include Which
25
25
  extend self
26
26
 
27
+ # Default whitelist for {#shelljoin}.
28
+ SHELLJOIN_WHITELIST = [/^2?[><]/]
29
+
30
+ # An improved version of Shellwords.shelljoin that doesn't escape a few
31
+ # things.
32
+ #
33
+ # @param cmd [Array<String>] Command array to join.
34
+ # @param whitelist [Array<Regexp>] Array of patterns to whitelist.
35
+ # @return [String]
36
+ def shelljoin(cmd, whitelist: SHELLJOIN_WHITELIST)
37
+ cmd.map do |str|
38
+ if whitelist.any? {|pat| str =~ pat }
39
+ str
40
+ else
41
+ Shellwords.shellescape(str)
42
+ end
43
+ end.join(' ')
44
+ end
45
+
27
46
  # Convert the executable in a string or array command to an absolute path.
28
47
  #
29
48
  # @param cmd [String, Array<String>] Command to fix up.
@@ -41,7 +60,7 @@ module PoiseLanguages
41
60
  # If which returns false, just leave it I guess.
42
61
  cmd[0] = which(cmd.first, path: path) || cmd.first
43
62
  end
44
- cmd = Shellwords.join(cmd) unless was_array
63
+ cmd = shelljoin(cmd) unless was_array
45
64
  cmd
46
65
  end
47
66
 
@@ -16,5 +16,5 @@
16
16
 
17
17
 
18
18
  module PoiseLanguages
19
- VERSION = '1.1.0'
19
+ VERSION = '1.2.0'
20
20
  end
@@ -23,7 +23,7 @@ Gem::Specification.new do |spec|
23
23
  spec.version = PoiseLanguages::VERSION
24
24
  spec.authors = ['Noah Kantrowitz']
25
25
  spec.email = %w{noah@coderanger.net}
26
- spec.description = "A Chef cookbook to help writing language cooobkoks."
26
+ spec.description = "A Chef cookbook to help writing language cookbooks."
27
27
  spec.summary = spec.description
28
28
  spec.homepage = 'https://github.com/poise/poise-languages'
29
29
  spec.license = 'Apache 2.0'
@@ -29,6 +29,9 @@ describe PoiseLanguages::Scl::Mixin do
29
29
  def scl_package
30
30
  {name: 'python34', url: 'http://something.rpm'}
31
31
  end
32
+ def options
33
+ {dev_package: true}
34
+ end
32
35
  def action_run
33
36
  install_scl_package
34
37
  end
@@ -47,6 +50,9 @@ describe PoiseLanguages::Scl::Mixin do
47
50
  def scl_package
48
51
  {name: 'python34', url: 'http://something.rpm'}
49
52
  end
53
+ def options
54
+ {dev_package: true}
55
+ end
50
56
  def action_run
51
57
  uninstall_scl_package
52
58
  end
@@ -181,6 +187,17 @@ EOH
181
187
  end # /context with an scl_source line
182
188
  end # /describe #parse_enable_file
183
189
 
190
+ describe '.default_inversion_options' do
191
+ provider(:poise_test) do
192
+ include Poise(inversion: :poise_test)
193
+ include described_class
194
+ end
195
+ let(:node) { double('node') }
196
+ let(:new_resource) { double('resource') }
197
+ subject { provider(:poise_test).default_inversion_options(node, new_resource) }
198
+ it { is_expected.to eq({dev_package: true, package_name: nil, package_version: nil, package_upgrade: false}) }
199
+ end # /describe .default_inversion_options
200
+
184
201
  describe '.provides_auto?' do
185
202
  let(:node) { double('node', :"[]" => {'machine' => 'x86_64'}) }
186
203
  let(:new_resource) { double('resource') }
@@ -196,13 +213,13 @@ EOH
196
213
  let(:version) { '' }
197
214
  provider(:poise_test) do
198
215
  include described_class
199
- scl_package('3.4.2', 'rh-python34', {
216
+ scl_package('3.4.2', 'rh-python34', 'rh-python34-python-devel', {
200
217
  ['redhat', 'centos'] => {
201
218
  '~> 7.0' => 'https://www.softwarecollections.org/en/scls/rhscl/rh-python34/epel-7-x86_64/download/rhscl-rh-python34-epel-7-x86_64.noarch.rpm',
202
219
  '~> 6.0' => 'https://www.softwarecollections.org/en/scls/rhscl/rh-python34/epel-6-x86_64/download/rhscl-rh-python34-epel-6-x86_64.noarch.rpm',
203
220
  },
204
221
  })
205
- scl_package('3.3.2', 'python33', {
222
+ scl_package('3.3.2', 'python33', 'python33-python-devel', {
206
223
  ['redhat', 'centos'] => {
207
224
  '~> 7.0' => 'https://www.softwarecollections.org/en/scls/rhscl/python33/epel-7-x86_64/download/rhscl-python33-epel-7-x86_64.noarch.rpm',
208
225
  '~> 6.0' => 'https://www.softwarecollections.org/en/scls/rhscl/python33/epel-6-x86_64/download/rhscl-python33-epel-6-x86_64.noarch.rpm',
@@ -221,6 +238,7 @@ EOH
221
238
  is_expected.to include({
222
239
  version: '3.4.2',
223
240
  name: 'rh-python34',
241
+ devel_name: 'rh-python34-python-devel',
224
242
  url: 'https://www.softwarecollections.org/en/scls/rhscl/rh-python34/epel-7-x86_64/download/rhscl-rh-python34-epel-7-x86_64.noarch.rpm',
225
243
  })
226
244
  end
@@ -233,6 +251,7 @@ EOH
233
251
  is_expected.to include({
234
252
  version: '3.3.2',
235
253
  name: 'python33',
254
+ devel_name: 'python33-python-devel',
236
255
  url: 'https://www.softwarecollections.org/en/scls/rhscl/python33/epel-6-x86_64/download/rhscl-python33-epel-6-x86_64.noarch.rpm',
237
256
  })
238
257
  end
@@ -242,5 +261,26 @@ EOH
242
261
  let(:chefspec_options) { {platform: 'ubuntu', version: '12.04'} }
243
262
  it { is_expected.to be_nil }
244
263
  end # /context on Ubuntu
264
+
265
+ context 'with no devel package' do
266
+ provider(:poise_test) do
267
+ include described_class
268
+ scl_package('3.4.2', 'rh-python34', {
269
+ ['redhat', 'centos'] => {
270
+ '~> 7.0' => 'https://www.softwarecollections.org/en/scls/rhscl/rh-python34/epel-7-x86_64/download/rhscl-rh-python34-epel-7-x86_64.noarch.rpm',
271
+ '~> 6.0' => 'https://www.softwarecollections.org/en/scls/rhscl/rh-python34/epel-6-x86_64/download/rhscl-rh-python34-epel-6-x86_64.noarch.rpm',
272
+ },
273
+ })
274
+ end
275
+ let(:chefspec_options) { {platform: 'centos', version: '7.0'} }
276
+ it do
277
+ is_expected.to include({
278
+ version: '3.4.2',
279
+ name: 'rh-python34',
280
+ devel_name: nil,
281
+ url: 'https://www.softwarecollections.org/en/scls/rhscl/rh-python34/epel-7-x86_64/download/rhscl-rh-python34-epel-7-x86_64.noarch.rpm',
282
+ })
283
+ end
284
+ end # /context with no devel package
245
285
  end # /describe .find_scl_package
246
286
  end
@@ -18,12 +18,20 @@ require 'spec_helper'
18
18
 
19
19
  describe PoiseLanguages::Scl::Resource do
20
20
  step_into(:poise_languages_scl)
21
+ step_into(:ruby_block)
21
22
  let(:chefspec_options) { {platform: 'centos', version: '7.0'} }
23
+ let(:yum_cache) { double('yum_cache', reload: nil) }
24
+ before do
25
+ allow(Chef::Provider::Package::Yum::YumCache).to receive(:instance).and_return(yum_cache)
26
+ end
22
27
 
23
28
  context 'action :install' do
24
29
  recipe do
25
- r = ruby_block 'parent'
30
+ r = ruby_block 'parent' do
31
+ block { }
32
+ end
26
33
  poise_languages_scl 'mylang' do
34
+ dev_package 'mylang-devel'
27
35
  parent r
28
36
  url 'http://mylang.rpm'
29
37
  end
@@ -31,14 +39,39 @@ describe PoiseLanguages::Scl::Resource do
31
39
 
32
40
  it { is_expected.to upgrade_package('scl-utils') }
33
41
  it { is_expected.to install_rpm_package('rhscl-mylang').with(source: 'http://mylang.rpm') }
34
- it { is_expected.to install_yum_package('mylang').with(flush_cache: {before: true}) }
42
+ it { is_expected.to install_yum_package('mylang') }
43
+ it { is_expected.to install_yum_package('mylang-devel') }
44
+ it { expect(yum_cache).to receive(:reload); run_chef }
35
45
  end # /context action :install
36
46
 
47
+ context 'action :upgrade' do
48
+ recipe do
49
+ r = ruby_block 'parent' do
50
+ block { }
51
+ end
52
+ poise_languages_scl 'mylang' do
53
+ action :upgrade
54
+ dev_package 'mylang-devel'
55
+ parent r
56
+ url 'http://mylang.rpm'
57
+ end
58
+ end
59
+
60
+ it { is_expected.to upgrade_package('scl-utils') }
61
+ it { is_expected.to install_rpm_package('rhscl-mylang').with(source: 'http://mylang.rpm') }
62
+ it { is_expected.to upgrade_yum_package('mylang') }
63
+ it { is_expected.to upgrade_yum_package('mylang-devel') }
64
+ it { expect(yum_cache).to receive(:reload); run_chef }
65
+ end # /context action :upgrade
66
+
37
67
  context 'action :uninstall' do
38
68
  recipe do
39
- r = ruby_block 'parent'
69
+ r = ruby_block 'parent' do
70
+ block { }
71
+ end
40
72
  poise_languages_scl 'mylang' do
41
73
  action :uninstall
74
+ dev_package 'mylang-devel'
42
75
  parent r
43
76
  url 'http://mylang.rpm'
44
77
  end
@@ -47,5 +80,7 @@ describe PoiseLanguages::Scl::Resource do
47
80
  it { is_expected.to remove_package('scl-utils') }
48
81
  it { is_expected.to remove_rpm_package('rhscl-mylang') }
49
82
  it { is_expected.to remove_yum_package('mylang') }
83
+ it { is_expected.to remove_yum_package('mylang-devel') }
84
+ it { expect(yum_cache).to receive(:reload); run_chef }
50
85
  end # /context action :uninstall
51
86
  end
@@ -17,6 +17,45 @@
17
17
  require 'spec_helper'
18
18
 
19
19
  describe PoiseLanguages::Utils do
20
+ describe '#shelljoin' do
21
+ let(:cmd) { [] }
22
+ subject { described_class.shelljoin(cmd) }
23
+
24
+ context 'with an empty array' do
25
+ it { is_expected.to eq '' }
26
+ end # /context with an empty array
27
+
28
+ context 'with simple arguments' do
29
+ let(:cmd) { %w{a b c} }
30
+ it { is_expected.to eq 'a b c' }
31
+ end # /context with simple arguments
32
+
33
+ context 'with complex arguments' do
34
+ let(:cmd) { ['a', 'b c', '--d=e'] }
35
+ it { is_expected.to eq 'a b\\ c --d\\=e' }
36
+ end # /context with complex arguments
37
+
38
+ context 'with input redirect' do
39
+ let(:cmd) { %w{a b < c} }
40
+ it { is_expected.to eq 'a b < c' }
41
+ end # /context with input redirect
42
+
43
+ context 'with input redirect and no space' do
44
+ let(:cmd) { %w{a b <c} }
45
+ it { is_expected.to eq 'a b <c' }
46
+ end # /context with input redirect
47
+
48
+ context 'with output redirect' do
49
+ let(:cmd) { %w{a b > c} }
50
+ it { is_expected.to eq 'a b > c' }
51
+ end # /context with output redirect
52
+
53
+ context 'with error redirect' do
54
+ let(:cmd) { %w{a b 2> c} }
55
+ it { is_expected.to eq 'a b 2> c' }
56
+ end # /context with error redirect
57
+ end # /describe #shelljoin
58
+
20
59
  describe '#absolute_command' do
21
60
  let(:path) { double('path') }
22
61
  let(:cmd) { }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: poise-languages
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Noah Kantrowitz
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-09-28 00:00:00.000000000 Z
11
+ date: 2015-10-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: halite
@@ -52,7 +52,7 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '1.0'
55
- description: A Chef cookbook to help writing language cooobkoks.
55
+ description: A Chef cookbook to help writing language cookbooks.
56
56
  email:
57
57
  - noah@coderanger.net
58
58
  executables: []
@@ -118,7 +118,7 @@ rubyforge_project:
118
118
  rubygems_version: 2.4.8
119
119
  signing_key:
120
120
  specification_version: 4
121
- summary: A Chef cookbook to help writing language cooobkoks.
121
+ summary: A Chef cookbook to help writing language cookbooks.
122
122
  test_files:
123
123
  - test/docker/docker.ca
124
124
  - test/docker/docker.pem