Module: TddDeploy::DeployTestMethods

Includes:
Assertions, RunMethods
Included in:
Base
Defined in:
lib/tdd_deploy/deploy_test_methods.rb

Overview

TddDeploy::DeployTestMethods

this module supplies the basic methods used to validate host installation structure.

all methods expect the first two arguments to be ‘userid’ and ‘host’ or ‘host-list’. the ‘userid’ is a userid which exists on the specified host. ‘host’ is a single host ‘host-list’ can be a single host (as a string) or an array of host names ‘success_message’ is what you will see in the report. I like positive messages, hence the name

the most frequently used are ‘deploy_test_process_running_on_hosts_as’ and ‘deploy_test_file_exists_on_hosts_as’.

‘deploy_test_on_hosts_as’ and ‘deploy_test_on_a_host_as’ are more primative and flexible.

Constant Summary

Constants included from Assertions

Assertions::GROUP_ELT_TAG, Assertions::HEADER_ELT_TAG, Assertions::RESULT_ELT_TAG

Instance Method Summary collapse

Methods included from RunMethods

#ping_host, #run_locally, #run_on_a_host_as, #run_on_all_hosts, #run_on_all_hosts_as, #run_on_hosts_as

Methods included from Assertions

#assert, #assert_equal, #assert_match, #assert_nil, #assert_not_nil, #assert_raises, #fail, #failure_count, #failure_messages, #formatted_test_results, #pass, #refute, #refute_equal, #refute_nil, #remove_failed_tests, #reset_tests, #test_count, #test_messages, #test_results, #total_failures, #total_tests

Instance Method Details

#deploy_test_file_exists_on_hosts_as(userid, host_list, path, success_msg = nil) ⇒ Object



31
32
33
34
35
36
# File 'lib/tdd_deploy/deploy_test_methods.rb', line 31

def deploy_test_file_exists_on_hosts_as(userid, host_list, path, success_msg = nil)
  host_list = rationalize_host_list(host_list)
  deploy_test_on_hosts_as(userid, host_list, /^\s*success\s*$/, success_msg || "path #{path} should exist") do
    "test -s #{path} && echo success || echo fail"
  end
end

#deploy_test_on_a_host_as(userid, host, match, success_msg, &block) ⇒ Object

deploy_test_on_a_host_as runs the command(s) return by ‘&block’ on the specified host as user ‘userid’ declares an error if EITHER STDOUT does not match ‘match’ OR STDERR returns anything ‘match’ can be a Regexp or a string (which will be converted to a Regexp)

Raises:

  • (ArgumentError)


56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/tdd_deploy/deploy_test_methods.rb', line 56

def deploy_test_on_a_host_as(userid, host, match, success_msg, &block)
  match = Regexp.new(match) if match.is_a? String
  raise ArgumentError, 'match expression cannot be empty' if match =~ ''

  rsp, err_rsp, cmd = run_on_a_host_as(userid, host, &block)
  prefix = "user@host: #{userid}@#{host}:\n --- #{success_msg}"

  if err_rsp
    return fail host, "#{prefix}:\n --- command generated error data:\n" +
      "  command: #{cmd}\n stdout: '#{rsp}'\n stderr: '#{err_rsp}'"
  elsif rsp.nil?
    return fail host, "#{prefix}:\n --- stdout is empty for command '#{cmd}'"
  else
    return assert_match host, match, rsp, prefix
  end
end

#deploy_test_on_hosts_as(userid, host_list, match_expr_or_str, success_msg, &block) ⇒ Object

deploy_test_on_hosts_as runs the command(s) return by ‘&block’ on hosts in ‘host_list’ as the specified user ‘userid’. For each host, an error is declared if EITHER STDOUT does not match ‘match_expr_or_str’ OR if the command returns anything on STDERR. ‘match_expr_or_str’ can be a Regexp or a string (which will be converted to a Regexp)



43
44
45
46
47
48
49
50
# File 'lib/tdd_deploy/deploy_test_methods.rb', line 43

def deploy_test_on_hosts_as userid, host_list, match_expr_or_str, success_msg, &block
  ret = true
  host_list = rationalize_host_list(host_list)
  host_list.uniq.each do |host|
    ret &= deploy_test_on_a_host_as userid, host, match_expr_or_str, success_msg, &block
  end
  ret
end

#deploy_test_process_running_on_hosts_as(userid, host_list, pid_file_path, success_msg = nil) ⇒ Object



22
23
24
25
26
27
28
29
# File 'lib/tdd_deploy/deploy_test_methods.rb', line 22

def deploy_test_process_running_on_hosts_as(userid, host_list, pid_file_path, success_msg = nil)
  host_list = rationalize_host_list(host_list)
  success_msg ||= "Process associated with #{pid_file_path} should be running"
  ret = deploy_test_file_exists_on_hosts_as(userid, host_list, pid_file_path, success_msg + " based on pid file: #{pid_file_path}") ||
  ret &= deploy_test_on_hosts_as(userid, host_list, /.+\n\s*\d+.*?\d\d:\d\d:\d\d/, "Process for #{pid_file_path} is running") do
    "ps -p `cat #{pid_file_path} | awk '{ print $1 ; exit }'`"
  end
end