chef-sugar 2.4.1 → 2.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +11 -0
- data/README.md +12 -2
- data/lib/chef/sugar/data_bag.rb +38 -0
- data/lib/chef/sugar/node.rb +5 -3
- data/lib/chef/sugar/version.rb +1 -1
- data/lib/chef/sugar/virtualization.rb +33 -1
- data/spec/unit/chef/sugar/data_bag_spec.rb +44 -0
- data/spec/unit/chef/sugar/node_spec.rb +1 -1
- data/spec/unit/chef/sugar/virtualization_spec.rb +34 -0
- data/spec/unit/recipes/default_spec.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cb7fd64f85beb2f7d54f0db0eeeddc14a7062c4c
|
4
|
+
data.tar.gz: 81314e1d07f9f66f6aaacec9791c136f18742e7d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c253b9e100abc3d1b37282b31bef7044dcbc89d198624ea921e1ad9110d5eae03158c0b1bd981c284db9182db58390254fc99ef0f6ac3c92bcff92f104d77f5c
|
7
|
+
data.tar.gz: e52323a36a787b6daf95e1ccef69e16c30f2bc92ca1e5ff2e8cbf82d981109cf31c6f18bafc895e8a8bbdc5c554deaae2088a9a80d6cbb707b83bfd411926c5e
|
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,17 @@ Chef Sugar Changelog
|
|
2
2
|
=========================
|
3
3
|
This file is used to list changes made in each version of the chef-sugar cookbook and gem.
|
4
4
|
|
5
|
+
v2.5.0 (2015-01-05)
|
6
|
+
-------------------
|
7
|
+
### Improvements
|
8
|
+
- Add `data_bag_item_for_environment` function
|
9
|
+
- Add `kvm?` matcher
|
10
|
+
- Add `virtualbox?` matcher
|
11
|
+
|
12
|
+
### Bug Fixes
|
13
|
+
- Use `.key?` to check for hash key presence, raising an `AttributeDoesNotExist`
|
14
|
+
error sooner
|
15
|
+
|
5
16
|
v2.4.1 (2014-10-12)
|
6
17
|
-------------------
|
7
18
|
- No changes from v2.4.0 - forced a new version upload to the Chef Supermarket
|
data/README.md
CHANGED
@@ -139,7 +139,8 @@ require 'chef/sugar/core_extensions'
|
|
139
139
|
|
140
140
|
### Data Bag
|
141
141
|
- `encrypted_data_bag_item` - a handy DSL method for loading encrypted data bag items the same way you load a regular data bag item; this requires `Chef::Config[:encrypted_data_bag_secret]` is set!
|
142
|
-
- `encrypted_data_bag_item_for_environment` - find the data bag entry for the current node's Chef environment.
|
142
|
+
- `encrypted_data_bag_item_for_environment` - find the encrypted data bag entry for the current node's Chef environment.
|
143
|
+
- `data_bag_item_for_environment` - find the data bag entry for the current node's Chef environment.
|
143
144
|
|
144
145
|
#### Examples
|
145
146
|
```ruby
|
@@ -150,6 +151,10 @@ encrypted_data_bag_item('accounts', 'hipchat')
|
|
150
151
|
encrypted_data_bag_item_for_environment('accounts', 'github')
|
151
152
|
```
|
152
153
|
|
154
|
+
```ruby
|
155
|
+
data_bag_item_for_environment('accounts', 'github')
|
156
|
+
```
|
157
|
+
|
153
158
|
### Docker
|
154
159
|
Chef Sugar looks for hints to see if the node being converged is a Docker container. When [Ohai supports checking other nodes](https://github.com/opscode/ohai/pull/428), Chef Sugar will automatically pick up the information.
|
155
160
|
|
@@ -258,13 +263,16 @@ end
|
|
258
263
|
```
|
259
264
|
|
260
265
|
### Node
|
266
|
+
|
267
|
+
Additional methods for the `node` object
|
268
|
+
|
261
269
|
- `deep_fetch` - safely fetch a nested attribute.
|
262
270
|
- `deep_fetch!` - fetch a nested attribute, raising a more semantic error if the key does not exist.
|
263
271
|
- `in?` - determine if the node is in the given Chef environment.
|
264
272
|
|
265
273
|
#### Examples
|
266
274
|
```ruby
|
267
|
-
credentials = if in?('production')
|
275
|
+
credentials = if node.in?('production')
|
268
276
|
Chef::EncryptedDataBag.new('...')
|
269
277
|
else
|
270
278
|
data_bag('...')
|
@@ -389,7 +397,9 @@ end
|
|
389
397
|
```
|
390
398
|
|
391
399
|
### Virtualization
|
400
|
+
- `kvm?`
|
392
401
|
- `lxc?`
|
402
|
+
- `virtualbox?`
|
393
403
|
- `vmware?`
|
394
404
|
|
395
405
|
#### Examples
|
data/lib/chef/sugar/data_bag.rb
CHANGED
@@ -91,6 +91,39 @@ EOH
|
|
91
91
|
data['default']
|
92
92
|
end
|
93
93
|
end
|
94
|
+
|
95
|
+
#
|
96
|
+
# This algorithm attempts to find the data bag entry for the current
|
97
|
+
# node's Chef environment. If there are no environment-specific
|
98
|
+
# values, the "default" bucket is used. The data bag must follow the
|
99
|
+
# schema:
|
100
|
+
#
|
101
|
+
# {
|
102
|
+
# "default": {...},
|
103
|
+
# "environment_name": {...},
|
104
|
+
# "other_environment": {...},
|
105
|
+
# }
|
106
|
+
#
|
107
|
+
# @param [Node] node
|
108
|
+
# the current Chef node
|
109
|
+
# @param [String] bag
|
110
|
+
# the name of the data bag
|
111
|
+
# @param [String] id
|
112
|
+
# the id of the data bag
|
113
|
+
#
|
114
|
+
# @return [Hash]
|
115
|
+
#
|
116
|
+
def data_bag_item_for_environment(node, bag, id)
|
117
|
+
data = Chef::DataBagItem.load(bag, id)
|
118
|
+
|
119
|
+
if data[node.chef_environment]
|
120
|
+
Chef::Log.debug "Using #{node.chef_environment} as the key"
|
121
|
+
data[node.chef_environment]
|
122
|
+
else
|
123
|
+
Chef::Log.debug "#{node.chef_environment} key does not exist, using `default`"
|
124
|
+
data['default']
|
125
|
+
end
|
126
|
+
end
|
94
127
|
end
|
95
128
|
|
96
129
|
module DSL
|
@@ -103,6 +136,11 @@ EOH
|
|
103
136
|
def encrypted_data_bag_item_for_environment(bag, id, secret = nil)
|
104
137
|
Chef::Sugar::DataBag.encrypted_data_bag_item_for_environment(node, bag, id, secret)
|
105
138
|
end
|
139
|
+
|
140
|
+
# @see Chef::Sugar::DataBag#data_bag_item_for_environment
|
141
|
+
def data_bag_item_for_environment(bag, id)
|
142
|
+
Chef::Sugar::DataBag.data_bag_item_for_environment(node, bag, id)
|
143
|
+
end
|
106
144
|
end
|
107
145
|
end
|
108
146
|
end
|
data/lib/chef/sugar/node.rb
CHANGED
@@ -73,10 +73,12 @@ EOH
|
|
73
73
|
keys.map!(&:to_s)
|
74
74
|
|
75
75
|
keys.inject(attributes.to_hash) do |hash, key|
|
76
|
-
hash
|
76
|
+
if hash.key?(key)
|
77
|
+
hash[key]
|
78
|
+
else
|
79
|
+
raise AttributeDoesNotExistError.new(keys)
|
80
|
+
end
|
77
81
|
end
|
78
|
-
rescue NoMethodError
|
79
|
-
raise AttributeDoesNotExistError.new(keys)
|
80
82
|
end
|
81
83
|
|
82
84
|
#
|
data/lib/chef/sugar/version.rb
CHANGED
@@ -19,6 +19,19 @@ class Chef
|
|
19
19
|
module Virtualization
|
20
20
|
extend self
|
21
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
|
+
|
22
35
|
#
|
23
36
|
# Determine if the current node is running in a linux container.
|
24
37
|
#
|
@@ -32,6 +45,19 @@ class Chef
|
|
32
45
|
node.key?('virtualization') && node['virtualization']['system'] == 'lxc'
|
33
46
|
end
|
34
47
|
|
48
|
+
#
|
49
|
+
# Determine if the current node is running under VirtualBox.
|
50
|
+
#
|
51
|
+
# @param [Chef::Node] node
|
52
|
+
#
|
53
|
+
# @return [Boolean]
|
54
|
+
# true if the machine is currently running under VirtualBox, false
|
55
|
+
# otherwise
|
56
|
+
#
|
57
|
+
def virtualbox?(node)
|
58
|
+
node.key?('virtualization') && node['virtualization']['system'] == 'vbox'
|
59
|
+
end
|
60
|
+
|
35
61
|
#
|
36
62
|
# Determine if the current node is running under VMware.
|
37
63
|
#
|
@@ -47,11 +73,17 @@ class Chef
|
|
47
73
|
end
|
48
74
|
|
49
75
|
module DSL
|
76
|
+
# @see Chef::Sugar::Virtualization#kvm?
|
77
|
+
def kvm?; Chef::Sugar::Virtualization.kvm?(node); end
|
78
|
+
|
50
79
|
# @see Chef::Sugar::Virtualization#lxc?
|
51
80
|
def lxc?; Chef::Sugar::Virtualization.lxc?(node); end
|
52
81
|
|
82
|
+
# @see Chef::Sugar::Virtualization#virtualbox?
|
83
|
+
def virtualbox?; Chef::Sugar::Virtualization.virtualbox?(node); end
|
84
|
+
|
53
85
|
# @see Chef::Sugar::Virtualization#vmware?
|
54
86
|
def vmware?; Chef::Sugar::Virtualization.vmware?(node); end
|
55
|
-
|
87
|
+
end
|
56
88
|
end
|
57
89
|
end
|
@@ -71,4 +71,48 @@ describe Chef::Sugar::DataBag do
|
|
71
71
|
end
|
72
72
|
end
|
73
73
|
end
|
74
|
+
|
75
|
+
describe '#data_bag_item_for_environment' do
|
76
|
+
let(:node) { double(:node, chef_environment: 'production') }
|
77
|
+
|
78
|
+
context 'when the environment exists' do
|
79
|
+
it 'loads the data from the environment' do
|
80
|
+
allow(Chef::DataBagItem).to receive(:load).and_return(
|
81
|
+
'production' => {
|
82
|
+
'username' => 'sethvargo',
|
83
|
+
'comment' => 'loves bacon',
|
84
|
+
},
|
85
|
+
'default' => {
|
86
|
+
'username' => 'schisamo',
|
87
|
+
'comment' => 'more of a ham guy',
|
88
|
+
}
|
89
|
+
)
|
90
|
+
|
91
|
+
expect(described_class.data_bag_item_for_environment(node, 'accounts', 'github')).to eq(
|
92
|
+
'comment' => 'loves bacon',
|
93
|
+
'username' => 'sethvargo',
|
94
|
+
)
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
context 'when the environment does not exist' do
|
99
|
+
it 'loads the data from the default bucket' do
|
100
|
+
allow(Chef::DataBagItem).to receive(:load).and_return(
|
101
|
+
'staging' => {
|
102
|
+
'username' => 'sethvargo',
|
103
|
+
'comment' => 'loves bacon',
|
104
|
+
},
|
105
|
+
'default' => {
|
106
|
+
'username' => 'schisamo',
|
107
|
+
'comment' => 'more of a ham guy',
|
108
|
+
}
|
109
|
+
)
|
110
|
+
|
111
|
+
expect(described_class.data_bag_item_for_environment(node, 'accounts', 'github')).to eq(
|
112
|
+
'comment' => 'more of a ham guy',
|
113
|
+
'username' => 'schisamo',
|
114
|
+
)
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
74
118
|
end
|
@@ -3,6 +3,23 @@ require 'spec_helper'
|
|
3
3
|
describe Chef::Sugar::Virtualization do
|
4
4
|
it_behaves_like 'a chef sugar'
|
5
5
|
|
6
|
+
describe '#kvm?' do
|
7
|
+
it 'returns true when the machine is under kvm' do
|
8
|
+
node = { 'virtualization' => { 'system' => 'kvm' } }
|
9
|
+
expect(described_class.kvm?(node)).to be true
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'returns false when the virtual machine is not under kvm' do
|
13
|
+
node = { 'virtualization' => { 'system' => 'vbox' } }
|
14
|
+
expect(described_class.kvm?(node)).to be false
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'returns false when the machine is not virtual' do
|
18
|
+
node = {}
|
19
|
+
expect(described_class.kvm?(node)).to be false
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
6
23
|
describe '#lxc?' do
|
7
24
|
it 'returns true when the machine is a linux contianer' do
|
8
25
|
node = { 'virtualization' => { 'system' => 'lxc' } }
|
@@ -20,6 +37,23 @@ describe Chef::Sugar::Virtualization do
|
|
20
37
|
end
|
21
38
|
end
|
22
39
|
|
40
|
+
describe '#virtualbox?' do
|
41
|
+
it 'returns true when the machine is under virtualbox' do
|
42
|
+
node = { 'virtualization' => { 'system' => 'vbox' } }
|
43
|
+
expect(described_class.virtualbox?(node)).to be true
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'returns false when the virtual machine is not under virtualbox' do
|
47
|
+
node = { 'virtualization' => { 'system' => 'kvm' } }
|
48
|
+
expect(described_class.virtualbox?(node)).to be false
|
49
|
+
end
|
50
|
+
|
51
|
+
it 'returns false when the machine is not virtual' do
|
52
|
+
node = {}
|
53
|
+
expect(described_class.virtualbox?(node)).to be false
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
23
57
|
describe '#vmware?' do
|
24
58
|
it 'returns true when the machine is under vmware' do
|
25
59
|
node = { 'virtualization' => { 'system' => 'vmware' } }
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe 'chef-sugar::default' do
|
4
|
-
let(:chef_run) { ChefSpec::
|
4
|
+
let(:chef_run) { ChefSpec::ServerRunner.new.converge(described_recipe) }
|
5
5
|
|
6
6
|
it 'installs the chef gem' do
|
7
7
|
expect(chef_run).to install_chef_gem('chef-sugar').with(version: Chef::Sugar::VERSION)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: chef-sugar
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Seth Vargo
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-01-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -166,7 +166,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
166
166
|
version: '0'
|
167
167
|
requirements: []
|
168
168
|
rubyforge_project:
|
169
|
-
rubygems_version: 2.
|
169
|
+
rubygems_version: 2.4.5
|
170
170
|
signing_key:
|
171
171
|
specification_version: 4
|
172
172
|
summary: A collection of helper methods and modules that make working with Chef recipes
|