poolparty 0.0.4 → 0.2.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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
@@ -0,0 +1,112 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+ require "open-uri"
3
+
4
+ describe "basic" do
5
+ before(:each) do
6
+ @example_dir = ::File.join(::File.dirname(__FILE__), "..", "..", "..", "examples")
7
+ reset!
8
+ PoolParty::Script.inflate open(@example_dir + "/basic.rb").read
9
+ end
10
+ it "should have one pool called :app" do
11
+ pool(:app).should_not be_nil
12
+ end
13
+ it "should have a cloud called :app" do
14
+ pool(:app).cloud(:app).should_not be_nil
15
+ end
16
+ it "should have a cloud called :db" do
17
+ pool(:app).cloud(:db).should_not be_nil
18
+ end
19
+ it "should set the minimum_instances on the cloud to 2 (overriding the pool options)" do
20
+ pool(:app).cloud(:app).minimum_instances.should == 2
21
+ end
22
+ it "should set the maximum_instances on the cloud to 5" do
23
+ pool(:app).cloud(:app).maximum_instances.should == 5
24
+ end
25
+ it "should set the minimum_instances on the db cloud to 3" do
26
+ pool(:app).cloud(:db).minimum_instances.should == 3
27
+ end
28
+ describe "with_apache_plugin" do
29
+ before(:each) do
30
+ reset!
31
+ PoolParty::Script.inflate(open(@example_dir + "/with_apache_plugin.rb").read, File.dirname(__FILE__))
32
+ end
33
+ it "should have one pool called :app" do
34
+ pool(:app).should_not be_nil
35
+ end
36
+ it "should have a cloud called :app" do
37
+ pool(:app).cloud(:app).should_not be_nil
38
+ end
39
+ it "should have a cloud called :db" do
40
+ pool(:app).cloud(:db).should_not be_nil
41
+ end
42
+ it "should set the minimum_instances on the cloud to 2 (overriding the pool options)" do
43
+ pool(:app).cloud(:app).minimum_instances.should == 2
44
+ end
45
+ it "should set the maximum_instances on the cloud to 10" do
46
+ pool(:app).cloud(:app).maximum_instances.should == 10
47
+ end
48
+ it "should set the minimum_instances on the db cloud to 2" do
49
+ pool(:app).cloud(:db).minimum_instances.should == 2
50
+ end
51
+ it "should have included the apache plugin and given the class a method by the name of the plugin" do
52
+ pool(:app).cloud(:app).methods.include?("apache").should == true
53
+ end
54
+ describe "apache plugin" do
55
+ before(:each) do
56
+ @c = pool(:app).cloud(:app)
57
+ end
58
+ it "should have apache as the ApacheClass" do
59
+ @c.apache.class.should == PoolPartyApacheClass
60
+ end
61
+ it "should set php == true on the apache plugin" do
62
+ @c.apache.php.should == true
63
+ end
64
+ it "should store the method in options if it's not defined on the plugin" do
65
+ @c.enable_asp true
66
+ @c.options[:enable_asp].should == true
67
+ end
68
+ end
69
+ end
70
+ describe "plugin_without_plugin_directory" do
71
+ before(:each) do
72
+ reset!
73
+ PoolParty::Script.inflate(open(@example_dir + "/plugin_without_plugin_directory.rb").read, File.dirname(__FILE__))
74
+ end
75
+ it "should have one pool called :app" do
76
+ pool(:app).should_not be_nil
77
+ end
78
+ it "should have a cloud called :app" do
79
+ pool(:app).cloud(:app).should_not be_nil
80
+ end
81
+ it "should have a cloud called :db" do
82
+ pool(:app).cloud(:db).should_not be_nil
83
+ end
84
+ it "should set the minimum_instances on the cloud to 2 (overriding the pool options)" do
85
+ pool(:app).cloud(:app).minimum_instances.should == 2
86
+ end
87
+ it "should set the maximum_instances on the cloud to 10" do
88
+ pool(:app).cloud(:app).maximum_instances.should == 10
89
+ end
90
+ it "should set the minimum_instances on the db cloud to 2" do
91
+ pool(:app).cloud(:db).minimum_instances.should == 2
92
+ end
93
+ it "should have included the apache plugin and given the class a method by the name of the plugin" do
94
+ pool(:app).cloud(:app).methods.include?("apache").should == true
95
+ end
96
+ describe "apache plugin" do
97
+ before(:each) do
98
+ @c = pool(:app).cloud(:app)
99
+ end
100
+ it "should have apache as the ApacheClass" do
101
+ @c.apache.class.should == PoolPartyApacheClass
102
+ end
103
+ it "should set php == true on the apache plugin" do
104
+ @c.apache.php.should == true
105
+ end
106
+ it "should store the method in options if it's not defined on the plugin" do
107
+ @c.enable_asp true
108
+ @c.options[:enable_asp].should == true
109
+ end
110
+ end
111
+ end
112
+ end
@@ -0,0 +1,63 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+ require File.dirname(__FILE__) + '/test_plugins/webserver'
3
+
4
+ describe "Plugin" do
5
+ before(:each) do
6
+ @p = pool :poolpartyrb do
7
+ cloud :app do
8
+ apache do
9
+ enable_php
10
+ site("heady", {
11
+ :document_root => "/root"
12
+ })
13
+ end
14
+ end
15
+ end
16
+ @c = @p.cloud(:app)
17
+ end
18
+ describe "methods should include" do
19
+ it "register_plugin(plugin)" do;WebServers.respond_to?(:register_plugin).should == true;end
20
+ end
21
+ describe "registered" do
22
+ before(:each) do
23
+ @plugin = "apache".class_constant.new(@c)
24
+ end
25
+ describe "storage" do
26
+ it "should store the plugin in a Hash on the pool" do
27
+ @c.plugins.class.should == Hash
28
+ end
29
+ it "should be able to retrieve the plugin as a name" do
30
+ @c.plugin("apache").should_not be_nil
31
+ end
32
+ end
33
+ it "should store the regsitered plugins in an array" do
34
+ @plugin.should_not be_nil
35
+ end
36
+ it "should set the pool on the plugin" do
37
+ @plugin.parent.should == @c
38
+ end
39
+ it "should have the plugin name as a method on the cloud " do
40
+ @c.respond_to?(:apache).should == true
41
+ end
42
+ describe "methods" do
43
+ before(:each) do
44
+ reset!
45
+ end
46
+ it "should call the enable_php method when in the defininition of the cloud" do
47
+ @plugin.respond_to?(:enable_php).should == true
48
+ end
49
+ it "should call php = true in the enable_php" do
50
+ @plugin.php.should_not == true
51
+ @plugin.enable_php
52
+ @plugin.php.should == true
53
+ end
54
+ it "should call the site method when in the defininition of the cloud" do
55
+ @plugin.respond_to?(:site).should == true
56
+ end
57
+ it "should be able to call the plugin method site" do
58
+ @plugin.should_receive(:virtual_host).once
59
+ @plugin.site("hi", {:document_root => "/root"})
60
+ end
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,85 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+ require File.dirname(__FILE__) + '/test_plugins/webserver'
3
+
4
+ describe "Plugin" do
5
+
6
+ before(:each) do
7
+ reset!
8
+ pool :poolpartyrb do
9
+ cloud :app do
10
+ apache do
11
+ enable_php
12
+ site("heady", {
13
+ :document_root => "/root"
14
+ })
15
+ end
16
+ end
17
+ end
18
+ @p = pool :poolpartyrb
19
+ @c = @p.cloud(:app)
20
+ end
21
+
22
+ it "should allow access to the pool on the cloud" do
23
+ @c.parent.should == @p
24
+ end
25
+ describe "instance" do
26
+ before(:each) do
27
+ @plugin = "apache".class_constant.new(@c)
28
+ end
29
+ it "should not be empty" do
30
+ @plugin.class.should == PoolPartyApacheClass
31
+ end
32
+ it "should have access to the cloud's container" do
33
+ @plugin.parent.should == @c
34
+ end
35
+ it "should have enable_php as a method" do
36
+ @plugin.respond_to?(:enable_php).should == true
37
+ end
38
+ describe "after eval'ing" do
39
+ before(:each) do
40
+ @plugin.instance_eval do
41
+ enable_php
42
+ has_gem(:name => "aska")
43
+ end
44
+ end
45
+ it "should call enable_php on the class" do
46
+ @plugin.php.should == true
47
+ end
48
+ it "should have resources attached to it" do
49
+ @plugin.resources.class.should == Hash
50
+ end
51
+ it "should have an array of gem resources" do
52
+ @plugin.resource(:package).class.should == Array
53
+ end
54
+ it "should have 1 gem in the resources defined" do
55
+ @plugin.resource(:package).size.should == 1
56
+ end
57
+ it "should have the gem named aska in the gem resource" do
58
+ @plugin.resource(:package).first.name.should == "aska"
59
+ end
60
+ it "should have its resources visible to its parent" do
61
+ @plugin.parent = @c
62
+ @c.resources
63
+ end
64
+ end
65
+ describe "before eval'ing" do
66
+ before(:each) do
67
+ reset!
68
+ @plugin = "apache".class_constant.new(@c)
69
+ end
70
+ it "should call has_line_in_file" do
71
+ @plugin.should_receive(:php).and_return true
72
+ end
73
+ it "should call site" do
74
+ @plugin.should_receive(:site).with("frank").and_return true
75
+ end
76
+ after do
77
+ @plugin.instance_eval do
78
+ enable_php
79
+ site("frank")
80
+ end
81
+ end
82
+
83
+ end
84
+ end
85
+ end
@@ -0,0 +1,83 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ describe "Pool" do
4
+ before(:each) do
5
+ @obj = Object.new
6
+ end
7
+ it "should respond to the pool method" do
8
+ @obj.respond_to?(:pool).should == true
9
+ end
10
+ it "should store the pool in the global array" do
11
+ @p = pool :app do
12
+ end
13
+ @obj.pools[:app].should == @p
14
+ end
15
+
16
+ describe "block" do
17
+ before(:each) do
18
+ @pool = Pool.new(:test) do
19
+ # Inside pool block
20
+ Proc.new {puts "hello world"}
21
+ end
22
+ end
23
+
24
+ it "should be able to define a cloud within the pool block" do
25
+ @pool.respond_to?(:cloud).should == true
26
+ end
27
+ it "should evaluate the block when creating a new pool" do
28
+ Proc.should_receive(:new).once
29
+ Pool.new(:test) do
30
+ Proc.new {puts "hi"}
31
+ end
32
+ end
33
+ describe "plugins" do
34
+ after(:each) do
35
+ @pool.instance_eval do
36
+ plugin_directory "yaway"
37
+ end
38
+ end
39
+ it "should call Dir when the plugin directory is set" do
40
+ Dir.should_receive(:[]).with("yaway/*.rb").once.and_return []
41
+ end
42
+ end
43
+ describe "configuration" do
44
+ before(:each) do
45
+ reset!
46
+ @pool = Pool.new :test do
47
+ nick_nack "nails"
48
+ rocky_shores "ranger"
49
+ end
50
+ end
51
+ it "should set the plugin_directory to nails" do
52
+ @pool.nick_nack.should == "nails"
53
+ end
54
+ it "should set the rocky_shores to ranger" do
55
+ @pool.rocky_shores.should == "ranger"
56
+ end
57
+ describe "range for min/max instances" do
58
+ it "should be able to respond to instances" do
59
+ @pool.respond_to?(:instances).should == true
60
+ end
61
+ it "should be able to pass instances a range" do
62
+ lambda {
63
+ @pool.instance_eval do
64
+ instances 2..5
65
+ end
66
+ }.should_not raise_error
67
+ end
68
+ it "should set the minimum as the minimum_instances from the range" do
69
+ @pool.instance_eval do
70
+ instances 2..5
71
+ end
72
+ @pool.minimum_instances.should == 2
73
+ end
74
+ it "should set the maximum as the maximum_instances from the range" do
75
+ @pool.instance_eval do
76
+ instances 2..5
77
+ end
78
+ @pool.maximum_instances.should == 5
79
+ end
80
+ end
81
+ end
82
+ end
83
+ end
@@ -0,0 +1,224 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+ require File.dirname(__FILE__) + '/test_plugins/webserver'
3
+
4
+ class MyResource < PoolParty::Resources::Resource
5
+ # Just to give some options for the test class
6
+ def options(h={})
7
+ @options ||= {:a => 1,:b => 2,:c => 3}
8
+ end
9
+ end
10
+ describe "Resource" do
11
+ before(:each) do
12
+ @resource = MyResource.new({:a => 10}) do
13
+ b "90"
14
+ end
15
+ end
16
+ it "should set a from the hash" do
17
+ @resource.a.should == 10
18
+ end
19
+ it "should set b from within the block" do
20
+ @resource.b.should == "90"
21
+ end
22
+ it "should not wipe out the rest of the default options" do
23
+ @resource.c.should == 3
24
+ end
25
+ describe "to_s" do
26
+ it "should be able to coalesce the instances" do
27
+ @resource.to_string.should =~ /resource \{\n/
28
+ end
29
+ describe "with resources" do
30
+ before(:each) do
31
+ self.stub!(:options).and_return(:name => "cook")
32
+
33
+ @obj = PoolParty::Resources::Resource.new
34
+ @obj.stub!(:name).and_return "cook"
35
+
36
+ @resource2 = MyResource.new do
37
+ file(:name => "shulie")
38
+ end
39
+ end
40
+ it "should call classpackage_with_self when it has resources" do
41
+ @resource2.should_receive(:classpackage_with_self).and_return @obj
42
+ @resource2.to_string
43
+ end
44
+ it "should call to_string on the class package" do
45
+ @obj.should_receive(:to_string).and_return "wee"
46
+ @resource2.should_receive(:classpackage_with_self).and_return @obj
47
+ @resource2.to_string
48
+ end
49
+ end
50
+ end
51
+ describe "class methods" do
52
+ it "should have an array of available resources" do
53
+ PoolParty::Resources::Resource.available_resources.class.should == Array
54
+ end
55
+ it "should not be empty" do
56
+ PoolParty::Resources::Resource.available_resources.should_not be_empty
57
+ end
58
+ end
59
+ describe "instance methods" do
60
+ before(:each) do
61
+ @resource = MyResource.new
62
+ end
63
+ %w(requires ensures is_present is_absent ifnot).each do |method|
64
+ eval <<-EOE
65
+ it "should have the method #{method} available" do; @resource.respond_to?(:#{method}).should == true; end
66
+ EOE
67
+ end
68
+ it "should be able to take requires method" do
69
+ @resource.respond_to?(:requires).should == true
70
+ end
71
+ it "should push require onto the options" do
72
+ @resource.options.has_key?(:require).should == false
73
+ @resource.requires("nibbles")
74
+ @resource.options.has_key?(:require).should == true
75
+ end
76
+ it "should be able to call ensures method on the resource" do
77
+ @resource.respond_to?(:ensures).should == true
78
+ end
79
+ it "should push the option ensure onto the options" do
80
+ @resource.options.has_key?(:ensure).should == false
81
+ @resource.ensures("nibbles")
82
+ @resource.options.has_key?(:ensure).should == true
83
+ end
84
+ it "should write the option ensures as present with is_present" do
85
+ @resource.options.has_key?(:ensure).should == false
86
+ @resource.is_present
87
+ @resource.options[:ensure].should == "present"
88
+ end
89
+ it "should write the option ensures as absent with is_absent" do
90
+ @resource.options.has_key?(:ensure).should == false
91
+ @resource.is_absent
92
+ @resource.options[:ensure].should == "absent"
93
+ end
94
+ it "should write the option unless for ifnot" do
95
+ @resource.options.has_key?(:unless).should == false
96
+ @resource.ifnot "str"
97
+ @resource.options[:unless].should == "str"
98
+ end
99
+ describe "templating" do
100
+ before(:each) do
101
+ FileUtils.stub!(:cp).and_return true
102
+ end
103
+ it "should have the method template" do
104
+ @resource.respond_to?(:template).should == true
105
+ end
106
+ it "should raise an exception if no file is given" do
107
+ lambda {
108
+ @resource.template
109
+ }.should raise_error
110
+ end
111
+ it "should raise an excepton if the file cannot be found" do
112
+ lambda {
113
+ @resource.template("radar")
114
+ }.should raise_error
115
+ end
116
+ it "should not raise an exception if there is a file passed and the file is found" do
117
+ File.should_receive(:file?).with("radar").and_return true
118
+ lambda {
119
+ @resource.template("radar")
120
+ }.should_not raise_error
121
+ end
122
+ # it "should push the template option on to the options" do
123
+ # File.stub!(:file?).with("radar").and_return true
124
+ # @resource.options.has_key?(:template).should == false
125
+ # @resource.template("radar")
126
+ # @resource.options.has_key?(:template).should == true
127
+ # end
128
+ end
129
+ end
130
+ describe "command" do
131
+ include PoolParty::Resources
132
+ before(:each) do
133
+ reset_resources!
134
+ end
135
+ it "should create the new 'resource' as a resource" do
136
+ resource(:file).class.should == Array
137
+ end
138
+ it "should receive << when adding a new one" do
139
+ resource(:file).should_receive(:<<).once
140
+ file({:name => "pop"})
141
+ end
142
+ it "should contain 3 instances after calling resource 3 times" do
143
+ file({:name => "red"})
144
+ file({:name => "hot"})
145
+ file({:name => "summer"})
146
+ resource(:file).size.should == 3
147
+ end
148
+ describe "adding" do
149
+ before(:each) do
150
+ @a = file({:name => "red"})
151
+ @b = file({:name => "hot"})
152
+ @c = file({:name => "summer"})
153
+ end
154
+ it "should contain file named with 'red'" do
155
+ resource(:file).include?(@a).should == true
156
+ end
157
+ end
158
+ describe "method_missing" do
159
+ before(:each) do
160
+ file({:name => "red"})
161
+ file({:name => "hot"})
162
+ file({:name => "summer"})
163
+ end
164
+ it "should be able to pick out methods with the phrase has_" do
165
+ lambda {
166
+ has_file
167
+ }.should_not raise_error
168
+ end
169
+ it "should not have a method prepended with crabs_" do
170
+ lambda {
171
+ crabs_file
172
+ }.should raise_error
173
+ end
174
+ it "should pick out methods with the phrase does_not_" do
175
+ lambda {
176
+ does_not_have_file({:name => "red"})
177
+ }.should_not raise_error
178
+ end
179
+ it "should set the has_file to present ensure" do
180
+ has_file({:name => "redface"})
181
+ resource(:file).get_named("redface").first.options[:ensure].should == "present"
182
+ end
183
+ it "should set the does_not_have_file to absent ensure" do
184
+ does_not_have_file({:name => "net"})
185
+ resource(:file).get_named("net").first.options[:ensure].should == "absent"
186
+ end
187
+ it "should be able to have_service as well" do
188
+ has_service({:name => "apache"})
189
+ resource(:service).get_named("apache").first.options[:ensure].should == "running"
190
+ end
191
+ end
192
+ describe "get_resource" do
193
+ before(:each) do
194
+ @red = file(:name => "red")
195
+ @hot = file(:name => "hot")
196
+ @tamales = file(:name => "tamales")
197
+ end
198
+ it "should return a type of resource when looking for a resource that exists" do
199
+ get_resource(:file, "hot").class.should == PoolParty::Resources::File
200
+ end
201
+ it "should return the resource of the name requested" do
202
+ get_resource(:file, "hot").should == @hot
203
+ end
204
+ it "should return nil if the resource requested is not there" do
205
+ get_resource(:file, "smarties").should be_nil
206
+ end
207
+ end
208
+ describe "parent" do
209
+ before(:each) do
210
+ @cloud = cloud :app do
211
+ tangerine "orange"
212
+ file(:name => "file.txt")
213
+ end
214
+ @file = @cloud.resources[:file].first
215
+ end
216
+ it "should take the options of the parent" do
217
+ @file.parent.tangerine.should_not == nil
218
+ end
219
+ it "should set the option as the same from the parent" do
220
+ @file.parent.tangerine.should == "orange"
221
+ end
222
+ end
223
+ end
224
+ end