Module: VirtualMonkey::Application

Included in:
ApplicationFrontend, ELBRunner
Defined in:
lib/virtualmonkey/application.rb

Instance Method Summary collapse

Instance Method Details

#app_serversObject

returns an Array of the App Servers in the deployment



7
8
9
10
11
# File 'lib/virtualmonkey/application.rb', line 7

def app_servers
  ret = @servers.select { |s| s.nickname =~ /App Server/ }
  raise "No app servers in deployment" unless ret.length > 0
  ret
end

#get_tester_ip_addrObject

Assumes the host machine is EC2, uses the meta-data to grab the IP address of this ‘tester server’ eg. used for the input variation MASTER_DB_DNSNAME



55
56
57
58
59
60
61
62
63
64
# File 'lib/virtualmonkey/application.rb', line 55

def get_tester_ip_addr
  if File.exists?("/var/spool/ec2/meta-data.rb")
    require "/var/spool/ec2/meta-data-cache" 
  else
    ENV['EC2_PUBLIC_HOSTNAME'] = "127.0.0.1"
  end
  my_ip_input = "text:" 
  my_ip_input += ENV['EC2_PUBLIC_HOSTNAME']
  my_ip_input
end

#lookup_scriptsObject



47
48
49
50
51
# File 'lib/virtualmonkey/application.rb', line 47

def lookup_scripts
  @scripts_to_run = {}
  st = ServerTemplate.find(@servers.first.server_template_href)
  @scripts_to_run['apache_restart'] = st.executables.detect { |ex| ex.name =~  /WEB apache \(re\)start v2/i }
end

#run_app_testsObject

Run spot checks for APP servers in the deployment



67
68
# File 'lib/virtualmonkey/application.rb', line 67

def run_app_tests
end

#run_rails_demo_application_checks(run_on = @servers, port = 80) ⇒ Object



40
41
42
43
44
45
# File 'lib/virtualmonkey/application.rb', line 40

def run_rails_demo_application_checks(run_on=@servers,port=80)
  run_on.each do |server|
    url_base = "#{server.dns_name}:#{port}"
    test_http_response("Mephisto", url_base, port) 
  end
end

#set_lb_hostnameObject

sets LB_HOSTNAME on the deployment using the private dns of the fe_servers



14
15
16
# File 'lib/virtualmonkey/application.rb', line 14

def set_lb_hostname
  @deployment.set_input("LB_HOSTNAME", get_lb_hostname_input)
end

#startupObject

Special startup sequence for an APP deployment



71
72
# File 'lib/virtualmonkey/application.rb', line 71

def startup
end

#test_http_response(expected_string, url, port) ⇒ Object

returns true if the http response contains the expected_string

  • url<~String> url to perform http request

  • expected_string<~String> regex compatible string used to match against the response output



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/virtualmonkey/application.rb', line 21

def test_http_response(expected_string, url, port)
  cmd = "curl -s #{url} 2> /dev/null "
  puts cmd
  timeout=300
  begin
    status = Timeout::timeout(timeout) do
      while true
        response = `#{cmd}`
        puts response 
        break if response.include?(expected_string)
        puts "Retrying..."
        sleep 5
      end
    end
  rescue Timeout::Error => e
    raise "ERROR: Query failed after #{timeout/60} minutes."
  end
end