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
@@ -1,48 +1,73 @@
1
- $:.unshift File.join(File.dirname(__FILE__), '..', '..', '..')
2
- require 'tests/drivers/rhevm/common'
1
+ require 'minitest/autorun'
3
2
 
4
- module RHEVMTest
3
+ require_relative File.join('..', '..', '..', 'lib', 'deltacloud', 'api.rb')
4
+ require_relative 'common.rb'
5
5
 
6
- class ImagesTest < Test::Unit::TestCase
7
- include Rack::Test::Methods
6
+ describe 'RhevmDriver Images' do
8
7
 
9
- def app
10
- Rack::Builder.new {
11
- map '/' do
12
- use Rack::Static, :urls => ["/stylesheets", "/javascripts"], :root => "public"
13
- run Rack::Cascade.new([Deltacloud::API])
14
- end
15
- }
16
- end
8
+ before do
9
+ @driver = Deltacloud::new(:rhevm, credentials)
10
+ VCR.insert_cassette __name__
11
+ end
12
+
13
+ after do
14
+ VCR.eject_cassette
15
+ end
17
16
 
18
- def test_01_it_returns_images
19
- get_auth_url '/api;driver=rhevm/images'
20
- puts last_response.body
21
- (last_xml_response/'images/image').length.should > 0
17
+ it 'must throw error when wrong credentials' do
18
+ Proc.new do
19
+ @driver.backend.images(OpenStruct.new(:user => 'unknown', :password => 'wrong'))
20
+ end.must_raise Deltacloud::ExceptionHandler::AuthenticationFailure, 'Authentication Failure'
21
+ end
22
+
23
+ it 'must return list of images' do
24
+ @driver.images.wont_be_empty
25
+ @driver.images.first.must_be_kind_of Image
26
+ end
27
+
28
+ it 'must allow to filter images' do
29
+ @driver.images(:id => 'dfa924b7-83e8-4a5c-9d5c-1270fd0c0872').wont_be_empty
30
+ @driver.images(:id => 'dfa924b7-83e8-4a5c-9d5c-1270fd0c0872').must_be_kind_of Array
31
+ @driver.images(:id => 'dfa924b7-83e8-4a5c-9d5c-1270fd0c0872').size.must_equal 1
32
+ @driver.images(:id => 'dfa924b7-83e8-4a5c-9d5c-1270fd0c0872').first.id.must_equal 'dfa924b7-83e8-4a5c-9d5c-1270fd0c0872'
33
+ @driver.images(:owner_id => 'vdcadmin@rhev.lab.eng.brq.redhat.com').each do |img|
34
+ img.owner_id.must_equal 'vdcadmin@rhev.lab.eng.brq.redhat.com'
22
35
  end
36
+ @driver.images(:id => 'ami-aaaaaaaa').must_be_empty
37
+ @driver.images(:id => 'unknown').must_be_empty
38
+ end
23
39
 
24
- def test_02_each_image_has_correct_properties
25
- get_auth_url '/api;driver=rhevm/images'
26
- (last_xml_response/'images/image').each do |image|
27
- (image/'name').should_not == nil
28
- (image/'name').should_not == ''
29
- (image/'description').should_not == nil
30
- (image/'description').should_not == ''
31
- (image/'architecture').should_not == nil
32
- (image/'architecture').should_not == ''
33
- (image/'state').text.should == 'OK'
34
- (image/'owner_id').text.should == ENV['API_USER']
35
- (image/'actions/link').length.should == 1
36
- (image/'actions/link').first[:rel].should == 'create_instance'
37
- end
40
+ it 'must allow to retrieve single image' do
41
+ # NOTE: This test will cause VCR to fail due to wrong serialization
42
+ # of YAML under Ruby 1.8.
43
+ #
44
+ if RUBY_VERSION =~ /^1\.9/
45
+ @driver.image(:id => 'dfa924b7-83e8-4a5c-9d5c-1270fd0c0872').wont_be_nil
46
+ @driver.image(:id => 'dfa924b7-83e8-4a5c-9d5c-1270fd0c0872').must_be_kind_of Image
47
+ @driver.image(:id => 'dfa924b7-83e8-4a5c-9d5c-1270fd0c0872').id.must_equal 'dfa924b7-83e8-4a5c-9d5c-1270fd0c0872'
48
+ @driver.image(:id => 'ami-aaaaaaaa').must_be_nil
49
+ @driver.image(:id => 'unknown').must_be_nil
38
50
  end
51
+ end
39
52
 
40
- def test_03_it_returns_single_image
41
- get_auth_url '/api;driver=rhevm/images/3e82e2d5-913f-4095-ae72-ebcfa9d0571d'
42
- (last_xml_response/'image').length.should == 1
43
- (last_xml_response/'image/name').text.should == 'f15-minimal-2'
44
- (last_xml_response/'image/state').text.should == 'OK'
53
+ it 'must throw proper exception when destroying used image' do
54
+ if RUBY_VERSION =~ /^1\.9/
55
+ image = @driver.image(:id => 'dfa924b7-83e8-4a5c-9d5c-1270fd0c0872')
56
+ image.wont_be_nil
57
+ image.state.must_equal 'OK'
58
+ Proc.new {
59
+ @driver.destroy_image(image.id)
60
+ }.must_raise Deltacloud::ExceptionHandler::BackendError, 'Cannot delete Template. Template is being used by the following VMs: test1.'
45
61
  end
62
+ end
46
63
 
64
+ it 'must support destroying images' do
65
+ image = @driver.image(:id => 'a90de8a2-0619-4625-b72e-db0ff65ef927')
66
+ image.wont_be_nil
67
+ image.state.must_equal 'OK'
68
+ @driver.destroy_image(image.id)
69
+ image.wait_for!(@driver) { |img| img.nil? }
47
70
  end
71
+
48
72
  end
73
+
@@ -0,0 +1,104 @@
1
+ require 'minitest/autorun'
2
+
3
+ require_relative File.join('..', '..', '..', 'lib', 'deltacloud', 'api.rb')
4
+ require_relative 'common.rb'
5
+
6
+ describe 'RhevmDriver Instances' do
7
+
8
+ before do
9
+ @driver = Deltacloud::new(:rhevm, credentials)
10
+ VCR.insert_cassette __name__
11
+ end
12
+
13
+ after do
14
+ VCR.eject_cassette
15
+ end
16
+
17
+ it 'must throw error when wrong credentials' do
18
+ Proc.new do
19
+ @driver.backend.images(OpenStruct.new(:user => 'unknown', :password => 'wrong'))
20
+ end.must_raise Deltacloud::ExceptionHandler::AuthenticationFailure, 'Authentication Failure'
21
+ end
22
+
23
+ it 'must return list of instances' do
24
+ @driver.instances.wont_be_empty
25
+ @driver.instances.first.must_be_kind_of Instance
26
+ end
27
+
28
+ it 'must allow to filter instances' do
29
+ @driver.instances(:id => 'c63758d9-3db6-47ca-8412-4f517946910e').wont_be_empty
30
+ @driver.instances(:id => 'c63758d9-3db6-47ca-8412-4f517946910e').must_be_kind_of Array
31
+ @driver.instances(:id => 'c63758d9-3db6-47ca-8412-4f517946910e').size.must_equal 1
32
+ @driver.instances(:id => 'c63758d9-3db6-47ca-8412-4f517946910e').first.id.must_equal 'c63758d9-3db6-47ca-8412-4f517946910e'
33
+ @driver.instances(:owner_id => 'vdcadmin@rhev.lab.eng.brq.redhat.com').wont_be_empty
34
+ @driver.instances(:owner_id => 'vdcadmin@rhev.lab.eng.brq.redhat.com').each do |inst|
35
+ inst.owner_id.must_equal 'vdcadmin@rhev.lab.eng.brq.redhat.com'
36
+ end
37
+ @driver.instances(:id => 'i-00000000').must_be_empty
38
+ @driver.instances(:id => 'unknown').must_be_empty
39
+ end
40
+
41
+ it 'must allow to retrieve single instance' do
42
+ @driver.instance(:id => 'c63758d9-3db6-47ca-8412-4f517946910e').wont_be_nil
43
+ @driver.instance(:id => 'c63758d9-3db6-47ca-8412-4f517946910e').must_be_kind_of Instance
44
+ @driver.instance(:id => 'c63758d9-3db6-47ca-8412-4f517946910e').id.must_equal 'c63758d9-3db6-47ca-8412-4f517946910e'
45
+ @driver.instance(:id => 'i-00000000').must_be_nil
46
+ @driver.instance(:id => 'unknown').must_be_nil
47
+ end
48
+
49
+ it 'must allow to create a new instance and destroy it' do
50
+ instance = @driver.create_instance('dfa924b7-83e8-4a5c-9d5c-1270fd0c0872',
51
+ :realm_id => '3c8af388-cff6-11e0-9267-52540013f702',
52
+ :hwp_id => 'SERVER',
53
+ :hwp_memory => '1024',
54
+ :user_data => 'test user data'
55
+ )
56
+ instance = instance.wait_for!(@driver, record_retries) { |i| i.is_stopped? }
57
+ instance.must_be_kind_of Instance
58
+ instance.is_running?.must_equal false
59
+ @driver.instance(:id => instance.id).wont_be_nil
60
+ @driver.instance(:id => instance.id).id.must_equal instance.id
61
+ @driver.instance(:id => instance.id).name.wont_be_nil
62
+ @driver.instance(:id => instance.id).instance_profile.name.must_equal 'SERVER'
63
+ @driver.instance(:id => instance.id).instance_profile.memory.must_equal 1024
64
+ @driver.instance(:id => instance.id).realm_id.must_equal '3c8af388-cff6-11e0-9267-52540013f702'
65
+ @driver.instance(:id => instance.id).image_id.must_equal 'dfa924b7-83e8-4a5c-9d5c-1270fd0c0872'
66
+ @driver.instance(:id => instance.id).owner_id.must_equal 'vdcadmin@rhev.lab.eng.brq.redhat.com'
67
+ @driver.instance(:id => instance.id).state.must_equal 'STOPPED'
68
+ @driver.instance(:id => instance.id).actions.must_include :start
69
+ @driver.destroy_instance(instance.id)
70
+ instance.wait_for!(@driver, record_retries('destroy')) { |i| i.nil? }
71
+ end
72
+
73
+ it 'must allow to create a new instance and make it running' do
74
+ instance = @driver.create_instance('5f411ae4-a3cf-48a8-8bca-d049ddd51f0b',
75
+ :realm_id => '3c8af388-cff6-11e0-9267-52540013f702',
76
+ :hwp_id => 'SERVER',
77
+ :hwp_memory => '1024',
78
+ :user_data => 'test user data'
79
+ )
80
+ instance = instance.wait_for!(@driver, record_retries) { |i| i.is_stopped? }
81
+ instance.must_be_kind_of Instance
82
+ instance.is_running?.must_equal false
83
+ @driver.instance(:id => instance.id).wont_be_nil
84
+ @driver.instance(:id => instance.id).id.must_equal instance.id
85
+ @driver.instance(:id => instance.id).name.wont_be_nil
86
+ @driver.instance(:id => instance.id).instance_profile.name.must_equal 'SERVER'
87
+ @driver.instance(:id => instance.id).instance_profile.memory.must_equal 1024
88
+ @driver.instance(:id => instance.id).realm_id.must_equal '3c8af388-cff6-11e0-9267-52540013f702'
89
+ @driver.instance(:id => instance.id).image_id.must_equal '5f411ae4-a3cf-48a8-8bca-d049ddd51f0b'
90
+ @driver.instance(:id => instance.id).owner_id.must_equal 'vdcadmin@rhev.lab.eng.brq.redhat.com'
91
+ @driver.instance(:id => instance.id).state.must_equal 'STOPPED'
92
+ @driver.instance(:id => instance.id).actions.must_include :start
93
+ @driver.start_instance(instance.id)
94
+ instance = instance.wait_for!(@driver, record_retries('start')) { |i| i.is_running? }
95
+ @driver.instance(:id => instance.id).state.must_equal 'RUNNING'
96
+ Proc.new { @driver.destroy_instance(instance.id) }.must_raise Deltacloud::ExceptionHandler::BackendError, 'Cannot remove VM. VM is running.'
97
+ @driver.stop_instance(instance.id)
98
+ instance = instance.wait_for!(@driver, record_retries('stop')) { |i| i.is_stopped? }
99
+ @driver.instance(:id => instance.id).state.must_equal 'STOPPED'
100
+ @driver.destroy_instance(instance.id)
101
+ instance.wait_for!(@driver, record_retries('destroy')) { |i| i.nil? }
102
+ end
103
+
104
+ end
@@ -0,0 +1,48 @@
1
+ require 'minitest/autorun'
2
+
3
+ require_relative File.join('..', '..', '..', 'lib', 'deltacloud', 'api.rb')
4
+ require_relative 'common.rb'
5
+
6
+ describe 'RHEV-M provider test' do
7
+
8
+ before do
9
+ @driver = Deltacloud::new(:rhevm, credentials)
10
+ VCR.insert_cassette __name__
11
+ end
12
+
13
+ after do
14
+ VCR.eject_cassette
15
+ end
16
+
17
+ it 'must throw error when using wrong provider' do
18
+ wrong_driver = Deltacloud::new(:rhevm, credentials.merge(:provider => 'unknown'))
19
+ Proc.new {
20
+ wrong_driver.realms
21
+ }.must_raise Deltacloud::ExceptionHandler::BackendError
22
+ end
23
+
24
+ it 'must support listing of available providers' do
25
+ @driver.providers.wont_be_empty
26
+ @driver.providers.each { |p| p.must_be_kind_of Provider }
27
+ @driver.providers.each { |p| p.name.wont_be_empty }
28
+ @driver.providers.each { |p| p.id.wont_be_empty }
29
+ @driver.providers.each { |p| p.url.wont_be_empty }
30
+ end
31
+
32
+ it 'must switch realms when switching between different clusters' do
33
+
34
+ provider1 = @driver.provider(:id => 'aa585157-a098-48c3-8b5b-70a32e88c263')
35
+ provider1.wont_be_nil
36
+ provider1.url.wont_be_empty
37
+
38
+ provider2 = @driver.provider(:id => '645e425e-66fe-4ac9-8874-537bd10ef08d')
39
+ provider2.wont_be_nil
40
+ provider2.url.wont_be_empty
41
+
42
+ drv1 = Deltacloud::new(:rhevm, credentials.merge(:provider => provider1.url))
43
+ drv2 = Deltacloud::new(:rhevm, credentials.merge(:provider => provider2.url))
44
+
45
+ drv1.realms.map { |r| r.id }.wont_include drv2.realms.map { |r| r.id }
46
+ end
47
+
48
+ end
@@ -1,40 +1,43 @@
1
- $:.unshift File.join(File.dirname(__FILE__), '..', '..', '..')
2
- require 'tests/drivers/rhevm/common'
3
-
4
- module RHEVMTest
5
-
6
- class RealmsTest < Test::Unit::TestCase
7
- include Rack::Test::Methods
8
-
9
- def app
10
- Rack::Builder.new {
11
- map '/' do
12
- use Rack::Static, :urls => ["/stylesheets", "/javascripts"], :root => "public"
13
- run Rack::Cascade.new([Deltacloud::API])
14
- end
15
- }
16
- end
17
-
18
- def test_01_it_returns_realms
19
- get_auth_url '/api;driver=rhevm/realms'
20
- (last_xml_response/'realms/realm').length.should == 1
21
- end
22
-
23
- def test_02_each_realm_has_a_name
24
- get_auth_url '/api;driver=rhevm/realms'
25
- (last_xml_response/'realms/realm').each do |profile|
26
- (profile/'name').text.should_not == nil
27
- (profile/'name').text.should_not == ''
28
- (profile/'name').text.should_not == 'Default'
29
- end
30
- end
31
-
32
- def test_03_it_returns_single_realm
33
- get_auth_url '/api;driver=rhevm/realms/3c8af388-cff6-11e0-9267-52540013f702'
34
- (last_xml_response/'realm').first[:id].should == '3c8af388-cff6-11e0-9267-52540013f702'
35
- (last_xml_response/'realm/name').first.text.should == 'engops-nfs'
36
- (last_xml_response/'realm/state').first.text.should == 'AVAILABLE'
37
- end
1
+ require 'minitest/autorun'
38
2
 
3
+ require_relative File.join('..', '..', '..', 'lib', 'deltacloud', 'api.rb')
4
+ require_relative 'common.rb'
5
+
6
+ describe 'RhevmDriver Realms' do
7
+
8
+ before do
9
+ @driver = Deltacloud::new(:rhevm, credentials)
10
+ VCR.insert_cassette __name__
11
+ end
12
+
13
+ after do
14
+ VCR.eject_cassette
15
+ end
16
+
17
+ it 'must throw error when wrong credentials' do
18
+ Proc.new do
19
+ @driver.backend.realms(OpenStruct.new(:user => 'unknown', :password => 'wrong'))
20
+ end.must_raise Deltacloud::ExceptionHandler::AuthenticationFailure, 'Authentication Failure'
21
+ end
22
+
23
+ it 'must return list of realms' do
24
+ @driver.realms.wont_be_empty
25
+ @driver.realms.first.must_be_kind_of Realm
26
+ end
27
+
28
+ it 'must allow to filter realms' do
29
+ @driver.realms(:id => '3c8af388-cff6-11e0-9267-52540013f702').wont_be_empty
30
+ @driver.realms(:id => '3c8af388-cff6-11e0-9267-52540013f702').must_be_kind_of Array
31
+ @driver.realms(:id => '3c8af388-cff6-11e0-9267-52540013f702').size.must_equal 1
32
+ @driver.realms(:id => '3c8af388-cff6-11e0-9267-52540013f702').first.id.must_equal '3c8af388-cff6-11e0-9267-52540013f702'
33
+ @driver.realms(:id => 'unknown').must_be_empty
39
34
  end
35
+
36
+ it 'must allow to retrieve single realm' do
37
+ @driver.realm(:id => '3c8af388-cff6-11e0-9267-52540013f702').wont_be_nil
38
+ @driver.realm(:id => '3c8af388-cff6-11e0-9267-52540013f702').must_be_kind_of Realm
39
+ @driver.realm(:id => 'unknown').must_be_nil
40
+ end
41
+
40
42
  end
43
+
@@ -0,0 +1,24 @@
1
+ require 'rubygems'
2
+ require 'require_relative' if RUBY_VERSION < '1.9'
3
+ require 'minitest/autorun'
4
+
5
+ require_relative File.join('..', '..', 'lib', 'deltacloud_rack.rb')
6
+ require_relative '../test_helper.rb'
7
+
8
+ # Setup Deltacloud::API Sinatra instance
9
+ #
10
+
11
+ Deltacloud::configure(:ec2) do |server|
12
+ server.root_url '/'
13
+ server.version '2012-04-01'
14
+ server.klass 'Deltacloud::EC2::API'
15
+ server.logger Rack::DeltacloudLogger.setup(ENV['API_LOG'], ENV['API_VERBOSE'])
16
+ server.default_driver :mock
17
+ end
18
+
19
+ Deltacloud.require_frontend! :ec2
20
+
21
+ Deltacloud[:ec2].require!
22
+ Deltacloud[:ec2].default_frontend!
23
+
24
+ def root_url; Deltacloud.config[:ec2].root_url; end
@@ -0,0 +1,98 @@
1
+ require 'rubygems'
2
+ require 'require_relative' if RUBY_VERSION < '1.9'
3
+ require_relative './common.rb'
4
+
5
+ require_relative File.join('..', '..', 'lib', 'deltacloud', 'api.rb')
6
+
7
+ describe Deltacloud::EC2 do
8
+
9
+ describe Deltacloud::EC2::ActionHandler do
10
+
11
+ before do
12
+ @handler = Deltacloud::EC2::ActionHandler
13
+ end
14
+
15
+ it 'provides access to mappings' do
16
+ @handler.mappings.wont_be_nil
17
+ @handler.mappings.must_be_kind_of Hash
18
+ end
19
+
20
+ end
21
+
22
+ describe Deltacloud::EC2::QueryParser do
23
+
24
+ before do
25
+ @parser = Deltacloud::EC2::QueryParser
26
+ end
27
+
28
+ it 'parse request parameters and assign the action' do
29
+ result = @parser.parse({'Action' => 'DescribeAvailabilityZones', 'ZoneName.1' => 'us'}, '1')
30
+ result.wont_be_nil
31
+ result.must_be_kind_of Deltacloud::EC2::ActionHandler
32
+ result.action.wont_be_nil
33
+ result.action.must_be_kind_of @parser
34
+ result.action.action.must_equal :describe_availability_zones
35
+ result.action.request_id.must_equal '1'
36
+ result.action.parameters.wont_be_nil
37
+ result.action.parameters.must_be_kind_of Hash
38
+ result.action.parameters['ZoneName.1'].must_equal 'us'
39
+ end
40
+
41
+ it 'must provide verification for actions' do
42
+ result = @parser.parse({'Action' => 'DescribeAvailabilityZones', 'ZoneName.1' => 'us'}, '1')
43
+ result.wont_be_nil
44
+ result.must_be_kind_of Deltacloud::EC2::ActionHandler
45
+ result.action.wont_be_nil
46
+ result.action.must_be_kind_of @parser
47
+ result.action.valid_actions.wont_be_nil
48
+ result.action.valid_actions.must_include :describe_availability_zones
49
+ result.action.valid_action?.must_equal true
50
+ end
51
+
52
+ it 'must provide the Deltacloud method for EC2 action' do
53
+ result = @parser.parse({'Action' => 'DescribeAvailabilityZones', 'ZoneName.1' => 'us'}, '1')
54
+ result.wont_be_nil
55
+ result.must_be_kind_of Deltacloud::EC2::ActionHandler
56
+ result.deltacloud_method.must_equal :realms
57
+ result.deltacloud_method_params[:id].wont_be_nil
58
+ result.deltacloud_method_params[:id].must_equal 'us'
59
+ end
60
+
61
+ end
62
+
63
+ describe Deltacloud::EC2::ResultParser do
64
+
65
+ before do
66
+ @parser = Deltacloud::EC2::QueryParser
67
+ @driver = Deltacloud::new(:mock, :user => 'mockuser', :password => 'mockpassword')
68
+ def app; Deltacloud::EC2::API; end
69
+ end
70
+
71
+ it 'must perform the EC2 action on Deltacloud driver' do
72
+ result = @parser.parse({'Action' => 'DescribeAvailabilityZones', 'ZoneName.1' => 'us'}, '1')
73
+ result.wont_be_nil
74
+ result.must_be_kind_of Deltacloud::EC2::ActionHandler
75
+ result.action.wont_be_nil
76
+ result.action.must_be_kind_of @parser
77
+ result.must_respond_to :'perform!'
78
+ realms = result.perform!(@driver.credentials, @driver.backend)
79
+ realms.wont_be_empty
80
+ realms.first.must_be_kind_of Realm
81
+ realms.first.id.must_equal 'us'
82
+ end
83
+
84
+ it 'must parse the result of EC2 action to EC2 formatted XML' do
85
+ result = @parser.parse({'Action' => 'DescribeAvailabilityZones', 'ZoneName.1' => 'us'}, '1')
86
+ result.wont_be_nil
87
+ result.must_be_kind_of Deltacloud::EC2::ActionHandler
88
+ result.action.wont_be_nil
89
+ result.action.must_be_kind_of @parser
90
+ result.must_respond_to :'perform!'
91
+ result.perform!(@driver.credentials, @driver.backend)
92
+ result = Nokogiri::XML(result.to_xml(app))
93
+ result.root.name.must_equal 'DescribeAvailabilityZonesResponse'
94
+ end
95
+
96
+ end
97
+
98
+ end