engineyard-cloud-client 1.0.8 → 1.0.9
Sign up to get free protection for your applications and to get access to all the features.
- data/ChangeLog.md +4 -0
- data/lib/engineyard-cloud-client/connection.rb +24 -2
- data/lib/engineyard-cloud-client/model_registry.rb +3 -3
- data/lib/engineyard-cloud-client/models/api_struct.rb +1 -1
- data/lib/engineyard-cloud-client/models/deployment.rb +11 -0
- data/lib/engineyard-cloud-client/test/fake_awsm/config.ru +6 -6
- data/lib/engineyard-cloud-client/test/fake_awsm.rb +1 -1
- data/lib/engineyard-cloud-client/version.rb +1 -1
- data/spec/engineyard-cloud-client/integration/deployment_spec.rb +32 -0
- data/spec/engineyard-cloud-client/models/api_struct_spec.rb +1 -1
- data/spec/engineyard-cloud-client/models/app_spec.rb +2 -2
- data/spec/engineyard-cloud-client/models/environment_spec.rb +4 -4
- data/spec/spec_helper.rb +0 -1
- metadata +20 -4
data/ChangeLog.md
CHANGED
@@ -40,7 +40,7 @@ module EY
|
|
40
40
|
unless String === value
|
41
41
|
value = value.pretty_inspect.rstrip # remove trailing whitespace
|
42
42
|
if value.index("\n") # if the inspect is multi-line
|
43
|
-
value.gsub
|
43
|
+
value = value.gsub(/^/, " "*(indent + 2)).lstrip # indent it
|
44
44
|
end
|
45
45
|
end
|
46
46
|
@output << "#{name.to_s.rjust(indent)} #{value.rstrip}\n" # just one newline
|
@@ -118,11 +118,33 @@ module EY
|
|
118
118
|
rescue RestClient::BadGateway
|
119
119
|
raise RequestFailed, "EY Cloud API is temporarily unavailable. Please try again soon."
|
120
120
|
rescue RestClient::RequestFailed => e
|
121
|
-
raise RequestFailed, "
|
121
|
+
raise RequestFailed, "Error: #{parse_error(e)}"
|
122
122
|
rescue OpenSSL::SSL::SSLError
|
123
123
|
raise RequestFailed, "SSL is misconfigured on your cloud"
|
124
124
|
end
|
125
125
|
|
126
|
+
def parse_error(error)
|
127
|
+
resp = error.response
|
128
|
+
debug("Error", error.message)
|
129
|
+
|
130
|
+
if resp.body.empty?
|
131
|
+
debug("Response", '<<Response body is empty>>')
|
132
|
+
error.message
|
133
|
+
elsif resp.headers[:content_type] =~ /application\/json/
|
134
|
+
begin
|
135
|
+
data = MultiJson.load(resp.body)
|
136
|
+
debug("Response", data)
|
137
|
+
data['message'] ? data['message'] : "#{error.message} #{data.inspect}"
|
138
|
+
rescue MultiJson::DecodeError
|
139
|
+
debug("Response", resp.body)
|
140
|
+
"#{error.message} #{resp.body}"
|
141
|
+
end
|
142
|
+
else
|
143
|
+
debug("Response", resp.body)
|
144
|
+
"#{error.message} #{resp.body}"
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
126
148
|
def parse_response(resp)
|
127
149
|
if resp.body.empty?
|
128
150
|
''
|
@@ -110,6 +110,17 @@ module EY
|
|
110
110
|
put_to_api({:successful => successful, :output => output.read})
|
111
111
|
end
|
112
112
|
|
113
|
+
def cancel
|
114
|
+
if finished?
|
115
|
+
raise EY::CloudClient::Error, "Previous deployment is already finished. Aborting."
|
116
|
+
else
|
117
|
+
current_user_name = api.current_user.name
|
118
|
+
self.successful = false
|
119
|
+
err << "!> Marked as canceled by #{current_user_name}"
|
120
|
+
finished
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
113
124
|
def finished?
|
114
125
|
!finished_at.nil?
|
115
126
|
end
|
@@ -97,7 +97,7 @@ class FakeAwsm < Sinatra::Base
|
|
97
97
|
""
|
98
98
|
else
|
99
99
|
status 404
|
100
|
-
|
100
|
+
json "message" => "Keypair not found with id #{params['id'].inspect}"
|
101
101
|
end
|
102
102
|
end
|
103
103
|
|
@@ -133,7 +133,7 @@ class FakeAwsm < Sinatra::Base
|
|
133
133
|
end
|
134
134
|
|
135
135
|
get "/api/v2/environments/:env_id/logs" do
|
136
|
-
|
136
|
+
json(
|
137
137
|
"logs" => [
|
138
138
|
{
|
139
139
|
"id" => 'i-12345678',
|
@@ -142,7 +142,7 @@ class FakeAwsm < Sinatra::Base
|
|
142
142
|
"custom" => "CUSTOM LOG OUTPUT"
|
143
143
|
}
|
144
144
|
]
|
145
|
-
|
145
|
+
)
|
146
146
|
end
|
147
147
|
|
148
148
|
get "/api/v2/environments/:env_id/recipes" do
|
@@ -210,7 +210,7 @@ class FakeAwsm < Sinatra::Base
|
|
210
210
|
render :rabl, :deployment, :format => "json"
|
211
211
|
else
|
212
212
|
status(404)
|
213
|
-
|
213
|
+
json "message" => "Deployment not found: last"
|
214
214
|
end
|
215
215
|
end
|
216
216
|
|
@@ -224,10 +224,10 @@ class FakeAwsm < Sinatra::Base
|
|
224
224
|
post "/api/v2/authenticate" do
|
225
225
|
user = User.first(:email => params[:email], :password => params[:password])
|
226
226
|
if user
|
227
|
-
|
227
|
+
json "api_token" => user.api_token, "ok" => true
|
228
228
|
else
|
229
229
|
status(401)
|
230
|
-
|
230
|
+
json "ok" => false
|
231
231
|
end
|
232
232
|
end
|
233
233
|
|
@@ -15,7 +15,7 @@ module EY::CloudClient::Test
|
|
15
15
|
unless system("ruby -c '#{config_ru}' > /dev/null")
|
16
16
|
raise SyntaxError, "There is a syntax error in fake_awsm/config.ru! FIX IT!"
|
17
17
|
end
|
18
|
-
@server = RealWeb.start_server_in_fork(config_ru, :timeout =>
|
18
|
+
@server = RealWeb.start_server_in_fork(config_ru, :timeout => 10, :verbose => ENV['DEBUG'])
|
19
19
|
@server.base_uri.to_s
|
20
20
|
end
|
21
21
|
end
|
@@ -109,5 +109,37 @@ describe EY::CloudClient::AppEnvironment do
|
|
109
109
|
deployment.finished
|
110
110
|
EY::CloudClient::Deployment.last(@api, @app_env).should == deployment
|
111
111
|
end
|
112
|
+
|
113
|
+
context "canceling" do
|
114
|
+
before do
|
115
|
+
deployment = @app_env.new_deployment({
|
116
|
+
:ref => 'master',
|
117
|
+
:migrate => true,
|
118
|
+
:migrate_command => 'rake migrate',
|
119
|
+
})
|
120
|
+
deployment.start
|
121
|
+
end
|
122
|
+
|
123
|
+
it "marks the deployment finish and unsuccessful with a message" do
|
124
|
+
deployment = EY::CloudClient::Deployment.last(@api, @app_env)
|
125
|
+
deployment.should_not be_finished
|
126
|
+
deployment.cancel
|
127
|
+
deployment.should be_finished
|
128
|
+
deployment.should_not be_successful
|
129
|
+
deployment.output.rewind
|
130
|
+
deployment.output.read.should =~ /Marked as canceled by Linked App/
|
131
|
+
|
132
|
+
EY::CloudClient::Deployment.last(@api, @app_env).should be_finished
|
133
|
+
end
|
134
|
+
|
135
|
+
it "raises if the deployment is already finished" do
|
136
|
+
deployment = EY::CloudClient::Deployment.last(@api, @app_env)
|
137
|
+
deployment.out << "Test output"
|
138
|
+
deployment.successful = true
|
139
|
+
deployment.finished
|
140
|
+
deployment.should be_finished
|
141
|
+
expect { deployment.cancel }.to raise_error(EY::CloudClient::Error, "Previous deployment is already finished. Aborting.")
|
142
|
+
end
|
143
|
+
end
|
112
144
|
end
|
113
145
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe EY::CloudClient::ApiStruct do
|
4
|
-
class Foo < EY::CloudClient::ApiStruct.new(:fruit, :veggie); end
|
4
|
+
class Foo < EY::CloudClient::ApiStruct.new(:id, :fruit, :veggie); end
|
5
5
|
|
6
6
|
it "acts like a normal struct" do
|
7
7
|
f = Foo.new(cloud_client, "fruit" => "banana")
|
@@ -16,7 +16,7 @@ describe EY::CloudClient::App do
|
|
16
16
|
}
|
17
17
|
|
18
18
|
FakeWeb.register_uri(:get, "https://cloud.engineyard.com/api/v2/apps?no_instances=true",
|
19
|
-
:body => response
|
19
|
+
:body => MultiJson.dump(response), :content_type => "application/json")
|
20
20
|
|
21
21
|
apps = EY::CloudClient::App.all(cloud_client)
|
22
22
|
|
@@ -40,7 +40,7 @@ describe EY::CloudClient::App do
|
|
40
40
|
}
|
41
41
|
|
42
42
|
FakeWeb.register_uri(:post, "https://cloud.engineyard.com/api/v2/accounts/1234/apps",
|
43
|
-
:body => response
|
43
|
+
:body => MultiJson.dump(response), :content_type => "application/json")
|
44
44
|
|
45
45
|
app = EY::CloudClient::App.create(cloud_client, {
|
46
46
|
"account" => account,
|
@@ -36,7 +36,7 @@ describe EY::CloudClient::Environment do
|
|
36
36
|
}
|
37
37
|
|
38
38
|
FakeWeb.register_uri(:get, "https://cloud.engineyard.com/api/v2/environments?no_instances=true",
|
39
|
-
:body => response
|
39
|
+
:body => MultiJson.dump(response), :content_type => "application/json")
|
40
40
|
|
41
41
|
environments = EY::CloudClient::Environment.all(cloud_client)
|
42
42
|
|
@@ -80,7 +80,7 @@ describe EY::CloudClient::Environment do
|
|
80
80
|
"instance_status"=>"none"}}
|
81
81
|
|
82
82
|
FakeWeb.register_uri(:post, "https://cloud.engineyard.com/api/v2/apps/12345/environments",
|
83
|
-
:body => response
|
83
|
+
:body => MultiJson.dump(response), :content_type => "application/json")
|
84
84
|
|
85
85
|
env = EY::CloudClient::Environment.create(cloud_client, {
|
86
86
|
"app" => app,
|
@@ -143,7 +143,7 @@ describe EY::CloudClient::Environment do
|
|
143
143
|
"instance_status"=>"starting"}}
|
144
144
|
|
145
145
|
FakeWeb.register_uri(:post, "https://cloud.engineyard.com/api/v2/apps/12345/environments",
|
146
|
-
:body => response
|
146
|
+
:body => MultiJson.dump(response), :content_type => "application/json")
|
147
147
|
|
148
148
|
env = EY::CloudClient::Environment.create(cloud_client, {
|
149
149
|
"app" => app,
|
@@ -218,7 +218,7 @@ describe EY::CloudClient::Environment do
|
|
218
218
|
|
219
219
|
FakeWeb.register_uri(:get,
|
220
220
|
"https://cloud.engineyard.com/api/v2/environments/#{env.id}/instances",
|
221
|
-
:body => {"instances" => [instance_data]}
|
221
|
+
:body => MultiJson.dump({"instances" => [instance_data]}),
|
222
222
|
:content_type => 'application/json'
|
223
223
|
)
|
224
224
|
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: engineyard-cloud-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.9
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-02-
|
12
|
+
date: 2013-02-20 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rest-client
|
@@ -251,6 +251,22 @@ dependencies:
|
|
251
251
|
- - ! '>='
|
252
252
|
- !ruby/object:Gem::Version
|
253
253
|
version: '0'
|
254
|
+
- !ruby/object:Gem::Dependency
|
255
|
+
name: oj
|
256
|
+
requirement: !ruby/object:Gem::Requirement
|
257
|
+
none: false
|
258
|
+
requirements:
|
259
|
+
- - ! '>='
|
260
|
+
- !ruby/object:Gem::Version
|
261
|
+
version: '0'
|
262
|
+
type: :development
|
263
|
+
prerelease: false
|
264
|
+
version_requirements: !ruby/object:Gem::Requirement
|
265
|
+
none: false
|
266
|
+
requirements:
|
267
|
+
- - ! '>='
|
268
|
+
- !ruby/object:Gem::Version
|
269
|
+
version: '0'
|
254
270
|
description: This gem connects to the EY Cloud API
|
255
271
|
email: cloud@engineyard.com
|
256
272
|
executables: []
|
@@ -338,7 +354,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
338
354
|
version: '0'
|
339
355
|
segments:
|
340
356
|
- 0
|
341
|
-
hash: -
|
357
|
+
hash: -3697782236831721463
|
342
358
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
343
359
|
none: false
|
344
360
|
requirements:
|
@@ -347,7 +363,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
347
363
|
version: '0'
|
348
364
|
segments:
|
349
365
|
- 0
|
350
|
-
hash: -
|
366
|
+
hash: -3697782236831721463
|
351
367
|
requirements: []
|
352
368
|
rubyforge_project:
|
353
369
|
rubygems_version: 1.8.24
|