deltacloud-core 0.4.1 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (166) hide show
  1. data/Rakefile +63 -7
  2. data/bin/deltacloudd +29 -17
  3. data/config.ru +5 -3
  4. data/config/drivers/ec2.yaml +9 -0
  5. data/config/drivers/google.yaml +3 -0
  6. data/config/drivers/openstack.yaml +3 -0
  7. data/deltacloud-core.gemspec +1 -1
  8. data/lib/cimi/dependencies.rb +62 -0
  9. data/lib/cimi/helpers/cimi_helper.rb +50 -0
  10. data/lib/cimi/model.rb +52 -0
  11. data/lib/cimi/model/action.rb +24 -0
  12. data/lib/cimi/model/base.rb +249 -0
  13. data/lib/cimi/model/cloud_entry_point.rb +48 -0
  14. data/lib/cimi/model/entity_metadata.rb +83 -0
  15. data/lib/cimi/model/entity_metadata_collection.rb +31 -0
  16. data/lib/cimi/model/errors.rb +40 -0
  17. data/lib/cimi/model/machine.rb +227 -0
  18. data/lib/cimi/model/machine_admin.rb +59 -0
  19. data/lib/cimi/model/machine_admin_collection.rb +34 -0
  20. data/lib/cimi/model/machine_collection.rb +34 -0
  21. data/lib/cimi/model/machine_configuration.rb +67 -0
  22. data/lib/cimi/model/machine_configuration_collection.rb +34 -0
  23. data/lib/cimi/model/machine_image.rb +46 -0
  24. data/lib/cimi/model/machine_image_collection.rb +34 -0
  25. data/lib/cimi/model/machine_template.rb +41 -0
  26. data/lib/cimi/model/machine_template_collection.rb +34 -0
  27. data/lib/cimi/model/network.rb +69 -0
  28. data/lib/cimi/model/network_collection.rb +34 -0
  29. data/lib/cimi/model/network_configuration.rb +50 -0
  30. data/lib/cimi/model/network_configuration_collection.rb +34 -0
  31. data/lib/cimi/model/network_template.rb +26 -0
  32. data/lib/cimi/model/schema.rb +277 -0
  33. data/lib/cimi/model/volume.rb +103 -0
  34. data/lib/cimi/model/volume_collection.rb +34 -0
  35. data/lib/cimi/model/volume_configuration.rb +60 -0
  36. data/lib/cimi/model/volume_configuration_collection.rb +34 -0
  37. data/lib/cimi/model/volume_image.rb +49 -0
  38. data/lib/cimi/model/volume_image_collection.rb +34 -0
  39. data/lib/cimi/model/volume_template.rb +23 -0
  40. data/lib/cimi/model/volume_template_collection.rb +34 -0
  41. data/lib/cimi/server.rb +575 -0
  42. data/lib/deltacloud/base_driver/base_driver.rb +11 -1
  43. data/lib/deltacloud/core_ext.rb +2 -0
  44. data/lib/deltacloud/core_ext/array.rb +25 -0
  45. data/lib/deltacloud/core_ext/hash.rb +7 -0
  46. data/lib/deltacloud/core_ext/proc.rb +31 -0
  47. data/lib/deltacloud/core_ext/string.rb +15 -0
  48. data/lib/deltacloud/drivers/condor/condor_driver.rb +2 -1
  49. data/lib/deltacloud/drivers/ec2/ec2_driver.rb +32 -10
  50. data/lib/deltacloud/drivers/eucalyptus/eucalyptus_driver.rb +1 -1
  51. data/lib/deltacloud/drivers/gogrid/gogrid_driver.rb +1 -1
  52. data/lib/deltacloud/drivers/google/google_driver.rb +233 -0
  53. data/lib/deltacloud/drivers/mock/data/instances/inst0.yml +7 -2
  54. data/lib/deltacloud/drivers/mock/data/instances/inst1.yml +7 -2
  55. data/lib/deltacloud/drivers/mock/data/instances/inst2.yml +7 -2
  56. data/lib/deltacloud/drivers/mock/mock_client.rb +17 -0
  57. data/lib/deltacloud/drivers/mock/mock_driver.rb +82 -8
  58. data/lib/deltacloud/drivers/opennebula/opennebula_driver.rb +1 -1
  59. data/lib/deltacloud/drivers/openstack/openstack_driver.rb +47 -0
  60. data/lib/deltacloud/drivers/rackspace/rackspace_driver.rb +8 -8
  61. data/lib/deltacloud/drivers/rhevm/rhevm_client.rb +122 -49
  62. data/lib/deltacloud/drivers/rhevm/rhevm_driver.rb +42 -22
  63. data/lib/deltacloud/drivers/rimuhosting/rimuhosting_driver.rb +1 -1
  64. data/lib/deltacloud/drivers/sbc/sbc_driver.rb +3 -2
  65. data/lib/deltacloud/drivers/terremark/terremark_driver.rb +2 -2
  66. data/lib/deltacloud/drivers/vsphere/vsphere_client.rb +25 -4
  67. data/lib/deltacloud/drivers/vsphere/vsphere_driver.rb +35 -12
  68. data/lib/deltacloud/hardware_profile.rb +34 -10
  69. data/lib/deltacloud/helpers/application_helper.rb +3 -28
  70. data/lib/deltacloud/helpers/blob_stream.rb +2 -1
  71. data/lib/deltacloud/models.rb +2 -0
  72. data/lib/deltacloud/models/bucket.rb +1 -1
  73. data/lib/deltacloud/models/image.rb +1 -1
  74. data/lib/deltacloud/models/instance.rb +2 -1
  75. data/lib/deltacloud/models/instance_address.rb +56 -0
  76. data/lib/deltacloud/models/provider.rb +27 -0
  77. data/{server.rb → lib/deltacloud/server.rb} +72 -14
  78. data/lib/deltacloud/validation.rb +31 -10
  79. data/lib/sinatra/rabbit.rb +34 -26
  80. data/lib/sinatra/rack_accept.rb +5 -5
  81. data/lib/sinatra/rack_matrix_params.rb +6 -2
  82. data/lib/sinatra/rack_syslog.rb +3 -3
  83. data/lib/sinatra/static_assets.rb +1 -1
  84. data/lib/sinatra/url_for.rb +1 -7
  85. data/public/images/bread-bg.png +0 -0
  86. data/public/images/logo-wide.png +0 -0
  87. data/public/images/topbar-bg.png +0 -0
  88. data/public/javascripts/application.js +5 -0
  89. data/public/javascripts/cmwgapp.js +249 -0
  90. data/public/javascripts/jquery-1.4.2.min.js +154 -0
  91. data/public/javascripts/jquery.mobile-1.0rc1.min.js +170 -0
  92. data/public/stylesheets/images/icons-18-black.png +0 -0
  93. data/public/stylesheets/images/icons-18-white.png +0 -0
  94. data/public/stylesheets/images/icons-36-black.png +0 -0
  95. data/public/stylesheets/images/icons-36-white.png +0 -0
  96. data/public/stylesheets/jquery.mobile-1.0rc1.min.css +12 -0
  97. data/public/stylesheets/new.css +4 -0
  98. data/support/fedora/deltacloud-core.init +20 -13
  99. data/tests/cimi/features/step_definitions/common_steps.rb +59 -0
  100. data/tests/cimi/features/step_definitions/machine_images_steps.rb +0 -0
  101. data/tests/cimi/features/step_definitions/machines_steps.rb +99 -0
  102. data/tests/cimi/features/step_definitions/volumes_steps.rb +115 -0
  103. data/tests/cimi/features/support/env.rb +53 -0
  104. data/tests/common.rb +89 -11
  105. data/tests/core_ext/string.rb +31 -0
  106. data/tests/drivers/google/api_test.rb +35 -0
  107. data/tests/drivers/google/buckets_test.rb +116 -0
  108. data/tests/drivers/google/setup.rb +38 -0
  109. data/tests/drivers/mock/instances_test.rb +20 -5
  110. data/tests/drivers/openstack/api_test.rb +41 -0
  111. data/tests/drivers/openstack/hardware_profiles_test.rb +53 -0
  112. data/tests/drivers/openstack/images_test.rb +40 -0
  113. data/tests/drivers/openstack/instances_test.rb +163 -0
  114. data/tests/drivers/openstack/realms_test.rb +36 -0
  115. data/tests/drivers/openstack/setup.rb +20 -0
  116. data/tests/drivers/rackspace/buckets_test.rb +145 -0
  117. data/tests/drivers/rackspace/setup.rb +3 -3
  118. data/tests/drivers/rhevm/api_test.rb +1 -1
  119. data/tests/drivers/rhevm/images_test.rb +2 -2
  120. data/tests/drivers/rhevm/instances_test.rb +10 -12
  121. data/tests/drivers/rhevm/realms_test.rb +4 -4
  122. data/tests/drivers/rhevm/setup.rb +3 -3
  123. data/tests/rabbit_test.rb +1 -1
  124. data/views/api/show.html.haml +13 -0
  125. data/views/cimi/cloudEntryPoint/index.html.haml +5 -0
  126. data/views/cimi/cloudEntryPoint/index.xml.haml +9 -0
  127. data/views/cimi/collection/index.html.haml +45 -0
  128. data/views/cimi/collection/response.xml.haml +3 -0
  129. data/views/cimi/error.html.haml +31 -0
  130. data/views/cimi/errors/400.html.haml +41 -0
  131. data/views/cimi/errors/400.xml.haml +3 -0
  132. data/views/cimi/errors/401.html.haml +41 -0
  133. data/views/cimi/errors/401.xml.haml +2 -0
  134. data/views/cimi/errors/403.html.haml +42 -0
  135. data/views/cimi/errors/403.xml.haml +2 -0
  136. data/views/cimi/errors/404.html.haml +29 -0
  137. data/views/cimi/errors/404.xml.haml +2 -0
  138. data/views/cimi/errors/405.html.haml +29 -0
  139. data/views/cimi/errors/405.xml.haml +5 -0
  140. data/views/cimi/errors/500.html.haml +43 -0
  141. data/views/cimi/errors/500.xml.haml +6 -0
  142. data/views/cimi/errors/502.html.haml +43 -0
  143. data/views/cimi/errors/502.xml.haml +7 -0
  144. data/views/cimi/errors/backend_capability_failure.html.haml +29 -0
  145. data/views/cimi/layout.html.haml +32 -0
  146. data/views/cimi/machine_configurations/show.html.haml +159 -0
  147. data/views/cimi/machine_configurations/show.xml.haml +27 -0
  148. data/views/cimi/machine_images/show.html.haml +79 -0
  149. data/views/cimi/machine_images/show.xml.haml +17 -0
  150. data/views/cimi/machines/show.html.haml +177 -0
  151. data/views/cimi/machines/show.xml.haml +28 -0
  152. data/views/cimi/volumes/show.html.haml +68 -0
  153. data/views/cimi/volumes/show.xml.haml +17 -0
  154. data/views/drivers/show.html.haml +10 -5
  155. data/views/drivers/show.xml.haml +9 -4
  156. data/views/error.html.haml +2 -2
  157. data/views/errors/500.xml.haml +7 -1
  158. data/views/instances/index.html.haml +1 -1
  159. data/views/instances/new.html.haml +19 -16
  160. data/views/instances/show.html.haml +7 -2
  161. data/views/instances/show.xml.haml +8 -7
  162. data/views/layout.html.haml +2 -2
  163. data/views/storage_volumes/show.html.haml +1 -1
  164. metadata +296 -204
  165. data/public/javascripts/jquery.mobile-1.0b1.min.js +0 -146
  166. data/public/stylesheets/jquery.mobile-1.0b1.min.css +0 -8
@@ -0,0 +1,53 @@
1
+ require 'rubygems'
2
+ require 'nokogiri'
3
+
4
+ ENV['API_DRIVER'] = 'mock'
5
+ ENV['API_FRONTEND'] = 'cimi'
6
+ ENV.delete('API_VERBOSE')
7
+
8
+ $top_srcdir = File.join(File.dirname(__FILE__), '..', '..', '..', '..')
9
+ $:.unshift File.join($top_srcdir, 'lib')
10
+
11
+ load File.join($top_srcdir, 'lib', 'cimi', 'server.rb')
12
+
13
+ require 'rack/test'
14
+
15
+ def last_xml_response
16
+ Nokogiri::XML(last_response.body)
17
+ end
18
+
19
+ def new_machine
20
+ @@new_machine
21
+ end
22
+
23
+ def set_new_machine(machine)
24
+ @@new_machine = machine
25
+ end
26
+
27
+ class String
28
+
29
+ def to_class_name
30
+ to_collection_name
31
+ end
32
+
33
+ def to_entity_name
34
+ to_collection_name.uncapitalize
35
+ end
36
+
37
+ def to_collection_name
38
+ self.tr(' ', '').singularize
39
+ end
40
+
41
+ def to_collection_uri
42
+ self.tr(' ', '_').downcase
43
+ end
44
+
45
+ def to_entity_uri
46
+ to_collection_uri.pluralize
47
+ end
48
+
49
+ end
50
+
51
+ def app
52
+ Sinatra::Application
53
+ end
@@ -13,19 +13,22 @@
13
13
  # License for the specific language governing permissions and limitations
14
14
  # under the License.
15
15
  #
16
+ ENV.delete 'API_VERBOSE'
16
17
 
17
- $:.unshift File.join(File.dirname(__FILE__), '..')
18
+ $:.unshift File.join(File.dirname(__FILE__), '..', 'lib')
19
+ $top_srcdir = File::dirname(File::dirname(__FILE__))
18
20
 
19
21
  require 'rubygems'
20
22
  require 'yaml'
23
+ require 'rspec/core'
24
+ require 'rspec/matchers'
21
25
  require 'test/unit'
22
- require 'spec'
23
26
  require 'nokogiri'
24
27
  require 'json'
25
28
  require 'digest/sha1'
26
29
  require 'base64'
27
30
  require 'rack/test'
28
- require 'server'
31
+ require "%s/server" % (ENV['API_FRONTEND'] == 'cimi' ? 'cimi' : 'deltacloud')
29
32
 
30
33
  driver
31
34
 
@@ -41,8 +44,9 @@ configure :test do
41
44
  set :show_exceptions, false
42
45
  end
43
46
 
44
- Spec::Runner.configure do |conf|
47
+ RSpec.configure do |conf|
45
48
  conf.include Rack::Test::Methods
49
+ conf.expect_with :rspec
46
50
  end
47
51
 
48
52
  module DeltacloudTestCommon
@@ -100,7 +104,9 @@ module DeltacloudTestCommon
100
104
  get(uri, params || {}, opts[:auth] ? authenticate(opts) : {})
101
105
  if last_response.status.to_s =~ /5(\d{2})/
102
106
  puts "============= [ ERROR ] ================"
103
- puts last_response.inspect
107
+ puts last_response.body
108
+ puts "============= [ RESPONSE ] ================"
109
+ puts last_response.errors
104
110
  puts "========================================"
105
111
  end
106
112
  end
@@ -112,7 +118,9 @@ module DeltacloudTestCommon
112
118
  get_url(uri, params, opts)
113
119
  if last_response.status.to_s =~ /5(\d{2})/
114
120
  puts "============= [ ERROR ] ================"
115
- puts last_response.inspect
121
+ puts last_response.body
122
+ puts "============= [ RESPONSE ] ================"
123
+ puts last_response.errors
116
124
  puts "========================================"
117
125
  end
118
126
  end
@@ -120,14 +128,22 @@ module DeltacloudTestCommon
120
128
  def post_url(uri, params={}, opts={})
121
129
  header 'Accept', accept(opts[:format] || :xml)
122
130
  if DeltacloudTestCommon::recording?
123
- VCR.use_cassette("post-" + Digest::SHA1.hexdigest("#{uri}-#{params}")) do
124
- post(uri, params || {}, authenticate(opts))
131
+ if opts['vcr_cassette']
132
+ VCR.use_cassette(opts['vcr_cassette']) do
133
+ post(uri, params || {}, authenticate(opts))
134
+ end
135
+ else
136
+ VCR.use_cassette("post-" + Digest::SHA1.hexdigest("#{uri}-#{params}")) do
137
+ post(uri, params || {}, authenticate(opts))
138
+ end
125
139
  end
126
140
  else
127
141
  post(uri, params || {}, authenticate(opts))
128
142
  if last_response.status.to_s =~ /5(\d{2})/
129
143
  puts "============= [ ERROR ] ================"
130
- puts last_response.inspect
144
+ puts last_response.body
145
+ puts "============= [ RESPONSE ] ================"
146
+ puts last_response.errors
131
147
  puts "========================================"
132
148
  end
133
149
  end
@@ -141,6 +157,23 @@ module DeltacloudTestCommon
141
157
  end
142
158
  else
143
159
  delete(uri, params || {}, authenticate(opts))
160
+ if last_response.status.to_s =~ /5(\d{2})/
161
+ puts "============= [ ERROR ] ================"
162
+ puts last_response.body
163
+ puts "============= [ RESPONSE ] ================"
164
+ puts last_response.errors
165
+ end
166
+ end
167
+ end
168
+
169
+ def head_url(uri, params={}, opts={})
170
+ header 'Accept', accept(opts[:format] || :xml)
171
+ if DeltacloudTestCommon::recording?
172
+ VCR.use_cassette("head-"+Digest::SHA1.hexdigest("#{uri}-#{params}")) do
173
+ head(uri, params || {}, authenticate(opts))
174
+ end
175
+ else
176
+ head(uri, params || {}, authenticate(opts))
144
177
  if last_response.status.to_s =~ /5(\d{2})/
145
178
  puts "============= [ ERROR ] ================"
146
179
  puts last_response.inspect
@@ -159,8 +192,9 @@ module DeltacloudTestCommon
159
192
  put(uri, params || {}, authenticate(opts))
160
193
  if last_response.status.to_s =~ /5(\d{2})/
161
194
  puts "============= [ ERROR ] ================"
162
- puts last_response.inspect
163
- puts "========================================"
195
+ puts last_response.body
196
+ puts "============= [ RESPONSE ] ================"
197
+ puts last_response.errors
164
198
  end
165
199
  end
166
200
  end
@@ -197,6 +231,50 @@ module DeltacloudTestCommon
197
231
  $created_instances << id
198
232
  end
199
233
 
234
+ #common variables used by the bucket/blob unit tests across clouds
235
+ @@created_bucket_name="testbucki2rpux3wdelme"
236
+ @@created_blob_name="testblobk1ds91kVdelme"
237
+ @@created_blob_local_file="#{File.dirname(__FILE__)}/drivers/common_fixtures/deltacloud_blob_test.png"
238
+
239
+ def check_bucket_basics(bucket, cloud)
240
+ (bucket/'bucket/name').first.text.should == "#{@@created_bucket_name}#{cloud}"
241
+ (bucket/'bucket').attribute("id").text.should == "#{@@created_bucket_name}#{cloud}"
242
+ (bucket/'bucket').length.should > 0
243
+ (bucket/'bucket/name').first.text.should_not == nil
244
+ (bucket/'bucket').attribute("href").text.should_not == nil
245
+ end
246
+
247
+ def check_blob_basics(blob, cloud)
248
+ (blob/'blob').length.should == 1
249
+ (blob/'blob').attribute("id").text.should_not == nil
250
+ (blob/'blob').attribute("href").text.should_not==nil
251
+ (blob/'blob/bucket').text.should_not == nil
252
+ (blob/'blob/content_length').text.should_not == nil
253
+ (blob/'blob/content_type').text.should_not == nil
254
+ (blob/'blob').attribute("id").text.should == "#{@@created_blob_name}#{cloud}"
255
+ (blob/'blob/bucket').text.should == "#{@@created_bucket_name}#{cloud}"
256
+ (blob/'blob/content_length').text.to_i.should == File.size(@@created_blob_local_file)
257
+ end
258
+
259
+ def check_blob_metadata(blob, metadata_hash)
260
+ meta_from_blob = {}
261
+ #extract metadata from nokogiri blob xml
262
+ (0.. (((blob/'blob/user_metadata').first).elements.size - 1) ).each do |i|
263
+ meta_from_blob[(((blob/'blob/user_metadata').first).elements[i].attribute("key").value)] =
264
+ (((blob/'blob/user_metadata').first).elements[i].children[1].text)
265
+ end
266
+ #remove any 'x-goog-meta-' prefixes (problem for google blobs and vcr...)
267
+ meta_from_blob.gsub_keys(/x-.*-meta-/i, "")
268
+ meta_from_blob.eql?(metadata_hash).should == true
269
+ end
270
+
271
+ #hash ordering is unpredictable - sort the params hash
272
+ #so we get same vcr cassette name each time
273
+ def stable_vcr_cassette_name(method, uri, params)
274
+ digest = Digest::SHA1.hexdigest("#{uri}-#{params.sort_by {|k,v| k.to_s}}")
275
+ return "#{method}-#{digest}"
276
+ end
277
+
200
278
  end
201
279
 
202
280
  include DeltacloudTestCommon
@@ -0,0 +1,31 @@
1
+ # Licensed to the Apache Software Foundation (ASF) under one or more
2
+ # contributor license agreements. See the NOTICE file distributed with
3
+ # this work for additional information regarding copyright ownership. The
4
+ # ASF licenses this file to you under the Apache License, Version 2.0 (the
5
+ # "License"); you may not use this file except in compliance with the
6
+ # License. You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12
+ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13
+ # License for the specific language governing permissions and limitations
14
+ # under the License.
15
+ #
16
+
17
+ $:.unshift File.join(File.dirname(__FILE__), '..', '..', '..', '..')
18
+ require 'tests/common'
19
+
20
+ require 'deltacloud/drivers'
21
+ require 'deltacloud/drivers/mock/mock_driver'
22
+
23
+ module DeltacloudUnitTest
24
+
25
+ class StringTest < Test::Unit::TestCase
26
+ def test_camelize
27
+ "hello_camel".camelize.should == "helloCamel"
28
+ "hello_camel_lots_of_humps".camelize.should == "helloCamelLotsOfHumps"
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,35 @@
1
+ $:.unshift File.join(File.dirname(__FILE__), '..', '..', '..')
2
+ require 'tests/common'
3
+
4
+ module GoogleTest
5
+
6
+ class ApiTest < Test::Unit::TestCase
7
+ include Rack::Test::Methods
8
+
9
+ def app
10
+ Sinatra::Application
11
+ end
12
+
13
+ def test_01_it_returns_entry_points
14
+ get_auth_url '/api;driver=google/?force_auth=1'
15
+ (last_xml_response/'/api').first[:driver].should == 'google'
16
+ (last_xml_response/'/api/link').length.should > 0
17
+ end
18
+
19
+ def test_02_it_has_google_features
20
+ get_url '/api;driver=google'
21
+ features = (last_xml_response/'/api/link[@rel="buckets"]/feature').collect { |f| f[:name] }
22
+ features.include?('bucket_location').should == true
23
+ features.length.should == 1
24
+ end
25
+
26
+ def test_03_it_has_google_collections
27
+ get_url '/api;driver=google'
28
+ collections = (last_xml_response/'/api/link').collect { |f| f[:rel] }
29
+ collections.include?('buckets').should == true
30
+ collections.include?('drivers').should == true
31
+ collections.length.should == 2
32
+ end
33
+
34
+ end
35
+ end
@@ -0,0 +1,116 @@
1
+ $:.unshift File.join(File.dirname(__FILE__), '..', '..', '..')
2
+ require 'tests/common'
3
+ #require 'webmock/test_unit'
4
+ module GoogleTest
5
+
6
+ class BucketsTest < Test::Unit::TestCase
7
+ include Rack::Test::Methods
8
+
9
+ def app
10
+ Sinatra::Application
11
+ end
12
+
13
+ @@bucket_name_google="#{@@created_bucket_name}googel"
14
+ @@blob_name_google="#{@@created_blob_name}googel"
15
+ #intentional typos here - bucket names cannot contain 'google'
16
+ #see http://code.google.com/apis/storage/docs/reference/v1/developer-guidev1.html
17
+
18
+ def test_01_it_can_create_new_bucket
19
+ params = {
20
+ :name => @@bucket_name_google,
21
+ :'api[driver]' => 'google'
22
+ }
23
+ vcr_cassette = stable_vcr_cassette_name('post', '/api/buckets', params)
24
+ post_url '/api/buckets', params, {'vcr_cassette'=>vcr_cassette}
25
+ last_response.status.should == 201 # Created
26
+ bucket = last_xml_response
27
+ check_bucket_basics(bucket, "googel")
28
+ (bucket/'bucket/size').first.text.should == "0"
29
+ end
30
+
31
+ def test_02_it_can_post_new_blob
32
+ temp_file=File.open(@@created_blob_local_file)
33
+ params = {
34
+ 'blob_id' => @@blob_name_google,
35
+ :meta_params=>"2",
36
+ :meta_name1=>"Author",
37
+ :meta_value1=>"deltacloud",
38
+ :meta_name2=>"foo",
39
+ :meta_value2=>"bar",
40
+ :'api[driver]' => 'google'
41
+ }
42
+ uri="/api/buckets/#{@@bucket_name_google}"
43
+ vcr_cassette = stable_vcr_cassette_name('post', uri, params)
44
+ params.merge!({'blob_data' => Rack::Test::UploadedFile.new(temp_file.path, "text/html")})
45
+ post_url uri, params, {'vcr_cassette'=>vcr_cassette}
46
+ last_response.status.should == 200
47
+ blob= last_xml_response
48
+ check_blob_basics(blob, "googel")
49
+ end
50
+
51
+ def test_03_it_can_retrieve_named_bucket_details
52
+ params = {
53
+ :'api[driver]' => 'google'
54
+ }
55
+ get_url "/api/buckets/#{@@bucket_name_google}", params
56
+ last_response.status.should == 200
57
+ bucket = last_xml_response
58
+ check_bucket_basics(bucket, "googel")
59
+ (bucket/'bucket/size').first.text.should == "1" #assuming blob created succesfully right?
60
+ end
61
+
62
+ def test_04_it_can_retrieve_named_blob_details
63
+ params = {
64
+ :'api[driver]' => 'google'
65
+ }
66
+ get_url "/api/buckets/#{@@bucket_name_google}/#{@@blob_name_google}", params
67
+ last_response.status.should == 200
68
+ blob = last_xml_response
69
+ check_blob_basics(blob, "googel")
70
+ check_blob_metadata(blob, {"author"=>"deltacloud", "foo"=>"bar"})
71
+ end
72
+
73
+ def test_05_it_can_retrieve_blob_metadata
74
+ params = {
75
+ :'api[driver]' => 'google'
76
+ }
77
+ head_url "/api/buckets/#{@@bucket_name_google}/#{@@blob_name_google}", params
78
+ last_response.status.should == 204
79
+ blob_meta_hash = last_response.headers.inject({}){|result, (k,v)| result[k]=v if k=~/^X-Deltacloud-Blobmeta-/i ; result}
80
+ blob_meta_hash.gsub_keys(/x-.*meta-/i, "")
81
+ ({"author"=>"deltacloud", "foo"=>"bar"}.eql?(blob_meta_hash)).should == true
82
+ end
83
+
84
+ def test_06_it_can_update_blob_metadata
85
+ params = {
86
+ :'api[driver]' => 'google'
87
+ }
88
+ new_meta = {"X-Deltacloud-Blobmeta-author" => "ApacheDeltacloud", "X-Deltacloud-Blobmeta-oof" => "rab"}
89
+ new_meta.each_pair do |k,v|
90
+ header k, v
91
+ end
92
+ post_url "/api/buckets/#{@@bucket_name_google}/#{@@blob_name_google}", params
93
+ last_response.status.should == 204
94
+ new_meta.each_pair do |k,v|
95
+ (last_response.headers[k]==v).should == true
96
+ end
97
+ end
98
+
99
+ def test_07_it_can_delete_blob
100
+ params = {
101
+ :'api[driver]' => 'google'
102
+ }
103
+ delete_url "/api/buckets/#{@@bucket_name_google}/#{@@blob_name_google}", params
104
+ last_response.status.should == 204
105
+ end
106
+
107
+ def test_08_it_can_delete_bucket
108
+ params = {
109
+ :'api[driver]' => 'google'
110
+ }
111
+ delete_url "/api/buckets/#{@@bucket_name_google}", params
112
+ last_response.status.should == 204
113
+ end
114
+
115
+ end
116
+ end
@@ -0,0 +1,38 @@
1
+ ENV['API_DRIVER'] = "google"
2
+ ENV['API_USER'] = 'GOOGK7JXLS6UEYS6AYVO'
3
+ ENV['API_PASSWORD'] = 'QjxUunLgszKhBGn/LISQajGR82CfwvraxA9lqnkg'
4
+
5
+ require 'vcr'
6
+
7
+ DeltacloudTestCommon::record!
8
+
9
+ VCR.config do |c|
10
+ c.cassette_library_dir = "#{File.dirname(__FILE__)}/fixtures/"
11
+ c.stub_with :excon
12
+ c.default_cassette_options = { :record => :new_episodes}
13
+ end
14
+
15
+ #monkey patch fix for VCR normalisation code:
16
+ #see https://github.com/myronmarston/vcr/issues/4
17
+ #when body is a tempfile, like when creating new blob
18
+ #this method of normalisation fails and excon throws errors
19
+ #(Excon::Errors::SocketError:can't convert Tempfile into String)
20
+ #
21
+ #RELEVANT: https://github.com/myronmarston/vcr/issues/101
22
+ #(will need revisiting when vcr 2 comes along)
23
+
24
+ module VCR
25
+ module Normalizers
26
+ module Body
27
+
28
+ private
29
+ def normalize_body
30
+ self.body = case body
31
+ when nil, ''; nil
32
+ else
33
+ String.new(body) unless body.is_a?(Tempfile)
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
@@ -109,18 +109,33 @@ module DeltacloudUnitTest
109
109
  test_instance_attributes(last_xml_response/'instance')
110
110
  end
111
111
 
112
- def test_it_create_a_new_instance_using_image_id_and_name_and_hwp
112
+ def test_it_create_a_new_instance_using_image_id_and_name_and_hwp_storage_and_hwp_cpu
113
113
  params = {
114
114
  :image_id => 'img1',
115
- :name => "unit_test_instance1",
116
- :hwp_id => "m1-xlarge"
115
+ :realm_id => '',
116
+ :name => "unit_test_instance3",
117
+ :hwp_id => "m1-large",
118
+ :hwp_storage => '850',
119
+ :hwp_memory => '7680.0',
120
+ :hwp_cpu => "1.0",
121
+ }
122
+ post_url '/api/instances', params
123
+ last_response.status.should == 400
124
+ end
125
+
126
+ def test_it_create_a_new_instance_using_image_id_and_name_and_hwp_storage
127
+ params = {
128
+ :image_id => 'img1',
129
+ :name => "unit_test_instance2",
130
+ :hwp_id => "m1-small",
131
+ :hwp_storage => "160"
117
132
  }
118
133
  post_url '/api/instances', params
119
134
  last_response.status.should == 201
120
135
  last_response.headers['Location'].should_not == nil
121
136
  get_auth_url last_response.headers['Location'], {}
122
- (last_xml_response/'instance/name').text.should == 'unit_test_instance1'
123
- (last_xml_response/'instance/hardware_profile').first['id'].should == 'm1-xlarge'
137
+ (last_xml_response/'instance/name').text.should == 'unit_test_instance2'
138
+ (last_xml_response/'instance/hardware_profile').first['id'].should == 'm1-small'
124
139
  add_created_instance (last_xml_response/'instance').first['id']
125
140
  test_instance_attributes(last_xml_response/'instance')
126
141
  end