kitchen-chef-extended-attributes 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG.md +5 -0
- data/LICENSE.txt +22 -0
- data/README.md +54 -0
- data/lib/kitchen-chef-extended-attributes.rb +1 -0
- data/lib/kitchen/provisioner/chef_extended_attributes.rb +73 -0
- data/test/cookbooks/extended_attributes_test/files/default/test/default_test.rb +11 -0
- data/test/cookbooks/extended_attributes_test/files/default/test/kitchenmerged_test.rb +13 -0
- data/test/cookbooks/extended_attributes_test/files/default/test/kitchenoverride_test.rb +11 -0
- data/test/cookbooks/extended_attributes_test/metadata.rb +5 -0
- data/test/cookbooks/extended_attributes_test/recipes/default.rb +1 -0
- data/test/cookbooks/extended_attributes_test/recipes/kitchenmerged.rb +1 -0
- data/test/cookbooks/extended_attributes_test/recipes/kitchenoverride.rb +1 -0
- data/test/nodes/default.json +3 -0
- data/test/nodes/kitchenmerged.json +6 -0
- data/test/nodes/kitchenoverride.json +3 -0
- metadata +128 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 044844b384d0ef8f6ef26d3dede410b5c372cf61
|
4
|
+
data.tar.gz: 1edbfdb07ab360e3e8c1817481d16acd31453939
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 4c643d69486c6f0d428070b534cdf55a73e50e0ae200129504d82052d221edc09e47a978812b22885c5aac8ebddf107e07d867d53491d5be2bbb607ed8003642
|
7
|
+
data.tar.gz: 6c3bedb4628a8bfb1f810865c2406e060b48b027edea02c528f9cae3eee66fa63f037b252394e9cdd060dd7cfcee13a4c060b9b613c17e2de4d89c07311b30e9
|
data/CHANGELOG.md
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2015 Jeremy Olliver
|
2
|
+
|
3
|
+
MIT LICENSE
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
# kitchen-chef-extended-attributes
|
2
|
+
|
3
|
+
[![Circle CI](https://circleci.com/gh/jeremyolliver/kitchen-chef-extended-attributes.svg?style=shield)](https://circleci.com/gh/jeremyolliver/kitchen-chef-extended-attributes)
|
4
|
+
[![Code Climate](https://codeclimate.com/github/jeremyolliver/kitchen-chef-extended-attributes/badges/gpa.svg)](https://codeclimate.com/github/jeremyolliver/kitchen-chef-extended-attributes)
|
5
|
+
|
6
|
+
## Use Case
|
7
|
+
|
8
|
+
If you use chef-solo for your main workflow, then you will have dna.json files defining the attributes and run_list etc for each of your roles. This test-kitchen extension allows you to use test-kitchen as your main entry point for a chef repo level test-kitchen setup - loading the pre-existing dna.json for your nodes so that your .kitchen.yml doesn't drift from the actual setup. Additionally adding extra run list items or attributes within the .kitchen.yml file will override the json file for example adding test handler cookbooks or vagrant user sudo permissions.
|
9
|
+
|
10
|
+
## Example
|
11
|
+
|
12
|
+
Given a chef repository layout similar to
|
13
|
+
|
14
|
+
chef_repo
|
15
|
+
|-- .kitchen.yml
|
16
|
+
|-- Berksfile
|
17
|
+
|-- Berksfile.lock
|
18
|
+
|-- roles
|
19
|
+
| |-- app.rb
|
20
|
+
| `-- db.rb
|
21
|
+
`-- nodes
|
22
|
+
|-- app.json
|
23
|
+
`-- db.json
|
24
|
+
|
25
|
+
Use the provisioner `chef_extended_attributes` in your .kitchen.yml and ensure `nodes_path` is set appropriately
|
26
|
+
|
27
|
+
# .kitchen.yml
|
28
|
+
---
|
29
|
+
driver:
|
30
|
+
name: vagrant
|
31
|
+
|
32
|
+
provisioner:
|
33
|
+
name: chef_extended_attributes
|
34
|
+
merge_attributes: true # the default
|
35
|
+
role_path: 'roles'
|
36
|
+
nodes_path: 'nodes'
|
37
|
+
|
38
|
+
platforms:
|
39
|
+
- name: ubuntu-14.04
|
40
|
+
attributes:
|
41
|
+
authorization:
|
42
|
+
sudo:
|
43
|
+
users: ['vagrant']
|
44
|
+
|
45
|
+
# Suites will have node data loaded from nodes_path (nodes/<SUITENAME>.json)
|
46
|
+
suites:
|
47
|
+
- name: app
|
48
|
+
run_list:
|
49
|
+
- "recipe[minitest-handler]" # this is merged with the run_list definition in nodes
|
50
|
+
attributes:
|
51
|
+
mysql:
|
52
|
+
password: test-password
|
53
|
+
|
54
|
+
This will result in `kitchen converge app-ubuntu-1404` running in chef-solo mode with a dna.json generated that uses the json file with the same name as the suite (e.g. nodes/app.json) your defined nodes/*.json files (where the suite name - e.g. `app`, and merges the overriden attributes given in the test kitchen definition.
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'kitchen/provisioner/chef_extended_attributes'
|
@@ -0,0 +1,73 @@
|
|
1
|
+
require 'kitchen/provisioner/chef_solo'
|
2
|
+
require 'json'
|
3
|
+
|
4
|
+
module Kitchen
|
5
|
+
module Provisioner
|
6
|
+
|
7
|
+
# Define a new test-kitchen provisioner, based on the chef-solo provisioner
|
8
|
+
# with an additional load step to insert our pre-defined / generated
|
9
|
+
# dna.json file before the chef run begins
|
10
|
+
class ChefExtendedAttributes < Kitchen::Provisioner::ChefSolo
|
11
|
+
|
12
|
+
default_config :merge_attributes, true
|
13
|
+
|
14
|
+
# At the time of this hook being run, `sandbox_path` has been created,
|
15
|
+
# populated, but not yet copied across to the destination environment
|
16
|
+
def create_sandbox
|
17
|
+
super
|
18
|
+
debug('hooking create_sandbox')
|
19
|
+
backup_original_dna_json
|
20
|
+
if config[:merge_attributes]
|
21
|
+
prepare_merged_json
|
22
|
+
else
|
23
|
+
prepare_overridden_json
|
24
|
+
end
|
25
|
+
debug('finished hooks')
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
def prepare_merged_json
|
31
|
+
info("merging #{instance.suite.name}.json and kitchen attributes")
|
32
|
+
|
33
|
+
custom_json = JSON.parse(File.read(source_file))
|
34
|
+
merged_json = custom_json.merge(config[:attributes])
|
35
|
+
merged_json['run_list'] ||= []
|
36
|
+
merged_json['run_list'] += (config[:run_list] || [])
|
37
|
+
|
38
|
+
File.open(destination_file, "wb") do |file|
|
39
|
+
file.write(merged_json.to_json)
|
40
|
+
end
|
41
|
+
debug('merged dna.json written')
|
42
|
+
end
|
43
|
+
|
44
|
+
def prepare_overridden_json
|
45
|
+
info("copying #{instance.suite.name}.json to dna.json")
|
46
|
+
|
47
|
+
`cp -f #{source_file} #{destination_file}`
|
48
|
+
end
|
49
|
+
|
50
|
+
def backup_original_dna_json
|
51
|
+
`cp #{sandbox_path}/dna.json #{sandbox_path}/original-dna.json`
|
52
|
+
end
|
53
|
+
|
54
|
+
def source_file
|
55
|
+
"#{config[:nodes_path]}/#{instance.suite.name}.json"
|
56
|
+
end
|
57
|
+
|
58
|
+
def destination_file
|
59
|
+
File.join(sandbox_path, 'dna.json')
|
60
|
+
end
|
61
|
+
|
62
|
+
def info(msg)
|
63
|
+
super("chef_solo_with_attributes: #{msg}")
|
64
|
+
end
|
65
|
+
|
66
|
+
def debug(msg)
|
67
|
+
super("chef_solo_with_attributes: #{msg}")
|
68
|
+
end
|
69
|
+
|
70
|
+
end
|
71
|
+
|
72
|
+
end
|
73
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'minitest/spec'
|
2
|
+
|
3
|
+
describe_recipe 'extended_attributes_test::default' do
|
4
|
+
it 'should include attributes from the dna' do
|
5
|
+
file('/tmp/kitchen/dna.json').must_match 'valuefromdna'
|
6
|
+
end
|
7
|
+
|
8
|
+
it 'should include attributes from kitchen.yml' do
|
9
|
+
file('/tmp/kitchen/dna.json').must_match 'valuefromkitchen'
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'minitest/spec'
|
2
|
+
|
3
|
+
describe_recipe 'extended_attributes_test::kitchenmerged' do
|
4
|
+
it 'should give higher precendence to attributes in kitchen.yml' do
|
5
|
+
merged_json_data = JSON.parse(File.read('/tmp/kitchen/dna.json'))
|
6
|
+
merged_json_data['valuefromdna'].must_equal 'overridden'
|
7
|
+
end
|
8
|
+
|
9
|
+
it 'should include run_list items from dna JSON file' do
|
10
|
+
node.run_list.must_include('recipe[git]')
|
11
|
+
package('git').must_be_installed
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'minitest/spec'
|
2
|
+
|
3
|
+
describe_recipe 'extended_attributes_test::kitchenoverride' do
|
4
|
+
it 'should not contain attributes from kitchen.yml' do
|
5
|
+
file('/tmp/kitchen/dna.json').must_not_match 'shouldnevershowup'
|
6
|
+
end
|
7
|
+
|
8
|
+
it 'should include attributes from dna JSON file' do
|
9
|
+
file('/tmp/kitchen/dna.json').must_match 'valuefromdna'
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
include_recipe 'minitest-handler'
|
@@ -0,0 +1 @@
|
|
1
|
+
include_recipe 'minitest-handler'
|
@@ -0,0 +1 @@
|
|
1
|
+
include_recipe 'minitest-handler'
|
metadata
ADDED
@@ -0,0 +1,128 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: kitchen-chef-extended-attributes
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jeremy Olliver
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-02-09 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: test-kitchen
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: kitchen-docker
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: berkshelf
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: cane
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description: |-
|
70
|
+
Plugin for test-kitchen that extends the chef_solo provisioner with
|
71
|
+
chef_extended_attributes to use pre-existing dna.json files, and
|
72
|
+
optionally, to merge those with attributes in .kitchen.yml
|
73
|
+
email:
|
74
|
+
- jeremy.olliver@gmail.com
|
75
|
+
executables: []
|
76
|
+
extensions: []
|
77
|
+
extra_rdoc_files: []
|
78
|
+
files:
|
79
|
+
- lib/kitchen/provisioner/chef_extended_attributes.rb
|
80
|
+
- lib/kitchen-chef-extended-attributes.rb
|
81
|
+
- LICENSE.txt
|
82
|
+
- README.md
|
83
|
+
- CHANGELOG.md
|
84
|
+
- test/cookbooks/extended_attributes_test/files/default/test/default_test.rb
|
85
|
+
- test/cookbooks/extended_attributes_test/files/default/test/kitchenmerged_test.rb
|
86
|
+
- test/cookbooks/extended_attributes_test/files/default/test/kitchenoverride_test.rb
|
87
|
+
- test/cookbooks/extended_attributes_test/metadata.rb
|
88
|
+
- test/cookbooks/extended_attributes_test/recipes/default.rb
|
89
|
+
- test/cookbooks/extended_attributes_test/recipes/kitchenmerged.rb
|
90
|
+
- test/cookbooks/extended_attributes_test/recipes/kitchenoverride.rb
|
91
|
+
- test/nodes/default.json
|
92
|
+
- test/nodes/kitchenmerged.json
|
93
|
+
- test/nodes/kitchenoverride.json
|
94
|
+
homepage: https://github.com/jeremyolliver/kitchen-chef-extended-attributes
|
95
|
+
licenses:
|
96
|
+
- MIT
|
97
|
+
metadata: {}
|
98
|
+
post_install_message:
|
99
|
+
rdoc_options: []
|
100
|
+
require_paths:
|
101
|
+
- lib
|
102
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
103
|
+
requirements:
|
104
|
+
- - '>='
|
105
|
+
- !ruby/object:Gem::Version
|
106
|
+
version: '0'
|
107
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
108
|
+
requirements:
|
109
|
+
- - '>='
|
110
|
+
- !ruby/object:Gem::Version
|
111
|
+
version: '0'
|
112
|
+
requirements: []
|
113
|
+
rubyforge_project:
|
114
|
+
rubygems_version: 2.0.14
|
115
|
+
signing_key:
|
116
|
+
specification_version: 4
|
117
|
+
summary: test-kitchen chef-solo integrated with dna.json files from your repo
|
118
|
+
test_files:
|
119
|
+
- test/cookbooks/extended_attributes_test/files/default/test/default_test.rb
|
120
|
+
- test/cookbooks/extended_attributes_test/files/default/test/kitchenmerged_test.rb
|
121
|
+
- test/cookbooks/extended_attributes_test/files/default/test/kitchenoverride_test.rb
|
122
|
+
- test/cookbooks/extended_attributes_test/metadata.rb
|
123
|
+
- test/cookbooks/extended_attributes_test/recipes/default.rb
|
124
|
+
- test/cookbooks/extended_attributes_test/recipes/kitchenmerged.rb
|
125
|
+
- test/cookbooks/extended_attributes_test/recipes/kitchenoverride.rb
|
126
|
+
- test/nodes/default.json
|
127
|
+
- test/nodes/kitchenmerged.json
|
128
|
+
- test/nodes/kitchenoverride.json
|