rspec-system-puppet 0.3.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
data/.nodeset.yml CHANGED
@@ -3,29 +3,29 @@ default_set: 'centos-64-x64'
3
3
  sets:
4
4
  'centos-59-x64':
5
5
  nodes:
6
- "main":
6
+ "main.foo.vm":
7
7
  prefab: 'centos-59-x64'
8
8
  'centos-64-x64':
9
9
  nodes:
10
- "main":
10
+ "main.foo.vm":
11
11
  prefab: 'centos-64-x64'
12
12
  'fedora-18-x64':
13
13
  nodes:
14
- "main":
14
+ "main.foo.vm":
15
15
  prefab: 'fedora-18-x64'
16
16
  'debian-607-x64':
17
17
  nodes:
18
- "main":
18
+ "main.foo.vm":
19
19
  prefab: 'debian-607-x64'
20
20
  'debian-70rc1-x64':
21
21
  nodes:
22
- "main":
22
+ "main.foo.vm":
23
23
  prefab: 'debian-70rc1-x64'
24
24
  'ubuntu-server-10044-x64':
25
25
  nodes:
26
- "main":
26
+ "main.foo.vm":
27
27
  prefab: 'ubuntu-server-10044-x64'
28
28
  'ubuntu-server-12042-x64':
29
29
  nodes:
30
- "main":
30
+ "main.foo.vm":
31
31
  prefab: 'ubuntu-server-12042-x64'
@@ -5,7 +5,9 @@ module RSpecSystemPuppet::Helpers
5
5
  include RSpecSystem::Log
6
6
 
7
7
  # Basic helper to install puppet
8
- def puppet_install(options = {})
8
+ #
9
+ # @param opts [Hash] a hash of opts
10
+ def puppet_install(opts = {})
9
11
  # Grab facts from node
10
12
  facts = system_node.facts
11
13
 
@@ -43,17 +45,19 @@ module RSpecSystemPuppet::Helpers
43
45
  end
44
46
 
45
47
  # Helper to copy a module onto a node from source
46
- def puppet_module_install(options)
48
+ #
49
+ # @param opts [Hash] a hash of opts
50
+ def puppet_module_install(opts)
47
51
  # Defaults etc.
48
- options = {
52
+ opts = {
49
53
  :node => rspec_system_node_set.default_node,
50
54
  :module_path => "/etc/puppet/modules",
51
- }.merge(options)
55
+ }.merge(opts)
52
56
 
53
- source = options[:source]
54
- module_name = options[:module_name]
55
- module_path = options[:module_path]
56
- node = options[:node]
57
+ source = opts[:source]
58
+ module_name = opts[:module_name]
59
+ module_path = opts[:module_path]
60
+ node = opts[:node]
57
61
 
58
62
  raise "Must provide :source and :module_name parameters" unless source && module_name
59
63
 
@@ -62,6 +66,8 @@ module RSpecSystemPuppet::Helpers
62
66
  end
63
67
 
64
68
  # Runs puppet resource commands
69
+ #
70
+ # @param opts [Hash] a hash of opts
65
71
  def puppet_resource(opts)
66
72
  if opts.is_a?(String)
67
73
  opts = {:resource => opts}
@@ -86,4 +92,62 @@ module RSpecSystemPuppet::Helpers
86
92
  result
87
93
  end
88
94
  end
95
+
96
+ # Run puppet DSL code directly with `puppet apply`.
97
+ #
98
+ # This takes a string of PuppetDSL code, uploads it to the test server and
99
+ # executes it directly with `puppet apply`.
100
+ #
101
+ # @param opts [Hash, String] a hash of opts, or a string containing the
102
+ # code to execute with option defaults
103
+ # @option opts [String] :code the Puppet DSL code to execute
104
+ # @option opts [RSpecSystem::Node] :node node to execute DSL on
105
+ # @return [Hash] a hash of results
106
+ # @yield [result] yields result when called as a block
107
+ # @yieldparam result [Hash] a hash containing :exit_code, :stdout and :stderr
108
+ # @example
109
+ # it "run notice" do
110
+ # puppet_apply("notice('foo')") do |r|
111
+ # r[:stdout].should =~ /foo/
112
+ # end
113
+ # end
114
+ # @todo Support for custom switches perhaps?
115
+ # @todo The destination path is static, need a good remote random path
116
+ # generator
117
+ def puppet_apply(opts)
118
+ if opts.is_a?(String)
119
+ opts = {:code => opts}
120
+ end
121
+
122
+ # Defaults
123
+ opts = {
124
+ :node => rspec_system_node_set.default_node
125
+ }.merge(opts)
126
+
127
+ code = opts[:code]
128
+ node = opts[:node]
129
+
130
+ raise 'Must provide code' unless code
131
+
132
+ log.info("Copying DSL to remote host")
133
+ file = Tempfile.new('rsp_puppet_apply')
134
+ file.write(code)
135
+ file.close
136
+
137
+ remote_path = '/tmp/puppetapply.' + rand(1000000000).to_s
138
+ r = system_rcp(:sp => file.path, :dp => remote_path, :d => node)
139
+ file.unlink
140
+
141
+ log.info("Cat file to see contents")
142
+ system_run(:n => node, :c => "cat #{remote_path}")
143
+
144
+ log.info("Now running puppet apply")
145
+ result = system_run(:n => node, :c => "puppet apply --detailed-exitcodes #{remote_path}")
146
+
147
+ if block_given?
148
+ yield(result)
149
+ else
150
+ result
151
+ end
152
+ end
89
153
  end
@@ -2,7 +2,7 @@
2
2
  Gem::Specification.new do |s|
3
3
  # Metadata
4
4
  s.name = "rspec-system-puppet"
5
- s.version = "0.3.0"
5
+ s.version = "0.3.1"
6
6
  s.authors = ["Ken Barber"]
7
7
  s.email = ["ken@bob.sh"]
8
8
  s.homepage = "https://github.com/kbarber/rspec-system-puppet"
@@ -5,10 +5,34 @@ describe "basic tests:" do
5
5
  puppet_install()
6
6
  end
7
7
 
8
+ it 'facter domain should return something valid' do
9
+ system_run("facter domain") do |r|
10
+ r[:stdout].should =~ /[a-z]+/
11
+ r[:stderr].should == ''
12
+ r[:exit_code].should == 0
13
+ end
14
+ end
15
+
16
+ it 'facter fqdn should return something valid' do
17
+ system_run("facter fqdn") do |r|
18
+ r[:stdout].should =~ /vm/
19
+ r[:stderr].should == ''
20
+ r[:exit_code].should == 0
21
+ end
22
+ end
23
+
8
24
  it 'check puppet_resource returns an exit code of 0' do
9
25
  puppet_resource('user') do |r|
26
+ r[:stderr].should == ''
10
27
  r[:exit_code].should == 0
28
+ end
29
+ end
30
+
31
+ it 'check puppet apply with just a notice' do
32
+ puppet_apply('notice("foo")') do |r|
33
+ r[:stdout].should =~ /foo/
11
34
  r[:stderr].should == ''
35
+ r[:exit_code].should == 0
12
36
  end
13
37
  end
14
38
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rspec-system-puppet
3
3
  version: !ruby/object:Gem::Version
4
- hash: 19
4
+ hash: 17
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 3
9
- - 0
10
- version: 0.3.0
9
+ - 1
10
+ version: 0.3.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Ken Barber
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2013-04-11 00:00:00 Z
18
+ date: 2013-04-13 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: rspec-system