Module: MSpectator::ExampleGroup

Includes:
MCollective::RPC
Defined in:
lib/mspectator/example.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(group) ⇒ Object



11
12
13
14
15
# File 'lib/mspectator/example.rb', line 11

def self.included(group)
  group.before(:all) do
    @mc_clients ||= {}
  end
end

Instance Method Details

#apply_filters(mc, example) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/mspectator/example.rb', line 39

def apply_filters (mc, example)
  classes = example.[:classes] || []
  facts = example.[:facts] || {}
  mc.compound_filter example.example_group.top_level_description
  unless classes.empty? and facts.empty?
    classes.each do |c|
      mc.class_filter c
    end
    facts.each do |f, v|
      mc.fact_filter f, v
    end
  end
  mc
end

#check_spec(example, action, values) ⇒ Object



54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/mspectator/example.rb', line 54

def check_spec (example, action, values)
  spec_mc = filtered_mc('spec', example)
  passed = []
  failed = []
  spec_mc.check(:action => action, :values => values).each do |resp|
    if resp[:data][:passed]
      passed << resp[:sender]
    else
      failed << resp[:sender]
    end
  end
  return passed, failed
end

#filtered_mc(agent, example) ⇒ Object



31
32
33
34
35
36
37
# File 'lib/mspectator/example.rb', line 31

def filtered_mc(agent, example)
  mc = mc_client(agent)
  # There is no need to reset only before :group currently
  # so we need to reset before applying filters
  mc.reset
  apply_filters(mc, example)
end

#get_fqdn(example) ⇒ Object



68
69
70
71
72
73
74
75
76
77
# File 'lib/mspectator/example.rb', line 68

def get_fqdn (example)
  util_mc = self.mc_client('rpcutil')
  util_mc.progress = false
  util_mc = apply_filters util_mc, example
  fqdn = []
  util_mc.get_fact(:fact => 'fqdn').each do |resp|
    fqdn << resp[:data][:value]
  end
  fqdn
end

#mc_client(agent) ⇒ Object



21
22
23
24
25
26
27
28
29
# File 'lib/mspectator/example.rb', line 21

def mc_client(agent)
  unless mc_clients.has_key? agent
    # Can't pass :progress_bar to rpcclient()?
    new = rpcclient(agent)
    new.progress = false
    mc_clients[agent] = new
  end
  mc_clients[agent]
end

#mc_clientsObject



17
18
19
# File 'lib/mspectator/example.rb', line 17

def mc_clients
  @mc_clients ||= {}
end

#subjectObject



7
8
9
# File 'lib/mspectator/example.rb', line 7

def subject
  @subject ||= self.class.top_level_description
end