rspec-system 1.2.1 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,8 @@
1
+ 1.3.0
2
+ =====
3
+
4
+ This release adds a new environment variable RSPEC_DESTROY, when set to false it stops the virtual machines from being destroyed. This is useful for debugging, so you can keep the virtual machine running and login after failures to dig deeper into the failed state if you so desire.
5
+
6
+ #### Detailed Changes
7
+
8
+ * Add an environment variale option, RSPEC_DESTROY. When set to 'no' or 'false' this prevents the VM from being destroy before and after a test. (Trey Dockendorf)
data/README.md CHANGED
@@ -124,6 +124,7 @@ Instead of switches, we use a number of environment variables to modify the beha
124
124
 
125
125
  * *RSPEC_VIRTUAL_ENV* - set this to `vagrant` if you wish, for now `vagrant` is the default so this is optional.
126
126
  * *RSPEC_SET* - the set to use when running tests (defaults to the `default_set` setting in the projects `.nodeset.yml` file). This string must align with the entries under `sets` in your `.nodeset.yml`.
127
+ * *RSPEC_DESTROY* - set this to `no` if you do not want the VM to be destroyed before or after a test completes. May be useful during initial testing of rspec tests to allow inspection of the VM.
127
128
 
128
129
  So if you wanted to run an alternate nodeset you could use:
129
130
 
@@ -141,6 +142,7 @@ This provider has a lot more options for setup, in the form of environment varia
141
142
 
142
143
  * *RSPEC_VIRTUAL_ENV* - set this to 'vsphere' to use this provider
143
144
  * *RSPEC_SET* - same as the vagrant provider, this defines the 'set' to launch.
145
+ * *RSPEC_DESTROY* - same as the vagrant provider, defines if the VM should be destroyed before and after a test.
144
146
  * *RSPEC_VSPHERE_HOST* - hostname of your vsphere api
145
147
  * *RSPEC_VSPHERE_USER* - username to authenticate with
146
148
  * *RSPEC_VSPHERE_PASS* - password to authenticate with
@@ -5,12 +5,12 @@ module RSpecSystem
5
5
  #
6
6
  # @return [RSpecSystem::NodeSet::Base] returns an object based on the Base
7
7
  # abstract class.
8
- def self.create(setname, config, virtual_env)
8
+ def self.create(setname, config, virtual_env, options)
9
9
  case(virtual_env)
10
10
  when 'vagrant'
11
- RSpecSystem::NodeSet::Vagrant.new(setname, config)
11
+ RSpecSystem::NodeSet::Vagrant.new(setname, config, options)
12
12
  when 'vsphere'
13
- RSpecSystem::NodeSet::Vsphere.new(setname, config)
13
+ RSpecSystem::NodeSet::Vsphere.new(setname, config, options)
14
14
  else
15
15
  raise "Unsupported virtual environment #{virtual_env}"
16
16
  end
@@ -7,11 +7,13 @@ module RSpecSystem
7
7
  attr_reader :config
8
8
  attr_reader :setname
9
9
  attr_reader :nodes
10
+ attr_reader :destroy
10
11
 
11
12
  # Create new NodeSet, populating necessary data structures.
12
- def initialize(setname, config)
13
+ def initialize(setname, config, options)
13
14
  @setname = setname
14
15
  @config = config
16
+ @destroy = options[:destroy]
15
17
 
16
18
  @nodes = {}
17
19
  config['nodes'].each do |k,v|
@@ -14,7 +14,8 @@ module RSpecSystem
14
14
  #
15
15
  # @param setname [String] name of the set to instantiate
16
16
  # @param config [Hash] nodeset configuration hash
17
- def initialize(setname, config)
17
+ # @param options [Hash] options Hash
18
+ def initialize(setname, config, options)
18
19
  super
19
20
  @vagrant_path = File.expand_path(File.join(RSpec.configuration.system_tmp, 'vagrant_projects', setname))
20
21
  end
@@ -53,8 +54,12 @@ module RSpecSystem
53
54
  v.close unless v.closed?
54
55
  end
55
56
 
56
- log.info "[Vagrant#teardown] Running 'vagrant destroy'"
57
- vagrant("destroy --force")
57
+ if destroy
58
+ log.info "[Vagrant#teardown] Running 'vagrant destroy'"
59
+ vagrant("destroy --force")
60
+ else
61
+ log.info "[Vagrant#teardown] Skipping 'vagrant destroy'"
62
+ end
58
63
  nil
59
64
  end
60
65
 
@@ -15,7 +15,8 @@ module RSpecSystem
15
15
  #
16
16
  # @param setname [String] name of the set to instantiate
17
17
  # @param config [Hash] nodeset configuration hash
18
- def initialize(setname, config)
18
+ # @param options [Hash] options Hash
19
+ def initialize(setname, config, options)
19
20
  super
20
21
  @vim = RbVmomi::VIM.connect(
21
22
  :host => ENV["RSPEC_VSPHERE_HOST"],
@@ -133,14 +134,19 @@ module RSpecSystem
133
134
  ssh = storage[:ssh]
134
135
  ssh.close unless ssh.closed?
135
136
 
136
- log.info "[Vsphere#teardown] destroy instance #{k}"
137
- vm = storage[:vm]
138
- if vm == nil
139
- puts "No vm object"
137
+ if destroy
138
+ log.info "[Vsphere#teardown] destroy instance #{k}"
139
+ vm = storage[:vm]
140
+ if vm == nil
141
+ puts "No vm object"
142
+ next
143
+ end
144
+ vm.PowerOffVM_Task.wait_for_completion
145
+ vm.Destroy_Task.wait_for_completion
146
+ else
147
+ log.info "[Vsphere#teardown] Skipping destroy instance #{k}"
140
148
  next
141
149
  end
142
- vm.PowerOffVM_Task.wait_for_completion
143
- vm.Destroy_Task.wait_for_completion
144
150
  end
145
151
 
146
152
  nil
@@ -31,10 +31,18 @@ RSpec.configure do |c|
31
31
  ENV["RSPEC_VIRTUAL_ENV"] || 'vagrant'
32
32
  end
33
33
 
34
+ # Defines if a set will be destroyed before and after tests
35
+ def rspec_destroy
36
+ return false if ENV["RSPEC_DESTROY"] =~ /(no|false)/
37
+ return true
38
+ end
39
+
34
40
  def rspec_system_node_set
35
41
  setname = ENV['RSPEC_SET'] || rspec_system_config['default_set']
36
42
  config = rspec_system_config['sets'][setname]
37
- RSpecSystem::NodeSet.create(setname, config, rspec_virtual_env)
43
+ options = {}
44
+ options[:destroy] = rspec_destroy
45
+ RSpecSystem::NodeSet.create(setname, config, rspec_virtual_env, options)
38
46
  end
39
47
 
40
48
  def start_nodes
@@ -45,6 +53,7 @@ RSpec.configure do |c|
45
53
  log.info "Configuration is: " + ns.config.pretty_inspect
46
54
  log.info "Virtual Environment type is: #{ns.env_type}"
47
55
  log.info "Default node is: #{ns.default_node.name}"
56
+ log.info "Destroy node is: #{ns.destroy}"
48
57
 
49
58
  ns.setup
50
59
  end
@@ -2,7 +2,7 @@
2
2
  Gem::Specification.new do |s|
3
3
  # Metadata
4
4
  s.name = "rspec-system"
5
- s.version = "1.2.1"
5
+ s.version = "1.3.0"
6
6
  s.authors = ["Ken Barber"]
7
7
  s.email = ["ken@bob.sh"]
8
8
  s.homepage = "https://github.com/puppetlabs/rspec-system"
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: 1.2.1
4
+ version: 1.3.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-05-23 00:00:00.000000000 Z
12
+ date: 2013-05-28 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
@@ -118,6 +118,7 @@ files:
118
118
  - .nodeset.yml
119
119
  - .ruby-version
120
120
  - .travis.yml
121
+ - CHANGELOG.md
121
122
  - Gemfile
122
123
  - LICENSE
123
124
  - README.md