rspec-system 2.3.0 → 2.4.0

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.md CHANGED
@@ -1,3 +1,22 @@
1
+ 2.4.0
2
+ =====
3
+
4
+ This feature release contains a number of new features:
5
+
6
+ * We now have an 'options' parameter for a node definition which allows customisation of the ip address, number of CPUs and amount of memory for a node. Currently this is only accepted for the Vagrant/Virtualbox provider.
7
+ * Dynamic loading of node_set plugins is now provided. This drops the requirement for having to 'require' the plugin to load it.
8
+
9
+ #### Detailed Changes
10
+
11
+ * (GH-44) Add 'options' parameter to node definition (Justen Walker)
12
+ * (GH-44) Support custom options for Vagrantfiles (Justen Walker)
13
+ * Fix wrong reference in README. (Stefano Zanella)
14
+ * Fix typo in example test code. (Stefano Zanella)
15
+ * Add 'ip' option to the 'options' parameter for node definitions (Trey Dockendorf)
16
+ * Add a simple plugin loading system for node_set plugins (Erik Dalén)
17
+
18
+ -------------------------------
19
+
1
20
  2.3.0
2
21
  =====
3
22
 
data/README.md CHANGED
@@ -18,7 +18,7 @@ For writing tests it uses the [rspec](https://www.relishapp.com/rspec) testing f
18
18
 
19
19
  #### Can this tool be used to test Puppet?
20
20
 
21
- Yes it can. Check out the plugin: [rspec-system-serverspec](http://rubygems.org/gems/rspec-system-serverspec).
21
+ Yes it can. Check out the plugin: [rspec-system-puppet](http://rubygems.org/gems/rspec-system-puppet).
22
22
 
23
23
  #### How does this tool overlap with serverspec?
24
24
 
@@ -73,7 +73,7 @@ An example file would look like this:
73
73
  its(:exit_code) { should be_zero }
74
74
  end
75
75
 
76
- it 'should cat /etc/resolv.conf' do
76
+ it 'should cat /etc/hosts' do
77
77
  # Here we run the shell command as a helper
78
78
  shell 'cat /etc/hosts' do |r|
79
79
  r.stdout.should =~ /localhost/
@@ -140,6 +140,38 @@ An example using the `shell` helper:
140
140
 
141
141
  This would execute the command `hostname` on node `second.mydomain.vm`.
142
142
 
143
+ ### Custom node options
144
+
145
+ By default, `rspec-system` launches nodes with the settings that were baked into the prefab. This means that your node's physical properties like RAM and vCPU count depend on the prefab selected. If you need to customize these values, `rspec-system` provides node-level customization in `.nodeset.yml` under `options`.
146
+
147
+ Currently supported options are:
148
+
149
+ * *ip:* additional IP address
150
+ * *cpus:* number of virtual cpus
151
+ * *memory:* memory in MB
152
+
153
+ Example:
154
+
155
+ ---
156
+ sets:
157
+ 'centos-59-x64-multinode':
158
+ nodes:
159
+ default_node: 'first.mydomain.vm':
160
+ 'first.mydomain.vm':
161
+ prefab: 'centos-59-x64'
162
+ options:
163
+ ip: '192.168.1.2'
164
+ cpus: 2
165
+ memory: 1024 #mb
166
+ 'second.mydomain.vm':
167
+ prefab: 'centos-59-x64'
168
+ options:
169
+ ip: '192.168.1.3'
170
+ cpus: 1
171
+ memory: 512 #mb
172
+
173
+ *Note:* These options are currently only supported on Vagrant + VirtualBox. On other providers they are ignored.
174
+
143
175
  ### Prefabs
144
176
 
145
177
  Prefabs are 'pre-rolled' virtual images, for now its the only way to specify a template.
@@ -18,7 +18,8 @@ module RSpecSystem
18
18
  :nodeset => nodeset,
19
19
  :custom_prefabs_path => custom_prefabs_path,
20
20
  :name => k,
21
- :prefab => v['prefab']
21
+ :prefab => v['prefab'],
22
+ :options => v['options']
22
23
  )
23
24
  end
24
25
 
@@ -27,6 +28,7 @@ module RSpecSystem
27
28
  # @param options [Hash] options for new node
28
29
  # @option options [String] :name name of node. Mandatory.
29
30
  # @option options [String] :prefab prefab setting. Mandatory.
31
+ # @option options [String] :options options setting. Optional.
30
32
  # @option options [RSpecSystem::NodeSet] :nodeset the parent nodeset for
31
33
  # this node. Mandatory.
32
34
  # @option options [String] :custom_prefabs_path path of custom prefabs
@@ -34,6 +36,7 @@ module RSpecSystem
34
36
  def initialize(options)
35
37
  @name = options[:name]
36
38
  prefab = options[:prefab]
39
+ @options = options[:options]
37
40
  @nodeset = options[:nodeset]
38
41
  @custom_prefabs_path = options[:custom_prefabs_path]
39
42
 
@@ -61,6 +64,13 @@ module RSpecSystem
61
64
  @prefab
62
65
  end
63
66
 
67
+ # Returns the custom object for this node (if any).
68
+ #
69
+ # @return [Hash] the options object used to customize the node
70
+ def options
71
+ @options
72
+ end
73
+
64
74
  # Retreives facts from the nodeset definition or prefab.
65
75
  #
66
76
  # @return [Hash] returns a hash of facter facts defined for this node
@@ -6,18 +6,12 @@ module RSpecSystem
6
6
  # @return [RSpecSystem::NodeSet::Base] returns an object based on the Base
7
7
  # abstract class.
8
8
  def self.create(setname, config, virtual_env, custom_prefabs_path, options)
9
- case(virtual_env)
10
- when 'vagrant'
11
- RSpecSystem::NodeSet::Vagrant.new(setname, config, custom_prefabs_path, options)
12
- when 'vsphere'
13
- RSpecSystem::NodeSet::Vsphere.new(setname, config, custom_prefabs_path, options)
14
- else
15
- raise "Unsupported virtual environment #{virtual_env}"
9
+ begin
10
+ require "rspec-system/node_set/#{virtual_env.downcase}"
11
+ rescue LoadError => e
12
+ raise "Unsupported virtual environment #{virtual_env}: #{e}"
16
13
  end
14
+ const_get(virtual_env.capitalize).new(setname, config, custom_prefabs_path, options)
17
15
  end
18
16
  end
19
17
  end
20
-
21
- require 'rspec-system/node_set/base'
22
- require 'rspec-system/node_set/vagrant'
23
- require 'rspec-system/node_set/vsphere'
@@ -1,6 +1,8 @@
1
1
  require 'fileutils'
2
2
  require 'systemu'
3
3
  require 'net/ssh'
4
+ require 'net/scp'
5
+ require 'rspec-system/node_set/base'
4
6
 
5
7
  module RSpecSystem
6
8
  # A NodeSet implementation for Vagrant.
@@ -9,6 +11,7 @@ module RSpecSystem
9
11
  include RSpecSystem::Util
10
12
 
11
13
  ENV_TYPE = 'vagrant'
14
+ VALID_VM_OPTIONS = ['ip']
12
15
 
13
16
  # Creates a new instance of RSpecSystem::NodeSet::Vagrant
14
17
  #
@@ -119,13 +122,16 @@ module RSpecSystem
119
122
  f.write('Vagrant.configure("2") do |c|' + "\n")
120
123
  nodes.each do |k,v|
121
124
  ps = v.provider_specifics['vagrant']
125
+ default_options = { 'mac' => randmac }
126
+ options = default_options.merge(v.options || {})
122
127
 
123
128
  node_config = " c.vm.define '#{k}' do |v|\n"
124
129
  node_config << " v.vm.hostname = '#{k}'\n"
125
130
  node_config << " v.vm.box = '#{ps['box']}'\n"
126
131
  node_config << " v.vm.box_url = '#{ps['box_url']}'\n" unless ps['box_url'].nil?
132
+ node_config << customize_vm(k,options)
127
133
  node_config << " v.vm.provider 'virtualbox' do |vbox|\n"
128
- node_config << " vbox.customize ['modifyvm',:id,'--macaddress1','#{randmac}']\n"
134
+ node_config << customize_virtualbox(k,options)
129
135
  node_config << " end\n"
130
136
  node_config << " end\n"
131
137
 
@@ -136,6 +142,47 @@ module RSpecSystem
136
142
  nil
137
143
  end
138
144
 
145
+ # Adds virtualbox customization to the Vagrantfile
146
+ #
147
+ # @api private
148
+ # @param name [String] name of the node
149
+ # @param options [Hash] customization options
150
+ # @return [String] a series of vbox.customize lines
151
+ def customize_virtualbox(name,options)
152
+ custom_config = ""
153
+ options.each_pair do |key,value|
154
+ next if VALID_VM_OPTIONS.include?(key)
155
+ case key
156
+ when 'cpus','memory'
157
+ custom_config << " vbox.customize ['modifyvm', :id, '--#{key}','#{value}']\n"
158
+ when 'mac'
159
+ custom_config << " vbox.customize ['modifyvm', :id, '--macaddress1','#{value}']\n"
160
+ else
161
+ log.warn("Skipped invalid custom option for node #{name}: #{key}=#{value}")
162
+ end
163
+ end
164
+ custom_config
165
+ end
166
+
167
+ # Adds VM customization to the Vagrantfile
168
+ #
169
+ # @api private
170
+ # @param name [String] name of the node
171
+ # @param options [Hash] customization options
172
+ # @return [String] a series of v.vm lines
173
+ def customize_vm(name,options)
174
+ vm_config = ""
175
+ options.each_pair do |key,value|
176
+ case key
177
+ when 'ip'
178
+ vm_config << " v.vm.network :private_network, :ip => '#{value}'\n"
179
+ else
180
+ next
181
+ end
182
+ end
183
+ vm_config
184
+ end
185
+
139
186
  # Here we get vagrant to drop the ssh_config its using so we can monopolize
140
187
  # it for transfers and custom stuff. We drop it into a single file, and
141
188
  # since its indexed based on our own node names its quite ideal.
@@ -3,6 +3,7 @@ require 'systemu'
3
3
  require 'net/ssh'
4
4
  require 'net/scp'
5
5
  require 'rbvmomi'
6
+ require 'rspec-system/node_set/base'
6
7
 
7
8
  module RSpecSystem
8
9
  # A NodeSet implementation for VSphere
@@ -15,4 +15,10 @@ mapping:
15
15
  type: map
16
16
  mapping:
17
17
  prefab: { type: str }
18
+ options:
19
+ type: map
20
+ mapping:
21
+ ip: { type: str }
22
+ memory: { type: int }
23
+ cpus: { type: int }
18
24
  role: { type: str }
data/rspec-system.gemspec CHANGED
@@ -2,7 +2,7 @@
2
2
  Gem::Specification.new do |s|
3
3
  # Metadata
4
4
  s.name = "rspec-system"
5
- s.version = "2.3.0"
5
+ s.version = "2.4.0"
6
6
  s.authors = ["Ken Barber"]
7
7
  s.email = ["info@puppetlabs.com"]
8
8
  s.homepage = "https://github.com/puppetlabs/rspec-system"
@@ -0,0 +1,15 @@
1
+ ---
2
+ default_set: 'centos-58-x64'
3
+ sets:
4
+ 'centos-58-x64':
5
+ nodes:
6
+ "master":
7
+ prefab: 'centos-58-x64'
8
+ options:
9
+ cpus: 2
10
+ memory: 4096 #mb
11
+ "agent":
12
+ prefab: 'centos-58-x64'
13
+ options:
14
+ cpus: 1
15
+ memory: 768 #mb
@@ -0,0 +1,17 @@
1
+ ---
2
+ default_set: 'centos-58-x64'
3
+ sets:
4
+ 'centos-58-x64':
5
+ nodes:
6
+ "master":
7
+ prefab: 'centos-58-x64'
8
+ options:
9
+ ip: '192.168.1.2'
10
+ cpus: 2
11
+ memory: 4096 #mb
12
+ "agent":
13
+ prefab: 'centos-58-x64'
14
+ options:
15
+ ip: '192.168.1.3'
16
+ cpus: 1
17
+ memory: 768 #mb
@@ -0,0 +1,13 @@
1
+ ---
2
+ default_set: 'centos-58-x64'
3
+ sets:
4
+ 'centos-58-x64':
5
+ nodes:
6
+ "master":
7
+ prefab: 'centos-58-x64'
8
+ options:
9
+ ip: '192.168.1.2'
10
+ "agent":
11
+ prefab: 'centos-58-x64'
12
+ options:
13
+ ip: '192.168.1.3'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rspec-system
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.3.0
4
+ version: 2.4.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-09-19 00:00:00.000000000 Z
12
+ date: 2013-10-19 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
@@ -174,6 +174,9 @@ files:
174
174
  - spec/fixtures/example_dir/example_file
175
175
  - spec/fixtures/nodeset_example1.yml
176
176
  - spec/fixtures/nodeset_example2.yml
177
+ - spec/fixtures/nodeset_example3.yml
178
+ - spec/fixtures/nodeset_example4.yml
179
+ - spec/fixtures/nodeset_example5.yml
177
180
  - spec/spec_helper.rb
178
181
  - spec/spec_helper_system.rb
179
182
  - spec/system/rcp_spec.rb