virtualmonkey 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (178) hide show
  1. data/.document +5 -0
  2. data/LICENSE +20 -0
  3. data/README.rdoc +77 -0
  4. data/Rakefile +51 -0
  5. data/VERSION +1 -0
  6. data/bin/grinder +102 -0
  7. data/bin/mcicp +46 -0
  8. data/bin/monkey +12 -0
  9. data/bin/vary_instance_types +59 -0
  10. data/config/cloud_variables/all_clouds.json +30 -0
  11. data/config/cloud_variables/east.json +9 -0
  12. data/config/cloud_variables/rackspace.json +7 -0
  13. data/config/cloud_variables/west.json +9 -0
  14. data/config/common_inputs/apache_haproxy.json +27 -0
  15. data/config/common_inputs/base.json +5 -0
  16. data/config/common_inputs/ebs_toolbox.json +10 -0
  17. data/config/common_inputs/haproxy.json +15 -0
  18. data/config/common_inputs/lamp.json +30 -0
  19. data/config/common_inputs/mysql.json +24 -0
  20. data/config/common_inputs/none.json +4 -0
  21. data/config/common_inputs/php.json +25 -0
  22. data/config/common_inputs/php_aio_trial_chef_alpha.json +3 -0
  23. data/config/common_inputs/php_app_fe_chef.json +12 -0
  24. data/config/common_inputs/php_elb.json +12 -0
  25. data/config/common_inputs/qstart.json +5 -0
  26. data/config/common_inputs/rails.json +31 -0
  27. data/config/common_inputs/rails_aio_demo_chef_alpha.json +3 -0
  28. data/config/common_inputs/rails_aio_developer_chef_alpha.json +10 -0
  29. data/config/common_inputs/rsgrid.json +10 -0
  30. data/config/common_inputs/tomcat.json +15 -0
  31. data/config/common_inputs/windows_blog_engine.json +3 -0
  32. data/config/common_inputs/windows_net_aio.json +14 -0
  33. data/config/troop/11H1/backup/base.json +10 -0
  34. data/config/troop/11H1/backup/lamp_mysql_50.json +10 -0
  35. data/config/troop/11H1/backup/lamp_mysql_51.json +10 -0
  36. data/config/troop/11H1/backup/loadbalancer-php.json +13 -0
  37. data/config/troop/11H1/backup/loadbalancer.json +14 -0
  38. data/config/troop/11H1/backup/loadbalancer_rails.json +13 -0
  39. data/config/troop/11H1/backup/loadbalancer_tomcat6.json +13 -0
  40. data/config/troop/11H1/backup/mysql50.json +11 -0
  41. data/config/troop/11H1/backup/mysql50_toolbox.json +12 -0
  42. data/config/troop/11H1/backup/mysql51.json +11 -0
  43. data/config/troop/11H1/backup/mysql51_toolbox.json +12 -0
  44. data/config/troop/11H1/backup/php_elb.json +11 -0
  45. data/config/troop/11H1/base.json +10 -0
  46. data/config/troop/11H1/ebs_toolbox.json +12 -0
  47. data/config/troop/11H1/lamp_mysql_50.json +10 -0
  48. data/config/troop/11H1/lamp_mysql_51.json +10 -0
  49. data/config/troop/11H1/loadbalancer-php.json +13 -0
  50. data/config/troop/11H1/loadbalancer.json +17 -0
  51. data/config/troop/11H1/loadbalancer_rails.json +13 -0
  52. data/config/troop/11H1/loadbalancer_tomcat6.json +13 -0
  53. data/config/troop/11H1/mysql50.json +11 -0
  54. data/config/troop/11H1/mysql50_toolbox.json +12 -0
  55. data/config/troop/11H1/mysql51.json +11 -0
  56. data/config/troop/11H1/mysql51_awsdns.json +11 -0
  57. data/config/troop/11H1/mysql51_debug.json +11 -0
  58. data/config/troop/11H1/mysql51_toolbox.json +12 -0
  59. data/config/troop/11H1/php.json +13 -0
  60. data/config/troop/11H1/php_elb.json +11 -0
  61. data/config/troop/11H1/rails.json +13 -0
  62. data/config/troop/11H1/tomcat6.json +13 -0
  63. data/config/troop/chef_quickstart.json +10 -0
  64. data/config/troop/just_elb +10 -0
  65. data/config/troop/lamp_v4.json +10 -0
  66. data/config/troop/patch_test.json +10 -0
  67. data/config/troop/rightlink.json +10 -0
  68. data/config/troop/simple_fail.json +11 -0
  69. data/config/troop/simple_pass.json +11 -0
  70. data/config/troop/windows_blog_engine.json +10 -0
  71. data/config/troop/windows_net_aio.json +10 -0
  72. data/config/troop/windows_quick_start.json +10 -0
  73. data/features/base.rb +31 -0
  74. data/features/db_toolbox.rb +59 -0
  75. data/features/ebs_toolbox.rb +62 -0
  76. data/features/lamp.rb +33 -0
  77. data/features/lb-apache-haproxy.rb +49 -0
  78. data/features/mysql_5.x_v2_v4_from_scratch.rb +71 -0
  79. data/features/mysql_5.x_v2_v4_from_scratch_awsdns.rb +71 -0
  80. data/features/mysql_5.x_v2_v4_from_scratch_dyndns.rb +71 -0
  81. data/features/mysql_v1_upgrade_v2.rb +54 -0
  82. data/features/old_cuke_features/Rakefile +121 -0
  83. data/features/old_cuke_features/Steps-TODO +31 -0
  84. data/features/old_cuke_features/app_state.feature +25 -0
  85. data/features/old_cuke_features/app_test.feature +24 -0
  86. data/features/old_cuke_features/base.feature +16 -0
  87. data/features/old_cuke_features/chef_quickstart.feature +11 -0
  88. data/features/old_cuke_features/db_toolbox.feature +38 -0
  89. data/features/old_cuke_features/ebs_toolbox.feature +39 -0
  90. data/features/old_cuke_features/elb_create_delete.feature +41 -0
  91. data/features/old_cuke_features/elb_generic.feature +27 -0
  92. data/features/old_cuke_features/fe_app_checks.feature +21 -0
  93. data/features/old_cuke_features/just-start.feature +13 -0
  94. data/features/old_cuke_features/lamp.feature +15 -0
  95. data/features/old_cuke_features/lb-apache-haproxy.feature +27 -0
  96. data/features/old_cuke_features/mysql_5.x_v2_v4_from_scratch.feature +33 -0
  97. data/features/old_cuke_features/mysql_5.x_v2_v4_from_scratch_awsdns.feature +33 -0
  98. data/features/old_cuke_features/mysql_5.x_v2_v4_from_scratch_dyndns.feature +33 -0
  99. data/features/old_cuke_features/mysql_chef_premium.feature +27 -0
  100. data/features/old_cuke_features/mysql_chef_premium_from_scratch.feature +37 -0
  101. data/features/old_cuke_features/mysql_v1_upgrade_v2.feature +42 -0
  102. data/features/old_cuke_features/php.feature +27 -0
  103. data/features/old_cuke_features/php_aio_trial_chef_alpha.feature +11 -0
  104. data/features/old_cuke_features/php_chef.feature +21 -0
  105. data/features/old_cuke_features/php_elb.feature +41 -0
  106. data/features/old_cuke_features/rails.feature +26 -0
  107. data/features/old_cuke_features/rails_aio_developer_chef.feature +17 -0
  108. data/features/old_cuke_features/reboot.feature +23 -0
  109. data/features/old_cuke_features/rightlink.feature +19 -0
  110. data/features/old_cuke_features/rsgrid.feature +19 -0
  111. data/features/old_cuke_features/simple.feature +8 -0
  112. data/features/old_cuke_features/simple_fail.feature +9 -0
  113. data/features/old_cuke_features/start-stop.feature +13 -0
  114. data/features/old_cuke_features/step_definitions/app.rb +21 -0
  115. data/features/old_cuke_features/step_definitions/deployment_steps.rb +112 -0
  116. data/features/old_cuke_features/step_definitions/ebs.rb +36 -0
  117. data/features/old_cuke_features/step_definitions/elb.rb +35 -0
  118. data/features/old_cuke_features/step_definitions/lb.rb +22 -0
  119. data/features/old_cuke_features/step_definitions/mysql_steps.rb +84 -0
  120. data/features/old_cuke_features/terminate.feature +7 -0
  121. data/features/old_cuke_features/tomcat6-tests-TODO +29 -0
  122. data/features/old_cuke_features/tomcat6.feature +27 -0
  123. data/features/patch_test.rb +33 -0
  124. data/features/php.rb +54 -0
  125. data/features/php_elb.rb +78 -0
  126. data/features/rails.rb +54 -0
  127. data/features/start_only.rb +26 -0
  128. data/features/tomcat6.rb +54 -0
  129. data/lib/virtualmonkey.rb +28 -0
  130. data/lib/virtualmonkey/application.rb +75 -0
  131. data/lib/virtualmonkey/application_frontend.rb +42 -0
  132. data/lib/virtualmonkey/command.rb +39 -0
  133. data/lib/virtualmonkey/command/clone.rb +50 -0
  134. data/lib/virtualmonkey/command/create.rb +21 -0
  135. data/lib/virtualmonkey/command/destroy.rb +51 -0
  136. data/lib/virtualmonkey/command/list.rb +10 -0
  137. data/lib/virtualmonkey/command/run.rb +76 -0
  138. data/lib/virtualmonkey/command/troop.rb +146 -0
  139. data/lib/virtualmonkey/cuke_monk.rb +184 -0
  140. data/lib/virtualmonkey/deployment_monk.rb +132 -0
  141. data/lib/virtualmonkey/deployment_runner.rb +333 -0
  142. data/lib/virtualmonkey/ebs.rb +161 -0
  143. data/lib/virtualmonkey/ebs_runner.rb +59 -0
  144. data/lib/virtualmonkey/elb_runner.rb +194 -0
  145. data/lib/virtualmonkey/fe_app_runner.rb +7 -0
  146. data/lib/virtualmonkey/file_locations.rb +7 -0
  147. data/lib/virtualmonkey/frontend.rb +124 -0
  148. data/lib/virtualmonkey/http_checks.rb +33 -0
  149. data/lib/virtualmonkey/index.html.erb +109 -0
  150. data/lib/virtualmonkey/lamp_runner.rb +29 -0
  151. data/lib/virtualmonkey/mysql.rb +172 -0
  152. data/lib/virtualmonkey/mysql_runner.rb +108 -0
  153. data/lib/virtualmonkey/mysql_toolbox_runner.rb +51 -0
  154. data/lib/virtualmonkey/patch_runner.rb +46 -0
  155. data/lib/virtualmonkey/php_aio_trial_chef_runner.rb +6 -0
  156. data/lib/virtualmonkey/php_chef_runner.rb +69 -0
  157. data/lib/virtualmonkey/rails_aio_developer_chef_runner.rb +8 -0
  158. data/lib/virtualmonkey/shared_dns.rb +67 -0
  159. data/lib/virtualmonkey/simple.rb +5 -0
  160. data/lib/virtualmonkey/simple_runner.rb +6 -0
  161. data/lib/virtualmonkey/test_case_interface.rb +151 -0
  162. data/lib/virtualmonkey/unified_application.rb +40 -0
  163. data/spec/bug3518.rb +16 -0
  164. data/spec/concurrent_writes_spec.rb +26 -0
  165. data/spec/cuke_job_spec.rb +26 -0
  166. data/spec/ek.rb +28 -0
  167. data/spec/little_ruby.rb +20 -0
  168. data/spec/mini.rb +25 -0
  169. data/spec/monitoring.rb +13 -0
  170. data/spec/release_aws_dns.rb +5 -0
  171. data/spec/release_dns.rb +5 -0
  172. data/spec/release_dyndns.rb +5 -0
  173. data/spec/shared_resources_spec.rb +25 -0
  174. data/spec/spec.opts +1 -0
  175. data/spec/spec_helper.rb +11 -0
  176. data/spec/virtualmonkey_spec.rb +7 -0
  177. data/virtualmonkey.gemspec +265 -0
  178. metadata +428 -0
@@ -0,0 +1,26 @@
1
+ #@base
2
+ #
3
+ # Feature: Base Server Test
4
+ # Tests the base server functions
5
+ #
6
+ # Scenario: base server test
7
+ #
8
+ # Given A simple deployment
9
+ @runner = VirtualMonkey::SimpleRunner.new(ENV['DEPLOYMENT'])
10
+
11
+ # Then I should stop the servers
12
+ @runner.behavior(:stop_all)
13
+
14
+ # Then I should launch all servers
15
+ @runner.behavior(:launch_all)
16
+
17
+ # Then I should wait for the state of "all" servers to be "operational"
18
+ @runner.behavior(:wait_for_all, "operational")
19
+
20
+ # Then I should reboot the servers
21
+ @runner.behavior(:reboot_all)
22
+
23
+ # Then I should wait for the state of "all" servers to be "operational"
24
+ @runner.behavior(:wait_for_all, "operational")
25
+
26
+
@@ -0,0 +1,54 @@
1
+ #@lb_test
2
+ #
3
+ #Feature: Tomcat6 Server Templates
4
+ # Tests the Tomcat6 servers
5
+ #
6
+ #Scenario: Tomcat6 server test
7
+ #
8
+ # Given A frontend with application servers deployment
9
+ @runner = VirtualMonkey::FeAppRunner.new(ENV['DEPLOYMENT'])
10
+
11
+ # Then I should stop the servers
12
+ @runner.behavior(:stop_all)
13
+
14
+ # Then I should set a variation for connecting to shared database host
15
+ @runner.set_var(:set_master_db_dnsname)
16
+
17
+ # When I launch the "Front End" servers
18
+ @runner.behavior(:launch_set, "Front End")
19
+
20
+ # Then I should wait for the state of "Front End" servers to be "booting"
21
+ @runner.behavior(:wait_for_set, "Front End", "booting")
22
+
23
+ # Then I should wait for the state of "Front End" servers to be "operational"
24
+ @runner.behavior(:wait_for_set, "Front End", "operational")
25
+
26
+ # Then I should set a variation LB_HOSTNAME
27
+ @runner.set_var(:set_lb_hostname)
28
+
29
+ # When I launch the "App Server" servers
30
+ @runner.behavior(:launch_set, "App Server")
31
+
32
+ # Then I should wait for the state of "App Server" servers to be "booting"
33
+ @runner.behavior(:wait_for_set, "App Server", "booting")
34
+
35
+ # Then I should wait for the state of "App Server" servers to be "operational"
36
+ @runner.behavior(:wait_for_set, "App Server", "operational")
37
+
38
+ # Then I should cross connect the frontends
39
+ @runner.behavior(:cross_connect_frontends)
40
+
41
+ # Then I should run unified application checks
42
+ @runner.behavior(:run_unified_application_checks, @runner.send(:app_servers))
43
+
44
+ # Then I should run frontend checks
45
+ @runner.behavior(:frontend_checks)
46
+
47
+ # Then I should run log rotation checks
48
+ @runner.behavior(:log_rotation_checks)
49
+
50
+ # Then I should test reboot operations on the deployment
51
+ @runner.behavior(:run_reboot_operations)
52
+
53
+ # Then I should check that monitoring is enabled
54
+ @runner.behavior(:check_monitoring)
@@ -0,0 +1,28 @@
1
+ require 'rest_connection'
2
+ require 'fog'
3
+ require 'fileutils'
4
+ require 'virtualmonkey/unified_application'
5
+ require 'virtualmonkey/file_locations'
6
+ require 'virtualmonkey/deployment_monk'
7
+ require 'virtualmonkey/cuke_monk'
8
+ require 'virtualmonkey/shared_dns'
9
+ require 'virtualmonkey/test_case_interface'
10
+ require 'virtualmonkey/deployment_runner'
11
+ require 'virtualmonkey/ebs'
12
+ require 'virtualmonkey/ebs_runner'
13
+ require 'virtualmonkey/mysql'
14
+ require 'virtualmonkey/mysql_runner'
15
+ require 'virtualmonkey/mysql_toolbox_runner'
16
+ require 'virtualmonkey/application'
17
+ require 'virtualmonkey/frontend'
18
+ require 'virtualmonkey/application_frontend'
19
+ require 'virtualmonkey/simple'
20
+ require 'virtualmonkey/fe_app_runner'
21
+ require 'virtualmonkey/php_aio_trial_chef_runner'
22
+ require 'virtualmonkey/rails_aio_developer_chef_runner'
23
+ require 'virtualmonkey/php_chef_runner'
24
+ require 'virtualmonkey/simple_runner'
25
+ require 'virtualmonkey/lamp_runner'
26
+ require 'virtualmonkey/elb_runner'
27
+ require 'virtualmonkey/command'
28
+ require 'virtualmonkey/patch_runner'
@@ -0,0 +1,75 @@
1
+ require 'timeout'
2
+
3
+ module VirtualMonkey
4
+ module Application
5
+
6
+ # returns an Array of the App Servers in the deployment
7
+ def app_servers
8
+ ret = @servers.select { |s| s.nickname =~ /App Server/ }
9
+ raise "No app servers in deployment" unless ret.length > 0
10
+ ret
11
+ end
12
+
13
+ # sets LB_HOSTNAME on the deployment using the private dns of the fe_servers
14
+ def set_lb_hostname
15
+ @deployment.set_input("LB_HOSTNAME", get_lb_hostname_input)
16
+ end
17
+
18
+ # returns true if the http response contains the expected_string
19
+ # * url<~String> url to perform http request
20
+ # * expected_string<~String> regex compatible string used to match against the response output
21
+ def test_http_response(expected_string, url, port)
22
+ cmd = "curl -s #{url} 2> /dev/null "
23
+ puts cmd
24
+ timeout=300
25
+ begin
26
+ status = Timeout::timeout(timeout) do
27
+ while true
28
+ response = `#{cmd}`
29
+ puts response
30
+ break if response.include?(expected_string)
31
+ puts "Retrying..."
32
+ sleep 5
33
+ end
34
+ end
35
+ rescue Timeout::Error => e
36
+ raise "ERROR: Query failed after #{timeout/60} minutes."
37
+ end
38
+ end
39
+
40
+ def run_rails_demo_application_checks(run_on=@servers,port=80)
41
+ run_on.each do |server|
42
+ url_base = "#{server.dns_name}:#{port}"
43
+ test_http_response("Mephisto", url_base, port)
44
+ end
45
+ end
46
+
47
+ def lookup_scripts
48
+ @scripts_to_run = {}
49
+ st = ServerTemplate.find(@servers.first.server_template_href)
50
+ @scripts_to_run['apache_restart'] = st.executables.detect { |ex| ex.name =~ /WEB apache \(re\)start v2/i }
51
+ end
52
+
53
+ # Assumes the host machine is EC2, uses the meta-data to grab the IP address of this
54
+ # 'tester server' eg. used for the input variation MASTER_DB_DNSNAME
55
+ def get_tester_ip_addr
56
+ if File.exists?("/var/spool/ec2/meta-data.rb")
57
+ require "/var/spool/ec2/meta-data-cache"
58
+ else
59
+ ENV['EC2_PUBLIC_HOSTNAME'] = "127.0.0.1"
60
+ end
61
+ my_ip_input = "text:"
62
+ my_ip_input += ENV['EC2_PUBLIC_HOSTNAME']
63
+ my_ip_input
64
+ end
65
+
66
+ # Run spot checks for APP servers in the deployment
67
+ def run_app_tests
68
+ end
69
+
70
+ # Special startup sequence for an APP deployment
71
+ def startup
72
+ end
73
+
74
+ end
75
+ end
@@ -0,0 +1,42 @@
1
+ module VirtualMonkey
2
+ module ApplicationFrontend
3
+ include VirtualMonkey::Application
4
+ include VirtualMonkey::Frontend
5
+ include VirtualMonkey::UnifiedApplication
6
+
7
+ # a custom startup sequence is required for fe/app deployments (inputs workaround)
8
+ def startup_sequence
9
+ fe_servers.each { |s| s.start }
10
+ fe_servers.each { |s| s.wait_for_operational_with_dns }
11
+
12
+ set_lb_hostname
13
+
14
+ app_servers.each { |s| s.start }
15
+ app_servers.each { |s| s.wait_for_operational_with_dns }
16
+ end
17
+
18
+ def run_reboot_operations
19
+ behavior(:reboot_all, true)
20
+ behavior(:run_reboot_checks)
21
+ end
22
+
23
+ def run_reboot_checks
24
+ behavior(:run_unified_application_checks, fe_servers, 80)
25
+ behavior(:run_unified_application_checks, app_servers)
26
+ end
27
+
28
+ def log_rotation_checks
29
+ # this works for php, TODO: rails
30
+ #app_servers.each do |server|
31
+ # force_log_rotation(server)
32
+ # log_check(server,"/mnt/log/#{server.apache_str}/access.log.1")
33
+ #end
34
+
35
+ fe_servers.each do |server|
36
+ behavior(:force_log_rotation, server)
37
+ behavior(:log_check, server, "/mnt/log/#{server.apache_str}/haproxy.log.1")
38
+ end
39
+ end
40
+
41
+ end
42
+ end
@@ -0,0 +1,39 @@
1
+ #!/usr/bin/env ruby
2
+ require 'rubygems'
3
+ require 'trollop'
4
+ require 'highline/import'
5
+ require 'virtualmonkey/command/create'
6
+ require 'virtualmonkey/command/destroy'
7
+ require 'virtualmonkey/command/run'
8
+ require 'virtualmonkey/command/list'
9
+ require 'virtualmonkey/command/troop'
10
+ require 'virtualmonkey/command/clone'
11
+
12
+ module VirtualMonkey
13
+ module Command
14
+ # Parses the initial command string, removing it from ARGV, then runs command.
15
+ def self.go
16
+ command = ARGV.shift
17
+ case command
18
+ when "create"
19
+ VirtualMonkey::Command.create
20
+ when "destroy"
21
+ VirtualMonkey::Command.destroy
22
+ when "run"
23
+ VirtualMonkey::Command.run
24
+ when "list"
25
+ VirtualMonkey::Command.list
26
+ when "troop"
27
+ VirtualMonkey::Command.troop
28
+ when "clone"
29
+ VirtualMonkey::Command.clone
30
+ when "help" || "--help" || "-h"
31
+ puts "Help usage: monkey <command> --help"
32
+ puts "Valid commands for monkey: create, destroy, list, run, troop, clone or help"
33
+ else
34
+ STDERR.puts "Invalid command #{command}: You need to specify a command for monkey: create, destroy, list, run, troop, clone or help\n"
35
+ exit(1)
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,50 @@
1
+ module VirtualMonkey
2
+ module Command
3
+
4
+ # monkey clone --deployment name --feature testcase.rb --breakpoint 4 --copies 7
5
+ def self.clone
6
+ options = Trollop::options do
7
+ opt :deployment, "regex string to use for matching deployment", :type => :string, :short => '-d', :required => true
8
+ opt :feature, "path to feature(s) to run against the deployments", :type => :string
9
+ opt :breakpoint, "feature file line to stop at", :type => :integer, :short => '-b'
10
+ opt :copies, "number of copies to make (default is 1)", :type => :integer, :short => '-c'
11
+ end
12
+
13
+ options[:copies] = 1 unless options[:copies] > 1
14
+ options[:no_resume] = true
15
+ dm = DeploymentMonk.new(options[:deployment])
16
+ if dm.deployments.length > 1
17
+ raise "FATAL: Ambiguous Regex; more than one deployment matched /#{options[:deployment]}/"
18
+ elsif dm.deployments.length < 1
19
+ raise "FATAL: Ambiguous Regex; no deployment matched /#{options[:deployment]}/"
20
+ end
21
+ origin = dm.deployments.first
22
+ do_these ||= []
23
+ # clone deployment
24
+ for i in 1 .. options[:copies]
25
+ new_deploy = origin.clone
26
+ new_deploy.nickname = "#{origin.nickname}-clone-#{i}"
27
+ new_deploy.save
28
+ do_these << new_deploy
29
+ end
30
+
31
+ # run to breakpoint
32
+ if options[:feature]
33
+ EM.run {
34
+ cm = CukeMonk.new
35
+ cm.options = options
36
+ do_these.each do |deploy|
37
+ cm.run_test(deploy, options[:feature])
38
+ end
39
+
40
+ watch = EM.add_periodic_timer(10) {
41
+ if cm.all_done?
42
+ watch.cancel
43
+ end
44
+ cm.watch_and_report
45
+ }
46
+ }
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,21 @@
1
+ module VirtualMonkey
2
+ module Command
3
+
4
+ # monkey create --server_template_ids 123,123 --common_inputs blah.json --feature simple.feature --tag unique_name --TBD:filter?
5
+ def self.create
6
+ options = Trollop::options do
7
+ opt :server_template_ids, "ServerTemplate ids to use for creating the deployment. Use one ID per server that you would like to be in the deployment. Accepts space separated integers, or one argument per id. Eg. -s 23747 23747", :type => :integers, :required => true, :short => '-s'
8
+ opt :common_inputs, "Paths to common input json files to load and set on all deployments. Accepts space separated pathnames or one argument per pathname. Eg. -c config/mysql_inputs.json -c config/other_inputs.json", :type => :strings, :required => true, :short => '-c'
9
+ opt :tag, "Tag to use as nickname prefix for all deployments.", :type => :string, :required => true, :short => '-t'
10
+ opt :cloud_variables, "Path to json file containing common inputs and variables per cloud. See config/cloud_variables.json.example", :type => :string, :required => true, :short => '-v'
11
+ opt :no_spot, "Do not use spot instances"
12
+ end
13
+ @dm = DeploymentMonk.new(options[:tag], options[:server_template_ids])
14
+ @dm.variables_for_cloud = JSON::parse(IO.read(options[:cloud_variables]))
15
+ options[:common_inputs].each do |cipath|
16
+ @dm.load_common_inputs(cipath)
17
+ end
18
+ @dm.generate_variations(options)
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,51 @@
1
+ module VirtualMonkey
2
+ module Command
3
+
4
+ # monkey destroy --tag unique_tag
5
+ def self.destroy
6
+ options = Trollop::options do
7
+ opt :tag, "Tag to match prefix of the deployments to destroy.", :type => :string, :required => true, :short => '-t'
8
+ opt :terminate, "Terminate using the specified runner", :type => :string, :required => true, :short => "-r"
9
+ opt :no_delete, "only terminate, no deletion."
10
+ opt :yes, "Turn off confirmation for destroy operation"
11
+ end
12
+ begin
13
+ eval("VirtualMonkey::#{options[:terminate]}.new('fgasvgreng243o520sdvnsals')") if options[:terminate]
14
+ rescue Exception => e
15
+ raise e unless e.message =~ /Could not find a deployment named/
16
+ options[:terminate] = "SimpleRunner" if options[:terminate]
17
+ end
18
+ @dm = DeploymentMonk.new(options[:tag])
19
+ # nicks = @dm.deployments.map &:nickname
20
+ nicks = @dm.deployments.map { |d| d.nickname }
21
+ nicks.each { |n| say n }
22
+ unless options[:yes]
23
+ confirm = ask("Really destroy these #{nicks.length} deployments (y/n)?", lambda { |ans| true if (ans =~ /^[y,Y]{1}/) })
24
+ raise "Aborting." unless confirm
25
+ end
26
+
27
+ global_state_dir = File.join(File.dirname(__FILE__), "..", "..", "..", "test_states")
28
+ @dm.deployments.each do |deploy|
29
+ @runner = eval("VirtualMonkey::#{options[:terminate]}.new(deploy.nickname)")
30
+ @runner.behavior(:stop_all, false)
31
+ state_dir = File.join(global_state_dir, deploy.nickname)
32
+ if File.directory?(state_dir)
33
+ puts "Deleting state files for #{deploy.nickname}..."
34
+ Dir.new(state_dir).each do |state_file|
35
+ if File.extname(state_file) =~ /((rb)|(feature))/
36
+ File.delete(File.join(state_dir, state_file))
37
+ end
38
+ end
39
+ Dir.rmdir(state_dir)
40
+ end
41
+ if @runner.respond_to?(:release_dns) and not options[:no_delete]
42
+ @runner.behavior(:release_dns)
43
+ end
44
+ end
45
+
46
+ @dm.destroy_all unless options[:no_delete]
47
+ say "monkey done."
48
+ end
49
+
50
+ end
51
+ end
@@ -0,0 +1,10 @@
1
+ module VirtualMonkey
2
+ module Command
3
+ def self.list
4
+ options = Trollop::options do
5
+ opt :tags, "List deployment set tags", :type => :string, :required => true
6
+ end
7
+ DeploymentMonk.new(options[:tags]).deployments.each { |d| puts d.nickname }
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,76 @@
1
+ require 'eventmachine'
2
+ module VirtualMonkey
3
+ module Command
4
+
5
+ # trollop supports Chronic for human readable dates. use with run command for delayed run?
6
+
7
+ # monkey run --feature --tag --only <regex to match on deploy nickname>
8
+ def self.run
9
+ options = Trollop::options do
10
+ opt :feature, "path to feature(s) to run against the deployments", :type => :string, :required => true
11
+ opt :breakpoint, "feature file line to stop at", :type => :integer, :short => '-b'
12
+ opt :tag, "Tag to match prefix of the deployments.", :type => :string, :required => true, :short => "-t"
13
+ opt :only, "regex string to use for subselection matching on deployments. Eg. --only x86_64", :type => :string
14
+ opt :terminate, "Terminate using the specified runner if feature successfully completes. (No destroy)", :type => :string, :short => "-r"
15
+ opt :no_resume, "Do not use current test-in-progress, start from scratch", :short => "-n"
16
+ opt :yes, "Turn off confirmation", :short => "-y"
17
+ end
18
+
19
+ global_state_dir = File.join(File.dirname(__FILE__), "..", "..", "..", "test_states")
20
+ begin
21
+ eval("VirtualMonkey::#{options[:terminate]}.new('fgasvgreng243o520sdvnsals')") if options[:terminate]
22
+ rescue Exception => e
23
+ raise e unless e.message =~ /Could not find a deployment named/
24
+ options[:terminate] = "SimpleRunner" if options[:terminate]
25
+ end
26
+ EM.run {
27
+ cm = CukeMonk.new
28
+ dm = DeploymentMonk.new(options[:tag])
29
+ if options[:only]
30
+ do_these = dm.deployments.select { |d| d.nickname =~ /#{options[:only]}/ }
31
+ else
32
+ do_these = dm.deployments
33
+ end
34
+
35
+ unless options[:no_resume]
36
+ temp = do_these.select do |d|
37
+ File.exist?(File.join(global_state_dir, d.nickname, File.basename(options[:feature])))
38
+ end
39
+ do_these = temp if temp.length > 0
40
+ end
41
+
42
+ cm.options = options
43
+ raise "No deployments matched!" unless do_these.length > 0
44
+ do_these.each { |d| say d.nickname }
45
+
46
+ unless options[:yes]
47
+ confirm = ask("Run tests on these #{do_these.length} deployments (y/n)?", lambda { |ans| true if (ans =~ /^[y,Y]{1}/) })
48
+ raise "Aborting." unless confirm
49
+ end
50
+
51
+ remaining_jobs = cm.jobs.dup
52
+ do_these.each do |deploy|
53
+ cm.run_test(deploy, options[:feature])
54
+ end
55
+
56
+ watch = EM.add_periodic_timer(10) {
57
+ cm.watch_and_report
58
+ if cm.all_done?
59
+ watch.cancel
60
+ end
61
+ if options[:terminate]
62
+ remaining_jobs.each do |job|
63
+ if job.status == 0
64
+ @runner = eval("VirtualMonkey::#{options[:terminate]}.new(job.deployment.nickname)")
65
+ puts "destroying successful deployment: #{@runner.deployment.nickname}"
66
+ @runner.behavior(:stop_all, false)
67
+ remaining_jobs.delete(job)
68
+ end
69
+ end
70
+ end
71
+ }
72
+
73
+ }
74
+ end
75
+ end
76
+ end