deltacloud-core 1.0.2 → 1.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (187) hide show
  1. data/Rakefile +2 -1
  2. data/bin/deltacloudd +11 -5
  3. data/config.ru +3 -3
  4. data/deltacloud-core.gemspec +24 -18
  5. data/lib/cimi/collections/address_templates.rb +3 -3
  6. data/lib/cimi/collections/addresses.rb +6 -5
  7. data/lib/cimi/collections/entity_metadata.rb +0 -2
  8. data/lib/cimi/collections/machine_admins.rb +5 -5
  9. data/lib/cimi/collections/machine_configurations.rb +2 -2
  10. data/lib/cimi/collections/machine_images.rb +3 -3
  11. data/lib/cimi/collections/machines.rb +32 -10
  12. data/lib/cimi/collections/network_configurations.rb +4 -3
  13. data/lib/cimi/collections/network_templates.rb +4 -3
  14. data/lib/cimi/collections/networks.rb +8 -8
  15. data/lib/cimi/collections/routing_group_templates.rb +4 -3
  16. data/lib/cimi/collections/routing_groups.rb +4 -3
  17. data/lib/cimi/collections/volume_configurations.rb +3 -3
  18. data/lib/cimi/collections/volume_images.rb +3 -3
  19. data/lib/cimi/collections/volumes.rb +4 -3
  20. data/lib/cimi/collections/vsp_configurations.rb +4 -3
  21. data/lib/cimi/collections/vsp_templates.rb +4 -3
  22. data/lib/cimi/collections/vsps.rb +8 -7
  23. data/lib/cimi/helpers.rb +1 -1
  24. data/lib/cimi/helpers/cimi_helper.rb +11 -1
  25. data/lib/cimi/models.rb +4 -0
  26. data/lib/cimi/models/base.rb +11 -1
  27. data/lib/cimi/models/cloud_entry_point.rb +7 -14
  28. data/lib/cimi/models/disk.rb +40 -0
  29. data/lib/cimi/models/disk_collection.rb +38 -0
  30. data/lib/cimi/models/machine.rb +9 -43
  31. data/lib/cimi/models/machine_collection.rb +7 -4
  32. data/lib/cimi/models/machine_configuration.rb +8 -15
  33. data/lib/cimi/models/machine_configuration_collection.rb +6 -4
  34. data/lib/cimi/models/machine_image_collection.rb +6 -4
  35. data/lib/cimi/models/machine_template_collection.rb +6 -4
  36. data/lib/cimi/models/machine_volume.rb +42 -0
  37. data/lib/cimi/models/machine_volume_collection.rb +34 -0
  38. data/lib/cimi/models/network.rb +5 -9
  39. data/lib/cimi/models/network_collection.rb +6 -5
  40. data/lib/cimi/models/schema.rb +20 -0
  41. data/lib/cimi/models/volume_collection.rb +6 -4
  42. data/lib/cimi/models/volume_configuration_collection.rb +6 -4
  43. data/lib/cimi/models/volume_image_collection.rb +6 -4
  44. data/lib/cimi/models/volume_template_collection.rb +6 -4
  45. data/lib/deltacloud/api.rb +3 -3
  46. data/lib/deltacloud/collections/addresses.rb +1 -1
  47. data/lib/deltacloud/collections/firewalls.rb +4 -2
  48. data/lib/deltacloud/collections/keys.rb +1 -1
  49. data/lib/deltacloud/collections/load_balancers.rb +1 -1
  50. data/lib/deltacloud/collections/storage_volumes.rb +4 -4
  51. data/lib/deltacloud/drivers/base_driver.rb +12 -20
  52. data/lib/deltacloud/drivers/ec2/aws_vpc_monkey_patch.rb +294 -0
  53. data/lib/deltacloud/drivers/ec2/ec2_driver.rb +38 -6
  54. data/lib/deltacloud/drivers/fgcp/fgcp_client.rb +4 -0
  55. data/lib/deltacloud/drivers/fgcp/fgcp_driver.rb +40 -4
  56. data/lib/deltacloud/drivers/gogrid/gogrid_client.rb +8 -7
  57. data/lib/deltacloud/drivers/gogrid/gogrid_driver.rb +422 -416
  58. data/lib/deltacloud/drivers/google/google_driver.rb +2 -1
  59. data/lib/deltacloud/drivers/openstack/openstack_driver.rb +30 -16
  60. data/lib/deltacloud/drivers/rhevm/rhevm_driver.rb +1 -0
  61. data/lib/deltacloud/drivers/vsphere/vsphere_driver.rb +3 -9
  62. data/lib/deltacloud/helpers/deltacloud_helper.rb +0 -2
  63. data/lib/deltacloud/models/firewall_rule.rb +2 -0
  64. data/lib/deltacloud/models/hardware_profile.rb +61 -59
  65. data/{tests/deprecated/core_ext/string.rb → lib/deltacloud/version.rb} +3 -15
  66. data/lib/deltacloud_rack.rb +1 -0
  67. data/lib/ec2/server.rb +5 -3
  68. data/lib/sinatra/rack_accept.rb +53 -53
  69. data/lib/sinatra/rack_etag.rb +1 -1
  70. data/tests/cimi/collections/cloud_entry_point_test.rb +11 -2
  71. data/tests/deltacloud/common.rb +1 -1
  72. data/tests/deltacloud/rack_test.rb +3 -3
  73. data/tests/drivers/base/base_driver_test.rb +6 -2
  74. data/tests/drivers/base/common.rb +1 -0
  75. data/tests/drivers/base/library_test.rb +6 -2
  76. data/tests/drivers/ec2/common.rb +34 -15
  77. data/tests/drivers/ec2/images_test.rb +2 -3
  78. data/tests/drivers/ec2/instance_test.rb +12 -2
  79. data/tests/drivers/ec2/keys_test.rb +2 -2
  80. data/tests/drivers/ec2/realms_test.rb +7 -3
  81. data/tests/drivers/ec2/storage_snapshots_test.rb +2 -3
  82. data/tests/drivers/gogrid/common.rb +24 -0
  83. data/tests/drivers/gogrid/hardware_profiles_test.rb +51 -0
  84. data/tests/drivers/gogrid/images_test.rb +57 -0
  85. data/tests/drivers/gogrid/instances_test.rb +92 -0
  86. data/tests/drivers/gogrid/realms_test.rb +45 -0
  87. data/tests/drivers/google/buckets_test.rb +105 -0
  88. data/tests/drivers/google/common.rb +20 -0
  89. data/tests/drivers/mock/common.rb +1 -0
  90. data/tests/drivers/mock/images_test.rb +3 -2
  91. data/tests/drivers/mock/instances_test.rb +3 -2
  92. data/tests/drivers/mock/keys_test.rb +3 -2
  93. data/tests/drivers/mock/realms_test.rb +3 -2
  94. data/tests/drivers/mock/storage_snapshots_test.rb +3 -2
  95. data/tests/drivers/mock/storage_volumes_test.rb +3 -2
  96. data/tests/drivers/models/address_test.rb +3 -3
  97. data/tests/drivers/models/base_test.rb +4 -2
  98. data/tests/drivers/models/blob_test.rb +3 -3
  99. data/tests/drivers/models/common.rb +3 -0
  100. data/tests/drivers/models/hardware_profile_test.rb +5 -4
  101. data/tests/drivers/models/instance_address_test.rb +3 -3
  102. data/tests/drivers/models/instance_profile_test.rb +3 -3
  103. data/tests/drivers/models/instance_test.rb +3 -3
  104. data/tests/drivers/models/keys_test.rb +3 -3
  105. data/tests/drivers/models/metrics_test.rb +3 -3
  106. data/tests/drivers/openstack/common.rb +26 -0
  107. data/tests/drivers/openstack/hardware_profiles_test.rb +46 -0
  108. data/tests/drivers/openstack/images_test.rb +50 -0
  109. data/tests/drivers/openstack/instances_test.rb +66 -0
  110. data/tests/drivers/openstack/keys_test.rb +61 -0
  111. data/tests/drivers/openstack/realms_test.rb +46 -0
  112. data/tests/drivers/rhevm/common.rb +2 -0
  113. data/tests/drivers/rhevm/images_test.rb +3 -4
  114. data/tests/drivers/rhevm/instance_test.rb +2 -2
  115. data/tests/drivers/rhevm/provider_test.rb +2 -2
  116. data/tests/drivers/rhevm/realms_test.rb +2 -3
  117. data/tests/ec2/common.rb +5 -4
  118. data/tests/ec2/server_test.rb +3 -2
  119. data/tests/helpers/rack/common.rb +3 -0
  120. data/tests/helpers/rack/rack_accept_test.rb +65 -0
  121. data/tests/helpers/rack/rack_date_test.rb +27 -0
  122. data/tests/helpers/rack/rack_driver_select_test.rb +53 -0
  123. data/tests/helpers/rack/rack_etag_test.rb +29 -0
  124. data/tests/helpers/rack/rack_matrix_params_test.rb +72 -0
  125. data/tests/test_helper.rb +44 -36
  126. data/views/hardware_profiles/index.html.haml +1 -1
  127. data/views/hardware_profiles/show.html.haml +2 -2
  128. data/views/hardware_profiles/show.xml.haml +2 -1
  129. data/views/images/show.html.haml +6 -5
  130. metadata +74 -117
  131. data/tests/deprecated/api/common.rb +0 -1
  132. data/tests/deprecated/api/driver_test.rb +0 -79
  133. data/tests/deprecated/api/library_test.rb +0 -6
  134. data/tests/deprecated/cimi/features/step_definitions/common_steps.rb +0 -59
  135. data/tests/deprecated/cimi/features/step_definitions/machine_images_steps.rb +0 -0
  136. data/tests/deprecated/cimi/features/step_definitions/machines_steps.rb +0 -100
  137. data/tests/deprecated/cimi/features/step_definitions/volumes_steps.rb +0 -115
  138. data/tests/deprecated/cimi/features/support/env.rb +0 -75
  139. data/tests/deprecated/common.rb +0 -279
  140. data/tests/deprecated/drivers/ec2/api_test.rb +0 -19
  141. data/tests/deprecated/drivers/ec2/common.rb +0 -23
  142. data/tests/deprecated/drivers/ec2/drivers_test.rb +0 -120
  143. data/tests/deprecated/drivers/ec2/hardware_profiles_test.rb +0 -224
  144. data/tests/deprecated/drivers/ec2/images_test.rb +0 -230
  145. data/tests/deprecated/drivers/ec2/instances_test.rb +0 -356
  146. data/tests/deprecated/drivers/ec2/keys_test.rb +0 -181
  147. data/tests/deprecated/drivers/ec2/realms_test.rb +0 -146
  148. data/tests/deprecated/drivers/fgcp/api_test.rb +0 -47
  149. data/tests/deprecated/drivers/fgcp/hardware_profiles_test.rb +0 -54
  150. data/tests/deprecated/drivers/fgcp/realms_test.rb +0 -42
  151. data/tests/deprecated/drivers/fgcp/setup.rb +0 -13
  152. data/tests/deprecated/drivers/google/api_test.rb +0 -19
  153. data/tests/deprecated/drivers/google/buckets_test.rb +0 -100
  154. data/tests/deprecated/drivers/google/common.rb +0 -54
  155. data/tests/deprecated/drivers/mock/api_test.rb +0 -10
  156. data/tests/deprecated/drivers/mock/buckets_test.rb +0 -195
  157. data/tests/deprecated/drivers/mock/common.rb +0 -7
  158. data/tests/deprecated/drivers/mock/drivers_test.rb +0 -123
  159. data/tests/deprecated/drivers/mock/hardware_profiles_test.rb +0 -224
  160. data/tests/deprecated/drivers/mock/images_test.rb +0 -197
  161. data/tests/deprecated/drivers/mock/instances_test.rb +0 -343
  162. data/tests/deprecated/drivers/mock/keys_test.rb +0 -161
  163. data/tests/deprecated/drivers/mock/realms_test.rb +0 -132
  164. data/tests/deprecated/drivers/mock/storage_snapshots_test.rb +0 -114
  165. data/tests/deprecated/drivers/mock/storage_volumes_test.rb +0 -122
  166. data/tests/deprecated/drivers/openstack/api_test.rb +0 -46
  167. data/tests/deprecated/drivers/openstack/common.rb +0 -21
  168. data/tests/deprecated/drivers/openstack/hardware_profiles_test.rb +0 -64
  169. data/tests/deprecated/drivers/openstack/images_test.rb +0 -46
  170. data/tests/deprecated/drivers/openstack/instances_test.rb +0 -208
  171. data/tests/deprecated/drivers/openstack/realms_test.rb +0 -40
  172. data/tests/deprecated/drivers/rackspace/api_test.rb +0 -46
  173. data/tests/deprecated/drivers/rackspace/buckets_test.rb +0 -150
  174. data/tests/deprecated/drivers/rackspace/common.rb +0 -16
  175. data/tests/deprecated/drivers/rackspace/hardware_profiles_test.rb +0 -58
  176. data/tests/deprecated/drivers/rackspace/images_test.rb +0 -45
  177. data/tests/deprecated/drivers/rackspace/instances_test.rb +0 -166
  178. data/tests/deprecated/drivers/rackspace/realms_test.rb +0 -41
  179. data/tests/deprecated/drivers/rhevm/api_test.rb +0 -45
  180. data/tests/deprecated/drivers/rhevm/common.rb +0 -21
  181. data/tests/deprecated/drivers/rhevm/hardware_profiles_test.rb +0 -58
  182. data/tests/deprecated/drivers/rhevm/images_test.rb +0 -48
  183. data/tests/deprecated/drivers/rhevm/instances_test.rb +0 -182
  184. data/tests/deprecated/drivers/rhevm/realms_test.rb +0 -40
  185. data/tests/deprecated/minitest_common.rb +0 -58
  186. data/tests/deprecated/minitest_common_api_test.rb +0 -115
  187. data/tests/deprecated/rabbit_test.rb +0 -52
@@ -42,7 +42,7 @@ module Rack
42
42
 
43
43
  if etag_status?(status) && etag_body?(body) && !http_caching?(headers)
44
44
  digest, body = digest_body(body)
45
- headers['ETag'] = %("#{digest}") if digest
45
+ headers['ETag'] = digest.to_s if digest
46
46
  end
47
47
 
48
48
  if not headers['Cache-Control'] and digest
@@ -17,8 +17,8 @@ describe CIMI::Collections::CloudEntryPoint do
17
17
 
18
18
  it 'set the CIMI-Version header' do
19
19
  get root_url
20
- headers['X-CIMI-Specification-Version'].wont_be_nil
21
- headers['X-CIMI-Specification-Version'].must_equal '1.0.0'
20
+ headers['CIMI-Specification-Version'].wont_be_nil
21
+ headers['CIMI-Specification-Version'].must_equal '1.0.0'
22
22
  end
23
23
 
24
24
  it 'advertise CIMI collections in XML format' do
@@ -43,4 +43,13 @@ describe CIMI::Collections::CloudEntryPoint do
43
43
  status.must_equal 200
44
44
  end
45
45
 
46
+ it 'advertise only supported CIMI collections by driver' do
47
+ header 'X-Deltacloud-Driver', 'ec2'
48
+ get root_url + '/cloudEntryPoint'
49
+ (xml/'CloudEntryPoint/routingGroups').must_be_empty
50
+ header 'X-Deltacloud-Driver', 'mock'
51
+ get root_url + '/cloudEntryPoint'
52
+ (xml/'CloudEntryPoint/routingGroups').wont_be_empty
53
+ end
54
+
46
55
  end
@@ -5,7 +5,7 @@ require_relative File.join('..', '..', 'lib', 'deltacloud_rack.rb')
5
5
 
6
6
  Deltacloud::configure do |server|
7
7
  server.root_url '/api'
8
- server.version '1.0.2'
8
+ server.version Deltacloud::API_VERSION
9
9
  server.klass 'Deltacloud::API'
10
10
  server.logger Rack::DeltacloudLogger.setup(ENV['API_LOG'], ENV['API_VERBOSE'])
11
11
  server.default_driver :mock
@@ -8,7 +8,7 @@ describe Deltacloud do
8
8
  before do
9
9
  Deltacloud::configure :cimi do |server|
10
10
  server.root_url '/cimi'
11
- server.version '1.0.2'
11
+ server.version Deltacloud::API_VERSION
12
12
  server.klass 'CIMI'
13
13
  server.logger Logger
14
14
  end
@@ -37,8 +37,8 @@ describe Deltacloud do
37
37
  end
38
38
 
39
39
  it 'should provide the correct version' do
40
- Deltacloud.config[:deltacloud].version.must_equal '1.0.2'
41
- Deltacloud.config[:cimi].version.must_equal '1.0.2'
40
+ Deltacloud.config[:deltacloud].version.must_equal Deltacloud::API_VERSION
41
+ Deltacloud.config[:cimi].version.must_equal Deltacloud::API_VERSION
42
42
  end
43
43
 
44
44
  it 'should provide the logger facility' do
@@ -1,5 +1,9 @@
1
- require 'minitest/autorun'
2
- require_relative File.join('..', '..', '..', 'lib', 'deltacloud', 'drivers', 'base_driver.rb')
1
+ require 'rubygems'
2
+ require 'require_relative' if RUBY_VERSION < '1.9'
3
+
4
+ require_relative 'common'
5
+
6
+ require_relative '../../../lib/deltacloud/drivers/base_driver'
3
7
 
4
8
  describe Deltacloud::BaseDriver do
5
9
 
@@ -0,0 +1 @@
1
+ require_relative '../../test_helper'
@@ -1,5 +1,9 @@
1
- require 'minitest/autorun'
2
- require_relative File.join('..', '..', '..', 'lib', 'deltacloud', 'api.rb')
1
+ require 'rubygems'
2
+ require 'require_relative' if RUBY_VERSION < '1.9'
3
+
4
+ require_relative 'common.rb'
5
+
6
+ require_relative '../../../lib/deltacloud/api'
3
7
 
4
8
  describe 'Deltacloud API Library' do
5
9
 
@@ -3,29 +3,48 @@
3
3
  require 'right_http_connection'
4
4
  require 'vcr'
5
5
 
6
- # Freeze time, so EC2 signatures have all the same time
7
- # This will avoid IncorrectSignature exceptions
8
-
9
- # NOTE: This timestamp need to be changed when re-recording
10
- # the fixtures.
6
+ require_relative '../../test_helper.rb'
7
+ require_relative '../../../lib/deltacloud/drivers/ec2/ec2_driver'
11
8
 
12
9
  def credentials
13
- {
14
- :user => 'AKIAJYOQYLLOIWN5LQ3A',
15
- :password => 'Ra2ViYaYgocAJqPAQHxMVU/l2sGGU2pifmWT4q3H'
16
- }
10
+ Deltacloud::Test::config.credentials('ec2')
17
11
  end
18
12
 
19
- unless Time.respond_to? :be
20
- require_relative '../../test_helper.rb'
13
+ # Monkey patch EC2 driver to return a client
14
+ class Deltacloud::Drivers::Ec2::Ec2Driver
15
+ def client(credentials)
16
+ new_client(credentials)
17
+ end
21
18
  end
22
19
 
23
- Time.be(DateTime.parse("2012-07-30 11:05:00 +0000").to_s)
24
-
20
+ # Configure VCR
25
21
  VCR.configure do |c|
26
22
  # NOTE: Empty this directory before re-recording
27
23
  c.cassette_library_dir = File.join(File.dirname(__FILE__), 'fixtures')
28
24
  c.hook_into :webmock
29
- # Set this to :new_episodes when you want to 're-record'
30
- c.default_cassette_options = { :record => :new_episodes }
25
+ matcher = VCR.request_matchers.uri_without_param("AWSAccessKeyId",
26
+ "Signature", "Timestamp")
27
+ c.register_request_matcher(:ec2_matcher, &matcher)
28
+ c.default_cassette_options = { :record => :none, :match_requests_on => [:method, :ec2_matcher] }
29
+ end
30
+
31
+ # Setup resources we need for the tests
32
+ def create_resources
33
+ VCR.use_cassette "create_resources" do
34
+ driver = Deltacloud::new(:ec2, credentials)
35
+ @@ec2 = driver.client
36
+ @@vpc = @@ec2.create_vpc("172.16.0.0/16").first
37
+ @@subnet = @@ec2.create_subnet(@@vpc[:vpc_id], "172.16.3.0/24", "us-east-1b").first
38
+ end
31
39
  end
40
+
41
+ def destroy_resources
42
+ VCR.use_cassette "destroy_resources" do
43
+ @@ec2.delete_subnet(@@subnet[:subnet_id]) if @@subnet
44
+ @@ec2.delete_vpc(@@vpc[:vpc_id]) if @@vpc
45
+ end
46
+ end
47
+
48
+ MiniTest::Unit::after_tests { destroy_resources }
49
+
50
+ create_resources
@@ -1,6 +1,6 @@
1
- require 'minitest/autorun'
1
+ require 'rubygems'
2
+ require 'require_relative' if RUBY_VERSION < '1.9'
2
3
 
3
- require_relative File.join('..', '..', '..', 'lib', 'deltacloud', 'api.rb')
4
4
  require_relative 'common.rb'
5
5
 
6
6
  describe 'Ec2Driver Images' do
@@ -46,4 +46,3 @@ describe 'Ec2Driver Images' do
46
46
  end
47
47
 
48
48
  end
49
-
@@ -1,6 +1,6 @@
1
- require 'minitest/autorun'
1
+ require 'rubygems'
2
+ require 'require_relative' if RUBY_VERSION < '1.9'
2
3
 
3
- require_relative File.join('..', '..', '..', 'lib', 'deltacloud', 'api.rb')
4
4
  require_relative 'common.rb'
5
5
 
6
6
  describe 'Ec2Driver Instances' do
@@ -90,6 +90,16 @@ describe 'Ec2Driver Instances' do
90
90
  instances.each { |i| i.is_stopped?.must_equal true }
91
91
  end
92
92
 
93
+ it 'must allow creating instance in a VPC subnet' do
94
+ realm_id = "#{@@subnet[:availability_zone]}:#{@@subnet[:subnet_id]}"
95
+ instance = @driver.create_instance('ami-aecd60c7',
96
+ :realm_id => realm_id,
97
+ :hwp_id => 'm1.small')
98
+ instance.must_be_kind_of Instance
99
+ instance.realm_id.must_equal realm_id
100
+ @driver.destroy_instance(instance.id)
101
+ end
102
+
93
103
  it 'must allow to reboot instance in running state' do
94
104
  instance = @driver.create_instance('ami-aecd60c7', :realm_id => 'us-east-1a', :hwp_id => 't1.micro')
95
105
  instance = instance.wait_for!(@driver, record_retries) { |i| i.is_running? }
@@ -1,6 +1,6 @@
1
- require 'minitest/autorun'
1
+ require 'rubygems'
2
+ require 'require_relative' if RUBY_VERSION < '1.9'
2
3
 
3
- require_relative File.join('..', '..', '..', 'lib', 'deltacloud', 'api.rb')
4
4
  require_relative 'common.rb'
5
5
 
6
6
  describe 'Ec2Driver Instances' do
@@ -1,6 +1,6 @@
1
- require 'minitest/autorun'
1
+ require 'rubygems'
2
+ require 'require_relative' if RUBY_VERSION < '1.9'
2
3
 
3
- require_relative File.join('..', '..', '..', 'lib', 'deltacloud', 'api.rb')
4
4
  require_relative 'common.rb'
5
5
 
6
6
  describe 'Ec2Driver Realms' do
@@ -40,5 +40,9 @@ describe 'Ec2Driver Realms' do
40
40
  @driver.realm(:id => 'unknown').must_be_nil
41
41
  end
42
42
 
43
- end
43
+ it 'must list VPC subnets as realms' do
44
+ id = "#{@@subnet[:availability_zone]}:#{@@subnet[:subnet_id]}"
45
+ @driver.realms.find { |r| r.id == id }.wont_be_nil
46
+ end
44
47
 
48
+ end
@@ -1,11 +1,10 @@
1
- require 'minitest/autorun'
1
+ require 'rubygems'
2
+ require 'require_relative' if RUBY_VERSION < '1.9'
2
3
 
3
- require_relative File.join('..', '..', '..', 'lib', 'deltacloud', 'api.rb')
4
4
  require_relative 'common.rb'
5
5
 
6
6
  describe 'Ec2Driver StorageSnapshots' do
7
7
  before do
8
- Time.be(DateTime.parse("2012-08-13 13:03:00 +0000").to_s)
9
8
  @driver = Deltacloud::new(:ec2, credentials)
10
9
  VCR.insert_cassette __name__
11
10
  end
@@ -0,0 +1,24 @@
1
+ require 'vcr'
2
+
3
+ require_relative '../../test_helper.rb'
4
+
5
+ def credentials
6
+ Deltacloud::Test::config.credentials("gogrid")
7
+ end
8
+
9
+ def fixed_image_id
10
+ # A fixed image we use throughout the tests; if GoGrid ever removes it
11
+ # we need to change it here
12
+ "9928"
13
+ end
14
+
15
+ VCR.configure do |c|
16
+ # NOTE: Empty this directory before re-recording
17
+ c.cassette_library_dir = File.join(File.dirname(__FILE__), 'fixtures')
18
+ c.hook_into :webmock
19
+ matcher = VCR.request_matchers.uri_without_param("api_key", "sig")
20
+ c.register_request_matcher(:gogrid_matcher, &matcher)
21
+ # Set this to :new_episodes to rerecord
22
+ c.default_cassette_options[:record] =:none
23
+ c.default_cassette_options[:match_requests_on] = [:method, :gogrid_matcher]
24
+ end
@@ -0,0 +1,51 @@
1
+ require 'rubygems'
2
+ require 'require_relative' if RUBY_VERSION < '1.9'
3
+
4
+ require_relative 'common'
5
+
6
+ describe 'GoGrid Hardware Profiles' do
7
+
8
+ before do
9
+ @driver = Deltacloud::new(:gogrid, credentials)
10
+ VCR.insert_cassette __name__
11
+ end
12
+
13
+ after do
14
+ VCR.eject_cassette
15
+ end
16
+
17
+ it 'must throw error when wrong credentials' do
18
+ Proc.new do
19
+ @driver.backend.realms(OpenStruct.new(:user => 'unknown', :password => 'wrong'))
20
+ end.must_raise Deltacloud::ExceptionHandler::AuthenticationFailure, 'Authentication Failure'
21
+ end
22
+
23
+ it 'must return list of hardware profiles' do
24
+ @driver.hardware_profiles.wont_be_empty
25
+ @driver.hardware_profiles.first.must_be_kind_of Deltacloud::HardwareProfile
26
+ end
27
+
28
+ it 'must allow to filter hardware profiles' do
29
+ @driver.hardware_profiles(:id => 'web-server').wont_be_empty
30
+ @driver.hardware_profiles(:id => 'web-server').must_be_kind_of Array
31
+ @driver.hardware_profiles(:id => 'web-server').size.must_equal 1
32
+ @driver.hardware_profiles(:id => 'web-server').first.name.must_equal 'web-server'
33
+ @driver.hardware_profiles(:id => 'unknown').must_be_empty
34
+ end
35
+
36
+ it 'must allow to retrieve single hardware_profile' do
37
+ profile = @driver.hardware_profile(:id => 'database-server')
38
+ profile.wont_be_nil
39
+ profile.must_be_kind_of Deltacloud::HardwareProfile
40
+ profile.name.must_equal 'database-server'
41
+ profile.properties.must_be_kind_of Array
42
+ profile.properties.wont_be_empty
43
+ profile.properties.each do |p|
44
+ p.must_be_kind_of Deltacloud::HardwareProfile::Property
45
+ p.name.to_s.wont_be_empty
46
+ p.kind.to_s.wont_be_empty
47
+ end
48
+ @driver.hardware_profile(:id => 'unknown').must_be_nil
49
+ end
50
+
51
+ end
@@ -0,0 +1,57 @@
1
+ require 'rubygems'
2
+ require 'require_relative' if RUBY_VERSION < '1.9'
3
+
4
+ require_relative 'common'
5
+
6
+ describe 'GoGridDriver Images' do
7
+
8
+ before do
9
+ @driver = Deltacloud::new(:gogrid, credentials)
10
+ VCR.insert_cassette __name__
11
+ end
12
+
13
+ after do
14
+ VCR.eject_cassette
15
+ end
16
+
17
+ it 'must throw error when wrong credentials' do
18
+ Proc.new do
19
+ @driver.backend.images(OpenStruct.new(:user => 'unknown', :password => 'wrong'))
20
+ end.must_raise Deltacloud::ExceptionHandler::AuthenticationFailure, 'Authentication Failure'
21
+ end
22
+
23
+ it 'must return list of images' do
24
+ @driver.images.wont_be_empty
25
+ @driver.images.first.must_be_kind_of Image
26
+ end
27
+
28
+ it 'must allow to filter images' do
29
+ img = @driver.images.first
30
+ img.wont_be_nil
31
+
32
+ imgs = @driver.images(:id => img.id)
33
+ imgs.wont_be_empty
34
+ imgs.must_be_kind_of Array
35
+ imgs.size.must_equal 1
36
+ imgs.first.id.must_equal img.id
37
+ imgs.first.name.must_equal img.name
38
+ end
39
+
40
+ it 'must return an empty array for nonexistent image' do
41
+ @driver.images(:id => 'unknown').must_be_empty
42
+ end
43
+
44
+ it 'must allow to retrieve single image' do
45
+ some_img = @driver.images.first
46
+ some_img.wont_be_nil
47
+ by_id = @driver.image(:id => some_img.id)
48
+
49
+ by_id.wont_be_nil
50
+ by_id.must_be_kind_of Image
51
+ by_id.id.must_equal some_img.id
52
+ end
53
+
54
+ it 'must return nil when retrieving a single nonexistent image' do
55
+ @driver.image(:id => 'unknown').must_be_nil
56
+ end
57
+ end
@@ -0,0 +1,92 @@
1
+ require 'rubygems'
2
+ require 'require_relative' if RUBY_VERSION < '1.9'
3
+
4
+ require_relative 'common'
5
+
6
+ describe 'GoGridDriver Instances' do
7
+
8
+ INSTANCE_ID = "test-instance"
9
+
10
+ before do
11
+ @driver = Deltacloud::new(:gogrid, credentials)
12
+ VCR.insert_cassette __name__
13
+ end
14
+
15
+ after do
16
+ VCR.eject_cassette
17
+ end
18
+
19
+ def self.create_test_instance
20
+ driver = Deltacloud::new(:gogrid, credentials)
21
+ VCR.use_cassette "instances_create_test_instance" do
22
+ @@instance = driver.instance(:id => INSTANCE_ID)
23
+ @@instance ||= driver.create_instance(fixed_image_id,
24
+ :name=> INSTANCE_ID)
25
+ end
26
+ end
27
+
28
+ # Destroy test instance when all test are done
29
+ def self.__name__
30
+ # record_retries below calls this
31
+ "instances_test_class"
32
+ end
33
+
34
+ def self.destroy_test_instance
35
+ driver = Deltacloud::new(:gogrid, credentials)
36
+
37
+ # Go fast when running off a recording
38
+ opts = record_retries('', :time_between_retry => 60)
39
+ @@instance.wait_for!(driver, opts) do |i|
40
+ i.actions.include?(:destroy)
41
+ end
42
+
43
+ VCR.use_cassette "instances_destroy_test_instance" do
44
+ driver.destroy_instance(@@instance.id)
45
+ @@instance = nil
46
+ end
47
+ end
48
+
49
+ # Setup/teardown before/after all tests
50
+ create_test_instance
51
+
52
+ MiniTest::Unit::after_tests { destroy_test_instance }
53
+
54
+ let :instance do
55
+ @@instance
56
+ end
57
+
58
+ it 'must throw error when wrong credentials' do
59
+ Proc.new do
60
+ @driver.backend.images(OpenStruct.new(:user => 'unknown', :password => 'wrong'))
61
+ end.must_raise Deltacloud::ExceptionHandler::AuthenticationFailure, 'Authentication Failure'
62
+ end
63
+
64
+ it 'must return list of instances' do
65
+ @driver.instances.wont_be_empty
66
+ @driver.instances.first.must_be_kind_of Instance
67
+ end
68
+
69
+ it 'must allow to filter instances' do
70
+ by_id = @driver.instances(:id => instance.id)
71
+ by_id.wont_be_empty
72
+ by_id.must_be_kind_of Array
73
+ by_id.size.must_equal 1
74
+ by_id.first.id.must_equal instance.id
75
+
76
+ by_owner = @driver.instances(:owner_id => instance.owner_id)
77
+ by_owner.wont_be_empty
78
+ by_owner.each do |inst|
79
+ inst.owner_id.must_equal instance.owner_id
80
+ end
81
+
82
+ @driver.instances(:id => 'unknown').must_be_empty
83
+ end
84
+
85
+ it 'must allow to retrieve single instance' do
86
+ by_id = @driver.instance(:id => instance.id)
87
+ by_id.wont_be_nil
88
+ by_id.must_be_kind_of Instance
89
+ by_id.id.must_equal instance.id
90
+ @driver.instance(:id => "unknown").must_be_nil
91
+ end
92
+ end