chef-sugar-ng 4.2.2

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.
Files changed (65) hide show
  1. checksums.yaml +7 -0
  2. data/.github/lock.yml +3 -0
  3. data/.github/reaction.yml +1 -0
  4. data/.gitignore +26 -0
  5. data/.kitchen.yml +16 -0
  6. data/.travis.yml +17 -0
  7. data/CHANGELOG.md +261 -0
  8. data/CONTRIBUTING.md +20 -0
  9. data/Gemfile +2 -0
  10. data/LICENSE +201 -0
  11. data/README.md +540 -0
  12. data/Rakefile +11 -0
  13. data/chef-sugar-ng.gemspec +33 -0
  14. data/lib/chef/sugar.rb +51 -0
  15. data/lib/chef/sugar/architecture.rb +171 -0
  16. data/lib/chef/sugar/cloud.rb +192 -0
  17. data/lib/chef/sugar/constraints.rb +108 -0
  18. data/lib/chef/sugar/constraints_dsl.rb +83 -0
  19. data/lib/chef/sugar/core_extensions.rb +19 -0
  20. data/lib/chef/sugar/core_extensions/array.rb +34 -0
  21. data/lib/chef/sugar/core_extensions/object.rb +27 -0
  22. data/lib/chef/sugar/core_extensions/string.rb +66 -0
  23. data/lib/chef/sugar/data_bag.rb +146 -0
  24. data/lib/chef/sugar/docker.rb +40 -0
  25. data/lib/chef/sugar/filters.rb +227 -0
  26. data/lib/chef/sugar/init.rb +62 -0
  27. data/lib/chef/sugar/ip.rb +48 -0
  28. data/lib/chef/sugar/kernel.rb +49 -0
  29. data/lib/chef/sugar/kitchen.rb +40 -0
  30. data/lib/chef/sugar/node.rb +213 -0
  31. data/lib/chef/sugar/platform.rb +327 -0
  32. data/lib/chef/sugar/platform_family.rb +179 -0
  33. data/lib/chef/sugar/ruby.rb +51 -0
  34. data/lib/chef/sugar/run_context.rb +41 -0
  35. data/lib/chef/sugar/shell.rb +147 -0
  36. data/lib/chef/sugar/vagrant.rb +77 -0
  37. data/lib/chef/sugar/version.rb +21 -0
  38. data/lib/chef/sugar/virtualization.rb +151 -0
  39. data/libraries/chef-sugar.rb +1 -0
  40. data/metadata.rb +24 -0
  41. data/recipes/default.rb +20 -0
  42. data/spec/spec_helper.rb +25 -0
  43. data/spec/support/shared_examples.rb +20 -0
  44. data/spec/unit/chef/sugar/architecture_spec.rb +129 -0
  45. data/spec/unit/chef/sugar/cloud_spec.rb +149 -0
  46. data/spec/unit/chef/sugar/constraints_spec.rb +45 -0
  47. data/spec/unit/chef/sugar/core_extensions/array_spec.rb +10 -0
  48. data/spec/unit/chef/sugar/core_extensions/object_spec.rb +62 -0
  49. data/spec/unit/chef/sugar/core_extensions/string_spec.rb +48 -0
  50. data/spec/unit/chef/sugar/data_bag_spec.rb +118 -0
  51. data/spec/unit/chef/sugar/docker_spec.rb +39 -0
  52. data/spec/unit/chef/sugar/init_spec.rb +74 -0
  53. data/spec/unit/chef/sugar/ip_spec.rb +53 -0
  54. data/spec/unit/chef/sugar/kernel_spec.rb +16 -0
  55. data/spec/unit/chef/sugar/kitchen_spec.rb +18 -0
  56. data/spec/unit/chef/sugar/node_spec.rb +172 -0
  57. data/spec/unit/chef/sugar/platform_family_spec.rb +166 -0
  58. data/spec/unit/chef/sugar/platform_spec.rb +342 -0
  59. data/spec/unit/chef/sugar/ruby_spec.rb +39 -0
  60. data/spec/unit/chef/sugar/run_context_spec.rb +19 -0
  61. data/spec/unit/chef/sugar/shell_spec.rb +104 -0
  62. data/spec/unit/chef/sugar/vagrant_spec.rb +37 -0
  63. data/spec/unit/chef/sugar/virtualization_spec.rb +135 -0
  64. data/spec/unit/recipes/default_spec.rb +9 -0
  65. metadata +202 -0
@@ -0,0 +1,21 @@
1
+ #
2
+ # Copyright 2013-2015, Seth Vargo <sethvargo@gmail.com>
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+
17
+ class Chef
18
+ module Sugar
19
+ VERSION = '4.2.2'
20
+ end
21
+ end
@@ -0,0 +1,151 @@
1
+ #
2
+ # Copyright 2014, Joseph J. Nuspl Jr. <nuspl@nvwls.com>
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+
17
+ class Chef
18
+ module Sugar
19
+ module Virtualization
20
+ extend self
21
+
22
+ #
23
+ # Determine if the current node is running under KVM.
24
+ #
25
+ # @param [Chef::Node] node
26
+ #
27
+ # @return [Boolean]
28
+ # true if the machine is currently running under KVM, false
29
+ # otherwise
30
+ #
31
+ def kvm?(node)
32
+ node.key?('virtualization') && node['virtualization']['system'] == 'kvm'
33
+ end
34
+
35
+ #
36
+ # Determine if the current node is running in a linux container.
37
+ #
38
+ # @param [Chef::Node] node
39
+ #
40
+ # @return [Boolean]
41
+ # true if the machine is currently running in a container, false
42
+ # otherwise
43
+ #
44
+ def lxc?(node)
45
+ node.key?('virtualization') && node['virtualization']['system'] == 'lxc'
46
+ end
47
+
48
+ #
49
+ # Determine if the current node is running under Parallels Desktop.
50
+ #
51
+ # @param [Chef::Node] node
52
+ #
53
+ # @return [Boolean]
54
+ # true if the machine is currently running under Parallels Desktop, false
55
+ # otherwise
56
+ #
57
+ def parallels?(node)
58
+ node.key?('virtualization') && node['virtualization']['system'] == 'Parallels'
59
+ end
60
+
61
+ #
62
+ # Determine if the current node is running under VirtualBox.
63
+ #
64
+ # @param [Chef::Node] node
65
+ #
66
+ # @return [Boolean]
67
+ # true if the machine is currently running under VirtualBox, false
68
+ # otherwise
69
+ #
70
+ def virtualbox?(node)
71
+ node.key?('virtualization') && node['virtualization']['system'] == 'vbox'
72
+ end
73
+
74
+ #
75
+ # Determine if the current node is running under VMware.
76
+ #
77
+ # @param [Chef::Node] node
78
+ #
79
+ # @return [Boolean]
80
+ # true if the machine is currently running under VMware, false
81
+ # otherwise
82
+ #
83
+ def vmware?(node)
84
+ node.key?('virtualization') && node['virtualization']['system'] == 'vmware'
85
+ end
86
+
87
+ #
88
+ # Determine if the current node is running under openvz.
89
+ #
90
+ # @param [Chef::Node] node
91
+ #
92
+ # @return [Boolean]
93
+ # true if the machine is currently running under openvz, false
94
+ # otherwise
95
+ #
96
+ def openvz?(node)
97
+ node.key?('virtualization') && node['virtualization']['system'] == 'openvz'
98
+ end
99
+
100
+ def virtual?(node)
101
+ openvz?(node) || vmware?(node) || virtualbox?(node) || parallels?(node) || lxc?(node) || kvm?(node)
102
+ end
103
+
104
+ def physical?(node)
105
+ !virtual?(node)
106
+ end
107
+ end
108
+
109
+ module DSL
110
+ # @see Chef::Sugar::Virtualization#kvm?
111
+ def kvm?
112
+ Chef::Sugar::Virtualization.kvm?(node)
113
+ end
114
+
115
+ # @see Chef::Sugar::Virtualization#lxc?
116
+ def lxc?
117
+ Chef::Sugar::Virtualization.lxc?(node)
118
+ end
119
+
120
+ # @see Chef::Sugar::Virtualization#parallels?
121
+ def parallels?
122
+ Chef::Sugar::Virtualization.parallels?(node)
123
+ end
124
+
125
+ # @see Chef::Sugar::Virtualization#virtualbox?
126
+ def virtualbox?
127
+ Chef::Sugar::Virtualization.virtualbox?(node)
128
+ end
129
+
130
+ # @see Chef::Sugar::Virtualization#vmware?
131
+ def vmware?
132
+ Chef::Sugar::Virtualization.vmware?(node)
133
+ end
134
+
135
+ # @see Chef::Sugar::Virtualization#openvz?
136
+ def openvz?
137
+ Chef::Sugar::Virtualization.openvz?(node)
138
+ end
139
+
140
+ # @see Chef::Sugar::Virtualization#virtual?
141
+ def virtual?
142
+ Chef::Sugar::Virtualization.virtual?(node)
143
+ end
144
+
145
+ # @see Chef::Sugar::Virtualization#physical?
146
+ def physical?
147
+ Chef::Sugar::Virtualization.physical?(node)
148
+ end
149
+ end
150
+ end
151
+ end
@@ -0,0 +1 @@
1
+ require "chef/sugar"
data/metadata.rb ADDED
@@ -0,0 +1,24 @@
1
+ name 'chef-sugar'
2
+ maintainer 'Seth Vargo'
3
+ maintainer_email 'sethvargo@gmail.com'
4
+ license 'Apache-2.0'
5
+ description 'Installs chef-sugar. Please see the chef-sugar ' \
6
+ 'Ruby gem for more information.'
7
+ long_description <<-EOH
8
+ Chef Sugar is a Gem & Chef Recipe that includes series of helpful syntactic
9
+ sugars on top of the Chef core and other resources to make a cleaner, more lean
10
+ recipe DSL, enforce DRY principles, and make writing Chef recipes an awesome and
11
+ fun experience!
12
+
13
+ For the most up-to-date information and documentation, please visit the [Chef
14
+ Sugar project page on GitHub](https://github.com/sethvargo/chef-sugar).
15
+ EOH
16
+
17
+ require File.expand_path('../lib/chef/sugar/version', __FILE__)
18
+ version Chef::Sugar::VERSION
19
+
20
+ supports 'any'
21
+ issues_url 'https://github.com/sethvargo/chef-sugar/issues'
22
+ source_url 'https://github.com/sethvargo/chef-sugar'
23
+ chef_version '>= 12.10.48' if respond_to?(:chef_version)
24
+ gem 'chef-sugar-ng'
@@ -0,0 +1,20 @@
1
+ #
2
+ # Cookbook Name:: chef-sugar
3
+ # Recipe:: default
4
+ #
5
+ # Copyright 2013-2015, Seth Vargo <sethvargo@gmail.com>
6
+ #
7
+ # Licensed under the Apache License, Version 2.0 (the "License");
8
+ # you may not use this file except in compliance with the License.
9
+ # You may obtain a copy of the License at
10
+ #
11
+ # http://www.apache.org/licenses/LICENSE-2.0
12
+ #
13
+ # Unless required by applicable law or agreed to in writing, software
14
+ # distributed under the License is distributed on an "AS IS" BASIS,
15
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ # See the License for the specific language governing permissions and
17
+ # limitations under the License.
18
+ #
19
+
20
+ Chef::Log.warn('chef-sugar::default no longer needs to be included in your runlist. Instead simply depend on the chef-sugar cookbook and the gem will be intalled and loaded automatically.')
@@ -0,0 +1,25 @@
1
+ require 'rspec'
2
+ require 'chefspec'
3
+ require 'chef/sugar'
4
+
5
+ require_relative 'support/shared_examples'
6
+
7
+ RSpec.configure do |config|
8
+ # Prohibit using the should syntax
9
+ config.expect_with :rspec do |spec|
10
+ spec.syntax = :expect
11
+ end
12
+
13
+ # Focus groups
14
+ config.filter_run(focus: true)
15
+ config.run_all_when_everything_filtered = true
16
+
17
+ # Run specs in random order to surface order dependencies. If you find an
18
+ # order dependency and want to debug it, you can fix the order by providing
19
+ # the seed, which is printed after each run.
20
+ # --seed 1234
21
+ config.order = 'random'
22
+
23
+ # ChefSpec configuration
24
+ config.log_level = :fatal
25
+ end
@@ -0,0 +1,20 @@
1
+ module RSpec
2
+ shared_examples 'a chef sugar' do
3
+ it 'acts as a singleton' do
4
+ described_class.module_eval("def foo; 'result'; end")
5
+ klass = Class.new.tap { |k| k.send(:include, described_class) }
6
+ expect(described_class.foo).to eq(klass.new.foo)
7
+ end
8
+
9
+ described_class.instance_methods.each do |name|
10
+ it "defines a `#{name}` DSL method" do
11
+ expect(Chef::Sugar::DSL).to be_method_defined(name)
12
+ end
13
+
14
+ it 'has n-1 arity from the parent method' do
15
+ method = Chef::Sugar::DSL.instance_method(name)
16
+ expect(method.arity).to eq(described_class.method(name).arity - 1)
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,129 @@
1
+ require 'spec_helper'
2
+
3
+ describe Chef::Sugar::Architecture do
4
+ it_behaves_like 'a chef sugar'
5
+
6
+ _64_bit_machines = %w(amd64 x86_64 ppc64 ppc64le s390x ia64 sparc64 aarch64 arch64 arm64 sun4u sun4v)
7
+ _intel_machines = %w(i86pc i386 x86_64 amd64 i686)
8
+
9
+ describe '#_64_bit?' do
10
+ _64_bit_machines.each do |arch|
11
+ it "returns true when the system is #{arch}" do
12
+ node = { 'kernel' => { 'machine' => arch } }
13
+ expect(described_class._64_bit?(node)).to be true
14
+ end
15
+ end
16
+
17
+ it 'returns true when ohai provides the bittiness' do
18
+ node = { 'kernel' => { 'bits' => '64' } }
19
+ expect(described_class._64_bit?(node)).to be true
20
+ end
21
+
22
+ it 'returns false when ohai provides the bittiness' do
23
+ node = { 'kernel' => { 'bits' => '32' } }
24
+ expect(described_class._64_bit?(node)).to be false
25
+ end
26
+
27
+ it 'returns false when the system is not 64 bit' do
28
+ node = { 'kernel' => { 'machine' => 'i386' } }
29
+ expect(described_class._64_bit?(node)).to be false
30
+ end
31
+ end
32
+
33
+ describe '#_32_bit?' do
34
+ it 'returns true when the system is 32 bit' do
35
+ node = { 'kernel' => { 'machine' => 'i386' } }
36
+ expect(described_class._32_bit?(node)).to be true
37
+ end
38
+
39
+ _64_bit_machines.each do |arch|
40
+ it "returns false when the system is #{arch}" do
41
+ node = { 'kernel' => { 'machine' => arch } }
42
+ expect(described_class._32_bit?(node)).to be false
43
+ end
44
+ end
45
+ end
46
+
47
+ describe '#i386?' do
48
+ it 'returns true when the system is 32 bit' do
49
+ node = { 'kernel' => { 'machine' => 'i386' } }
50
+ expect(described_class.i386?(node)).to be true
51
+ end
52
+
53
+ _64_bit_machines.each do |arch|
54
+ it "returns false when the system is #{arch}" do
55
+ node = { 'kernel' => { 'machine' => arch } }
56
+ expect(described_class.i386?(node)).to be false
57
+ end
58
+ end
59
+ end
60
+
61
+ describe '#intel?' do
62
+ _intel_machines.each do |arch|
63
+ it "returns true when the system is #{arch}" do
64
+ node = { 'kernel' => { 'machine' => arch } }
65
+ expect(described_class.intel?(node)).to be true
66
+ end
67
+
68
+ it 'returns false when the system is non Intel' do
69
+ node = { 'kernel' => { 'machine' => 'sun4u' } }
70
+ expect(described_class.intel?(node)).to be false
71
+ end
72
+ end
73
+ end
74
+
75
+ describe '#powerpc?' do
76
+ it 'returns true when the system is IBM POWER or powerpc' do
77
+ node = { 'kernel' => { 'machine' => 'powerpc' } }
78
+ end
79
+ end
80
+
81
+ describe '#armhf?' do
82
+ it 'returns true when the system is ARM' do
83
+ node = { 'kernel' => { 'machine' => 'armv7l' } }
84
+ expect(described_class.intel?(node)).to be false
85
+ expect(described_class.armhf?(node)).to be true
86
+ end
87
+ end
88
+
89
+ describe '#aarch64?' do
90
+ it 'returns true when the system is AArch64' do
91
+ node = { 'kernel' => { 'machine' => 'aarch64' } }
92
+ expect(described_class.intel?(node)).to be false
93
+ expect(described_class.aarch64?(node)).to be true
94
+ end
95
+ end
96
+
97
+ describe '#sparc?' do
98
+ it 'returns true when the system is SPARC sun4u' do
99
+ node = { 'kernel' => { 'machine' => 'sun4u' } }
100
+ expect(described_class.sparc?(node)).to be true
101
+ end
102
+
103
+ it 'returns true when the system is SPARC sun4v' do
104
+ node = { 'kernel' => { 'machine' => 'sun4v' } }
105
+ expect(described_class.sparc?(node)).to be true
106
+ end
107
+ end
108
+
109
+ describe '#ppc64?' do
110
+ it 'returns true when the system is PowerPC64 Big Endian' do
111
+ node = { 'kernel' => { 'machine' => 'ppc64' } }
112
+ expect(described_class.ppc64?(node)).to be true
113
+ end
114
+ end
115
+
116
+ describe '#ppc64le?' do
117
+ it 'returns true when the system is PowerPC64 Little Endian' do
118
+ node = { 'kernel' => { 'machine' => 'ppc64le' } }
119
+ expect(described_class.ppc64le?(node)).to be true
120
+ end
121
+ end
122
+
123
+ describe '#s390x?' do
124
+ it 'returns true when the system is s390x' do
125
+ node = { 'kernel' => { 'machine' => 's390x' } }
126
+ expect(described_class.s390x?(node)).to be true
127
+ end
128
+ end
129
+ end
@@ -0,0 +1,149 @@
1
+ require 'spec_helper'
2
+
3
+ describe Chef::Sugar::Cloud do
4
+ it_behaves_like 'a chef sugar'
5
+
6
+ describe '#cloud?' do
7
+ it 'is true when the node is on cloud' do
8
+ node = { 'cloud' => nil }
9
+ expect(described_class.cloud?(node)).to be true
10
+ end
11
+
12
+ it 'is false when the node is not on cloud' do
13
+ node = {}
14
+ expect(described_class.cloud?(node)).to be false
15
+ end
16
+ end
17
+
18
+ describe '#ec2?' do
19
+ it 'is true when the node is on ec2' do
20
+ node = { 'ec2' => nil }
21
+ expect(described_class.ec2?(node)).to be true
22
+ end
23
+
24
+ it 'is false when the node is not on ec2' do
25
+ node = {}
26
+ expect(described_class.ec2?(node)).to be false
27
+ end
28
+ end
29
+
30
+ describe '#gce?' do
31
+ it 'is true when the node is on gce' do
32
+ node = { 'gce' => nil }
33
+ expect(described_class.gce?(node)).to be true
34
+ end
35
+
36
+ it 'is false when the node is not on gce' do
37
+ node = {}
38
+ expect(described_class.gce?(node)).to be false
39
+ end
40
+ end
41
+
42
+ describe '#rackspace?' do
43
+ it 'is true when the node is on rackspace' do
44
+ node = { 'rackspace' => nil }
45
+ expect(described_class.rackspace?(node)).to be true
46
+ end
47
+
48
+ it 'is false when the node is not on rackspace' do
49
+ node = {}
50
+ expect(described_class.rackspace?(node)).to be false
51
+ end
52
+ end
53
+
54
+ describe '#eucalyptus?' do
55
+ it 'is true when the node is on eucalyptus' do
56
+ node = { 'eucalyptus' => nil }
57
+ expect(described_class.eucalyptus?(node)).to be true
58
+ end
59
+
60
+ it 'is false when the node is not on eucalyptus' do
61
+ node = {}
62
+ expect(described_class.eucalyptus?(node)).to be false
63
+ end
64
+ end
65
+
66
+ describe '#euca?' do
67
+ it 'is true when the node is on eucalyptus' do
68
+ node = { 'eucalyptus' => nil }
69
+ expect(described_class.euca?(node)).to be true
70
+ end
71
+
72
+ it 'is false when the node is not on eucalyptus' do
73
+ node = {}
74
+ expect(described_class.euca?(node)).to be false
75
+ end
76
+ end
77
+
78
+ describe '#linode?' do
79
+ it 'is true when the node is on linode' do
80
+ node = { 'linode' => nil }
81
+ expect(described_class.linode?(node)).to be true
82
+ end
83
+
84
+ it 'is false when the node is not on linode' do
85
+ node = {}
86
+ expect(described_class.linode?(node)).to be false
87
+ end
88
+ end
89
+
90
+ describe '#openstack?' do
91
+ it 'is true when the node is on openstack' do
92
+ node = { 'openstack' => nil }
93
+ expect(described_class.openstack?(node)).to be true
94
+ end
95
+
96
+ it 'is false when the node is not on openstack' do
97
+ node = {}
98
+ expect(described_class.openstack?(node)).to be false
99
+ end
100
+ end
101
+
102
+ describe '#cloudstack?' do
103
+ it 'is true when the node is on cloudstack' do
104
+ node = { 'cloudstack' => nil }
105
+ expect(described_class.cloudstack?(node)).to be true
106
+ end
107
+
108
+ it 'is false when the node is not on cloudstack' do
109
+ node = {}
110
+ expect(described_class.cloudstack?(node)).to be false
111
+ end
112
+ end
113
+
114
+ describe '#azure?' do
115
+ it 'is true when the node is on azure' do
116
+ node = { 'azure' => nil }
117
+ expect(described_class.azure?(node)).to be true
118
+ end
119
+
120
+ it 'is false when the node is not on azure' do
121
+ node = {}
122
+ expect(described_class.azure?(node)).to be false
123
+ end
124
+ end
125
+
126
+ describe '#digitalocean?' do
127
+ it 'is true when the node is on digitalocean' do
128
+ node = { 'digital_ocean' => nil }
129
+ expect(described_class.digitalocean?(node)).to be true
130
+ end
131
+
132
+ it 'is false when the node is not on digitalocean' do
133
+ node = {}
134
+ expect(described_class.digitalocean?(node)).to be false
135
+ end
136
+ end
137
+
138
+ describe '#softlayer?' do
139
+ it 'is true when the node is on softlayer' do
140
+ node = { 'softlayer' => nil }
141
+ expect(described_class.softlayer?(node)).to be true
142
+ end
143
+
144
+ it 'is false when the node is not on softlayer' do
145
+ node = {}
146
+ expect(described_class.softlayer?(node)).to be false
147
+ end
148
+ end
149
+ end