deltacloud-core 1.0.2 → 1.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (187) hide show
  1. data/Rakefile +2 -1
  2. data/bin/deltacloudd +11 -5
  3. data/config.ru +3 -3
  4. data/deltacloud-core.gemspec +24 -18
  5. data/lib/cimi/collections/address_templates.rb +3 -3
  6. data/lib/cimi/collections/addresses.rb +6 -5
  7. data/lib/cimi/collections/entity_metadata.rb +0 -2
  8. data/lib/cimi/collections/machine_admins.rb +5 -5
  9. data/lib/cimi/collections/machine_configurations.rb +2 -2
  10. data/lib/cimi/collections/machine_images.rb +3 -3
  11. data/lib/cimi/collections/machines.rb +32 -10
  12. data/lib/cimi/collections/network_configurations.rb +4 -3
  13. data/lib/cimi/collections/network_templates.rb +4 -3
  14. data/lib/cimi/collections/networks.rb +8 -8
  15. data/lib/cimi/collections/routing_group_templates.rb +4 -3
  16. data/lib/cimi/collections/routing_groups.rb +4 -3
  17. data/lib/cimi/collections/volume_configurations.rb +3 -3
  18. data/lib/cimi/collections/volume_images.rb +3 -3
  19. data/lib/cimi/collections/volumes.rb +4 -3
  20. data/lib/cimi/collections/vsp_configurations.rb +4 -3
  21. data/lib/cimi/collections/vsp_templates.rb +4 -3
  22. data/lib/cimi/collections/vsps.rb +8 -7
  23. data/lib/cimi/helpers.rb +1 -1
  24. data/lib/cimi/helpers/cimi_helper.rb +11 -1
  25. data/lib/cimi/models.rb +4 -0
  26. data/lib/cimi/models/base.rb +11 -1
  27. data/lib/cimi/models/cloud_entry_point.rb +7 -14
  28. data/lib/cimi/models/disk.rb +40 -0
  29. data/lib/cimi/models/disk_collection.rb +38 -0
  30. data/lib/cimi/models/machine.rb +9 -43
  31. data/lib/cimi/models/machine_collection.rb +7 -4
  32. data/lib/cimi/models/machine_configuration.rb +8 -15
  33. data/lib/cimi/models/machine_configuration_collection.rb +6 -4
  34. data/lib/cimi/models/machine_image_collection.rb +6 -4
  35. data/lib/cimi/models/machine_template_collection.rb +6 -4
  36. data/lib/cimi/models/machine_volume.rb +42 -0
  37. data/lib/cimi/models/machine_volume_collection.rb +34 -0
  38. data/lib/cimi/models/network.rb +5 -9
  39. data/lib/cimi/models/network_collection.rb +6 -5
  40. data/lib/cimi/models/schema.rb +20 -0
  41. data/lib/cimi/models/volume_collection.rb +6 -4
  42. data/lib/cimi/models/volume_configuration_collection.rb +6 -4
  43. data/lib/cimi/models/volume_image_collection.rb +6 -4
  44. data/lib/cimi/models/volume_template_collection.rb +6 -4
  45. data/lib/deltacloud/api.rb +3 -3
  46. data/lib/deltacloud/collections/addresses.rb +1 -1
  47. data/lib/deltacloud/collections/firewalls.rb +4 -2
  48. data/lib/deltacloud/collections/keys.rb +1 -1
  49. data/lib/deltacloud/collections/load_balancers.rb +1 -1
  50. data/lib/deltacloud/collections/storage_volumes.rb +4 -4
  51. data/lib/deltacloud/drivers/base_driver.rb +12 -20
  52. data/lib/deltacloud/drivers/ec2/aws_vpc_monkey_patch.rb +294 -0
  53. data/lib/deltacloud/drivers/ec2/ec2_driver.rb +38 -6
  54. data/lib/deltacloud/drivers/fgcp/fgcp_client.rb +4 -0
  55. data/lib/deltacloud/drivers/fgcp/fgcp_driver.rb +40 -4
  56. data/lib/deltacloud/drivers/gogrid/gogrid_client.rb +8 -7
  57. data/lib/deltacloud/drivers/gogrid/gogrid_driver.rb +422 -416
  58. data/lib/deltacloud/drivers/google/google_driver.rb +2 -1
  59. data/lib/deltacloud/drivers/openstack/openstack_driver.rb +30 -16
  60. data/lib/deltacloud/drivers/rhevm/rhevm_driver.rb +1 -0
  61. data/lib/deltacloud/drivers/vsphere/vsphere_driver.rb +3 -9
  62. data/lib/deltacloud/helpers/deltacloud_helper.rb +0 -2
  63. data/lib/deltacloud/models/firewall_rule.rb +2 -0
  64. data/lib/deltacloud/models/hardware_profile.rb +61 -59
  65. data/{tests/deprecated/core_ext/string.rb → lib/deltacloud/version.rb} +3 -15
  66. data/lib/deltacloud_rack.rb +1 -0
  67. data/lib/ec2/server.rb +5 -3
  68. data/lib/sinatra/rack_accept.rb +53 -53
  69. data/lib/sinatra/rack_etag.rb +1 -1
  70. data/tests/cimi/collections/cloud_entry_point_test.rb +11 -2
  71. data/tests/deltacloud/common.rb +1 -1
  72. data/tests/deltacloud/rack_test.rb +3 -3
  73. data/tests/drivers/base/base_driver_test.rb +6 -2
  74. data/tests/drivers/base/common.rb +1 -0
  75. data/tests/drivers/base/library_test.rb +6 -2
  76. data/tests/drivers/ec2/common.rb +34 -15
  77. data/tests/drivers/ec2/images_test.rb +2 -3
  78. data/tests/drivers/ec2/instance_test.rb +12 -2
  79. data/tests/drivers/ec2/keys_test.rb +2 -2
  80. data/tests/drivers/ec2/realms_test.rb +7 -3
  81. data/tests/drivers/ec2/storage_snapshots_test.rb +2 -3
  82. data/tests/drivers/gogrid/common.rb +24 -0
  83. data/tests/drivers/gogrid/hardware_profiles_test.rb +51 -0
  84. data/tests/drivers/gogrid/images_test.rb +57 -0
  85. data/tests/drivers/gogrid/instances_test.rb +92 -0
  86. data/tests/drivers/gogrid/realms_test.rb +45 -0
  87. data/tests/drivers/google/buckets_test.rb +105 -0
  88. data/tests/drivers/google/common.rb +20 -0
  89. data/tests/drivers/mock/common.rb +1 -0
  90. data/tests/drivers/mock/images_test.rb +3 -2
  91. data/tests/drivers/mock/instances_test.rb +3 -2
  92. data/tests/drivers/mock/keys_test.rb +3 -2
  93. data/tests/drivers/mock/realms_test.rb +3 -2
  94. data/tests/drivers/mock/storage_snapshots_test.rb +3 -2
  95. data/tests/drivers/mock/storage_volumes_test.rb +3 -2
  96. data/tests/drivers/models/address_test.rb +3 -3
  97. data/tests/drivers/models/base_test.rb +4 -2
  98. data/tests/drivers/models/blob_test.rb +3 -3
  99. data/tests/drivers/models/common.rb +3 -0
  100. data/tests/drivers/models/hardware_profile_test.rb +5 -4
  101. data/tests/drivers/models/instance_address_test.rb +3 -3
  102. data/tests/drivers/models/instance_profile_test.rb +3 -3
  103. data/tests/drivers/models/instance_test.rb +3 -3
  104. data/tests/drivers/models/keys_test.rb +3 -3
  105. data/tests/drivers/models/metrics_test.rb +3 -3
  106. data/tests/drivers/openstack/common.rb +26 -0
  107. data/tests/drivers/openstack/hardware_profiles_test.rb +46 -0
  108. data/tests/drivers/openstack/images_test.rb +50 -0
  109. data/tests/drivers/openstack/instances_test.rb +66 -0
  110. data/tests/drivers/openstack/keys_test.rb +61 -0
  111. data/tests/drivers/openstack/realms_test.rb +46 -0
  112. data/tests/drivers/rhevm/common.rb +2 -0
  113. data/tests/drivers/rhevm/images_test.rb +3 -4
  114. data/tests/drivers/rhevm/instance_test.rb +2 -2
  115. data/tests/drivers/rhevm/provider_test.rb +2 -2
  116. data/tests/drivers/rhevm/realms_test.rb +2 -3
  117. data/tests/ec2/common.rb +5 -4
  118. data/tests/ec2/server_test.rb +3 -2
  119. data/tests/helpers/rack/common.rb +3 -0
  120. data/tests/helpers/rack/rack_accept_test.rb +65 -0
  121. data/tests/helpers/rack/rack_date_test.rb +27 -0
  122. data/tests/helpers/rack/rack_driver_select_test.rb +53 -0
  123. data/tests/helpers/rack/rack_etag_test.rb +29 -0
  124. data/tests/helpers/rack/rack_matrix_params_test.rb +72 -0
  125. data/tests/test_helper.rb +44 -36
  126. data/views/hardware_profiles/index.html.haml +1 -1
  127. data/views/hardware_profiles/show.html.haml +2 -2
  128. data/views/hardware_profiles/show.xml.haml +2 -1
  129. data/views/images/show.html.haml +6 -5
  130. metadata +74 -117
  131. data/tests/deprecated/api/common.rb +0 -1
  132. data/tests/deprecated/api/driver_test.rb +0 -79
  133. data/tests/deprecated/api/library_test.rb +0 -6
  134. data/tests/deprecated/cimi/features/step_definitions/common_steps.rb +0 -59
  135. data/tests/deprecated/cimi/features/step_definitions/machine_images_steps.rb +0 -0
  136. data/tests/deprecated/cimi/features/step_definitions/machines_steps.rb +0 -100
  137. data/tests/deprecated/cimi/features/step_definitions/volumes_steps.rb +0 -115
  138. data/tests/deprecated/cimi/features/support/env.rb +0 -75
  139. data/tests/deprecated/common.rb +0 -279
  140. data/tests/deprecated/drivers/ec2/api_test.rb +0 -19
  141. data/tests/deprecated/drivers/ec2/common.rb +0 -23
  142. data/tests/deprecated/drivers/ec2/drivers_test.rb +0 -120
  143. data/tests/deprecated/drivers/ec2/hardware_profiles_test.rb +0 -224
  144. data/tests/deprecated/drivers/ec2/images_test.rb +0 -230
  145. data/tests/deprecated/drivers/ec2/instances_test.rb +0 -356
  146. data/tests/deprecated/drivers/ec2/keys_test.rb +0 -181
  147. data/tests/deprecated/drivers/ec2/realms_test.rb +0 -146
  148. data/tests/deprecated/drivers/fgcp/api_test.rb +0 -47
  149. data/tests/deprecated/drivers/fgcp/hardware_profiles_test.rb +0 -54
  150. data/tests/deprecated/drivers/fgcp/realms_test.rb +0 -42
  151. data/tests/deprecated/drivers/fgcp/setup.rb +0 -13
  152. data/tests/deprecated/drivers/google/api_test.rb +0 -19
  153. data/tests/deprecated/drivers/google/buckets_test.rb +0 -100
  154. data/tests/deprecated/drivers/google/common.rb +0 -54
  155. data/tests/deprecated/drivers/mock/api_test.rb +0 -10
  156. data/tests/deprecated/drivers/mock/buckets_test.rb +0 -195
  157. data/tests/deprecated/drivers/mock/common.rb +0 -7
  158. data/tests/deprecated/drivers/mock/drivers_test.rb +0 -123
  159. data/tests/deprecated/drivers/mock/hardware_profiles_test.rb +0 -224
  160. data/tests/deprecated/drivers/mock/images_test.rb +0 -197
  161. data/tests/deprecated/drivers/mock/instances_test.rb +0 -343
  162. data/tests/deprecated/drivers/mock/keys_test.rb +0 -161
  163. data/tests/deprecated/drivers/mock/realms_test.rb +0 -132
  164. data/tests/deprecated/drivers/mock/storage_snapshots_test.rb +0 -114
  165. data/tests/deprecated/drivers/mock/storage_volumes_test.rb +0 -122
  166. data/tests/deprecated/drivers/openstack/api_test.rb +0 -46
  167. data/tests/deprecated/drivers/openstack/common.rb +0 -21
  168. data/tests/deprecated/drivers/openstack/hardware_profiles_test.rb +0 -64
  169. data/tests/deprecated/drivers/openstack/images_test.rb +0 -46
  170. data/tests/deprecated/drivers/openstack/instances_test.rb +0 -208
  171. data/tests/deprecated/drivers/openstack/realms_test.rb +0 -40
  172. data/tests/deprecated/drivers/rackspace/api_test.rb +0 -46
  173. data/tests/deprecated/drivers/rackspace/buckets_test.rb +0 -150
  174. data/tests/deprecated/drivers/rackspace/common.rb +0 -16
  175. data/tests/deprecated/drivers/rackspace/hardware_profiles_test.rb +0 -58
  176. data/tests/deprecated/drivers/rackspace/images_test.rb +0 -45
  177. data/tests/deprecated/drivers/rackspace/instances_test.rb +0 -166
  178. data/tests/deprecated/drivers/rackspace/realms_test.rb +0 -41
  179. data/tests/deprecated/drivers/rhevm/api_test.rb +0 -45
  180. data/tests/deprecated/drivers/rhevm/common.rb +0 -21
  181. data/tests/deprecated/drivers/rhevm/hardware_profiles_test.rb +0 -58
  182. data/tests/deprecated/drivers/rhevm/images_test.rb +0 -48
  183. data/tests/deprecated/drivers/rhevm/instances_test.rb +0 -182
  184. data/tests/deprecated/drivers/rhevm/realms_test.rb +0 -40
  185. data/tests/deprecated/minitest_common.rb +0 -58
  186. data/tests/deprecated/minitest_common_api_test.rb +0 -115
  187. data/tests/deprecated/rabbit_test.rb +0 -52
@@ -1 +0,0 @@
1
- require 'minitest/autorun'
@@ -1,79 +0,0 @@
1
- require_relative './common'
2
- require_relative '../../lib/deltacloud/api'
3
-
4
- begin
5
- require 'arguments'
6
- rescue LoadError
7
- puts "You don't have 'rdp-arguments' gems installed. (gem install rdp-arguments)"
8
- exit(1)
9
- end
10
- require 'pp'
11
-
12
- describe 'Deltacloud drivers API' do
13
-
14
- before do
15
- @stderr = $stderr.clone
16
- $stderr = StringIO.new
17
- end
18
-
19
- after do
20
- $stderr = @stderr
21
- end
22
-
23
- it 'should pass the known method to Deltacloud driver' do
24
- Deltacloud.new(:mock).hardware_profiles.must_be_kind_of Array
25
- Deltacloud.new(:mock).hardware_profiles.wont_be_empty
26
- end
27
-
28
- it 'should raise NoMethodError when driver does not respond to method' do
29
- lambda { Deltacloud.new(:mock).non_existing_method }.must_raise NoMethodError
30
- end
31
-
32
- it 'should apply the credentials to methods that require them' do
33
- Deltacloud.new(:mock).realms.must_be_kind_of Array
34
- Deltacloud.new(:mock).realms.wont_be_empty
35
- end
36
-
37
- it 'should allow to use different drivers' do
38
- Deltacloud.new(:ec2).backend.must_be_instance_of Deltacloud::Drivers::Ec2::Ec2Driver
39
- Deltacloud.new(:mock).backend.must_be_instance_of Deltacloud::Drivers::Mock::MockDriver
40
- end
41
-
42
- it 'should support loading all supported drivers' do
43
- Deltacloud.drivers.keys.each do |key|
44
- Deltacloud.new(key).current_driver.must_equal key.to_s
45
- end
46
- end
47
-
48
- METHODS = {
49
- :firewalls => [[:credentials], [:opts, "{ }"]],
50
- :firewall => [[:credentials], [:opts, "{ }"]],
51
- :keys => [[:credentials], [:opts, "{ }"]],
52
- :key => [[:credentials], [:opts]],
53
- :storage_snapshots => [[:credentials], [:opts, "{ }"]],
54
- :storage_snapshot => [[:credentials], [:opts]],
55
- :storage_volumes => [[:credentials], [:opts, "{ }"]],
56
- :storage_volume => [[:credentials], [:opts]],
57
- :realms => [[:credentials], [:opts, "{ }"]],
58
- :realm => [[:credentials], [:opts]],
59
- :images => [[:credentials], [:opts, "{ }"]],
60
- :image => [[:credentials], [:opts]],
61
- :instances => [[:credentials], [:opts, "{ }"]],
62
- :instance => [[:credentials], [:opts]],
63
- :create_instance => [[:credentials], [:image_id], [:opts, "{ }"]],
64
- :destroy_instance => [[:credentials], [:id]],
65
- :stop_instance => [[:credentials], [:id]],
66
- :start_instance => [[:credentials], [:id]],
67
- :reboot_instance => [[:credentials], [:id]],
68
- }
69
-
70
- Deltacloud.drivers.keys.each do |key|
71
- METHODS.each do |m, definition|
72
- it "should have the correct parameters for the :#{m} method in #{key} driver" do
73
- next unless Deltacloud.new(key).backend.respond_to? m
74
- Arguments.names(Deltacloud.new(key).backend.class, m).must_equal definition
75
- end
76
- end
77
- end
78
-
79
- end
@@ -1,6 +0,0 @@
1
- require_relative './common'
2
- require_relative '../../lib/deltacloud/api'
3
-
4
- require 'pp'
5
-
6
-
@@ -1,59 +0,0 @@
1
- World(Rack::Test::Methods)
2
-
3
- Given /^Cloud Entry Point URL is provided$/ do
4
- get '/cimi'
5
- last_response.status.should == 301
6
- last_response.location.should == "http://example.org/cimi/cloudEntryPoint"
7
- end
8
-
9
- Given /^client retrieve the Cloud Entry Point$/ do
10
- get "/cimi/cloudEntryPoint"
11
- header 'Accept', 'application/xml'
12
- last_response.status.should == 200
13
- end
14
-
15
- When /^client lists ([\w ]+) collection$/ do |col_name|
16
- authorize 'mockuser', 'mockpassword'
17
- header 'Accept', 'application/xml'
18
- get "/cimi/%s" % col_name.to_collection_uri
19
- last_response.status.should == 200
20
- end
21
-
22
- Then /^client should get list of all ([\w ]+)$/ do |col_name|
23
- root_name = "#{col_name.to_collection_name}Collection"
24
- last_xml_response.root.name.should == root_name
25
- (last_xml_response/"#{root_name}/name").size.should == 1
26
- (last_xml_response/"#{root_name}/name").first.text.should == 'default'
27
- (last_xml_response/"#{root_name}/id").size.should == 1
28
- (last_xml_response/"#{root_name}/id").first.text.should == last_request.url
29
- (last_xml_response/"#{root_name}/#{col_name.to_entity_name}").size.should == 3
30
- (last_xml_response/"#{root_name}/#{col_name.to_entity_name}").each do |machine_img|
31
- machine_img[:href].should_not be_nil
32
- machine_img[:href].should =~ /http:\/\/example\.org\/cimi\/#{col_name.to_collection_uri}\/img(\d)/
33
- end
34
- end
35
-
36
- When /^client( should be able to)? query for '(\w+)' ([\w ]+) entity$/ do |s, entity_id, entity_name|
37
- authorize 'mockuser', 'mockpassword'
38
- header 'Accept', 'application/xml'
39
- get "/cimi/%s/%s" % [entity_name.to_entity_uri, entity_id]
40
- last_response.status.should == 200
41
- @entity_id = entity_id
42
- end
43
-
44
- Then /^client should verify that this ([\w ]+) exists$/ do |entity_name|
45
- root_name = entity_name.to_class_name
46
- last_xml_response.root.name.should == root_name
47
- @entity = last_xml_response
48
- end
49
-
50
- Then /^client should verify that this ([\w ]+) has set$/ do |entity, attrs|
51
- model = CIMI::Model.const_get(entity.to_class_name).from_xml(last_response.body)
52
- attrs.rows_hash.each do |key, value|
53
- if key =~ /^\*/
54
- model.send(key.gsub(/^\*/, '').intern).href.should == value
55
- else
56
- model.send(key.intern).to_s.should == value
57
- end
58
- end
59
- end
@@ -1,100 +0,0 @@
1
- When /^client specifies a Machine Image$/ do |machine_image|
2
- header 'Accept', 'application/xml'
3
- authorize 'mockuser', 'mockpassword'
4
- get machine_image.raw[0][1]
5
- last_response.status.should == 200
6
- @machine_image = CIMI::Model::MachineImage.from_xml(last_response.body)
7
- @machine_image.should_not be_nil
8
- @machine_image.id.should == machine_image.raw[0][1]
9
- end
10
-
11
- When /^client specifies a Machine Configuration$/ do |machine_conf|
12
- header 'Accept', 'application/xml'
13
- authorize 'mockuser', 'mockpassword'
14
- get machine_conf.raw[0][1]
15
- last_response.status.should == 200
16
- @machine_configuration = CIMI::Model::MachineImage.from_xml(last_response.body)
17
- @machine_configuration.should_not be_nil
18
- @machine_configuration.id.should == machine_conf.raw[0][1]
19
- end
20
-
21
- When /^client specifies a new Machine using$/ do |machine|
22
- @machine_image.should_not be_nil
23
- @machine_configuration.should_not be_nil
24
- @new_machine_name = machine.raw[0][1]
25
- @builder = Nokogiri::XML::Builder.new do |xml|
26
- xml.MachineCreate(:xmlns => CMWG_NAMESPACE) {
27
- xml.name @new_machine_name
28
- xml.description machine.raw[1][1]
29
- xml.machineTemplate {
30
- xml.machineConfig( :href => @machine_configuration.id )
31
- xml.machineImage( :href => @machine_image.id )
32
- }
33
- }
34
- end
35
- end
36
-
37
- Then /^client should be able to create this Machine$/ do
38
- authorize 'mockuser', 'mockpassword'
39
- header 'Content-Type', 'application/xml'
40
- post '/cimi/machines', @builder.to_xml
41
- if [500, 501, 502].include? last_response.status
42
- puts last_response.body
43
- end
44
- last_response.status.should == 201
45
- set_new_machine(CIMI::Model::Machine.from_xml(last_response.body))
46
- end
47
-
48
- Then /^client query for created Machine entity$/ do
49
- authorize 'mockuser', 'mockpassword'
50
- header 'Content-Type', 'application/xml'
51
- get "/cimi/machines/%s" % new_machine.name
52
- if [500, 501, 502].include? last_response.status
53
- puts last_response.body
54
- end
55
- if @delete_operation
56
- last_response.status.should == 404
57
- else
58
- last_response.status.should == 200
59
- @machine = CIMI::Model::Machine.from_xml(last_response.body)
60
- @machine.name.should == new_machine.name
61
- end
62
-
63
- end
64
-
65
- Then /^client should verify that this Machine has been created properly$/ do |attrs|
66
- attrs.rows_hash.each do |key, value|
67
- if key == 'memory'
68
- @machine.memory['quantity'].to_s.should == value
69
- else
70
- @machine.send(key.intern).to_s.should == value
71
- end
72
- end
73
- end
74
-
75
- When /^client executes (\w+) operation on created Machine$/ do |operation|
76
- builder = Nokogiri::XML::Builder.new do |xml|
77
- xml.Action(:xmlns => CMWG_NAMESPACE) {
78
- xml.action "http://www.dmtf.org/cimi/action/#{operation}"
79
- }
80
- end
81
- authorize 'mockuser', 'mockpassword'
82
- header 'Content-Type', 'application/xml'
83
- if operation == 'delete'
84
- delete "/cimi/machines/%s" % new_machine.name
85
- puts last_response.body
86
- last_response.status.should == 200
87
- last_response.body.should be_empty
88
- @delete_operation = true
89
- else
90
- post "/cimi/machines/%s/%s" % [new_machine.name, operation], builder.to_xml
91
- last_response.status.should == 202
92
- last_response.body.should be_empty
93
- end
94
- end
95
-
96
- Then /^client should verify that this machine is (\w+)$/ do |status|
97
- unless @delete_operation
98
- @machine.state.should == status.upcase
99
- end
100
- end
@@ -1,115 +0,0 @@
1
- When /^client specifies a Volume Configuration$/ do |volume_config|
2
- header 'Accept', 'application/xml'
3
- authorize 'mockuser', 'mockpassword'
4
- get volume_config.raw[0][1]
5
- last_response.status.should==200
6
- @volume_config = CIMI::Model::VolumeConfiguration.from_xml(last_response.body)
7
- @volume_config.class.should == CIMI::Model::VolumeConfiguration
8
- @volume_config.attribute_values[:capacity].quantity.should == "2"
9
- @volume_config.id.should == volume_config.raw[0][1]
10
- end
11
-
12
- When /^client specifies a new Volume using$/ do |volume|
13
- @volume_config.should_not be_nil
14
- volume_name = volume.raw[0][1]
15
- volume_description = volume.raw[1][1]
16
- @builder = Nokogiri::XML::Builder.new do |xml|
17
- xml.Volume(:xmlns => CMWG_NAMESPACE) {
18
- xml.name volume_name
19
- xml.description volume_description
20
- xml.volumeTemplate {
21
- xml.volumeConfig( :href => @volume_config.id )
22
- }
23
- }
24
- end
25
- end
26
-
27
- Then /^client should be able to create this Volume$/ do
28
- authorize 'mockuser', 'mockpassword'
29
- header 'Content-Type', 'application/xml'
30
- post '/cimi/volumes', @builder.to_xml
31
- last_response.status.should == 200
32
- @@created_volume = CIMI::Model::Volume.from_xml(last_response.body)
33
- end
34
-
35
- When /^client GET the Volumes Collection$/ do
36
- authorize 'mockuser', 'mockpassword'
37
- header 'Content-Type', 'application/xml'
38
- get "/cimi/volumes"
39
- last_response.status.should == 200
40
- @@volume_collection = CIMI::Model::VolumeCollection.from_xml(last_response.body)
41
- end
42
-
43
- Then /^client should get a list of volumes$/ do
44
- @@volume_collection.id.end_with?("/cimi/volumes").should == true
45
- @@volume_collection.attribute_values.has_key?(:volumes).should == true
46
- end
47
-
48
- Then /^list of volumes should contain newly created volume$/ do
49
- volumes = @@volume_collection.attribute_values[:volumes].map{|v| v.href.split("/").last}
50
- volumes.include?(@@created_volume.name).should == true
51
- end
52
-
53
- When /^client GET the newly created Volume in json format$/ do
54
- authorize 'mockuser', 'mockpassword'
55
- get "/cimi/volumes/#{@@created_volume.name}?format=json"
56
- last_response.status.should == 200
57
- @@retrieved_volume = CIMI::Model::Volume.from_json(last_response.body)
58
- end
59
-
60
- Then /^client should verify that this Volume was created correctly$/ do |capacity|
61
- @@retrieved_volume.name.should == @@created_volume.name
62
- @@retrieved_volume.id.should == @@created_volume.id
63
- @@retrieved_volume.capacity[:quantity].should == capacity.raw[0][1]
64
- end
65
-
66
- When /^client specifies a running Machine using$/ do |machine|
67
- @machine_id = machine.raw[0][1]
68
- authorize 'mockuser', 'mockpassword'
69
- header 'Content-Type', 'application/xml'
70
- get "/cimi/machines/#{@machine_id}?format=xml"
71
- last_response.status.should==200
72
- @@machine = CIMI::Model::Machine.from_xml(last_response.body)
73
- @@machine.name.should == @machine_id
74
- @@machine.state.should == "STARTED"
75
- end
76
-
77
- When /^client specifies the new Volume with attachment point using$/ do |attach|
78
- @builder = Nokogiri::XML::Builder.new do |xml|
79
- xml.VolumeAttach {
80
- xml.volume( :href => @@created_volume.id, :attachmentPoint=>attach.raw[0][1])
81
- }
82
- end
83
- end
84
-
85
- Then /^client should be able to attach the new volume to the Machine$/ do
86
- authorize 'mockuser', 'mockpassword'
87
- header 'Content-Type', 'application/CIMI-Machine+xml'
88
- put "/cimi/machines/#{@@machine.name}/attach_volume?format=xml", @builder.to_xml
89
- last_response.status.should == 200
90
- end
91
-
92
- When /^client should be able to detach the volume$/ do
93
- authorize 'mockuser', 'mockpassword'
94
- header 'Content-Type', 'application/CIMI-Machine+xml'
95
- @builder = Nokogiri::XML::Builder.new do |xml|
96
- xml.VolumeDetach {
97
- xml.volume(:href => @@created_volume.id)
98
- }
99
- end
100
- put "/cimi/machines/#{@@machine.name}/detach_volume", @builder.to_xml
101
- last_response.status.should == 200
102
- end
103
-
104
- When /^client deletes the newly created Volume$/ do
105
- authorize 'mockuser', 'mockpassword'
106
- delete "/cimi/volumes/#{@@created_volume.name}"
107
- last_response.status.should == 200
108
- end
109
-
110
- Then /^client should verify the volume was deleted$/ do
111
- authorize 'mockuser', 'mockpassword'
112
- get "/cimi/volumes/#{@@created_volume.name}"
113
- last_response.status.should == 404
114
- end
115
-
@@ -1,75 +0,0 @@
1
- require 'rubygems'
2
- require 'nokogiri'
3
- require 'rack/test'
4
-
5
- ENV['API_FRONTEND'] = 'cimi'
6
-
7
- load File.join(File.dirname(__FILE__), '..', '..', '..', '..', 'lib', 'deltacloud_rack.rb')
8
-
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
-
15
- def last_xml_response
16
- Nokogiri::XML(last_response.body)
17
- end
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
-
45
- def new_machine
46
- @@new_machine
47
- end
48
-
49
- def set_new_machine(machine)
50
- @@new_machine = machine
51
- end
52
-
53
- class String
54
-
55
- def to_class_name
56
- to_collection_name
57
- end
58
-
59
- def to_entity_name
60
- to_collection_name.uncapitalize
61
- end
62
-
63
- def to_collection_name
64
- self.tr(' ', '').singularize
65
- end
66
-
67
- def to_collection_uri
68
- self.tr(' ', '_').downcase
69
- end
70
-
71
- def to_entity_uri
72
- to_collection_uri.pluralize
73
- end
74
-
75
- end
@@ -1,279 +0,0 @@
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
- ENV.delete 'API_VERBOSE'
17
-
18
- $:.unshift File.join(File.dirname(__FILE__), '..', 'lib')
19
- $top_srcdir = File::dirname(File::dirname(__FILE__))
20
-
21
- require 'rubygems'
22
- require 'yaml'
23
- require 'rspec/core'
24
- require 'rspec/matchers'
25
- require 'test/unit'
26
- require 'nokogiri'
27
- require 'json'
28
- require 'digest/sha1'
29
- require 'base64'
30
- require 'rack/test'
31
-
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!
39
-
40
- # Set proper environment variables for running test
41
-
42
- ENV['RACK_ENV'] = 'test'
43
- ENV['API_HOST'] = 'localhost'
44
- ENV['API_PORT'] = '4040'
45
-
46
- RSpec.configure do |conf|
47
- conf.include Rack::Test::Methods
48
- conf.expect_with :rspec
49
- end
50
-
51
- module DeltacloudTestCommon
52
-
53
- def recording?
54
- @use_recording
55
- end
56
-
57
- def record!
58
- @use_recording = true
59
- end
60
-
61
-
62
- # Authentication helper for Basic HTTP authentication
63
- # To change default user credentials stored in ENV['API_USER|PASSWORD'] you
64
- # need to set opts[:credentials] = { :user => '...', :password => '...'}
65
- #
66
- def authenticate(opts={})
67
- credentials = opts[:credentials] || { :user => ENV['API_USER'], :password => ENV['API_PASSWORD']}
68
- return {
69
- 'HTTP_AUTHORIZATION' => "Basic " + Base64.encode64("#{credentials[:user]}:#{credentials[:password]}")
70
- }
71
- end
72
-
73
- # HTTP Accept header helper.
74
- # Will set appropriate value for this header.
75
- # Available options for format are: :json, :html or :xml
76
- # By default :xml is used
77
- #
78
- def accept(format=:xml)
79
- case format
80
- when :json then 'application/json;q=0.9'
81
- when :html then 'text/html;q=0.9'
82
- when :xml then 'application/xml;q=0.9'
83
- else 'application/xml;q=0.9'
84
- end
85
- end
86
-
87
- # This helper will execute GET operation on given URI.
88
- # You can set additional parameters using params Hash, which will be passed to
89
- # request.
90
- # You can change format used for communication using opts[:format] = :xml | :html :json
91
- # You can turn on recording (you need to configure it first in setup.rb) using
92
- # opts[:record] (true/false)
93
- # You can force authentication using opts[:auth] parameter or use
94
- # 'get_auth_url' which will do it for you ;-)
95
- #
96
- def get_url(uri, params={}, opts={})
97
- header 'Accept', accept(opts[:format] || :xml)
98
- if DeltacloudTestCommon::recording?
99
- VCR.use_cassette("get-" + Digest::SHA1.hexdigest("#{uri}-#{params}}")) do
100
- get(uri, params || {}, opts[:auth] ? authenticate(opts) : {})
101
- end
102
- else
103
- get(uri, params || {}, opts[:auth] ? authenticate(opts) : {})
104
- if last_response.status.to_s =~ /5(\d{2})/
105
- puts "============= [ ERROR ] ================"
106
- puts last_response.body
107
- puts "============= [ RESPONSE ] ================"
108
- puts last_response.errors
109
- puts "========================================"
110
- end
111
- end
112
- last_response.status.should_not == 401
113
- end
114
-
115
- def get_auth_url(uri, params={}, opts={})
116
- opts.merge!(:auth => true)
117
- get_url(uri, params, opts)
118
- if last_response.status.to_s =~ /5(\d{2})/
119
- puts "============= [ ERROR ] ================"
120
- puts last_response.body
121
- puts "============= [ RESPONSE ] ================"
122
- puts last_response.errors
123
- puts "========================================"
124
- end
125
- end
126
-
127
- def post_url(uri, params={}, opts={})
128
- header 'Accept', accept(opts[:format] || :xml)
129
- if DeltacloudTestCommon::recording?
130
- if opts['vcr_cassette']
131
- VCR.use_cassette(opts['vcr_cassette']) do
132
- post(uri, params || {}, authenticate(opts))
133
- end
134
- else
135
- VCR.use_cassette("post-" + Digest::SHA1.hexdigest("#{uri}-#{params}")) do
136
- post(uri, params || {}, authenticate(opts))
137
- end
138
- end
139
- else
140
- post(uri, params || {}, authenticate(opts))
141
- if last_response.status.to_s =~ /5(\d{2})/
142
- puts "============= [ ERROR ] ================"
143
- puts last_response.body
144
- puts "============= [ RESPONSE ] ================"
145
- puts last_response.errors
146
- puts "========================================"
147
- end
148
- end
149
- end
150
-
151
- def delete_url(uri, params={}, opts={})
152
- header 'Accept', accept(opts[:format] || :xml)
153
- if DeltacloudTestCommon::recording?
154
- VCR.use_cassette("delete-"+Digest::SHA1.hexdigest("#{uri}-#{params}")) do
155
- delete(uri, params || {}, authenticate(opts))
156
- end
157
- else
158
- delete(uri, params || {}, authenticate(opts))
159
- if last_response.status.to_s =~ /5(\d{2})/
160
- puts "============= [ ERROR ] ================"
161
- puts last_response.body
162
- puts "============= [ RESPONSE ] ================"
163
- puts last_response.errors
164
- end
165
- end
166
- end
167
-
168
- def head_url(uri, params={}, opts={})
169
- header 'Accept', accept(opts[:format] || :xml)
170
- if DeltacloudTestCommon::recording?
171
- VCR.use_cassette("head-"+Digest::SHA1.hexdigest("#{uri}-#{params}")) do
172
- head(uri, params || {}, authenticate(opts))
173
- end
174
- else
175
- head(uri, params || {}, authenticate(opts))
176
- if last_response.status.to_s =~ /5(\d{2})/
177
- puts "============= [ ERROR ] ================"
178
- puts last_response.inspect
179
- puts "========================================"
180
- end
181
- end
182
- end
183
-
184
- def put_url(uri, params={}, opts={})
185
- header 'Accept', accept(opts[:format] || :xml)
186
- if DeltacloudTestCommon::recording?
187
- VCR.use_cassette("put-"+Digest::SHA1.hexdigest("#{uri}-#{params}-#{authenticate(opts)}")) do
188
- put(uri, params || {}, authenticate(opts))
189
- end
190
- else
191
- put(uri, params || {}, authenticate(opts))
192
- if last_response.status.to_s =~ /5(\d{2})/
193
- puts "============= [ ERROR ] ================"
194
- puts last_response.body
195
- puts "============= [ RESPONSE ] ================"
196
- puts last_response.errors
197
- end
198
- end
199
- end
200
-
201
- # This helper will automatically convert output from method above to Nokogiri
202
- # XML object
203
- def last_xml_response
204
- Nokogiri::XML(last_response.body) #if last_response.status.to_s =~ /2(\d+)/
205
- end
206
-
207
- # Check if given URI require authentication
208
- def require_authentication?(uri)
209
- # We need to make sure we don't have both API_USER and API_PASSWORD
210
- # set in the environment; otherwise LazyAuth will use those instead
211
- # of asking for credentials
212
- api_user = ENV.delete("API_USER")
213
- get uri, {}
214
- ENV["API_USER"] = api_user
215
- last_response.status == 401
216
- end
217
-
218
- def with_provider(new_provider, &block)
219
- old_provider = ENV["API_PROVIDER"]
220
- begin
221
- ENV["API_PROVIDER"] = new_provider
222
- yield
223
- ensure
224
- ENV["API_PROVIDER"] = old_provider
225
- end
226
- end
227
-
228
- def add_created_instance(id)
229
- $created_instances ||= []
230
- $created_instances << id
231
- end
232
-
233
- #common variables used by the bucket/blob unit tests across clouds
234
- @@created_bucket_name="testbucki2rpux3wdelme"
235
- @@created_blob_name="testblobk1ds91kVdelme"
236
- @@created_blob_local_file="#{File.dirname(__FILE__)}/drivers/common_fixtures/deltacloud_blob_test.png"
237
-
238
- def check_bucket_basics(bucket, cloud)
239
- (bucket/'bucket/name').first.text.should == "#{@@created_bucket_name}#{cloud}"
240
- (bucket/'bucket').attribute("id").text.should == "#{@@created_bucket_name}#{cloud}"
241
- (bucket/'bucket').length.should > 0
242
- (bucket/'bucket/name').first.text.should_not == nil
243
- (bucket/'bucket').attribute("href").text.should_not == nil
244
- end
245
-
246
- def check_blob_basics(blob, cloud)
247
- (blob/'blob').length.should == 1
248
- (blob/'blob').attribute("id").text.should_not == nil
249
- (blob/'blob').attribute("href").text.should_not==nil
250
- (blob/'blob/bucket').text.should_not == nil
251
- (blob/'blob/content_length').text.should_not == nil
252
- (blob/'blob/content_type').text.should_not == nil
253
- (blob/'blob').attribute("id").text.should == "#{@@created_blob_name}#{cloud}"
254
- (blob/'blob/bucket').text.should == "#{@@created_bucket_name}#{cloud}"
255
- (blob/'blob/content_length').text.to_i.should == File.size(@@created_blob_local_file)
256
- end
257
-
258
- def check_blob_metadata(blob, metadata_hash)
259
- meta_from_blob = {}
260
- #extract metadata from nokogiri blob xml
261
- (0.. (((blob/'blob/user_metadata').first).elements.size - 1) ).each do |i|
262
- meta_from_blob[(((blob/'blob/user_metadata').first).elements[i].attribute("key").value)] =
263
- (((blob/'blob/user_metadata').first).elements[i].children[1].text)
264
- end
265
- #remove any 'x-goog-meta-' prefixes (problem for google blobs and vcr...)
266
- meta_from_blob.gsub_keys(/x-.*-meta-/i, "")
267
- meta_from_blob.eql?(metadata_hash).should == true
268
- end
269
-
270
- #hash ordering is unpredictable - sort the params hash
271
- #so we get same vcr cassette name each time
272
- def stable_vcr_cassette_name(method, uri, params)
273
- digest = Digest::SHA1.hexdigest("#{uri}-#{params.sort_by {|k,v| k.to_s}}")
274
- return "#{method}-#{digest}"
275
- end
276
-
277
- end
278
-
279
- include DeltacloudTestCommon