cucumber-puppet 0.0.6 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,5 +1,5 @@
1
1
  ---
2
2
  :build:
3
- :patch: 6
4
- :minor: 0
3
+ :patch: 0
4
+ :minor: 1
5
5
  :major: 0
@@ -32,6 +32,21 @@ module CucumberPuppetGenerators
32
32
  end
33
33
  end
34
34
 
35
+ class PolicyGenerator < Templater::Generator
36
+ include CucumberPuppet::Helper
37
+
38
+ def source_root
39
+ File.join(File.dirname(__FILE__), '..', 'lib', 'generators', 'policy')
40
+ end
41
+
42
+ desc <<-DESC
43
+ Generate a catalog policy
44
+ cucumber-puppet-gen policy
45
+ DESC
46
+
47
+ directory('catalog', 'catalog', 'features/catalog')
48
+ end
49
+
35
50
  class TestcaseGenerator < Templater::Generator
36
51
  extend CucumberPuppet::Helper
37
52
 
@@ -74,6 +89,7 @@ module CucumberPuppetGenerators
74
89
 
75
90
  desc "Generators for cucumber-puppet"
76
91
  add :feature, FeatureGenerator
92
+ add :policy, PolicyGenerator
77
93
  add :testcase, TestcaseGenerator
78
94
  add :world, WorldGenerator
79
95
 
@@ -7,7 +7,7 @@ class CucumberPuppet
7
7
  # Returns a new CucumberPuppet object.
8
8
  def initialize
9
9
  @confdir = "/etc/puppet"
10
- @manifest = @confdir + "/manifest/site.pp"
10
+ @manifest = @confdir + "/manifests/site.pp"
11
11
 
12
12
  # default facts
13
13
  @facts = {
@@ -41,9 +41,11 @@ class CucumberPuppet
41
41
  # @manifest defaults to @confdir + '/manifests/site.pp'
42
42
  #
43
43
  def compile_catalog( node = nil )
44
- Puppet[:confdir] = @confdir
45
- Puppet[:manifest] = @manifest
44
+ Puppet.settings.handlearg("--confdir", @confdir)
46
45
  Puppet.parse_config
46
+ # reset confdir in case it got overwritten
47
+ Puppet.settings.handlearg("--confdir", @confdir)
48
+ Puppet.settings.handlearg("--manifest", @manifest)
47
49
 
48
50
  unless node.is_a?(Puppet::Node)
49
51
  node = Puppet::Node.new(@facts['hostname'], :classes => @klass)
@@ -71,12 +73,24 @@ class CucumberPuppet
71
73
  end
72
74
 
73
75
  # Returns an Object with the given title from catalog.
74
- def get_resource(title)
75
- @catalog.resource(title)
76
- end
77
- # XXX add deprecation warning for resource()
78
76
  def resource(title)
79
- get_resource(title)
77
+ @catalog.resource(title)
80
78
  end
81
79
 
80
+ # Returns an Array with the catalog's Puppet::Resource objects.
81
+ def catalog_resources
82
+ # This method exists to supply a common interface to the puppet catalog
83
+ # for different versions of puppet.
84
+ @catalog.resources.map do |r|
85
+ if r.is_a?(Puppet::Resource)
86
+ # puppet 2.6 and newer
87
+ r
88
+ elsif r.is_a?(String)
89
+ # puppet 0.25 and older
90
+ resource(r)
91
+ else
92
+ raise "Unknown resource object #{r.class}"
93
+ end
94
+ end
95
+ end
82
96
  end
@@ -0,0 +1,41 @@
1
+ Given /^a node specified by "([^\"]*)"$/ do |file|
2
+ # file: yaml node file
3
+ fail("Cannot find node facts #{file}.") unless File.exist?(file)
4
+ @node = YAML.load_file(file)
5
+ fail("Invalid node file #{file}, this should come from " +
6
+ "/var/lib/puppet/yaml/node.") unless @node.is_a?(Puppet::Node)
7
+ end
8
+
9
+ Given /^I use storeconfigs$/ do
10
+ # XXX workaround storeconfig warnings
11
+ Puppet::Util::Log.level = :err
12
+ end
13
+
14
+ When /^I compile its catalog$/ do
15
+ compile_catalog(@node)
16
+ end
17
+
18
+ Then /^all resource dependencies should resolve$/ do
19
+ steps %Q{
20
+ Then all "before" should resolve
21
+ And all "notify" should resolve
22
+ And all "require" should resolve
23
+ And all "subscribe" should resolve
24
+ }
25
+ end
26
+
27
+ Then /^all "(before|notify|require|subscribe)" should resolve$/ do |parameter|
28
+ catalog_resources.each do |resource|
29
+ dependency = [ resource[parameter] ].flatten.compact
30
+
31
+ dependency.each do |dep|
32
+ fail("#{resource} cannot #{parameter} #{dep}, not in catalog.") \
33
+ unless resource(dep.to_s)
34
+ end
35
+ end
36
+ end
37
+
38
+ Then /^compilation should succeed$/ do
39
+ fail("Catalog compilation failed.") unless
40
+ @catalog.is_a?(Puppet::Resource::Catalog)
41
+ end
@@ -0,0 +1,14 @@
1
+ Feature: General policy for all catalogs
2
+ In order to ensure applicability of a host's catalog
3
+ As a manifest developer
4
+ I want all catalogs to obey some general rules
5
+
6
+ Scenario Outline: Compile and verify catalog
7
+ Given a node specified by "features/yaml/<hostname>.example.com.yaml"
8
+ When I compile its catalog
9
+ Then compilation should succeed
10
+ And all resource dependencies should resolve
11
+
12
+ Examples:
13
+ | hostname |
14
+ | localhost |
@@ -1,6 +1,7 @@
1
1
  Before do
2
2
  # local configuration
3
- @confdir = File.dirname(__FILE__) + "/../../"
3
+ # @confdir = File.join(File.dirname(__FILE__), '..', '..')
4
+ # @manifest = File.join(@confdir, 'manifests', 'site.pp')
4
5
  # adjust facts like this
5
6
  @facts['architecture'] = "i386"
6
7
  end
@@ -9,6 +9,7 @@ if version
9
9
  end
10
10
  %>
11
11
  require 'cucumber-puppet/puppet'
12
+ require 'cucumber-puppet/steps'
12
13
 
13
14
  World do
14
15
  CucumberPuppet.new
@@ -1,7 +1,7 @@
1
1
  .\" generated with Ronn/v0.7.3
2
2
  .\" http://github.com/rtomayko/ronn/tree/0.7.3
3
3
  .
4
- .TH "CUCUMBER\-PUPPET\-GEN" "1" "August 2010" "" ""
4
+ .TH "CUCUMBER\-PUPPET\-GEN" "1" "September 2010" "" ""
5
5
  .
6
6
  .SH "NAME"
7
7
  \fBcucumber\-puppet\-gen\fR \- Generator script for cucumber\-puppet
@@ -69,7 +69,7 @@ $ cucumber\-puppet\-gen feature foo bar
69
69
  .IP "" 0
70
70
  .
71
71
  .SH "REPORTING BUGS"
72
- Report bugs to \fIcucumber\-puppet@erisiandiscord\.de\fR or go to http://github\.com/nistude/cucumber\-puppet/issues
72
+ Please report any bugs at http://projects\.puppetlabs\.com/projects/cucumber\-puppet/issues/new or send an email to \fIcucumber\-puppet@erisiandiscord\.de\fR\.
73
73
  .
74
74
  .SH "COPYRIGHT"
75
75
  \fBcucumber\-puppet\fR is Copyright (c) 2010 Nikolay Sturm \fIsturm@nistu\.de\fR
@@ -1,16 +1,16 @@
1
1
  .\" generated with Ronn/v0.7.3
2
2
  .\" http://github.com/rtomayko/ronn/tree/0.7.3
3
3
  .
4
- .TH "CUCUMBER\-PUPPET" "1" "August 2010" "" ""
4
+ .TH "CUCUMBER\-PUPPET" "1" "September 2010" "" ""
5
5
  .
6
6
  .SH "NAME"
7
- \fBcucumber\-puppet\fR \- Puppet manifest testing with Cucumber
7
+ \fBcucumber\-puppet\fR \- Puppet catalog testing with Cucumber
8
8
  .
9
9
  .SH "SYNOPSIS"
10
10
  \fBcucumber\-puppet\fR [ OPTIONS ] FILE | DIR \.\.\.
11
11
  .
12
12
  .SH "DESCRIPTION"
13
- \fBcucumber\-puppet\fR is a tool for behavioral testing of Puppet manifests\. It provides the glue necessary to access Puppet\'s data structures from Cucumber\'s step definitions\.
13
+ \fBcucumber\-puppet\fR is a tool for behavioral testing of Puppet catalogs\. It provides the glue necessary to access Puppet\'s data structures from Cucumber\'s step definitions\.
14
14
  .
15
15
  .P
16
16
  \fBcucumber\-puppet\fR takes a list of feature files or directories, containing feature files, as argument\. These will then be run through \fBcucumber\fR\. It needs to be started from somewhere inside the Puppet directory tree\.
@@ -119,7 +119,7 @@ $ cucumber\-puppet features/modules/foo/bar\.feature
119
119
  .IP "" 0
120
120
  .
121
121
  .SH "REPORTING BUGS"
122
- Report bugs to \fIcucumber\-puppet@erisiandiscord\.de\fR or go to http://github\.com/nistude/cucumber\-puppet/issues
122
+ Please report any bugs at http://projects\.puppetlabs\.com/projects/cucumber\-puppet/issues/new or send an email to \fIcucumber\-puppet@erisiandiscord\.de\fR\.
123
123
  .
124
124
  .SH "COPYRIGHT"
125
125
  \fBcucumber\-puppet\fR is Copyright (c) 2010 Nikolay Sturm \fIsturm@nistu\.de\fR
metadata CHANGED
@@ -1,7 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cucumber-puppet
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ hash: 27
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 0
10
+ version: 0.1.0
5
11
  platform: ruby
6
12
  authors:
7
13
  - Nikolay Sturm
@@ -9,40 +15,57 @@ autorequire:
9
15
  bindir: bin
10
16
  cert_chain: []
11
17
 
12
- date: 2010-08-23 00:00:00 +02:00
18
+ date: 2010-10-20 00:00:00 +02:00
13
19
  default_executable:
14
20
  dependencies:
15
21
  - !ruby/object:Gem::Dependency
16
22
  name: cucumber
17
- type: :runtime
18
- version_requirement:
19
- version_requirements: !ruby/object:Gem::Requirement
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
20
26
  requirements:
21
27
  - - ">="
22
28
  - !ruby/object:Gem::Version
29
+ hash: 15
30
+ segments:
31
+ - 0
32
+ - 6
33
+ - 4
23
34
  version: 0.6.4
24
- version:
35
+ type: :runtime
36
+ version_requirements: *id001
25
37
  - !ruby/object:Gem::Dependency
26
38
  name: gem-man
27
- type: :runtime
28
- version_requirement:
29
- version_requirements: !ruby/object:Gem::Requirement
39
+ prerelease: false
40
+ requirement: &id002 !ruby/object:Gem::Requirement
41
+ none: false
30
42
  requirements:
31
43
  - - ">="
32
44
  - !ruby/object:Gem::Version
45
+ hash: 23
46
+ segments:
47
+ - 0
48
+ - 2
49
+ - 0
33
50
  version: 0.2.0
34
- version:
51
+ type: :runtime
52
+ version_requirements: *id002
35
53
  - !ruby/object:Gem::Dependency
36
54
  name: templater
37
- type: :runtime
38
- version_requirement:
39
- version_requirements: !ruby/object:Gem::Requirement
55
+ prerelease: false
56
+ requirement: &id003 !ruby/object:Gem::Requirement
57
+ none: false
40
58
  requirements:
41
59
  - - ">="
42
60
  - !ruby/object:Gem::Version
61
+ hash: 15
62
+ segments:
63
+ - 1
64
+ - 0
43
65
  version: "1.0"
44
- version:
45
- description: cucumber-puppet is a tool for behavioral testing of Puppet manifests
66
+ type: :runtime
67
+ version_requirements: *id003
68
+ description: cucumber-puppet is a tool for behavioral testing of Puppet catalogs
46
69
  email: cucumber-puppet@erisiandiscord.de
47
70
  executables:
48
71
  - cucumber-puppet
@@ -57,13 +80,14 @@ files:
57
80
  - lib/cucumber-puppet.rb
58
81
  - lib/cucumber-puppet/helper.rb
59
82
  - lib/cucumber-puppet/puppet.rb
83
+ - lib/cucumber-puppet/steps.rb
60
84
  - lib/cucumber-puppet/rake/task.rb
61
85
  - lib/generators/feature/%feature_name%.feature
86
+ - lib/generators/policy/catalog/policy.feature
62
87
  - man/cucumber-puppet.1
63
88
  - man/cucumber-puppet-gen.1
64
89
  - VERSION.yml
65
90
  - lib/generators/world/steps/package.rb
66
- - lib/generators/world/steps/catalog_specs.rb
67
91
  - lib/generators/world/steps/exec.rb
68
92
  - lib/generators/world/steps/user.rb
69
93
  - lib/generators/world/steps/file.rb
@@ -73,7 +97,7 @@ files:
73
97
  - lib/generators/world/support/hooks.rb
74
98
  - lib/generators/world/support/world.rb
75
99
  has_rdoc: true
76
- homepage: http://github.com/nistude/cucumber-puppet/
100
+ homepage: http://projects.puppetlabs.com/projects/cucumber-puppet
77
101
  licenses: []
78
102
 
79
103
  post_install_message:
@@ -82,23 +106,29 @@ rdoc_options: []
82
106
  require_paths:
83
107
  - lib
84
108
  required_ruby_version: !ruby/object:Gem::Requirement
109
+ none: false
85
110
  requirements:
86
111
  - - ">="
87
112
  - !ruby/object:Gem::Version
113
+ hash: 3
114
+ segments:
115
+ - 0
88
116
  version: "0"
89
- version:
90
117
  required_rubygems_version: !ruby/object:Gem::Requirement
118
+ none: false
91
119
  requirements:
92
120
  - - ">="
93
121
  - !ruby/object:Gem::Version
122
+ hash: 3
123
+ segments:
124
+ - 0
94
125
  version: "0"
95
- version:
96
126
  requirements: []
97
127
 
98
128
  rubyforge_project:
99
- rubygems_version: 1.3.5
129
+ rubygems_version: 1.3.7
100
130
  signing_key:
101
131
  specification_version: 3
102
- summary: Puppet manifest testing with Cucumber
132
+ summary: Puppet catalog testing with Cucumber
103
133
  test_files: []
104
134
 
@@ -1,67 +0,0 @@
1
- Given /^a node specified by "([^\"]*)"$/ do |file|
2
- # file: yaml node file, usually from /var/lib/puppet/yaml/node
3
- fail("Cannot find node facts #{file}.") unless File.exist?(file)
4
- @node = YAML.load_file(file)
5
- file("Invalid node file #{file}, this should come from " +
6
- "/var/lib/puppet/yaml/node.") unless @node.is_a?(Puppet::Node)
7
- end
8
-
9
- When /^I compile its catalog$/ do
10
- compile_catalog(@node)
11
- end
12
-
13
- Then /^all "([^\"]*)" should resolve$/ do |parameter|
14
- # paramter: before, notify, require, or subscribe
15
- @catalog.resources.each do |name|
16
- resource = get_resource(name)
17
-
18
- dependency = resource[parameter]
19
- next unless dependency
20
- if dependency.is_a?(Array)
21
- dependency.each do |dep|
22
- fail("#{resource} cannot #{parameter} #{dep}, not in catalog.") \
23
- unless get_resource(dep.to_s)
24
- end
25
- elsif dependency.is_a?(Puppet::Resource::Reference)
26
- fail("#{resource} cannot #{parameter} #{dependency}, not in catalog.") \
27
- unless get_resource(dependency.to_s)
28
- else
29
- fail("#{resource} #{parameter} #{dependency} of unknown class.")
30
- end
31
- end
32
- end
33
-
34
- Then /^all file sources should exist in git repository$/ do
35
- @catalog.resources.each do |name|
36
- next unless name.match(/^File/)
37
- file = get_resource(name)
38
-
39
- next unless file['source']
40
- source = file['source']
41
-
42
- filepath = source.gsub(%r{^puppet:///([^/]*)/(.*)$}, 'modules/\1/files/\2')
43
- fail("#{name}: source #{filepath} not in git repository.") unless
44
- system("git cat-file -e :#{filepath} > /dev/null 2>&1")
45
- end
46
- end
47
-
48
- Then /^all file templates should exist in git repository$/ do
49
- Dir.glob('modules/*/templates/**.erb').each do |template|
50
- fail("#{template} not in git.") unless
51
- system("git cat-file -e :#{template} > /dev/null 2>&1")
52
- end
53
- end
54
-
55
- Then /^all resource dependencies should resolve$/ do
56
- steps %Q{
57
- Then all "before" should resolve
58
- And all "notify" should resolve
59
- And all "require" should resolve
60
- And all "subscribe" should resolve
61
- }
62
- end
63
-
64
- Then /^compilation should succeed$/ do
65
- fail("Catalog compilation failed.") unless
66
- @catalog.is_a?(Puppet::Resource::Catalog)
67
- end