auser-poolparty 0.1.2 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (199) hide show
  1. data/History.txt +22 -0
  2. data/License.txt +20 -0
  3. data/README.txt +52 -0
  4. data/Rakefile +4 -109
  5. data/bin/cloud +31 -0
  6. data/bin/cloud-add-keypair +23 -0
  7. data/bin/cloud-configure +35 -0
  8. data/bin/cloud-contract +27 -0
  9. data/bin/cloud-expand +27 -0
  10. data/bin/cloud-list +32 -0
  11. data/bin/cloud-maintain +36 -0
  12. data/bin/cloud-provision +30 -0
  13. data/bin/cloud-reconfigure +24 -0
  14. data/bin/cloud-ssh +18 -0
  15. data/bin/cloud-start +29 -0
  16. data/bin/pool +23 -75
  17. data/bin/pool-console +12 -0
  18. data/bin/pool-describe +9 -0
  19. data/bin/pool-list +28 -0
  20. data/bin/pool-provision +34 -0
  21. data/bin/pool-spec +17 -0
  22. data/bin/pool-start +32 -0
  23. data/examples/basic.rb +20 -0
  24. data/examples/plugin_without_plugin_directory.rb +13 -0
  25. data/examples/poolparty.rb +12 -0
  26. data/examples/with_apache_plugin.rb +22 -0
  27. data/generators/poolspec/USAGE +5 -0
  28. data/generators/poolspec/poolspec_generator.rb +65 -0
  29. data/generators/poolspec/templates/pool_spec_template.erb +9 -0
  30. data/lib/erlang/eb_server.erl +27 -0
  31. data/lib/poolparty.rb +40 -116
  32. data/lib/poolparty/base_packages/haproxy.rb +41 -0
  33. data/lib/poolparty/base_packages/heartbeat.rb +43 -0
  34. data/lib/poolparty/base_packages/poolparty.rb +18 -0
  35. data/lib/poolparty/base_packages/ruby.rb +27 -0
  36. data/lib/poolparty/core/array.rb +24 -0
  37. data/lib/{core → poolparty/core}/exception.rb +0 -0
  38. data/lib/{core → poolparty/core}/float.rb +0 -0
  39. data/lib/poolparty/core/hash.rb +29 -0
  40. data/lib/poolparty/core/kernel.rb +34 -0
  41. data/lib/{core → poolparty/core}/module.rb +18 -0
  42. data/lib/poolparty/core/my_open_struct.rb +18 -0
  43. data/lib/poolparty/core/object.rb +54 -0
  44. data/lib/poolparty/core/proc.rb +2 -0
  45. data/lib/poolparty/core/string.rb +72 -0
  46. data/lib/poolparty/core/symbol.rb +8 -0
  47. data/lib/{core → poolparty/core}/time.rb +15 -0
  48. data/lib/poolparty/exceptions/RemoteException.rb +12 -0
  49. data/lib/poolparty/exceptions/ResourceException.rb +7 -0
  50. data/lib/poolparty/exceptions/RuntimeException.rb +7 -0
  51. data/lib/poolparty/exceptions/SpecException.rb +7 -0
  52. data/lib/poolparty/exceptions/TemplateNotFound.rb +7 -0
  53. data/lib/poolparty/helpers/binary.rb +30 -0
  54. data/lib/poolparty/helpers/console.rb +30 -0
  55. data/lib/poolparty/helpers/display.rb +25 -0
  56. data/lib/poolparty/helpers/optioner.rb +61 -0
  57. data/lib/poolparty/helpers/provisioner_base.rb +226 -0
  58. data/lib/poolparty/helpers/provisioners/master.rb +120 -0
  59. data/lib/poolparty/helpers/provisioners/slave.rb +52 -0
  60. data/lib/poolparty/modules/cloud_resourcer.rb +72 -0
  61. data/lib/poolparty/modules/configurable.rb +34 -0
  62. data/lib/poolparty/modules/definable_resource.rb +59 -0
  63. data/lib/poolparty/modules/file_writer.rb +55 -0
  64. data/lib/poolparty/modules/method_missing_sugar.rb +17 -0
  65. data/lib/poolparty/modules/output.rb +13 -0
  66. data/lib/poolparty/modules/pretty_printer.rb +38 -0
  67. data/lib/{core/string.rb → poolparty/modules/s3_string.rb} +5 -29
  68. data/lib/{modules → poolparty/modules}/safe_instance.rb +0 -0
  69. data/lib/poolparty/monitors/base_monitor.rb +16 -0
  70. data/lib/poolparty/net/remote.rb +35 -0
  71. data/lib/poolparty/net/remote_bases/ec2.rb +145 -0
  72. data/lib/poolparty/net/remote_instance.rb +68 -0
  73. data/lib/poolparty/net/remoter.rb +209 -0
  74. data/lib/poolparty/net/remoter_base.rb +117 -0
  75. data/lib/poolparty/plugins/gem_package.rb +39 -0
  76. data/lib/poolparty/plugins/line.rb +76 -0
  77. data/lib/poolparty/plugins/svn.rb +48 -0
  78. data/lib/poolparty/pool/base.rb +74 -0
  79. data/lib/poolparty/pool/cloud.rb +132 -0
  80. data/lib/poolparty/pool/custom_resource.rb +61 -0
  81. data/lib/poolparty/pool/loggable.rb +29 -0
  82. data/lib/poolparty/pool/plugin.rb +42 -0
  83. data/lib/poolparty/pool/plugin_model.rb +48 -0
  84. data/lib/poolparty/pool/pool.rb +55 -0
  85. data/lib/poolparty/pool/resource.rb +235 -0
  86. data/lib/poolparty/pool/resources/class_package.rb +60 -0
  87. data/lib/poolparty/pool/resources/cron.rb +14 -0
  88. data/lib/poolparty/pool/resources/directory.rb +23 -0
  89. data/lib/poolparty/pool/resources/exec.rb +26 -0
  90. data/lib/poolparty/pool/resources/file.rb +23 -0
  91. data/lib/poolparty/pool/resources/gem.rb +14 -0
  92. data/lib/poolparty/pool/resources/host.rb +14 -0
  93. data/lib/poolparty/pool/resources/package.rb +14 -0
  94. data/lib/poolparty/pool/resources/remote_file.rb +20 -0
  95. data/lib/poolparty/pool/resources/service.rb +21 -0
  96. data/lib/poolparty/pool/resources/sshkey.rb +19 -0
  97. data/lib/poolparty/pool/resources/variable.rb +27 -0
  98. data/lib/poolparty/pool/script.rb +21 -0
  99. data/{config/heartbeat_authkeys.conf → lib/poolparty/templates/authkeys} +0 -0
  100. data/lib/poolparty/templates/cib.xml +1 -0
  101. data/lib/poolparty/templates/fileserver.conf +4 -0
  102. data/{config/heartbeat.conf → lib/poolparty/templates/ha.cf} +3 -1
  103. data/{config → lib/poolparty/templates}/haproxy.conf +13 -6
  104. data/lib/poolparty/templates/namespaceauth.conf +19 -0
  105. data/lib/poolparty/templates/puppet.conf +13 -0
  106. data/lib/poolparty/version.rb +9 -0
  107. data/lib/poolpartycl.rb +3 -0
  108. data/script/destroy +14 -0
  109. data/script/generate +14 -0
  110. data/script/txt2html +82 -0
  111. data/{lib/poolparty/tasks → tasks}/cloud.rake +1 -1
  112. data/tasks/deployment.rake +34 -0
  113. data/tasks/development.rake +78 -0
  114. data/{lib/poolparty/tasks → tasks}/ec2.rake +1 -1
  115. data/tasks/environment.rake +7 -0
  116. data/{lib/poolparty/tasks → tasks}/instance.rake +0 -0
  117. data/{lib/poolparty/tasks → tasks}/server.rake +0 -0
  118. data/tasks/spec.rake +17 -0
  119. data/tasks/website.rake +17 -0
  120. metadata +154 -249
  121. data/CHANGELOG +0 -23
  122. data/LICENSE +0 -22
  123. data/README +0 -139
  124. data/assets/clouds.png +0 -0
  125. data/bin/instance +0 -68
  126. data/bin/poolnotify +0 -34
  127. data/config/cloud_master_takeover +0 -17
  128. data/config/create_proxy_ami.sh +0 -582
  129. data/config/installers/ubuntu_install.sh +0 -77
  130. data/config/monit.conf +0 -9
  131. data/config/monit/haproxy.monit.conf +0 -8
  132. data/config/monit/nginx.monit.conf +0 -0
  133. data/config/nginx.conf +0 -24
  134. data/config/reconfigure_instances_script.sh +0 -37
  135. data/config/sample-config.yml +0 -23
  136. data/config/scp_instances_script.sh +0 -12
  137. data/lib/core/array.rb +0 -16
  138. data/lib/core/hash.rb +0 -11
  139. data/lib/core/kernel.rb +0 -12
  140. data/lib/core/object.rb +0 -21
  141. data/lib/core/proc.rb +0 -15
  142. data/lib/helpers/plugin_spec_helper.rb +0 -58
  143. data/lib/modules/callback.rb +0 -133
  144. data/lib/modules/ec2_wrapper.rb +0 -108
  145. data/lib/modules/file_writer.rb +0 -38
  146. data/lib/modules/sprinkle_overrides.rb +0 -27
  147. data/lib/modules/vlad_override.rb +0 -83
  148. data/lib/poolparty/application.rb +0 -199
  149. data/lib/poolparty/init.rb +0 -6
  150. data/lib/poolparty/master.rb +0 -492
  151. data/lib/poolparty/monitors.rb +0 -11
  152. data/lib/poolparty/monitors/cpu.rb +0 -23
  153. data/lib/poolparty/monitors/memory.rb +0 -33
  154. data/lib/poolparty/monitors/web.rb +0 -29
  155. data/lib/poolparty/optioner.rb +0 -20
  156. data/lib/poolparty/plugin.rb +0 -78
  157. data/lib/poolparty/provider.rb +0 -104
  158. data/lib/poolparty/provider/essential.rb +0 -6
  159. data/lib/poolparty/provider/git.rb +0 -8
  160. data/lib/poolparty/provider/haproxy.rb +0 -9
  161. data/lib/poolparty/provider/heartbeat.rb +0 -6
  162. data/lib/poolparty/provider/rsync.rb +0 -8
  163. data/lib/poolparty/provider/ruby.rb +0 -65
  164. data/lib/poolparty/provider/s3fuse.rb +0 -22
  165. data/lib/poolparty/remote_instance.rb +0 -250
  166. data/lib/poolparty/remoter.rb +0 -171
  167. data/lib/poolparty/remoting.rb +0 -137
  168. data/lib/poolparty/scheduler.rb +0 -93
  169. data/lib/poolparty/tasks.rb +0 -47
  170. data/lib/poolparty/tasks/development.rake +0 -78
  171. data/lib/poolparty/tasks/plugins.rake +0 -30
  172. data/lib/poolparty/thread_pool.rb +0 -94
  173. data/lib/s3/s3_object_store_folders.rb +0 -44
  174. data/poolparty.gemspec +0 -71
  175. data/spec/files/describe_response +0 -37
  176. data/spec/files/multi_describe_response +0 -69
  177. data/spec/files/remote_desc_response +0 -37
  178. data/spec/helpers/ec2_mock.rb +0 -57
  179. data/spec/lib/core/core_spec.rb +0 -26
  180. data/spec/lib/core/kernel_spec.rb +0 -24
  181. data/spec/lib/core/string_spec.rb +0 -28
  182. data/spec/lib/modules/callback_spec.rb +0 -213
  183. data/spec/lib/modules/file_writer_spec.rb +0 -74
  184. data/spec/lib/poolparty/application_spec.rb +0 -135
  185. data/spec/lib/poolparty/ec2_wrapper_spec.rb +0 -110
  186. data/spec/lib/poolparty/master_spec.rb +0 -479
  187. data/spec/lib/poolparty/optioner_spec.rb +0 -34
  188. data/spec/lib/poolparty/plugin_spec.rb +0 -115
  189. data/spec/lib/poolparty/poolparty_spec.rb +0 -60
  190. data/spec/lib/poolparty/provider_spec.rb +0 -74
  191. data/spec/lib/poolparty/remote_instance_spec.rb +0 -178
  192. data/spec/lib/poolparty/remoter_spec.rb +0 -72
  193. data/spec/lib/poolparty/remoting_spec.rb +0 -148
  194. data/spec/lib/poolparty/scheduler_spec.rb +0 -70
  195. data/spec/monitors/cpu_monitor_spec.rb +0 -39
  196. data/spec/monitors/memory_spec.rb +0 -51
  197. data/spec/monitors/misc_monitor_spec.rb +0 -51
  198. data/spec/monitors/web_spec.rb +0 -40
  199. data/spec/spec_helper.rb +0 -53
@@ -1,74 +0,0 @@
1
- require File.dirname(__FILE__) + '/../../spec_helper'
2
-
3
- class TestClass
4
- include FileWriter
5
- end
6
- describe "FileWriter" do
7
- before(:each) do
8
- # Application.reset!
9
- @instance = RemoteInstance.new
10
- @instance.stub!(:name).and_return "node0"
11
- @instance.stub!(:ip).and_return "127.0.0.1"
12
- @test = TestClass.new
13
- end
14
- describe "writing to the temp directory with a string" do
15
- before(:each) do
16
- @test.write_to_file_for("haproxy", @instance, "topical")
17
- @outfile = "#{@test.base_tmp_dir}/node0-haproxy"
18
- end
19
- after(:each) do
20
- FileUtils.rm @outfile
21
- end
22
- it "should be able to write a file to the tmp directory with a string" do
23
- File.file?(@outfile).should == true
24
- end
25
- it "should be able to write to the file with the string" do
26
- open(@outfile).read.should == "topical"
27
- end
28
- end
29
-
30
- describe "writing to the temp directory with a block" do
31
- before(:each) do
32
- @test.write_to_file_for("haproxy", @instance) do
33
- "Hello topical"
34
- end
35
- @outfile = "#{@test.base_tmp_dir}/node0-haproxy"
36
- end
37
- after(:each) do
38
- FileUtils.rm @outfile
39
- end
40
- it "should be able to write a file to the tmp directory with a string" do
41
- File.file?(@outfile).should == true
42
- end
43
- it "should be able to write to the file with the string" do
44
- open(@outfile).read.should == "Hello topical"
45
- end
46
- describe "for output of block" do
47
- before(:each) do
48
- @test.write_to_file_for("haproxy", @instance) do
49
- "Fix and me"
50
- "Hello topical"
51
- end
52
- end
53
- it "should just write the final output of the block to the file" do
54
- open(@outfile).read.should == "Hello topical"
55
- end
56
- end
57
- end
58
-
59
- describe "without a node" do
60
- before(:each) do
61
- @test.write_to_file_for("haproxy") do
62
- "Hello topical"
63
- end
64
- @outfile = "#{@test.base_tmp_dir}/haproxy"
65
- end
66
- after(:each) do
67
- FileUtils.rm @outfile
68
- end
69
- it "should write to the master file without a node name" do
70
- File.file?(@outfile).should == true
71
- end
72
- end
73
-
74
- end
@@ -1,135 +0,0 @@
1
- require File.dirname(__FILE__) + '/../../spec_helper'
2
-
3
- describe "Application" do
4
- before(:each) do
5
- stub_option_load
6
- Application.reset!
7
- Application.stub!(:keypair).and_return("testappkeypair")
8
- end
9
- describe "command line options" do
10
- it "should destroy the default options with the commandline options" do
11
- ARGV << ["-k", "testappkeypair"]
12
- ARGV.should_receive(:dup).and_return ARGV
13
- PoolParty.options.keypair.should == "testappkeypair"
14
- end
15
- end
16
- it "should have the root_dir defined" do
17
- PoolParty.root_dir.should_not be_nil
18
- end
19
- it "should be able to call on the haproxy_config_file" do
20
- Application.haproxy_config_file.should_not be_nil
21
- end
22
- it "should be able to find the client_port" do
23
- Application.options.should_receive(:client_port).and_return(7788)
24
- Application.client_port.should == 7788
25
- end
26
- it "should always have cloud_master_takeover in the managed services list" do
27
- Application.master_managed_services.should =~ /cloud_master_takeover/
28
- end
29
- it "should be able to say it is in development mode if it is in dev mode" do
30
- Application.stub!(:environment).and_return("development")
31
- Application.development?.should == true
32
- end
33
- it "should be able to say it is in production if it is in production" do
34
- Application.stub!(:environment).and_return("production")
35
- Application.production?.should == true
36
- end
37
- describe "keypair" do
38
- before(:each) do
39
- Application.stub!(:ec2_dir).and_return("~/.ec2")
40
- Application.stub!(:keypair).and_return("poolparty")
41
- end
42
- it "should be able to say it's keypair path is in the $HOME/ directory" do
43
- Application.keypair_path.should == "~/.ec2/id_rsa-poolparty"
44
- end
45
- it "should be able to say the keypair is of the structure id_rsa-keyname" do
46
- Application.keypair_name.should == "id_rsa-poolparty"
47
- end
48
- end
49
- it "should be able to show the version of the gem" do
50
- Application.version.should_not be_nil
51
- end
52
- it "should show the version as a string" do
53
- Application.version.class.should == String
54
- end
55
- describe "User data" do
56
- before(:each) do
57
- @str = ":access_key: 3.14159\n:secret_access_key: pi"
58
- Application.options = nil
59
- Application.stub!(:open).with("http://169.254.169.254/latest/user-data").and_return(@str)
60
- @str.stub!(:read).and_return ":access_key: 3.14159\n:secret_access_key: pi"
61
- end
62
- describe "added data keypair_path" do
63
- before(:each) do
64
- @str.stub!(:read).and_return ":access_key: 3.14159\n:secret_access_key: pi\n:keypair_path: hopscotch"
65
- end
66
- it "should use the options keypair_path if it exists" do
67
- Application.keypair_path.should == "hopscotch"
68
- end
69
- end
70
- it "should try to load the user data into a yaml hash" do
71
- YAML.should_receive(:load).with(":access_key: 3.14159\n:secret_access_key: pi")
72
- Application.local_user_data
73
- end
74
- it "should be able to start instances with the the key access information on the user-data" do
75
- Application.launching_user_data.should =~ /:access_key/
76
- Application.launching_user_data.should =~ /:secret_access_key/
77
- end
78
- it "should be able to pull out the access_key from the user data" do
79
- Application.local_user_data[:access_key].should == 3.14159
80
- end
81
- it "should be able tp pull out the secret_access_key from the user-data" do
82
- Application.local_user_data[:secret_access_key].should == "pi"
83
- end
84
- it "should not have the application name in the user-data" do
85
- Application.local_user_data[:application_name].should be_nil
86
- end
87
- it "should have the application_name in the options even though it is nil in the application" do
88
- Application.options.app_name.should_not be_nil
89
- end
90
- it "should overwrite the default_options when passing in to the instance data" do
91
- Application.stub!(:default_options).and_return({:access_key => 42})
92
- Application.options.access_key.should == 3.14159
93
- end
94
- it "should have the required lauching hash" do
95
- Application.hash_to_launch_with.should == {:access_key=>3.14159, :keypair_path=>"/mnt", :keypair=>"testappkeypair", :secret_access_key=>"pi", :user_data=>"", :polling_time=>"30.seconds"}
96
- end
97
- it "should create the hash_to_launch_with a YAML string" do
98
- Application.launching_user_data.should == Application.hash_to_launch_with.to_yaml
99
- end
100
- end
101
- it "should parse and use a config file if it is given for the options" do
102
- YAML.should_receive(:load).at_least(1).and_return({:config_file => "config/sample-config.yml"})
103
- Application.make_options(:config_file => "config/sample-config.yml")
104
- end
105
- describe "config file" do
106
- before(:each) do
107
- @str = ":access_key: 3.14159\n:secret_access_key: pi"
108
- Application.options = nil
109
- @str.stub!(:read).and_return ":access_key: 3.14159\n:secret_access_key: pi"
110
- Application.make_options
111
- end
112
- it "should read the config file and use the options in the config file if it exists" do
113
- Application.access_key.should == 3.14159
114
- end
115
- it "should set the secret_access_key if the config file exists" do
116
- Application.secret_access_key.should == "pi"
117
- end
118
- end
119
- it "should not read the config file if it is not passed and doesn't exist" do
120
- File.stub!(:file?).and_return false
121
- YAML.should_not_receive(:load).with("config/config.yml")
122
- Application.make_options
123
- end
124
- it "should not read the config file if it is passed and doesn't exist" do
125
- File.stub!(:file?).and_return false
126
- YAML.should_not_receive(:load).with("config/config.yml")
127
- Application.make_options(:config_file => "ted")
128
- end
129
- describe "defaults" do
130
- it "should if EC2_HOME ENV is empty, then default to ~/.ec2" do
131
- Application.make_options
132
- Application.ec2_dir.should =~ /\/\.ec2/
133
- end
134
- end
135
- end
@@ -1,110 +0,0 @@
1
- require File.dirname(__FILE__) + '/../../spec_helper'
2
- require File.dirname(__FILE__) + "/../../helpers/ec2_mock"
3
-
4
- class EC2Test
5
- include Ec2Wrapper
6
-
7
- def get_non_empty_instance_description
8
- @resp ||= EC2::Response.parse(:xml => read_file("describe_response"))
9
- end
10
- def get_non_empty_instances_description
11
- @resp2 ||= EC2::Response.parse(:xml => read_file("multi_describe_response"))
12
- end
13
- def get_remote_inst_desc
14
- @resp3 = EC2::Response.parse(:xml => read_file("remote_desc_response"))
15
- end
16
- def read_file(name)
17
- open("#{File.dirname(__FILE__)}/../../files/#{name}").read
18
- end
19
- end
20
- describe "EC2ResponseObject" do
21
- before(:each) do
22
- @test = EC2Test.new
23
- @r = @test.get_non_empty_instance_description
24
- @rs = @test.get_non_empty_instances_description
25
- @rst = @test.get_remote_inst_desc
26
- end
27
- describe "single instance" do
28
- it "should be able to get the response object from the query" do
29
- EC2ResponseObject.get_response_from(@r).should_not be_nil
30
- end
31
- it "should return an EC2:Response from EC2ResponseObject.get_response_from" do
32
- EC2ResponseObject.get_response_from(@r).class.should == EC2::Response
33
- end
34
- it "should be able to grab the keypair name from the response object" do
35
- EC2ResponseObject.get_response_from(@r).instancesSet.item.instanceId.should == "i-60bc6a09"
36
- end
37
- it "should be able to list out the running instances" do
38
- EC2ResponseObject.get_descriptions(@r)
39
- end
40
- it "should return an array of instances" do
41
- EC2ResponseObject.get_descriptions(@r).class.should == Array
42
- end
43
- it "should be able to iterate through the instances" do
44
- EC2ResponseObject.get_descriptions(@r).select {|a| a[:keypair] == "auser"}.should_not be_empty
45
- end
46
- end
47
- describe "multiple responses" do
48
- it "should be able to get the response object from the query" do
49
- EC2ResponseObject.get_response_from(@r).should_not be_nil
50
- end
51
- it "should return an EC2:Response from EC2ResponseObject.get_response_from" do
52
- EC2ResponseObject.get_response_from(@r).class.should == EC2::Response
53
- end
54
- it "should be able to grab the keypair name from the response object" do
55
- EC2ResponseObject.get_response_from(@r).instancesSet.item.instanceId.should == "i-60bc6a09"
56
- end
57
- it "should be able to list out the running instances" do
58
- EC2ResponseObject.get_descriptions(@r)
59
- end
60
- it "should return an array of instances" do
61
- EC2ResponseObject.get_descriptions(@r).class.should == Array
62
- end
63
- it "should be able to iterate through the instances" do
64
- EC2ResponseObject.get_descriptions(@r).select {|a| a[:keypair] == "auser"}.should_not be_empty
65
- end
66
- end
67
- describe "multiple responses" do
68
- it "should be able to get the response object from the query" do
69
- EC2ResponseObject.get_response_from(@rst).should_not be_nil
70
- end
71
- it "should return an EC2:Response from EC2ResponseObject.get_response_from" do
72
- EC2ResponseObject.get_response_from(@rst).class.should == EC2::Response
73
- end
74
- it "should be able to grab the keypair name from the response object" do
75
- EC2ResponseObject.get_response_from(@rst).instancesSet.item.instanceId.should == "i-94f82efd"
76
- end
77
- it "should be able to list out the running instances" do
78
- EC2ResponseObject.get_descriptions(@rst)
79
- end
80
- it "should return an array of instances" do
81
- EC2ResponseObject.get_descriptions(@rst).class.should == Array
82
- end
83
- it "should be able to iterate through the instances" do
84
- EC2ResponseObject.get_descriptions(@rst).select {|a| a[:keypair] == "auser"}.should_not be_empty
85
- end
86
- end
87
- describe "launching" do
88
- before(:each) do
89
- @test.ec2.stub!(:run_instances).and_return true
90
- end
91
- it "should launch with the ami" do
92
- Application.should_receive(:ami).once.and_return("ami-abcdefg")
93
- end
94
- it "should with the user data" do
95
- Application.should_receive(:launching_user_data).once.and_return("")
96
- end
97
- it "should launch with the Application keypair" do
98
- Application.should_receive(:keypair)
99
- end
100
- it "should launch with the requested size" do
101
- Application.should_receive(:size)
102
- end
103
- it "should try to run the instances" do
104
- @test.ec2.should_receive(:run_instances)
105
- end
106
- after do
107
- @test.launch_new_instance!
108
- end
109
- end
110
- end
@@ -1,479 +0,0 @@
1
- require File.dirname(__FILE__) + '/../../spec_helper'
2
- require File.dirname(__FILE__) + '/../../helpers/ec2_mock'
3
-
4
- describe "Master" do
5
- before(:each) do
6
- stub_option_load
7
- Kernel.stub!(:system).and_return true
8
- Kernel.stub!(:exec).and_return true
9
- Kernel.stub!(:sleep).and_return true # WHy wait?, just do it
10
-
11
- Application.options
12
-
13
- Application.options.stub!(:contract_when).and_return("web > 30.0\n cpu > 0.80")
14
- Application.options.stub!(:expand_when).and_return("web < 3.0\n cpu > 0.80")
15
- @master = Master.new
16
- end
17
- after(:all) do
18
- @master.cleanup_tmp_directory(nil)
19
- end
20
- it "should launch the first instances and set the first as the master and the rest as slaves" do
21
- Application.stub!(:minimum_instances).and_return(1)
22
- Application.stub!(:verbose).and_return(false) # Hide messages
23
- Master.stub!(:new).and_return(@master)
24
-
25
- @master.stub!(:number_of_running_instances).and_return(0);
26
- @master.stub!(:number_of_pending_instances).and_return(0);
27
- @master.stub!(:wait).and_return true
28
-
29
- @master.should_receive(:launch_new_instance!).and_return(
30
- {:instance_id => "i-5849ba", :ip => "127.0.0.1", :status => "running"})
31
- @master.stub!(:list_of_nonterminated_instances).and_return(
32
- [{:instance_id => "i-5849ba", :ip => "127.0.0.1", :status => "running"}])
33
-
34
- node = RemoteInstance.new({:instance_id => "i-5849ba", :ip => "127.0.0.1", :status => "running"})
35
- node.stub!(:scp).and_return "true"
36
- node.stub!(:ssh).and_return "true"
37
-
38
- @master.stub!(:number_of_pending_instances).and_return(0)
39
- @master.stub!(:get_node).with(0).and_return node
40
- @master.start_cloud!
41
-
42
- @master.nodes.first.instance_id.should == "i-5849ba"
43
- end
44
- describe "Singleton methods" do
45
- before(:each) do
46
- @master = Master.new
47
- @instance = RemoteInstance.new
48
- @instance.stub!(:ip).and_return "127.0.0.1"
49
- @blk = Proc.new {puts "new"}
50
- Master.stub!(:new).once.and_return @master
51
- end
52
- it "should be able to run with_nodes" do
53
- Master.should_receive(:new).once.and_return @master
54
- @master.should_receive(:nodes).once.and_return []
55
- Master.with_nodes &@blk
56
- end
57
- it "should run the block on each node" do
58
- collection = [@instance]
59
- @master.should_receive(:nodes).once.and_return collection
60
- collection.should_receive(:each).once
61
- Master.with_nodes &@blk
62
- end
63
- end
64
- describe "with stubbed instances" do
65
- before(:each) do
66
- @master.stub!(:list_of_nonterminated_instances).and_return([
67
- {:instance_id => "i-5849ba", :ip => "127.0.0.1", :status => "running"},
68
- {:instance_id => "i-5849bb", :ip => "127.0.0.2", :status => "running"},
69
- {:instance_id => "i-5849bc", :ip => "127.0.0.3", :status => "pending"}
70
- ])
71
- Kernel.stub!(:exec).and_return true
72
- @instance = RemoteInstance.new
73
- @instance.stub!(:ip).and_return("127.0.0.1")
74
- @instance.stub!(:name).and_return("node0")
75
- end
76
-
77
- it "should be able to go through the instances and assign them numbers" do
78
- i = 0
79
- @master.nodes.each do |node|
80
- node.number.should == i
81
- i += 1
82
- end
83
- end
84
- it "should be able to say that the master is the master" do
85
- @master.nodes.first.master?.should == true
86
- end
87
- it "should be able to say that the slave is not a master" do
88
- @master.nodes[1].master?.should == false
89
- end
90
- it "should be able to get a specific node in the nodes from the master" do
91
- @master.get_node(2).instance_id.should == "i-5849bc"
92
- end
93
- it "should be able to get the next node" do
94
- @master.get_next_node(@instance).instance_id.should == "i-5849bb"
95
- end
96
- it "should be able to build a hosts file" do
97
- open(@master.build_hosts_file_for(@instance).path).read.should == "127.0.0.1 node0\n127.0.0.1 localhost.localdomain localhost ubuntu\n127.0.0.2 node1\n127.0.0.3 node2"
98
- end
99
- it "should be able to build a hosts file for a specific instance" do
100
- open(@master.build_hosts_file_for(@instance).path).read.should =~ /127\.0\.0\.1 node0/
101
- end
102
- it "should be able to build a haproxy file" do
103
- open(@master.build_haproxy_file.path).read.should =~ /server node0 127\.0\.0\.1:#{Application.client_port}/
104
- end
105
- it "should be able to reconfigure the instances (working on two files a piece)" do
106
- @master.should_receive(:remote_configure_instances).and_return true
107
- @master.stub!(:number_of_unconfigured_nodes).and_return 1
108
- @master.reconfigure_cloud_when_necessary
109
- end
110
- it "should return the number of unconfigured nodes when asked" do
111
- @master.nodes.each {|node| node.stub!(:stack_installed?).and_return(node.master? ? false : true) }
112
- @master.number_of_unconfigured_nodes.should == 1
113
- end
114
- it "should be able to return the size of the cloud" do
115
- @master.nodes.size.should == 3
116
- end
117
- # it "should be able to restart the running instances' services" do
118
- # @master.nodes.each {|a| a.should_receive(:restart_with_monit).and_return true }
119
- # @master.restart_running_instances_services
120
- # end
121
- it "should be able to build a heartbeat auth file" do
122
- open(@master.build_and_copy_heartbeat_authkeys_file.path).read.should =~ /1 md5/
123
- end
124
- describe "configuration" do
125
- describe "sending configuration files" do
126
- before(:each) do
127
- Master.stub!(:new).and_return(@master)
128
- @master.stub!(:ssh)
129
- @master.stub!(:scp)
130
- @master.nodes.each do |node|
131
- node.stub!(:ssh)
132
- node.stub!(:scp)
133
- node.stub!(:stack_installed?).and_return true
134
- end
135
- end
136
- it "should be able to build a heartbeat resources file for the specific node" do
137
- open(@master.build_heartbeat_resources_file_for(@master.nodes.first).path).read.should == "node0 127.0.0.1\nnode1 127.0.0.2"
138
- end
139
- it "should be able to build a heartbeat config file" do
140
- open(@master.build_heartbeat_config_file_for(@master.nodes.first).path).read.should =~ /\nnode node0\nnode node1/
141
- end
142
- it "should be able to say if heartbeat is necessary with more than 1 server or not" do
143
- Master.requires_heartbeat?.should == true
144
- end
145
- it "should be able to say that heartbeat is not necessary if there is 1 server" do
146
- @master.stub!(:nodes).and_return([
147
- {:instance_id => "i-5849ba", :ip => "127.0.0.1", :status => "running"}
148
- ])
149
- Master.requires_heartbeat?.should == false
150
- end
151
- it "should only install the stack on nodes that don't have it marked locally as installed" do
152
- @master.nodes.each {|i| i.should_receive(:stack_installed?).at_least(1).and_return(true)}
153
- @master.should_not_receive(:reconfigure_running_instances)
154
- @master.reconfigure_cloud_when_necessary
155
- end
156
- it "should install the stack on all the nodes (because it needs reconfiguring) if there is any node that needs the stack" do
157
- @master.nodes.first.should_receive(:stack_installed?).at_least(1).and_return(false)
158
- @master.should_receive(:configure_cloud).once.and_return(true)
159
- @master.reconfigure_cloud_when_necessary
160
- end
161
- describe "rsync'ing the files to the instances" do
162
- it "should cleanup the tmp directory before sending configuration to the nodes" do
163
- @master.should_receive(:cleanup_tmp_directory).at_least(1)
164
- @master.build_and_send_config_files_in_temp_directory
165
- end
166
- it "should receive send_config_files_to_nodes after it builds the config files in the temp directory" do
167
- @master.should_receive(:send_config_files_to_nodes).at_least(1)
168
- @master.build_and_send_config_files_in_temp_directory
169
- end
170
- it "should run_array_of_tasks(scp_tasks)" do
171
- @master.should_receive(:run_array_of_tasks).at_least(1).and_return true
172
- @master.build_and_send_config_files_in_temp_directory
173
- end
174
- it "should compile a list of files to rsync" do
175
- @master.stub!(:run_array_of_tasks).and_return true
176
- @master.rsync_tasks("#{@master.base_tmp_dir}", "tmp")[0].should =~ /rsync/
177
- end
178
- end
179
- describe "remote configuration" do
180
- before(:each) do
181
- @master.stub!(:nodes).and_return [@instance]
182
- end
183
- it "should call remote_configure_instances when configuring" do
184
- @master.should_receive(:remote_configure_instances).and_return true
185
- @master.configure_cloud
186
- end
187
- it "should change the configuration script into an executable and run it" do
188
- @master.should_receive(:run_array_of_tasks).and_return true
189
- @master.remote_configure_instances
190
- end
191
- end
192
-
193
- end
194
- end
195
- describe "installation" do
196
- it "should not install on the instances if the application doesn't say it should" do
197
- Application.stub!(:install_on_load?).and_return false
198
- Provider.should_not_receive(:install_poolparty)
199
- @master.install_cloud
200
- end
201
- describe "when asked" do
202
- before(:each) do
203
- Application.stub!(:install_on_load?).and_return true
204
- Sprinkle::Script.stub!(:sprinkle).and_return true
205
- Provider.stub!(:install_poolparty).and_return true
206
- @master.stub!(:ssh).and_return true
207
- @master.nodes.each do |node|
208
- node.stub!(:run_now).and_return true
209
- end
210
- end
211
- after(:all) do
212
- Kernel.system("ssh-add -d #{Application.keypair_path} >/dev/null 2>/dev/null")
213
- end
214
- it "should install on the instances if the application says it should" do
215
- Provider.should_receive(:install_poolparty)
216
- @master.install_cloud
217
- end
218
- it "should execute the remote tasks on all of the instances" do
219
- @master.should_receive(:ssh).and_return true
220
- @master.install_cloud
221
- end
222
- it "should store the ssh keypair before install" do
223
- Kernel.should_receive(:system).with("ssh-add #{Application.keypair_path} >/dev/null 2>/dev/null").at_least(1).and_return true
224
- @master.install_cloud
225
- end
226
- it "should delete the ssh keypair after configure_cloud" do
227
- Kernel.should_receive_at_least_once(:system).with("ssh-add -d #{Application.keypair_name} >/dev/null 2>/dev/null").and_return true
228
- @master.configure_cloud
229
- end
230
- describe "stubbing installation" do
231
- before(:each) do
232
- @master.stub!(:execute_tasks).and_return true
233
- end
234
- it "should install poolparty" do
235
- Provider.should_receive(:install_poolparty).and_return true
236
- @master.install_cloud
237
- end
238
- it "should install the user packages" do
239
- Provider.should_receive(:install_poolparty).and_return true
240
- @master.install_cloud
241
- end
242
- end
243
- end
244
- end
245
- describe "displaying" do
246
- it "should be able to list the cloud instances" do
247
- @master.list.should =~ /CLOUD \(/
248
- end
249
- end
250
- it "should be able to grab a list of the instances" do
251
- @master.cloud_ips.should == %w(127.0.0.1 127.0.0.2 127.0.0.3)
252
- end
253
- describe "starting" do
254
- before(:each) do
255
- Kernel.stub!(:sleep).and_return true
256
- end
257
- it "should request to launch the minimum number of instances" do
258
- Application.stub!(:minimum_instances).and_return 3
259
- @master.stub!(:number_of_pending_and_running_instances).and_return 1
260
- @master.should_receive(:request_launch_new_instances).with(2).and_return true
261
- @master.launch_minimum_instances
262
- end
263
- end
264
- describe "monitoring" do
265
- it "should start the monitor when calling start_monitor!" do
266
- @master.should_receive(:run_thread_loop).and_return(Proc.new {})
267
- @master.start_monitor!
268
- end
269
- it "should request to launch a new instance" do
270
- @master.should_receive(:add_instance_if_load_is_high).and_return(true)
271
- @master.add_instance_if_load_is_high
272
- end
273
- it "should request to terminate a non-master instance if the load" do
274
- @master.should_receive(:contract?).and_return(true)
275
- @master.should_receive(:request_termination_of_instance).and_return(true)
276
- @master.terminate_instance_if_load_is_low
277
- end
278
- it "should launch the minimum_instances when the minimum aren't launched"
279
- it "should reconfigure the cloud if it's necessary to do so"
280
- it "should try to scale the cloud when monitoring"
281
- it "should check the stats of the cloud"
282
- end
283
- describe "expanding and contracting" do
284
- before(:each) do
285
- Application.options.stub!(:contract_when).and_return("web > 30.0\n cpu > 0.80")
286
- Application.options.stub!(:expand_when).and_return("web < 3.0\n cpu > 0.80")
287
- end
288
- it "should be able to say that it should not contract" do
289
- @master.stub!(:web).and_return(10.2)
290
- @master.stub!(:cpu).and_return(0.32)
291
-
292
- @master.contract?.should == false
293
- end
294
- # This works when run inside textmate or individually, but does not work
295
- # when run solo using rake spec
296
- it "should be able to say that it should contract"
297
- # @master.should_receive(:cpu).at_least(1).and_return(0.95)
298
- # @master.should_receive(:web).at_least(1).and_return(35.2)
299
- #
300
- # @master.contract?.should == true
301
- # end
302
- it "should be able to say that it should not expand if it shouldn't expand" do
303
- @master.stub!(:web).and_return(30.2)
304
- @master.stub!(:cpu).and_return(0.92)
305
-
306
- @master.expand?.should == false
307
- end
308
- # This works when run inside textmate or individually, but does not work
309
- # when run solo using rake spec
310
- it "should be able to say that it should expand if it should expand"
311
- # @master.stub!(:web).and_return(1.2)
312
- # @master.stub!(:cpu).and_return(0.92)
313
- #
314
- # @master.should_receive(:web).once.and_return(1.2)
315
- # @master.expand?.should == true
316
- # end
317
- describe "scaling" do
318
- before(:each) do
319
- Kernel.stub!(:sleep).and_return true
320
- @master.stub!(:wait_for_all_instances_to_boot).and_return true
321
- @master.stub!(:wait_for_all_instances_to_terminate).and_return true
322
- end
323
- it "should try to add a new instance" do
324
- @master.should_receive(:add_instance_if_load_is_high).and_return true
325
- @master.scale_cloud!
326
- end
327
- it "should try to terminate an instance" do
328
- @master.should_receive(:terminate_instance_if_load_is_low).and_return true
329
- @master.scale_cloud!
330
- end
331
- it "should try to grow the cloud by 1 node when asked" do
332
- @master.should_receive(:request_launch_new_instances).once.and_return true
333
- @master.should_receive(:configure_cloud).once.and_return true
334
- @master.grow_by(1)
335
- end
336
- it "should try to shrink the cloud by 1 when asked" do
337
- @master.should_receive(:request_termination_of_instance).and_return true
338
- @master.should_receive(:configure_cloud).and_return true
339
- @master.shrink_by(1)
340
- end
341
- end
342
- end
343
- describe "Configuration" do
344
- before(:each) do
345
- @instance = RemoteInstance.new
346
- end
347
- it "should be able to build the haproxy file" do
348
- @master.build_haproxy_file
349
- end
350
- describe "by copying files to the poolpartytmp directory" do
351
- it "should build and copy files to the tmp directory" do
352
- @master.build_and_send_config_files_in_temp_directory
353
- File.directory?(@master.base_tmp_dir).should == true
354
- end
355
- it "should copy the cloud_master_takeover script to the tmp directory" do
356
- @master.should_not_receive(:get_config_file_for)
357
- @master.build_and_send_config_files_in_temp_directory
358
- end
359
- it "should tar the plugin_dir into the tmp directory" do
360
- FileUtils.mkdir_p Application.plugin_dir rescue ""
361
-
362
- Kernel.should_receive(:system).with("tar -czf #{@master.base_tmp_dir}/plugins.tar.gz #{File.basename(Application.plugin_dir)}").and_return true
363
- @master.build_and_send_config_files_in_temp_directory
364
- end
365
- it "should try to copy the pem files" do
366
- @master.should_receive(:copy_pem_files_to_tmp_dir).and_return true
367
- @master.build_and_send_config_files_in_temp_directory
368
- end
369
- it "should try to copy the cert file"
370
- it "should try the copy the pk file"
371
- describe "get configs" do
372
- before(:each) do
373
- @master.stub!(:user_dir).and_return("user")
374
- @master.stub!(:root_dir).and_return("root")
375
- end
376
- it "should try to get the config file in the user directory before the root_dir" do
377
- File.should_receive(:exists?).with("#{@master.user_dir}/config/config.yml").and_return true
378
- @master.get_config_file_for("config.yml").should == "user/config/config.yml"
379
- end
380
- it "should try to get the config file in the root directory if it doesn't exist in the user directory" do
381
- File.should_receive(:exists?).with("#{@master.user_dir}/config/config.yml").and_return false
382
- @master.get_config_file_for("config.yml").should == "root/config/config.yml"
383
- end
384
- end
385
- it "should copy the config file if it exists" do
386
- Application.stub!(:config_file).and_return "config.yml"
387
- File.stub!(:exists?).and_return true
388
- File.should_receive(:copy).at_least(2).times.and_return true
389
- @master.build_and_send_config_files_in_temp_directory
390
- end
391
- describe "with copy_config_files_in_directory_to_tmp_dir method" do
392
- before(:each) do
393
- @instance2 = RemoteInstance.new
394
- @instance2.stub!(:ip).and_return "127.0.0.2"
395
- Master.stub!(:new).and_return @master
396
- @master.stub!(:nodes).and_return [@instance, @instance2]
397
- end
398
- it "should be able to clean up after itself" do
399
- File.open("#{@master.base_tmp_dir}/test", "w+") {|f| f << "hello world"}
400
- @master.cleanup_tmp_directory(nil)
401
- File.file?("#{@master.base_tmp_dir}/test").should == false
402
- end
403
- it "should check to see if there is a directory in the user directory to grab the files from" do
404
- File.stub!(:directory?).with("/Users/auser/Sites/work/citrusbyte/internal/gems/poolparty/pool/tmp/resource.d").and_return false
405
- File.should_receive(:directory?).at_least(1).with("#{user_dir}/config/resource.d").at_least(1).and_return true
406
- @master.copy_config_files_in_directory_to_tmp_dir("config/resource.d")
407
- end
408
- it "should copy all the files that are in the directory" do
409
- Dir.stub!(:[]).and_return ["1","2","3"]
410
- File.should_receive(:copy).exactly(3).times.and_return true
411
- @master.copy_config_files_in_directory_to_tmp_dir("config/resource.d")
412
- end
413
- describe "building" do
414
- it "should copy all the resource.d files from the monit directory to the tmp directory" do
415
- @master.should_receive_at_least_once(:copy_config_files_in_directory_to_tmp_dir).with("config/resource.d").and_return true
416
- end
417
- it "should build the authkeys file for haproxy" do
418
- @master.should_receive(:build_and_copy_heartbeat_authkeys_file).and_return true
419
- end
420
- it "should build the haproxy configuration file" do
421
- @master.should_receive(:build_haproxy_file).and_return true
422
- end
423
- it "should build the nodes list file" do
424
- @master.should_receive(:build_nodes_list).and_return true
425
- end
426
- it "should build the hosts file for nodes" do
427
- @master.should_receive(:build_hosts_file_for).at_least(1).and_return true
428
- end
429
- it "should build the ssh reconfigure script" do
430
- @master.should_receive(:build_reconfigure_instances_script_for).at_least(1).and_return ""
431
- end
432
- it "should build global files" do
433
- Master.should_receive(:build_user_global_files).once
434
- end
435
- it "should build user node files" do
436
- Master.should_receive(:build_user_node_files_for).at_least(1)
437
- end
438
- after(:each) do
439
- @master.build_and_send_config_files_in_temp_directory
440
- end
441
- end
442
- describe "when the cloud requires heartbeat" do
443
- before(:each) do
444
- Master.stub!(:requires_heartbeat?).and_return true
445
- end
446
- it "should build the heartbeat configuration file" do
447
- @master.should_receive(:build_heartbeat_config_file_for).at_least(1).and_return true
448
- @master.build_and_send_config_files_in_temp_directory
449
- end
450
- end
451
- end
452
- describe "user define files" do
453
- it "should have access to global_user_files as an array" do
454
- Master.global_user_files.class.should == Array
455
- end
456
- it "should be able to add a global file to the array" do
457
- Master.define_global_user_file(:box) {"box"}
458
- Master.global_user_files.size.should == 1
459
- end
460
- it "should have access to user_node_files as an array" do
461
- Master.user_node_files.class.should == Array
462
- end
463
- it "should be able to add a node file to the array" do
464
- Master.define_node_user_file(:box) {|a| "#{a}.box"}
465
- Master.user_node_files.size.should == 1
466
- end
467
- it "should write_to_file_for for each of the global_user_files" do
468
- Master.should_receive(:write_to_file_for).once.and_return true
469
- Master.build_user_global_files
470
- end
471
- it "should write_to_file_for for each of the user_node_files" do
472
- Master.should_receive(:write_to_file_for).once.and_return true
473
- Master.build_user_node_files_for(@instance)
474
- end
475
- end
476
- end
477
- end
478
- end
479
- end