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,34 @@
1
+
2
+ # Licensed to the Apache Software Foundation (ASF) under one or more
3
+ # contributor license agreements. See the NOTICE file distributed with
4
+ # this work for additional information regarding copyright ownership. The
5
+ # ASF licenses this file to you under the Apache License, Version 2.0 (the
6
+ # "License"); you may not use this file except in compliance with the
7
+ # License. You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13
+ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14
+ # License for the specific language governing permissions and limitations
15
+ # under the License.
16
+ #
17
+ require 'rubygems'
18
+ require 'require_relative' if RUBY_VERSION < '1.9'
19
+
20
+ require_relative '../../spec_helper.rb' if require 'minitest/autorun'
21
+
22
+ describe "Volume Configuration model" do
23
+
24
+ before do
25
+ @xml = IO::read(File::join(DATA_DIR, "volume_configuration.xml"))
26
+ @json = IO::read(File::join(DATA_DIR, "volume_configuration.json"))
27
+ end
28
+
29
+ it "can be constructed from XML and JSON" do
30
+ should_properly_serialize_model CIMI::Model::VolumeConfiguration, @xml, @json
31
+ end
32
+
33
+
34
+ end
@@ -0,0 +1,33 @@
1
+ # Licensed to the Apache Software Foundation (ASF) under one or more
2
+ # contributor license agreements. See the NOTICE file distributed with
3
+ # this work for additional information regarding copyright ownership. The
4
+ # ASF licenses this file to you under the Apache License, Version 2.0 (the
5
+ # "License"); you may not use this file except in compliance with the
6
+ # License. You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12
+ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13
+ # License for the specific language governing permissions and limitations
14
+ # under the License.
15
+ #
16
+ require 'rubygems'
17
+ require 'require_relative' if RUBY_VERSION < '1.9'
18
+
19
+ require_relative '../../spec_helper.rb' if require 'minitest/autorun'
20
+
21
+ describe "Volume Image model" do
22
+
23
+ before do
24
+ @xml = IO::read(File::join(DATA_DIR, "volume_image.xml"))
25
+ @json = IO::read(File::join(DATA_DIR, "volume_image.json"))
26
+ end
27
+
28
+ it "can be constructed from XML and JSON" do
29
+ should_properly_serialize_model CIMI::Model::VolumeImage, @xml, @json
30
+ end
31
+
32
+
33
+ end
@@ -0,0 +1,32 @@
1
+ # Licensed to the Apache Software Foundation (ASF) under one or more
2
+ # contributor license agreements. See the NOTICE file distributed with
3
+ # this work for additional information regarding copyright ownership. The
4
+ # ASF licenses this file to you under the Apache License, Version 2.0 (the
5
+ # "License"); you may not use this file except in compliance with the
6
+ # License. You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12
+ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13
+ # License for the specific language governing permissions and limitations
14
+ # under the License.
15
+ #
16
+ require 'rubygems'
17
+ require 'require_relative' if RUBY_VERSION < '1.9'
18
+
19
+ require_relative '../../spec_helper.rb' if require 'minitest/autorun'
20
+
21
+ describe "Volume model" do
22
+
23
+ before do
24
+ @xml = IO::read(File::join(DATA_DIR, "volume.xml"))
25
+ @json = IO::read(File::join(DATA_DIR, "volume.json"))
26
+ end
27
+
28
+ it "can be constructed from XML and JSON" do
29
+ should_properly_serialize_model CIMI::Model::Volume, @xml, @json
30
+ end
31
+
32
+ end
@@ -0,0 +1,32 @@
1
+ # Licensed to the Apache Software Foundation (ASF) under one or more
2
+ # contributor license agreements. See the NOTICE file distributed with
3
+ # this work for additional information regarding copyright ownership. The
4
+ # ASF licenses this file to you under the Apache License, Version 2.0 (the
5
+ # "License"); you may not use this file except in compliance with the
6
+ # License. You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12
+ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13
+ # License for the specific language governing permissions and limitations
14
+ # under the License.
15
+ #
16
+ require 'rubygems'
17
+ require 'require_relative' if RUBY_VERSION < '1.9'
18
+
19
+ require_relative '../../spec_helper.rb' if require 'minitest/autorun'
20
+
21
+ describe "Volume Template model" do
22
+
23
+ before do
24
+ @xml = IO::read(File::join(DATA_DIR, "volume_template.xml"))
25
+ @json = IO::read(File::join(DATA_DIR, "volume_template.json"))
26
+ end
27
+
28
+ it "can be constructed from XML and JSON" do
29
+ should_properly_serialize_model CIMI::Model::VolumeTemplate, @xml, @json
30
+ end
31
+
32
+ end
@@ -0,0 +1,136 @@
1
+ # Licensed to the Apache Software Foundation (ASF) under one or more
2
+ # contributor license agreements. See the NOTICE file distributed with
3
+ # this work for additional information regarding copyright ownership. The
4
+ # ASF licenses this file to you under the Apache License, Version 2.0 (the
5
+ # "License"); you may not use this file except in compliance with the
6
+ # License. You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12
+ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13
+ # License for the specific language governing permissions and limitations
14
+ # under the License.
15
+ #
16
+
17
+ require 'rubygems'
18
+ require 'minitest/autorun'
19
+ require 'minitest/spec'
20
+ require 'xmlsimple'
21
+ require 'require_relative' if RUBY_VERSION < '1.9'
22
+
23
+ require_relative '../../../lib/deltacloud/core_ext.rb'
24
+ require_relative '../../../lib/cimi/models.rb'
25
+
26
+ DATA_DIR = File::join(File::expand_path(File::dirname(__FILE__)), 'cimi', 'data')
27
+
28
+ def parse_xml(xml, opts = {})
29
+ opts[:force_content] = true
30
+ opts[:keep_root] = true unless opts.has_key?(:keep_root)
31
+ XmlSimple.xml_in(xml, opts)
32
+ end
33
+
34
+ class HashCmp
35
+ def initialize(exp, act)
36
+ @exp = exp
37
+ @act = act
38
+ @io = StringIO.new
39
+ end
40
+
41
+ def match?
42
+ @equal = true
43
+ compare_values(@exp, @act, [])
44
+ @equal
45
+ end
46
+
47
+ def errors
48
+ @io.string
49
+ end
50
+
51
+ private
52
+ def compare_values(exp, act, path)
53
+ if exp.is_a?(String)
54
+ mismatch("entries differ", exp, act, path) unless exp == act
55
+ elsif exp.is_a?(Array)
56
+ mismatch("expected array", exp, act, path) unless act.is_a?(Array)
57
+ unless act.size == exp.size
58
+ mismatch("different array lengths", exp, act, path)
59
+ end
60
+ name = path.pop
61
+ if name == "property"
62
+ # Special hack for properties, since they truly are a hash
63
+ # and therefore not ordered, even though XmlSimple
64
+ # represents them as an array; since that array can be generated
65
+ # from a hash, in Ruby 1.8 the order of the array is random
66
+ exp = exp.sort! { |item1, item2| item1["name"] <=> item2["name"] }
67
+ act = act.sort! { |item1, item2| item1["name"] <=> item2["name"] }
68
+ end
69
+ 0.upto(exp.size-1) do |i|
70
+ compare_values(exp[i], act[i], path + [ "#{name}[#{i}]" ])
71
+ end
72
+ elsif exp.is_a?(Hash)
73
+ unless act.is_a?(Hash)
74
+ mismatch("expected Hash", exp, act, path)
75
+ return
76
+ end
77
+ unless (missing = exp.keys - act.keys).empty?
78
+ error "Missing key(s) at /#{path.join("/")}: #{missing.inspect}"
79
+ end
80
+ unless (excess = act.keys - exp.keys).empty?
81
+ error "Excess key(s) at /#{path.join("/")}: #{excess.inspect}"
82
+ end
83
+ (exp.keys - missing - excess).each do |k|
84
+ compare_values(exp[k], act[k], path + [ k ])
85
+ end
86
+ end
87
+ end
88
+
89
+ def mismatch(msg, exp, act, path)
90
+ error "#{msg}[#{fmt(path)}]: #{exp.inspect} != #{act.inspect}"
91
+ end
92
+
93
+ def error(msg)
94
+ @equal = false
95
+ @io.puts msg
96
+ end
97
+
98
+ def fmt(path)
99
+ "/#{path.join("/")}"
100
+ end
101
+ end
102
+
103
+ def should_properly_serialize_model(model_class, xml, json)
104
+ # Roundtrip in same format
105
+ model_class.from_xml(xml).must_serialize_to xml, :fmt => :xml
106
+ model_class.from_json(json).must_serialize_to json, :fmt => :json
107
+ # Roundtrip crossing format
108
+ model_class.from_xml(xml).must_serialize_to json, :fmt => :json
109
+ model_class.from_json(json).must_serialize_to xml, :fmt => :xml
110
+ end
111
+
112
+ module MiniTest::Assertions
113
+
114
+ def assert_serialize_to(exp, act, opts)
115
+ raise "missing format; use :fmt => [:xml || :json]" if opts[:fmt].nil?
116
+ exp, act = [exp, act].map { |x| convert(x, opts[:fmt]) }
117
+ m = HashCmp.new(exp, act)
118
+ assert m.match?, "#{opts[:fmt].to_s.upcase} documents do not match\n" + m.errors
119
+ end
120
+
121
+ def convert(x, fmt)
122
+ if fmt == :json
123
+ x = x.to_json if x.is_a?(CIMI::Model::Base)
124
+ x = JSON.parse(x) if x.is_a?(String)
125
+ elsif fmt == :xml
126
+ x = x.to_xml if x.is_a?(CIMI::Model::Base)
127
+ x = parse_xml(x) if x.is_a?(String)
128
+ else
129
+ raise "Invalid format #{fmt}"
130
+ end
131
+ x
132
+ end
133
+
134
+ end
135
+
136
+ CIMI::Model::Base.infect_an_assertion :assert_serialize_to, :must_serialize_to
@@ -0,0 +1,30 @@
1
+ require 'rubygems'
2
+ require 'require_relative' if RUBY_VERSION < '1.9'
3
+
4
+ require_relative 'common.rb'
5
+
6
+ describe Deltacloud::Collections::Base do
7
+
8
+ before do
9
+ @base = Deltacloud::Collections::Base
10
+ end
11
+
12
+ it 'has config set correctly' do
13
+ @base.config.must_be_kind_of Deltacloud::Server
14
+ @base.config.root_url.must_equal Deltacloud.config[:deltacloud].root_url
15
+ end
16
+
17
+ it 'has root_url set correctly' do
18
+ @base.root_url.must_equal Deltacloud.config[:deltacloud].root_url
19
+ end
20
+
21
+ it 'has version set correctly' do
22
+ @base.version.must_equal Deltacloud.config[:deltacloud].version
23
+ end
24
+
25
+ it 'provides helper for routes' do
26
+ @base.must_respond_to :route_for
27
+ @base.route_for('/hardware_profiles').must_equal "#{Deltacloud.config[:deltacloud].root_url}/hardware_profiles"
28
+ end
29
+
30
+ end
@@ -0,0 +1,65 @@
1
+ require 'rubygems'
2
+ require 'require_relative' if RUBY_VERSION < '1.9'
3
+
4
+ require_relative File.join('..', 'common.rb')
5
+
6
+ describe Deltacloud::Collections::Buckets do
7
+
8
+ before do
9
+ def app; Deltacloud::API; end
10
+ authorize 'mockuser', 'mockpassword'
11
+ @collection = Deltacloud::Collections.collection(:buckets)
12
+ end
13
+
14
+ it 'has index operation' do
15
+ @collection.operation(:index).must_equal Sinatra::Rabbit::BucketsCollection::IndexOperation
16
+ end
17
+
18
+ it 'provides URL to specify new bucket' do
19
+ header 'Accept', 'text/html'
20
+ get root_url + '/buckets/new/' + Deltacloud::Helpers::Application::NEW_BLOB_FORM_ID
21
+ status.must_equal 200
22
+ end
23
+
24
+ it 'returns list of buckets in various formats with index operation' do
25
+ formats.each do |format|
26
+ header 'Accept', format
27
+ get root_url + '/buckets'
28
+ status.must_equal 200
29
+ end
30
+ end
31
+
32
+ it 'must support creating a new bucket and destroying it' do
33
+ post root_url + '/buckets', { :name => 'test-bucket1' }
34
+ status.must_equal 201
35
+ xml.root.name.must_equal 'bucket'
36
+ delete root_url + '/buckets/' + xml.root[:id]
37
+ status.must_equal 204
38
+ end
39
+
40
+ it 'returns blob metadata' do
41
+ head root_url + '/buckets/bucket1/blob1'
42
+ headers['X-Deltacloud-Blobmeta-SOMENEWKEY'].must_equal 'NEWVALUE'
43
+ status.must_equal 204
44
+ head root_url + '/buckets/bucket1/non-existing-blob'
45
+ status.must_equal 404
46
+ end
47
+
48
+ it 'returns blob details on show operation in various formats' do
49
+ formats.each do |format|
50
+ header 'Accept', format
51
+ get root_url + '/buckets/bucket1/blob1'
52
+ last_response
53
+ status.must_equal 200
54
+ end
55
+ end
56
+
57
+ it 'creates a new blob and then destroy it' do
58
+ post root_url + '/buckets/bucket1', { :blob_id => 'test-blob', :blob_data => 'test', :meta_params => '1', :meta_name1 => 'test-meta1' }
59
+ status.must_equal 201
60
+ delete root_url + '/buckets/bucket1/test-blob'
61
+ status.must_equal 204
62
+ end
63
+
64
+
65
+ end
@@ -0,0 +1,37 @@
1
+ require 'rubygems'
2
+ require 'require_relative' if RUBY_VERSION < '1.9'
3
+
4
+ require_relative File.join('..', 'common.rb')
5
+
6
+ describe Deltacloud::Collections::Drivers do
7
+
8
+ before do
9
+ def app; Deltacloud::API; end
10
+ @collection = Deltacloud::Collections.collection(:drivers)
11
+ end
12
+
13
+ it 'has index operation' do
14
+ @collection.operation(:index).must_equal Sinatra::Rabbit::DriversCollection::IndexOperation
15
+ end
16
+
17
+ it 'has show operation' do
18
+ @collection.operation(:show).must_equal Sinatra::Rabbit::DriversCollection::ShowOperation
19
+ end
20
+
21
+ it 'returns list of drivers in various formats with index operation' do
22
+ formats.each do |format|
23
+ header 'Accept', format
24
+ get root_url + '/drivers'
25
+ status.must_equal 200
26
+ end
27
+ end
28
+
29
+ it 'returns details about driver in various formats with show operation' do
30
+ formats.each do |format|
31
+ header 'Accept', format
32
+ get root_url + '/drivers/mock'
33
+ status.must_equal 200
34
+ end
35
+ end
36
+
37
+ end
@@ -0,0 +1,53 @@
1
+ require 'rubygems'
2
+ require 'require_relative' if RUBY_VERSION < '1.9'
3
+
4
+ require_relative File.join('..', 'common.rb')
5
+
6
+ describe Deltacloud::Collections::HardwareProfiles do
7
+
8
+ before do
9
+ def app; Deltacloud::API; end
10
+ authorize 'mockuser', 'mockpassword'
11
+ @collection = Deltacloud::Collections.collection(:hardware_profiles)
12
+ end
13
+
14
+ it 'has index operation' do
15
+ @collection.operation(:index).must_equal Sinatra::Rabbit::HardwareProfilesCollection::IndexOperation
16
+ end
17
+
18
+ it 'has show operation' do
19
+ @collection.operation(:show).must_equal Sinatra::Rabbit::HardwareProfilesCollection::ShowOperation
20
+ end
21
+
22
+ it 'returns list of hardware profiles in various formats with index operation' do
23
+ formats.each do |format|
24
+ header 'Accept', format
25
+ get root_url + '/hardware_profiles'
26
+ status.must_equal 200
27
+ end
28
+ end
29
+
30
+ it 'returns details about hardware profile in various formats with show operation' do
31
+ formats.each do |format|
32
+ header 'Accept', format
33
+ get root_url + '/hardware_profiles/m1-small'
34
+ status.must_equal 200
35
+ end
36
+ end
37
+
38
+ it 'returns details for various hardware profile configurations' do
39
+ get root_url + '/hardware_profiles'
40
+ status.must_equal 200
41
+ (xml/'hardware_profiles/hardware_profile').each do |hwp|
42
+ get root_url + '/hardware_profiles/' + hwp[:id]
43
+ status.must_equal 200
44
+ xml.root[:id].must_equal hwp[:id]
45
+ end
46
+ end
47
+
48
+ it 'reports 404 when querying non-existing hardware profile' do
49
+ get root_url + '/hardware_profiles/unknown'
50
+ status.must_equal 404
51
+ end
52
+
53
+ end