right_api_helper 0.0.1
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.
- data/.gitignore +25 -0
- data/.rspec +2 -0
- data/Gemfile +4 -0
- data/LICENSE +13 -0
- data/README.md +66 -0
- data/Rakefile +7 -0
- data/bin/organize +193 -0
- data/demo/deployments.json +44 -0
- data/demo/index.html +83 -0
- data/demo/logo.png +0 -0
- data/demo/start_server.sh +12 -0
- data/demo/tree.jquery.js +2947 -0
- data/lib/right_api_helper/api15.rb +357 -0
- data/lib/right_api_helper/base.rb +54 -0
- data/lib/right_api_helper/cache.rb +53 -0
- data/lib/right_api_helper/deployments.rb +39 -0
- data/lib/right_api_helper/instances.rb +46 -0
- data/lib/right_api_helper/scripts/deployments_creator.rb +44 -0
- data/lib/right_api_helper/session.rb +76 -0
- data/lib/right_api_helper/version.rb +3 -0
- data/lib/right_api_helper.rb +32 -0
- data/right_api_helper.gemspec +30 -0
- data/spec/api15_spec.rb +280 -0
- data/spec/cache_spec.rb +57 -0
- data/spec/data/deployments.json +44 -0
- data/spec/deployments_spec.rb +57 -0
- data/spec/instances_spec.rb +41 -0
- data/spec/scripts/deployments_creator_spec.rb +59 -0
- data/spec/session_spec.rb +46 -0
- data/spec/spec_helper.rb +50 -0
- metadata +214 -0
@@ -0,0 +1,32 @@
|
|
1
|
+
#
|
2
|
+
# Author: cary@rightscale.com
|
3
|
+
# Copyright 2014 RightScale, Inc.
|
4
|
+
#
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
# you may not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
# See the License for the specific language governing permissions and
|
15
|
+
# limitations under the License.
|
16
|
+
#
|
17
|
+
|
18
|
+
require "right_api_client"
|
19
|
+
require "yaml"
|
20
|
+
|
21
|
+
require 'right_api_helper/version'
|
22
|
+
require 'right_api_helper/base'
|
23
|
+
require 'right_api_helper/cache'
|
24
|
+
require 'right_api_helper/session'
|
25
|
+
require 'right_api_helper/api15'
|
26
|
+
require 'right_api_helper/deployments'
|
27
|
+
require 'right_api_helper/instances'
|
28
|
+
require 'right_api_helper/scripts/deployments_creator'
|
29
|
+
|
30
|
+
module RightApiHelper
|
31
|
+
# Hey now!
|
32
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'right_api_helper/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "right_api_helper"
|
8
|
+
spec.version = RightApiHelper::VERSION
|
9
|
+
spec.authors = ["caryp"]
|
10
|
+
spec.email = ["cary@rightscale.com"]
|
11
|
+
spec.summary = %q{A collection of helper objects and methods for right_api_client gem}
|
12
|
+
spec.description = %q{A collection of helper objects and methods for right_api_client gem}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_dependency "right_api_client", "~> 1.5.15"
|
22
|
+
spec.add_dependency "thor"
|
23
|
+
|
24
|
+
spec.add_development_dependency "bundler", "~> 1.6"
|
25
|
+
spec.add_development_dependency "rake"
|
26
|
+
spec.add_development_dependency "rspec"
|
27
|
+
spec.add_development_dependency "webmock"
|
28
|
+
spec.add_development_dependency "vcr", "~> 2.9.0"
|
29
|
+
spec.add_development_dependency "pry"
|
30
|
+
end
|
data/spec/api15_spec.rb
ADDED
@@ -0,0 +1,280 @@
|
|
1
|
+
#
|
2
|
+
# Author: cary@rightscale.com
|
3
|
+
# Copyright 2014 RightScale, Inc.
|
4
|
+
#
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
# you may not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
# See the License for the specific language governing permissions and
|
15
|
+
# limitations under the License.
|
16
|
+
#
|
17
|
+
|
18
|
+
require 'json'
|
19
|
+
require 'right_api_client'
|
20
|
+
require 'right_api_helper'
|
21
|
+
|
22
|
+
describe "API15 object" do
|
23
|
+
|
24
|
+
BAD_USER_DATA = "RS_server=my.rightscale.com&RS_token=89eeb0b19af40b5b72668dc3caa9934a&RS_sketchy=sketchy1-166.rightscale.com"
|
25
|
+
|
26
|
+
before(:each) do
|
27
|
+
apiStub = double("RightApi::Client", :api_url => "http://foo.com", :log => "")
|
28
|
+
RightApi::Client.should_receive(:new).and_return(apiStub)
|
29
|
+
@right_api_client = RightApiHelper::Session.new.create_client("someemail", "somepasswd", "someaccountid", "https://my.rightscale.com")
|
30
|
+
@api = RightApiHelper::API15.new(@right_api_client)
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should find deployment by name" do
|
34
|
+
deploymentsStub = double("deployments", :index => [ :name => "my_fake_deployment" ])
|
35
|
+
@api.instance_variable_get("@client").should_receive(:deployments).and_return(deploymentsStub)
|
36
|
+
@api.find_deployment_by_name("my_fake_deployment")
|
37
|
+
end
|
38
|
+
|
39
|
+
it "should raise error if deployment not found by name" do
|
40
|
+
deploymentsStub = double("deployments", :index => nil)
|
41
|
+
@api.instance_variable_get("@client").should_receive(:deployments).and_return(deploymentsStub)
|
42
|
+
lambda{@api.find_deployment_by_name("my_fake_deployment")}.should raise_error
|
43
|
+
end
|
44
|
+
|
45
|
+
it "should raise error if multiple deployments found by name" do
|
46
|
+
deploymentsStub = double("deployments", :index => [ {:name => "my_fake_deployment"}, {:name => "my_fake_deployment2"} ])
|
47
|
+
@api.instance_variable_get("@client").should_receive(:deployments).and_return(deploymentsStub)
|
48
|
+
lambda{@api.find_deployment_by_name("my_fake_deployment")}.should raise_error
|
49
|
+
end
|
50
|
+
|
51
|
+
it "should find server by name" do
|
52
|
+
serversStub = double("servers", :index => [ :name => "my_fake_server" ])
|
53
|
+
@api.instance_variable_get("@client").should_receive(:servers).and_return(serversStub)
|
54
|
+
@api.find_server_by_name("my_fake_server")
|
55
|
+
end
|
56
|
+
|
57
|
+
it "should raise error if multiple servers found by name" do
|
58
|
+
serversStub = double("servers", :index => [ {:name => "my_fake_server"}, {:name => "my_fake_server2"} ])
|
59
|
+
@api.instance_variable_get("@client").should_receive(:servers).and_return(serversStub)
|
60
|
+
lambda{@api.find_server_by_name("my_fake_server")}.should raise_error
|
61
|
+
end
|
62
|
+
|
63
|
+
it "should find cloud by name" do
|
64
|
+
cloudsStub = double("clouds", :index => [ :name => "my_fake_cloud" ])
|
65
|
+
@api.instance_variable_get("@client").should_receive(:clouds).and_return(cloudsStub)
|
66
|
+
@api.find_cloud_by_name("my_fake_cloud")
|
67
|
+
end
|
68
|
+
|
69
|
+
it "should raise error if cloud not found by name" do
|
70
|
+
cloudsStub = double("clouds", :index => nil)
|
71
|
+
@api.instance_variable_get("@client").should_receive(:clouds).and_return(cloudsStub)
|
72
|
+
lambda{@api.find_cloud_by_name("my_fake_cloud")}.should raise_error
|
73
|
+
end
|
74
|
+
|
75
|
+
it "should find MCI by name" do
|
76
|
+
mcisStub = double("multi_cloud_images", :index => [ :name => "my_fake_mci" ])
|
77
|
+
@api.instance_variable_get("@client").should_receive(:multi_cloud_images).and_return(mcisStub)
|
78
|
+
@api.find_mci_by_name("my_fake_mci")
|
79
|
+
end
|
80
|
+
|
81
|
+
it "should raise error if multiple MCI found by name" do
|
82
|
+
mcisStub = double("multi_cloud_images", :index => [ {:name => "my_fake_mci"}, {:name => "my_fake_mci2"} ])
|
83
|
+
@api.instance_variable_get("@client").should_receive(:multi_cloud_images).and_return(mcisStub)
|
84
|
+
lambda{@api.find_mci_by_name("my_fake_mci")}.should raise_error
|
85
|
+
end
|
86
|
+
|
87
|
+
it "should find servertemplate by name" do
|
88
|
+
servertemplatesStub = double("servertemplates", :index => [ double("servertemplate", :name => "my_fake_servertemplate", :revision => [0, 1, 2, 3, 4 ]) ])
|
89
|
+
@api.instance_variable_get("@client").should_receive(:server_templates).and_return(servertemplatesStub)
|
90
|
+
@api.find_servertemplate("my_fake_servertemplate")
|
91
|
+
end
|
92
|
+
|
93
|
+
it "should raise error if no servertemplates found by name" do
|
94
|
+
servertemplatesStub = double("servertemplates", :index => [])
|
95
|
+
@api.instance_variable_get("@client").should_receive(:server_templates).and_return(servertemplatesStub)
|
96
|
+
lambda{@api.find_servertemplate("my_fake_servertemplate")}.should raise_error
|
97
|
+
end
|
98
|
+
|
99
|
+
it "should raise error if multiple servertemplates found by name" do
|
100
|
+
servertemplatesStub = double("servertemplates", :index => [ double("servertemplate", :name => "my_fake_servertemplate"), double("servertemplate", :name => "my_fake_servertemplate") ])
|
101
|
+
@api.instance_variable_get("@client").should_receive(:server_templates).and_return(servertemplatesStub)
|
102
|
+
lambda{@api.find_servertemplate("my_fake_servertemplate")}.should raise_error
|
103
|
+
end
|
104
|
+
|
105
|
+
it "should find servertemplate by id" do
|
106
|
+
servertemplatesStub = double("servertemplates", :index => [ :name => "my_fake_servertemplate" ])
|
107
|
+
@api.instance_variable_get("@client").should_receive(:server_templates).and_return(servertemplatesStub)
|
108
|
+
@api.find_servertemplate(1234)
|
109
|
+
end
|
110
|
+
|
111
|
+
it "should create deployment" do
|
112
|
+
deploymentsStub = double("deployments", :create => [ {:name => "my_fake_deployment"} ])
|
113
|
+
@api.instance_variable_get("@client").should_receive(:deployments).and_return(deploymentsStub)
|
114
|
+
deploymentsStub.should_receive(:create)
|
115
|
+
@api.create_deployment("my_deployment")
|
116
|
+
end
|
117
|
+
|
118
|
+
it "should destroy a deployment" do
|
119
|
+
deploymentsStub = double("deployments", :destroy => nil)
|
120
|
+
deploymentsStub.should_receive(:destroy)
|
121
|
+
@api.destroy_deployment(deploymentsStub)
|
122
|
+
end
|
123
|
+
|
124
|
+
it "should create server with the default MCI" do
|
125
|
+
dStub = double("deployment", :href => "/some/fake/path")
|
126
|
+
dsStub = double("deployments", :show => dStub)
|
127
|
+
@api.should_receive(:create_deployment).and_return(dsStub)
|
128
|
+
deployment = @api.create_deployment("my_deployment")
|
129
|
+
|
130
|
+
stStub = double("servertemplate", :href => "/some/fake/path", :show => "")
|
131
|
+
stsStub = double("servertemplates", :show => stStub)
|
132
|
+
@api.should_receive(:find_servertemplate).and_return(stsStub)
|
133
|
+
server_template = @api.find_servertemplate(1234)
|
134
|
+
|
135
|
+
cStub = double("cloud", :href => "/some/fake/path")
|
136
|
+
csStub = double("clouds", :show => cStub)
|
137
|
+
@api.should_receive(:find_cloud_by_name).and_return(csStub)
|
138
|
+
cloud = @api.find_cloud_by_name(1234)
|
139
|
+
|
140
|
+
serversStub = double("servers", :create => [ :name => "my_fake_server" ])
|
141
|
+
@api.instance_variable_get("@client").should_receive(:servers).and_return(serversStub)
|
142
|
+
@api.create_server(deployment, server_template, nil, cloud, "my_fake_server")
|
143
|
+
end
|
144
|
+
|
145
|
+
it "should create server with the MCI given" do
|
146
|
+
dStub = double("deployment", :href => "/some/fake/path")
|
147
|
+
dsStub = double("deployments", :show => dStub)
|
148
|
+
@api.should_receive(:create_deployment).and_return(dsStub)
|
149
|
+
deployment = @api.create_deployment("my_deployment")
|
150
|
+
|
151
|
+
stStub = double("servertemplate", :href => "/some/fake/path", :show => "")
|
152
|
+
stsStub = double("servertemplates", :show => stStub)
|
153
|
+
@api.should_receive(:find_servertemplate).and_return(stsStub)
|
154
|
+
server_template = @api.find_servertemplate(1234)
|
155
|
+
|
156
|
+
mciStub = double("mci", :href => "/some/fake/path")
|
157
|
+
mcisStub = double("mcis", :show => mciStub)
|
158
|
+
@api.should_receive(:find_mci_by_name).and_return(mcisStub)
|
159
|
+
mci = @api.find_mci_by_name("CentOS")
|
160
|
+
|
161
|
+
cStub = double("cloud", :href => "/some/fake/path")
|
162
|
+
csStub = double("clouds", :show => cStub)
|
163
|
+
@api.should_receive(:find_cloud_by_name).and_return(csStub)
|
164
|
+
cloud = @api.find_cloud_by_name(1234)
|
165
|
+
|
166
|
+
serversStub = double("servers", :create => [ :name => "my_fake_server" ])
|
167
|
+
@api.instance_variable_get("@client").should_receive(:servers).and_return(serversStub)
|
168
|
+
@api.create_server(deployment, server_template, mci, cloud, "my_fake_server")
|
169
|
+
end
|
170
|
+
|
171
|
+
it "should launch server with inputs" do
|
172
|
+
serverStub = double("server", :name => "foo")
|
173
|
+
serversStub = double("servers", :launch => true, :show => serverStub, :index => [ :name => "my_fake_server" ])
|
174
|
+
@api.should_receive(:create_server).and_return(serversStub)
|
175
|
+
server = @api.create_server("foo", "bar", "my_fake_server")
|
176
|
+
@api.instance_variable_get("@client").should_receive(:servers).and_return(serversStub)
|
177
|
+
@api.launch_server(server, [ {:name => "input1", :value => 1} ])
|
178
|
+
end
|
179
|
+
|
180
|
+
it "should launch server without inputs" do
|
181
|
+
serverStub = double("server", :name => "foo")
|
182
|
+
serversStub = double("servers", :launch => true, :show => serverStub, :index => [ :name => "my_fake_server" ])
|
183
|
+
@api.should_receive(:create_server).and_return(serversStub)
|
184
|
+
server = @api.create_server("foo", "bar", "my_fake_server")
|
185
|
+
@api.instance_variable_get("@client").should_receive(:servers).and_return(serversStub)
|
186
|
+
@api.launch_server(server)
|
187
|
+
end
|
188
|
+
|
189
|
+
it "returns user_data" do
|
190
|
+
instanceDataStub = double("idata", :user_data => "someuserdata")
|
191
|
+
instanceStub = double("instance", :show => instanceDataStub)
|
192
|
+
serverDataStub = double("sdata", :current_instance => instanceStub)
|
193
|
+
serverStub = double("server", :show => serverDataStub)
|
194
|
+
serverDataStub.should_receive(:current_instance).with(:view=>"extended")
|
195
|
+
@api.user_data(serverStub).should == "someuserdata"
|
196
|
+
end
|
197
|
+
|
198
|
+
it "returns data_request_url for instance" do
|
199
|
+
@user_data = "RS_rn_url=amqp://b915586461:278a854748@orange2-broker.test.rightscale.com/right_net&RS_rn_id=4985249009&RS_server=orange2-moo.test.rightscale.com&RS_rn_auth=d98106775832c174ffd55bd7b7cb175077574adf&RS_token=b233a57d1d24f27bd8650d0f9b6bfd54&RS_sketchy=sketchy1-145.rightscale.com&RS_rn_host=:0"
|
200
|
+
@request_data_url = "https://my.rightscale.com/servers/data_injection_payload/d98106775832c174ffd55bd7b7cb175077574adf"
|
201
|
+
@right_api_client.should_receive(:api_url).and_return("https://my.rightscale.com")
|
202
|
+
@api.data_request_url(@user_data).should == @request_data_url
|
203
|
+
end
|
204
|
+
|
205
|
+
it "returns true if server has a current instance" do
|
206
|
+
serverDataStub = double("sdata", :api_methods => [:current_instance])
|
207
|
+
serverStub = double("server", :show => serverDataStub)
|
208
|
+
@api.is_provisioned?(serverStub).should == true
|
209
|
+
end
|
210
|
+
|
211
|
+
it "returns false if server does not have a current instance" do
|
212
|
+
serverDataStub = double("sdata", :api_methods => [])
|
213
|
+
serverStub = double("server", :show => serverDataStub)
|
214
|
+
@api.is_provisioned?(serverStub).should == false
|
215
|
+
end
|
216
|
+
|
217
|
+
it "will not wait if server is in expected state" do
|
218
|
+
@api.should_receive(:server_state).and_return("booting")
|
219
|
+
@api.server_wait_for_state("fakeserver", "booting")
|
220
|
+
end
|
221
|
+
|
222
|
+
it "throws an error if server is stranded" do
|
223
|
+
@api.should_receive(:server_state).and_return("stranded")
|
224
|
+
@api.set_bad_states([ "stranded", "terminated"])
|
225
|
+
lambda{@api.server_wait_for_state("fakeserver", "operational")}.should raise_error
|
226
|
+
end
|
227
|
+
|
228
|
+
it "returns the server's cloud" do
|
229
|
+
cData = double("clouddata", :name => "cloudname")
|
230
|
+
cStub = double("cloud", :show => cData)
|
231
|
+
@api.should_receive(:instance_from_server)
|
232
|
+
@api.should_receive(:cloud_from_instance).and_return(cStub)
|
233
|
+
@api.server_cloud_name("foo").should == "cloudname"
|
234
|
+
end
|
235
|
+
|
236
|
+
it "returns the current instance from the server is provisioned" do
|
237
|
+
serverDataStub = double("sdata", :current_instance => "current")
|
238
|
+
serverStub = double("server", :show => serverDataStub)
|
239
|
+
@api.should_receive(:is_provisioned?).and_return(true)
|
240
|
+
@api.send(:instance_from_server, serverStub).should == "current"
|
241
|
+
end
|
242
|
+
|
243
|
+
it "returns the next instance from the server is not provisioned" do
|
244
|
+
serverDataStub = double("sdata", :next_instance => "next")
|
245
|
+
serverStub = double("server", :show => serverDataStub)
|
246
|
+
@api.should_receive(:is_provisioned?).and_return(false)
|
247
|
+
@api.send(:instance_from_server, serverStub).should == "next"
|
248
|
+
end
|
249
|
+
|
250
|
+
it "returns server state" do
|
251
|
+
instanceDataStub = double("idata", :state => "booting")
|
252
|
+
instanceStub = double("instance", :show => instanceDataStub)
|
253
|
+
@api.should_receive(:instance_from_server).and_return(instanceStub)
|
254
|
+
@api.send(:server_state, "server").should == "booting"
|
255
|
+
end
|
256
|
+
|
257
|
+
it "returns the cloud from the instance" do
|
258
|
+
instanceDataStub = double("idata", :cloud => "somecloudobj")
|
259
|
+
instanceStub = double("instance", :show => instanceDataStub)
|
260
|
+
@api.send(:cloud_from_instance, instanceStub).should == "somecloudobj"
|
261
|
+
end
|
262
|
+
|
263
|
+
it "sets inputs on the next instance" do
|
264
|
+
inputsStub = double("inputs")
|
265
|
+
inputsStub.should_receive(:multi_update).with({"inputs" => "heynow"})
|
266
|
+
instanceDataStub = double("idata", :inputs => inputsStub)
|
267
|
+
instanceStub = double("instance", :show => instanceDataStub)
|
268
|
+
serverDataStub = double("sdata", :next_instance => instanceStub)
|
269
|
+
serverStub = double("server", :show => serverDataStub)
|
270
|
+
@api.set_server_inputs(serverStub, "heynow")
|
271
|
+
end
|
272
|
+
|
273
|
+
it "terminates a server" do
|
274
|
+
serverStub = double("server")
|
275
|
+
serverStub.should_receive(:terminate)
|
276
|
+
@api.terminate_server(serverStub)
|
277
|
+
end
|
278
|
+
|
279
|
+
|
280
|
+
end
|
data/spec/cache_spec.rb
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
#
|
2
|
+
# Author: cary@rightscale.com
|
3
|
+
# Copyright 2014 RightScale, Inc.
|
4
|
+
#
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
# you may not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
# See the License for the specific language governing permissions and
|
15
|
+
# limitations under the License.
|
16
|
+
#
|
17
|
+
|
18
|
+
require 'spec_helper'
|
19
|
+
|
20
|
+
describe RightApiHelper::Cache do
|
21
|
+
|
22
|
+
before(:each) do
|
23
|
+
@helper = RightApiHelper::Cache.new("test_cache")
|
24
|
+
@helper.logger(double("Logger", :info => nil))
|
25
|
+
@test_hash = { "lame saying" => "hey now!", :foo => :bar }
|
26
|
+
end
|
27
|
+
|
28
|
+
it "clears a cache file" do
|
29
|
+
File.should_receive(:exists?).exactly(1).and_return(true)
|
30
|
+
File.should_receive(:delete).exactly(1)
|
31
|
+
@helper.clear
|
32
|
+
end
|
33
|
+
|
34
|
+
it "does not clear a cache file if it does not exist" do
|
35
|
+
File.should_receive(:exists?).exactly(1).and_return(false)
|
36
|
+
File.should_receive(:delete).exactly(0)
|
37
|
+
@helper.clear
|
38
|
+
end
|
39
|
+
|
40
|
+
it "returns nil if no cache file" do
|
41
|
+
File.should_receive(:exists?).exactly(1).and_return(false)
|
42
|
+
@helper.get.should == nil
|
43
|
+
end
|
44
|
+
|
45
|
+
it "writes a hash to a cache file" do
|
46
|
+
io_stub = double('fakefile', :write => nil)
|
47
|
+
File.should_receive(:open).and_return(io_stub)
|
48
|
+
@helper.set(@test_hash)
|
49
|
+
end
|
50
|
+
|
51
|
+
it "returns cache file contents" do
|
52
|
+
File.should_receive(:exists?).exactly(1).and_return(true)
|
53
|
+
File.should_receive(:open).and_return(YAML.dump(@test_hash))
|
54
|
+
@helper.get.should == @test_hash
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
{
|
2
|
+
"deployments": [
|
3
|
+
{
|
4
|
+
"name": "test-prefix-zensmartfeedpool-a-zookeeper",
|
5
|
+
"members": [
|
6
|
+
{
|
7
|
+
"href": "/api/clouds/3/instances/81UFDJ84L77VP",
|
8
|
+
"type": "Instance",
|
9
|
+
"name": "zookeeper002"
|
10
|
+
},
|
11
|
+
{
|
12
|
+
"href": "/api/clouds/3/instances/CST1BOUCO79MV",
|
13
|
+
"type": "Instance",
|
14
|
+
"name": "zookeeper001"
|
15
|
+
},
|
16
|
+
{
|
17
|
+
"href": "/api/clouds/3/instances/2BMBTLFSR3K7T",
|
18
|
+
"type": "Instance",
|
19
|
+
"name": "zookeeper001"
|
20
|
+
}
|
21
|
+
]
|
22
|
+
},
|
23
|
+
{
|
24
|
+
"name": "test-prefix-zensmartfeedpool-b-zookeeper",
|
25
|
+
"members": [
|
26
|
+
{
|
27
|
+
"href": "/api/clouds/3/instances/E3F9H5G2M7D05",
|
28
|
+
"type": "Instance",
|
29
|
+
"name": "zookeeper002"
|
30
|
+
}
|
31
|
+
]
|
32
|
+
},
|
33
|
+
{
|
34
|
+
"name": "test-prefix-zensmartfeedpool-a-zook",
|
35
|
+
"members": [
|
36
|
+
{
|
37
|
+
"href": "/api/clouds/3/instances/18UBA2151G2BQ",
|
38
|
+
"type": "Instance",
|
39
|
+
"name": "zook0023"
|
40
|
+
}
|
41
|
+
]
|
42
|
+
}
|
43
|
+
]
|
44
|
+
}
|
@@ -0,0 +1,57 @@
|
|
1
|
+
#
|
2
|
+
# Author: cary@rightscale.com
|
3
|
+
# Copyright 2014 RightScale, Inc.
|
4
|
+
#
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
# you may not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
# See the License for the specific language governing permissions and
|
15
|
+
# limitations under the License.
|
16
|
+
#
|
17
|
+
|
18
|
+
require 'spec_helper'
|
19
|
+
|
20
|
+
describe RightApiHelper::Deployments do
|
21
|
+
|
22
|
+
before(:all) do
|
23
|
+
# Get API session
|
24
|
+
VCR.use_cassette('right_api_session') do
|
25
|
+
session = RightApiHelper::Session.new
|
26
|
+
session.should_receive(:setup_client_logging)
|
27
|
+
@right_api_client = session.create_client_from_file("~/.right_api_client/login.yml")
|
28
|
+
end
|
29
|
+
VCR.use_cassette('right_api_general') do
|
30
|
+
@deployment_helper = RightApiHelper::Deployments.new(@right_api_client)
|
31
|
+
@logger = stub("Logger")
|
32
|
+
@deployment_helper.logger(@logger)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
it "finds existing deployments" do
|
37
|
+
VCR.use_cassette('right_api_general') do
|
38
|
+
@logger.should_receive(:info).exactly(2)
|
39
|
+
deployment = @deployment_helper.find_or_create("Default")
|
40
|
+
deployment.name.should == "Default"
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
it "creates new deployment if not found" do
|
45
|
+
VCR.use_cassette('right_api_general') do
|
46
|
+
@logger.should_receive(:info).exactly(3)
|
47
|
+
deployment = @deployment_helper.find_or_create("TEST:right_api_helper deleteme!")
|
48
|
+
deployment.show.name.should == "TEST:right_api_helper deleteme!"
|
49
|
+
deployment.destroy
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
it "adds an instance to a deployment" do
|
54
|
+
pending("this feature not yet supported by RightScale API")
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
#
|
2
|
+
# Author: cary@rightscale.com
|
3
|
+
# Copyright 2014 RightScale, Inc.
|
4
|
+
#
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
# you may not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
# See the License for the specific language governing permissions and
|
15
|
+
# limitations under the License.
|
16
|
+
#
|
17
|
+
|
18
|
+
require 'spec_helper'
|
19
|
+
|
20
|
+
describe RightApiHelper::Instances do
|
21
|
+
|
22
|
+
before(:all) do
|
23
|
+
# Get API session
|
24
|
+
VCR.use_cassette('right_api_session') do
|
25
|
+
session = RightApiHelper::Session.new
|
26
|
+
session.should_receive(:setup_client_logging)
|
27
|
+
@right_api_client = session.create_client_from_file("~/.right_api_client/login.yml")
|
28
|
+
end
|
29
|
+
VCR.use_cassette('right_api_general') do
|
30
|
+
@helper = RightApiHelper::Instances.new(@right_api_client)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
it "gets all instances in account" do
|
35
|
+
VCR.use_cassette('right_api_general') do
|
36
|
+
instances = @helper.get_instances
|
37
|
+
instances.should_not == nil
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
#
|
2
|
+
# Author: cary@rightscale.com
|
3
|
+
# Copyright 2014 RightScale, Inc.
|
4
|
+
#
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
# you may not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
# See the License for the specific language governing permissions and
|
15
|
+
# limitations under the License.
|
16
|
+
#
|
17
|
+
|
18
|
+
require 'right_api_helper'
|
19
|
+
|
20
|
+
describe RightApiHelper::DeploymentsCreator do
|
21
|
+
|
22
|
+
before(:all) do
|
23
|
+
@dc = RightApiHelper::DeploymentsCreator.new
|
24
|
+
end
|
25
|
+
|
26
|
+
@real_file = File.join(File.dirname(__FILE__),"..","data","deployments.json")
|
27
|
+
let (:bogus_file) { File.join(File.dirname(__FILE__),"..","data","iamnothere.json") }
|
28
|
+
|
29
|
+
it "exits with error if no argument is passed" do
|
30
|
+
argv = []
|
31
|
+
@dc.should_receive(:log_error)
|
32
|
+
lambda{ @dc.run(argv) }.should raise_error SystemExit
|
33
|
+
end
|
34
|
+
|
35
|
+
it "exits with error argument empty filename is passed" do
|
36
|
+
argv = [""]
|
37
|
+
@dc.should_receive(:log_error)
|
38
|
+
lambda{ @dc.run(argv) }.should raise_error SystemExit
|
39
|
+
end
|
40
|
+
|
41
|
+
it "exits with error invalid filename is passed" do
|
42
|
+
argv = [ File.join(File.dirname(__FILE__),"..","data","iamnothere.json") ]
|
43
|
+
@dc.should_receive(:log_error)
|
44
|
+
lambda{ @dc.run(argv) }.should raise_error SystemExit
|
45
|
+
end
|
46
|
+
|
47
|
+
it "reads a json file into memory" do
|
48
|
+
# grab test data
|
49
|
+
test_file = File.join(File.dirname(__FILE__),"..","data","deployments.json")
|
50
|
+
test_data = File.open(test_file, "r") {|f| f.read }
|
51
|
+
|
52
|
+
# Compare class json with test data
|
53
|
+
argv = [ File.join(File.dirname(__FILE__),"..","data","deployments.json") ]
|
54
|
+
@dc.run(argv)
|
55
|
+
|
56
|
+
@dc.instance_variable_get("@json").should == test_data
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
#
|
2
|
+
# Author: cary@rightscale.com
|
3
|
+
# Copyright 2014 RightScale, Inc.
|
4
|
+
#
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
# you may not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
# See the License for the specific language governing permissions and
|
15
|
+
# limitations under the License.
|
16
|
+
#
|
17
|
+
|
18
|
+
require 'spec_helper'
|
19
|
+
|
20
|
+
describe RightApiHelper::Session do
|
21
|
+
|
22
|
+
it "creates an client" do
|
23
|
+
VCR.use_cassette('right_api_session') do
|
24
|
+
apiStub = double("RightApi::Client", :api_url => "http://foo.com", :log => "")
|
25
|
+
RightApi::Client.should_receive(:new).and_return(apiStub)
|
26
|
+
session = RightApiHelper::Session.new
|
27
|
+
session.should_receive(:setup_client_logging)
|
28
|
+
session.logger(double("Logger"))
|
29
|
+
@client = session.create_client("someemail", "somepasswd", "someaccountid", "https://my.rightscale.com")
|
30
|
+
@client.should_not == nil
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
it "creates an client from file" do
|
35
|
+
VCR.use_cassette('right_api_session') do
|
36
|
+
apiStub = double("RightApi::Client", :api_url => "http://foo.com", :log => "")
|
37
|
+
RightApi::Client.should_receive(:new).and_return(apiStub)
|
38
|
+
session = RightApiHelper::Session.new
|
39
|
+
session.should_receive(:setup_client_logging)
|
40
|
+
session.logger(double("Logger"))
|
41
|
+
@client = session.create_client_from_file("~/.right_api_client/login.yml")
|
42
|
+
@client.should_not == nil
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|