puppet-retrospec 0.7.2 → 0.7.3
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 +4 -4
- data/README.md +61 -21
- data/VERSION +1 -1
- data/bin/retrospec +1 -1
- data/lib/retrospec.rb +2 -1
- data/lib/retrospec/spec_object.rb +30 -1
- data/lib/retrospec/templates/acceptance_spec_test.erb +12 -12
- data/lib/retrospec/templates/module_files/Gemfile +16 -18
- data/lib/retrospec/templates/module_files/README.markdown +75 -0
- data/lib/retrospec/templates/module_files/Rakefile +35 -7
- data/lib/retrospec/templates/module_files/Vagrantfile +95 -0
- data/lib/retrospec/templates/module_files/spec/acceptance/nodesets/default.yml +6 -6
- data/lib/retrospec/templates/module_files/spec/shared_contexts.rb +14 -6
- data/lib/retrospec/templates/module_files/spec/spec_helper.rb +1 -0
- data/lib/retrospec/version.rb +1 -1
- data/puppet-retrospec.gemspec +4 -2
- data/spec/unit/module_spec.rb +1 -1
- data/spec/unit/puppet-retrospec_spec.rb +19 -1
- data/spec/unit/resource_spec.rb +0 -2
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: eaace655a4e5f360e93ef3ee07ed003dfeecdf61
|
4
|
+
data.tar.gz: 20f0b75846a20d22b35db36bfee6b8768503ca30
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 46c667b57c0d670e2ccde78f388b4d3a881b423679a6e438905e2f7bbf1667b760a8a973652a73ed6803068e6a5ba7e73a73c6f7892077b9da0bfc7a7a65685f
|
7
|
+
data.tar.gz: 667274f680050e06ef26e63d6804a46cc09a2ce9c5bf4831337070f8a16c2250978fa8e9573c6da634e4b28310e4036a68824561289327ac642f5fb96417468b
|
data/README.md
CHANGED
@@ -369,13 +369,14 @@ To override these templates just set **one** of the following cli options.
|
|
369
369
|
|
370
370
|
```
|
371
371
|
|
372
|
-
Once one of the options is set, retrospec will copy over all the templates from the gem location to the default
|
373
|
-
or specified
|
372
|
+
Once one of the options is set, retrospec will copy over all the templates from the default gem location to the default
|
373
|
+
or specified templates path.
|
374
374
|
If you have already created the erb file in the templates location, then puppet-retrospec will not overwrite the file.
|
375
375
|
You can set multiple template paths if you use them for different projects so just be sure the set the correct
|
376
376
|
template option when running retrospec.
|
377
377
|
|
378
|
-
Setting the `--enable-user-templates` option will tell retrospec to use the default user template location
|
378
|
+
Setting the `--enable-user-templates` option will tell retrospec to use the default user template location and will
|
379
|
+
copy over all the default templates that came with the gem.
|
379
380
|
|
380
381
|
The default user location for the templates when using this variable is ~/.puppet_retrospec_templates
|
381
382
|
|
@@ -387,35 +388,74 @@ If you set the `--template-dir` option you are not required to set the set `--en
|
|
387
388
|
Example:
|
388
389
|
`--template-dir=~/my_templates`
|
389
390
|
|
391
|
+
As I said above some of us need different templates for different projects and so I have outlined a simple scenario below:
|
392
|
+
Lets say I have three clients that each need site specific files in the module and the default templates just
|
393
|
+
don't give me everything I want. Thus I will need to override the templates for each client.
|
394
|
+
|
395
|
+
```shell
|
396
|
+
retrospec --template-dir ~/retrspec_client1
|
397
|
+
retrospec --template-dir ~/retrspec_client2
|
398
|
+
retrospec --template-dir ~/retrspec_client3
|
399
|
+
touch ~/retrspec_client1/module_files/special_file_for_client1.yml
|
400
|
+
touch ~/retrspec_client2/module_files/special_file_for_client2.yml
|
401
|
+
touch ~/retrspec_client3/module_files/special_file_for_client3.yml
|
402
|
+
|
403
|
+
mkdir -p ~/{client1,client2, client3}
|
404
|
+
cd ~/client1 && puppet module generate lmc-module1
|
405
|
+
cd ~/client2 && puppet module generate lmc-module1
|
406
|
+
cd ~/client3 && puppet module generate lmc-module1
|
407
|
+
|
408
|
+
cd ~/client1/module1 && retrospec --template-dir ~/retrspec_client1
|
409
|
+
cd ~/client2/module1 && retrospec --template-dir ~/retrspec_client2
|
410
|
+
cd ~/client3/module1 && retrospec --template-dir ~/retrspec_client3
|
411
|
+
```
|
412
|
+
Now when you run retrospec just pass in the template path for the specified client and the files will be created as you
|
413
|
+
specified in each clients template directory.
|
414
|
+
|
390
415
|
Adding New Templates
|
391
416
|
======================
|
392
417
|
Should you ever need to add new templates or normal files of any kind retrospec will automatically render and copy the template file
|
393
|
-
to the module path if you place a file inside the
|
394
|
-
is that retrospec will recursively create the same directory structure you make inside the module_files directory inside your
|
418
|
+
to the module path if you place a file inside the `template_path/module_files` directory. The cool thing about this feature
|
419
|
+
is that retrospec will recursively create the same directory structure you make inside the `module_files` directory inside your
|
395
420
|
module. Files do not need to end in .erb will still be rendered as a erb template.
|
396
421
|
|
397
|
-
This
|
422
|
+
This follow the convention over configuration pattern so no directory name or filename is required when running retrospec.
|
398
423
|
Just put the template file in the directory where you want it (under module_files) and name it exactly how you want it to appear in the module and retrospec
|
399
424
|
will take care of the rest. Please note that any file ending in .erb will have this extension automatically removed.
|
400
425
|
|
401
426
|
Example:
|
427
|
+
So lets say you want to add a .gitlab-ci.yaml file to all of your modules in your modules directory.
|
402
428
|
|
403
429
|
```shell
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
│
|
411
|
-
│
|
412
|
-
│
|
413
|
-
│
|
414
|
-
│
|
415
|
-
│
|
416
|
-
│
|
417
|
-
│
|
418
|
-
└──
|
430
|
+
touch ~/.puppet_retrospec_templates/module_files/.gitlab-ci.yaml
|
431
|
+
|
432
|
+
tree ~/.puppet_retrospec_templates -a
|
433
|
+
./.puppet_retrospec_templates
|
434
|
+
├── acceptance_spec_test.erb
|
435
|
+
├── module_files
|
436
|
+
│ ├── .fixtures.yml
|
437
|
+
│ ├── .gitignore.erb
|
438
|
+
│ ├── .gitlab-ci.yaml
|
439
|
+
│ ├── .travis.yml
|
440
|
+
│ ├── Gemfile
|
441
|
+
│ ├── README.markdown
|
442
|
+
│ ├── Rakefile
|
443
|
+
│ ├── Vagrantfile
|
444
|
+
│ └── spec
|
445
|
+
│ ├── acceptance
|
446
|
+
│ │ └── nodesets
|
447
|
+
│ │ └── ubuntu-server-1404-x64.yml
|
448
|
+
│ ├── shared_contexts.rb
|
449
|
+
│ ├── spec_helper.rb
|
450
|
+
│ └── spec_helper_acceptance.rb
|
451
|
+
└── resource_spec_file.erb
|
452
|
+
|
453
|
+
for dir in ../modules/*; do
|
454
|
+
name=`basename $dir`
|
455
|
+
retrospec -m $dir -e
|
456
|
+
+ /Users/user1/modules/module1/.gitlab-ci.yaml
|
457
|
+
done
|
458
|
+
|
419
459
|
```
|
420
460
|
|
421
461
|
Beaker Testing
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.7.
|
1
|
+
0.7.3
|
data/bin/retrospec
CHANGED
data/lib/retrospec.rb
CHANGED
@@ -41,11 +41,12 @@ class Retrospec
|
|
41
41
|
end
|
42
42
|
|
43
43
|
def create_files
|
44
|
+
types = spec_object.types
|
44
45
|
safe_create_module_files
|
45
46
|
# a Type is nothing more than a defined type or puppet class
|
46
47
|
# we could have named this manifest but there could be multiple types
|
47
48
|
# in a manifest.
|
48
|
-
|
49
|
+
types.each do |type|
|
49
50
|
safe_create_resource_spec_files(type)
|
50
51
|
if spec_object.enable_beaker_tests?
|
51
52
|
safe_create_acceptance_tests(type)
|
@@ -1,17 +1,46 @@
|
|
1
1
|
|
2
2
|
module Utilities
|
3
3
|
class SpecObject
|
4
|
-
attr_reader :instance
|
4
|
+
attr_reader :instance, :all_hiera_data
|
5
5
|
attr_accessor :enable_beaker_tests, :parameters, :types, :resources, :type
|
6
6
|
|
7
7
|
def initialize(mod_instance)
|
8
8
|
@instance = mod_instance
|
9
|
+
all_hiera_data
|
9
10
|
end
|
10
11
|
|
11
12
|
def types
|
12
13
|
instance.types
|
13
14
|
end
|
14
15
|
|
16
|
+
def class_hiera_data(classname)
|
17
|
+
data = {}
|
18
|
+
types.each do |t|
|
19
|
+
next unless t.type == :hostclass #defines don't have hiera lookup values
|
20
|
+
next unless t.name == classname
|
21
|
+
t.arguments.each do |k, v|
|
22
|
+
key = "#{t.name}::#{k}"
|
23
|
+
data[key] = nil
|
24
|
+
end
|
25
|
+
end
|
26
|
+
data
|
27
|
+
end
|
28
|
+
|
29
|
+
# gathers all the class parameters that could be used in hiera data mocking
|
30
|
+
def all_hiera_data
|
31
|
+
if @all_hiera_data.nil?
|
32
|
+
@all_hiera_data = {}
|
33
|
+
types.each do |t|
|
34
|
+
next unless t.type == :hostclass #defines don't have hiera lookup values
|
35
|
+
t.arguments.each do |k, v|
|
36
|
+
key = "#{t.name}::#{k}"
|
37
|
+
@all_hiera_data[key] = nil
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
@all_hiera_data
|
42
|
+
end
|
43
|
+
|
15
44
|
def module_name
|
16
45
|
instance.module_name
|
17
46
|
end
|
@@ -4,21 +4,21 @@ describe '<%= @type.name -%> <%= @type.type %>' do
|
|
4
4
|
describe 'running puppet code' do
|
5
5
|
it 'should work with no errors' do
|
6
6
|
pp = <<-EOS
|
7
|
-
class { '<%= @type.name %>':
|
8
|
-
<%- @parameters.each do |k,v| -%>
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
<%- end -%>
|
15
|
-
}
|
7
|
+
class { '<%= @type.name %>':
|
8
|
+
<%- @parameters.each do |k,v| -%>
|
9
|
+
<%- if v.nil? -%>
|
10
|
+
<%= "#{k} => 'place_value_here'," %>
|
11
|
+
<%- else -%>
|
12
|
+
<%= "##{k} => #{variable_value(v)}," %>
|
13
|
+
<%- end -%>
|
14
|
+
<%- end -%>
|
15
|
+
}
|
16
16
|
EOS
|
17
17
|
|
18
|
-
|
18
|
+
# Run it twice and test for idempotency
|
19
19
|
apply_manifest(pp, :catch_failures => true)
|
20
|
-
|
20
|
+
apply_manifest(pp, :catch_changes => true)
|
21
21
|
end
|
22
22
|
|
23
23
|
end
|
24
|
-
end
|
24
|
+
end
|
@@ -1,29 +1,27 @@
|
|
1
1
|
source "https://rubygems.org"
|
2
2
|
|
3
3
|
group :test do
|
4
|
-
gem "rake"
|
5
|
-
gem "puppet", ENV['PUPPET_VERSION'] || '~> 3.7.3'
|
6
|
-
gem "rspec-puppet", :git => 'https://github.com/rodjek/rspec-puppet.git'
|
7
|
-
gem "puppetlabs_spec_helper"
|
8
|
-
gem 'rspec-puppet-utils', :git => 'https://github.com/Accuity/rspec-puppet-utils.git'
|
9
|
-
gem 'hiera-puppet-helper', :git => 'https://github.com/bobtfish/hiera-puppet-helper.git'
|
10
|
-
|
4
|
+
gem "rake"
|
5
|
+
gem "puppet", ENV['PUPPET_VERSION'] || '~> 3.7.3'
|
6
|
+
gem "rspec-puppet", :git => 'https://github.com/rodjek/rspec-puppet.git'
|
7
|
+
gem "puppetlabs_spec_helper"
|
8
|
+
gem 'rspec-puppet-utils', :git => 'https://github.com/Accuity/rspec-puppet-utils.git'
|
9
|
+
gem 'hiera-puppet-helper', :git => 'https://github.com/bobtfish/hiera-puppet-helper.git'
|
10
|
+
gem "metadata-json-lint"
|
11
|
+
gem 'puppet-syntax'
|
12
|
+
gem 'puppet-lint'
|
13
|
+
end
|
14
|
+
|
15
|
+
group :integration do
|
11
16
|
gem "beaker", :git => 'https://github.com/puppetlabs/beaker.git'
|
12
17
|
gem "beaker-rspec", :git => 'https://github.com/puppetlabs/beaker-rspec.git'
|
13
18
|
gem "vagrant-wrapper"
|
14
19
|
gem 'serverspec'
|
15
|
-
<%- end -%>
|
16
|
-
# there seems to be a bug with puppet-blacksmith and metadata-json-lint
|
17
|
-
# removing metadata for now
|
18
|
-
gem "metadata-json-lint"
|
19
|
-
gem 'puppet-syntax'
|
20
|
-
gem 'puppet-lint'
|
21
20
|
end
|
22
21
|
|
23
22
|
group :development do
|
24
|
-
gem "travis"
|
25
|
-
gem "travis-lint"
|
26
|
-
gem "puppet-blacksmith"
|
27
|
-
gem "guard-rake"
|
23
|
+
gem "travis"
|
24
|
+
gem "travis-lint"
|
25
|
+
gem "puppet-blacksmith"
|
26
|
+
gem "guard-rake"
|
28
27
|
end
|
29
|
-
|
@@ -0,0 +1,75 @@
|
|
1
|
+
# profiles
|
2
|
+
|
3
|
+
## Module development setup
|
4
|
+
|
5
|
+
Install all the require gems to run test code
|
6
|
+
```shell
|
7
|
+
bundle install (only need to do once)
|
8
|
+
|
9
|
+
```
|
10
|
+
## Running Tests
|
11
|
+
|
12
|
+
### Unit tests
|
13
|
+
This type of testing is fast and should be the first thing you do before comming your code. Mistakes can be found
|
14
|
+
in a matter of seconds vs minutes/hours. You can test your logic in a unit test. The downside is you need to learn
|
15
|
+
how to write unit tests which can take some initial time getting used to.
|
16
|
+
|
17
|
+
```shell
|
18
|
+
bundle exec rake spec
|
19
|
+
|
20
|
+
```
|
21
|
+
|
22
|
+
### Integration Testing
|
23
|
+
This type of testing is somewhat manual and requires the use of vagrant and a test vm that is controlled by vagrant.
|
24
|
+
You can find the list of available test vms by running `vagrant status` in the root of the module directory. There is
|
25
|
+
at lot of magic happening in the vagrantfile that makes this easy. Windows support with this module has not been added yet.
|
26
|
+
|
27
|
+
```shell
|
28
|
+
|
29
|
+
$ vagrant status
|
30
|
+
Current machine states:
|
31
|
+
|
32
|
+
win2012r2 not created (vmware_fusion)
|
33
|
+
win2008r2 not created (vmware_fusion)
|
34
|
+
centos6 running (vmware_fusion)
|
35
|
+
```
|
36
|
+
|
37
|
+
To run a test first you need to define the test code located in module_root/tests directory. This code is nothing more
|
38
|
+
than a bunch of puppet code that uses your manifest code. You will be using puppet apply to run this code on the vm.
|
39
|
+
Have a look inside the tests directory for examples.
|
40
|
+
|
41
|
+
Example test file
|
42
|
+
```
|
43
|
+
include profiles::default_linux
|
44
|
+
file{'/tmp/test.txt':
|
45
|
+
ensure => file,
|
46
|
+
content => 'Hello World'
|
47
|
+
}
|
48
|
+
```
|
49
|
+
|
50
|
+
There are a few ways to run the test code against a test vm, both of which have the same outcome.
|
51
|
+
|
52
|
+
```shell
|
53
|
+
bundle exec rake spec_prep
|
54
|
+
VAGRANT_MANIFEST=linux.pp vagrant provision centos6
|
55
|
+
```
|
56
|
+
|
57
|
+
or use the rake command which bundles the two commands together
|
58
|
+
|
59
|
+
```shell
|
60
|
+
bundle exec rake "vagrant_up[linux.pp,centos6]"
|
61
|
+
```
|
62
|
+
|
63
|
+
### Acceptance Tests
|
64
|
+
Acceptance testing is sorta like combining unit testing and integration testing where it tests the code on real systems
|
65
|
+
automatically across a wide range of operating systems. This is an advanced topic, so yu will want to master unit and
|
66
|
+
integration testing first before writing acceptance tests.
|
67
|
+
|
68
|
+
```shell
|
69
|
+
bundle exec rake beaker
|
70
|
+
|
71
|
+
```
|
72
|
+
|
73
|
+
|
74
|
+
## CI config doc
|
75
|
+
https://gitlab.com/gitlab-org/gitlab-ci-multi-runner/blob/master/docs/configuration/advanced-configuration.md
|
@@ -24,9 +24,9 @@ PuppetLint.configuration.send('disable_class_parameter_defaults')
|
|
24
24
|
PuppetLint.configuration.send('disable_class_inherits_from_params_class')
|
25
25
|
|
26
26
|
exclude_paths = [
|
27
|
-
|
28
|
-
|
29
|
-
|
27
|
+
"pkg/**/*",
|
28
|
+
"vendor/**/*",
|
29
|
+
"spec/**/*",
|
30
30
|
]
|
31
31
|
PuppetLint.configuration.ignore_paths = exclude_paths
|
32
32
|
PuppetSyntax.exclude_paths = exclude_paths
|
@@ -37,8 +37,36 @@ end
|
|
37
37
|
|
38
38
|
desc "Run syntax, lint, and spec tests."
|
39
39
|
task :test => [
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
40
|
+
:syntax,
|
41
|
+
:lint,
|
42
|
+
:spec,
|
43
|
+
:metadata,
|
44
44
|
]
|
45
|
+
def io_popen(command)
|
46
|
+
IO.popen(command) do |io|
|
47
|
+
io.each do |line|
|
48
|
+
print line
|
49
|
+
yield line if block_given?
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
desc 'Vagrant VM power up and provision'
|
55
|
+
task :vagrant_up, [:manifest, :hostname] do |t, args|
|
56
|
+
args.with_defaults(:manifest => 'init.pp', :hostname => '')
|
57
|
+
Rake::Task['spec_prep'].execute
|
58
|
+
ENV['VAGRANT_MANIFEST'] = args[:manifest]
|
59
|
+
provision = false
|
60
|
+
io_popen("vagrant up #{args[:hostname]}") do |line|
|
61
|
+
provision = true if line =~ /is already running./
|
62
|
+
end
|
63
|
+
io_popen("vagrant provision #{args[:hostname]}") if provision
|
64
|
+
end
|
65
|
+
|
66
|
+
# Cleanup vagrant environment
|
67
|
+
desc 'Vagrant VM shutdown and fixtures cleanup'
|
68
|
+
task :vagrant_destroy do
|
69
|
+
Rake::Task['spec_prep'].execute
|
70
|
+
`vagrant destroy -f`
|
71
|
+
Rake::Task['spec_clean'].execute
|
72
|
+
end
|
@@ -0,0 +1,95 @@
|
|
1
|
+
def vm(opt)
|
2
|
+
module_name = opt.fetch(:module).to_s || raise(ArgumentError, 'Must provide puppet module name')
|
3
|
+
hostname = opt.fetch(:hostname, module_name).to_s
|
4
|
+
memory = opt.fetch(:memory, 512)
|
5
|
+
cpu = opt.fetch(:cpu, 1)
|
6
|
+
box = opt.fetch(:box).to_s || raise(ArgumentError, 'Must provide box type.')
|
7
|
+
url = opt.fetch(:url, '').to_s
|
8
|
+
os_type = opt[:os_type] || opt[:type] || :linux
|
9
|
+
gui = opt.fetch(:gui, false)
|
10
|
+
ports = Array(opt.fetch(:port, []))
|
11
|
+
iso = opt.fetch(:iso, nil)
|
12
|
+
proj_root = File.expand_path(File.join(File.dirname(__FILE__)))
|
13
|
+
fixture_modules = File.join(proj_root, 'spec', 'fixtures', 'modules')
|
14
|
+
|
15
|
+
Vagrant.configure('2') do |conf|
|
16
|
+
|
17
|
+
# forward all the ports
|
18
|
+
ports.each do |p|
|
19
|
+
conf.vm.network(:forwarded_port, guest: p, host: p, auto_correct: true)
|
20
|
+
end
|
21
|
+
|
22
|
+
if os_type == :windows
|
23
|
+
conf.ssh.username = 'vagrant'
|
24
|
+
conf.winrm.username = 'vagrant'
|
25
|
+
conf.winrm.password = 'vagrant'
|
26
|
+
end
|
27
|
+
|
28
|
+
conf.vm.define hostname.to_sym do |mod|
|
29
|
+
mod.vm.box = box
|
30
|
+
mod.vm.box_url = url
|
31
|
+
|
32
|
+
if os_type == :windows
|
33
|
+
mod.vm.guest = :windows
|
34
|
+
mod.vm.communicator = 'winrm'
|
35
|
+
mod.vm.synced_folder './' , "/ProgramData/PuppetLabs/puppet/etc/modules/#{module_name}"
|
36
|
+
mod.vm.synced_folder 'spec/fixtures/modules' , '/temp/modules'
|
37
|
+
else
|
38
|
+
mod.vm.synced_folder './', "/etc/puppet/modules/#{module_name}"
|
39
|
+
mod.vm.synced_folder 'spec/fixtures/modules', '/tmp/puppet/modules'
|
40
|
+
end
|
41
|
+
|
42
|
+
mod.vm.hostname = hostname
|
43
|
+
|
44
|
+
mod.vm.provider :vmware_fusion do |f|
|
45
|
+
f.gui = gui
|
46
|
+
f.vmx['displayName'] = hostname
|
47
|
+
f.vmx['memsize'] = memory
|
48
|
+
f.vmx['numvcpus'] = cpu
|
49
|
+
if iso
|
50
|
+
f.vmx['ide1:0.devicetype'] = "cdrom-image"
|
51
|
+
f.vmx['ide1:0.filename'] = iso
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
mod.vm.provider :vmware_workstation do |f|
|
56
|
+
f.gui = gui
|
57
|
+
f.vmx['displayName'] = hostname
|
58
|
+
f.vmx['memsize'] = memory
|
59
|
+
f.vmx['numvcpus'] = cpu
|
60
|
+
if iso
|
61
|
+
f.vmx['ide1:0.devicetype'] = "cdrom-image"
|
62
|
+
f.vmx['ide1:0.filename'] = iso
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
mod.vm.provider :virtualbox do |v|
|
67
|
+
v.gui = gui
|
68
|
+
v.name = hostname
|
69
|
+
v.memory = memory
|
70
|
+
v.cpus = cpu
|
71
|
+
end
|
72
|
+
|
73
|
+
if os_type == :windows
|
74
|
+
manifest = ENV['VAGRANT_MANIFEST'] || 'init.pp'
|
75
|
+
mod.vm.provision :shell, :inline => "@powershell -NoProfile -ExecutionPolicy Bypass -Command \"iex ((new-object net.webclient).DownloadString('https://chocolatey.org/install.ps1'))\" && SET PATH=%PATH%;%ALLUSERSPROFILE%\chocolatey\bin"
|
76
|
+
mod.vm.provision :shell, :inline => "choco install puppet"
|
77
|
+
mod.vm.provision :shell, :inline => "puppet apply --modulepath 'C:/ProgramData/PuppetLabs/puppet/etc/modules;C:/temp/modules' --verbose C:/ProgramData/PuppetLabs/puppet/etc/modules/#{module_name}/tests/#{manifest}"
|
78
|
+
else
|
79
|
+
mod.vm.provision :puppet do |p|
|
80
|
+
p.manifests_path = 'tests'
|
81
|
+
p.hiera_config_path = File.join(fixture_modules, 'hieradata', 'hiera.yaml')
|
82
|
+
p.manifest_file = ENV['VAGRANT_MANIFEST'] || 'init.pp'
|
83
|
+
#p.module_path = fixture_modules
|
84
|
+
# because of how symlinks are handled via the spec_helper we are forced to mount the modules is different locations
|
85
|
+
# otherwise we could just use the above option
|
86
|
+
p.options = '--modulepath="/etc/puppet/modules:/tmp/puppet/modules"'
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
module_name = File.basename(File.expand_path(File.join(File.dirname(__FILE__))))
|
93
|
+
vm :hostname => 'win2012r2', :module => module_name, :box => 'opentable/win-2012r2-standard-amd64-nocm', :url => 'opentable/win-2012r2-standard-amd64-nocm', :cpu => 1, :memory => 4096, :gui => true
|
94
|
+
vm :hostname => 'win2008r2', :module => module_name, :box => 'opentable/win-2008r2-standard-amd64-nocm', :url => 'opentable/win-2008r2-standard-amd64-nocm', :cpu => 1, :memory => 4096, :gui => true
|
95
|
+
vm :hostname => 'centos6', :module => module_name, :box => 'puppetlabs/centos-6.6-64-puppet', :url => 'puppetlabs/centos-6.6-64-puppet', :cpu => 1, :memory => 2048, :gui => false
|
@@ -1,11 +1,11 @@
|
|
1
1
|
HOSTS:
|
2
|
-
centos-
|
2
|
+
centos-66-x64:
|
3
3
|
roles:
|
4
4
|
- master
|
5
5
|
platform: el-6-x86_64
|
6
|
-
box
|
7
|
-
box_url
|
8
|
-
hypervisor
|
6
|
+
box: puppetlabs/centos-6.6-64-nocm
|
7
|
+
box_url: https://vagrantcloud.com/puppetlabs/boxes/centos-6.6-64-nocm
|
8
|
+
hypervisor: vagrant
|
9
9
|
CONFIG:
|
10
|
-
log_level:
|
11
|
-
type:
|
10
|
+
log_level: verbose
|
11
|
+
type: foss
|
@@ -1,12 +1,20 @@
|
|
1
|
-
require 'hiera-puppet-helper'
|
2
|
-
|
3
1
|
# optional, this should be the path to where the hiera data config file is in this repo
|
4
2
|
# You must update this if your actual hiera data lives inside your module.
|
5
|
-
# I only assume
|
6
|
-
hiera_config_file = File.expand_path(File.join(File.dirname(__FILE__), '
|
3
|
+
# I only assume you have a separate repository for hieradata and its include in your .fixtures
|
4
|
+
hiera_config_file = File.expand_path(File.join(File.dirname(__FILE__), 'fixtures','modules','hieradata', 'hiera.yaml'))
|
7
5
|
|
8
6
|
# hiera_config and hiera_data are mutually exclusive contexts.
|
9
7
|
|
8
|
+
shared_content :global_hiera_data do
|
9
|
+
let(:hiera_data) do
|
10
|
+
{
|
11
|
+
<% @all_hiera_data.sort.each do |key, value| -%>
|
12
|
+
#"<%= key %>" => '',
|
13
|
+
<% end %>
|
14
|
+
}
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
10
18
|
shared_context :hiera do
|
11
19
|
# example only,
|
12
20
|
let(:hiera_data) do
|
@@ -32,6 +40,6 @@ end
|
|
32
40
|
# you cannot use this in addition to any of the hiera_data contexts above
|
33
41
|
shared_context :real_hiera_data do
|
34
42
|
let(:hiera_config) do
|
35
|
-
|
43
|
+
hiera_config_file
|
36
44
|
end
|
37
|
-
end
|
45
|
+
end
|
data/lib/retrospec/version.rb
CHANGED
data/puppet-retrospec.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "puppet-retrospec"
|
8
|
-
s.version = "0.7.
|
8
|
+
s.version = "0.7.3"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Corey Osman"]
|
12
|
-
s.date = "2015-
|
12
|
+
s.date = "2015-07-28"
|
13
13
|
s.description = "Retrofits and generates valid puppet rspec test code to existing modules"
|
14
14
|
s.email = "corey@logicminds.biz"
|
15
15
|
s.executables = ["retrospec"]
|
@@ -40,7 +40,9 @@ Gem::Specification.new do |s|
|
|
40
40
|
"lib/retrospec/templates/module_files/.gitignore.erb",
|
41
41
|
"lib/retrospec/templates/module_files/.travis.yml",
|
42
42
|
"lib/retrospec/templates/module_files/Gemfile",
|
43
|
+
"lib/retrospec/templates/module_files/README.markdown",
|
43
44
|
"lib/retrospec/templates/module_files/Rakefile",
|
45
|
+
"lib/retrospec/templates/module_files/Vagrantfile",
|
44
46
|
"lib/retrospec/templates/module_files/spec/acceptance/nodesets/centos-59-x64.yml",
|
45
47
|
"lib/retrospec/templates/module_files/spec/acceptance/nodesets/centos-64-x64-pe.yml",
|
46
48
|
"lib/retrospec/templates/module_files/spec/acceptance/nodesets/centos-64-x64.yml",
|
data/spec/unit/module_spec.rb
CHANGED
@@ -145,10 +145,28 @@ describe "puppet-retrospec" do
|
|
145
145
|
tomcat = Retrospec.new(@opts[:module_path], @opts)
|
146
146
|
filepath = File.expand_path(File.join(@path, 'spec', 'shared_contexts.rb'))
|
147
147
|
tomcat.safe_create_module_files
|
148
|
-
path = tomcat.module_path
|
149
148
|
expect(File.exists?(filepath)).to eq(true)
|
150
149
|
end
|
151
150
|
|
151
|
+
it 'should produce hiera data' do
|
152
|
+
tomcat = Retrospec.new(@opts[:module_path], @opts)
|
153
|
+
filepath = File.expand_path(File.join(@path, 'spec', 'shared_contexts.rb'))
|
154
|
+
tomcat.safe_create_module_files
|
155
|
+
path = tomcat.module_path
|
156
|
+
require 'pry'
|
157
|
+
expect(tomcat.spec_object.all_hiera_data).to eq({"tomcat::catalina_home"=>nil,
|
158
|
+
"tomcat::user"=>nil,
|
159
|
+
"tomcat::group"=>nil,
|
160
|
+
"tomcat::install_from_source"=>nil,
|
161
|
+
"tomcat::purge_connectors"=>nil,
|
162
|
+
"tomcat::purge_realms"=>nil,
|
163
|
+
"tomcat::manage_user"=>nil,
|
164
|
+
"tomcat::manage_group"=>nil}
|
165
|
+
)
|
166
|
+
|
167
|
+
expect(File.read(filepath)).to include('#"tomcat::catalina_home" => \'\',')
|
168
|
+
end
|
169
|
+
|
152
170
|
it 'should create acceptance spec helper file' do
|
153
171
|
opts = {:module_path => @path, :enable_beaker_tests => true,
|
154
172
|
:enable_user_templates => false, :template_dir => nil }
|
data/spec/unit/resource_spec.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: puppet-retrospec
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.7.
|
4
|
+
version: 0.7.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Corey Osman
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-07-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: facter
|
@@ -277,7 +277,9 @@ files:
|
|
277
277
|
- lib/retrospec/templates/module_files/.gitignore.erb
|
278
278
|
- lib/retrospec/templates/module_files/.travis.yml
|
279
279
|
- lib/retrospec/templates/module_files/Gemfile
|
280
|
+
- lib/retrospec/templates/module_files/README.markdown
|
280
281
|
- lib/retrospec/templates/module_files/Rakefile
|
282
|
+
- lib/retrospec/templates/module_files/Vagrantfile
|
281
283
|
- lib/retrospec/templates/module_files/spec/acceptance/nodesets/centos-59-x64.yml
|
282
284
|
- lib/retrospec/templates/module_files/spec/acceptance/nodesets/centos-64-x64-pe.yml
|
283
285
|
- lib/retrospec/templates/module_files/spec/acceptance/nodesets/centos-64-x64.yml
|