chef-gen-flavors 0.6.2 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/ARUBA_STEPS.md +74 -0
- data/History.md +16 -0
- data/Manifest.txt +25 -30
- data/README.md +121 -16
- data/chef-gen-flavors.gemspec +8 -5
- data/lib/chef_gen/flavor_base.rb +42 -34
- data/lib/chef_gen/flavors.rb +36 -10
- data/lib/chef_gen/snippet/attributes.rb +13 -0
- data/lib/chef_gen/snippet/chef_spec.rb +84 -14
- data/lib/chef_gen/snippet/cookbook_base.rb +109 -23
- data/lib/chef_gen/snippet/example_file.rb +15 -0
- data/lib/chef_gen/snippet/example_template.rb +15 -0
- data/lib/chef_gen/snippet/git_init.rb +2 -0
- data/lib/chef_gen/snippet/recipes.rb +15 -0
- data/lib/chef_gen/snippet/resource_provider.rb +18 -0
- data/lib/chef_gen/snippet/standard_ignore.rb +56 -80
- data/lib/chef_gen/snippet/style_foodcritic.rb +51 -0
- data/lib/chef_gen/snippet/style_rubocop.rb +80 -0
- data/lib/chef_gen/snippet/style_tailor.rb +48 -0
- data/lib/chef_gen/snippet/test_kitchen.rb +70 -15
- data/lib/chef_gen/snippets.rb +2 -0
- data/shared/snippet/attributes/attributes_default_rb.erb +8 -0
- data/{.rspec → shared/snippet/chef_spec/_rspec.erb} +0 -0
- data/shared/snippet/chef_spec/spec_chef_runner_context_rb.erb +36 -0
- data/shared/snippet/chef_spec/spec_recipes_default_spec_rb.erb +7 -0
- data/shared/snippet/chef_spec/spec_spec_helper_rb.erb +95 -0
- data/shared/snippet/cookbookbase/Berksfile.erb +5 -0
- data/shared/snippet/cookbookbase/CHANGELOG_md.erb +5 -0
- data/shared/snippet/cookbookbase/Gemfile.erb +7 -0
- data/shared/snippet/cookbookbase/Guardfile.erb +10 -0
- data/shared/snippet/cookbookbase/README_md.erb +92 -0
- data/shared/snippet/cookbookbase/Rakefile.erb +20 -0
- data/shared/snippet/cookbookbase/metadata_rb.erb +10 -0
- data/shared/snippet/examplefile/files_default_example_conf +34 -0
- data/shared/snippet/exampletemplate/templates_default_example_conf_erb +22 -0
- data/shared/snippet/recipes/recipes_default_rb.erb +9 -0
- data/shared/snippet/resourceprovider/providers_default_rb.erb +20 -0
- data/shared/snippet/resourceprovider/resources_default_rb.erb +9 -0
- data/shared/snippet/stylerubocop/_rubocop_yml.erb +27 -0
- data/shared/snippet/testkitchen/_kitchen_yml.erb +30 -0
- data/shared/snippet/testkitchen/libraries_kitchen_helper_rb +13 -0
- data/shared/snippet/testkitchen/test_integration_default_serverspec_recipes_default_spec_rb.erb +16 -0
- data/shared/snippet/testkitchen/test_integration_default_serverspec_spec_helper_rb.erb +7 -0
- metadata +42 -32
- data/.rubocop.yml +0 -27
- data/.travis.yml +0 -6
- data/Gemfile +0 -3
- data/Guardfile +0 -15
- data/Rakefile +0 -98
- data/features/generate.feature +0 -17
- data/features/support/env.rb +0 -15
- data/spec/lib/chef_gen/flavor_base_spec.rb +0 -167
- data/spec/lib/chef_gen/flavors_spec.rb +0 -132
- data/spec/lib/chef_gen/snippet/attributes_spec.rb +0 -40
- data/spec/lib/chef_gen/snippet/chef_spec_spec.rb +0 -40
- data/spec/lib/chef_gen/snippet/cookbook_base_spec.rb +0 -32
- data/spec/lib/chef_gen/snippet/example_file_spec.rb +0 -40
- data/spec/lib/chef_gen/snippet/example_template_spec.rb +0 -40
- data/spec/lib/chef_gen/snippet/git_init_spec.rb +0 -30
- data/spec/lib/chef_gen/snippet/recipes_spec.rb +0 -40
- data/spec/lib/chef_gen/snippet/resource_provider_spec.rb +0 -40
- data/spec/lib/chef_gen/snippet/standard_ignore_spec.rb +0 -35
- data/spec/lib/chef_gen/snippet/style_rubocop_spec.rb +0 -31
- data/spec/lib/chef_gen/snippet/test_kitchen_spec.rb +0 -44
- data/spec/spec_helper.rb +0 -64
- data/spec/support/fixtures/code_generator/metadata.rb +0 -2
- data/spec/support/fixtures/code_generator/recipes/cookbook.rb +0 -1
- data/spec/support/fixtures/code_generator_2/metadata.rb +0 -2
- data/spec/support/fixtures/code_generator_2/recipes/cookbook.rb +0 -3
- data/spec/support/fixtures/code_generator_2/templates/default/README_md.erb +0 -1
- data/spec/support/fixtures/lib/chef_gen/flavor/bar.rb +0 -21
- data/spec/support/fixtures/lib/chef_gen/flavor/baz.rb +0 -6
- data/spec/support/fixtures/lib/chef_gen/flavor/foo.rb +0 -9
data/lib/chef_gen/snippets.rb
CHANGED
@@ -10,6 +10,8 @@ module ChefGen
|
|
10
10
|
autoload :ResourceProvider, 'chef_gen/snippet/resource_provider'
|
11
11
|
autoload :StandardIgnore, 'chef_gen/snippet/standard_ignore'
|
12
12
|
autoload :StyleRubocop, 'chef_gen/snippet/style_rubocop'
|
13
|
+
autoload :StyleTailor, 'chef_gen/snippet/style_tailor'
|
14
|
+
autoload :StyleFoodcritic, 'chef_gen/snippet/style_foodcritic'
|
13
15
|
autoload :TestKitchen, 'chef_gen/snippet/test_kitchen'
|
14
16
|
autoload :GitInit, 'chef_gen/snippet/git_init'
|
15
17
|
end
|
File without changes
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'rspec/core/shared_context'
|
2
|
+
|
3
|
+
# this is a 'standard' chef run, with no overrides
|
4
|
+
module ChefRun
|
5
|
+
extend RSpec::Core::SharedContext
|
6
|
+
|
7
|
+
let(:chef_run) do
|
8
|
+
ChefSpec::ServerRunner.new.converge(described_recipe)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
# the following are commented out to save memory
|
13
|
+
# they show how you can set up alternate Chef Runners that
|
14
|
+
# override the node's chef environment or other attributes
|
15
|
+
# module ChefRunTestEnv
|
16
|
+
# extend RSpec::Core::SharedContext
|
17
|
+
#
|
18
|
+
# let(:chef_run) do
|
19
|
+
# ChefSpec::ServerRunner.new do |node, server|
|
20
|
+
# server.create_environment('<%= cookbook_name %>-test')
|
21
|
+
# node.chef_environment = '<%= cookbook_name %>-test'
|
22
|
+
# server.create_node(node)
|
23
|
+
# end.converge(described_recipe)
|
24
|
+
# end
|
25
|
+
# end
|
26
|
+
#
|
27
|
+
# # a chef run where node attributes are overriden
|
28
|
+
# module ChefRunOverrideAttrs
|
29
|
+
# extend RSpec::Core::SharedContext
|
30
|
+
#
|
31
|
+
# let(:chef_run) do
|
32
|
+
# ChefSpec::ServerRunner.new do |node|
|
33
|
+
# node.set['<%= cookbook_name %>']['foobar'] = true
|
34
|
+
# end.converge(described_recipe)
|
35
|
+
# end
|
36
|
+
# end
|
@@ -0,0 +1,95 @@
|
|
1
|
+
require 'chefspec'
|
2
|
+
require 'chefspec/berkshelf'
|
3
|
+
require 'chef_runner_context'
|
4
|
+
|
5
|
+
# This file was generated by the `rspec --init` command. Conventionally, all
|
6
|
+
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
7
|
+
# The generated `.rspec` file contains `--require spec_helper` which will
|
8
|
+
# cause this file to always be loaded, without a need to explicitly require
|
9
|
+
# it in any files.
|
10
|
+
#
|
11
|
+
# Given that it is always loaded, you are encouraged to keep this file as
|
12
|
+
# light-weight as possible. Requiring heavyweight dependencies from this file
|
13
|
+
# will add to the boot time of your test suite on EVERY test run, even for
|
14
|
+
# an individual file that may not need all of that loaded. Instead, consider
|
15
|
+
# making a separate helper file that requires the additional dependencies
|
16
|
+
# and performs the additional setup, and require it from the spec files that
|
17
|
+
# actually need it.
|
18
|
+
#
|
19
|
+
# The `.rspec` file also contains a few flags that are not defaults but that
|
20
|
+
# users commonly want.
|
21
|
+
#
|
22
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
23
|
+
RSpec.configure do |config|
|
24
|
+
# rspec-expectations config goes here. You can use an alternate
|
25
|
+
# assertion/expectation library such as wrong or the stdlib/minitest
|
26
|
+
# assertions if you prefer.
|
27
|
+
config.expect_with :rspec do |expectations|
|
28
|
+
# This option will default to `true` in RSpec 4. It makes the `description`
|
29
|
+
# and `failure_message` of custom matchers include text for helper methods
|
30
|
+
# defined using `chain`, e.g.:
|
31
|
+
# be_bigger_than(2).and_smaller_than(4).description
|
32
|
+
# # => "be bigger than 2 and smaller than 4"
|
33
|
+
# ...rather than:
|
34
|
+
# # => "be bigger than 2"
|
35
|
+
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
|
36
|
+
end
|
37
|
+
|
38
|
+
# rspec-mocks config goes here. You can use an alternate test double
|
39
|
+
# library (such as bogus or mocha) by changing the `mock_with` option here.
|
40
|
+
config.mock_with :rspec do |mocks|
|
41
|
+
# Prevents you from mocking or stubbing a method that does not exist on
|
42
|
+
# a real object. This is generally recommended, and will default to
|
43
|
+
# `true` in RSpec 4.
|
44
|
+
mocks.verify_partial_doubles = true
|
45
|
+
end
|
46
|
+
|
47
|
+
# The settings below are suggested to provide a good initial experience
|
48
|
+
# with RSpec, but feel free to customize to your heart's content.
|
49
|
+
# These two settings work together to allow you to limit a spec run
|
50
|
+
# to individual examples or groups you care about by tagging them with
|
51
|
+
# `:focus` metadata. When nothing is tagged with `:focus`, all examples
|
52
|
+
# get run.
|
53
|
+
config.filter_run :focus
|
54
|
+
config.run_all_when_everything_filtered = true
|
55
|
+
|
56
|
+
# Limits the available syntax to the non-monkey patched syntax that is
|
57
|
+
# recommended. For more details, see:
|
58
|
+
# - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
|
59
|
+
# - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
|
60
|
+
# - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching
|
61
|
+
config.disable_monkey_patching!
|
62
|
+
|
63
|
+
# This setting enables warnings. It's recommended, but in some cases may
|
64
|
+
# be too noisy due to issues in dependencies.
|
65
|
+
config.warnings = false
|
66
|
+
|
67
|
+
# Many RSpec users commonly either run the entire suite or an individual
|
68
|
+
# file, and it's useful to allow more verbose output when running an
|
69
|
+
# individual spec file.
|
70
|
+
if config.files_to_run.one?
|
71
|
+
# Use the documentation formatter for detailed output,
|
72
|
+
# unless a formatter has already been configured
|
73
|
+
# (e.g. via a command-line flag).
|
74
|
+
config.default_formatter = 'doc'
|
75
|
+
end
|
76
|
+
|
77
|
+
# Print the 10 slowest examples and example groups at the
|
78
|
+
# end of the spec run, to help surface which specs are running
|
79
|
+
# particularly slow.
|
80
|
+
config.profile_examples = 10
|
81
|
+
|
82
|
+
# Run specs in random order to surface order dependencies. If you find an
|
83
|
+
# order dependency and want to debug it, you can fix the order by providing
|
84
|
+
# the seed, which is printed after each run.
|
85
|
+
# --seed 1234
|
86
|
+
config.order = :random
|
87
|
+
|
88
|
+
# Seed global randomization in this process using the `--seed` CLI option.
|
89
|
+
# Setting this allows you to use `--seed` to deterministically reproduce
|
90
|
+
# test failures related to randomization by passing the same `--seed` value
|
91
|
+
# as the one that triggered the failure.
|
92
|
+
Kernel.srand config.seed
|
93
|
+
end
|
94
|
+
|
95
|
+
ChefSpec::Coverage.start! if ENV['COVERAGE']
|
@@ -0,0 +1,92 @@
|
|
1
|
+
# <%= cookbook_name %>
|
2
|
+
|
3
|
+
## Description
|
4
|
+
|
5
|
+
...
|
6
|
+
|
7
|
+
## Usage
|
8
|
+
|
9
|
+
Add 'recipe[<%= cookbook_name %>::default]' to your node's run-list.
|
10
|
+
|
11
|
+
## Recipes
|
12
|
+
|
13
|
+
### default
|
14
|
+
|
15
|
+
The default recipe ...
|
16
|
+
|
17
|
+
## Attributes
|
18
|
+
|
19
|
+
The attributes defined by this recipe are organized under the
|
20
|
+
`node['<%= cookbook_name %>']` namespace.
|
21
|
+
|
22
|
+
Attribute | Description | Type | Default
|
23
|
+
----------|-------------|--------|--------
|
24
|
+
... | ... | String | ...
|
25
|
+
|
26
|
+
## Development
|
27
|
+
|
28
|
+
The first time you check out this cookbook, run
|
29
|
+
|
30
|
+
bundle --binstubs
|
31
|
+
|
32
|
+
to download and install the development tools.
|
33
|
+
|
34
|
+
## Testing
|
35
|
+
|
36
|
+
Three forms of cookbook testing are available:
|
37
|
+
|
38
|
+
### Style Checks
|
39
|
+
|
40
|
+
bin/rake style
|
41
|
+
|
42
|
+
Will run foodcritic (cookbook style) and tailor (ruby style/syntax)
|
43
|
+
checks. These tests must pass before the cookbook can progress
|
44
|
+
through the CI pipeline.
|
45
|
+
|
46
|
+
### Unit Tests
|
47
|
+
|
48
|
+
bin/rake spec
|
49
|
+
|
50
|
+
Will run ChefSpec tests. It is a good idea to ensure that these
|
51
|
+
tests pass before committing changes to git.
|
52
|
+
|
53
|
+
#### Unit Test Coverage
|
54
|
+
|
55
|
+
bin/rake coverage
|
56
|
+
|
57
|
+
Will run the ChefSpec tests and report on test coverage. It is a
|
58
|
+
good idea to make sure that every Chef resource you declare is covered
|
59
|
+
by a unit test.
|
60
|
+
|
61
|
+
#### Automated Testing with Guard
|
62
|
+
|
63
|
+
bin/guard
|
64
|
+
|
65
|
+
Will run foodcritic, tailor, rubocop (if enabled) and chefspec tests
|
66
|
+
automatically when the associated files change. If a chefspec test
|
67
|
+
fails, it will drop you into a pry session in the context of the
|
68
|
+
failure to explore the state of the run.
|
69
|
+
|
70
|
+
To disable the pry-rescue behavior, define the environment variable
|
71
|
+
DISABLE_PRY_RESCUE before running guard:
|
72
|
+
|
73
|
+
DISABLE_PRY_RESCUE=1 bin/guard
|
74
|
+
|
75
|
+
### Integration Tests
|
76
|
+
|
77
|
+
bin/rake kitchen:all
|
78
|
+
|
79
|
+
Will run the test kitchen integration tests. These tests use Vagrant
|
80
|
+
and Virtualbox, which must be installed for the tests to execute.
|
81
|
+
|
82
|
+
After converging in a virtual machine, ServerSpec tests are executed.
|
83
|
+
This skeleton comes with a very basic ServerSpec test; refer to
|
84
|
+
http://serverspec.org for detail on how to create tests.
|
85
|
+
|
86
|
+
## Author
|
87
|
+
|
88
|
+
<%= copyright_holder %>
|
89
|
+
|
90
|
+
## License
|
91
|
+
|
92
|
+
<%= license_description %>
|
@@ -0,0 +1,20 @@
|
|
1
|
+
desc 'runs style tests'
|
2
|
+
task style: []
|
3
|
+
|
4
|
+
desc 'runs unit tests'
|
5
|
+
task spec: []
|
6
|
+
|
7
|
+
desc 'runs integration tests'
|
8
|
+
task integration: []
|
9
|
+
|
10
|
+
desc 'runs style and unit tests'
|
11
|
+
task test: [:style, :spec]
|
12
|
+
|
13
|
+
desc 'runs all tests'
|
14
|
+
task default: :test
|
15
|
+
|
16
|
+
<% @tasks.each do |name, task| -%>
|
17
|
+
# <%= name %>
|
18
|
+
<%= task %>
|
19
|
+
|
20
|
+
<% end -%>
|
@@ -0,0 +1,10 @@
|
|
1
|
+
#
|
2
|
+
# Copyright (c) <%= year %> <%= copyright_holder %>
|
3
|
+
#
|
4
|
+
|
5
|
+
name '<%= cookbook_name %>'
|
6
|
+
maintainer '<%= copyright_holder %>'
|
7
|
+
maintainer_email '<%= email %>'
|
8
|
+
license '<%= license %>'
|
9
|
+
description 'Installs/Configures <%= cookbook_name %>'
|
10
|
+
version '0.1.0'
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# this is an example of a Chef cookbook file. It is
|
2
|
+
# copied intact when referenced by the cookbook_file
|
3
|
+
# resource.
|
4
|
+
|
5
|
+
[today_2014_09_17]
|
6
|
+
variable = value
|
7
|
+
|
8
|
+
[section_two]
|
9
|
+
variable_1=value_1
|
10
|
+
variable_2=value_2
|
11
|
+
variable_3=value_3
|
12
|
+
variable_4=value_4
|
13
|
+
variable_5=value_5
|
14
|
+
|
15
|
+
[section_three]
|
16
|
+
variable_1=value_1
|
17
|
+
variable_2=value_2
|
18
|
+
variable_3=value_3
|
19
|
+
variable_4=value_4
|
20
|
+
variable_5=value_5
|
21
|
+
|
22
|
+
[section_four]
|
23
|
+
variable_1=value_1
|
24
|
+
variable_2=value_2
|
25
|
+
variable_3=value_3
|
26
|
+
variable_4=value_4
|
27
|
+
variable_5=value_5
|
28
|
+
|
29
|
+
[section_five]
|
30
|
+
variable_1=value_1
|
31
|
+
variable_2=value_2
|
32
|
+
variable_3=value_3
|
33
|
+
variable_4=value_4
|
34
|
+
variable_5=value_5
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# this is an example of a Chef template. It is a simple
|
2
|
+
# INI-style file. The first section name is dynamically
|
3
|
+
# generated to be the current date in YYYY_MM_DD format
|
4
|
+
# and the second through fifth sections are generated in
|
5
|
+
# an 'each' loop.
|
6
|
+
#
|
7
|
+
# note that ending an ERB tag with -% instead of just %,
|
8
|
+
# that line doesn't produce an empty line in the output.
|
9
|
+
# Use this syntax on lines that are pure logic (like the
|
10
|
+
# require line and start and end of the loop) and contain
|
11
|
+
# no actual output
|
12
|
+
|
13
|
+
<% require 'date' -%>
|
14
|
+
[today_<%= DateTime.now.strftime('%Y_%M_%D') %>]
|
15
|
+
variable = value
|
16
|
+
|
17
|
+
<% %w(two three four five).each do |section_name| -%>
|
18
|
+
[<%= section_name %>]
|
19
|
+
<% 5.times do |i| -%>
|
20
|
+
variable_<%= i %>=value_<%= i %>
|
21
|
+
<% end -%>
|
22
|
+
<% end -%>
|
@@ -0,0 +1,9 @@
|
|
1
|
+
#
|
2
|
+
# Recipe: <%= cookbook_name %>::default
|
3
|
+
# Copyright (c) <%= year %> <%= copyright_holder %>
|
4
|
+
#
|
5
|
+
|
6
|
+
# a common pattern is to seperate the cookbook into distinct
|
7
|
+
# recipes and pull them all in via the default recipe
|
8
|
+
# include_recipe '<%= cookbook_name %>::recipe_a'
|
9
|
+
# include_recipe '<%= cookbook_name %>::recipe_b'
|
@@ -0,0 +1,20 @@
|
|
1
|
+
#
|
2
|
+
# Resource: <%= cookbook_name %>
|
3
|
+
# Copyright (c) <%= year %> <%= copyright_holder %>
|
4
|
+
#
|
5
|
+
|
6
|
+
use_inline_resources
|
7
|
+
|
8
|
+
def whyrun_supported?
|
9
|
+
true
|
10
|
+
end
|
11
|
+
|
12
|
+
action :create do
|
13
|
+
converge_by 'create a <%= cookbook_name %>' do
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
action :delete do
|
18
|
+
converge_by 'delete a <%= cookbook_name %>' do
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
AllCops:
|
2
|
+
Exclude:
|
3
|
+
- 'vendor/**/*'
|
4
|
+
|
5
|
+
Style/SingleSpaceBeforeFirstArg:
|
6
|
+
Exclude:
|
7
|
+
- '**/Berksfile'
|
8
|
+
- '**/metadata.rb'
|
9
|
+
|
10
|
+
Style/FileName:
|
11
|
+
Exclude:
|
12
|
+
- '**/Gemfile'
|
13
|
+
- '**/Berksfile'
|
14
|
+
|
15
|
+
Style/RegexpLiteral:
|
16
|
+
Exclude:
|
17
|
+
- '**/Guardfile'
|
18
|
+
|
19
|
+
Style/EmptyLines:
|
20
|
+
Exclude:
|
21
|
+
- '**/Guardfile'
|
22
|
+
- '**/Rakefile'
|
23
|
+
|
24
|
+
Style/TrailingBlankLines:
|
25
|
+
Exclude:
|
26
|
+
- '**/Guardfile'
|
27
|
+
- '**/Rakefile'
|