deltacloud-core 1.0.5 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +10 -2
- data/bin/deltacloudd +10 -10
- data/config.ru +2 -1
- data/config/drivers/digitalocean.yaml +3 -0
- data/deltacloud-core.gemspec +13 -6
- data/lib/cimi/collections.rb +1 -1
- data/lib/cimi/collections/address_templates.rb +27 -3
- data/lib/cimi/collections/addresses.rb +1 -1
- data/lib/cimi/collections/base.rb +1 -0
- data/lib/cimi/collections/cloud_entry_point.rb +4 -0
- data/lib/cimi/collections/credentials.rb +2 -2
- data/lib/cimi/collections/machine_images.rb +20 -0
- data/lib/cimi/collections/machine_templates.rb +72 -0
- data/lib/cimi/collections/machines.rb +50 -41
- data/lib/cimi/collections/network_ports.rb +3 -3
- data/lib/cimi/collections/networks.rb +4 -4
- data/lib/cimi/collections/resource_metadata.rb +1 -1
- data/lib/cimi/collections/volume_configurations.rb +25 -0
- data/lib/cimi/collections/volume_images.rb +21 -1
- data/lib/cimi/collections/volume_templates.rb +69 -0
- data/lib/cimi/collections/volumes.rb +5 -10
- data/lib/cimi/dependencies.rb +0 -1
- data/lib/cimi/helpers.rb +4 -1
- data/lib/cimi/helpers/cimi_helper.rb +62 -0
- data/lib/cimi/helpers/database_helper.rb +95 -0
- data/lib/cimi/models.rb +15 -1
- data/lib/cimi/models/address.rb +10 -5
- data/lib/cimi/models/address_template.rb +67 -3
- data/lib/cimi/models/base.rb +8 -5
- data/lib/cimi/models/cloud_entry_point.rb +6 -1
- data/lib/cimi/models/collection.rb +9 -4
- data/lib/cimi/models/disk.rb +6 -1
- data/lib/cimi/models/errors.rb +8 -0
- data/lib/cimi/models/machine.rb +68 -42
- data/lib/cimi/models/machine_configuration.rb +2 -2
- data/lib/cimi/models/machine_image.rb +41 -6
- data/lib/cimi/models/machine_template.rb +58 -0
- data/lib/cimi/models/machine_volume.rb +51 -3
- data/lib/cimi/models/resource_metadata.rb +88 -25
- data/lib/cimi/models/schema.rb +19 -5
- data/lib/cimi/models/volume.rb +66 -30
- data/lib/cimi/models/volume_configuration.rb +53 -21
- data/lib/cimi/models/volume_image.rb +24 -9
- data/lib/cimi/models/volume_template.rb +61 -0
- data/lib/cimi/server.rb +0 -6
- data/lib/db.rb +82 -0
- data/lib/db/address_template.rb +15 -0
- data/lib/db/entity.rb +22 -0
- data/lib/db/machine_template.rb +10 -0
- data/lib/db/provider.rb +13 -0
- data/lib/db/volume_configuration.rb +10 -0
- data/lib/db/volume_template.rb +10 -0
- data/lib/deltacloud/collections/addresses.rb +1 -1
- data/lib/deltacloud/collections/base.rb +12 -1
- data/lib/deltacloud/collections/buckets.rb +41 -8
- data/lib/deltacloud/collections/drivers.rb +1 -1
- data/lib/deltacloud/collections/firewalls.rb +2 -2
- data/lib/deltacloud/collections/images.rb +1 -1
- data/lib/deltacloud/collections/instances.rb +7 -1
- data/lib/deltacloud/collections/keys.rb +1 -1
- data/lib/deltacloud/collections/load_balancers.rb +4 -4
- data/lib/deltacloud/collections/storage_snapshots.rb +5 -1
- data/lib/deltacloud/collections/storage_volumes.rb +7 -3
- data/lib/deltacloud/drivers/base_driver.rb +10 -9
- data/lib/deltacloud/drivers/cimi_features.rb +42 -0
- data/lib/deltacloud/drivers/digitalocean/digitalocean_driver.rb +307 -0
- data/lib/deltacloud/drivers/ec2/ec2_driver.rb +40 -14
- data/lib/deltacloud/drivers/exceptions.rb +8 -0
- data/lib/deltacloud/drivers/features.rb +19 -2
- data/lib/deltacloud/drivers/fgcp/fgcp_client.rb +11 -0
- data/lib/deltacloud/drivers/fgcp/fgcp_driver.rb +83 -11
- data/lib/deltacloud/drivers/gogrid/gogrid_client.rb +1 -1
- data/lib/deltacloud/drivers/mock/mock_client.rb +2 -4
- data/lib/deltacloud/drivers/mock/mock_driver.rb +29 -0
- data/lib/deltacloud/drivers/openstack/openstack_driver.rb +153 -36
- data/lib/deltacloud/drivers/rackspace/anti_cache_monkey_patch.rb +20 -0
- data/lib/deltacloud/drivers/rackspace/rackspace_driver.rb +1 -0
- data/lib/deltacloud/drivers/rhevm/rhevm_driver.rb +30 -12
- data/lib/deltacloud/drivers/sbc/sbc_client.rb +0 -1
- data/lib/deltacloud/drivers/sbc/sbc_driver.rb +5 -1
- data/lib/deltacloud/drivers/vsphere/vsphere_client.rb +1 -1
- data/lib/deltacloud/drivers/vsphere/vsphere_driver.rb +19 -9
- data/lib/deltacloud/helpers/blob_stream_helper.rb +42 -3
- data/lib/deltacloud/helpers/deltacloud_helper.rb +31 -14
- data/lib/deltacloud/models/address.rb +9 -0
- data/lib/deltacloud/models/base_model.rb +4 -0
- data/lib/deltacloud/models/blob.rb +12 -0
- data/lib/deltacloud/models/bucket.rb +9 -0
- data/lib/deltacloud/models/firewall.rb +13 -1
- data/lib/deltacloud/models/firewall_rule.rb +14 -0
- data/lib/deltacloud/models/hardware_profile.rb +14 -0
- data/lib/deltacloud/models/image.rb +15 -0
- data/lib/deltacloud/models/instance.rb +40 -1
- data/lib/deltacloud/models/instance_address.rb +9 -0
- data/lib/deltacloud/models/key.rb +15 -0
- data/lib/deltacloud/models/load_balancer.rb +20 -0
- data/lib/deltacloud/models/metric.rb +15 -0
- data/lib/deltacloud/models/provider.rb +8 -0
- data/lib/deltacloud/models/realm.rb +9 -0
- data/lib/deltacloud/models/state_machine.rb +8 -0
- data/lib/deltacloud/models/storage_snapshot.rb +11 -0
- data/lib/deltacloud/models/storage_volume.rb +24 -0
- data/lib/deltacloud/server.rb +1 -3
- data/lib/deltacloud/version.rb +2 -1
- data/lib/deltacloud_rack.rb +1 -1
- data/tests/cimi/db/database_helper_test.rb +190 -0
- data/tests/cimi/db/db_helper.rb +30 -0
- data/tests/cimi/db/schema_test.rb +94 -0
- data/tests/cimi/model/collection_spec.rb +0 -1
- data/tests/cimi/model/machine_spec.rb +17 -0
- data/tests/cimi/spec_helper.rb +3 -2
- data/tests/deltacloud/collections/buckets_collection_test.rb +3 -0
- data/tests/deltacloud/collections/drivers_collection_test.rb +10 -0
- data/tests/deltacloud/collections/hardware_profiles_collection_test.rb +4 -0
- data/tests/deltacloud/collections/images_collection_test.rb +4 -0
- data/tests/deltacloud/collections/instances_collection_test.rb +14 -1
- data/tests/deltacloud/collections/keys_collection_test.rb +4 -0
- data/tests/deltacloud/collections/realms_collection_test.rb +47 -0
- data/tests/deltacloud/collections/storage_snapshots_collection_test.rb +47 -0
- data/tests/deltacloud/collections/storage_volumes_collection_test.rb +47 -0
- data/tests/deltacloud/common.rb +15 -0
- data/tests/deltacloud/deltacloud_helper_test.rb +0 -4
- data/tests/deltacloud/launcher_test.rb +108 -0
- data/tests/drivers/ec2/buckets_test.rb +2 -1
- data/tests/drivers/mock/buckets_test.rb +27 -0
- data/tests/drivers/mock/instances_test.rb +6 -0
- data/tests/drivers/openstack/common.rb +1 -1
- data/tests/drivers/openstack/hardware_profiles_test.rb +2 -1
- data/tests/drivers/openstack/instances_test.rb +18 -17
- data/tests/drivers/rhevm/common.rb +1 -0
- data/tests/drivers/rhevm/images_test.rb +1 -1
- data/tests/drivers/rhevm/instance_test.rb +7 -7
- data/tests/helpers/rack/rack_matrix_params_test.rb +0 -2
- data/tests/test_helper.rb +2 -1
- data/views/errors/403.xml.haml +6 -0
- data/views/errors/409.html.haml +47 -0
- data/views/errors/409.xml.haml +11 -0
- data/views/errors/502.html.haml +6 -5
- data/views/images/show.xml.haml +3 -2
- data/views/instances/new.html.haml +1 -1
- metadata +77 -30
@@ -0,0 +1,30 @@
|
|
1
|
+
# Memory database
|
2
|
+
if RUBY_PLATFORM == 'java'
|
3
|
+
ENV['DATABASE_LOCATION'] = 'jdbc:sqlite::memory:'
|
4
|
+
else
|
5
|
+
ENV['DATABASE_LOCATION'] = 'sqlite:/'
|
6
|
+
end
|
7
|
+
|
8
|
+
ENV['RACK_ENV'] = 'development'
|
9
|
+
|
10
|
+
require_relative '../../../lib/db'
|
11
|
+
|
12
|
+
module Deltacloud
|
13
|
+
module DatabaseTestHelper
|
14
|
+
|
15
|
+
def check_entity_base_attrs(entity, entity_klass, provider)
|
16
|
+
entity.must_be_kind_of entity_klass
|
17
|
+
entity.id.wont_be_nil
|
18
|
+
entity.created_at.wont_be_nil
|
19
|
+
entity.name.wont_be_empty
|
20
|
+
entity.description.wont_be_empty
|
21
|
+
entity.provider.must_equal provider
|
22
|
+
entity.model.must_equal entity_klass
|
23
|
+
entity.to_hash[:name].must_equal entity.name
|
24
|
+
entity.to_hash[:description].must_equal entity.description
|
25
|
+
entity.to_hash[:property].must_be_kind_of Hash
|
26
|
+
entity.to_hash[:property].wont_be_empty
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,94 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'require_relative' if RUBY_VERSION < '1.9'
|
3
|
+
|
4
|
+
require_relative 'db_helper.rb'
|
5
|
+
require_relative '../spec_helper.rb'
|
6
|
+
|
7
|
+
describe "Deltacloud::Database" do
|
8
|
+
|
9
|
+
include Deltacloud::DatabaseTestHelper
|
10
|
+
|
11
|
+
before do
|
12
|
+
@db = Deltacloud.database
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'has valid database connection' do
|
16
|
+
@db.test_connection.must_equal true
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'creates the database schema' do
|
20
|
+
@db.tables.wont_be_empty
|
21
|
+
@db.tables.must_include :providers
|
22
|
+
@db.tables.must_include :entities
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'should allow creation of providers' do
|
26
|
+
provider = Deltacloud::Database::Provider
|
27
|
+
provider.table_name.must_equal :providers
|
28
|
+
new_provider = provider.create(:driver => 'mock', :url => 'test1')
|
29
|
+
new_provider.must_be_kind_of provider
|
30
|
+
new_provider.destroy.wont_equal false
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'should not allow creation of provider with nil driver' do
|
34
|
+
provider = Deltacloud::Database::Provider
|
35
|
+
lambda {
|
36
|
+
new_provider = provider.create(:driver => nil, :url => 'test1')
|
37
|
+
}.must_raise Sequel::InvalidValue
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'allow creation of simple entity' do
|
41
|
+
provider = Deltacloud::Database::Provider
|
42
|
+
entity = Deltacloud::Database::Entity
|
43
|
+
entity.table_name.must_equal :entities
|
44
|
+
|
45
|
+
entity_provider = provider.create(:driver => :mock)
|
46
|
+
|
47
|
+
new_entity = entity_provider.add_entity(
|
48
|
+
:name => 'testEntity1',
|
49
|
+
:description => 'testEntity1 description',
|
50
|
+
:ent_properties => JSON::dump(:key => 'value')
|
51
|
+
)
|
52
|
+
|
53
|
+
check_entity_base_attrs new_entity, entity, entity_provider
|
54
|
+
|
55
|
+
new_entity.destroy.wont_equal false
|
56
|
+
entity_provider.destroy.wont_equal false
|
57
|
+
end
|
58
|
+
|
59
|
+
it 'allow creation of extended entities' do
|
60
|
+
provider = Deltacloud::Database::Provider
|
61
|
+
entity = Deltacloud::Database::MachineTemplate
|
62
|
+
entity.table_name.must_equal :entities
|
63
|
+
entity_provider = provider.create(:driver => :mock)
|
64
|
+
new_entity = entity_provider.add_machine_template(
|
65
|
+
:name => 'testMachineTemplate1',
|
66
|
+
:description => 'testMachineTemplate1 description',
|
67
|
+
:ent_properties => JSON::dump(:key => 'value'),
|
68
|
+
:machine_config => 'http://example.com/cimi/machine_configurations/m1-small',
|
69
|
+
:machine_image => 'http://example.com/cimi/machine_image/img1'
|
70
|
+
)
|
71
|
+
check_entity_base_attrs new_entity, entity, entity_provider
|
72
|
+
|
73
|
+
new_entity.machine_config.wont_be_empty
|
74
|
+
new_entity.machine_image.wont_be_empty
|
75
|
+
|
76
|
+
new_entity.destroy.wont_equal false
|
77
|
+
entity_provider.destroy.wont_equal false
|
78
|
+
end
|
79
|
+
|
80
|
+
it 'validate presence of required attributes for extended entities' do
|
81
|
+
provider = Deltacloud::Database::Provider
|
82
|
+
entity = Deltacloud::Database::MachineTemplate
|
83
|
+
entity.table_name.must_equal :entities
|
84
|
+
entity_provider = provider.create(:driver => :mock)
|
85
|
+
lambda {
|
86
|
+
new_entity = entity_provider.add_machine_template(
|
87
|
+
:name => 'testMachineTemplate1',
|
88
|
+
:description => 'testMachineTemplate1 description',
|
89
|
+
:ent_properties => JSON::dump(:key => 'value')
|
90
|
+
)
|
91
|
+
}.must_raise Sequel::ValidationFailed
|
92
|
+
end
|
93
|
+
|
94
|
+
end
|
@@ -23,10 +23,27 @@ describe "Machine model" do
|
|
23
23
|
before do
|
24
24
|
@xml = IO::read(File::join(DATA_DIR, "machine.xml"))
|
25
25
|
@json = IO::read(File::join(DATA_DIR, "machine.json"))
|
26
|
+
@xml_minimal = IO::read(File::join(DATA_DIR, "machine-minimal.xml"))
|
27
|
+
@json_minimal = IO::read(File::join(DATA_DIR, "machine-minimal.json"))
|
26
28
|
end
|
27
29
|
|
28
30
|
it "can be constructed from XML and JSON" do
|
29
31
|
should_properly_serialize_model CIMI::Model::Machine, @xml, @json
|
30
32
|
end
|
31
33
|
|
34
|
+
it "should parse minimal XML machine" do
|
35
|
+
machine = CIMI::Model::Machine.from_xml(@xml_minimal)
|
36
|
+
machine.id.wont_be_nil
|
37
|
+
machine.state.must_equal "STARTED"
|
38
|
+
machine.disks.entries.wont_be_nil
|
39
|
+
machine.disks.entries.size.must_equal 0
|
40
|
+
end
|
41
|
+
|
42
|
+
it "should parse minimal JSON machine" do
|
43
|
+
machine = CIMI::Model::Machine.from_json(@json_minimal)
|
44
|
+
machine.id.wont_be_nil
|
45
|
+
machine.state.must_equal "STARTED"
|
46
|
+
machine.disks.entries.wont_be_nil
|
47
|
+
machine.disks.entries.size.must_equal 0
|
48
|
+
end
|
32
49
|
end
|
data/tests/cimi/spec_helper.rb
CHANGED
@@ -18,6 +18,7 @@ require 'rubygems'
|
|
18
18
|
require 'minitest/autorun'
|
19
19
|
require 'minitest/spec'
|
20
20
|
require 'xmlsimple'
|
21
|
+
require 'json/pure'
|
21
22
|
require 'require_relative' if RUBY_VERSION < '1.9'
|
22
23
|
|
23
24
|
require_relative '../../lib/deltacloud/core_ext.rb'
|
@@ -66,8 +67,8 @@ class HashCmp
|
|
66
67
|
# and therefore not ordered, even though XmlSimple
|
67
68
|
# represents them as an array; since that array can be generated
|
68
69
|
# from a hash, in Ruby 1.8 the order of the array is random
|
69
|
-
exp = exp.sort! { |item1, item2| item1["
|
70
|
-
act = act.sort! { |item1, item2| item1["
|
70
|
+
exp = exp.sort! { |item1, item2| item1["key"] <=> item2["key"] }
|
71
|
+
act = act.sort! { |item1, item2| item1["key"] <=> item2["key"] }
|
71
72
|
end
|
72
73
|
0.upto(exp.size-1) do |i|
|
73
74
|
compare_values(exp[i], act[i], path + [ "#{name}[#{i}]" ])
|
@@ -34,4 +34,14 @@ describe Deltacloud::Collections::Drivers do
|
|
34
34
|
end
|
35
35
|
end
|
36
36
|
|
37
|
+
it 'properly serialize attributes in JSON' do
|
38
|
+
header 'Accept', 'application/json'
|
39
|
+
get root_url + "/drivers/ec2"
|
40
|
+
status.must_equal 200
|
41
|
+
json['driver'].wont_be_empty
|
42
|
+
json['driver']['id'].must_equal 'ec2'
|
43
|
+
json['driver']['name'].must_equal 'EC2'
|
44
|
+
json['driver']['entrypoints'].wont_be_empty
|
45
|
+
end
|
46
|
+
|
37
47
|
end
|
@@ -59,5 +59,18 @@ describe Deltacloud::Collections::Instances do
|
|
59
59
|
status.must_equal 204
|
60
60
|
end
|
61
61
|
|
62
|
-
|
62
|
+
it 'properly serialize attributes in JSON' do
|
63
|
+
header 'Accept', 'application/json'
|
64
|
+
get root_url + "/instances"
|
65
|
+
status.must_equal 200
|
66
|
+
json['instances'].wont_be_empty
|
67
|
+
get root_url + "/instances/inst1"
|
68
|
+
status.must_equal 200
|
69
|
+
json['instance'].wont_be_empty
|
70
|
+
Instance.attributes.each do |attr|
|
71
|
+
attr = attr.to_s.gsub(/_id$/,'') if attr.to_s =~ /_id$/
|
72
|
+
next if ['authn_error', 'firewalls', 'keyname', 'username', 'password'].include?(attr.to_s)
|
73
|
+
json['instance'].keys.must_include attr.to_s
|
74
|
+
end
|
75
|
+
end
|
63
76
|
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'require_relative' if RUBY_VERSION < '1.9'
|
3
|
+
|
4
|
+
require_relative File.join('..', 'common.rb')
|
5
|
+
|
6
|
+
describe Deltacloud::Collections::Realms do
|
7
|
+
|
8
|
+
before do
|
9
|
+
def app; run_frontend; end
|
10
|
+
authorize 'mockuser', 'mockpassword'
|
11
|
+
@collection = Deltacloud::Collections.collection(:realms)
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'has index operation' do
|
15
|
+
@collection.operation(:index).must_equal Sinatra::Rabbit::RealmsCollection::IndexOperation
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'has show operation' do
|
19
|
+
@collection.operation(:show).must_equal Sinatra::Rabbit::RealmsCollection::ShowOperation
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'returns list of realms in various formats with index operation' do
|
23
|
+
formats.each do |format|
|
24
|
+
header 'Accept', format
|
25
|
+
get root_url + '/realms'
|
26
|
+
status.must_equal 200
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'returns details about key in various formats with show operation' do
|
31
|
+
formats.each do |format|
|
32
|
+
header 'Accept', format
|
33
|
+
get root_url + '/realms/eu'
|
34
|
+
status.must_equal 200
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'reports 404 when querying non-existing key' do
|
39
|
+
get root_url + '/realms/unknown'
|
40
|
+
status.must_equal 404
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'properly serialize attributes in JSON' do
|
44
|
+
check_json_serialization_for :realm, 'us'
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'require_relative' if RUBY_VERSION < '1.9'
|
3
|
+
|
4
|
+
require_relative File.join('..', 'common.rb')
|
5
|
+
|
6
|
+
describe Deltacloud::Collections::StorageSnapshots do
|
7
|
+
|
8
|
+
before do
|
9
|
+
def app; run_frontend; end
|
10
|
+
authorize 'mockuser', 'mockpassword'
|
11
|
+
@collection = Deltacloud::Collections.collection(:storage_snapshots)
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'has index operation' do
|
15
|
+
@collection.operation(:index).must_equal Sinatra::Rabbit::StorageSnapshotsCollection::IndexOperation
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'has show operation' do
|
19
|
+
@collection.operation(:show).must_equal Sinatra::Rabbit::StorageSnapshotsCollection::ShowOperation
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'returns list of storage_snapshots in various formats with index operation' do
|
23
|
+
formats.each do |format|
|
24
|
+
header 'Accept', format
|
25
|
+
get root_url + '/storage_snapshots'
|
26
|
+
status.must_equal 200
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'returns details about storage_volume in various formats with show operation' do
|
31
|
+
formats.each do |format|
|
32
|
+
header 'Accept', format
|
33
|
+
get root_url + '/storage_snapshots/snap1'
|
34
|
+
status.must_equal 200
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'reports 404 when querying non-existing key' do
|
39
|
+
get root_url + '/storage_snapshots/unknown'
|
40
|
+
status.must_equal 404
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'properly serialize attributes in JSON' do
|
44
|
+
check_json_serialization_for :storage_snapshot, 'snap1', [:name, :description]
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'require_relative' if RUBY_VERSION < '1.9'
|
3
|
+
|
4
|
+
require_relative File.join('..', 'common.rb')
|
5
|
+
|
6
|
+
describe Deltacloud::Collections::StorageVolumes do
|
7
|
+
|
8
|
+
before do
|
9
|
+
def app; run_frontend; end
|
10
|
+
authorize 'mockuser', 'mockpassword'
|
11
|
+
@collection = Deltacloud::Collections.collection(:storage_volumes)
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'has index operation' do
|
15
|
+
@collection.operation(:index).must_equal Sinatra::Rabbit::StorageVolumesCollection::IndexOperation
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'has show operation' do
|
19
|
+
@collection.operation(:show).must_equal Sinatra::Rabbit::StorageVolumesCollection::ShowOperation
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'returns list of storage_volumes in various formats with index operation' do
|
23
|
+
formats.each do |format|
|
24
|
+
header 'Accept', format
|
25
|
+
get root_url + '/storage_volumes'
|
26
|
+
status.must_equal 200
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'returns details about storage_volume in various formats with show operation' do
|
31
|
+
formats.each do |format|
|
32
|
+
header 'Accept', format
|
33
|
+
get root_url + '/storage_volumes/vol1'
|
34
|
+
status.must_equal 200
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'reports 404 when querying non-existing key' do
|
39
|
+
get root_url + '/storage_volumes/unknown'
|
40
|
+
status.must_equal 404
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'properly serialize attributes in JSON' do
|
44
|
+
check_json_serialization_for :storage_volume, 'vol1'
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
data/tests/deltacloud/common.rb
CHANGED
@@ -12,3 +12,18 @@ Deltacloud::configure do |server|
|
|
12
12
|
end
|
13
13
|
|
14
14
|
Deltacloud.require_frontend!
|
15
|
+
|
16
|
+
def check_json_serialization_for(model, sample_id, optional_attrs=[])
|
17
|
+
header 'Accept', 'application/json'
|
18
|
+
get root_url + "/#{model.to_s.pluralize}"
|
19
|
+
status.must_equal 200
|
20
|
+
json[model.to_s.pluralize].wont_be_empty
|
21
|
+
get root_url + "/#{model.to_s.pluralize}/#{sample_id}"
|
22
|
+
status.must_equal 200
|
23
|
+
json[model.to_s].wont_be_empty
|
24
|
+
klass = self.class.const_get(model.to_s.camelize)
|
25
|
+
klass.attributes.each do |attr|
|
26
|
+
attr = attr.to_s.gsub(/_id$/,'') if attr.to_s =~ /_id$/
|
27
|
+
json[model.to_s].keys.must_include attr.to_s unless optional_attrs.include? attr
|
28
|
+
end
|
29
|
+
end
|
@@ -27,10 +27,6 @@ describe Deltacloud::Helpers::Application do
|
|
27
27
|
@helper.instance_action_method(:destroy).must_equal :delete
|
28
28
|
end
|
29
29
|
|
30
|
-
it 'provide helper to parse from XML to JSON' do
|
31
|
-
@helper.to_json('<xml>1</xml>').must_equal '{"xml":"1"}'
|
32
|
-
end
|
33
|
-
|
34
30
|
it 'provide helper for wrapping text nodes with CDATA' do
|
35
31
|
@helper.render_cdata('test').must_equal '<![CDATA[test]]>'
|
36
32
|
@helper.render_cdata('').must_equal '<![CDATA[]]>'
|
@@ -0,0 +1,108 @@
|
|
1
|
+
=begin
|
2
|
+
|
3
|
+
# TODO: This test require full access to 'kill' command and also
|
4
|
+
# ability to execute the actual launcher.
|
5
|
+
#
|
6
|
+
|
7
|
+
require 'rubygems'
|
8
|
+
require 'require_relative' if RUBY_VERSION < '1.9'
|
9
|
+
require_relative 'common.rb'
|
10
|
+
require 'socket'
|
11
|
+
require 'timeout'
|
12
|
+
require 'rest-client'
|
13
|
+
|
14
|
+
def is_port_open?(ip, port)
|
15
|
+
begin
|
16
|
+
Timeout::timeout(1) do
|
17
|
+
begin
|
18
|
+
s = TCPSocket.new(ip, port)
|
19
|
+
s.close
|
20
|
+
return true
|
21
|
+
rescue Errno::ECONNREFUSED, Errno::EHOSTUNREACH
|
22
|
+
return false
|
23
|
+
end
|
24
|
+
end
|
25
|
+
rescue Timeout::Error
|
26
|
+
end
|
27
|
+
return false
|
28
|
+
end
|
29
|
+
|
30
|
+
def wait_for_port_open(port)
|
31
|
+
retries = 5
|
32
|
+
begin
|
33
|
+
raise unless is_port_open?('127.0.0.1', port)
|
34
|
+
true
|
35
|
+
rescue
|
36
|
+
sleep(1) && retry if (retries-=1) != 0
|
37
|
+
false
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def kill_process(pid)
|
42
|
+
Process.kill('TERM', pid) rescue ''
|
43
|
+
# Die!
|
44
|
+
Process.kill('KILL', pid) rescue ''
|
45
|
+
end
|
46
|
+
|
47
|
+
describe "deltacloudd" do
|
48
|
+
|
49
|
+
before do
|
50
|
+
@pids ||= []
|
51
|
+
end
|
52
|
+
|
53
|
+
it 'starts the deltacloud server gracefully' do
|
54
|
+
pid = Process.fork
|
55
|
+
if pid.nil? then
|
56
|
+
Dir.chdir(File.join(File.dirname(__FILE__), '..', '..'))
|
57
|
+
exec("./bin/deltacloudd -i mock -p 3011")
|
58
|
+
else
|
59
|
+
Process.detach(pid) && @pids << pid
|
60
|
+
wait_for_port_open(3011).must_equal true
|
61
|
+
RestClient.get('http://localhost:3011/api').code.must_equal 200
|
62
|
+
kill_process(pid)
|
63
|
+
is_port_open?('127.0.0.1', 3011).must_equal false
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
it 'starts the deltacloud server gracefully with multiple frontends' do
|
68
|
+
pid = Process.fork
|
69
|
+
if pid.nil? then
|
70
|
+
Dir.chdir(File.join(File.dirname(__FILE__), '..', '..'))
|
71
|
+
exec("./bin/deltacloudd -i mock -f deltacloud,cimi,ec2 -p 3011")
|
72
|
+
else
|
73
|
+
Process.detach(pid) && @pids << pid
|
74
|
+
wait_for_port_open(3011).must_equal true
|
75
|
+
RestClient.get('http://localhost:3011/api').code.must_equal 200
|
76
|
+
RestClient.get('http://localhost:3011/cimi/cloudEntryPoint').code.must_equal 200
|
77
|
+
kill_process(pid)
|
78
|
+
is_port_open?('127.0.0.1', 3011).must_equal false
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
it 'starts the deltacloud server gracefully when using webrick' do
|
83
|
+
pid = Process.fork
|
84
|
+
if pid.nil? then
|
85
|
+
Dir.chdir(File.join(File.dirname(__FILE__), '..', '..'))
|
86
|
+
exec("./bin/deltacloudd -w -i mock -p 3011")
|
87
|
+
else
|
88
|
+
Process.detach(pid) && @pids << pid
|
89
|
+
wait_for_port_open(3011).must_equal true
|
90
|
+
RestClient.get('http://localhost:3011/api').code.must_equal 200
|
91
|
+
kill_process(pid)
|
92
|
+
is_port_open?('127.0.0.1', 3011).must_equal false
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
it 'lists the available drivers' do
|
97
|
+
Dir.chdir(File.join(File.dirname(__FILE__), '..', '..'))
|
98
|
+
output = `./bin/deltacloudd -l`
|
99
|
+
output.must_include 'Available drivers'
|
100
|
+
output.must_include 'mock'
|
101
|
+
end
|
102
|
+
|
103
|
+
after do
|
104
|
+
@pids.map { |pid| kill_process(pid) }
|
105
|
+
end
|
106
|
+
|
107
|
+
end
|
108
|
+
=end
|