Class: Houcho::Spec::Runner

Inherits:
Object
  • Object
show all
Defined in:
lib/houcho/spec/runner.rb

Instance Method Summary collapse

Constructor Details

#initializeRunner

Returns a new instance of Runner.



15
16
17
18
19
20
21
22
# File 'lib/houcho/spec/runner.rb', line 15

def initialize
  @role = Houcho::Role.new
  @host = Houcho::Host.new
  @spec = Houcho::Spec.new
  @outerrole = Houcho::OuterRole.new
  @specdir = Houcho::Config::SPECDIR
  @logger = Logger.new(Houcho::Config::SPECLOG, 10)
end

Instance Method Details

#check(spec, host_count, opt = {}) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/houcho/spec/runner.rb', line 25

def check(spec, host_count, opt = {})
  spec = spec.is_a?(Array) ? spec : [spec]
  role = spec.map { |s| @spec.details(s)[s]["role"] }.flatten
  host = []

  @role.details(role).each do |rolename, value|
    host.concat(value["host"]).uniq if value["host"]

    if value["outer role"]
      value["outer role"].each do |outerrolename, v|
        host.concat(v["host"]).uniq if v["host"]
      end
    end
  end

  execute_manually(
    host.sample(host_count), spec,
    dryrun: opt[:dryrun], console_output: opt[:console_output])
  # dry run for test
end

#execute_manually(host, spec, opt = {}) ⇒ Object



47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/houcho/spec/runner.rb', line 47

def execute_manually(host, spec, opt = {})
  host = host.is_a?(Array) ? host : [host]
  spec = spec.is_a?(Array) ? spec : [spec]

  run(
    { rand(36**50).to_s(36) => { "host" => host, "spec" => spec } },
    opt[:dryrun],
    false, # ci
    opt[:console_output],
    opt[:attr]
  )
end

#execute_role(role, ex_host = [], dryrun = false, console_output = false, attr = nil) ⇒ Object



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/houcho/spec/runner.rb', line 61

def execute_role(role, ex_host = [], dryrun = false, console_output = false, attr = nil)
  role = role.is_a?(Array) ? role : [role]
  ex_host = ex_host.is_a?(Array) ? ex_host : [ex_host]

  role_valiables = {}

  @role.details(role).each do |rolename, value|
    next unless value["spec"]

    rv = {}
    rv["host"] = []
    rv["spec"] = []

    rv["spec"].concat(value["spec"]).uniq
    rv["host"].concat(value["host"]).uniq if value["host"]

    if value["outer role"]
      value["outer role"].each do |outerrolename, v|
        rv["host"].concat(v["host"]).uniq if v["host"]
      end
    end

    rv["host"] = rv["host"] - ex_host
    role_valiables[rolename] = rv
  end

  run(role_valiables, dryrun, true, console_output, attr)
end