deltacloud-core 1.0.1 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (222) hide show
  1. data/Rakefile +99 -141
  2. data/bin/deltacloudd +4 -1
  3. data/config.ru +13 -6
  4. data/config/drivers/aruba.yaml +8 -0
  5. data/config/drivers/fgcp.yaml +3 -2
  6. data/deltacloud-core.gemspec +13 -9
  7. data/lib/cimi/collections/cloud_entry_point.rb +1 -1
  8. data/lib/cimi/models.rb +1 -7
  9. data/lib/cimi/models/base.rb +1 -4
  10. data/lib/cimi/models/cloud_entry_point.rb +14 -0
  11. data/lib/cimi/models/machine.rb +4 -4
  12. data/lib/cimi/models/machine_admin.rb +1 -0
  13. data/lib/cimi/models/machine_configuration.rb +4 -4
  14. data/lib/cimi/models/schema.rb +17 -14
  15. data/lib/cimi/models/volume_image.rb +1 -1
  16. data/lib/cimi/server.rb +1 -1
  17. data/lib/deltacloud/api.rb +55 -3
  18. data/lib/deltacloud/collections/addresses.rb +1 -1
  19. data/lib/deltacloud/collections/buckets.rb +12 -10
  20. data/lib/deltacloud/collections/firewalls.rb +2 -1
  21. data/lib/deltacloud/collections/hardware_profiles.rb +1 -1
  22. data/lib/deltacloud/collections/images.rb +2 -2
  23. data/lib/deltacloud/collections/instance_states.rb +6 -3
  24. data/lib/deltacloud/collections/instances.rb +2 -1
  25. data/lib/deltacloud/collections/keys.rb +6 -2
  26. data/lib/deltacloud/collections/load_balancers.rb +8 -7
  27. data/lib/deltacloud/collections/metrics.rb +2 -1
  28. data/lib/deltacloud/collections/realms.rb +1 -1
  29. data/lib/deltacloud/collections/storage_snapshots.rb +2 -1
  30. data/lib/deltacloud/collections/storage_volumes.rb +2 -2
  31. data/lib/deltacloud/core_ext.rb +1 -7
  32. data/lib/deltacloud/core_ext/hash.rb +7 -5
  33. data/lib/deltacloud/core_ext/string.rb +1 -0
  34. data/lib/deltacloud/drivers/aruba/aruba_driver.rb +469 -0
  35. data/lib/deltacloud/drivers/base_driver.rb +12 -17
  36. data/lib/deltacloud/drivers/ec2/ec2_driver.rb +50 -22
  37. data/lib/deltacloud/drivers/eucalyptus/eucalyptus_driver.rb +1 -1
  38. data/lib/deltacloud/drivers/exceptions.rb +12 -2
  39. data/lib/deltacloud/drivers/features.rb +8 -0
  40. data/lib/deltacloud/drivers/fgcp/fgcp_client.rb +21 -6
  41. data/lib/deltacloud/drivers/fgcp/fgcp_driver.rb +169 -57
  42. data/lib/deltacloud/drivers/gogrid/gogrid_driver.rb +1 -1
  43. data/lib/deltacloud/drivers/mock/mock_client.rb +2 -0
  44. data/lib/deltacloud/drivers/mock/mock_driver.rb +101 -13
  45. data/lib/deltacloud/drivers/opennebula/occi_client.rb +12 -6
  46. data/lib/deltacloud/drivers/opennebula/opennebula_driver.rb +10 -18
  47. data/lib/deltacloud/drivers/openstack/openstack_driver.rb +46 -1
  48. data/lib/deltacloud/drivers/rhevm/rhevm_driver.rb +17 -17
  49. data/lib/deltacloud/drivers/vsphere/vsphere_driver.rb +4 -4
  50. data/lib/deltacloud/helpers.rb +4 -4
  51. data/lib/deltacloud/helpers/blob_stream_helper.rb +4 -6
  52. data/lib/deltacloud/helpers/deltacloud_helper.rb +17 -1
  53. data/lib/deltacloud/helpers/driver_helper.rb +7 -3
  54. data/lib/deltacloud/helpers/url_helper.rb +4 -4
  55. data/lib/deltacloud/models/address.rb +1 -1
  56. data/lib/deltacloud/models/base_model.rb +0 -14
  57. data/lib/deltacloud/models/bucket.rb +0 -10
  58. data/lib/deltacloud/models/hardware_profile.rb +5 -26
  59. data/lib/deltacloud/models/image.rb +0 -12
  60. data/lib/deltacloud/models/instance.rb +6 -22
  61. data/lib/deltacloud/models/key.rb +2 -2
  62. data/lib/deltacloud/models/metric.rb +1 -1
  63. data/lib/deltacloud/models/storage_snapshot.rb +4 -0
  64. data/lib/deltacloud/server.rb +8 -2
  65. data/lib/deltacloud_rack.rb +40 -10
  66. data/lib/ec2/query_parser.rb +9 -4
  67. data/lib/ec2/server.rb +1 -1
  68. data/lib/ec2/views/create_key_pair.haml +3 -0
  69. data/lib/ec2/views/delete_key_pair.haml +1 -0
  70. data/lib/ec2/views/describe_availability_zones.haml +6 -0
  71. data/lib/ec2/views/describe_images.haml +10 -0
  72. data/lib/ec2/views/describe_instance_set.haml +24 -0
  73. data/lib/ec2/views/describe_instances.haml +9 -0
  74. data/lib/ec2/views/describe_key_pairs.haml +5 -0
  75. data/lib/ec2/views/error.haml +4 -0
  76. data/lib/ec2/views/instance_action.haml +9 -0
  77. data/lib/ec2/views/reboot_instances.haml +1 -0
  78. data/lib/ec2/views/run_instances.haml +7 -0
  79. data/lib/ec2/views/start_instances.haml +1 -0
  80. data/lib/ec2/views/stop_instances.haml +1 -0
  81. data/lib/ec2/views/terminate_instances.haml +9 -0
  82. data/lib/sinatra.rb +0 -1
  83. data/lib/sinatra/rack_accept.rb +1 -1
  84. data/lib/sinatra/rack_driver_select.rb +2 -2
  85. data/lib/sinatra/rack_etag.rb +5 -1
  86. data/lib/sinatra/rack_logger.rb +127 -0
  87. data/lib/sinatra/rack_matrix_params.rb +1 -1
  88. data/tests/cimi/collections/cloud_entry_point_test.rb +46 -0
  89. data/tests/cimi/collections/common.rb +17 -0
  90. data/tests/cimi/collections/machine_images_test.rb +44 -0
  91. data/tests/cimi/collections/machines_test.rb +41 -0
  92. data/tests/cimi/spec/cimi/model/machine_admin_spec.rb +35 -0
  93. data/tests/cimi/spec/cimi/model/machine_configuration_spec.rb +31 -0
  94. data/tests/cimi/spec/cimi/model/machine_image_spec.rb +33 -0
  95. data/tests/cimi/spec/cimi/model/machine_spec.rb +32 -0
  96. data/tests/cimi/spec/cimi/model/machine_template_spec.rb +32 -0
  97. data/tests/cimi/spec/cimi/model/schema_spec.rb +245 -0
  98. data/tests/cimi/spec/cimi/model/volume_configuration_spec.rb +34 -0
  99. data/tests/cimi/spec/cimi/model/volume_image_spec.rb +33 -0
  100. data/tests/cimi/spec/cimi/model/volume_spec.rb +32 -0
  101. data/tests/cimi/spec/cimi/model/volume_template_spec.rb +32 -0
  102. data/tests/cimi/spec/spec_helper.rb +136 -0
  103. data/tests/deltacloud/base_collection_test.rb +30 -0
  104. data/tests/deltacloud/collections/buckets_collection_test.rb +65 -0
  105. data/tests/deltacloud/collections/drivers_collection_test.rb +37 -0
  106. data/tests/deltacloud/collections/hardware_profiles_collection_test.rb +53 -0
  107. data/tests/deltacloud/collections/images_collection_test.rb +59 -0
  108. data/tests/deltacloud/collections/instance_states_collection_test.rb +34 -0
  109. data/tests/deltacloud/collections/instances_collection_test.rb +63 -0
  110. data/tests/deltacloud/collections/keys_collection_test.rb +63 -0
  111. data/tests/deltacloud/collections_test.rb +35 -0
  112. data/tests/deltacloud/common.rb +14 -0
  113. data/tests/deltacloud/deltacloud_helper_test.rb +55 -0
  114. data/tests/deltacloud/drivers_test.rb +73 -0
  115. data/tests/deltacloud/rack_test.rb +51 -0
  116. data/tests/deltacloud/server_test.rb +149 -0
  117. data/tests/{api → deprecated/api}/common.rb +0 -0
  118. data/tests/{api → deprecated/api}/driver_test.rb +0 -0
  119. data/tests/deprecated/api/library_test.rb +6 -0
  120. data/tests/{cimi → deprecated/cimi}/features/step_definitions/common_steps.rb +0 -0
  121. data/tests/{cimi → deprecated/cimi}/features/step_definitions/machine_images_steps.rb +0 -0
  122. data/tests/{cimi → deprecated/cimi}/features/step_definitions/machines_steps.rb +0 -0
  123. data/tests/{cimi → deprecated/cimi}/features/step_definitions/volumes_steps.rb +0 -0
  124. data/tests/{cimi → deprecated/cimi}/features/support/env.rb +0 -0
  125. data/tests/{common.rb → deprecated/common.rb} +0 -0
  126. data/tests/{core_ext → deprecated/core_ext}/string.rb +0 -0
  127. data/tests/{drivers → deprecated/drivers}/ec2/api_test.rb +0 -0
  128. data/tests/deprecated/drivers/ec2/common.rb +23 -0
  129. data/tests/{drivers → deprecated/drivers}/ec2/drivers_test.rb +0 -0
  130. data/tests/{drivers → deprecated/drivers}/ec2/hardware_profiles_test.rb +0 -0
  131. data/tests/deprecated/drivers/ec2/images_test.rb +230 -0
  132. data/tests/{drivers → deprecated/drivers}/ec2/instances_test.rb +0 -0
  133. data/tests/deprecated/drivers/ec2/keys_test.rb +181 -0
  134. data/tests/deprecated/drivers/ec2/realms_test.rb +146 -0
  135. data/tests/{drivers → deprecated/drivers}/fgcp/api_test.rb +0 -0
  136. data/tests/{drivers → deprecated/drivers}/fgcp/hardware_profiles_test.rb +0 -0
  137. data/tests/{drivers → deprecated/drivers}/fgcp/realms_test.rb +0 -0
  138. data/tests/{drivers → deprecated/drivers}/fgcp/setup.rb +0 -0
  139. data/tests/{drivers → deprecated/drivers}/google/api_test.rb +0 -0
  140. data/tests/{drivers → deprecated/drivers}/google/buckets_test.rb +0 -0
  141. data/tests/{drivers → deprecated/drivers}/google/common.rb +2 -2
  142. data/tests/{drivers → deprecated/drivers}/mock/api_test.rb +0 -0
  143. data/tests/{drivers → deprecated/drivers}/mock/buckets_test.rb +0 -0
  144. data/tests/{drivers → deprecated/drivers}/mock/common.rb +0 -0
  145. data/tests/{drivers → deprecated/drivers}/mock/drivers_test.rb +0 -0
  146. data/tests/{drivers → deprecated/drivers}/mock/hardware_profiles_test.rb +0 -0
  147. data/tests/deprecated/drivers/mock/images_test.rb +197 -0
  148. data/tests/deprecated/drivers/mock/instances_test.rb +343 -0
  149. data/tests/deprecated/drivers/mock/keys_test.rb +161 -0
  150. data/tests/deprecated/drivers/mock/realms_test.rb +132 -0
  151. data/tests/deprecated/drivers/mock/storage_snapshots_test.rb +114 -0
  152. data/tests/deprecated/drivers/mock/storage_volumes_test.rb +122 -0
  153. data/tests/{drivers → deprecated/drivers}/openstack/api_test.rb +0 -0
  154. data/tests/{drivers → deprecated/drivers}/openstack/common.rb +0 -0
  155. data/tests/{drivers → deprecated/drivers}/openstack/hardware_profiles_test.rb +0 -0
  156. data/tests/{drivers → deprecated/drivers}/openstack/images_test.rb +0 -0
  157. data/tests/{drivers → deprecated/drivers}/openstack/instances_test.rb +0 -0
  158. data/tests/{drivers → deprecated/drivers}/openstack/realms_test.rb +0 -0
  159. data/tests/{drivers → deprecated/drivers}/rackspace/api_test.rb +0 -0
  160. data/tests/{drivers → deprecated/drivers}/rackspace/buckets_test.rb +0 -0
  161. data/tests/{drivers → deprecated/drivers}/rackspace/common.rb +0 -0
  162. data/tests/{drivers → deprecated/drivers}/rackspace/hardware_profiles_test.rb +0 -0
  163. data/tests/{drivers → deprecated/drivers}/rackspace/images_test.rb +0 -0
  164. data/tests/{drivers → deprecated/drivers}/rackspace/instances_test.rb +0 -0
  165. data/tests/{drivers → deprecated/drivers}/rackspace/realms_test.rb +0 -0
  166. data/tests/{drivers → deprecated/drivers}/rhevm/api_test.rb +0 -0
  167. data/tests/deprecated/drivers/rhevm/common.rb +21 -0
  168. data/tests/{drivers → deprecated/drivers}/rhevm/hardware_profiles_test.rb +0 -0
  169. data/tests/deprecated/drivers/rhevm/images_test.rb +48 -0
  170. data/tests/{drivers → deprecated/drivers}/rhevm/instances_test.rb +0 -0
  171. data/tests/deprecated/drivers/rhevm/realms_test.rb +40 -0
  172. data/tests/{minitest_common.rb → deprecated/minitest_common.rb} +0 -0
  173. data/tests/{minitest_common_api_test.rb → deprecated/minitest_common_api_test.rb} +0 -0
  174. data/tests/{rabbit_test.rb → deprecated/rabbit_test.rb} +0 -0
  175. data/tests/drivers/base/base_driver_test.rb +124 -0
  176. data/tests/{api → drivers/base}/library_test.rb +2 -8
  177. data/tests/drivers/ec2/common.rb +23 -15
  178. data/tests/drivers/ec2/images_test.rb +30 -211
  179. data/tests/drivers/ec2/instance_test.rb +104 -0
  180. data/tests/drivers/ec2/keys_test.rb +32 -161
  181. data/tests/drivers/ec2/realms_test.rb +26 -128
  182. data/tests/drivers/ec2/storage_snapshots_test.rb +54 -0
  183. data/tests/drivers/mock/images_test.rb +37 -179
  184. data/tests/drivers/mock/instances_test.rb +103 -340
  185. data/tests/drivers/mock/keys_test.rb +30 -145
  186. data/tests/drivers/mock/realms_test.rb +23 -118
  187. data/tests/drivers/mock/storage_snapshots_test.rb +23 -100
  188. data/tests/drivers/mock/storage_volumes_test.rb +41 -104
  189. data/tests/drivers/models/address_test.rb +18 -0
  190. data/tests/drivers/models/base_test.rb +33 -0
  191. data/tests/drivers/models/blob_test.rb +18 -0
  192. data/tests/drivers/models/hardware_profile_test.rb +52 -0
  193. data/tests/drivers/models/instance_address_test.rb +24 -0
  194. data/tests/drivers/models/instance_profile_test.rb +21 -0
  195. data/tests/drivers/models/instance_test.rb +29 -0
  196. data/tests/drivers/models/keys_test.rb +25 -0
  197. data/tests/drivers/models/metrics_test.rb +20 -0
  198. data/tests/drivers/rhevm/common.rb +15 -15
  199. data/tests/drivers/rhevm/images_test.rb +61 -36
  200. data/tests/drivers/rhevm/instance_test.rb +104 -0
  201. data/tests/drivers/rhevm/provider_test.rb +48 -0
  202. data/tests/drivers/rhevm/realms_test.rb +40 -37
  203. data/tests/ec2/common.rb +24 -0
  204. data/tests/ec2/query_parser_test.rb +98 -0
  205. data/tests/ec2/server_test.rb +45 -0
  206. data/tests/helpers/core_ext/array_test.rb +24 -0
  207. data/tests/helpers/core_ext/hash_test.rb +42 -0
  208. data/tests/helpers/core_ext/integer_test.rb +19 -0
  209. data/tests/helpers/core_ext/string_test.rb +74 -0
  210. data/tests/test_helper.rb +66 -0
  211. data/views/api/show.html.haml +1 -2
  212. data/views/api/show.xml.haml +1 -2
  213. data/views/blobs/show.xml.haml +1 -2
  214. data/views/keys/new.html.haml +9 -2
  215. data/views/load_balancers/new.html.haml +35 -34
  216. data/views/metrics/index.html.haml +1 -1
  217. data/views/metrics/show.html.haml +2 -2
  218. data/views/metrics/show.xml.haml +6 -2
  219. data/views/storage_volumes/attach.html.haml +1 -1
  220. data/views/storage_volumes/show.html.haml +1 -1
  221. metadata +853 -544
  222. data/lib/sinatra/accept_media_types.rb +0 -154
@@ -0,0 +1,54 @@
1
+ require 'minitest/autorun'
2
+
3
+ require_relative File.join('..', '..', '..', 'lib', 'deltacloud', 'api.rb')
4
+ require_relative 'common.rb'
5
+
6
+ describe 'Ec2Driver StorageSnapshots' do
7
+ before do
8
+ Time.be(DateTime.parse("2012-08-13 13:03:00 +0000").to_s)
9
+ @driver = Deltacloud::new(:ec2, 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 storage snapshots' do
24
+ @driver.storage_snapshots.wont_be_empty
25
+ @driver.storage_snapshots.first.must_be_kind_of StorageSnapshot
26
+ end
27
+
28
+ it 'must allow to filter storage snapshots' do
29
+ @driver.storage_snapshots(:id => 'snap-e5bc8d95').wont_be_empty
30
+ @driver.storage_snapshots(:id => 'snap-e5bc8d95').must_be_kind_of Array
31
+ @driver.storage_snapshots(:id => 'snap-e5bc8d95').size.must_equal 1
32
+ @driver.storage_snapshots(:id => 'snap-e5bc8d95').first.id.must_equal 'snap-e5bc8d95'
33
+ @driver.storage_snapshots(:id => 'snap-00000000').must_be_empty
34
+ end
35
+
36
+ it 'must allow to create and destroy the storage snapshot' do
37
+ record_options = record_retries.merge(:method => :storage_snapshot)
38
+
39
+ # Create the new storage snapshot
40
+ snapshot = @driver.create_storage_snapshot(:volume_id => 'vol-732cf013')
41
+ snapshot.wait_for!(@driver, record_options) { |i| i.is_completed? }
42
+
43
+ # Get created snapshot and check its properties
44
+ snapshot = @driver.storage_snapshot(:id => snapshot.id)
45
+ snapshot.is_completed?.must_equal true
46
+ snapshot.storage_volume_id.must_equal 'vol-732cf013'
47
+
48
+ # Destroy the snapshot at the end
49
+ @driver.destroy_storage_snapshot(:id => snapshot.id)
50
+ snapshot.wait_for!(@driver, record_options) { |i| i.nil? }
51
+ @driver.storage_snapshot(:id => snapshot.id).must_be_nil
52
+ end
53
+
54
+ end
@@ -1,197 +1,55 @@
1
- $:.unshift File.join(File.dirname(__FILE__), '..', '..', '..')
2
- require 'tests/drivers/mock/common'
1
+ require 'minitest/autorun'
3
2
 
4
- describe 'Deltacloud API Images' do
5
- include Deltacloud::Test
3
+ require_relative File.join('..', '..', '..', 'lib', 'deltacloud', 'api.rb')
6
4
 
7
- it 'must advertise have the images collection in API entrypoint' do
8
- get root_url
9
- (xml_response/'api/link[@rel=images]').wont_be_empty
10
- end
11
-
12
- it 'must require authentication to access the "image" collection' do
13
- get collection_url(:images)
14
- last_response.status.must_equal 401
15
- end
16
-
17
- it 'should respond with HTTP_OK when accessing the :images collection with authentication' do
18
- authenticate
19
- get collection_url(:images)
20
- last_response.status.must_equal 200
21
- end
22
-
23
- it 'should support the JSON media type' do
24
- authenticate
25
- header 'Accept', 'application/json'
26
- get collection_url(:images)
27
- last_response.status.must_equal 200
28
- last_response.headers['Content-Type'].must_equal 'application/json'
29
- end
30
-
31
- it 'must include the ETag in HTTP headers' do
32
- authenticate
33
- get collection_url(:images)
34
- last_response.headers['ETag'].wont_be_nil
35
- end
36
-
37
- it 'must have the "images" element on top level' do
38
- authenticate
39
- get collection_url(:images)
40
- xml_response.root.name.must_equal 'images'
41
- end
42
-
43
- it 'must have some "image" elements inside "images"' do
44
- authenticate
45
- get collection_url(:images)
46
- (xml_response/'images/image').wont_be_empty
47
- end
48
-
49
- it 'must provide the :id attribute for each image in collection' do
50
- authenticate
51
- get collection_url(:images)
52
- (xml_response/'images/image').each do |r|
53
- r[:id].wont_be_nil
54
- end
55
- end
56
-
57
- it 'must include the :href attribute for each "image" element in collection' do
58
- authenticate
59
- get collection_url(:images)
60
- (xml_response/'images/image').each do |r|
61
- r[:href].wont_be_nil
62
- end
63
- end
64
-
65
- it 'must use the absolute URL in each :href attribute' do
66
- authenticate
67
- get collection_url(:images)
68
- (xml_response/'images/image').each do |r|
69
- r[:href].must_match /^http/
70
- end
71
- end
72
-
73
- it 'must have the URL ending with the :id of the image' do
74
- authenticate
75
- get collection_url(:images)
76
- (xml_response/'images/image').each do |r|
77
- r[:href].must_match /#{r[:id]}$/
78
- end
79
- end
80
-
81
- it 'must return the list of valid parameters for the :index action' do
82
- authenticate
83
- options collection_url(:images) + '/index'
84
- last_response.headers['Allow'].wont_be_nil
85
- end
86
-
87
- it 'must have the "name" element defined for each image in collection' do
88
- authenticate
89
- get collection_url(:images)
90
- (xml_response/'images/image').each do |r|
91
- (r/'name').wont_be_empty
92
- end
93
- end
94
-
95
- it 'must have the "state" element defined for each image in collection' do
96
- authenticate
97
- get collection_url(:images)
98
- (xml_response/'images/image').each do |r|
99
- (r/'state').wont_be_empty
100
- end
101
- end
102
-
103
- it 'must return the full "image" when following the URL in image element' do
104
- authenticate
105
- get collection_url(:images)
106
- (xml_response/'images/image').each do |r|
107
- get collection_url(:images) + '/' + r[:id]
108
- last_response.status.must_equal 200
109
- end
110
- end
111
-
112
- it 'must have the "name" element for the image and it should match with the one in collection' do
113
- authenticate
114
- get collection_url(:images)
115
- (xml_response/'images/image').each do |r|
116
- get collection_url(:images) + '/' + r[:id]
117
- (xml_response/'name').wont_be_empty
118
- (xml_response/'name').first.text.must_equal((r/'name').first.text)
119
- end
120
- end
5
+ describe 'MockDriver Images' do
121
6
 
122
- it 'must have the "name" element for the image and it should match with the one in collection' do
123
- authenticate
124
- get collection_url(:images)
125
- (xml_response/'images/image').each do |r|
126
- get collection_url(:images) + '/' + r[:id]
127
- (xml_response/'state').wont_be_empty
128
- (xml_response/'state').first.text.must_equal((r/'state').first.text)
129
- end
7
+ before do
8
+ @driver = Deltacloud::new(:mock, :user => 'mockuser', :password => 'mockpassword')
130
9
  end
131
10
 
132
- it 'should have the "owner_id" element for each image' do
133
- authenticate
134
- get collection_url(:images)
135
- (xml_response/'images/image').each do |r|
136
- get collection_url(:images) + '/' + r[:id]
137
- (xml_response/'owner_id').wont_be_empty
138
- end
11
+ it 'must throw error when wrong credentials' do
12
+ Proc.new do
13
+ @driver.backend.images(OpenStruct.new(:user => 'unknown', :password => 'wrong'))
14
+ end.must_raise Deltacloud::ExceptionHandler::AuthenticationFailure, 'Authentication Failure'
139
15
  end
140
16
 
141
- it 'should have the "description" element for each image' do
142
- authenticate
143
- get collection_url(:images)
144
- (xml_response/'images/image').each do |r|
145
- get collection_url(:images) + '/' + r[:id]
146
- (xml_response/'description').wont_be_empty
147
- end
17
+ it 'must return list of images' do
18
+ @driver.images.wont_be_empty
19
+ @driver.images.first.must_be_kind_of Image
148
20
  end
149
21
 
150
- it 'should have the "architecture" element for each image' do
151
- authenticate
152
- get collection_url(:images)
153
- (xml_response/'images/image').each do |r|
154
- get collection_url(:images) + '/' + r[:id]
155
- (xml_response/'architecture').wont_be_empty
156
- end
22
+ it 'must allow to filter images' do
23
+ @driver.images(:id => 'img1').wont_be_empty
24
+ @driver.images(:id => 'img1').must_be_kind_of Array
25
+ @driver.images(:id => 'img1').size.must_equal 1
26
+ @driver.images(:id => 'img1').first.id.must_equal 'img1'
27
+ @driver.images(:owner_id => 'mockuser').size.must_equal 1
28
+ @driver.images(:owner_id => 'mockuser').first.owner_id.must_equal 'mockuser'
29
+ @driver.images(:id => 'unknown').must_be_empty
157
30
  end
158
31
 
159
- it 'should include the list of compatible hardware_profiles for each image' do
160
- authenticate
161
- get collection_url(:images)
162
- (xml_response/'images/image').each do |r|
163
- get collection_url(:images) + '/' + r[:id]
164
- (xml_response/'hardware_profiles/hardware_profile').wont_be_empty
165
- (xml_response/'hardware_profiles/hardware_profile').each do |hwp|
166
- hwp[:href].wont_be_nil
167
- hwp[:href].must_match /^http/
168
- hwp[:id].wont_be_nil
169
- hwp[:href].must_match /\/#{hwp[:id]}$/
170
- hwp[:rel].must_equal 'hardware_profile'
171
- end
172
- end
32
+ it 'must allow to retrieve single image' do
33
+ @driver.image(:id => 'img1').wont_be_nil
34
+ @driver.image(:id => 'img1').must_be_kind_of Image
35
+ @driver.image(:id => 'img1').id.must_equal 'img1'
36
+ @driver.image(:id => 'unknown').must_be_nil
173
37
  end
174
38
 
175
- it 'should advertise the list of actions that can be executed for each image' do
176
- authenticate
177
- get collection_url(:images)
178
- (xml_response/'images/image').each do |r|
179
- get collection_url(:images) + '/' + r[:id]
180
- (xml_response/'actions/link').wont_be_empty
181
- (xml_response/'actions/link').each do |l|
182
- l[:href].wont_be_nil
183
- l[:href].must_match /^http/
184
- l[:method].wont_be_nil
185
- l[:rel].wont_be_nil
186
- end
187
- end
39
+ it 'must allow to create a new image if instance supported' do
40
+ @driver.create_image(:id => 'inst1', :name => 'img1-test', :description => 'Test1').must_be_kind_of Image
41
+ @driver.image(:id => 'img1-test').wont_be_nil
42
+ @driver.image(:id => 'img1-test').id.must_equal 'img1-test'
43
+ @driver.image(:id => 'img1-test').name.must_equal 'img1-test'
44
+ @driver.image(:id => 'img1-test').description.must_equal 'Test1'
45
+ Proc.new { @driver.create_image(:id => 'unknown-instance', :name => 'test') }.must_raise Deltacloud::ExceptionHandler::BackendError, 'CreateImageNotSupported'
46
+ @driver.image(:id => 'test').must_be_nil
188
47
  end
189
48
 
190
- it 'should give client HTML form to create new image' do
191
- authenticate
192
- header 'Accept', 'text/html'
193
- get collection_url(:images) + '/new'
194
- last_response.status.must_equal 200
49
+ it 'must allow to destroy created image' do
50
+ @driver.create_image(:id => 'inst1', :name => 'img1-test-destroy').must_be_kind_of Image
51
+ @driver.destroy_image('img1-test-destroy')
52
+ @driver.image(:id => 'img1-test-destroy').must_be_nil
195
53
  end
196
54
 
197
55
  end
@@ -1,343 +1,106 @@
1
- $:.unshift File.join(File.dirname(__FILE__), '..', '..', '..')
2
- require 'tests/drivers/mock/common'
3
-
4
- describe 'Deltacloud API instances' do
5
- include Deltacloud::Test
6
-
7
- it 'must advertise have the instances collection in API entrypoint' do
8
- get root_url
9
- (xml_response/'api/link[@rel=instances]').wont_be_empty
10
- end
11
-
12
- it 'must require authentication to access the "instance" collection' do
13
- get collection_url(:instances)
14
- last_response.status.must_equal 401
15
- end
16
-
17
- it 'should respond with HTTP_OK when accessing the :instances collection with authentication' do
18
- authenticate
19
- get collection_url(:instances)
20
- last_response.status.must_equal 200
21
- end
22
-
23
- it 'should support the JSON media type' do
24
- authenticate
25
- header 'Accept', 'application/json'
26
- get collection_url(:instances)
27
- last_response.status.must_equal 200
28
- last_response.headers['Content-Type'].must_equal 'application/json'
29
- end
30
-
31
- it 'must include the ETag in HTTP headers' do
32
- authenticate
33
- get collection_url(:instances)
34
- last_response.headers['ETag'].wont_be_nil
35
- end
36
-
37
- it 'must have the "instances" element on top level' do
38
- authenticate
39
- get collection_url(:instances)
40
- xml_response.root.name.must_equal 'instances'
41
- end
42
-
43
- it 'must have some "instance" elements inside "instances"' do
44
- authenticate
45
- get collection_url(:instances)
46
- (xml_response/'instances/instance').wont_be_empty
47
- end
48
-
49
- it 'must provide the :id attribute for each instance in collection' do
50
- authenticate
51
- get collection_url(:instances)
52
- (xml_response/'instances/instance').each do |r|
53
- r[:id].wont_be_nil
54
- end
55
- end
56
-
57
- it 'must include the :href attribute for each "instance" element in collection' do
58
- authenticate
59
- get collection_url(:instances)
60
- (xml_response/'instances/instance').each do |r|
61
- r[:href].wont_be_nil
62
- end
63
- end
64
-
65
- it 'must use the absolute URL in each :href attribute' do
66
- authenticate
67
- get collection_url(:instances)
68
- (xml_response/'instances/instance').each do |r|
69
- r[:href].must_match /^http/
70
- end
71
- end
72
-
73
- it 'must have the URL ending with the :id of the instance' do
74
- authenticate
75
- get collection_url(:instances)
76
- (xml_response/'instances/instance').each do |r|
77
- r[:href].must_match /#{r[:id]}$/
78
- end
79
- end
80
-
81
- it 'must return the list of valid parameters for the :index action' do
82
- authenticate
83
- options collection_url(:instances) + '/index'
84
- last_response.headers['Allow'].wont_be_nil
85
- end
86
-
87
- it 'must have the "name" element defined for each instance in collection' do
88
- authenticate
89
- get collection_url(:instances)
90
- (xml_response/'instances/instance').each do |r|
91
- (r/'name').wont_be_empty
92
- end
93
- end
94
-
95
- it 'must have the "state" element defined for each instance in collection' do
96
- authenticate
97
- get collection_url(:instances)
98
- (xml_response/'instances/instance').each do |r|
99
- (r/'state').wont_be_empty
100
- (r/'state').first.must_match /(RUNNING|STOPPED|PENDING)/
101
- end
102
- end
103
-
104
- it 'must return the full "instance" when following the URL in instance element' do
105
- authenticate
106
- get collection_url(:instances)
107
- (xml_response/'instances/instance').each do |r|
108
- get collection_url(:instances) + '/' + r[:id]
109
- last_response.status.must_equal 200
110
- end
111
- end
112
-
113
- it 'must have the "name" element for the instance and it should match with the one in collection' do
114
- authenticate
115
- get collection_url(:instances)
116
- (xml_response/'instances/instance').each do |r|
117
- get collection_url(:instances) + '/' + r[:id]
118
- (xml_response/'name').wont_be_empty
119
- (xml_response/'name').first.text.must_equal((r/'name').first.text)
120
- end
121
- end
122
-
123
- it 'must have the "name" element for the instance and it should match with the one in collection' do
124
- authenticate
125
- get collection_url(:instances)
126
- (xml_response/'instances/instance').each do |r|
127
- get collection_url(:instances) + '/' + r[:id]
128
- (xml_response/'state').wont_be_empty
129
- (xml_response/'state').first.text.must_equal((r/'state').first.text)
130
- end
131
- end
132
-
133
- it 'must have the "owner_id" element for the instance and it should match with the one in collection' do
134
- authenticate
135
- get collection_url(:instances)
136
- (xml_response/'instances/instance').each do |r|
137
- get collection_url(:instances) + '/' + r[:id]
138
- (xml_response/'owner_id').wont_be_empty
139
- (xml_response/'owner_id').first.text.must_equal((r/'owner_id').first.text)
140
- end
141
- end
142
-
143
- it 'must link to the realm that was used to during instance creation' do
144
- authenticate
145
- get collection_url(:instances)
146
- (xml_response/'instances/instance').each do |r|
147
- get collection_url(:instances) + '/' + r[:id]
148
- (xml_response/'realm').wont_be_empty
149
- (xml_response/'realm').size.must_equal 1
150
- (xml_response/'realm').first[:id].wont_be_nil
151
- (xml_response/'realm').first[:href].wont_be_nil
152
- (xml_response/'realm').first[:href].must_match /\/#{(xml_response/'realm').first[:id]}$/
153
- end
154
- end
155
-
156
- it 'must link to the image that was used to during instance creation' do
157
- authenticate
158
- get collection_url(:instances)
159
- (xml_response/'instances/instance').each do |r|
160
- get collection_url(:instances) + '/' + r[:id]
161
- (xml_response/'image').wont_be_empty
162
- (xml_response/'image').size.must_equal 1
163
- (xml_response/'image').first[:id].wont_be_nil
164
- (xml_response/'image').first[:href].wont_be_nil
165
- (xml_response/'image').first[:href].must_match /\/#{(xml_response/'image').first[:id]}$/
166
- end
167
- end
168
-
169
- it 'must link to the hardware_profile that was used to during instance creation' do
170
- authenticate
171
- get collection_url(:instances)
172
- (xml_response/'instances/instance').each do |r|
173
- get collection_url(:instances) + '/' + r[:id]
174
- (xml_response/'hardware_profile').wont_be_empty
175
- (xml_response/'hardware_profile').size.must_equal 1
176
- (xml_response/'hardware_profile').first[:id].wont_be_nil
177
- (xml_response/'hardware_profile').first[:href].wont_be_nil
178
- (xml_response/'hardware_profile').first[:href].must_match /\/#{(xml_response/'hardware_profile').first[:id]}$/
179
- end
180
- end
181
-
182
- it 'should advertise the public and private addresses of the instance' do
183
- authenticate
184
- get collection_url(:instances)
185
- (xml_response/'instances/instance').each do |r|
186
- get collection_url(:instances) + '/' + r[:id]
187
- (xml_response/'public_addresses').wont_be_empty
188
- (xml_response/'public_addresses').size.must_equal 1
189
- (xml_response/'public_addresses/address').each do |a|
190
- a[:type].wont_be_nil
191
- a.text.strip.wont_be_empty
192
- end
193
- (xml_response/'private_addresses').wont_be_empty
194
- (xml_response/'private_addresses').size.must_equal 1
195
- (xml_response/'private_addresses/address').each do |a|
196
- a[:type].wont_be_nil
197
- a.text.strip.wont_be_empty
198
- end
199
- end
200
- end
201
-
202
- it 'should advertise the storage volumes used by the instance' do
203
- authenticate
204
- get collection_url(:instances)
205
- (xml_response/'instances/instance').each do |r|
206
- get collection_url(:instances) + '/' + r[:id]
207
- (xml_response/'storage_volumes').wont_be_empty
208
- end
209
- end
210
-
211
- it 'should advertise the list of actions that can be executed for each instance' do
212
- authenticate
213
- get collection_url(:instances)
214
- (xml_response/'instances/instance').each do |r|
215
- get collection_url(:instances) + '/' + r[:id]
216
- (xml_response/'actions/link').wont_be_empty
217
- (xml_response/'actions/link').each do |l|
218
- l[:href].wont_be_nil
219
- l[:href].must_match /^http/
220
- l[:method].wont_be_nil
221
- l[:rel].wont_be_nil
222
- end
223
- end
224
- end
225
-
226
- it 'should allow to create and destroy new instance using the first available image without realm' do
227
- authenticate
228
- get collection_url(:images)
229
- image_id = (xml_response/'images/image').first[:id]
230
- image_id.wont_be_nil
231
- post collection_url(:instances), {
232
- :image_id => image_id
233
- }
234
- last_response.status.must_equal 201 # HTTP_CREATED
235
- last_response.headers['Location'].wont_be_nil # Location header must be set, pointing to new the instance
236
- instance_id = last_response.headers['Location'].split('/').last
237
- # Get the instance and check if ID and image is set correctly
238
- get collection_url(:instances) + '/' + instance_id
239
- last_response.status.must_equal 200 # HTTP_OK
240
- (xml_response/'instance').first[:id].must_equal instance_id
241
- (xml_response/'instance/image').first[:id].must_equal image_id
242
- # If instance is RUNNING then stop it
243
- if (xml_response/'instance/state').first.text == 'RUNNING'
244
- post collection_url(:instances) + '/' + instance_id + '/stop'
245
- last_response.status.must_equal 202 # HTTP_NO_CONTENT
246
- end
247
- # Delete created instance
248
- delete collection_url(:instances) + '/' + instance_id
249
- last_response.status.must_equal 204 # HTTP_NO_CONTENT
250
- end
251
-
252
- it 'should allow to create and destroy new instance using the first available image within first realm' do
253
- authenticate
254
- get collection_url(:images)
255
- image_id = (xml_response/'images/image').first[:id]
256
- get collection_url(:realms)
257
- realm_id = (xml_response/'realms/realm').first[:id]
258
- image_id.wont_be_nil
259
- realm_id.wont_be_nil
260
- post collection_url(:instances), {
261
- :image_id => image_id,
262
- :realm_id => realm_id,
263
- }
264
- last_response.status.must_equal 201 # HTTP_CREATED
265
- last_response.headers['Location'].wont_be_nil # Location header must be set, pointing to new the instance
266
- instance_id = last_response.headers['Location'].split('/').last
267
- # Get the instance and check if ID and image is set correctly
268
- get collection_url(:instances) + '/' + instance_id
269
- last_response.status.must_equal 200 # HTTP_OK
270
- (xml_response/'instance').first[:id].must_equal instance_id
271
- (xml_response/'instance/image').first[:id].must_equal image_id
272
- (xml_response/'instance/realm').first[:id].must_equal realm_id
273
- # If instance is RUNNING then stop it
274
- if (xml_response/'instance/state').first.text == 'RUNNING'
275
- post collection_url(:instances) + '/' + instance_id + '/stop'
276
- last_response.status.must_equal 202 # HTTP_NO_CONTENT
277
- end
278
- # Delete created instance
279
- delete collection_url(:instances) + '/' + instance_id
280
- last_response.status.must_equal 204 # HTTP_NO_CONTENT
281
- end
282
-
283
- it 'should allow to create and destroy new instance using the first available image with user defined name' do
284
- authenticate
285
- get collection_url(:images)
286
- image_id = (xml_response/'images/image').first[:id]
287
- image_id.wont_be_nil
288
- name = "i#{Time.now.to_i}"
289
- post collection_url(:instances), {
290
- :image_id => image_id,
291
- :name => name
292
- }
293
- last_response.status.must_equal 201 # HTTP_CREATED
294
- last_response.headers['Location'].wont_be_nil # Location header must be set, pointing to new the instance
295
- instance_id = last_response.headers['Location'].split('/').last
296
- # Get the instance and check if ID and image is set correctly
297
- get collection_url(:instances) + '/' + instance_id
298
- last_response.status.must_equal 200 # HTTP_OK
299
- (xml_response/'instance').first[:id].must_equal instance_id
300
- (xml_response/'instance/image').first[:id].must_equal image_id
301
- (xml_response/'instance/name').first.text.must_equal name
302
- # If instance is RUNNING then stop it
303
- if (xml_response/'instance/state').first.text == 'RUNNING'
304
- post collection_url(:instances) + '/' + instance_id + '/stop'
305
- last_response.status.must_equal 202 # HTTP_NO_CONTENT
306
- end
307
- # Delete created instance
308
- delete collection_url(:instances) + '/' + instance_id
309
- last_response.status.must_equal 204 # HTTP_NO_CONTENT
310
- end
311
-
312
- it 'should allow to create and destroy new instance using the first available image and first hardware_profile' do
313
- authenticate
314
- get collection_url(:images)
315
- image_id = (xml_response/'images/image').first[:id]
316
- get collection_url(:hardware_profiles)
317
- hwp_id = (xml_response/'hardware_profiles/hardware_profile').first[:id]
318
- image_id.wont_be_nil
319
- name = "i#{Time.now.to_i}"
320
- post collection_url(:instances), {
321
- :image_id => image_id,
322
- :hwp_id => hwp_id
323
- }
324
- last_response.status.must_equal 201 # HTTP_CREATED
325
- last_response.headers['Location'].wont_be_nil # Location header must be set, pointing to new the instance
326
- instance_id = last_response.headers['Location'].split('/').last
327
- # Get the instance and check if ID and image is set correctly
328
- get collection_url(:instances) + '/' + instance_id
329
- last_response.status.must_equal 200 # HTTP_OK
330
- (xml_response/'instance').first[:id].must_equal instance_id
331
- (xml_response/'instance/image').first[:id].must_equal image_id
332
- (xml_response/'instance/hardware_profile').first[:id].must_equal hwp_id
333
- # If instance is RUNNING then stop it
334
- if (xml_response/'instance/state').first.text == 'RUNNING'
335
- post collection_url(:instances) + '/' + instance_id + '/stop'
336
- last_response.status.must_equal 202 # HTTP_NO_CONTENT
337
- end
338
- # Delete created instance
339
- delete collection_url(:instances) + '/' + instance_id
340
- last_response.status.must_equal 204 # HTTP_NO_CONTENT
1
+ require 'minitest/autorun'
2
+
3
+ require_relative File.join('..', '..', '..', 'lib', 'deltacloud', 'api.rb')
4
+
5
+ describe 'MockDriver Instances' do
6
+
7
+ before do
8
+ @driver = Deltacloud::new(:mock, :user => 'mockuser', :password => 'mockpassword')
9
+ end
10
+
11
+ it 'must throw error when wrong credentials' do
12
+ Proc.new do
13
+ @driver.backend.instances(OpenStruct.new(:user => 'unknown', :password => 'wrong'))
14
+ end.must_raise Deltacloud::ExceptionHandler::AuthenticationFailure, 'Authentication Failure'
15
+ end
16
+
17
+ it 'must return list of instances' do
18
+ @driver.instances.wont_be_empty
19
+ @driver.instances.first.must_be_kind_of Instance
20
+ end
21
+
22
+ it 'must allow to filter instances' do
23
+ @driver.instances(:id => 'inst1').wont_be_empty
24
+ @driver.instances(:id => 'inst1').must_be_kind_of Array
25
+ @driver.instances(:id => 'inst1').size.must_equal 1
26
+ @driver.instances(:id => 'inst1').first.id.must_equal 'inst1'
27
+ @driver.instances(:owner_id => 'mockuser').size.must_equal 2
28
+ @driver.instances(:owner_id => 'mockuser').first.owner_id.must_equal 'mockuser'
29
+ @driver.instances(:id => 'unknown').must_be_empty
30
+ end
31
+
32
+ it 'must allow to retrieve single instance' do
33
+ @driver.instance(:id => 'inst1').wont_be_nil
34
+ @driver.instance(:id => 'inst1').must_be_kind_of Instance
35
+ @driver.instance(:id => 'inst1').id.must_equal 'inst1'
36
+ @driver.instance(:id => 'unknown').must_be_nil
37
+ end
38
+
39
+ it 'must allow to create a new instance if instance supported' do
40
+ instance = @driver.create_instance('img1', :name => 'inst1-test', :realm_id => 'us', :hwp_id => 'm1-small')
41
+ instance.must_be_kind_of Instance
42
+ @driver.instance(:id => instance.id).wont_be_nil
43
+ @driver.instance(:id => instance.id).id.must_equal instance.id
44
+ @driver.instance(:id => instance.id).name.must_equal 'inst1-test'
45
+ @driver.instance(:id => instance.id).instance_profile.name.must_equal 'm1-small'
46
+ @driver.instance(:id => instance.id).realm_id.must_equal 'us'
47
+ @driver.instance(:id => instance.id).owner_id.must_equal 'mockuser'
48
+ @driver.instance(:id => instance.id).state.must_equal 'RUNNING'
49
+ @driver.instance(:id => instance.id).public_addresses.wont_be_empty
50
+ @driver.instance(:id => instance.id).actions.must_include :reboot
51
+ @driver.instance(:id => instance.id).actions.must_include :stop
52
+ @driver.destroy_instance(instance.id)
53
+ @driver.instance(:id => instance.id).must_be_nil
54
+ end
55
+
56
+ it 'must allow to destroy created instance' do
57
+ instance = @driver.create_instance('img1', :name => 'inst1-test-destroy')
58
+ instance.must_be_kind_of Instance
59
+ @driver.destroy_instance(instance.id)
60
+ @driver.instance(:id => instance.id).must_be_nil
61
+ end
62
+
63
+ it 'must allow to stop instance in running state' do
64
+ instance = @driver.create_instance('img1', :name => 'inst1-test-destroy')
65
+ instance.must_be_kind_of Instance
66
+ instance.state.must_equal 'RUNNING'
67
+ @driver.stop_instance(instance.id)
68
+ @driver.instance(:id => instance.id).state.must_equal 'STOPPED'
69
+ @driver.destroy_instance(instance.id)
70
+ @driver.instance(:id => instance.id).must_be_nil
71
+ end
72
+
73
+ it 'must allow to start instance in stopped state' do
74
+ instance = @driver.create_instance('img1', :name => 'inst1-test-destroy')
75
+ instance.must_be_kind_of Instance
76
+ instance.state.must_equal 'RUNNING'
77
+ @driver.stop_instance(instance.id)
78
+ @driver.instance(:id => instance.id).state.must_equal 'STOPPED'
79
+ @driver.start_instance(instance.id)
80
+ @driver.instance(:id => instance.id).state.must_equal 'RUNNING'
81
+ @driver.destroy_instance(instance.id)
82
+ @driver.instance(:id => instance.id).must_be_nil
83
+ end
84
+
85
+ it 'must allow to reboot instance in running state' do
86
+ instance = @driver.create_instance('img1', :name => 'inst1-test-destroy')
87
+ instance.must_be_kind_of Instance
88
+ instance.state.must_equal 'RUNNING'
89
+ @driver.reboot_instance(instance.id)
90
+ @driver.instance(:id => instance.id).state.must_equal 'RUNNING'
91
+ @driver.stop_instance(instance.id)
92
+ @driver.instance(:id => instance.id).state.must_equal 'STOPPED'
93
+ @driver.reboot_instance(instance.id)
94
+ @driver.instance(:id => instance.id).state.must_equal 'RUNNING'
95
+ @driver.destroy_instance(instance.id)
96
+ @driver.instance(:id => instance.id).must_be_nil
97
+ end
98
+
99
+ it 'must support run_on_instance' do
100
+ run_cmd = @driver.run_on_instance(:cmd => 'uname', :port => '22', :private_key => '123', :ip => '127.0.0.1')
101
+ run_cmd.body.must_equal 'This is where the output would appear if this were not a mock provider'
102
+ run_cmd.ssh.must_be_kind_of Deltacloud::Drivers::Mock::MockDriver::Mock_ssh
103
+ run_cmd.ssh.command.must_equal 'uname'
341
104
  end
342
105
 
343
106
  end