lib/testlab/providers/vagrant.rb in testlab-1.16.0 vs lib/testlab/providers/vagrant.rb in testlab-1.16.1
- old
+ new
@@ -47,31 +47,35 @@
true
end
# Destroy Vagrant-controlled VM
def destroy
+ @state = nil
self.alive? and self.down
+
+ @state = nil
self.exists? and self.vagrant_cli("destroy", "--force", self.instance_id)
true
end
################################################################################
# Online Vagrant-controlled VM
def up
+ @state = nil
self.vagrant_cli("up", self.instance_id)
ZTK::TCPSocketCheck.new(:host => self.ip, :port => self.port, :wait => 120, :ui => @ui).wait
true
end
# Halt Vagrant-controlled VM
def down(*args)
+ @state = nil
arguments = (%W(halt #{self.instance_id}) + args).flatten.compact
-
self.vagrant_cli(*arguments)
true
end
@@ -149,18 +153,21 @@
################################################################################
# Inquire the state of the Vagrant-controlled VM
def state
- output = self.vagrant_cli("status").output.split("\n").select{ |line| (line =~ /#{self.instance_id}/) }.first
- result = UNKNOWN_STATE
- ALL_STATES.map{ |s| s.to_s.gsub('_', ' ') }.each do |state|
- if output =~ /#{state}/
- result = state.to_s.gsub(' ', '_')
- break
+ if @state.nil?
+ output = self.vagrant_cli("status").output.split("\n").select{ |line| (line =~ /#{self.instance_id}/) }.first
+ result = UNKNOWN_STATE
+ ALL_STATES.map{ |s| s.to_s.gsub('_', ' ') }.each do |state|
+ if output =~ /#{state}/
+ result = state.to_s.gsub(' ', '_')
+ break
+ end
end
+ @state = result.to_sym
end
- result.to_sym
+ @state
end
################################################################################
# Does the Vagrant-controlled VM exist?