Module: CheckDSL
- Included in:
- Checker
- Defined in:
- lib/teuton/check/dsl/all.rb,
lib/teuton/check/dsl/run.rb,
lib/teuton/check/dsl/expect.rb,
lib/teuton/check/dsl/getset.rb,
lib/teuton/check/dsl/builtin.rb,
lib/teuton/check/dsl/expect_sequence.rb
Defined Under Namespace
Classes: ExpectSequence
Instance Method Summary collapse
- #expect(cond) ⇒ Object
- #expect_exit(cond) ⇒ Object
- #expect_fail ⇒ Object
- #expect_first(cond) ⇒ Object
- #expect_last(cond) ⇒ Object
- #expect_none(cond = nil, args = {}) ⇒ Object
- #expect_nothing ⇒ Object
- #expect_ok ⇒ Object
- #expect_one(cond) ⇒ Object
- #expect_sequence(&block) ⇒ Object
- #get(varname) ⇒ Object
- #gett(option) ⇒ Object
- #goto(host = :localhost, args = {}) ⇒ Object
- #log(text = "", type = :info) ⇒ Object
- #readme(text) ⇒ Object
- #run(command, args = {}) ⇒ Object
- #run_script(command, args = {}) ⇒ Object
- #service(param) ⇒ Object
- #set(key, value) ⇒ Object
- #target(desc, args = {}) ⇒ Object (also: #goal)
- #unique(key, _value) ⇒ Object
- #unset(key) ⇒ Object
- #upload(filename, args = {}) ⇒ Object
Instance Method Details
#expect(cond) ⇒ Object
4 5 6 7 8 9 10 11 12 |
# File 'lib/teuton/check/dsl/expect.rb', line 4 def expect(cond) unless @target_begin Logger.warn "WARN 'expect' with no previous 'target'" end Logger.info " alter #{result.alterations}" unless result.alterations.empty? Logger.info " expect #{cond} (#{cond.class})" Logger.info "" @target_begin = false end |
#expect_exit(cond) ⇒ Object
14 15 16 17 18 19 20 21 |
# File 'lib/teuton/check/dsl/expect.rb', line 14 def expect_exit(cond) unless @target_begin Logger.warn "WARN 'expect' with no previous 'target'" end Logger.info " expect_exit #{cond} (#{cond.class})" Logger.info "" @target_begin = false end |
#expect_fail ⇒ Object
23 24 25 26 27 28 29 30 |
# File 'lib/teuton/check/dsl/expect.rb', line 23 def expect_fail unless @target_begin Logger.warn "WARN 'expect' with no previous 'target'" end Logger.info " expect_fail" Logger.info "" @target_begin = false end |
#expect_first(cond) ⇒ Object
32 33 34 35 36 37 38 39 40 |
# File 'lib/teuton/check/dsl/expect.rb', line 32 def expect_first(cond) unless @target_begin Logger.warn "WARN 'expect' with no previous 'target'" end Logger.info " alter #{result.alterations}" unless result.alterations.empty? Logger.info " expect_first #{cond} (#{cond.class})" Logger.info "" @target_begin = false end |
#expect_last(cond) ⇒ Object
42 43 44 45 46 47 48 49 50 |
# File 'lib/teuton/check/dsl/expect.rb', line 42 def expect_last(cond) unless @target_begin Logger.warn "WARN 'expect' with no previous 'target'" end Logger.info " alter #{result.alterations}" unless result.alterations.empty? Logger.info " expect_last #{cond} (#{cond.class})" Logger.info "" @target_begin = false end |
#expect_none(cond = nil, args = {}) ⇒ Object
52 53 54 55 56 57 58 59 60 |
# File 'lib/teuton/check/dsl/expect.rb', line 52 def expect_none(cond = nil, args = {}) unless @target_begin Logger.warn "WARN 'expect' with no previous 'target'" end Logger.info " alter #{result.alterations}" unless result.alterations.empty? Logger.info " expect_none #{cond} (#{cond.class})" Logger.info "" @target_begin = false end |
#expect_nothing ⇒ Object
62 63 64 |
# File 'lib/teuton/check/dsl/expect.rb', line 62 def expect_nothing expect_none nil, {} end |
#expect_ok ⇒ Object
66 67 68 |
# File 'lib/teuton/check/dsl/expect.rb', line 66 def expect_ok expect_exit 0 end |
#expect_one(cond) ⇒ Object
70 71 72 73 74 75 76 77 78 |
# File 'lib/teuton/check/dsl/expect.rb', line 70 def expect_one(cond) unless @target_begin Logger.warn "WARN 'expect' with no previous 'target'" end Logger.info " alter #{result.alterations}" unless result.alterations.empty? Logger.info " expect_one #{cond} (#{cond.class})" Logger.info "" @target_begin = false end |
#expect_sequence(&block) ⇒ Object
80 81 82 83 84 85 86 87 88 89 |
# File 'lib/teuton/check/dsl/expect.rb', line 80 def expect_sequence(&block) unless @target_begin Logger.warn "WARN 'expect' with no previous 'target'" end seq = CheckDSL::ExpectSequence.new seq.is_valid?(&block) Logger.info " expect_sequence #{seq.expected}" Logger.info "" @target_begin = false end |
#get(varname) ⇒ Object
2 3 4 5 6 |
# File 'lib/teuton/check/dsl/getset.rb', line 2 def get(varname) data = @stats[:gets] data[varname] = data[varname] ? (data[varname] + 1) : 1 "get(#{varname})" end |
#gett(option) ⇒ Object
8 9 10 |
# File 'lib/teuton/check/dsl/getset.rb', line 8 def gett(option) get(option) end |
#goto(host = :localhost, args = {}) ⇒ Object
17 18 19 20 21 |
# File 'lib/teuton/check/dsl/run.rb', line 17 def goto(host = :localhost, args = {}) result.reset @stats[:hosts][host] = @stats[:hosts][host] ? (@stats[:hosts][host] + 1) : 1 Logger.info " run '#{args[:exec]}' on #{host}" end |
#log(text = "", type = :info) ⇒ Object
7 8 9 10 11 |
# File 'lib/teuton/check/dsl/all.rb', line 7 def log(text = "", type = :info) @stats[:logs] += 1 prefix = (type == :info) ? "" : "#{type.to_s.upcase}: " Logger.info " log #{prefix}" + text.to_s end |
#readme(text) ⇒ Object
13 14 15 16 |
# File 'lib/teuton/check/dsl/all.rb', line 13 def readme(text) @stats[:readmes] += 1 Logger.info " readme #{text}" end |
#run(command, args = {}) ⇒ Object
2 3 4 5 6 7 |
# File 'lib/teuton/check/dsl/run.rb', line 2 def run(command, args = {}) args[:exec] = command host = :localhost host = args[:on] if args[:on] goto(host, args) end |
#run_script(command, args = {}) ⇒ Object
9 10 11 12 13 14 15 |
# File 'lib/teuton/check/dsl/run.rb', line 9 def run_script(command, args = {}) host = :localhost host = args[:on] if args[:on] filename = command.split[1] upload filename, to: host run command, args end |
#service(param) ⇒ Object
20 21 22 23 24 25 |
# File 'lib/teuton/check/dsl/builtin.rb', line 20 def service(param) log "BUILTIN service(#{param})" @builtin ||= Builtin.new(self) @builtin.param = param @builtin end |
#set(key, value) ⇒ Object
12 13 14 15 16 17 18 |
# File 'lib/teuton/check/dsl/getset.rb', line 12 def set(key, value) key = ":" + key.to_s if key.instance_of? Symbol value = ":" + value.to_s if value.instance_of? Symbol @stats[:sets] << "#{key}=#{value}" Logger.info " set(#{key},#{value})" end |
#target(desc, args = {}) ⇒ Object Also known as: goal
18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/teuton/check/dsl/all.rb', line 18 def target(desc, args = {}) if @target_begin Logger.warn "WARN Previous 'target' requires 'expect'" end @target_begin = true @stats[:targets] += 1 @targetid += 1 weight = args[:weight] ? args[:weight].to_f : 1.0 Logger.info format("(%03<targetid>d) target %<desc>s", targetid: @targetid, desc: desc) Logger.info " weight #{weight}" end |
#unique(key, _value) ⇒ Object
31 32 33 34 35 36 |
# File 'lib/teuton/check/dsl/all.rb', line 31 def unique(key, _value) @stats[:uniques] += 1 Logger.info " unique value for <#{key}>" Logger.info "" end |
#unset(key) ⇒ Object
20 21 22 |
# File 'lib/teuton/check/dsl/getset.rb', line 20 def unset(key) Logger.info " unset(#{key})" end |
#upload(filename, args = {}) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/teuton/check/dsl/run.rb', line 23 def upload(filename, args = {}) host = args[:to] args.delete(:to) custom = if args == {} "" else values = args.map { "#{_1}=#{_2}" } "and #{values.join(",")}" end @stats[:uploads] << filename Logger.info " upload '#{filename}' to #{host} #{custom}" end |