poolparty 0.0.4 → 0.2.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (247) hide show
  1. data/History.txt +25 -0
  2. data/License.txt +20 -0
  3. data/Manifest.txt +203 -0
  4. data/PostInstall.txt +18 -0
  5. data/README.txt +21 -82
  6. data/Rakefile +25 -18
  7. data/bin/cloud +31 -0
  8. data/bin/cloud-add-keypair +23 -0
  9. data/bin/cloud-configure +31 -0
  10. data/bin/cloud-contract +27 -0
  11. data/bin/cloud-expand +27 -0
  12. data/bin/cloud-list +32 -0
  13. data/bin/cloud-maintain +36 -0
  14. data/bin/cloud-osxcopy +22 -0
  15. data/bin/cloud-provision +31 -0
  16. data/bin/cloud-refresh +26 -0
  17. data/bin/cloud-ssh +18 -0
  18. data/bin/cloud-start +32 -0
  19. data/bin/cloud-terminate +23 -0
  20. data/bin/pool +25 -27
  21. data/bin/pool-console +12 -0
  22. data/bin/pool-describe +9 -0
  23. data/bin/pool-list +28 -0
  24. data/bin/pool-provision +34 -0
  25. data/bin/pool-spec +17 -0
  26. data/bin/pool-start +32 -0
  27. data/bin/pool-start-monitor +1 -0
  28. data/config/hoe.rb +115 -0
  29. data/config/requirements.rb +15 -0
  30. data/examples/basic.rb +20 -0
  31. data/examples/plugin_without_plugin_directory.rb +13 -0
  32. data/examples/poolparty.rb +12 -0
  33. data/examples/with_apache_plugin.rb +22 -0
  34. data/generators/poolspec/USAGE +5 -0
  35. data/generators/poolspec/poolspec_generator.rb +65 -0
  36. data/generators/poolspec/templates/pool_spec_template.erb +9 -0
  37. data/lib/erlang/eb_server.erl +27 -0
  38. data/lib/poolparty.rb +56 -0
  39. data/lib/poolparty/base_packages/haproxy.rb +42 -0
  40. data/lib/poolparty/base_packages/heartbeat.rb +45 -0
  41. data/lib/poolparty/base_packages/poolparty.rb +36 -0
  42. data/lib/poolparty/base_packages/ruby.rb +43 -0
  43. data/lib/poolparty/core/array.rb +24 -0
  44. data/lib/{core → poolparty/core}/exception.rb +0 -0
  45. data/lib/poolparty/core/float.rb +13 -0
  46. data/lib/poolparty/core/hash.rb +29 -0
  47. data/lib/poolparty/core/kernel.rb +37 -0
  48. data/lib/{core → poolparty/core}/module.rb +18 -0
  49. data/lib/poolparty/core/my_open_struct.rb +18 -0
  50. data/lib/poolparty/core/object.rb +54 -0
  51. data/lib/poolparty/core/proc.rb +7 -0
  52. data/lib/poolparty/core/string.rb +72 -0
  53. data/lib/poolparty/core/symbol.rb +8 -0
  54. data/lib/{core → poolparty/core}/time.rb +15 -0
  55. data/lib/poolparty/exceptions/RemoteException.rb +12 -0
  56. data/lib/poolparty/exceptions/ResourceException.rb +7 -0
  57. data/lib/poolparty/exceptions/RuntimeException.rb +7 -0
  58. data/lib/poolparty/exceptions/SpecException.rb +7 -0
  59. data/lib/poolparty/exceptions/TemplateNotFound.rb +7 -0
  60. data/lib/poolparty/helpers/binary.rb +31 -0
  61. data/lib/poolparty/helpers/console.rb +30 -0
  62. data/lib/poolparty/helpers/display.rb +34 -0
  63. data/lib/poolparty/helpers/optioner.rb +64 -0
  64. data/lib/poolparty/helpers/provisioner_base.rb +250 -0
  65. data/lib/poolparty/helpers/provisioners/master.rb +136 -0
  66. data/lib/poolparty/helpers/provisioners/slave.rb +44 -0
  67. data/lib/poolparty/modules/cloud_resourcer.rb +89 -0
  68. data/lib/poolparty/modules/configurable.rb +34 -0
  69. data/lib/poolparty/modules/definable_resource.rb +59 -0
  70. data/lib/poolparty/modules/file_writer.rb +55 -0
  71. data/lib/poolparty/modules/method_missing_sugar.rb +53 -0
  72. data/lib/poolparty/modules/output.rb +13 -0
  73. data/lib/poolparty/modules/pretty_printer.rb +39 -0
  74. data/lib/{core/string.rb → poolparty/modules/s3_string.rb} +5 -22
  75. data/lib/{modules → poolparty/modules}/safe_instance.rb +0 -0
  76. data/lib/poolparty/monitors/base_monitor.rb +16 -0
  77. data/lib/poolparty/net/remote.rb +35 -0
  78. data/lib/poolparty/net/remote_bases/ec2.rb +148 -0
  79. data/lib/poolparty/net/remote_instance.rb +69 -0
  80. data/lib/poolparty/net/remoter.rb +224 -0
  81. data/lib/poolparty/net/remoter_base.rb +117 -0
  82. data/lib/poolparty/plugins/gem_package.rb +17 -0
  83. data/lib/poolparty/plugins/git.rb +41 -0
  84. data/lib/poolparty/plugins/line.rb +76 -0
  85. data/lib/poolparty/plugins/svn.rb +48 -0
  86. data/lib/poolparty/pool/base.rb +75 -0
  87. data/lib/poolparty/pool/cloud.rb +164 -0
  88. data/lib/poolparty/pool/custom_resource.rb +61 -0
  89. data/lib/poolparty/pool/loggable.rb +29 -0
  90. data/lib/poolparty/pool/plugin.rb +41 -0
  91. data/lib/poolparty/pool/plugin_model.rb +48 -0
  92. data/lib/poolparty/pool/pool.rb +55 -0
  93. data/lib/poolparty/pool/resource.rb +248 -0
  94. data/lib/poolparty/pool/resources/class_package.rb +64 -0
  95. data/lib/poolparty/pool/resources/conditional.rb +41 -0
  96. data/lib/poolparty/pool/resources/cron.rb +14 -0
  97. data/lib/poolparty/pool/resources/directory.rb +23 -0
  98. data/lib/poolparty/pool/resources/exec.rb +26 -0
  99. data/lib/poolparty/pool/resources/file.rb +23 -0
  100. data/lib/poolparty/pool/resources/gem.rb +14 -0
  101. data/lib/poolparty/pool/resources/host.rb +14 -0
  102. data/lib/poolparty/pool/resources/package.rb +14 -0
  103. data/lib/poolparty/pool/resources/remote_file.rb +22 -0
  104. data/lib/poolparty/pool/resources/service.rb +21 -0
  105. data/lib/poolparty/pool/resources/sshkey.rb +19 -0
  106. data/lib/poolparty/pool/resources/variable.rb +27 -0
  107. data/lib/poolparty/pool/script.rb +44 -0
  108. data/lib/poolparty/templates/authkeys +2 -0
  109. data/{config/monit/nginx.monit.conf → lib/poolparty/templates/cib.xml} +0 -0
  110. data/lib/poolparty/templates/fileserver.conf +4 -0
  111. data/lib/poolparty/templates/gem +25 -0
  112. data/{config/heartbeat.conf → lib/poolparty/templates/ha.cf} +3 -2
  113. data/{config → lib/poolparty/templates}/haproxy.conf +13 -6
  114. data/lib/poolparty/templates/namespaceauth.conf +19 -0
  115. data/lib/poolparty/templates/puppet.conf +17 -0
  116. data/lib/poolparty/version.rb +9 -0
  117. data/lib/poolpartycl.rb +3 -0
  118. data/poolparty.gemspec +56 -47
  119. data/script/destroy +14 -0
  120. data/script/generate +14 -0
  121. data/script/txt2html +82 -0
  122. data/setup.rb +1585 -0
  123. data/spec/poolparty/base_packages/haproxy_spec.rb +13 -0
  124. data/spec/poolparty/base_packages/heartbeat_spec.rb +30 -0
  125. data/spec/poolparty/bin/console_spec.rb +80 -0
  126. data/spec/poolparty/core/array_spec.rb +26 -0
  127. data/spec/poolparty/core/float.rb +13 -0
  128. data/spec/poolparty/core/hash_spec.rb +63 -0
  129. data/spec/poolparty/core/kernel_spec.rb +24 -0
  130. data/spec/poolparty/core/module_spec.rb +15 -0
  131. data/spec/poolparty/core/object_spec.rb +40 -0
  132. data/spec/poolparty/core/string_spec.rb +152 -0
  133. data/spec/poolparty/core/time_spec.rb +52 -0
  134. data/spec/poolparty/helpers/binary_spec.rb +26 -0
  135. data/spec/poolparty/helpers/display_spec.rb +13 -0
  136. data/spec/poolparty/helpers/optioner_spec.rb +39 -0
  137. data/spec/poolparty/helpers/provisioner_base_spec.rb +121 -0
  138. data/spec/poolparty/helpers/provisioners/master_spec.rb +54 -0
  139. data/spec/poolparty/helpers/provisioners/slave_spec.rb +28 -0
  140. data/spec/poolparty/modules/cloud_resourcer_spec.rb +135 -0
  141. data/spec/poolparty/modules/configurable_spec.rb +26 -0
  142. data/spec/poolparty/modules/definable_resource.rb +9 -0
  143. data/spec/poolparty/modules/file_writer_spec.rb +49 -0
  144. data/spec/poolparty/modules/s3_string_spec.rb +15 -0
  145. data/spec/poolparty/modules/tmp/willy/nilly.rb +1 -0
  146. data/spec/poolparty/net/remote_bases/ec2_spec.rb +92 -0
  147. data/spec/poolparty/net/remote_instance_spec.rb +70 -0
  148. data/spec/poolparty/net/remote_spec.rb +286 -0
  149. data/spec/poolparty/net/remoter_base_spec.rb +80 -0
  150. data/spec/poolparty/net/remoter_spec.rb +191 -0
  151. data/spec/poolparty/plugins/git_spec.rb +33 -0
  152. data/spec/poolparty/plugins/line_spec.rb +16 -0
  153. data/spec/poolparty/plugins/svn_spec.rb +16 -0
  154. data/spec/poolparty/pool/base_spec.rb +108 -0
  155. data/spec/poolparty/pool/cloud_spec.rb +299 -0
  156. data/spec/poolparty/pool/configurers/files/ruby_basic.rb +17 -0
  157. data/spec/poolparty/pool/configurers/files/ruby_plugins.rb +16 -0
  158. data/spec/poolparty/pool/configurers/ruby_spec.rb +58 -0
  159. data/spec/poolparty/pool/custom_resource_spec.rb +115 -0
  160. data/spec/poolparty/pool/example_spec.rb +112 -0
  161. data/spec/poolparty/pool/plugin_model_spec.rb +63 -0
  162. data/spec/poolparty/pool/plugin_spec.rb +85 -0
  163. data/spec/poolparty/pool/pool_spec.rb +83 -0
  164. data/spec/poolparty/pool/resource_spec.rb +224 -0
  165. data/spec/poolparty/pool/resources/class_package_spec.rb +84 -0
  166. data/spec/poolparty/pool/resources/conditional_spec.rb +38 -0
  167. data/spec/poolparty/pool/resources/cron_spec.rb +49 -0
  168. data/spec/poolparty/pool/resources/directory_spec.rb +40 -0
  169. data/spec/poolparty/pool/resources/exec_spec.rb +37 -0
  170. data/spec/poolparty/pool/resources/file_spec.rb +40 -0
  171. data/spec/poolparty/pool/resources/gem_spec.rb +16 -0
  172. data/spec/poolparty/pool/resources/host_spec.rb +28 -0
  173. data/spec/poolparty/pool/resources/package_spec.rb +44 -0
  174. data/spec/poolparty/pool/resources/remote_file_spec.rb +40 -0
  175. data/spec/poolparty/pool/resources/service_spec.rb +45 -0
  176. data/spec/poolparty/pool/resources/sshkey_spec.rb +48 -0
  177. data/spec/poolparty/pool/resources/variable_spec.rb +20 -0
  178. data/spec/poolparty/pool/script_spec.rb +51 -0
  179. data/spec/poolparty/pool/test_plugins/sshkey_test +2 -0
  180. data/{test/test_pool_party.rb → spec/poolparty/pool/test_plugins/virtual_host_template.erb} +0 -0
  181. data/spec/poolparty/pool/test_plugins/webserver.rb +46 -0
  182. data/spec/poolparty/poolparty_spec.rb +33 -0
  183. data/spec/poolparty/spec_helper.rb +120 -0
  184. data/tasks/cloud.rake +57 -0
  185. data/tasks/deployment.rake +34 -0
  186. data/tasks/development.rake +78 -0
  187. data/tasks/ec2.rake +20 -0
  188. data/tasks/environment.rake +7 -0
  189. data/tasks/instance.rake +63 -0
  190. data/tasks/server.rake +42 -0
  191. data/tasks/spec.rake +17 -0
  192. data/tasks/website.rake +17 -0
  193. data/test/test_generator_helper.rb +29 -0
  194. data/test/test_helper.rb +2 -0
  195. data/test/test_pool_spec_generator.rb +47 -0
  196. data/test/test_poolparty.rb +11 -0
  197. data/test_manifest.pp +538 -0
  198. data/website/index.html +107 -0
  199. data/website/index.txt +95 -0
  200. data/website/javascripts/rounded_corners_lite.inc.js +285 -0
  201. data/website/stylesheets/code.css +29 -0
  202. data/website/stylesheets/screen.css +147 -0
  203. data/website/template.html.erb +49 -0
  204. metadata +282 -101
  205. data/CHANGELOG +0 -4
  206. data/Manifest +0 -55
  207. data/bin/instance +0 -54
  208. data/config/config.yml +0 -23
  209. data/config/create_proxy_ami.sh +0 -582
  210. data/config/heartbeat_authkeys.conf +0 -2
  211. data/config/monit.conf +0 -8
  212. data/config/monit/haproxy.monit.conf +0 -7
  213. data/config/nginx.conf +0 -24
  214. data/lib/core/array.rb +0 -10
  215. data/lib/core/kernel.rb +0 -9
  216. data/lib/core/object.rb +0 -14
  217. data/lib/modules/callback.rb +0 -55
  218. data/lib/modules/ec2_wrapper.rb +0 -74
  219. data/lib/pool_party.rb +0 -69
  220. data/lib/pool_party/application.rb +0 -133
  221. data/lib/pool_party/init.rb +0 -4
  222. data/lib/pool_party/master.rb +0 -189
  223. data/lib/pool_party/monitors.rb +0 -13
  224. data/lib/pool_party/monitors/cpu.rb +0 -18
  225. data/lib/pool_party/monitors/memory.rb +0 -21
  226. data/lib/pool_party/monitors/web.rb +0 -18
  227. data/lib/pool_party/optioner.rb +0 -16
  228. data/lib/pool_party/os.rb +0 -11
  229. data/lib/pool_party/os/ubuntu.rb +0 -78
  230. data/lib/pool_party/remote_instance.rb +0 -180
  231. data/lib/pool_party/remoting.rb +0 -112
  232. data/lib/pool_party/scheduler.rb +0 -93
  233. data/lib/pool_party/tasks.rb +0 -220
  234. data/lib/s3/s3_object_store_folders.rb +0 -44
  235. data/spec/application_spec.rb +0 -32
  236. data/spec/callback_spec.rb +0 -65
  237. data/spec/helpers/ec2_mock.rb +0 -56
  238. data/spec/helpers/remote_instance_mock.rb +0 -11
  239. data/spec/kernel_spec.rb +0 -11
  240. data/spec/master_spec.rb +0 -147
  241. data/spec/monitor_spec.rb +0 -16
  242. data/spec/optioner_spec.rb +0 -22
  243. data/spec/poolparty_spec.rb +0 -8
  244. data/spec/remote_instance_spec.rb +0 -29
  245. data/spec/remoting_spec.rb +0 -75
  246. data/spec/spec_helper.rb +0 -38
  247. data/spec/string_spec.rb +0 -28
@@ -1,56 +0,0 @@
1
- module PoolParty
2
- module EC2Mock
3
- def launch_new_instance!
4
- letter = ("a".."z").to_a[instances.size] # For unique instance_ids
5
- h = {:instance_id => "i-58ba56#{letter}", :ip => "ip-127-0-0-1.aws.amazonaws.com", :status => "pending", :launching_time => Time.now }
6
- instances << h
7
- Thread.new {wait 0.1;h[:status] = "running"} # Simulate the startup time
8
- return h
9
- end
10
- # Shutdown the instance by instance_id
11
- def terminate_instance!(instance_id)
12
- instances.select {|a| a[:instance_id] == instance_id}[0][:status] = "terminating"
13
- end
14
- # Instance description
15
- def describe_instance(id)
16
- item = instances.select {|a| a[:instance_id] == id}[0]
17
- EC2ResponseObject.get_hash_from_response(item)
18
- end
19
- # Get instance by id
20
- def get_instance_by_id(id)
21
- get_instances_description.select {|a| a.instance_id == id}[0] rescue nil
22
- end
23
- # Get the s3 description for the response in a hash format
24
- def get_instances_description
25
- instances
26
- end
27
- # Fake the ec2 connection
28
- def ec2
29
- @ec2 ||= EC2::Base.new(:access_key_id => "not a key", :secret_access_key => "not a key")
30
- end
31
- # Some basic instances, not totally necessary
32
- def instances
33
- @instances ||= []
34
- end
35
- end
36
- class EC2ResponseObject
37
- def self.get_descriptions(resp)
38
- rs = resp.DescribeInstancesResponse.reservationSet.item
39
- rs = rs.respond_to?(:instancesSet) ? rs.instancesSet : rs
40
- out = begin
41
- rs.reject {|a| a.empty? }.collect {|r| EC2ResponseObject.get_hash_from_response(r.instancesSet.item)}.reject {|a| a.nil? }
42
- rescue Exception => e
43
- begin
44
- # Really weird bug with amazon's ec2 gem
45
- rs.reject {|a| a.empty? }.collect {|r| EC2ResponseObject.get_hash_from_response(r)}.reject {|a| a.nil? }
46
- rescue Exception => e
47
- []
48
- end
49
- end
50
- out
51
- end
52
- def self.get_hash_from_response(resp)
53
- {:instance_id => resp.instanceId, :ip => resp.dnsName, :status => resp.instanceState.name, :launching_time => resp.launchTime} rescue nil
54
- end
55
- end
56
- end
@@ -1,11 +0,0 @@
1
- module PoolParty
2
- module RemoteInstanceMock
3
- def scp(src="", dest="")
4
- true
5
- end
6
- # Ssh into the instance or run a command, if the cmd is set
7
- def ssh(cmd="")
8
- true
9
- end
10
- end
11
- end
@@ -1,11 +0,0 @@
1
- require File.dirname(__FILE__) + '/spec_helper'
2
-
3
- describe "Kernel extensions" do
4
- before(:each) do
5
- @host = Master.new
6
- end
7
- it "should eval the string into time" do
8
- @host.should_receive(:sleep).once.and_return true
9
- @host.wait "10.seconds"
10
- end
11
- end
@@ -1,147 +0,0 @@
1
- require File.dirname(__FILE__) + '/spec_helper'
2
-
3
- describe "Master" do
4
- before(:each) do
5
- Application.options.stub!(:contract_when).and_return("web_requests > 30.0\n cpu_usage < 0.10")
6
- Application.options.stub!(:expand_when).and_return("web_requests < 3.0\n cpu_usage > 0.80")
7
- @master = Master.new
8
- end
9
- it "should launch the first instances and set the first as the master and the rest as slaves" do
10
- Application.stub!(:minimum_instances).and_return(1)
11
- Application.stub!(:verbose).and_return(false) # Hide messages
12
- Master.stub!(:new).and_return(@master)
13
-
14
- @master.stub!(:number_of_running_instances).and_return(0);
15
- @master.stub!(:number_of_pending_instances).and_return(0);
16
-
17
- @master.should_receive(:launch_new_instance!).and_return(
18
- {:instance_id => "i-5849ba", :ip => "ip-127-0-0-1.aws.amazon.com", :status => "running"})
19
- @master.stub!(:list_of_nonterminated_instances).and_return(
20
- [{:instance_id => "i-5849ba", :ip => "ip-127-0-0-1.aws.amazon.com", :status => "running"}])
21
- @master.start_cloud!
22
- @master.nodes.first.instance_id.should == "i-5849ba"
23
- end
24
- describe "with stubbed instances" do
25
- before(:each) do
26
- @master.stub!(:list_of_nonterminated_instances).and_return([
27
- {:instance_id => "i-5849ba", :ip => "ip-127-0-0-1.aws.amazon.com", :status => "running"},
28
- {:instance_id => "i-5849bb", :ip => "ip-127-0-0-2.aws.amazon.com", :status => "running"},
29
- {:instance_id => "i-5849bc", :ip => "ip-127-0-0-3.aws.amazon.com", :status => "pending"}
30
- ])
31
- Kernel.stub!(:exec).and_return true
32
- end
33
-
34
- it "should be able to go through the instances and assign them numbers" do
35
- i = 0
36
- @master.nodes.each do |node|
37
- node.number.should == i
38
- i += 1
39
- end
40
- end
41
- it "should be able to say that the master is the master" do
42
- @master.nodes.first.master?.should == true
43
- end
44
- it "should be able to say that the slave is not a master" do
45
- @master.nodes[1].master?.should == false
46
- end
47
- it "should be able to get a specific node in the nodes from the master" do
48
- @master.get_node(2).instance_id.should == "i-5849bc"
49
- end
50
- it "should be able to build a hosts file" do
51
- open(@master.build_hosts_file.path).read.should == "node0\tip-127-0-0-1.aws.amazon.com\nnode1\tip-127-0-0-2.aws.amazon.com\nnode2\tip-127-0-0-3.aws.amazon.com"
52
- end
53
- it "should be able to build a hosts file for a specific instance" do
54
- open(@master.build_hosts_file_for(@master.nodes.first).path).read.should =~ "node0\t127.0.0.1"
55
- end
56
- it "should be able to build a haproxy file" do
57
- open(@master.build_haproxy_file.path).read.should =~ "server node0 ip-127-0-0-1.aws.amazon.com:#{Application.client_port}"
58
- end
59
- it "should be able to reconfigure the instances (working on two files a piece)" do
60
- @master.nodes.each {|a| a.should_receive(:configure).and_return true if a.status =~ /running/}
61
- @master.reconfigure_running_instances
62
- end
63
- it "should be able to restart the running instances' services" do
64
- @master.nodes.each {|a| a.should_receive(:restart_with_monit).and_return true }
65
- @master.restart_running_instances_services
66
- end
67
- it "should be able to build a heartbeat auth file" do
68
- open(@master.build_heartbeat_authkeys_file).read.should =~ /1 md5/
69
- end
70
- describe "configuring" do
71
- before(:each) do
72
- Master.stub!(:new).and_return(@master)
73
- end
74
- it "should be able to build a heartbeat resources file for the specific node" do
75
- open(Master.build_heartbeat_resources_file_for(@master.nodes.first)).read.should =~ /node0\tip-127/
76
- end
77
- it "should be able to build a heartbeat config file" do
78
- open(Master.build_heartbeat_config_file_for(@master.nodes.first)).read.should =~ /\nnode node0\nnode node1/
79
- end
80
- it "should be able to say if heartbeat is necessary with more than 1 server or not" do
81
- Master.requires_heartbeat?.should == true
82
- end
83
- it "should be able to say that heartbeat is not necessary if there is 1 server" do
84
- @master.stub!(:list_of_nonterminated_instances).and_return([
85
- {:instance_id => "i-5849ba", :ip => "ip-127-0-0-1.aws.amazon.com", :status => "running"}
86
- ])
87
- Master.requires_heartbeat?.should == false
88
- end
89
- it "should only install the stack on nodes that don't have it marked locally as installed" do
90
- @master.nodes.each {|i| i.should_receive(:stack_installed?).and_return(true)}
91
- @master.should_not_receive(:reconfigure_running_instances)
92
- @master.reconfigure_cloud_when_necessary
93
- end
94
- it "should install the stack on all the nodes (because it needs reconfiguring) if there is any node that needs the stack" do
95
- @master.nodes.first.should_receive(:stack_installed?).and_return(false)
96
- @master.should_receive(:reconfigure_running_instances).once.and_return(true)
97
- @master.reconfigure_cloud_when_necessary
98
- end
99
- end
100
- describe "displaying" do
101
- it "should be able to list the cloud instances" do
102
- @master.list.should =~ /CLOUD \(/
103
- end
104
- end
105
- describe "monitoring" do
106
- it "should start the monitor when calling start_monitor!" do
107
- @master.should_receive(:run_thread_loop).and_return(Proc.new {})
108
- @master.start_monitor!
109
- end
110
- it "should request to launch a new instance" do
111
- @master.should_receive(:add_instance_if_load_is_high).and_return(true)
112
- @master.add_instance_if_load_is_high
113
- end
114
- it "should request to terminate a non-master instance if the load" do
115
- @master.should_receive(:contract?).and_return(true)
116
- @master.should_receive(:request_termination_of_instance).and_return(true)
117
- @master.terminate_instance_if_load_is_low
118
- end
119
- end
120
- describe "expanding and contracting" do
121
- it "should be able to say that it should not contract" do
122
- @master.stub!(:web_requests).and_return(10.2)
123
- @master.stub!(:cpu_usage).and_return(0.32)
124
-
125
- @master.contract?.should == false
126
- end
127
- it "should be able to say that it should contract" do
128
- @master.stub!(:web_requests).and_return(30.2)
129
- @master.stub!(:cpu_usage).and_return(0.05)
130
-
131
- @master.contract?.should == true
132
- end
133
- it "should be able to say that it should not expand if it shouldn't expand" do
134
- @master.stub!(:web_requests).and_return(30.2)
135
- @master.stub!(:cpu_usage).and_return(0.92)
136
-
137
- @master.expand?.should == false
138
- end
139
- it "should be able to say that it should expand if it should expand" do
140
- @master.stub!(:web_requests).and_return(1.2)
141
- @master.stub!(:cpu_usage).and_return(0.92)
142
-
143
- @master.expand?.should == true
144
- end
145
- end
146
- end
147
- end
@@ -1,16 +0,0 @@
1
- require File.dirname(__FILE__) + '/spec_helper'
2
-
3
- describe "monitors" do
4
- it "should web monitor should be able to extract the amount of the requests it can handle" do
5
- str = "Request rate: 1.5 req/s (649.9 ms/req)"
6
- Monitors::Web.monitor_from_string(str).should == 1.5
7
- end
8
- it "should be able to monitor the percentage of memory available on the server" do
9
- str = "Mem: 1700 56 1644 0 2 18"
10
- Monitors::Memory.monitor_from_string(str).to_s.should =~ /0.032/
11
- end
12
- it "should be able to show the load on the cpu available on the server" do
13
- str = "18:55:31 up 5 min, 1 user, load average: 0.32, 0.03, 0.00"
14
- Monitors::Cpu.monitor_from_string(str).should == 0.32
15
- end
16
- end
@@ -1,22 +0,0 @@
1
- require File.dirname(__FILE__) + '/spec_helper'
2
-
3
- describe "Optioner with options" do
4
- it "should be able to pull out the lonely arguments without any switches" do
5
- Optioner.parse("hello".split(" ")).should == ["hello"]
6
- end
7
- it "should be able to pull out the lonely arguments with switches" do
8
- Optioner.parse("-s 30.seconds -m hello world".split(" ")).should == ["world"]
9
- end
10
- it "should be able to pull out start from the the string" do
11
- Optioner.parse("-c 'config/config.yml' -A 'Who' -S 'DarkwingDuck' list".split(" ")).should == ["list"]
12
- end
13
- it "should be able to pull out the lonely arguments with optional argument switches" do
14
- Optioner.parse("-s 30 -q -n start".split(" "), %w(-q -n)).should == ["start"]
15
- end
16
- it "should pull out the lonely arguments if none are there" do
17
- Optioner.parse("-s 30 -q".split(" ")).should == []
18
- end
19
- it "should pull out empty array if there are no lonely arguments" do
20
- Optioner.parse("-s 30".split(" ")).should == []
21
- end
22
- end
@@ -1,8 +0,0 @@
1
- require File.dirname(__FILE__) + '/spec_helper'
2
-
3
- describe "Application options" do
4
- it "should parse and use a config file if it is given for the options" do
5
- YAML.should_receive(:load).and_return({:config_file => "config/config.yml"})
6
- Application.make_options(:config_file => "config/config.yml")
7
- end
8
- end
@@ -1,29 +0,0 @@
1
- require File.dirname(__FILE__) + '/spec_helper'
2
-
3
- describe "remote instance" do
4
- before(:each) do
5
- @instance = RemoteInstance.new({:ip => "127.0.0.1"})
6
- @instance.stub!(:ssh).and_return "true"
7
- @instance.stub!(:scp).and_return "true"
8
- end
9
-
10
- describe "in general" do
11
- it "should set the ip upon creation" do
12
- @instance.ip.should == "127.0.0.1"
13
- end
14
- it "should be able to tell if it is the master or not" do
15
- @instance.master?.should == true
16
- end
17
- it "should be able to build a list of the heartbeat nodes" do
18
- @instance.node_entry.should =~ /node/
19
- end
20
- it "should call configure after it calls install_stack" do
21
- @instance.should_receive(:configure).once.and_return(true)
22
- @instance.install_stack
23
- end
24
- it "should call restart_with_monit after it calls configure" do
25
- @instance.should_receive(:restart_with_monit).once.and_return(true)
26
- @instance.configure
27
- end
28
- end
29
- end
@@ -1,75 +0,0 @@
1
- require File.dirname(__FILE__) + '/spec_helper'
2
-
3
- # RUN THESE ONE AT A TIME
4
- module PoolParty
5
- class Master;include EC2Mock;end
6
- class RemoteInstance; include RemoteInstanceMock;end
7
- end
8
-
9
- describe "Master remoting: " do
10
- before(:each) do
11
- Application.stub!(:environment).and_return("test") # So it daemonizes
12
- Application.stub!(:minimum_instances).and_return(2)
13
- Application.stub!(:maximum_instances).and_return(10)
14
- Application.stub!(:polling_time).and_return(0.3)
15
- Application.stub!(:verbose).and_return(false) # Turn off messaging
16
-
17
- @master = Master.new
18
- end
19
- describe "starting" do
20
- before(:each) do
21
- @master.start_cloud!
22
- end
23
- it "should start the cloud with instances" do
24
- @master.list_of_instances.should_not be_empty
25
- end
26
- it "should start the cloud with running instances" do
27
- @master.list_of_running_instances.should_not be_empty
28
- end
29
- it "should start with the minimum_instances running" do
30
- wait 0.5 # Give the last one time to get to running
31
- @master.list_of_running_instances.size.should == Application.minimum_instances
32
- end
33
- end
34
- describe "maintaining" do
35
- it "should maintain the minimum_instances if one goes down" do
36
- @master.start_cloud!
37
- wait 0.2 # Give the two instances time to boot up
38
- (Application.minimum_instances - @master.number_of_pending_and_running_instances).should == 0
39
-
40
- # Kill one off to test how it handles the response
41
- @master.terminate_instance!(@master.list_of_running_instances[0][:instance_id])
42
- (Application.minimum_instances - @master.number_of_pending_and_running_instances).should == 1
43
- @master.launch_minimum_instances # Assume this runs in the bg process
44
-
45
- (Application.minimum_instances - @master.number_of_pending_and_running_instances).should == 0
46
- @master.number_of_pending_and_running_instances.should == Application.minimum_instances
47
- end
48
- it "should launch a new instance when the load gets too heavy set in the configs" do
49
- @master.stub!(:expand?).and_return true
50
- @master.start_cloud!
51
- wait 0.2 # Give the two instances time to boot up
52
- (Application.minimum_instances - @master.number_of_pending_and_running_instances).should == 0
53
- @master.add_instance_if_load_is_high
54
- @master.nodes.size.should == Application.minimum_instances + 1
55
- end
56
- it "should terminate an instance when the load shows that it's too light" do
57
- @master.stub!(:contract?).and_return true
58
- @master.start_cloud!
59
- @master.request_launch_new_instance
60
- wait 0.5 # Give the two instances time to boot up
61
- @master.terminate_instance_if_load_is_low
62
- @master.number_of_pending_and_running_instances.should == Application.minimum_instances
63
- end
64
- end
65
- describe "configuring" do
66
- it "should call configure on all of the nodes when calling reconfigure_running_instances" do
67
- @master.nodes.each {|a| a.should_receive(:configure).and_return true }
68
- @master.reconfigure_running_instances
69
- end
70
- it "should call restart_with_monit on all of the nodes when calling restart_running_instances_services" do
71
- @master.nodes.each {|a| a.should_receive(:restart_with_monit).and_return true }
72
- @master.restart_running_instances_services
73
- end
74
- end
75
- end
@@ -1,38 +0,0 @@
1
- require File.join(File.dirname(__FILE__), *%w[.. lib pool_party])
2
-
3
- %w(test/spec).each do |library|
4
- begin
5
- require library
6
- rescue
7
- STDERR.puts "== Cannot run test without #{library}"
8
- end
9
- end
10
-
11
- Dir["#{File.dirname(__FILE__)}/helpers/**"].each {|a| require a}
12
-
13
- include PoolParty
14
- extend PoolParty
15
-
16
- Application.verbose = false
17
-
18
- def wait_launch(time=5)
19
- pid = fork {yield}
20
- wait time
21
- Process.kill("INT", pid)
22
- Process.wait(pid, 0)
23
- end
24
-
25
- module Test::Unit::AssertDifference
26
- def assert_difference(object, method = nil, difference = 1)
27
- initial_value = object.send(method)
28
- yield
29
- assert_equal initial_value + difference, object.send(method), "#{object}##{method}"
30
- end
31
-
32
- def assert_no_difference(object, method, &block)
33
- assert_difference object, method, 0, &block
34
- end
35
- end
36
-
37
- Test::Spec::Should.send(:include, Test::Unit::AssertDifference)
38
- Test::Spec::ShouldNot.send(:include, Test::Unit::AssertDifference)
@@ -1,28 +0,0 @@
1
- require File.dirname(__FILE__) + '/spec_helper'
2
-
3
- describe "String" do
4
- before(:each) do
5
- @string = "string"
6
- @string.stub!(:bucket_objects).and_return([])
7
- end
8
- # Dumb test
9
- it "should be able to call bucket_objects on itself" do
10
- @string.should_receive(:bucket_objects)
11
- @string.bucket_objects
12
- end
13
- describe "with config replacements" do
14
- it "should replace those syms in the string" do
15
- ("new :port" ^ {:port => 100}).should == "new 100"
16
- end
17
- it "should be able to detect vars" do
18
- @string=<<-EOC
19
- listen web_proxy 127.0.0.1::client_port
20
- \tserver web1 127.0.0.1::port weight 1 minconn 3 maxconn 6 check inter 30000
21
- EOC
22
- (@string ^ {:client_port => 3000, :port => 3001}).should ==<<-EOO
23
- listen web_proxy 127.0.0.1:3000
24
- \tserver web1 127.0.0.1:3001 weight 1 minconn 3 maxconn 6 check inter 30000
25
- EOO
26
- end
27
- end
28
- end