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,149 @@
1
+ require 'rubygems'
2
+ require 'require_relative' if RUBY_VERSION < '1.9'
3
+
4
+ require_relative 'common.rb'
5
+
6
+ describe Deltacloud::API do
7
+
8
+ before do
9
+ def app; Deltacloud::API; end
10
+ end
11
+
12
+ it 'has the config set property' do
13
+ Deltacloud::config[:deltacloud].must_be_kind_of Deltacloud::Server
14
+ root_url.must_equal Deltacloud[:deltacloud].root_url
15
+ end
16
+
17
+ it 'must provide the root_url entrypoint' do
18
+ get root_url
19
+ status.must_equal 200
20
+ xml.root.name.must_equal 'api'
21
+ end
22
+
23
+ it 'must advertise current API version in response headers' do
24
+ get root_url
25
+ headers['Server'].must_match(/Apache-Deltacloud\/(\d+).(\d+).(\d+)/)
26
+ xml.root.name.must_equal 'api'
27
+ end
28
+
29
+ it 'must advertise current API driver in response headers' do
30
+ get root_url
31
+ headers['X-Deltacloud-Driver'].must_equal Deltacloud[:deltacloud].default_driver.to_s
32
+ xml.root.name.must_equal 'api'
33
+ end
34
+
35
+ it 'must force authentication when :force_auth param set' do
36
+ get root_url, :force_auth => '1'
37
+ status.must_equal 401
38
+ authorize 'mockuser', 'mockpassword'
39
+ get root_url, :force_auth => '1'
40
+ status.must_equal 200
41
+ end
42
+
43
+ it 'must return list of collections on OPTIONS' do
44
+ options root_url
45
+ headers['Allow'].wont_be_nil
46
+ headers['Allow'].split(',').must_include 'Sinatra::Rabbit::DriversCollection'
47
+ end
48
+
49
+ it 'must support setting driver and provider using POST' do
50
+ post root_url, { :driver => :ec2 }
51
+ headers['Location'].wont_be_nil
52
+ headers['Location'].must_match(/\/api;driver=ec2/)
53
+ post root_url, { :provider => :test_provider }
54
+ headers['Location'].wont_be_nil
55
+ headers['Location'].must_match(/\/api;provider=test_provider/)
56
+ end
57
+
58
+ it 'must support matrix parameters for changing API driver' do
59
+ get root_url + ';driver=ec2'
60
+ headers['X-Deltacloud-Driver'].must_equal 'ec2'
61
+ xml.root.name.must_equal 'api'
62
+ end
63
+
64
+ it 'must support matrix parameters for changing API provider' do
65
+ get root_url + ';provider=someprovider'
66
+ headers['X-Deltacloud-Provider'].must_equal 'someprovider'
67
+ xml.root.name.must_equal 'api'
68
+ end
69
+
70
+ it 'must support matrix parameters for changing both API provider and driver' do
71
+ get root_url + ';provider=someprovider;driver=ec2'
72
+ headers['X-Deltacloud-Provider'].must_equal 'someprovider'
73
+ headers['X-Deltacloud-Driver'].must_equal 'ec2'
74
+ xml.root.name.must_equal 'api'
75
+ end
76
+
77
+ it 'must change driver back to default when no matrix param set' do
78
+ get root_url + ';driver=ec2'
79
+ headers['X-Deltacloud-Driver'].must_equal 'ec2'
80
+ get root_url
81
+ headers['X-Deltacloud-Driver'].must_equal Deltacloud[:deltacloud].default_driver.to_s
82
+ xml.root.name.must_equal 'api'
83
+ end
84
+
85
+ it 'must change provider back to default when no matrix param set' do
86
+ get root_url + ';provider=someprovider'
87
+ headers['X-Deltacloud-Provider'].must_equal 'someprovider'
88
+ get root_url
89
+ headers['X-Deltacloud-Provider'].must_be_nil
90
+ xml.root.name.must_equal 'api'
91
+ end
92
+
93
+ it 'must support matrix params when they are part of URL' do
94
+ get root_url + ';driver=ec2/hardware_profiles'
95
+ headers['X-Deltacloud-Driver'].must_equal 'ec2'
96
+ status.must_equal 200
97
+ xml.root.name.must_equal 'hardware_profiles'
98
+ end
99
+
100
+ it 'must switch driver using X-Deltacloud-Driver HTTP header in request' do
101
+ header 'X-Deltacloud-Driver', 'ec2'
102
+ get root_url
103
+ headers['X-Deltacloud-Driver'].must_equal 'ec2'
104
+ header 'X-Deltacloud-Driver', 'mock'
105
+ get root_url
106
+ headers['X-Deltacloud-Driver'].must_equal 'mock'
107
+ end
108
+
109
+ it 'must switch provider using X-Deltacloud-Provider HTTP header in request' do
110
+ header 'X-Deltacloud-Provider', 'someprovider'
111
+ get root_url
112
+ headers['X-Deltacloud-Provider'].must_equal 'someprovider'
113
+ header 'X-Deltacloud-Provider', nil
114
+ get root_url
115
+ headers['X-Deltacloud-Provider'].must_be_nil
116
+ end
117
+
118
+ it 'must support media type negotiation for JSON format' do
119
+ header 'Accept', 'application/json'
120
+ get root_url
121
+ status.must_equal 200
122
+ headers['Content-Type'].must_equal 'application/json'
123
+ JSON::parse(response_body).must_be_kind_of Hash
124
+ JSON::parse(response_body)['api'].must_be_kind_of Hash
125
+ end
126
+
127
+ it 'must support media type negotiation for HTML format' do
128
+ header 'Accept', 'text/html'
129
+ get root_url
130
+ status.must_equal 200
131
+ headers['Content-Type'].must_equal 'text/html'
132
+ response_body.must_match(/^<\!DOCTYPE html>/)
133
+ end
134
+
135
+ it 'must support media type negotiation for XML format' do
136
+ header 'Accept', 'application/xml'
137
+ get root_url
138
+ status.must_equal 200
139
+ headers['Content-Type'].must_equal 'application/xml'
140
+ xml.root.name.must_equal 'api'
141
+ end
142
+
143
+ it 'must return proper error when unknown media type requested' do
144
+ header 'Accept', 'application/unknown'
145
+ get root_url
146
+ status.must_equal 406
147
+ end
148
+
149
+ end
File without changes
File without changes
@@ -0,0 +1,6 @@
1
+ require_relative './common'
2
+ require_relative '../../lib/deltacloud/api'
3
+
4
+ require 'pp'
5
+
6
+
File without changes
File without changes
@@ -0,0 +1,23 @@
1
+ ENV['API_DRIVER'] = 'ec2'
2
+ ENV['TESTS_API_USERNAME'] = 'AKIAIZ63KHGXIWDMBY6Q'
3
+ ENV['TESTS_API_PASSWORD'] = 'zUfBCbML2S6pXKS44eEEXw0Cf/G8z9hMSxP2hcLV'
4
+ ENV['RACK_ENV'] = 'test'
5
+
6
+ $:.unshift File.join(File.dirname(__FILE__), '..', '..', '..')
7
+ require 'tests/minitest_common'
8
+
9
+ require 'vcr'
10
+ require 'timecop'
11
+
12
+ VCR.configure do |c|
13
+ c.cassette_library_dir = File.join(File.dirname(__FILE__), 'fixtures')
14
+ c.hook_into :webmock
15
+ c.default_cassette_options = { :record => :new_episodes }
16
+ #c.default_cassette_options = { :record => :none }
17
+ end
18
+
19
+ # Let's set time that timecop will use to freeze
20
+ # Time.now will then return this time instead of 'real' system time
21
+
22
+ FREEZED_TIME = DateTime.parse("2012-05-31 12:58:00 +0200")
23
+ Timecop.freeze(FREEZED_TIME)
@@ -0,0 +1,230 @@
1
+ $:.unshift File.join(File.dirname(__FILE__), '..', '..', '..')
2
+ require 'tests/drivers/ec2/common'
3
+
4
+ describe 'Deltacloud API Images' do
5
+ before do
6
+ Timecop.freeze(FREEZED_TIME)
7
+ VCR.insert_cassette __name__
8
+ end
9
+
10
+ after do
11
+ VCR.eject_cassette
12
+ end
13
+
14
+ include Deltacloud::Test
15
+
16
+ it 'must advertise have the images collection in API entrypoint' do
17
+ get root_url
18
+ (xml_response/'api/link[@rel=images]').wont_be_empty
19
+ end
20
+
21
+ it 'must require authentication to access the "image" collection' do
22
+ get collection_url(:images)
23
+ last_response.status.must_equal 401
24
+ end
25
+
26
+ it 'should respond with HTTP_OK when accessing the :images collection with authentication' do
27
+ authenticate
28
+ get collection_url(:images)
29
+ last_response.status.must_equal 200
30
+ end
31
+
32
+ it 'should support the JSON media type' do
33
+ authenticate
34
+ header 'Accept', 'application/json'
35
+ get collection_url(:images)
36
+ last_response.status.must_equal 200
37
+ last_response.headers['Content-Type'].must_equal 'application/json'
38
+ end
39
+
40
+ it 'must include the ETag in HTTP headers' do
41
+ authenticate
42
+ get collection_url(:images)
43
+ last_response.headers['ETag'].wont_be_nil
44
+ end
45
+
46
+ it 'must have the "images" element on top level' do
47
+ authenticate
48
+ get collection_url(:images)
49
+ xml_response.root.name.must_equal 'images'
50
+ end
51
+
52
+ it 'must have some "image" elements inside "images"' do
53
+ authenticate
54
+ get collection_url(:images)
55
+ (xml_response/'images/image').wont_be_empty
56
+ end
57
+
58
+ it 'must provide the :id attribute for each image in collection' do
59
+ authenticate
60
+ get collection_url(:images)
61
+ (xml_response/'images/image').each do |r|
62
+ r[:id].wont_be_nil
63
+ end
64
+ end
65
+
66
+ it 'must include the :href attribute for each "image" element in collection' do
67
+ authenticate
68
+ get collection_url(:images)
69
+ (xml_response/'images/image').each do |r|
70
+ r[:href].wont_be_nil
71
+ end
72
+ end
73
+
74
+ it 'must use the absolute URL in each :href attribute' do
75
+ authenticate
76
+ get collection_url(:images)
77
+ (xml_response/'images/image').each do |r|
78
+ r[:href].must_match /^http/
79
+ end
80
+ end
81
+
82
+ it 'must have the URL ending with the :id of the image' do
83
+ authenticate
84
+ get collection_url(:images)
85
+ (xml_response/'images/image').each do |r|
86
+ r[:href].must_match /#{r[:id]}$/
87
+ end
88
+ end
89
+
90
+ it 'must return the list of valid parameters for the :index action' do
91
+ authenticate
92
+ options collection_url(:images) + '/index'
93
+ last_response.headers['Allow'].wont_be_nil
94
+ end
95
+
96
+ it 'must have the "name" element defined for each image in collection' do
97
+ authenticate
98
+ get collection_url(:images)
99
+ (xml_response/'images/image').each do |r|
100
+ (r/'name').wont_be_empty
101
+ end
102
+ end
103
+
104
+ it 'must have the "state" element defined for each image in collection' do
105
+ authenticate
106
+ get collection_url(:images)
107
+ (xml_response/'images/image').each do |r|
108
+ (r/'state').wont_be_empty
109
+ end
110
+ end
111
+
112
+ it 'must return the full "image" when following the URL in image element' do
113
+ authenticate
114
+ get collection_url(:images)
115
+ (xml_response/'images/image').wont_be_empty
116
+ (xml_response/'images/image')[0..10].each do |r|
117
+ VCR.use_cassette "#{__name__}_image_#{r[:id]}" do
118
+ get collection_url(:images) + '/' + r[:id]
119
+ end
120
+ last_response.status.must_equal 200
121
+ end
122
+ end
123
+
124
+ it 'must have the "name" element for the image and it should match with the one in collection' do
125
+ authenticate
126
+ get collection_url(:images)
127
+ (xml_response/'images/image').wont_be_empty
128
+ (xml_response/'images/image')[0..10].each do |r|
129
+ VCR.use_cassette "#{__name__}_image_#{r[:id]}" do
130
+ get collection_url(:images) + '/' + r[:id]
131
+ end
132
+ (xml_response/'name').wont_be_empty
133
+ (xml_response/'name').first.text.must_equal((r/'name').first.text)
134
+ end
135
+ end
136
+
137
+ it 'must have the "name" element for the image and it should match with the one in collection' do
138
+ authenticate
139
+ get collection_url(:images)
140
+ (xml_response/'images/image').wont_be_empty
141
+ (xml_response/'images/image')[0..10].each do |r|
142
+ VCR.use_cassette "#{__name__}_image_#{r[:id]}" do
143
+ get collection_url(:images) + '/' + r[:id]
144
+ end
145
+ (xml_response/'state').wont_be_empty
146
+ (xml_response/'state').first.text.must_equal((r/'state').first.text)
147
+ end
148
+ end
149
+
150
+ it 'should have the "owner_id" element for each image' do
151
+ authenticate
152
+ get collection_url(:images)
153
+ (xml_response/'images/image').wont_be_empty
154
+ (xml_response/'images/image')[0..10].each do |r|
155
+ VCR.use_cassette "#{__name__}_image_#{r[:id]}" do
156
+ get collection_url(:images) + '/' + r[:id]
157
+ end
158
+ (xml_response/'owner_id').wont_be_empty
159
+ end
160
+ end
161
+
162
+ it 'should have the "description" element for each image' do
163
+ authenticate
164
+ get collection_url(:images)
165
+ (xml_response/'images/image').wont_be_empty
166
+ (xml_response/'images/image')[0..10].each do |r|
167
+ VCR.use_cassette "#{__name__}_image_#{r[:id]}" do
168
+ get collection_url(:images) + '/' + r[:id]
169
+ end
170
+ (xml_response/'description').wont_be_empty
171
+ end
172
+ end
173
+
174
+ it 'should have the "architecture" element for each image' do
175
+ authenticate
176
+ get collection_url(:images)
177
+ (xml_response/'images/image').wont_be_empty
178
+ (xml_response/'images/image')[0..10].each do |r|
179
+ VCR.use_cassette "#{__name__}_image_#{r[:id]}" do
180
+ get collection_url(:images) + '/' + r[:id]
181
+ end
182
+ (xml_response/'architecture').wont_be_empty
183
+ end
184
+ end
185
+
186
+ it 'should include the list of compatible hardware_profiles for each image' do
187
+ authenticate
188
+ get collection_url(:images)
189
+ (xml_response/'images/image').wont_be_empty
190
+ (xml_response/'images/image')[0..10].each do |r|
191
+ VCR.use_cassette "#{__name__}_image_#{r[:id]}" do
192
+ get collection_url(:images) + '/' + r[:id]
193
+ end
194
+ (xml_response/'hardware_profiles/hardware_profile').wont_be_empty
195
+ (xml_response/'hardware_profiles/hardware_profile').each do |hwp|
196
+ hwp[:href].wont_be_nil
197
+ hwp[:href].must_match /^http/
198
+ hwp[:id].wont_be_nil
199
+ hwp[:href].must_match /\/#{hwp[:id]}$/
200
+ hwp[:rel].must_equal 'hardware_profile'
201
+ end
202
+ end
203
+ end
204
+
205
+ it 'should advertise the list of actions that can be executed for each image' do
206
+ authenticate
207
+ get collection_url(:images)
208
+ (xml_response/'images/image').wont_be_empty
209
+ (xml_response/'images/image')[0..10].each do |r|
210
+ VCR.use_cassette "#{__name__}_image_#{r[:id]}" do
211
+ get collection_url(:images) + '/' + r[:id]
212
+ end
213
+ (xml_response/'actions/link').wont_be_empty
214
+ (xml_response/'actions/link').each do |l|
215
+ l[:href].wont_be_nil
216
+ l[:href].must_match /^http/
217
+ l[:method].wont_be_nil
218
+ l[:rel].wont_be_nil
219
+ end
220
+ end
221
+ end
222
+
223
+ it 'should give client HTML form to create new image' do
224
+ authenticate
225
+ header 'Accept', 'text/html'
226
+ get collection_url(:images) + '/new'
227
+ last_response.status.must_equal 200
228
+ end
229
+
230
+ end
@@ -0,0 +1,181 @@
1
+ $:.unshift File.join(File.dirname(__FILE__), '..', '..', '..')
2
+ require 'tests/drivers/ec2/common'
3
+
4
+ describe 'Deltacloud API Keys' do
5
+
6
+ before do
7
+ Timecop.freeze(FREEZED_TIME)
8
+ VCR.insert_cassette __name__
9
+ end
10
+
11
+ after do
12
+ VCR.eject_cassette
13
+ end
14
+
15
+ include Deltacloud::Test
16
+
17
+ it 'must advertise have the keys collection in API entrypoint' do
18
+ get root_url
19
+ (xml_response/'api/link[@rel=keys]').wont_be_empty
20
+ end
21
+
22
+ it 'must require authentication to access the "key" collection' do
23
+ get collection_url(:keys)
24
+ last_response.status.must_equal 401
25
+ end
26
+
27
+ it 'should respond with HTTP_OK when accessing the :keys collection with authentication' do
28
+ authenticate
29
+ get collection_url(:keys)
30
+ last_response.status.must_equal 200
31
+ end
32
+
33
+ it 'should support the JSON media type' do
34
+ authenticate
35
+ header 'Accept', 'application/json'
36
+ get collection_url(:keys)
37
+ last_response.status.must_equal 200
38
+ last_response.headers['Content-Type'].must_equal 'application/json'
39
+ end
40
+
41
+ it 'must include the ETag in HTTP headers' do
42
+ authenticate
43
+ get collection_url(:keys)
44
+ last_response.headers['ETag'].wont_be_nil
45
+ end
46
+
47
+ it 'must have the "keys" element on top level' do
48
+ authenticate
49
+ get collection_url(:keys)
50
+ xml_response.root.name.must_equal 'keys'
51
+ end
52
+
53
+ it 'must have some "key" elements inside "keys"' do
54
+ authenticate
55
+ get collection_url(:keys)
56
+ (xml_response/'keys/key').wont_be_empty
57
+ end
58
+
59
+ it 'must tell the kind of "key" elements inside "keys"' do
60
+ authenticate
61
+ get collection_url(:keys)
62
+ (xml_response/'keys/key').each do |k|
63
+ k[:type].must_match /(key|password)/
64
+ end
65
+ end
66
+
67
+ it 'must provide the :id attribute for each key in collection' do
68
+ authenticate
69
+ get collection_url(:keys)
70
+ (xml_response/'keys/key').each do |r|
71
+ r[:id].wont_be_nil
72
+ end
73
+ end
74
+
75
+ it 'must include the :href attribute for each "key" element in collection' do
76
+ authenticate
77
+ get collection_url(:keys)
78
+ (xml_response/'keys/key').each do |r|
79
+ r[:href].wont_be_nil
80
+ end
81
+ end
82
+
83
+ it 'must use the absolute URL in each :href attribute' do
84
+ authenticate
85
+ get collection_url(:keys)
86
+ (xml_response/'keys/key').each do |r|
87
+ r[:href].must_match /^http/
88
+ end
89
+ end
90
+
91
+ it 'must have the URL ending with the :id of the key' do
92
+ authenticate
93
+ get collection_url(:keys)
94
+ (xml_response/'keys/key').each do |r|
95
+ r[:href].must_match /#{r[:id]}$/
96
+ end
97
+ end
98
+
99
+ it 'must return the list of valid parameters for the :index action' do
100
+ authenticate
101
+ options collection_url(:keys) + '/index'
102
+ last_response.headers['Allow'].wont_be_nil
103
+ end
104
+
105
+ it 'must have the "name" element defined for each key in collection' do
106
+ authenticate
107
+ get collection_url(:keys)
108
+ (xml_response/'keys/key').each do |r|
109
+ (r/'name').wont_be_empty
110
+ end
111
+ end
112
+
113
+
114
+ it 'must return the full "key" when following the URL in key element' do
115
+ authenticate
116
+ get collection_url(:keys)
117
+ (xml_response/'keys/key').each do |r|
118
+ get collection_url(:keys) + '/' + r[:id]
119
+ last_response.status.must_equal 200
120
+ end
121
+ end
122
+
123
+ it 'must have the "name" element for the key and it should match with the one in collection' do
124
+ authenticate
125
+ get collection_url(:keys)
126
+ (xml_response/'keys/key').each do |r|
127
+ VCR.use_cassette "#{__name__}_key_#{r[:id]}" do
128
+ get collection_url(:keys) + '/' + r[:id]
129
+ end
130
+ (xml_response/'name').wont_be_empty
131
+ (xml_response/'name').first.text.must_equal((r/'name').first.text)
132
+ end
133
+ end
134
+
135
+ it 'must have the "name" element for the key and it should match with the one in collection' do
136
+ authenticate
137
+ get collection_url(:keys)
138
+ (xml_response/'keys/key').each do |r|
139
+ VCR.use_cassette "#{__name__}_key_#{r[:id]}" do
140
+ get collection_url(:keys) + '/' + r[:id]
141
+ end
142
+ (xml_response/'state').wont_be_empty
143
+ (xml_response/'state').first.text.must_equal((r/'state').first.text)
144
+ end
145
+ end
146
+
147
+ it 'should advertise the list of actions that can be executed for each key' do
148
+ authenticate
149
+ get collection_url(:keys)
150
+ (xml_response/'keys/key').each do |r|
151
+ VCR.use_cassette "#{__name__}_key_#{r[:id]}" do
152
+ get collection_url(:keys) + '/' + r[:id]
153
+ end
154
+ (xml_response/'actions/link').wont_be_empty
155
+ (xml_response/'actions/link').each do |l|
156
+ l[:href].wont_be_nil
157
+ l[:href].must_match /^http/
158
+ l[:method].wont_be_nil
159
+ l[:rel].wont_be_nil
160
+ end
161
+ end
162
+ end
163
+
164
+ it 'should allow to create a new key and then remove it' do
165
+ authenticate
166
+ key_name = Time.now.to_i.to_s
167
+ post collection_url(:keys), {
168
+ :name => 'test_key_'+key_name
169
+ }
170
+ last_response.status.must_equal 201 # HTTP_CREATED
171
+ VCR.use_cassette "#{__name__}_key_#{key_name}" do
172
+ get collection_url(:keys) + '/' + 'test_key_'+key_name
173
+ end
174
+ last_response.status.must_equal 200 # HTTP_OK
175
+ VCR.use_cassette "#{__name__}_delete_key_#{key_name}" do
176
+ delete collection_url(:keys) + '/' + 'test_key_'+key_name
177
+ end
178
+ last_response.status.must_equal 204 # HTTP_NO_CONTENT
179
+ end
180
+
181
+ end