stackfu 0.1.1 → 0.1.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (58) hide show
  1. data/Gemfile +4 -0
  2. data/Manifest +36 -4
  3. data/Rakefile +1 -1
  4. data/autotest/discover.rb +1 -0
  5. data/firewall/config/01-controls.yml +5 -0
  6. data/firewall/config/02-requirements.yml +4 -0
  7. data/firewall/config/03-executions.yml +6 -0
  8. data/firewall/config/03-scripts.yml +6 -0
  9. data/firewall/config/04-validations.yml +4 -0
  10. data/firewall/executables/configure_ufw.sh.erb +9 -0
  11. data/firewall/executables/install_ufw.sh.erb +7 -0
  12. data/firewall/script/configure_ufw.sh.erb +9 -0
  13. data/firewall/script/install_ufw.sh.erb +7 -0
  14. data/firewall/script.yml +8 -0
  15. data/lib/stackfu/api_hooks.rb +2 -2
  16. data/lib/stackfu/app.rb +5 -5
  17. data/lib/stackfu/commands/command.rb +7 -3
  18. data/lib/stackfu/commands/config_command.rb +1 -1
  19. data/lib/stackfu/commands/deploy_command.rb +53 -61
  20. data/lib/stackfu/commands/dump_command.rb +46 -40
  21. data/lib/stackfu/commands/generate_command.rb +10 -12
  22. data/lib/stackfu/commands/help_command.rb +1 -1
  23. data/lib/stackfu/commands/list_command.rb +76 -22
  24. data/lib/stackfu/commands/publish_command.rb +35 -18
  25. data/lib/stackfu/commands/server_command.rb +124 -124
  26. data/lib/stackfu/date_helper.rb +111 -0
  27. data/lib/stackfu.rb +4 -2
  28. data/spec/fixtures/scripts/all.json +11 -0
  29. data/spec/fixtures/scripts/create.json +10 -0
  30. data/spec/fixtures/scripts/delete.json +10 -0
  31. data/spec/fixtures/scripts/firewall.json +12 -0
  32. data/spec/fixtures/scripts/none.json +12 -0
  33. data/spec/fixtures/scripts/not_found.json +11 -0
  34. data/spec/fixtures/scripts/script_not_found.json +11 -0
  35. data/spec/fixtures/servers/all.json +12 -0
  36. data/spec/fixtures/servers/cannot_deploy.json +0 -0
  37. data/spec/fixtures/servers/deploy.json +290 -0
  38. data/spec/fixtures/servers/none.json +12 -0
  39. data/spec/fixtures/servers/not_found.json +11 -0
  40. data/spec/fixtures/servers/webbynode/deploy.json +12 -0
  41. data/spec/fixtures/servers/webbynode.json +12 -0
  42. data/spec/spec_helper.rb +191 -0
  43. data/spec/stackfu/api_hooks_spec.rb +7 -0
  44. data/spec/stackfu/commands/deploy_command_spec.rb +65 -0
  45. data/spec/stackfu/commands/dump_command_spec.rb +47 -0
  46. data/spec/stackfu/commands/generate_command_spec.rb +90 -0
  47. data/spec/stackfu/commands/list_command_spec.rb +53 -0
  48. data/spec/stackfu/commands/publish_command_spec.rb +67 -0
  49. data/stackfu.gemspec +4 -4
  50. data/templates/02-requirements.yml.erb +8 -10
  51. data/templates/{03-scripts.yml.erb → 03-executions.yml.erb} +3 -3
  52. data/templates/04-validations.yml.erb +1 -2
  53. data/templates/stack.yml.erb +4 -13
  54. data/test/support/fixtures.rb +1 -1
  55. data/test/unit/commands/test_server_command.rb +259 -259
  56. metadata +42 -7
  57. data/test/stack.yml +0 -26
  58. /data/stackfu-installer/config/{03-scripts.yml → 03-executions.yml} +0 -0
@@ -7,20 +7,18 @@
7
7
  #
8
8
  # Types of dependencies:
9
9
  #
10
- # file - a given file exists
11
- # symlink - a given symlink exists
12
- # directory - a given directory exits
13
- # process - a process is runnning
14
- # ruby_can_load - if ruby can load a given lib
15
- # ruby_gem - if a given ruby gem is installed
10
+ # FileExists - a given file exists
11
+ # SymlinkExists - a given symlink exists
12
+ # DirExists - a given directory exits
13
+ # ProcessExists - a process is runnning
14
+ # RubyCanLoad - if ruby can load a given lib
15
+ # RubyGem - if a given ruby gem is installed
16
16
  #
17
17
  # Example of expected contents for this file:
18
18
  #
19
19
  # requirements:
20
- # - type: directory
20
+ # - type: DirExists
21
21
  # data: "/var"
22
- # error: "You need /var folder before installing"
23
- # - type: file
22
+ # - type: FireExists
24
23
  # data: "/etc/init.d/mysql"
25
- # error: MySQL start script was not found
26
24
  #
@@ -25,9 +25,9 @@
25
25
  # install_apache.sh.erb, isntall_mysql.sh.erb and
26
26
  # install_php.sh.erb
27
27
  #
28
- <% if scripts %>
29
- scripts:
30
- <% scripts.each do |s| %>
28
+ <% if executions %>
29
+ executions:
30
+ <% executions.each do |s| %>
31
31
  - description: <%= s.first.titleize %>
32
32
  file: <%= s.first %>
33
33
  <% end %>
@@ -11,7 +11,6 @@
11
11
  # Example of expected contents for this file:
12
12
  #
13
13
  # validations:
14
- # - type: directory
14
+ # - type: DirExists
15
15
  # data: "/etc/apache2"
16
- # error: Apache was not installed properly
17
16
  #
@@ -1,17 +1,8 @@
1
1
  ---
2
- type: <%= stack_type %>
2
+ type: script
3
3
  name: "<%= name %>"
4
+ description: "Add your description here"
4
5
  #
5
- # TODO: Before submitting this stack, you have to specify
6
- # the attributes below.
7
- #
8
- # Available operating systems
9
- #
10
- # <%= "For OS".ljust(20) %> <%= "Use" %>
11
- # <%= "-"*20 %> <%= "-"*20 %>
12
- <% FriendlyNames.each_pair do |key, value| %># <%= key.ljust(20) %> <%= value %>
13
- <% end %>#
14
- # operating_system:
15
- # description: "<%= description %>"
16
- # tags: [add, some, tags]
6
+ # TODO: Before submitting this script, double check the
7
+ # attributes above.
17
8
  #
@@ -81,7 +81,7 @@ module Fixtures
81
81
  fixture = options[:fixture] || options[:path]
82
82
  params = options[:params] ? "?#{options[:params]}" : ""
83
83
 
84
- # d "Registering: #{method} #{ApiUrlPrefix}/#{path}.json#{params} => #{fixture}#{kind}"
84
+ d "Registering: #{method} #{ApiUrlPrefix}/#{path}.json#{params} => #{fixture}#{kind}"
85
85
  FakeWeb.register_uri(method, "#{ApiUrlPrefix}/#{path}.json#{params}",
86
86
  :response => fixture("#{fixture}#{kind}"))
87
87
  end
@@ -1,259 +1,259 @@
1
- require File.dirname(__FILE__) + '/../../test_helper.rb'
2
-
3
- class TestServerCommand < Test::Unit::TestCase
4
- should "map 'servers' to ServerCommand" do
5
- Command.create("servers").class.should == ServerCommand
6
- end
7
-
8
- should "map 'server' to ServerCommand" do
9
- Command.create("server").class.should == ServerCommand
10
- end
11
-
12
- context "list servers with invalid user" do
13
- should "return an user friendly error" do
14
- with_server_list("unauthorized")
15
- command "server list"
16
- stdout.should =~ /Access denied for user 'flipper'/
17
- end
18
- end
19
-
20
- context "list servers with 404" do
21
- should "return an user friendly error" do
22
- with_server_list("not_found")
23
- command "server list"
24
- stdout.should =~ /There was an internal error contacting StackFu backend./
25
- end
26
- end
27
-
28
- should "indicate user have no servers" do
29
- with_server_list "empty"
30
- command "server list"
31
- stdout.should =~ /You have no servers under your account. Try adding some with 'server add' command.\n/
32
- end
33
-
34
- context "add command" do
35
- should "require two parameters" do
36
- command "server add Slicehost"
37
- stdout.should =~ /requires 2 parameters/
38
- end
39
- end
40
-
41
- context "adding a server" do
42
- should "fail when adding to add the same server twice" do
43
- with_users
44
- with_server_add("dupe")
45
-
46
- command "server add Slicehost slicey"
47
- stdout.should =~ /already exists in your account./
48
- end
49
-
50
- should "ask for credentials before the walkthrough if user have no credentials" do
51
- with_users "no_credentials"
52
- with_users_add
53
- with_providers
54
- with_provider("slicehost", "servers")
55
- with_server_add
56
-
57
- when_asked_to_choose "\nSelect the provider:",
58
- :with_options => ["Webbynode", "Slicehost", "Linode"],
59
- :answer => 1
60
-
61
- when_asked "", :answer => "abc123"
62
-
63
- when_asked_to_choose "\nSelect the server:",
64
- :with_options => ["slicey", "peeps"],
65
- :answer => 1
66
-
67
- command "server add"
68
-
69
- stdout.should =~ /Slicehost credentials saved/
70
- stdout.should =~ /Server peeps added successfully/
71
- end
72
-
73
- should "fail when adding to add the same server twice and using the walkthrough" do
74
- with_users
75
- with_providers
76
- with_provider("slicehost", "servers")
77
- with_server_add("dupe")
78
-
79
- when_asked_to_choose "\nSelect the provider:",
80
- :with_options => ["Webbynode", "Slicehost", "Linode"],
81
- :answer => 1
82
-
83
- when_asked_to_choose "\nSelect the server:",
84
- :with_options => ["slicey", "peeps"],
85
- :answer => 1
86
-
87
- command "server add"
88
-
89
- stdout.should =~ /already exists in your account./
90
- end
91
-
92
- should "guide the user to add a server when no params are given" do
93
- with_users
94
- with_providers
95
- with_provider("slicehost", "servers")
96
- with_server_add
97
-
98
- when_asked_to_choose "\nSelect the provider:",
99
- :with_options => ["Webbynode", "Slicehost", "Linode"],
100
- :answer => 1
101
-
102
- when_asked_to_choose "\nSelect the server:",
103
- :with_options => ["slicey", "peeps"],
104
- :answer => 1
105
-
106
- command "server add"
107
- end
108
- end
109
-
110
- context "adding a webbynode server" do
111
- should "abort when user enters 'abort' into the API login field" do
112
- with_users "no_credentials"
113
-
114
- when_asked "Webbynode Login:", :answer => 'abort'
115
- command "server add webbynode sandbox"
116
-
117
- stdout.should =~ /Aborted adding server./
118
- stdout.should =~ /Enter your Webbynode API credentials/
119
- end
120
-
121
- should "abort when user enters 'abort' into the API token field" do
122
- with_users "no_credentials"
123
-
124
- when_asked "Webbynode Login:", :answer => 'fcoury@me.com'
125
- when_asked "Webbynode Token:", :answer => 'abort'
126
-
127
- command "server add webbynode sandbox"
128
-
129
- stdout.should =~ /Aborted adding server./
130
- stdout.should =~ /Enter your Webbynode API credentials/
131
- end
132
-
133
- should "show the help message when user enters 'help' into the API login field" do
134
- with_users "no_credentials"
135
-
136
- when_asked "Webbynode Login:", :answer => 'help'
137
- when_asked "Webbynode Login:", :answer => 'abort'
138
- command "server add webbynode sandbox"
139
-
140
- stdout.should =~ /== Webbynode StackFu integration ==/
141
- end
142
-
143
- should "ask for credentials when none were given before" do
144
- with_users "no_credentials"
145
- with_users_add
146
- with_server_add
147
-
148
- when_asked "Webbynode Login:", :answer => 'fcoury@me.com'
149
- when_asked "Webbynode Token:", :answer => 'abc123456'
150
-
151
- command "server add webbynode sandbox"
152
- stdout.should =~ /Webbynode credentials saved./
153
- stdout.should =~ /Server sandbox added successfully/
154
- end
155
-
156
- should "add the server if proper credentials given" do
157
- with_users
158
- with_users_add
159
- with_server_add
160
-
161
- command "server add webbynode sandbox"
162
- stdout.should =~ /Server sandbox added successfully/
163
- end
164
-
165
- should "delete the server if proper credentials given and server exists" do
166
- with_users
167
- with_server_list("webbynode")
168
- with_server_delete
169
-
170
- command "server delete sandbox"
171
- stdout.should =~ /Server sandbox deleted successfully/
172
- end
173
-
174
- should "show the webbynode server when listing servers" do
175
- with_users
176
- with_server_list("webbynode")
177
-
178
- command "server"
179
- stdout.should =~ /Name/
180
- stdout.should =~ /Provider/
181
- stdout.should =~ /IP/
182
- stdout.should =~ /Status/
183
-
184
- stdout.should =~ /sandbox/
185
- stdout.should =~ /Webbynode/
186
- stdout.should =~ /208\.88\.125\.207/
187
- stdout.should =~ /running/
188
- end
189
- end
190
-
191
- context "adding a slicehost server" do
192
- should "abort when user enters 'abort' into the API password field" do
193
- with_users "no_credentials"
194
-
195
- when_asked "", :answer => 'abort'
196
- command "server add slicehost slicey"
197
-
198
- stdout.should =~ /Aborted adding server./
199
- stdout.should =~ /Enter your Slicehost API password/
200
- end
201
-
202
- should "show the help message when user enters 'help' into the API password field" do
203
- with_users "no_credentials"
204
-
205
- when_asked "", :answer => 'help'
206
- when_asked "", :answer => 'abort'
207
- command "server add slicehost slicey"
208
-
209
- stdout.should =~ /== Slicehost StackFu integration ==/
210
- end
211
-
212
- should "ask for credentials when none were given before" do
213
- with_users "no_credentials"
214
- with_users_add
215
- with_server_add
216
-
217
- when_asked "", :answer => "abc123"
218
-
219
- command "server add slicehost slicey"
220
- stdout.should =~ /Server slicey added successfully/
221
- end
222
-
223
- should "add the server if proper credentials given" do
224
- with_users
225
- with_users_add
226
- with_server_add
227
-
228
- command "server add slicehost slicey"
229
- stdout.should =~ /Server slicey added successfully/
230
- end
231
-
232
- should "delete the server if proper credentials given and server exists" do
233
- with_users
234
- with_server_list
235
- with_server_delete
236
-
237
- command "server delete slicey"
238
- stdout.should =~ /Server slicey deleted successfully/
239
- end
240
-
241
- should "show a selection when same server hostname repeats in more than one provider"
242
-
243
- should "show the slicehost server when listing servers" do
244
- with_users
245
- with_server_list
246
-
247
- command "server"
248
- stdout.should =~ /Name/
249
- stdout.should =~ /Provider/
250
- stdout.should =~ /IP/
251
- stdout.should =~ /Status/
252
-
253
- stdout.should =~ /slicey/
254
- stdout.should =~ /Slicehost/
255
- stdout.should =~ /174\.143\.145\.37/
256
- stdout.should =~ /running/
257
- end
258
- end
259
- end
1
+ # require File.dirname(__FILE__) + '/../../test_helper.rb'
2
+ #
3
+ # class TestServerCommand < Test::Unit::TestCase
4
+ # should "map 'servers' to ServerCommand" do
5
+ # Command.create("servers").class.should == ServerCommand
6
+ # end
7
+ #
8
+ # should "map 'server' to ServerCommand" do
9
+ # Command.create("server").class.should == ServerCommand
10
+ # end
11
+ #
12
+ # context "list servers with invalid user" do
13
+ # should "return an user friendly error" do
14
+ # with_server_list("unauthorized")
15
+ # command "server list"
16
+ # stdout.should =~ /Access denied for user 'flipper'/
17
+ # end
18
+ # end
19
+ #
20
+ # context "list servers with 404" do
21
+ # should "return an user friendly error" do
22
+ # with_server_list("not_found")
23
+ # command "server list"
24
+ # stdout.should =~ /There was an internal error contacting StackFu backend./
25
+ # end
26
+ # end
27
+ #
28
+ # should "indicate user have no servers" do
29
+ # with_server_list "empty"
30
+ # command "server list"
31
+ # stdout.should =~ /You have no servers under your account. Try adding some with 'server add' command.\n/
32
+ # end
33
+ #
34
+ # context "add command" do
35
+ # should "require two parameters" do
36
+ # command "server add Slicehost"
37
+ # stdout.should =~ /requires 2 parameters/
38
+ # end
39
+ # end
40
+ #
41
+ # context "adding a server" do
42
+ # should "fail when adding to add the same server twice" do
43
+ # with_users
44
+ # with_server_add("dupe")
45
+ #
46
+ # command "server add Slicehost slicey"
47
+ # stdout.should =~ /already exists in your account./
48
+ # end
49
+ #
50
+ # should "ask for credentials before the walkthrough if user have no credentials" do
51
+ # with_users "no_credentials"
52
+ # with_users_add
53
+ # with_providers
54
+ # with_provider("slicehost", "servers")
55
+ # with_server_add
56
+ #
57
+ # when_asked_to_choose "\nSelect the provider:",
58
+ # :with_options => ["Webbynode", "Slicehost", "Linode"],
59
+ # :answer => 1
60
+ #
61
+ # when_asked "", :answer => "abc123"
62
+ #
63
+ # when_asked_to_choose "\nSelect the server:",
64
+ # :with_options => ["slicey", "peeps"],
65
+ # :answer => 1
66
+ #
67
+ # command "server add"
68
+ #
69
+ # stdout.should =~ /Slicehost credentials saved/
70
+ # stdout.should =~ /Server peeps added successfully/
71
+ # end
72
+ #
73
+ # should "fail when adding to add the same server twice and using the walkthrough" do
74
+ # with_users
75
+ # with_providers
76
+ # with_provider("slicehost", "servers")
77
+ # with_server_add("dupe")
78
+ #
79
+ # when_asked_to_choose "\nSelect the provider:",
80
+ # :with_options => ["Webbynode", "Slicehost", "Linode"],
81
+ # :answer => 1
82
+ #
83
+ # when_asked_to_choose "\nSelect the server:",
84
+ # :with_options => ["slicey", "peeps"],
85
+ # :answer => 1
86
+ #
87
+ # command "server add"
88
+ #
89
+ # stdout.should =~ /already exists in your account./
90
+ # end
91
+ #
92
+ # should "guide the user to add a server when no params are given" do
93
+ # with_users
94
+ # with_providers
95
+ # with_provider("slicehost", "servers")
96
+ # with_server_add
97
+ #
98
+ # when_asked_to_choose "\nSelect the provider:",
99
+ # :with_options => ["Webbynode", "Slicehost", "Linode"],
100
+ # :answer => 1
101
+ #
102
+ # when_asked_to_choose "\nSelect the server:",
103
+ # :with_options => ["slicey", "peeps"],
104
+ # :answer => 1
105
+ #
106
+ # command "server add"
107
+ # end
108
+ # end
109
+ #
110
+ # context "adding a webbynode server" do
111
+ # should "abort when user enters 'abort' into the API login field" do
112
+ # with_users "no_credentials"
113
+ #
114
+ # when_asked "Webbynode Login:", :answer => 'abort'
115
+ # command "server add webbynode sandbox"
116
+ #
117
+ # stdout.should =~ /Aborted adding server./
118
+ # stdout.should =~ /Enter your Webbynode API credentials/
119
+ # end
120
+ #
121
+ # should "abort when user enters 'abort' into the API token field" do
122
+ # with_users "no_credentials"
123
+ #
124
+ # when_asked "Webbynode Login:", :answer => 'fcoury@me.com'
125
+ # when_asked "Webbynode Token:", :answer => 'abort'
126
+ #
127
+ # command "server add webbynode sandbox"
128
+ #
129
+ # stdout.should =~ /Aborted adding server./
130
+ # stdout.should =~ /Enter your Webbynode API credentials/
131
+ # end
132
+ #
133
+ # should "show the help message when user enters 'help' into the API login field" do
134
+ # with_users "no_credentials"
135
+ #
136
+ # when_asked "Webbynode Login:", :answer => 'help'
137
+ # when_asked "Webbynode Login:", :answer => 'abort'
138
+ # command "server add webbynode sandbox"
139
+ #
140
+ # stdout.should =~ /== Webbynode StackFu integration ==/
141
+ # end
142
+ #
143
+ # should "ask for credentials when none were given before" do
144
+ # with_users "no_credentials"
145
+ # with_users_add
146
+ # with_server_add
147
+ #
148
+ # when_asked "Webbynode Login:", :answer => 'fcoury@me.com'
149
+ # when_asked "Webbynode Token:", :answer => 'abc123456'
150
+ #
151
+ # command "server add webbynode sandbox"
152
+ # stdout.should =~ /Webbynode credentials saved./
153
+ # stdout.should =~ /Server sandbox added successfully/
154
+ # end
155
+ #
156
+ # should "add the server if proper credentials given" do
157
+ # with_users
158
+ # with_users_add
159
+ # with_server_add
160
+ #
161
+ # command "server add webbynode sandbox"
162
+ # stdout.should =~ /Server sandbox added successfully/
163
+ # end
164
+ #
165
+ # should "delete the server if proper credentials given and server exists" do
166
+ # with_users
167
+ # with_server_list("webbynode")
168
+ # with_server_delete
169
+ #
170
+ # command "server delete sandbox"
171
+ # stdout.should =~ /Server sandbox deleted successfully/
172
+ # end
173
+ #
174
+ # should "show the webbynode server when listing servers" do
175
+ # with_users
176
+ # with_server_list("webbynode")
177
+ #
178
+ # command "server"
179
+ # stdout.should =~ /Name/
180
+ # stdout.should =~ /Provider/
181
+ # stdout.should =~ /IP/
182
+ # stdout.should =~ /Status/
183
+ #
184
+ # stdout.should =~ /sandbox/
185
+ # stdout.should =~ /Webbynode/
186
+ # stdout.should =~ /208\.88\.125\.207/
187
+ # stdout.should =~ /running/
188
+ # end
189
+ # end
190
+ #
191
+ # context "adding a slicehost server" do
192
+ # should "abort when user enters 'abort' into the API password field" do
193
+ # with_users "no_credentials"
194
+ #
195
+ # when_asked "", :answer => 'abort'
196
+ # command "server add slicehost slicey"
197
+ #
198
+ # stdout.should =~ /Aborted adding server./
199
+ # stdout.should =~ /Enter your Slicehost API password/
200
+ # end
201
+ #
202
+ # should "show the help message when user enters 'help' into the API password field" do
203
+ # with_users "no_credentials"
204
+ #
205
+ # when_asked "", :answer => 'help'
206
+ # when_asked "", :answer => 'abort'
207
+ # command "server add slicehost slicey"
208
+ #
209
+ # stdout.should =~ /== Slicehost StackFu integration ==/
210
+ # end
211
+ #
212
+ # should "ask for credentials when none were given before" do
213
+ # with_users "no_credentials"
214
+ # with_users_add
215
+ # with_server_add
216
+ #
217
+ # when_asked "", :answer => "abc123"
218
+ #
219
+ # command "server add slicehost slicey"
220
+ # stdout.should =~ /Server slicey added successfully/
221
+ # end
222
+ #
223
+ # should "add the server if proper credentials given" do
224
+ # with_users
225
+ # with_users_add
226
+ # with_server_add
227
+ #
228
+ # command "server add slicehost slicey"
229
+ # stdout.should =~ /Server slicey added successfully/
230
+ # end
231
+ #
232
+ # should "delete the server if proper credentials given and server exists" do
233
+ # with_users
234
+ # with_server_list
235
+ # with_server_delete
236
+ #
237
+ # command "server delete slicey"
238
+ # stdout.should =~ /Server slicey deleted successfully/
239
+ # end
240
+ #
241
+ # should "show a selection when same server hostname repeats in more than one provider"
242
+ #
243
+ # should "show the slicehost server when listing servers" do
244
+ # with_users
245
+ # with_server_list
246
+ #
247
+ # command "server"
248
+ # stdout.should =~ /Name/
249
+ # stdout.should =~ /Provider/
250
+ # stdout.should =~ /IP/
251
+ # stdout.should =~ /Status/
252
+ #
253
+ # stdout.should =~ /slicey/
254
+ # stdout.should =~ /Slicehost/
255
+ # stdout.should =~ /174\.143\.145\.37/
256
+ # stdout.should =~ /running/
257
+ # end
258
+ # end
259
+ # end