deltacloud-core 1.0.3 → 1.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +23 -0
- data/NOTICE +3 -0
- data/Rakefile +32 -20
- data/bin/deltacloudd +1 -1
- data/config.ru +25 -32
- data/deltacloud-core.gemspec +1 -1
- data/lib/cimi/collections.rb +4 -1
- data/lib/cimi/collections/address_templates.rb +2 -2
- data/lib/cimi/collections/addresses.rb +1 -1
- data/lib/cimi/collections/base.rb +64 -0
- data/lib/cimi/collections/{machine_admins.rb → credentials.rb} +12 -12
- data/lib/cimi/collections/{vsp_templates.rb → forwarding_group_templates.rb} +12 -16
- data/lib/cimi/collections/{vsp_configurations.rb → forwarding_groups.rb} +12 -13
- data/lib/cimi/collections/machine_configurations.rb +2 -2
- data/lib/cimi/collections/machine_images.rb +1 -1
- data/lib/cimi/collections/machines.rb +8 -2
- data/lib/cimi/collections/network_configurations.rb +2 -2
- data/lib/cimi/collections/{routing_groups.rb → network_port_configurations.rb} +12 -12
- data/lib/cimi/collections/{routing_group_templates.rb → network_port_templates.rb} +15 -12
- data/lib/cimi/collections/{vsps.rb → network_ports.rb} +33 -32
- data/lib/cimi/collections/network_templates.rb +2 -2
- data/lib/cimi/collections/networks.rb +17 -2
- data/lib/cimi/collections/{entity_metadata.rb → resource_metadata.rb} +10 -10
- data/lib/cimi/collections/volume_configurations.rb +1 -1
- data/lib/cimi/collections/volume_images.rb +1 -1
- data/lib/cimi/collections/volumes.rb +1 -2
- data/lib/cimi/dependencies.rb +1 -1
- data/lib/cimi/helpers.rb +3 -84
- data/lib/cimi/helpers/cimi_helper.rb +15 -14
- data/lib/cimi/models.rb +20 -36
- data/lib/cimi/models/address.rb +32 -4
- data/lib/cimi/models/address_template.rb +2 -2
- data/lib/cimi/models/base.rb +24 -5
- data/lib/cimi/models/cloud_entry_point.rb +4 -9
- data/lib/cimi/models/collection.rb +101 -0
- data/lib/cimi/models/{machine_admin.rb → credential.rb} +6 -4
- data/lib/cimi/models/disk_collection.rb +1 -2
- data/lib/cimi/models/{routing_group_template.rb → forwarding_group.rb} +5 -3
- data/lib/cimi/models/{routing_group.rb → forwarding_group_template.rb} +5 -3
- data/lib/cimi/models/machine.rb +9 -7
- data/lib/cimi/models/machine_configuration.rb +2 -0
- data/lib/cimi/models/machine_image.rb +2 -0
- data/lib/cimi/models/machine_template.rb +3 -1
- data/lib/cimi/models/machine_volume_collection.rb +1 -1
- data/lib/cimi/models/network.rb +2 -0
- data/lib/cimi/models/network_configuration.rb +4 -8
- data/lib/cimi/models/{vsp.rb → network_port.rb} +7 -11
- data/lib/cimi/models/{network_configuration_collection.rb → network_port_collection.rb} +25 -8
- data/lib/cimi/models/{vsp_configuration.rb → network_port_configuration.rb} +6 -10
- data/lib/cimi/models/{network_collection.rb → network_port_configuration_collection.rb} +9 -9
- data/lib/cimi/models/{vsp_template.rb → network_port_template.rb} +6 -4
- data/lib/cimi/models/{network_template_collection.rb → network_port_template_collection.rb} +10 -8
- data/lib/cimi/models/network_template.rb +3 -1
- data/lib/cimi/models/{entity_metadata.rb → resource_metadata.rb} +16 -15
- data/lib/cimi/models/schema.rb +23 -12
- data/lib/cimi/models/volume.rb +2 -0
- data/lib/cimi/models/volume_configuration.rb +2 -0
- data/lib/cimi/models/volume_image.rb +2 -0
- data/lib/cimi/models/volume_template.rb +2 -0
- data/lib/cimi/server.rb +10 -6
- data/lib/deltacloud/collections.rb +7 -2
- data/lib/deltacloud/collections/addresses.rb +3 -1
- data/lib/deltacloud/collections/base.rb +64 -0
- data/lib/deltacloud/collections/buckets.rb +14 -4
- data/lib/deltacloud/collections/drivers.rb +1 -1
- data/lib/deltacloud/collections/firewalls.rb +1 -1
- data/lib/deltacloud/collections/instances.rb +5 -1
- data/lib/deltacloud/collections/keys.rb +1 -1
- data/lib/deltacloud/collections/load_balancers.rb +2 -0
- data/lib/deltacloud/collections/storage_volumes.rb +3 -5
- data/lib/deltacloud/core_ext.rb +1 -0
- data/lib/deltacloud/core_ext/hash.rb +8 -0
- data/lib/deltacloud/core_ext/ordered_hash.rb +222 -0
- data/lib/deltacloud/core_ext/string.rb +9 -0
- data/lib/deltacloud/drivers/aruba/aruba_driver.rb +0 -9
- data/lib/deltacloud/drivers/base_driver.rb +22 -4
- data/lib/deltacloud/drivers/ec2/ec2_driver.rb +0 -4
- data/lib/deltacloud/drivers/exceptions.rb +30 -13
- data/lib/deltacloud/drivers/features.rb +7 -0
- data/lib/deltacloud/drivers/fgcp/fgcp_driver.rb +1 -9
- data/lib/deltacloud/drivers/google/google_driver.rb +13 -0
- data/lib/deltacloud/drivers/mock/data/addresses/192.168.0.1.yml +3 -0
- data/lib/deltacloud/drivers/mock/data/addresses/192.168.0.2.yml +3 -0
- data/lib/deltacloud/drivers/mock/data/addresses/192.168.0.3.yml +3 -0
- data/lib/deltacloud/drivers/mock/data/addresses/192.168.0.4.yml +3 -0
- data/lib/deltacloud/drivers/mock/mock_driver.rb +65 -1
- data/lib/deltacloud/drivers/mock/mock_driver_cimi_methods.rb +55 -32
- data/lib/deltacloud/drivers/openstack/openstack_driver.rb +18 -6
- data/lib/deltacloud/helpers.rb +0 -75
- data/lib/deltacloud/helpers/deltacloud_helper.rb +66 -28
- data/lib/deltacloud/helpers/driver_helper.rb +7 -0
- data/lib/deltacloud/helpers/rabbit_helper.rb +51 -0
- data/lib/deltacloud/server.rb +12 -14
- data/lib/deltacloud/version.rb +1 -1
- data/lib/deltacloud_rack.rb +26 -2
- data/lib/ec2/query_parser.rb +18 -3
- data/lib/sinatra/rack_accept.rb +7 -2
- data/lib/sinatra/rack_matrix_params.rb +14 -14
- data/public/javascripts/cmwgapp.js +2 -2
- data/tests/cimi/collections/cloud_entry_point_test.rb +3 -3
- data/tests/cimi/collections/machine_images_test.rb +2 -2
- data/tests/cimi/collections/machines_test.rb +1 -1
- data/tests/cimi/collections/url_helper_test.rb +31 -0
- data/tests/cimi/spec/cimi/model/{machine_admin_spec.rb → credential_spec.rb} +4 -4
- data/tests/deltacloud/base_collection_test.rb +0 -5
- data/tests/deltacloud/collections/buckets_collection_test.rb +1 -1
- data/tests/deltacloud/collections/drivers_collection_test.rb +1 -1
- data/tests/deltacloud/collections/hardware_profiles_collection_test.rb +1 -1
- data/tests/deltacloud/collections/images_collection_test.rb +1 -1
- data/tests/deltacloud/collections/instance_states_collection_test.rb +1 -1
- data/tests/deltacloud/collections/instances_collection_test.rb +1 -1
- data/tests/deltacloud/collections/keys_collection_test.rb +1 -4
- data/tests/deltacloud/deltacloud_helper_test.rb +0 -9
- data/tests/deltacloud/server_test.rb +1 -1
- data/tests/drivers/base/base_driver_test.rb +30 -0
- data/tests/drivers/base/common.rb +14 -0
- data/tests/drivers/base/exceptions_test.rb +64 -0
- data/tests/drivers/ec2/buckets_test.rb +45 -0
- data/tests/drivers/ec2/keys_test.rb +1 -1
- data/tests/drivers/google/buckets_test.rb +2 -2
- data/tests/drivers/google/common.rb +3 -3
- data/tests/test_helper.rb +28 -0
- data/views/api/show.html.haml +2 -2
- data/views/api/show.xml.haml +1 -1
- data/views/buckets/index.html.haml +1 -1
- data/views/cimi/cloudEntryPoint/index.xml.haml +1 -1
- data/views/cimi/collection/index.html.haml +3 -3
- data/views/cimi/collection/response.xml.haml +1 -1
- data/views/cimi/error.html.haml +1 -1
- data/views/cimi/errors/500.xml.haml +1 -1
- data/views/cimi/layout.html.haml +1 -1
- data/views/cimi/machine_configurations/show.html.haml +2 -2
- data/views/cimi/machine_configurations/show.xml.haml +1 -1
- data/views/cimi/machine_images/show.html.haml +2 -2
- data/views/cimi/machine_images/show.xml.haml +1 -1
- data/views/cimi/machines/show.html.haml +2 -2
- data/views/cimi/machines/show.xml.haml +1 -1
- data/views/cimi/volumes/show.html.haml +2 -2
- data/views/cimi/volumes/show.xml.haml +1 -1
- data/views/docs/collection.html.haml +1 -1
- data/views/docs/collection.xml.haml +2 -2
- data/views/docs/index.html.haml +1 -1
- data/views/docs/index.xml.haml +1 -1
- data/views/docs/operation.xml.haml +1 -1
- data/views/error.html.haml +1 -1
- data/views/errors/500.html.haml +7 -4
- data/views/firewalls/index.html.haml +1 -1
- data/views/firewalls/show.html.haml +1 -1
- data/views/images/show.html.haml +2 -2
- data/views/index.html.haml +9 -0
- data/views/instance_states/show.html.haml +1 -1
- data/views/instances/run_command.html.haml +1 -1
- data/views/instances/show.html.haml +2 -2
- data/views/keys/index.html.haml +1 -1
- data/views/layout.html.haml +1 -1
- data/views/load_balancers/index.html.haml +1 -1
- data/views/load_balancers/show.html.haml +3 -3
- data/views/storage_snapshots/show.html.haml +1 -1
- data/views/storage_volumes/attach.html.haml +1 -1
- data/views/storage_volumes/index.html.haml +1 -1
- data/views/storage_volumes/show.html.haml +4 -4
- metadata +40 -43
- data/lib/cimi/models/address_collection.rb +0 -34
- data/lib/cimi/models/address_template_collection.rb +0 -34
- data/lib/cimi/models/entity_metadata_collection.rb +0 -31
- data/lib/cimi/models/machine_admin_collection.rb +0 -34
- data/lib/cimi/models/machine_collection.rb +0 -37
- data/lib/cimi/models/machine_configuration_collection.rb +0 -36
- data/lib/cimi/models/machine_image_collection.rb +0 -36
- data/lib/cimi/models/machine_template_collection.rb +0 -36
- data/lib/cimi/models/routing_group_collection.rb +0 -34
- data/lib/cimi/models/routing_group_template_collection.rb +0 -35
- data/lib/cimi/models/volume_collection.rb +0 -36
- data/lib/cimi/models/volume_configuration_collection.rb +0 -36
- data/lib/cimi/models/volume_image_collection.rb +0 -36
- data/lib/cimi/models/volume_template_collection.rb +0 -36
- data/lib/cimi/models/vsp_collection.rb +0 -34
- data/lib/cimi/models/vsp_configuration_collection.rb +0 -34
- data/lib/cimi/models/vsp_template_collection.rb +0 -34
- data/lib/deltacloud/helpers/url_helper.rb +0 -115
@@ -36,15 +36,21 @@ module Rack
|
|
36
36
|
#
|
37
37
|
# All HTTP methods are supported, in case of POST they will be passed as a
|
38
38
|
# regular <form> parameters.
|
39
|
-
|
40
39
|
def call(env)
|
41
|
-
|
42
|
-
|
43
|
-
|
40
|
+
|
41
|
+
# This ugly hack should fix the issue with Rack::Test where
|
42
|
+
# these two variables are empty and Rack::Test will always
|
43
|
+
# return 404.
|
44
|
+
#
|
45
|
+
if env['rack.test']
|
46
|
+
env['REQUEST_URI'] = env['PATH_INFO']
|
47
|
+
env['REQUEST_PATH'] = env['PATH_INFO']
|
48
|
+
end
|
44
49
|
|
45
50
|
# Split URI to components and then extract ;var=value pairs
|
46
|
-
uri_components = env['REQUEST_URI'].split('/')
|
47
51
|
matrix_params = {}
|
52
|
+
uri_components = (env['rack.test'] ? env['PATH_INFO'] : env['REQUEST_URI']).split('/')
|
53
|
+
|
48
54
|
uri_components.each do |component|
|
49
55
|
sub_components, value = component.split(/\;(\w+)\=/), nil
|
50
56
|
next unless sub_components.first # Skip subcomponent if it's empty (usually /)
|
@@ -73,15 +79,9 @@ module Rack
|
|
73
79
|
# does not trip over them
|
74
80
|
|
75
81
|
# (1) Rewrite current path by stripping all matrix params from it
|
76
|
-
|
77
|
-
env[
|
78
|
-
env[
|
79
|
-
end
|
80
|
-
|
81
|
-
# This is needed for OpenShift deployment / Passenger
|
82
|
-
if env['REQUEST_PATH']
|
83
|
-
env['REQUEST_PATH'] = env['REQUEST_PATH'].gsub(/;([^\/]*)/, '').gsub(/\?(.*)$/, '')
|
84
|
-
env['PATH_INFO'] = env['REQUEST_PATH']
|
82
|
+
['REQUEST_PATH', 'REQUEST_URI', 'PATH_INFO'].select { |k|
|
83
|
+
env[k] }.each do |k|
|
84
|
+
env[k] = env[k].remove_matrix_params
|
85
85
|
end
|
86
86
|
|
87
87
|
# (2) Append the matrix params to the 'normal' request params
|
@@ -29,7 +29,7 @@ function doXmlPut(theNode, addId, func)
|
|
29
29
|
}
|
30
30
|
else {
|
31
31
|
xmlData = "<?xml version='1.0' encoding='utf-8' ?>";
|
32
|
-
xmlData += "<" + $(theNode.form).attr("xmlRootNode").value + " xmlns='http://
|
32
|
+
xmlData += "<" + $(theNode.form).attr("xmlRootNode").value + " xmlns='http://schemas.dmtf.org/cimi/1'>";
|
33
33
|
xmlData += getStandardData(theNode);
|
34
34
|
xmlData += "</" + $(theNode.form).attr("xmlRootNode").value + ">";
|
35
35
|
}
|
@@ -72,7 +72,7 @@ function doXmlPost(theNode, func)
|
|
72
72
|
}
|
73
73
|
else {
|
74
74
|
xmlData = "<?xml version='1.0' encoding='utf-8' ?>";
|
75
|
-
xmlData += "<" + $(theNode.form).attr("xmlRootNode").value + " xmlns='http://
|
75
|
+
xmlData += "<" + $(theNode.form).attr("xmlRootNode").value + " xmlns='http://schemas.dmtf.org/cimi/1'>";
|
76
76
|
xmlData += getStandardData(theNode)
|
77
77
|
xmlData += "</" + $(theNode.form).attr("xmlRootNode").value + ">";
|
78
78
|
}
|
@@ -7,7 +7,7 @@ require_relative './common.rb'
|
|
7
7
|
describe CIMI::Collections::CloudEntryPoint do
|
8
8
|
|
9
9
|
before do
|
10
|
-
def app;
|
10
|
+
def app; run_frontend(:cimi) end
|
11
11
|
@collection = CIMI::Collections.collection(:cloudEntryPoint)
|
12
12
|
end
|
13
13
|
|
@@ -46,10 +46,10 @@ describe CIMI::Collections::CloudEntryPoint do
|
|
46
46
|
it 'advertise only supported CIMI collections by driver' do
|
47
47
|
header 'X-Deltacloud-Driver', 'ec2'
|
48
48
|
get root_url + '/cloudEntryPoint'
|
49
|
-
(xml/'CloudEntryPoint/
|
49
|
+
(xml/'CloudEntryPoint/forwardingGroups').must_be_empty
|
50
50
|
header 'X-Deltacloud-Driver', 'mock'
|
51
51
|
get root_url + '/cloudEntryPoint'
|
52
|
-
(xml/'CloudEntryPoint/
|
52
|
+
(xml/'CloudEntryPoint/forwardingGroups').wont_be_empty
|
53
53
|
end
|
54
54
|
|
55
55
|
end
|
@@ -6,7 +6,7 @@ require_relative './common.rb'
|
|
6
6
|
describe CIMI::Collections::MachineImages do
|
7
7
|
|
8
8
|
before do
|
9
|
-
def app;
|
9
|
+
def app; run_frontend(:cimi) end
|
10
10
|
authorize 'mockuser', 'mockpassword'
|
11
11
|
@collection = CIMI::Collections.collection(:machine_images)
|
12
12
|
end
|
@@ -36,7 +36,7 @@ describe CIMI::Collections::MachineImages do
|
|
36
36
|
it 'should allow to filter using CIMISelect' do
|
37
37
|
get root_url '/machine_images?CIMISelect=description'
|
38
38
|
status.must_equal 200
|
39
|
-
xml.root.name.must_equal '
|
39
|
+
xml.root.name.must_equal 'Collection'
|
40
40
|
(xml/'description').wont_be_empty
|
41
41
|
(xml/'id').must_be_empty
|
42
42
|
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'require_relative' if RUBY_VERSION < '1.9'
|
3
|
+
|
4
|
+
require 'minitest/autorun'
|
5
|
+
require_relative './common.rb'
|
6
|
+
|
7
|
+
class CIMITestHelper
|
8
|
+
def settings; OpenStruct.new(:root_url => '//'); end
|
9
|
+
def url(path); '/cimi' + path; end
|
10
|
+
include Sinatra::Rabbit::URLFor(CIMI.collections)
|
11
|
+
end
|
12
|
+
|
13
|
+
describe CIMI do
|
14
|
+
|
15
|
+
before do
|
16
|
+
@api = CIMITestHelper.new
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'generate url helpers for CIMI model' do
|
20
|
+
@api.machines_url.must_equal '/cimi/machines'
|
21
|
+
@api.machine_url('123').must_equal '/cimi/machines/123'
|
22
|
+
@api.machines_url(:format => 'json').must_equal '/cimi/machines?format=json'
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'generate proper url for ResourceMetadata' do
|
26
|
+
@api.resource_metadata_url.must_equal '/cimi/resource_metadata'
|
27
|
+
@api.resource_metadata_url('123').must_equal '/cimi/resource_metadata/123'
|
28
|
+
@api.resource_metadata_url(:format => 'json').must_equal '/cimi/resource_metadata/?format=json'
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
@@ -21,15 +21,15 @@ if require 'minitest/autorun'
|
|
21
21
|
require_relative '../../spec_helper.rb'
|
22
22
|
end
|
23
23
|
|
24
|
-
describe "
|
24
|
+
describe "Credential model" do
|
25
25
|
|
26
26
|
before do
|
27
|
-
@xml = IO::read(File::join(DATA_DIR, "
|
28
|
-
@json = IO::read(File::join(DATA_DIR, "
|
27
|
+
@xml = IO::read(File::join(DATA_DIR, "credential.xml"))
|
28
|
+
@json = IO::read(File::join(DATA_DIR, "credential.json"))
|
29
29
|
end
|
30
30
|
|
31
31
|
it "can be constructed from XML and JSON" do
|
32
|
-
should_properly_serialize_model CIMI::Model::
|
32
|
+
should_properly_serialize_model CIMI::Model::Credential, @xml, @json
|
33
33
|
end
|
34
34
|
|
35
35
|
end
|
@@ -22,9 +22,4 @@ describe Deltacloud::Collections::Base do
|
|
22
22
|
@base.version.must_equal Deltacloud.config[:deltacloud].version
|
23
23
|
end
|
24
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
25
|
end
|
@@ -6,7 +6,7 @@ require_relative File.join('..', 'common.rb')
|
|
6
6
|
describe Deltacloud::Collections::Buckets do
|
7
7
|
|
8
8
|
before do
|
9
|
-
def app;
|
9
|
+
def app; run_frontend; end
|
10
10
|
authorize 'mockuser', 'mockpassword'
|
11
11
|
@collection = Deltacloud::Collections.collection(:buckets)
|
12
12
|
end
|
@@ -6,7 +6,7 @@ require_relative File.join('..', 'common.rb')
|
|
6
6
|
describe Deltacloud::Collections::HardwareProfiles do
|
7
7
|
|
8
8
|
before do
|
9
|
-
def app;
|
9
|
+
def app; run_frontend; end
|
10
10
|
authorize 'mockuser', 'mockpassword'
|
11
11
|
@collection = Deltacloud::Collections.collection(:hardware_profiles)
|
12
12
|
end
|
@@ -6,7 +6,7 @@ require_relative File.join('..', 'common.rb')
|
|
6
6
|
describe Deltacloud::Collections::Images do
|
7
7
|
|
8
8
|
before do
|
9
|
-
def app;
|
9
|
+
def app; run_frontend; end
|
10
10
|
authorize 'mockuser', 'mockpassword'
|
11
11
|
@collection = Deltacloud::Collections.collection(:images)
|
12
12
|
end
|
@@ -6,7 +6,7 @@ require_relative File.join('..', 'common.rb')
|
|
6
6
|
describe Deltacloud::Collections::InstanceStates do
|
7
7
|
|
8
8
|
before do
|
9
|
-
def app;
|
9
|
+
def app; run_frontend; end
|
10
10
|
authorize 'mockuser', 'mockpassword'
|
11
11
|
@collection = Deltacloud::Collections.collection(:instance_states)
|
12
12
|
end
|
@@ -6,7 +6,7 @@ require_relative File.join('..', 'common.rb')
|
|
6
6
|
describe Deltacloud::Collections::Instances do
|
7
7
|
|
8
8
|
before do
|
9
|
-
def app;
|
9
|
+
def app; run_frontend; end
|
10
10
|
authorize 'mockuser', 'mockpassword'
|
11
11
|
@collection = Deltacloud::Collections.collection(:instances)
|
12
12
|
end
|
@@ -6,7 +6,7 @@ require_relative File.join('..', 'common.rb')
|
|
6
6
|
describe Deltacloud::Collections::Keys do
|
7
7
|
|
8
8
|
before do
|
9
|
-
def app;
|
9
|
+
def app; run_frontend; end
|
10
10
|
authorize 'mockuser', 'mockpassword'
|
11
11
|
@collection = Deltacloud::Collections.collection(:keys)
|
12
12
|
end
|
@@ -48,9 +48,6 @@ describe Deltacloud::Collections::Keys do
|
|
48
48
|
xml.root.name.must_equal 'key'
|
49
49
|
xml.root[:id].must_equal 'unit-test1'
|
50
50
|
(xml/'key/pem').wont_be_empty
|
51
|
-
Proc.new {
|
52
|
-
post root_url + '/keys', { :name => 'unit-test1' }
|
53
|
-
}.must_raise Deltacloud::ExceptionHandler::ProviderError, 'keyExist'
|
54
51
|
delete root_url + '/keys/unit-test1'
|
55
52
|
status.must_equal 204
|
56
53
|
end
|
@@ -13,15 +13,6 @@ describe Deltacloud::Helpers::Application do
|
|
13
13
|
@helper = ApplicationHelper.new
|
14
14
|
end
|
15
15
|
|
16
|
-
it 'provides list of supported collections for the current driver' do
|
17
|
-
@helper.supported_collections.wont_be_empty
|
18
|
-
@helper.supported_collections.must_include Sinatra::Rabbit::InstancesCollection
|
19
|
-
@helper.supported_collections.wont_include Sinatra::Rabbit::LoadBalancersCollection
|
20
|
-
Thread.current[:driver] = 'ec2'
|
21
|
-
@helper.supported_collections.must_include Sinatra::Rabbit::LoadBalancersCollection
|
22
|
-
Thread.current[:driver] = 'mock'
|
23
|
-
end
|
24
|
-
|
25
16
|
it 'provides name for the authentication feature' do
|
26
17
|
@helper.auth_feature_name.wont_be_nil
|
27
18
|
@helper.auth_feature_name.must_equal 'key'
|
@@ -8,6 +8,7 @@ require_relative '../../../lib/deltacloud/drivers/base_driver'
|
|
8
8
|
describe Deltacloud::BaseDriver do
|
9
9
|
|
10
10
|
before do
|
11
|
+
|
11
12
|
class TestDriver < Deltacloud::BaseDriver
|
12
13
|
|
13
14
|
define_hardware_profile('t1.micro') do
|
@@ -36,8 +37,37 @@ describe Deltacloud::BaseDriver do
|
|
36
37
|
end
|
37
38
|
|
38
39
|
def realms(credentials, opts={}); end
|
40
|
+
|
41
|
+
def supported_collections(credentials)
|
42
|
+
collections = super
|
43
|
+
#lets add images/instances just for testing of method override from base
|
44
|
+
collections + [Sinatra::Rabbit::ImagesCollection, Sinatra::Rabbit::InstancesCollection]
|
45
|
+
end
|
39
46
|
end
|
47
|
+
|
40
48
|
@driver = TestDriver.new
|
49
|
+
|
50
|
+
end
|
51
|
+
|
52
|
+
describe 'supported driver collections' do
|
53
|
+
|
54
|
+
it 'provides list of supported collections' do
|
55
|
+
current_driver = Thread.current[:driver]
|
56
|
+
#change to test driver, mock defined in common.rb
|
57
|
+
Thread.current[:driver] = 'test'
|
58
|
+
credentials = OpenStruct.new(:user => 'unkown', :password => 'wrong')
|
59
|
+
@driver.supported_collections(credentials).wont_be_empty
|
60
|
+
@driver.supported_collections(credentials).must_include Sinatra::Rabbit::InstancesCollection
|
61
|
+
#check override of supported_collections, we added Images above
|
62
|
+
@driver.supported_collections(credentials).must_include Sinatra::Rabbit::ImagesCollection
|
63
|
+
@driver.supported_collections(credentials).wont_include Sinatra::Rabbit::KeysCollection
|
64
|
+
#switch driver, check supported_collections
|
65
|
+
Thread.current[:driver] = 'mock'
|
66
|
+
@driver.supported_collections(credentials).must_include Sinatra::Rabbit::KeysCollection
|
67
|
+
#restore driver to not impact other tests
|
68
|
+
Thread.current[:driver] = current_driver
|
69
|
+
end
|
70
|
+
|
41
71
|
end
|
42
72
|
|
43
73
|
describe 'when creating a new driver' do
|
@@ -1 +1,15 @@
|
|
1
1
|
require_relative '../../test_helper'
|
2
|
+
|
3
|
+
require_relative File.join('..', '..', '..', 'lib', 'deltacloud_rack.rb')
|
4
|
+
|
5
|
+
# Setup Deltacloud::API Sinatra instance
|
6
|
+
|
7
|
+
Deltacloud::configure do |server|
|
8
|
+
server.root_url '/api'
|
9
|
+
server.version Deltacloud::API_VERSION
|
10
|
+
server.klass 'Deltacloud::API'
|
11
|
+
server.logger Rack::DeltacloudLogger.setup(ENV['API_LOG'], ENV['API_VERBOSE'])
|
12
|
+
server.default_driver :mock
|
13
|
+
end
|
14
|
+
|
15
|
+
Deltacloud.require_frontend!
|
@@ -0,0 +1,64 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'require_relative' if RUBY_VERSION < '1.9'
|
3
|
+
require_relative './common'
|
4
|
+
require_relative '../../../lib/deltacloud/drivers/exceptions'
|
5
|
+
|
6
|
+
class TestException < StandardError; end
|
7
|
+
|
8
|
+
class ExceptionTestClass
|
9
|
+
include Deltacloud::ExceptionHandler
|
10
|
+
|
11
|
+
def raise_exception(id)
|
12
|
+
case id
|
13
|
+
when 1 then safely { raise 'test1 exception' }
|
14
|
+
when 2 then safely { raise TestException }
|
15
|
+
when 3 then safely { raise 'not captured' }
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
exceptions do
|
20
|
+
on /test1/ do
|
21
|
+
status 500
|
22
|
+
message 'Test1ErrorMessage'
|
23
|
+
end
|
24
|
+
on TestException do
|
25
|
+
status 400
|
26
|
+
message 'StandardErrorTest'
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def raise_error(id); ExceptionTestClass.new.raise_exception(id); end
|
32
|
+
|
33
|
+
describe Deltacloud::ExceptionHandler do
|
34
|
+
|
35
|
+
it 'should capture exception when match the exception message' do
|
36
|
+
lambda { raise_error 1 }.must_raise Deltacloud::ExceptionHandler::BackendError
|
37
|
+
|
38
|
+
begin raise_error(1); rescue Deltacloud::ExceptionHandler::BackendError => e
|
39
|
+
e.code.must_equal 500
|
40
|
+
e.message.must_equal 'Test1ErrorMessage'
|
41
|
+
e.backtrace.wont_be_empty
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'should capture exception when match the exception class' do
|
47
|
+
lambda { raise_error 2 }.must_raise Deltacloud::ExceptionHandler::ValidationFailure
|
48
|
+
begin raise_error(2); rescue Deltacloud::ExceptionHandler::ValidationFailure => e
|
49
|
+
e.code.must_equal 400
|
50
|
+
e.message.must_equal 'StandardErrorTest'
|
51
|
+
e.backtrace.wont_be_empty
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
it 'should capture exception when no match found' do
|
56
|
+
lambda { raise_error 3 }.must_raise Deltacloud::ExceptionHandler::BackendError
|
57
|
+
begin raise_error(3); rescue Deltacloud::ExceptionHandler::BackendError => e
|
58
|
+
e.code.must_equal 500
|
59
|
+
e.message.must_equal 'Unhandled exception or status code (not captured)'
|
60
|
+
e.backtrace.wont_be_empty
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'minitest/autorun'
|
2
|
+
|
3
|
+
require_relative File.join('..', '..', '..', 'lib', 'deltacloud', 'api.rb')
|
4
|
+
require_relative 'common.rb'
|
5
|
+
|
6
|
+
describe 'Ec2Driver Buckets' do
|
7
|
+
|
8
|
+
def credentials
|
9
|
+
{
|
10
|
+
:user => "AKIAJATNOR5HKG3FK27Q",
|
11
|
+
:password => "dPe47rAlKhlBdTYNbL4ZsMthDga08vEL9d3MS5UO"
|
12
|
+
}
|
13
|
+
end
|
14
|
+
|
15
|
+
before do
|
16
|
+
@driver = Deltacloud::new(:ec2, credentials)
|
17
|
+
VCR.insert_cassette __name__
|
18
|
+
end
|
19
|
+
|
20
|
+
after do
|
21
|
+
VCR.eject_cassette
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'must throw error when wrong credentials for buckets' do
|
25
|
+
Proc.new do
|
26
|
+
@driver.backend.buckets(OpenStruct.new(:user => 'unknown', :password => 'wrong'))
|
27
|
+
end.must_raise Deltacloud::ExceptionHandler::AuthenticationFailure, 'Authentication Failure'
|
28
|
+
end
|
29
|
+
|
30
|
+
|
31
|
+
it 'must handle us-east buckets from other regions' do
|
32
|
+
#create us-east bucket:
|
33
|
+
bucket = @driver.create_bucket("deltacloud-unit-test-bucket-2012-08-20-1704")
|
34
|
+
#get a new deltacloud handle using eu-west-1
|
35
|
+
@dcloud_other_provider = Deltacloud::new(:ec2, credentials.merge!(:provider=>"eu-west-1"))
|
36
|
+
#get the bucket and check
|
37
|
+
retrieved_bucket = @dcloud_other_provider.bucket(:id=>bucket.name)
|
38
|
+
retrieved_bucket.must_be_kind_of Bucket
|
39
|
+
retrieved_bucket.name.must_equal bucket.name
|
40
|
+
#delete the bucket
|
41
|
+
@driver.delete_bucket(bucket.id)
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
|