bugfix & cleanup of the vm loading and a speedup / bugfix for the regex lib

git-svn-id: file:///home/svn/framework3/trunk@12032 4d416f70-5f16-0410-b530-b9f4589650da
unstable
Jonathan Cran 2011-03-20 02:33:39 +00:00
parent ea274d1537
commit d45b2aaa20
2 changed files with 28 additions and 24 deletions

View File

@ -32,25 +32,13 @@ module Controllers
def initialize (labdef = nil)
@vms = [] ## Start with an empty array of vms
## labdef is a big array of hashes (vms) - generally loaded from yaml
if !labdef
labdef = [] ## Just use a blank lab to start
else
labdef = labdef
end
## labdef is a big array of hashes, use yaml to store
labdef = [] unless labdef
## Create vm objects from the lab definition
labdef.each do |item|
begin
@vms << Vm.new(item)
rescue Exception => e
puts "Invalid VM definition"
end
end
load_vms(labdef)
end
def clear!
@ -85,17 +73,22 @@ module Controllers
def from_file(file)
labdef = YAML::load_file(file)
load_vms(labdef)
end
labdef.each do |item|
#puts "Lab item: " + item.inspect
@vms << Vm.new(item)
def load_vms(vms)
vms.each do |item|
begin
vm = Vm.new(item)
@vms << vm unless includes_vmid? vm.vmid
rescue Exception => e
puts "Invalid VM definition"
end
end
end
def to_file(file)
File.open(file, 'w') do |f|
@vms.each { |vm| f.puts vm.to_yaml }
end
File.open(file, 'w') { |f| @vms.each { |vm| f.puts vm.to_yaml } }
end
def each &block
@ -107,7 +100,10 @@ module Controllers
end
def includes_vmid?(vmid)
@vms.each { |vm| if (vm.vmid.to_s == vmid.to_s) then return true end }
@vms.each do |vm|
return true if (vm.vmid == vmid)
end
return false
end
def build_from_dir(type, dir, clear=false)

View File

@ -13,9 +13,12 @@ class Regexr
# Check for the beginning and end lines. Handy when you need to ensure a log has started & completed
def verify_start_and_end(data,the_start,the_end)
return false unless data
data_lines = data.split("\n")
regex_start = Regexp.new(the_start, @case_insensitive)
regex_end = Regexp.new(the_end, @case_insensitive)
if regex_start =~ data_lines.first
return regex_end =~ data_lines.last
end
@ -25,6 +28,8 @@ class Regexr
# Scan for any number of success lines. In order to pass, all successes must match.
def find_strings_that_dont_exist_in_data(data,regexes=[])
return false unless data
data_lines = data.split("\n")
return nil unless regexes ## count as a pass
@ -60,6 +65,9 @@ class Regexr
# Scan for failures -- if any single failure matches, the test returns true.
def find_strings_that_exist_in_data_except(data,regexes=[],exceptions=[])
return false unless data
data_lines = data.split("\n")
return nil unless regexes ## count as a pass