controlrepo 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -1
- data/README.md +89 -9
- data/controlrepo.gemspec +2 -1
- data/lib/controlrepo/beaker.rb +1 -6
- data/lib/controlrepo/rake_tasks.rb +18 -3
- data/lib/controlrepo/testconfig.rb +13 -4
- data/lib/controlrepo.rb +1 -8
- data/templates/Gemfile.erb +13 -5
- data/templates/Rakefile.erb +6 -1
- data/templates/acceptance_test_spec.rb.erb +89 -12
- data/templates/spec_helper_acceptance.rb.erb +63 -16
- data/templates/test_spec.rb.erb +7 -0
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1a2459c4880e5865531609c8b94a3d7a1c492133
|
4
|
+
data.tar.gz: 32094fc438825fb19b1d40cfde19b56837e24566
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ccc385b3ce617f8f28146fe78cf10ef4c39a21e317ad572cd358bcf1668a818375e33c1c94451cca9bfdc0351b994819183970b187b95f4d4e8a8550db6d0c77
|
7
|
+
data.tar.gz: 8fc06a94e542a89c3cd5a19907fdedb47c249fc7faf00e4ac967974ddc8b36c0dbeb4419a567bfc82970ad58bdc34493838cbf8f89f8def9a702fd1d9fd4616c
|
data/.gitignore
CHANGED
@@ -1 +1,2 @@
|
|
1
|
-
.DS_Store
|
1
|
+
.DS_Store
|
2
|
+
*.gem
|
data/README.md
CHANGED
@@ -6,7 +6,7 @@ This gem gives you a bunch of tools to use for testing and generally managing Pu
|
|
6
6
|
|
7
7
|
This toolset has two distinct ways of being used, easy mode and hard mode.
|
8
8
|
|
9
|
-
|
9
|
+
## Easy Mode
|
10
10
|
|
11
11
|
The object of *easy mode* is to allow people to run simple `it { should compile }` acceptance tests without needing to set up any of the extra stuff required by the rspec-puppet testing framework.
|
12
12
|
|
@@ -14,7 +14,7 @@ The object of *easy mode* is to allow people to run simple `it { should compile
|
|
14
14
|
|
15
15
|
A stretch goal is to also include acceptance testing, allowing people to spin up boxes for each role they have and test them before merging code into development environments or production. At the moment we can't do this, hold tight.
|
16
16
|
|
17
|
-
|
17
|
+
### Easy mode config
|
18
18
|
|
19
19
|
The whole idea of easy mode is that we should just be able to write down which classes we want to test on which machines and this tool should be able to do the rest. This all has to be set up somewhere, this is **spec/controlrepo.yaml** which looks something like this:
|
20
20
|
|
@@ -50,15 +50,15 @@ test_matrix:
|
|
50
50
|
|
51
51
|
It consists of the following sections:
|
52
52
|
|
53
|
-
|
53
|
+
#### Classes:
|
54
54
|
|
55
55
|
This is where we list all of the classes that we want to test, normally this will just be a list of roles. Note that these classes must *actually exist* for reasons that should be obvious.
|
56
56
|
|
57
|
-
|
57
|
+
#### Nodes:
|
58
58
|
|
59
59
|
Each node in the list refers one of two things depending on weather we are running **spec** or **acceptance** tests. If we are running **spec** tests each node refers to the name of a [fact set](#fact-sets) because this will be the set of facts that the `it { should compile }` test will be run against. If we are are running **acceptance** tests then each node will refer to a *nodeset* file which we can generate (or at least try to) using the `generate_nodesets` rake task. For acceptance testing the nodeset file will tell us how to spin up the VMs for each machine.
|
60
60
|
|
61
|
-
|
61
|
+
#### Groups:
|
62
62
|
|
63
63
|
Groups are used to save us a bit of time and code (if you can call yaml that). Unsurprisingly a group is a way to bundle either classes or nodes into a group that we can refer to but it's name instead of repeating ourselves a whole bunch. There are 2 **default groups:**
|
64
64
|
|
@@ -69,7 +69,7 @@ You can guess what they are for I hope.
|
|
69
69
|
|
70
70
|
*Note that groups CANNOT contain a mix of classes and nodes, only one or the other.*
|
71
71
|
|
72
|
-
|
72
|
+
#### Test Matrix:
|
73
73
|
|
74
74
|
This is the section of th config file that makes the magic happen. In the test matrix we choose on which nodes we will tests which classes. You can use groups anywhere here as you can see in the example above. We also have the option of using *include* and *exclude* which will be useful if you have a lot of groups.
|
75
75
|
|
@@ -86,12 +86,92 @@ This is assuming that you have all of your linux nodes in the `linux_nodes` grou
|
|
86
86
|
|
87
87
|
When setting up your tests matrix don't worry too much about using groups that will cause duplicate combinations of `node -> class` pairs. The rake tasks run deduplication before running any of the tests to make sure that we are not wasting time. This happens at runtime and does not affect the file or anything.
|
88
88
|
|
89
|
-
|
89
|
+
## Hiera Data
|
90
90
|
|
91
|
-
|
91
|
+
If you have hiera data inside your controlrepo (or somewhere else) the Controlrepo gem can be configured to use it. Just dump your `hiera.yaml` file from the puppet master into the `spec/` directory and you are good to go. **NOTE:** This assumes that the path to your hiera data (datadir) is relative to the root of the controlrepo, if not it will fall over
|
92
92
|
|
93
|
+
## R10k.yaml
|
93
94
|
|
94
|
-
|
95
|
+
For the Controlrepo gem to be able to clone the controlrepo (itself) from git (into a temp dir) it needs an `r10k.yaml` file under the `spec/` directory. Don't worry about any of the paths here, we dynamically generate and override them. I realise that this is kind of redundant and will be looking into changing it in the future.
|
96
|
+
|
97
|
+
TODO: Look into this ^
|
98
|
+
|
99
|
+
## pre_conditions
|
100
|
+
|
101
|
+
If your spec tests are failing because if dependencies on the (closed source) PE modules, don't stress, there is a way around this! Let's start with an example: Somewhere in my puppet code I am managing something that needs to restart the Puppet Server i.e.
|
102
|
+
|
103
|
+
```puppet
|
104
|
+
file { '/etc/puppetlabs/puppet/puppet.conf':
|
105
|
+
ensure => file,
|
106
|
+
content => '#nothing',
|
107
|
+
notify => Service['pe-puppetserver'], # This will fail without the PE module!
|
108
|
+
}
|
109
|
+
```
|
110
|
+
|
111
|
+
If we try to compile a catalog against this code it will fail because we are not including the PE class that manages `Service['pe-puppetserver']`, therefore it is not in the catalog and we cannot establist dependencies upon it.
|
112
|
+
|
113
|
+
If we run into a situations like this we can use the `spec/pre_conditions` folder to get around them e.g. Putting this in the `spec/pre_conditions` folder will solve our issues:
|
114
|
+
|
115
|
+
```puppet
|
116
|
+
service { 'pe-puppetserver':
|
117
|
+
ensure => 'running',
|
118
|
+
}
|
119
|
+
```
|
120
|
+
|
121
|
+
This is because anything in this folder will get add to the catalog along with the class (role) we are testing.
|
122
|
+
|
123
|
+
NOTE: [resource collector ovverides](https://docs.puppetlabs.com/puppet/latest/reference/lang_resources_advanced.html#amending-attributes-with-a-collector) could be useful in this situation.
|
124
|
+
|
125
|
+
## Lets go!
|
126
|
+
|
127
|
+
Now to **run the spec tests** just do a:
|
128
|
+
|
129
|
+
`bundler exec rake controlrepo_spec`
|
130
|
+
|
131
|
+
## Acceptance testing
|
132
|
+
|
133
|
+
Now that we have a lot of stuff set up, we can also run acceptance testing! This will do much the same thing as the spec testing, except on an actual box. (It will run `include role::your_role` on the server and check for errors)
|
134
|
+
|
135
|
+
This does however take a little more preparation. The main thing we need is that we need to know which nodes to spin up in order to do the testing. We use Beaker to actually interact with the hypervisor of choice and therefore we use their [nodeset file syntax](https://github.com/puppetlabs/beaker/blob/master/docs/Example-Vagrant-Hosts-Files.md). The only thing we need to do is **name the nodes the same aswe do for spec tests** and **have all the nodes in the same file**.
|
136
|
+
|
137
|
+
Here is an example:
|
138
|
+
|
139
|
+
```yaml
|
140
|
+
# spec/acceptance/nodesets/controlrepo.yaml
|
141
|
+
HOSTS:
|
142
|
+
centos6a:
|
143
|
+
roles:
|
144
|
+
- agent
|
145
|
+
platform: el-6-64
|
146
|
+
box: puppetlabs/centos-6.6-64-puppet
|
147
|
+
box_url: https://atlas.hashicorp.com/puppetlabs/boxes/centos-6.6-64-puppet
|
148
|
+
hypervisor: vagrant_virtualbox
|
149
|
+
centos7b:
|
150
|
+
roles:
|
151
|
+
- agent
|
152
|
+
platform: el-7-64
|
153
|
+
box: puppetlabs/centos-7.0-64-puppet
|
154
|
+
box_url: https://atlas.hashicorp.com/puppetlabs/boxes/centos-7.0-64-puppet
|
155
|
+
hypervisor: vagrant_virtualbox
|
156
|
+
ubuntu1404a:
|
157
|
+
roles:
|
158
|
+
- agent
|
159
|
+
platform: ubuntu-14.04-64
|
160
|
+
box: puppetlabs/ubuntu-14.04-64-puppet
|
161
|
+
box_url: https://atlas.hashicorp.com/puppetlabs/boxes/ubuntu-14.04-64-puppet
|
162
|
+
hypervisor: vagrant_virtualbox
|
163
|
+
```
|
164
|
+
|
165
|
+
Now when we run:
|
166
|
+
|
167
|
+
`bundle exec rake controlrepo_acceptance`
|
168
|
+
|
169
|
+
It will use the same test matrix we have already defined in `controlrepo.yaml` and spin up each node and do the testing.
|
170
|
+
|
171
|
+
NOTE: The same test deduplication will be applied here as it is in spec tests, also; macines will be classified with **one** role, run, destroyed, re-created and then classified with the next role.
|
172
|
+
|
173
|
+
|
174
|
+
## Hard mode
|
95
175
|
|
96
176
|
The point of *hard mode* is to give people who are familiar with RSpec testing with puppet a set of useful tools that they can mix into their tests to save some hassle. We also want to help in getting your tests set up by automatically generating `.fixtures.yml` and nodesets.
|
97
177
|
|
data/controlrepo.gemspec
CHANGED
@@ -3,7 +3,7 @@ $LOAD_PATH.unshift File.expand_path("../lib", __FILE__)
|
|
3
3
|
|
4
4
|
Gem::Specification.new do |s|
|
5
5
|
s.name = "controlrepo"
|
6
|
-
s.version = "1.
|
6
|
+
s.version = "1.1.0"
|
7
7
|
s.authors = ["Dylan Ratcliffe"]
|
8
8
|
s.email = ["dylan.ratcliffe@puppetlabs.com"]
|
9
9
|
s.homepage = ""
|
@@ -22,5 +22,6 @@ Gem::Specification.new do |s|
|
|
22
22
|
s.add_runtime_dependency 'rspec-puppet'
|
23
23
|
s.add_runtime_dependency 'rspec'
|
24
24
|
s.add_runtime_dependency 'bundler'
|
25
|
+
s.add_runtime_dependency 'r10k'
|
25
26
|
s.add_runtime_dependency 'puppet'
|
26
27
|
end
|
data/lib/controlrepo/beaker.rb
CHANGED
@@ -151,7 +151,7 @@ class Controlrepo
|
|
151
151
|
network_manager = ::Beaker::NetworkManager.new(options,logger)
|
152
152
|
|
153
153
|
# Hack the network manager to smash our host in there without provisioning
|
154
|
-
network_manager.instance_variable_set(:@hosts,host)
|
154
|
+
network_manager.instance_variable_set(:@hosts,[host])
|
155
155
|
|
156
156
|
# Now that we have a working network manager object, we can provision, but only if
|
157
157
|
# we need to, ahhh smart...
|
@@ -162,11 +162,6 @@ class Controlrepo
|
|
162
162
|
network_manager.configure
|
163
163
|
end
|
164
164
|
|
165
|
-
if opts[:deploy_controlrepo]
|
166
|
-
# Get the code onto the host
|
167
|
-
Controlrepo::Beaker.deploy_controlrepo_on(host,repo)
|
168
|
-
end
|
169
|
-
|
170
165
|
# Actually run the tests
|
171
166
|
manifest = "include #{puppet_class}"
|
172
167
|
|
@@ -104,9 +104,10 @@ task :controlrepo_autotest_prep do
|
|
104
104
|
# Deduplicate and write the tests (Spec and Acceptance)
|
105
105
|
Controlrepo::Test.deduplicate(@config.tests).each do |test|
|
106
106
|
@config.write_spec_test("#{@repo.tempdir}/spec/classes",test)
|
107
|
-
@config.write_acceptance_test("#{@repo.tempdir}/spec/acceptance",test)
|
108
107
|
end
|
109
108
|
|
109
|
+
@config.write_acceptance_tests("#{@repo.tempdir}/spec/acceptance",Controlrepo::Test.deduplicate(@config.tests))
|
110
|
+
|
110
111
|
# Parse the current hiera config, modify, and write it to the temp dir
|
111
112
|
hiera_config = @repo.hiera_config
|
112
113
|
hiera_config.each do |setting,value|
|
@@ -125,9 +126,16 @@ task :controlrepo_autotest_spec do
|
|
125
126
|
Dir.chdir(@repo.tempdir) do
|
126
127
|
#`bundle install --binstubs`
|
127
128
|
#`bin/rake spec_standalone`
|
128
|
-
exec("bundle install --
|
129
|
+
exec("bundle install --without acceptance; bundle exec rake spec_standalone")
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
task :controlrepo_autotest_acceptance do
|
134
|
+
Dir.chdir(@repo.tempdir) do
|
135
|
+
#`bundle install --binstubs`
|
136
|
+
#`bin/rake spec_standalone`
|
137
|
+
exec("bundle install; bundle exec rake acceptance")
|
129
138
|
end
|
130
|
-
# TODO: Look at how this outputs and see if it needs to be improved
|
131
139
|
end
|
132
140
|
|
133
141
|
task :controlrepo_spec => [
|
@@ -135,6 +143,13 @@ task :controlrepo_spec => [
|
|
135
143
|
:controlrepo_autotest_spec
|
136
144
|
]
|
137
145
|
|
146
|
+
task :controlrepo_acceptance => [
|
147
|
+
:controlrepo_autotest_prep,
|
148
|
+
:controlrepo_autotest_acceptance
|
149
|
+
]
|
150
|
+
|
151
|
+
|
152
|
+
|
138
153
|
task :r10k_deploy_local do
|
139
154
|
require 'controlrepo/testconfig'
|
140
155
|
@repo = Controlrepo.new
|
@@ -40,6 +40,17 @@ class Controlrepo
|
|
40
40
|
end
|
41
41
|
end
|
42
42
|
|
43
|
+
def pre_condition
|
44
|
+
# Read all the pre_conditions and return the string
|
45
|
+
spec_dir = Controlrepo.new.spec_dir
|
46
|
+
puppetcode = []
|
47
|
+
Dir["#{spec_dir}/pre_conditions/*.pp"].each do |condition_file|
|
48
|
+
puppetcode << File.read(condition_file)
|
49
|
+
end
|
50
|
+
return false if puppetcode.count == 0
|
51
|
+
puppetcode.join("\n")
|
52
|
+
end
|
53
|
+
|
43
54
|
def r10k_deploy_local(repo = Controlrepo.new)
|
44
55
|
require 'controlrepo'
|
45
56
|
tempdir = Dir.mktmpdir('r10k')
|
@@ -74,12 +85,10 @@ class Controlrepo
|
|
74
85
|
File.write("#{location}/#{randomness}_#{test.to_s}_spec.rb",ERB.new(spec_template, nil, '-').result(binding))
|
75
86
|
end
|
76
87
|
|
77
|
-
def
|
88
|
+
def write_acceptance_tests(location, tests)
|
78
89
|
template_dir = File.expand_path('../../templates',File.dirname(__FILE__))
|
79
90
|
acc_test_template = File.read(File.expand_path('./acceptance_test_spec.rb.erb',template_dir))
|
80
|
-
|
81
|
-
randomness = (0...6).map { (65 + rand(26)).chr }.join
|
82
|
-
File.write("#{location}/#{randomness}_#{test.to_s}_spec.rb",ERB.new(acc_test_template, nil, '-').result(binding))
|
91
|
+
File.write("#{location}/acceptance_spec.rb",ERB.new(acc_test_template, nil, '-').result(binding))
|
83
92
|
end
|
84
93
|
|
85
94
|
def write_spec_helper_acceptance(location, repo)
|
data/lib/controlrepo.rb
CHANGED
data/templates/Gemfile.erb
CHANGED
@@ -1,5 +1,13 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
gem '
|
5
|
-
gem 'puppetlabs_spec_helper'
|
1
|
+
source 'https://rubygems.org'
|
2
|
+
|
3
|
+
group :spec do
|
4
|
+
gem 'rspec-puppet'
|
5
|
+
gem 'puppetlabs_spec_helper'
|
6
|
+
end
|
7
|
+
|
8
|
+
group :acceptance do
|
9
|
+
gem 'beaker-rspec'
|
10
|
+
gem 'controlrepo', :git => 'https://github.com/dylanratcliffe/controlrepo_gem.git'
|
11
|
+
end
|
12
|
+
|
13
|
+
gem 'rake'
|
data/templates/Rakefile.erb
CHANGED
@@ -1,18 +1,95 @@
|
|
1
1
|
require 'spec_helper_acceptance'
|
2
2
|
|
3
|
+
describe "Acceptance Testing" do
|
4
|
+
before :each do |test|
|
5
|
+
#try to find the indentation level and mirror it in beaker logger
|
6
|
+
padding = ""
|
7
|
+
# Get the depth and add that as padding
|
8
|
+
(test.metadata[:scoped_id].split(':').count - 1).times do
|
9
|
+
padding << " "
|
10
|
+
end
|
11
|
+
logger.line_prefix = padding
|
12
|
+
end
|
13
|
+
<% tests.each do |test| -%>
|
3
14
|
<% test.nodes.each do |node| -%>
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
15
|
+
<% test.classes.each do |cls| -%>
|
16
|
+
describe "<%= cls.name %> on <%= node.name %>" do
|
17
|
+
after :all do
|
18
|
+
logger.line_prefix = " "
|
19
|
+
$nwm.cleanup
|
20
|
+
end
|
21
|
+
|
22
|
+
describe "provisioning <%= node.name %>" do
|
23
|
+
#after :all do
|
24
|
+
# # Reset the HOSTS hash to its original value
|
25
|
+
# options[:HOSTS] = $original_hosts
|
26
|
+
#end
|
27
|
+
|
28
|
+
it "should be able to set up a Beaker Network Manger object to handle the hypervisors" do
|
29
|
+
current_opts = {}
|
30
|
+
OPTIONS.each do |opt,val|
|
31
|
+
if opt == :HOSTS
|
32
|
+
val.each do |k,v|
|
33
|
+
if k == :<%= node.name %>
|
34
|
+
current_opts[:HOSTS] = {k => v}
|
35
|
+
end
|
36
|
+
end
|
37
|
+
else
|
38
|
+
current_opts[opt] = val
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
# I copied this code off the internet, basically it allows us
|
43
|
+
# to refer to each key as either a string or an object
|
44
|
+
current_opts.default_proc = proc do |h, k|
|
45
|
+
case k
|
46
|
+
when String then sym = k.to_sym; h[sym] if h.key?(sym)
|
47
|
+
when Symbol then str = k.to_s; h[str] if h.key?(str)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
expect {
|
52
|
+
$nwm = Beaker::NetworkManager.new(current_opts,logger)
|
53
|
+
}.to_not raise_exception
|
54
|
+
end
|
55
|
+
|
56
|
+
it "should be able to provision using Beaker" do
|
57
|
+
expect {
|
58
|
+
$nwm.provision
|
59
|
+
$nwm.proxy_package_manager
|
60
|
+
$nwm.validate
|
61
|
+
$nwm.configure
|
62
|
+
$hosts = $nwm.instance_variable_get(:@hosts)
|
63
|
+
}.not_to raise_exception
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
describe "copying code to <%= node.name %>" do
|
68
|
+
it "should copy the code successfully" do
|
69
|
+
expect {
|
70
|
+
scp_to $hosts, 'etc', '/'
|
71
|
+
}.not_to raise_exception
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
describe "running puppet" do
|
76
|
+
it "should run with no errors" do
|
77
|
+
expect {
|
78
|
+
apply_manifest_on($hosts,"include <%= cls.name %>",{:catch_failures => true})
|
79
|
+
}.not_to raise_exception
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
describe "checking for idempotency" do
|
84
|
+
it "should run with no changes" do
|
85
|
+
expect {
|
86
|
+
apply_manifest_on($hosts,"include <%= cls.name %>",{:catch_changes => true})
|
87
|
+
}.not_to raise_exception
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
<% end -%>
|
12
92
|
<% end -%>
|
13
93
|
<% end -%>
|
14
|
-
apply_manifest(role, :catch_changes => true)
|
15
|
-
end
|
16
|
-
<% end %>
|
17
94
|
end
|
18
|
-
|
95
|
+
|
@@ -1,24 +1,71 @@
|
|
1
|
-
require 'beaker
|
1
|
+
require 'beaker'
|
2
|
+
require 'beaker-rspec/beaker_shim' # This overloads Rspec's methods and provides the interface between beaker and RSpec
|
3
|
+
require "beaker-rspec/helpers/serverspec"
|
4
|
+
include BeakerRSpec::BeakerShim
|
5
|
+
require 'controlrepo/beaker'
|
2
6
|
|
3
|
-
scp_to hosts, '<%= repo.tempdir %>/etc', '/etc' # Check that this wil work recursively
|
4
7
|
|
8
|
+
#scp_to hosts, '<%= repo.tempdir %>/etc', '/'
|
5
9
|
RSpec.configure do |c|
|
6
|
-
#
|
7
|
-
|
10
|
+
# Enable color
|
11
|
+
c.color = true
|
12
|
+
c.tty = true
|
8
13
|
|
9
14
|
# Readable test descriptions
|
10
15
|
c.formatter = :documentation
|
11
16
|
|
17
|
+
# Define persistant hosts setting
|
18
|
+
c.add_setting :hosts, :default => []
|
19
|
+
# Define persistant options setting
|
20
|
+
c.add_setting :options, :default => {}
|
21
|
+
# Define persistant metadata object
|
22
|
+
c.add_setting :metadata, :default => {}
|
23
|
+
# Define persistant logger object
|
24
|
+
c.add_setting :logger, :default => nil
|
25
|
+
# Define persistant default node
|
26
|
+
c.add_setting :default_node, :default => nil
|
27
|
+
|
28
|
+
#default option values
|
29
|
+
defaults = {
|
30
|
+
:nodeset => 'controlrepo',
|
31
|
+
}
|
32
|
+
#read env vars
|
33
|
+
env_vars = {
|
34
|
+
:color => ENV['BEAKER_color'] || ENV['RS_COLOR'],
|
35
|
+
:nodeset => ENV['BEAKER_set'] || ENV['RS_SET'],
|
36
|
+
:nodesetfile => ENV['BEAKER_setfile'] || ENV['RS_SETFILE'],
|
37
|
+
:provision => ENV['BEAKER_provision'] || ENV['RS_PROVISION'],
|
38
|
+
:keyfile => ENV['BEAKER_keyfile'] || ENV['RS_KEYFILE'],
|
39
|
+
:debug => ENV['BEAKER_debug'] || ENV['RS_DEBUG'],
|
40
|
+
:destroy => ENV['BEAKER_destroy'] || ENV['RS_DESTROY'],
|
41
|
+
}.delete_if {|key, value| value.nil?}
|
42
|
+
#combine defaults and env_vars to determine overall options
|
43
|
+
options = defaults.merge(env_vars)
|
44
|
+
|
45
|
+
# process options to construct beaker command string
|
46
|
+
nodesetfile = options[:nodesetfile] || File.join('spec/acceptance/nodesets',"#{options[:nodeset]}.yml")
|
47
|
+
fresh_nodes = options[:provision] == 'no' ? '--no-provision' : nil
|
48
|
+
keyfile = options[:keyfile] ? ['--keyfile', options[:keyfile]] : nil
|
49
|
+
debug = options[:debug] ? ['--log-level', 'debug'] : nil
|
50
|
+
color = options[:color] == 'no' ? ['--no-color'] : nil
|
51
|
+
|
12
52
|
# Configure all nodes in nodeset
|
13
|
-
|
14
|
-
#
|
15
|
-
#
|
16
|
-
#
|
17
|
-
|
18
|
-
#
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
53
|
+
c.setup([fresh_nodes, '--hosts', nodesetfile, keyfile, debug, color].flatten.compact)
|
54
|
+
#c.provision
|
55
|
+
#c.validate
|
56
|
+
#c.configure
|
57
|
+
|
58
|
+
# Destroy nodes if no preserve hosts
|
59
|
+
c.after :suite do
|
60
|
+
case options[:destroy]
|
61
|
+
when 'no'
|
62
|
+
# Don't cleanup
|
63
|
+
when 'onpass'
|
64
|
+
c.cleanup if RSpec.world.filtered_examples.values.flatten.none?(&:exception)
|
65
|
+
else
|
66
|
+
c.cleanup
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
OPTIONS = options
|
data/templates/test_spec.rb.erb
CHANGED
@@ -5,6 +5,13 @@ describe "<%= cls.name %>" do
|
|
5
5
|
<% test.nodes.each do |node| -%>
|
6
6
|
context "using fact set <%= node.name %>" do
|
7
7
|
let(:facts) { <%= node.fact_set %> }
|
8
|
+
<% if pre_condition -%>
|
9
|
+
let(:pre_condition) {
|
10
|
+
pp = <<END
|
11
|
+
<%= pre_condition.chomp %>
|
12
|
+
END
|
13
|
+
}
|
14
|
+
<% end -%>
|
8
15
|
it { should compile }
|
9
16
|
end
|
10
17
|
<% end -%>
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: controlrepo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dylan Ratcliffe
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-10-
|
11
|
+
date: 2015-10-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -94,6 +94,20 @@ dependencies:
|
|
94
94
|
- - ">="
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: r10k
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :runtime
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
97
111
|
- !ruby/object:Gem::Dependency
|
98
112
|
name: puppet
|
99
113
|
requirement: !ruby/object:Gem::Requirement
|