Module: Validator::StatusHelpers

Defined in:
spec/support/status_helpers.rb,
spec/support/sequence_helper.rb

Defined Under Namespace

Classes: SequenceHelper

Instance Method Summary collapse

Instance Method Details

#convert_status_list(list) ⇒ Object

Convert from a hash: :cyclecounter, :basecyclecounter, :stage]

to an rsmp-style list: [

{"sCI"=>"S0001", "n"=>"signalgroupstatus"},
{"sCI"=>"S0001", "n"=>"cyclecounter"},
{"sCI"=>"S0001", "n"=>"basecyclecounter"},
{"sCI"=>"S0001", "n"=>"stage"}

]

If the input is already an array, just return it



15
16
17
18
19
20
21
22
# File 'spec/support/status_helpers.rb', line 15

def convert_status_list list
  return list.clone if list.is_a? Array
  list.map do |status_code_id,names|
    names.map do |name|
      { 'sCI' => status_code_id.to_s, 'n' => name.to_s }
    end
  end.flatten
end

#request_status_and_confirm(site, description, status_list, component = Validator.get_config('main_component')) ⇒ Object



78
79
80
81
82
83
84
# File 'spec/support/status_helpers.rb', line 78

def request_status_and_confirm site, description, status_list, component=Validator.get_config('main_component')
  @site = site
  log "Read #{description}"
  result = site.request_status component, convert_status_list(status_list), collect!: {
    timeout: Validator.get_config('timeouts','status_response'),
  }
end

#unsubscribe_from_allObject



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'spec/support/status_helpers.rb', line 24

def unsubscribe_from_all
  @site.unsubscribe_to_status Validator.get_config('main_component'), [
    {'sCI'=>'S0015','n'=>'status'},
    {'sCI'=>'S0014','n'=>'status'},
    {'sCI'=>'S0011','n'=>'status'},
    {'sCI'=>'S0009','n'=>'status'},
    {'sCI'=>'S0007','n'=>'status'},
    {'sCI'=>'S0006','n'=>'status'},
    {'sCI'=>'S0006','n'=>'emergencystage'},
    {'sCI'=>'S0005','n'=>'status'},
    {'sCI'=>'S0003','n'=>'inputstatus'},
    {'sCI'=>'S0002','n'=>'detectorlogicstatus'},
    {'sCI'=>'S0001','n'=>'signalgroupstatus'},
    {'sCI'=>'S0001','n'=>'cyclecounter'},
    {'sCI'=>'S0001','n'=>'basecyclecounter'},
    {'sCI'=>'S0001','n'=>'stage'}
  ]
end

#use_sOc?(site) ⇒ Boolean

Should the sOc attribute be used? It should if the core version is 3.1.5 or higher.

Returns:

  • (Boolean)


88
89
90
# File 'spec/support/status_helpers.rb', line 88

def use_sOc? site
  RSMP::Proxy.version_meets_requirement? site.core_version, '>=3.1.5'
end

#verify_status(parent_task, description, status_list) ⇒ Object



43
44
45
46
47
48
# File 'spec/support/status_helpers.rb', line 43

def verify_status parent_task, description, status_list
  log description
  @site.request_status Validator.get_config('main_component'), convert_status_list(status_list), collect!: {
    timeout: Validator.get_config('timeouts','status_update', assume: 0)
  }
end

#wait_for_groups(state, timeout:) ⇒ Object



68
69
70
71
72
73
74
75
76
# File 'spec/support/status_helpers.rb', line 68

def wait_for_groups state, timeout:
  regex = /^#{state}+$/
  wait_for_status(@task,
    "Wait for all groups to go to yellow flash",
    [{'sCI'=>'S0001','n'=>'signalgroupstatus','s'=>regex}],
    update_rate: 0,
    timeout: timeout
  )
end

#wait_for_status(parent_task, description, status_list, update_rate: Validator.get_config('intervals','status_update', assume: 0), timeout: Validator.get_config('timeouts','command')) ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'spec/support/status_helpers.rb', line 50

def wait_for_status parent_task, description, status_list,
    update_rate: Validator.get_config('intervals','status_update', assume: 0),
    timeout: Validator.get_config('timeouts','command')
  update_rate = 0 unless update_rate
  log "Wait for #{description}"
  subscribe_list = convert_status_list(status_list).map { |item| item.merge 'uRt'=>update_rate.to_s }
  subscribe_list.map! { |item| item.merge!('sOc' => false) } if use_sOc?(@site)

  begin
    result = @site.subscribe_to_status Validator.get_config('main_component'), subscribe_list, collect!: {
      timeout: timeout
    }
  ensure
    unsubscribe_list = convert_status_list(status_list).map { |item| item.slice('sCI','n') }
    @site.unsubscribe_to_status Validator.get_config('main_component'), unsubscribe_list
  end
end