deltacloud-core 0.5.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (294) hide show
  1. data/NOTICE +1 -1
  2. data/Rakefile +63 -21
  3. data/bin/deltacloudd +10 -6
  4. data/config.ru +62 -6
  5. data/config/drivers/ec2.yaml +8 -0
  6. data/config/drivers/fgcp.yaml +13 -0
  7. data/deltacloud-core.gemspec +10 -2
  8. data/lib/cimi/collections.rb +58 -0
  9. data/lib/cimi/collections/address_templates.rb +49 -0
  10. data/lib/cimi/collections/addresses.rb +74 -0
  11. data/lib/cimi/collections/cloud_entry_point.rb +37 -0
  12. data/lib/{deltacloud/helpers/conversion_helper.rb → cimi/collections/entity_metadata.rb} +24 -16
  13. data/lib/cimi/collections/machine_admins.rb +74 -0
  14. data/lib/cimi/collections/machine_configurations.rb +49 -0
  15. data/lib/cimi/collections/machine_images.rb +50 -0
  16. data/lib/cimi/collections/machines.rb +157 -0
  17. data/lib/cimi/collections/network_configurations.rb +47 -0
  18. data/lib/cimi/collections/network_templates.rb +48 -0
  19. data/lib/cimi/collections/networks.rb +125 -0
  20. data/lib/cimi/collections/routing_group_templates.rb +47 -0
  21. data/lib/cimi/collections/routing_groups.rb +48 -0
  22. data/lib/cimi/collections/volume_configurations.rb +48 -0
  23. data/lib/cimi/collections/volume_images.rb +50 -0
  24. data/lib/cimi/collections/volumes.rb +80 -0
  25. data/lib/cimi/collections/vsp_configurations.rb +48 -0
  26. data/lib/cimi/collections/vsp_templates.rb +50 -0
  27. data/lib/cimi/collections/vsps.rb +108 -0
  28. data/lib/cimi/dependencies.rb +1 -0
  29. data/lib/cimi/helpers.rb +116 -0
  30. data/lib/cimi/helpers/cimi_helper.rb +6 -2
  31. data/lib/cimi/models.rb +72 -0
  32. data/lib/cimi/{model → models}/action.rb +1 -1
  33. data/lib/cimi/models/address.rb +72 -0
  34. data/lib/cimi/models/address_collection.rb +34 -0
  35. data/lib/cimi/models/address_template.rb +54 -0
  36. data/lib/cimi/models/address_template_collection.rb +34 -0
  37. data/lib/cimi/{model → models}/base.rb +2 -2
  38. data/lib/cimi/{model → models}/cloud_entry_point.rb +3 -5
  39. data/lib/cimi/{model → models}/entity_metadata.rb +7 -6
  40. data/lib/cimi/{model → models}/entity_metadata_collection.rb +2 -2
  41. data/lib/cimi/{model → models}/errors.rb +8 -0
  42. data/lib/cimi/{model → models}/machine.rb +10 -10
  43. data/lib/cimi/{model → models}/machine_admin.rb +1 -1
  44. data/lib/cimi/{model → models}/machine_admin_collection.rb +2 -2
  45. data/lib/cimi/{model → models}/machine_collection.rb +2 -2
  46. data/lib/cimi/{model → models}/machine_configuration.rb +9 -6
  47. data/lib/cimi/{model → models}/machine_configuration_collection.rb +2 -2
  48. data/lib/cimi/{model → models}/machine_image.rb +1 -1
  49. data/lib/cimi/{model → models}/machine_image_collection.rb +2 -2
  50. data/lib/cimi/{model → models}/machine_template.rb +0 -0
  51. data/lib/cimi/{model → models}/machine_template_collection.rb +2 -2
  52. data/lib/cimi/models/network.rb +109 -0
  53. data/lib/cimi/{model → models}/network_collection.rb +2 -2
  54. data/lib/cimi/{model → models}/network_configuration.rb +3 -4
  55. data/lib/cimi/{model → models}/network_configuration_collection.rb +2 -2
  56. data/lib/cimi/models/network_template.rb +36 -0
  57. data/lib/cimi/models/network_template_collection.rb +35 -0
  58. data/lib/cimi/models/routing_group.rb +34 -0
  59. data/lib/cimi/models/routing_group_collection.rb +34 -0
  60. data/lib/cimi/models/routing_group_template.rb +34 -0
  61. data/lib/cimi/models/routing_group_template_collection.rb +35 -0
  62. data/lib/cimi/{model → models}/schema.rb +0 -0
  63. data/lib/cimi/{model → models}/volume.rb +4 -4
  64. data/lib/cimi/{model → models}/volume_collection.rb +2 -2
  65. data/lib/cimi/{model → models}/volume_configuration.rb +1 -1
  66. data/lib/cimi/{model → models}/volume_configuration_collection.rb +2 -2
  67. data/lib/cimi/{model → models}/volume_image.rb +1 -1
  68. data/lib/cimi/{model → models}/volume_image_collection.rb +2 -2
  69. data/lib/cimi/{model → models}/volume_template.rb +0 -0
  70. data/lib/cimi/{model → models}/volume_template_collection.rb +2 -2
  71. data/lib/cimi/models/vsp.rb +102 -0
  72. data/lib/cimi/models/vsp_collection.rb +34 -0
  73. data/lib/cimi/models/vsp_configuration.rb +40 -0
  74. data/lib/cimi/models/vsp_configuration_collection.rb +34 -0
  75. data/lib/cimi/models/vsp_template.rb +34 -0
  76. data/lib/cimi/models/vsp_template_collection.rb +34 -0
  77. data/lib/cimi/server.rb +27 -549
  78. data/lib/deltacloud/api.rb +79 -0
  79. data/lib/deltacloud/collections.rb +54 -0
  80. data/lib/deltacloud/collections/addresses.rb +91 -0
  81. data/lib/deltacloud/collections/buckets.rb +273 -0
  82. data/lib/deltacloud/collections/drivers.rb +51 -0
  83. data/lib/deltacloud/collections/firewalls.rb +116 -0
  84. data/lib/deltacloud/collections/hardware_profiles.rb +29 -0
  85. data/lib/deltacloud/collections/images.rb +73 -0
  86. data/lib/deltacloud/collections/instance_states.rb +59 -0
  87. data/lib/deltacloud/collections/instances.rb +113 -0
  88. data/lib/deltacloud/collections/keys.rb +61 -0
  89. data/lib/deltacloud/collections/load_balancers.rb +102 -0
  90. data/lib/deltacloud/collections/metrics.rb +28 -0
  91. data/lib/deltacloud/collections/realms.rb +28 -0
  92. data/lib/deltacloud/collections/storage_snapshots.rb +51 -0
  93. data/lib/deltacloud/collections/storage_volumes.rb +99 -0
  94. data/lib/deltacloud/core_ext.rb +14 -6
  95. data/lib/deltacloud/core_ext/string.rb +17 -5
  96. data/lib/deltacloud/drivers.rb +6 -42
  97. data/lib/deltacloud/drivers/azure/azure_driver.rb +0 -4
  98. data/lib/deltacloud/{base_driver → drivers}/base_driver.rb +56 -18
  99. data/lib/deltacloud/drivers/condor/condor_driver.rb +1 -8
  100. data/lib/deltacloud/drivers/ec2/ec2_driver.rb +142 -33
  101. data/lib/deltacloud/drivers/eucalyptus/eucalyptus_driver.rb +2 -6
  102. data/lib/deltacloud/{base_driver → drivers}/exceptions.rb +25 -2
  103. data/lib/deltacloud/drivers/features.rb +154 -0
  104. data/lib/deltacloud/drivers/fgcp/fgcp_client.rb +387 -0
  105. data/lib/deltacloud/drivers/fgcp/fgcp_driver.rb +1435 -0
  106. data/lib/deltacloud/drivers/gogrid/gogrid_driver.rb +8 -11
  107. data/lib/deltacloud/drivers/google/google_driver.rb +2 -5
  108. data/lib/deltacloud/drivers/mock/data/keys/test-key.yml +28 -0
  109. data/lib/deltacloud/drivers/mock/mock_client.rb +2 -2
  110. data/lib/deltacloud/drivers/mock/mock_driver.rb +58 -40
  111. data/lib/deltacloud/drivers/mock/mock_driver_cimi_methods.rb +145 -0
  112. data/lib/deltacloud/drivers/opennebula/cloud_client.rb +107 -73
  113. data/lib/deltacloud/drivers/opennebula/occi_client.rb +285 -145
  114. data/lib/deltacloud/drivers/opennebula/opennebula_driver.rb +189 -126
  115. data/lib/deltacloud/drivers/openstack/openstack_driver.rb +427 -8
  116. data/lib/deltacloud/drivers/rackspace/rackspace_driver.rb +7 -9
  117. data/lib/deltacloud/drivers/rhevm/rhevm_driver.rb +48 -66
  118. data/lib/deltacloud/drivers/rimuhosting/rimuhosting_client.rb +44 -51
  119. data/lib/deltacloud/drivers/rimuhosting/rimuhosting_driver.rb +7 -8
  120. data/lib/deltacloud/drivers/sbc/sbc_client.rb +1 -1
  121. data/lib/deltacloud/drivers/sbc/sbc_driver.rb +3 -3
  122. data/lib/deltacloud/drivers/terremark/terremark_driver.rb +8 -8
  123. data/lib/deltacloud/drivers/vsphere/vsphere_driver.rb +39 -13
  124. data/lib/deltacloud/drivers/vsphere/vsphere_filemanager.rb +1 -0
  125. data/lib/deltacloud/helpers.rb +79 -7
  126. data/lib/{sinatra/lazy_auth.rb → deltacloud/helpers/auth_helper.rb} +5 -9
  127. data/lib/deltacloud/helpers/{blob_stream.rb → blob_stream_helper.rb} +7 -7
  128. data/lib/deltacloud/helpers/deltacloud_helper.rb +286 -0
  129. data/lib/deltacloud/helpers/driver_helper.rb +58 -0
  130. data/lib/deltacloud/helpers/rabbit_helper.rb +34 -0
  131. data/lib/{sinatra/url_for.rb → deltacloud/helpers/url_helper.rb} +31 -9
  132. data/lib/deltacloud/models.rb +19 -17
  133. data/lib/deltacloud/models/bucket.rb +4 -0
  134. data/lib/deltacloud/{hardware_profile.rb → models/hardware_profile.rb} +4 -2
  135. data/lib/deltacloud/models/image.rb +1 -0
  136. data/lib/deltacloud/models/instance.rb +4 -2
  137. data/lib/deltacloud/models/instance_address.rb +4 -0
  138. data/lib/deltacloud/models/key.rb +4 -0
  139. data/lib/deltacloud/models/metric.rb +40 -0
  140. data/lib/deltacloud/{state_machine.rb → models/state_machine.rb} +18 -1
  141. data/lib/deltacloud/server.rb +41 -1222
  142. data/lib/deltacloud_rack.rb +79 -0
  143. data/lib/{cimi/model/network_template.rb → ec2/helpers.rb} +7 -10
  144. data/lib/{deltacloud/backend_capability.rb → ec2/helpers/errors.rb} +24 -29
  145. data/lib/ec2/helpers/result.rb +31 -0
  146. data/lib/ec2/query_parser.rb +152 -0
  147. data/lib/ec2/server.rb +70 -0
  148. data/lib/{deltacloud.rb → sinatra.rb} +7 -12
  149. data/lib/sinatra/rack_accept.rb +13 -7
  150. data/lib/sinatra/rack_driver_select.rb +1 -1
  151. data/lib/sinatra/rack_matrix_params.rb +1 -3
  152. data/public/images/metric.png +0 -0
  153. data/public/javascripts/jquery.mobile-1.0.1.min.js +177 -0
  154. data/public/stylesheets/jquery.mobile-1.0.1.min.css +2 -0
  155. data/public/stylesheets/new.css +10 -0
  156. data/support/fedora/deltacloud-core.spec +1 -1
  157. data/tests/api/common.rb +1 -0
  158. data/tests/api/driver_test.rb +79 -0
  159. data/tests/api/library_test.rb +48 -0
  160. data/tests/cimi/features/step_definitions/common_steps.rb +2 -2
  161. data/tests/cimi/features/step_definitions/machines_steps.rb +5 -4
  162. data/tests/cimi/features/step_definitions/volumes_steps.rb +8 -8
  163. data/tests/cimi/features/support/env.rb +33 -11
  164. data/tests/common.rb +7 -8
  165. data/tests/drivers/ec2/api_test.rb +19 -0
  166. data/tests/drivers/ec2/common.rb +23 -0
  167. data/tests/drivers/ec2/drivers_test.rb +120 -0
  168. data/tests/drivers/ec2/hardware_profiles_test.rb +224 -0
  169. data/tests/drivers/ec2/images_test.rb +230 -0
  170. data/tests/drivers/ec2/instances_test.rb +356 -0
  171. data/tests/drivers/ec2/keys_test.rb +181 -0
  172. data/tests/drivers/ec2/realms_test.rb +146 -0
  173. data/tests/drivers/fgcp/api_test.rb +47 -0
  174. data/tests/drivers/fgcp/hardware_profiles_test.rb +54 -0
  175. data/tests/drivers/fgcp/realms_test.rb +42 -0
  176. data/tests/drivers/{rackspace → fgcp}/setup.rb +5 -6
  177. data/tests/drivers/google/api_test.rb +10 -26
  178. data/tests/drivers/google/buckets_test.rb +79 -95
  179. data/tests/drivers/google/common.rb +54 -0
  180. data/tests/drivers/mock/api_test.rb +4 -127
  181. data/tests/drivers/mock/buckets_test.rb +195 -0
  182. data/tests/drivers/mock/common.rb +7 -0
  183. data/tests/drivers/mock/drivers_test.rb +123 -0
  184. data/tests/drivers/mock/hardware_profiles_test.rb +190 -100
  185. data/tests/drivers/mock/images_test.rb +162 -103
  186. data/tests/drivers/mock/instances_test.rb +310 -220
  187. data/tests/drivers/mock/keys_test.rb +161 -0
  188. data/tests/drivers/mock/realms_test.rb +109 -70
  189. data/tests/drivers/mock/storage_snapshots_test.rb +114 -0
  190. data/tests/drivers/mock/storage_volumes_test.rb +122 -0
  191. data/tests/drivers/openstack/api_test.rb +8 -3
  192. data/tests/drivers/openstack/common.rb +21 -0
  193. data/tests/drivers/openstack/hardware_profiles_test.rb +20 -9
  194. data/tests/drivers/openstack/images_test.rb +11 -5
  195. data/tests/drivers/openstack/instances_test.rb +61 -16
  196. data/tests/drivers/openstack/realms_test.rb +11 -7
  197. data/tests/drivers/rackspace/api_test.rb +7 -2
  198. data/tests/drivers/rackspace/buckets_test.rb +7 -2
  199. data/tests/drivers/rackspace/common.rb +16 -0
  200. data/tests/drivers/rackspace/hardware_profiles_test.rb +7 -2
  201. data/tests/drivers/rackspace/images_test.rb +7 -2
  202. data/tests/drivers/rackspace/instances_test.rb +10 -5
  203. data/tests/drivers/rackspace/realms_test.rb +7 -2
  204. data/tests/drivers/rhevm/api_test.rb +12 -6
  205. data/tests/drivers/rhevm/{setup.rb → common.rb} +8 -1
  206. data/tests/drivers/rhevm/hardware_profiles_test.rb +7 -2
  207. data/tests/drivers/rhevm/images_test.rb +8 -2
  208. data/tests/drivers/rhevm/instances_test.rb +7 -2
  209. data/tests/drivers/rhevm/realms_test.rb +7 -2
  210. data/tests/minitest_common.rb +58 -0
  211. data/tests/minitest_common_api_test.rb +115 -0
  212. data/views/addresses/associate.html.haml +1 -1
  213. data/views/addresses/index.html.haml +1 -1
  214. data/views/addresses/show.html.haml +2 -3
  215. data/views/api/show.html.haml +22 -9
  216. data/views/api/show.xml.haml +8 -7
  217. data/views/blobs/show.xml.haml +7 -4
  218. data/views/buckets/new.html.haml +2 -2
  219. data/views/cimi/errors/401.xml.haml +1 -1
  220. data/views/error.html.haml +3 -3
  221. data/views/errors/400.html.haml +1 -1
  222. data/views/errors/400.xml.haml +1 -2
  223. data/views/errors/401.html.haml +8 -7
  224. data/views/errors/401.xml.haml +1 -1
  225. data/views/errors/404.xml.haml +1 -0
  226. data/views/errors/500.xml.haml +4 -2
  227. data/views/{cimi/errors/403.html.haml → errors/501.html.haml} +4 -2
  228. data/views/errors/501.xml.haml +1 -0
  229. data/views/errors/502.xml.haml +1 -7
  230. data/views/{cimi/errors/500.html.haml → errors/504.html.haml} +0 -0
  231. data/views/errors/504.xml.haml +1 -0
  232. data/views/firewalls/new.html.haml +2 -2
  233. data/views/firewalls/new_rule.html.haml +1 -1
  234. data/views/firewalls/show.html.haml +1 -1
  235. data/views/hardware_profiles/index.html.haml +3 -1
  236. data/views/hardware_profiles/index.xml.haml +2 -2
  237. data/views/hardware_profiles/show.html.haml +3 -3
  238. data/views/hardware_profiles/show.xml.haml +3 -3
  239. data/views/images/show.html.haml +5 -0
  240. data/views/images/show.xml.haml +6 -1
  241. data/views/instance_states/show.html.haml +1 -1
  242. data/views/instances/index.html.haml +1 -1
  243. data/views/instances/new.html.haml +54 -39
  244. data/views/instances/run_command.html.haml +24 -15
  245. data/views/instances/show.html.haml +7 -3
  246. data/views/instances/show.xml.haml +2 -2
  247. data/views/keys/show.xml.haml +1 -0
  248. data/views/layout.html.haml +5 -9
  249. data/views/load_balancers/show.html.haml +12 -6
  250. data/views/metrics/index.html.haml +13 -0
  251. data/views/metrics/index.xml.haml +5 -0
  252. data/views/metrics/show.html.haml +23 -0
  253. data/views/metrics/show.xml.haml +9 -0
  254. data/views/realms/show.xml.haml +2 -1
  255. data/views/root/index.html.haml +1 -1
  256. data/views/storage_snapshots/show.html.haml +1 -1
  257. data/views/storage_snapshots/show.xml.haml +1 -0
  258. data/views/storage_volumes/attach.html.haml +1 -2
  259. data/views/storage_volumes/index.html.haml +1 -1
  260. data/views/storage_volumes/new.html.haml +22 -16
  261. data/views/storage_volumes/show.html.haml +10 -4
  262. data/views/storage_volumes/show.xml.haml +3 -4
  263. metadata +547 -519
  264. data/DISCLAIMER +0 -8
  265. data/lib/cimi/model.rb +0 -52
  266. data/lib/cimi/model/network.rb +0 -69
  267. data/lib/deltacloud/base_driver.rb +0 -18
  268. data/lib/deltacloud/base_driver/features.rb +0 -262
  269. data/lib/deltacloud/base_driver/mock_driver.rb +0 -78
  270. data/lib/deltacloud/drivers/ec2/ec2_mock_driver.rb +0 -186
  271. data/lib/deltacloud/drivers/rhevm/rhevm_client.rb +0 -521
  272. data/lib/deltacloud/helpers/application_helper.rb +0 -267
  273. data/lib/deltacloud/helpers/hardware_profiles_helper.rb +0 -50
  274. data/lib/deltacloud/helpers/json_helper.rb +0 -31
  275. data/lib/deltacloud/method_serializer.rb +0 -83
  276. data/lib/deltacloud/validation.rb +0 -107
  277. data/lib/sinatra/rabbit.rb +0 -441
  278. data/lib/sinatra/rack_runtime.rb +0 -47
  279. data/lib/sinatra/rack_syslog.rb +0 -86
  280. data/lib/sinatra/sinatra_verbose.rb +0 -73
  281. data/lib/sinatra/static_assets.rb +0 -99
  282. data/public/javascripts/jquery.mobile-1.0rc1.min.js +0 -170
  283. data/public/stylesheets/jquery.mobile-1.0rc1.min.css +0 -12
  284. data/tests/drivers/google/setup.rb +0 -38
  285. data/tests/drivers/mock/instance_states_test.rb +0 -71
  286. data/tests/drivers/mock/setup.rb +0 -3
  287. data/tests/drivers/mock/url_for_test.rb +0 -67
  288. data/tests/drivers/openstack/setup.rb +0 -20
  289. data/views/cimi/errors/400.html.haml +0 -41
  290. data/views/cimi/errors/401.html.haml +0 -41
  291. data/views/cimi/errors/404.html.haml +0 -29
  292. data/views/cimi/errors/405.html.haml +0 -29
  293. data/views/cimi/errors/502.html.haml +0 -43
  294. data/views/cimi/errors/backend_capability_failure.html.haml +0 -29
@@ -6,7 +6,7 @@ When /^client specifies a Volume Configuration$/ do |volume_config|
6
6
  @volume_config = CIMI::Model::VolumeConfiguration.from_xml(last_response.body)
7
7
  @volume_config.class.should == CIMI::Model::VolumeConfiguration
8
8
  @volume_config.attribute_values[:capacity].quantity.should == "2"
9
- @volume_config.uri.should == volume_config.raw[0][1]
9
+ @volume_config.id.should == volume_config.raw[0][1]
10
10
  end
11
11
 
12
12
  When /^client specifies a new Volume using$/ do |volume|
@@ -18,7 +18,7 @@ When /^client specifies a new Volume using$/ do |volume|
18
18
  xml.name volume_name
19
19
  xml.description volume_description
20
20
  xml.volumeTemplate {
21
- xml.volumeConfig( :href => @volume_config.uri )
21
+ xml.volumeConfig( :href => @volume_config.id )
22
22
  }
23
23
  }
24
24
  end
@@ -37,11 +37,11 @@ When /^client GET the Volumes Collection$/ do
37
37
  header 'Content-Type', 'application/xml'
38
38
  get "/cimi/volumes"
39
39
  last_response.status.should == 200
40
- @@volume_collection = VolumeCollection.from_xml(last_response.body)
40
+ @@volume_collection = CIMI::Model::VolumeCollection.from_xml(last_response.body)
41
41
  end
42
42
 
43
43
  Then /^client should get a list of volumes$/ do
44
- @@volume_collection.uri.end_with?("/cimi/volumes").should == true
44
+ @@volume_collection.id.end_with?("/cimi/volumes").should == true
45
45
  @@volume_collection.attribute_values.has_key?(:volumes).should == true
46
46
  end
47
47
 
@@ -59,7 +59,7 @@ end
59
59
 
60
60
  Then /^client should verify that this Volume was created correctly$/ do |capacity|
61
61
  @@retrieved_volume.name.should == @@created_volume.name
62
- @@retrieved_volume.uri.should == @@created_volume.uri
62
+ @@retrieved_volume.id.should == @@created_volume.id
63
63
  @@retrieved_volume.capacity[:quantity].should == capacity.raw[0][1]
64
64
  end
65
65
 
@@ -69,7 +69,7 @@ When /^client specifies a running Machine using$/ do |machine|
69
69
  header 'Content-Type', 'application/xml'
70
70
  get "/cimi/machines/#{@machine_id}?format=xml"
71
71
  last_response.status.should==200
72
- @@machine = Machine.from_xml(last_response.body)
72
+ @@machine = CIMI::Model::Machine.from_xml(last_response.body)
73
73
  @@machine.name.should == @machine_id
74
74
  @@machine.state.should == "STARTED"
75
75
  end
@@ -77,7 +77,7 @@ end
77
77
  When /^client specifies the new Volume with attachment point using$/ do |attach|
78
78
  @builder = Nokogiri::XML::Builder.new do |xml|
79
79
  xml.VolumeAttach {
80
- xml.volume( :href => @@created_volume.uri, :attachmentPoint=>attach.raw[0][1])
80
+ xml.volume( :href => @@created_volume.id, :attachmentPoint=>attach.raw[0][1])
81
81
  }
82
82
  end
83
83
  end
@@ -94,7 +94,7 @@ When /^client should be able to detach the volume$/ do
94
94
  header 'Content-Type', 'application/CIMI-Machine+xml'
95
95
  @builder = Nokogiri::XML::Builder.new do |xml|
96
96
  xml.VolumeDetach {
97
- xml.volume(:href => @@created_volume.uri)
97
+ xml.volume(:href => @@created_volume.id)
98
98
  }
99
99
  end
100
100
  put "/cimi/machines/#{@@machine.name}/detach_volume", @builder.to_xml
@@ -1,21 +1,47 @@
1
1
  require 'rubygems'
2
2
  require 'nokogiri'
3
+ require 'rack/test'
3
4
 
4
- ENV['API_DRIVER'] = 'mock'
5
5
  ENV['API_FRONTEND'] = 'cimi'
6
- ENV.delete('API_VERBOSE')
7
-
8
- $top_srcdir = File.join(File.dirname(__FILE__), '..', '..', '..', '..')
9
- $:.unshift File.join($top_srcdir, 'lib')
10
6
 
11
- load File.join($top_srcdir, 'lib', 'cimi', 'server.rb')
7
+ load File.join(File.dirname(__FILE__), '..', '..', '..', '..', 'lib', 'deltacloud_rack.rb')
12
8
 
13
- require 'rack/test'
9
+ Deltacloud::configure do |server|
10
+ server.root_url '/cimi'
11
+ server.version '1.0.0'
12
+ server.klass 'CIMI::API'
13
+ end.require_frontend!
14
14
 
15
15
  def last_xml_response
16
16
  Nokogiri::XML(last_response.body)
17
17
  end
18
18
 
19
+ class IndexEntrypoint < Sinatra::Base
20
+ get "/" do
21
+ redirect Deltacloud[:root_url], 301
22
+ end
23
+ end
24
+
25
+ =begin
26
+ def app
27
+ Rack::URLMap.new(
28
+ "/" => IndexEntrypoint.new,
29
+ Deltacloud[:root_url] => CIMI::API,
30
+ "/stylesheets" => Rack::Directory.new( "public/stylesheets" ),
31
+ "/javascripts" => Rack::Directory.new( "public/javascripts" )
32
+ )
33
+ end
34
+ =end
35
+
36
+ def app
37
+ Rack::Builder.new {
38
+ map '/' do
39
+ use Rack::Static, :urls => ["/stylesheets", "/javascripts"], :root => "public"
40
+ run Rack::Cascade.new([CIMI::API])
41
+ end
42
+ }
43
+ end
44
+
19
45
  def new_machine
20
46
  @@new_machine
21
47
  end
@@ -47,7 +73,3 @@ class String
47
73
  end
48
74
 
49
75
  end
50
-
51
- def app
52
- Sinatra::Application
53
- end
@@ -28,9 +28,14 @@ require 'json'
28
28
  require 'digest/sha1'
29
29
  require 'base64'
30
30
  require 'rack/test'
31
- require "%s/server" % (ENV['API_FRONTEND'] == 'cimi' ? 'cimi' : 'deltacloud')
32
31
 
33
- driver
32
+ load File.join(File.dirname(__FILE__), '..', 'lib', 'deltacloud_rack.rb')
33
+
34
+ Deltacloud::configure do |server|
35
+ server.root_url '/api'
36
+ server.version '1.0.0'
37
+ server.klass 'Deltacloud::API'
38
+ end.require_frontend!
34
39
 
35
40
  # Set proper environment variables for running test
36
41
 
@@ -38,12 +43,6 @@ ENV['RACK_ENV'] = 'test'
38
43
  ENV['API_HOST'] = 'localhost'
39
44
  ENV['API_PORT'] = '4040'
40
45
 
41
- configure :test do
42
- set :environment, :test
43
- set :raise_errors, false
44
- set :show_exceptions, false
45
- end
46
-
47
46
  RSpec.configure do |conf|
48
47
  conf.include Rack::Test::Methods
49
48
  conf.expect_with :rspec
@@ -0,0 +1,19 @@
1
+ $:.unshift File.join(File.dirname(__FILE__), '..', '..', '..')
2
+ require 'tests/drivers/ec2/common'
3
+
4
+ describe 'Deltacloud API' 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
+ eval File.read('tests/minitest_common_api_test.rb')
18
+
19
+ end
@@ -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,120 @@
1
+ $:.unshift File.join(File.dirname(__FILE__), '..', '..', '..')
2
+ require 'tests/drivers/ec2/common'
3
+
4
+ describe 'Deltacloud API drivers' do
5
+ include Deltacloud::Test
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
+ it 'must advertise have the drivers collection in API entrypoint' do
16
+ get root_url
17
+ (xml_response/'api/link[@rel=drivers]').wont_be_empty
18
+ end
19
+
20
+ it 'must not require authentication to access the "driver" collection' do
21
+ get collection_url(:drivers)
22
+ last_response.status.must_equal 200
23
+ end
24
+
25
+ it 'should respond with HTTP_OK when accessing the :drivers collection with authentication' do
26
+ get collection_url(:drivers)
27
+ last_response.status.must_equal 200
28
+ end
29
+
30
+ it 'should support the JSON media type' do
31
+ header 'Accept', 'application/json'
32
+ get collection_url(:drivers)
33
+ last_response.status.must_equal 200
34
+ last_response.headers['Content-Type'].must_equal 'application/json'
35
+ end
36
+
37
+ it 'must include the ETag in HTTP headers' do
38
+ get collection_url(:drivers)
39
+ last_response.headers['ETag'].wont_be_nil
40
+ end
41
+
42
+ it 'must have the "drivers" element on top level' do
43
+ get collection_url(:drivers)
44
+ xml_response.root.name.must_equal 'drivers'
45
+ end
46
+
47
+ it 'must have some "driver" elements inside "drivers"' do
48
+ get collection_url(:drivers)
49
+ (xml_response/'drivers/driver').wont_be_empty
50
+ end
51
+
52
+ it 'must provide the :id attribute for each driver in collection' do
53
+ get collection_url(:drivers)
54
+ (xml_response/'drivers/driver').each do |r|
55
+ r[:id].wont_be_nil
56
+ end
57
+ end
58
+
59
+ it 'must include the :href attribute for each "driver" element in collection' do
60
+ get collection_url(:drivers)
61
+ (xml_response/'drivers/driver').each do |r|
62
+ r[:href].wont_be_nil
63
+ end
64
+ end
65
+
66
+ it 'must use the absolute URL in each :href attribute' do
67
+ get collection_url(:drivers)
68
+ (xml_response/'drivers/driver').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 driver' do
74
+ get collection_url(:drivers)
75
+ (xml_response/'drivers/driver').each do |r|
76
+ r[:href].must_match /#{r[:id]}$/
77
+ end
78
+ end
79
+
80
+ it 'must return the list of valid parameters for the :index action' do
81
+ options collection_url(:drivers) + '/index'
82
+ last_response.headers['Allow'].wont_be_nil
83
+ end
84
+
85
+ it 'must have the "name" element defined for each driver in collection' do
86
+ get collection_url(:drivers)
87
+ (xml_response/'drivers/driver').each do |r|
88
+ (r/'name').wont_be_nil
89
+ end
90
+ end
91
+
92
+
93
+ it 'must return the full "driver" when following the URL in driver element' do
94
+ authenticate
95
+ get collection_url(:drivers)
96
+ (xml_response/'drivers/driver').each do |r|
97
+ get collection_url(:drivers) + '/' + r[:id]
98
+ last_response.status.must_equal 200
99
+ end
100
+ end
101
+
102
+ it 'must have the "name" element for the driver and it should match with the one in collection' do
103
+ authenticate
104
+ get collection_url(:drivers)
105
+ (xml_response/'drivers/driver').each do |r|
106
+ r[:id].wont_be_nil
107
+ get collection_url(:drivers) + '/' + r[:id]
108
+ (xml_response/'name').wont_be_empty
109
+ (xml_response/'name').first.text.must_equal((r/'name').first.text)
110
+ end
111
+ end
112
+
113
+ it 'should advertise available providers for some drivers' do
114
+ get collection_url(:drivers)
115
+ (xml_response/'drivers/driver/provider').each do |p|
116
+ p[:id].wont_be_nil
117
+ end
118
+ end
119
+
120
+ end
@@ -0,0 +1,224 @@
1
+ $:.unshift File.join(File.dirname(__FILE__), '..', '..', '..')
2
+ require 'tests/drivers/ec2/common'
3
+
4
+ describe 'Deltacloud API Hardware Profiles' do
5
+ include Deltacloud::Test
6
+
7
+ it 'must advertise have the hardware_profiles collection in API entrypoint' do
8
+ get root_url
9
+ (xml_response/'api/link[@rel=hardware_profiles]').wont_be_empty
10
+ end
11
+
12
+ it 'should respond with HTTP_OK when accessing the :hardware_profiles collection with authentication' do
13
+ authenticate
14
+ get collection_url(:hardware_profiles)
15
+ last_response.status.must_equal 200
16
+ end
17
+
18
+ it 'should support the JSON media type' do
19
+ authenticate
20
+ header 'Accept', 'application/json'
21
+ get collection_url(:hardware_profiles)
22
+ last_response.status.must_equal 200
23
+ last_response.headers['Content-Type'].must_equal 'application/json'
24
+ end
25
+
26
+ it 'must include the ETag in HTTP headers' do
27
+ authenticate
28
+ get collection_url(:hardware_profiles)
29
+ last_response.headers['ETag'].wont_be_nil
30
+ end
31
+
32
+ it 'must have the "hardware_profiles" element on top level' do
33
+ authenticate
34
+ get collection_url(:hardware_profiles)
35
+ xml_response.root.name.must_equal 'hardware_profiles'
36
+ end
37
+
38
+ it 'must have some "hardware_profile" elements inside "hardware_profiles"' do
39
+ authenticate
40
+ get collection_url(:hardware_profiles)
41
+ (xml_response/'hardware_profiles/hardware_profile').wont_be_empty
42
+ end
43
+
44
+ it 'must provide the :id attribute for each hardware_profile in collection' do
45
+ authenticate
46
+ get collection_url(:hardware_profiles)
47
+ (xml_response/'hardware_profiles/hardware_profile').each do |r|
48
+ r[:id].wont_be_nil
49
+ end
50
+ end
51
+
52
+ it 'must include the :href attribute for each "hardware_profile" element in collection' do
53
+ authenticate
54
+ get collection_url(:hardware_profiles)
55
+ (xml_response/'hardware_profiles/hardware_profile').each do |r|
56
+ r[:href].wont_be_nil
57
+ end
58
+ end
59
+
60
+ it 'must use the absolute URL in each :href attribute' do
61
+ authenticate
62
+ get collection_url(:hardware_profiles)
63
+ (xml_response/'hardware_profiles/hardware_profile').each do |r|
64
+ r[:href].must_match /^http/
65
+ end
66
+ end
67
+
68
+ it 'must have the URL ending with the :id of the hardware_profile' do
69
+ authenticate
70
+ get collection_url(:hardware_profiles)
71
+ (xml_response/'hardware_profiles/hardware_profile').each do |r|
72
+ r[:href].must_match /#{r[:id]}$/
73
+ end
74
+ end
75
+
76
+ it 'must return the list of valid parameters for the :index action' do
77
+ authenticate
78
+ options collection_url(:hardware_profiles) + '/index'
79
+ last_response.headers['Allow'].wont_be_nil
80
+ end
81
+
82
+ it 'must have the "name" element defined for each hardware_profile in collection' do
83
+ authenticate
84
+ get collection_url(:hardware_profiles)
85
+ (xml_response/'hardware_profiles/hardware_profile').each do |r|
86
+ (r/'name').wont_be_empty
87
+ end
88
+ end
89
+
90
+ it 'should have the "property" element defined if not the opaque hardware_profile' do
91
+ authenticate
92
+ get collection_url(:hardware_profiles)
93
+ (xml_response/'hardware_profiles/hardware_profile').each do |r|
94
+ next if r[:id] == 'opaque'
95
+ (r/'property').wont_be_empty
96
+ end
97
+ end
98
+
99
+ it 'must define the :kind attribute for each "property" ' do
100
+ authenticate
101
+ get collection_url(:hardware_profiles)
102
+ (xml_response/'hardware_profiles/hardware_profile').each do |r|
103
+ next if r[:id] == 'opaque'
104
+ (r/'property').each { |p| p[:kind].wont_be_nil }
105
+ end
106
+ end
107
+
108
+ it 'must define the :name attribute for each "property" ' do
109
+ authenticate
110
+ get collection_url(:hardware_profiles)
111
+ (xml_response/'hardware_profiles/hardware_profile').each do |r|
112
+ next if r[:id] == 'opaque'
113
+ (r/'property').each { |p| p[:name].wont_be_nil }
114
+ end
115
+ end
116
+
117
+ it 'must define the :unit attribute for each "property" ' do
118
+ authenticate
119
+ get collection_url(:hardware_profiles)
120
+ (xml_response/'hardware_profiles/hardware_profile').each do |r|
121
+ next if r[:id] == 'opaque'
122
+ (r/'property').each { |p| p[:unit].wont_be_nil }
123
+ end
124
+ end
125
+
126
+ it 'must define the :value attribute for each "property" ' do
127
+ authenticate
128
+ get collection_url(:hardware_profiles)
129
+ (xml_response/'hardware_profiles/hardware_profile').each do |r|
130
+ next if r[:id] == 'opaque'
131
+ (r/'property').each { |p| p[:value].wont_be_nil }
132
+ end
133
+ end
134
+
135
+ it 'must define the "param" element if property kind is not "fixed"' do
136
+ authenticate
137
+ get collection_url(:hardware_profiles)
138
+ (xml_response/'hardware_profiles/hardware_profile').each do |r|
139
+ next if r[:id] == 'opaque'
140
+ (r/'property').each do |p|
141
+ next if p[:kind] == 'fixed'
142
+ (p/'param').wont_be_empty
143
+ (p/'param').size.must_equal 1
144
+ (p/'param').first[:href].wont_be_nil
145
+ (p/'param').first[:href].must_match /^http/
146
+ (p/'param').first[:method].wont_be_nil
147
+ (p/'param').first[:name].wont_be_nil
148
+ (p/'param').first[:operation].wont_be_nil
149
+ end
150
+ end
151
+ end
152
+
153
+ it 'must provide the list of valid values when the property is defined as "enum"' do
154
+ authenticate
155
+ get collection_url(:hardware_profiles)
156
+ (xml_response/'hardware_profiles/hardware_profile').each do |r|
157
+ next if r[:id] == 'opaque'
158
+ (r/'property').each do |p|
159
+ next if p[:kind] != 'enum'
160
+ (p/'enum/entry').wont_be_empty
161
+ (p/'enum/entry').each { |e| e[:value].wont_be_nil }
162
+ end
163
+ end
164
+ end
165
+
166
+ it 'must provide the range of valid values when the property is defined as "range"' do
167
+ authenticate
168
+ get collection_url(:hardware_profiles)
169
+ (xml_response/'hardware_profiles/hardware_profile').each do |r|
170
+ next if r[:id] == 'opaque'
171
+ (r/'property').each do |p|
172
+ next if p[:kind] != 'range'
173
+ (p/'range').wont_be_empty
174
+ (p/'range').size.must_equal 1
175
+ (p/'range').first[:first].wont_be_nil
176
+ (p/'range').first[:last].wont_be_nil
177
+ end
178
+ end
179
+ end
180
+
181
+ it 'must provide the default value within the range if property defined as "range"' do
182
+ authenticate
183
+ get collection_url(:hardware_profiles)
184
+ (xml_response/'hardware_profiles/hardware_profile').each do |r|
185
+ next if r[:id] == 'opaque'
186
+ (r/'property').each do |p|
187
+ next if p[:kind] != 'range'
188
+ ((p/'range').first[:first].to_i..(p/'range').first[:last].to_i).include?(p[:value].to_i).must_equal true
189
+ end
190
+ end
191
+ end
192
+
193
+ it 'must provide the default value that is included in enum list if property defined as "enum"' do
194
+ authenticate
195
+ get collection_url(:hardware_profiles)
196
+ (xml_response/'hardware_profiles/hardware_profile').each do |r|
197
+ next if r[:id] == 'opaque'
198
+ (r/'property').each do |p|
199
+ next if p[:kind] != 'enum'
200
+ (p/'enum/entry').map { |e| e[:value] }.include?(p[:value]).must_equal true
201
+ end
202
+ end
203
+ end
204
+
205
+ it 'must return the full "hardware_profile" when following the URL in hardware_profile element' do
206
+ authenticate
207
+ get collection_url(:hardware_profiles)
208
+ (xml_response/'hardware_profiles/hardware_profile').each do |r|
209
+ get collection_url(:hardware_profiles) + '/' + r[:id]
210
+ last_response.status.must_equal 200
211
+ end
212
+ end
213
+
214
+ it 'must have the "name" element for the hardware_profile and it should match with the one in collection' do
215
+ authenticate
216
+ get collection_url(:hardware_profiles)
217
+ (xml_response/'hardware_profiles/hardware_profile').each do |r|
218
+ get collection_url(:hardware_profiles) + '/' + r[:id]
219
+ (xml_response/'name').wont_be_empty
220
+ (xml_response/'name').first.text.must_equal((r/'name').first.text)
221
+ end
222
+ end
223
+
224
+ end