deltacloud-core 1.1.1 → 1.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +40 -28
- data/bin/deltacloud-db-upgrade +24 -0
- data/bin/deltacloudd +20 -9
- data/config.ru +12 -53
- data/db/migrations/1_add_realm_to_machine_template.rb +23 -0
- data/deltacloud-core.gemspec +11 -5
- data/lib/cimi/collections.rb +4 -31
- data/lib/cimi/collections/address_templates.rb +2 -5
- data/lib/cimi/collections/addresses.rb +2 -5
- data/lib/cimi/collections/base.rb +18 -6
- data/lib/cimi/collections/credentials.rb +2 -5
- data/lib/cimi/collections/machine_images.rb +2 -1
- data/lib/cimi/collections/machine_templates.rb +2 -5
- data/lib/cimi/collections/machines.rb +6 -9
- data/lib/cimi/collections/network_ports.rb +3 -3
- data/lib/cimi/collections/networks.rb +5 -8
- data/lib/cimi/collections/system_templates.rb +72 -0
- data/lib/cimi/collections/systems.rb +194 -0
- data/lib/cimi/collections/volume_configurations.rb +1 -1
- data/lib/cimi/collections/volume_images.rb +2 -1
- data/lib/cimi/collections/volume_templates.rb +3 -2
- data/lib/cimi/collections/volumes.rb +2 -2
- data/lib/cimi/dependencies.rb +0 -2
- data/lib/cimi/helpers/cimi_helper.rb +12 -57
- data/lib/cimi/helpers/database_helper.rb +0 -4
- data/lib/cimi/models.rb +25 -14
- data/lib/cimi/models/address.rb +4 -31
- data/lib/cimi/models/address_create.rb +51 -0
- data/lib/cimi/models/address_template.rb +8 -52
- data/lib/cimi/models/address_template_create.rb +44 -0
- data/lib/cimi/models/base.rb +44 -6
- data/lib/cimi/models/cloud_entry_point.rb +1 -1
- data/lib/cimi/models/credential.rb +1 -1
- data/lib/cimi/models/credential_create.rb +46 -0
- data/lib/cimi/models/credential_template.rb +24 -0
- data/lib/cimi/models/machine.rb +1 -71
- data/lib/cimi/models/machine_configuration.rb +3 -3
- data/lib/cimi/models/machine_create.rb +49 -0
- data/lib/cimi/models/machine_image.rb +2 -25
- data/lib/cimi/models/machine_image_create.rb +41 -0
- data/lib/cimi/models/machine_template.rb +14 -34
- data/lib/cimi/models/machine_template_create.rb +33 -0
- data/lib/cimi/models/network.rb +0 -38
- data/lib/cimi/models/network_create.rb +43 -0
- data/lib/cimi/models/network_port.rb +17 -17
- data/lib/cimi/models/network_template.rb +2 -3
- data/lib/cimi/models/resource.rb +22 -3
- data/lib/cimi/models/schema.rb +94 -8
- data/lib/cimi/models/system.rb +67 -0
- data/lib/cimi/models/system_template.rb +63 -0
- data/lib/cimi/models/volume.rb +2 -42
- data/lib/cimi/models/volume_configuration.rb +4 -4
- data/lib/cimi/models/volume_create.rb +58 -0
- data/lib/cimi/models/volume_image.rb +8 -17
- data/lib/cimi/models/volume_image_create.rb +47 -0
- data/lib/cimi/models/volume_template.rb +6 -19
- data/lib/cimi/models/volume_template_create.rb +33 -0
- data/lib/db.rb +14 -22
- data/lib/db/volume_template.rb +1 -1
- data/lib/deltacloud/api.rb +6 -5
- data/lib/deltacloud/collections.rb +4 -27
- data/lib/deltacloud/collections/base.rb +4 -0
- data/lib/deltacloud/collections/images.rb +1 -1
- data/lib/deltacloud/collections/instances.rb +2 -2
- data/lib/deltacloud/core_ext/array.rb +1 -0
- data/lib/deltacloud/core_ext/integer.rb +13 -9
- data/lib/deltacloud/core_ext/string.rb +45 -28
- data/lib/deltacloud/drivers/arubacloud/arubacloud_driver.rb +0 -9
- data/lib/deltacloud/drivers/base_driver.rb +45 -16
- data/lib/deltacloud/drivers/digitalocean/digitalocean_driver.rb +78 -8
- data/lib/deltacloud/drivers/ec2/ec2_driver.rb +13 -9
- data/lib/deltacloud/drivers/fgcp/fgcp_client.rb +44 -0
- data/lib/deltacloud/drivers/fgcp/fgcp_driver.rb +164 -90
- data/lib/deltacloud/drivers/fgcp/fgcp_driver_cimi_methods.rb +74 -0
- data/lib/deltacloud/drivers/mock/data/instances/inst0.yml +3 -3
- data/lib/deltacloud/drivers/mock/data/instances/inst1.yml +3 -3
- data/lib/deltacloud/drivers/mock/data/instances/inst2.yml +3 -3
- data/lib/deltacloud/drivers/mock/mock_client.rb +17 -1
- data/lib/deltacloud/drivers/mock/mock_driver.rb +161 -204
- data/lib/deltacloud/drivers/mock/mock_driver_cimi_methods.rb +80 -0
- data/lib/deltacloud/drivers/opennebula/opennebula_driver.rb +6 -1
- data/lib/deltacloud/drivers/openstack/openstack_driver.rb +61 -68
- data/lib/deltacloud/drivers/rackspace/rackspace_driver.rb +0 -9
- data/lib/deltacloud/drivers/rhevm/rhevm_driver.rb +11 -6
- data/lib/deltacloud/drivers/terremark/terremark_driver.rb +0 -8
- data/lib/deltacloud/drivers/vsphere/vsphere_client.rb +11 -4
- data/lib/deltacloud/drivers/vsphere/vsphere_driver.rb +0 -12
- data/lib/deltacloud/helpers/collection_helper.rb +106 -0
- data/lib/deltacloud/helpers/deltacloud_helper.rb +12 -8
- data/lib/deltacloud/models/address.rb +19 -17
- data/lib/deltacloud/models/base_model.rb +29 -26
- data/lib/deltacloud/models/blob.rb +22 -20
- data/lib/deltacloud/models/bucket.rb +21 -16
- data/lib/deltacloud/models/firewall.rb +18 -16
- data/lib/deltacloud/models/firewall_rule.rb +22 -20
- data/lib/deltacloud/models/image.rb +29 -28
- data/lib/deltacloud/models/instance.rb +92 -94
- data/lib/deltacloud/models/instance_address.rb +42 -40
- data/lib/deltacloud/models/instance_profile.rb +28 -26
- data/lib/deltacloud/models/key.rb +47 -45
- data/lib/deltacloud/models/load_balancer.rb +32 -31
- data/lib/deltacloud/models/metric.rb +76 -29
- data/lib/deltacloud/models/provider.rb +15 -13
- data/lib/deltacloud/models/realm.rb +15 -21
- data/lib/deltacloud/models/storage_snapshot.rb +23 -19
- data/lib/deltacloud/models/storage_volume.rb +35 -34
- data/lib/deltacloud/version.rb +1 -1
- data/lib/deltacloud_rack.rb +22 -0
- data/lib/initialize.rb +28 -0
- data/lib/initializers/database_initialize.rb +76 -0
- data/lib/initializers/frontend_initialize.rb +42 -0
- data/lib/initializers/mock_initialize.rb +33 -0
- data/lib/sinatra/rack_logger.rb +35 -24
- data/tests/cimi/collections/cloud_entry_point_test.rb +1 -7
- data/tests/cimi/collections/machine_images_test.rb +2 -2
- data/tests/cimi/collections/machine_templates_test.rb +75 -0
- data/tests/cimi/collections/machines_test.rb +2 -2
- data/tests/cimi/collections/system_templates_test.rb +41 -0
- data/tests/cimi/collections/systems_test.rb +50 -0
- data/tests/cimi/db/database_helper_test.rb +17 -25
- data/tests/cimi/db/db_helper.rb +1 -12
- data/tests/cimi/db/entity_test.rb +7 -8
- data/tests/cimi/model/machine_create_spec.rb +44 -0
- data/tests/cimi/model/machine_template_spec.rb +29 -0
- data/tests/cimi/model/resource_spec.rb +40 -0
- data/tests/cimi/model/schema_spec.rb +37 -0
- data/tests/cimi/spec_helper.rb +3 -0
- data/tests/deltacloud/collections/buckets_collection_test.rb +1 -1
- data/tests/deltacloud/collections/drivers_collection_test.rb +2 -2
- data/tests/deltacloud/collections/hardware_profiles_collection_test.rb +2 -2
- data/tests/deltacloud/collections/images_collection_test.rb +2 -2
- data/tests/deltacloud/collections/instance_states_collection_test.rb +1 -1
- data/tests/deltacloud/collections/instances_collection_test.rb +6 -3
- data/tests/deltacloud/collections/keys_collection_test.rb +2 -2
- data/tests/deltacloud/collections/realms_collection_test.rb +2 -2
- data/tests/deltacloud/collections/storage_snapshots_collection_test.rb +2 -2
- data/tests/deltacloud/collections/storage_volumes_collection_test.rb +2 -2
- data/tests/deltacloud/collections_test.rb +5 -5
- data/tests/deltacloud/common.rb +2 -13
- data/tests/deltacloud/launcher_test.rb +3 -3
- data/tests/deltacloud/rack_test.rb +2 -2
- data/tests/deltacloud/server_test.rb +1 -1
- data/tests/drivers/base/base_driver_test.rb +5 -5
- data/tests/drivers/base/common.rb +2 -12
- data/tests/drivers/ec2/buckets_test.rb +1 -1
- data/tests/drivers/ec2/images_test.rb +2 -2
- data/tests/drivers/ec2/instance_test.rb +6 -6
- data/tests/drivers/ec2/keys_test.rb +3 -3
- data/tests/drivers/ec2/realms_test.rb +2 -2
- data/tests/drivers/ec2/storage_snapshots_test.rb +1 -1
- data/tests/drivers/fgcp/common.rb +32 -0
- data/tests/drivers/fgcp/firewall_test.rb +70 -0
- data/tests/drivers/fgcp/hardware_profiles_test.rb +61 -0
- data/tests/drivers/fgcp/images_test.rb +46 -0
- data/tests/drivers/fgcp/provider_test.rb +27 -0
- data/tests/drivers/fgcp/realms_test.rb +53 -0
- data/tests/drivers/fgcp/storage_volumes_test.rb +58 -0
- data/tests/drivers/gogrid/images_test.rb +2 -2
- data/tests/drivers/gogrid/instances_test.rb +2 -2
- data/tests/drivers/gogrid/realms_test.rb +2 -2
- data/tests/drivers/mock/images_test.rb +4 -4
- data/tests/drivers/mock/instances_test.rb +9 -9
- data/tests/drivers/mock/keys_test.rb +3 -3
- data/tests/drivers/mock/realms_test.rb +2 -2
- data/tests/drivers/mock/storage_snapshots_test.rb +2 -2
- data/tests/drivers/mock/storage_volumes_test.rb +4 -4
- data/tests/drivers/models/instance_test.rb +2 -2
- data/tests/drivers/openstack/images_test.rb +2 -2
- data/tests/drivers/openstack/instances_test.rb +2 -3
- data/tests/drivers/openstack/keys_test.rb +1 -1
- data/tests/drivers/openstack/realms_test.rb +2 -11
- data/tests/drivers/rhevm/common.rb +33 -12
- data/tests/drivers/rhevm/images_test.rb +20 -12
- data/tests/drivers/rhevm/instance_test.rb +62 -46
- data/tests/drivers/rhevm/provider_test.rb +12 -6
- data/tests/drivers/rhevm/realms_test.rb +15 -9
- data/tests/ec2/query_parser_test.rb +1 -1
- data/tests/test_helper.rb +68 -12
- data/views/addresses/show.html.haml +1 -1
- data/views/buckets/show.html.haml +1 -1
- data/views/errors/{500.html.haml → common.html.haml} +0 -0
- data/views/errors/common.xml.haml +17 -0
- data/views/firewalls/index.xml.haml +2 -2
- data/views/firewalls/new.html.haml +2 -2
- data/views/images/show.html.haml +1 -1
- data/views/instances/run_command.html.haml +1 -1
- data/views/instances/show.html.haml +3 -3
- data/views/keys/index.html.haml +1 -0
- data/views/keys/show.html.haml +8 -4
- data/views/keys/show.xml.haml +3 -2
- data/views/load_balancers/new.html.haml +1 -1
- data/views/load_balancers/show.html.haml +2 -2
- data/views/metrics/show.html.haml +1 -1
- data/views/realms/index.html.haml +0 -2
- data/views/realms/show.html.haml +0 -4
- data/views/realms/show.xml.haml +0 -3
- data/views/storage_snapshots/index.html.haml +1 -1
- data/views/storage_snapshots/new.html.haml +1 -1
- data/views/storage_volumes/new.html.haml +2 -2
- data/views/storage_volumes/show.html.haml +3 -3
- metadata +90 -41
- data/views/errors/400.html.haml +0 -41
- data/views/errors/400.xml.haml +0 -3
- data/views/errors/401.html.haml +0 -26
- data/views/errors/401.xml.haml +0 -3
- data/views/errors/403.html.haml +0 -42
- data/views/errors/403.xml.haml +0 -9
- data/views/errors/404.html.haml +0 -28
- data/views/errors/404.xml.haml +0 -3
- data/views/errors/405.html.haml +0 -29
- data/views/errors/405.xml.haml +0 -5
- data/views/errors/409.html.haml +0 -47
- data/views/errors/409.xml.haml +0 -11
- data/views/errors/500.xml.haml +0 -13
- data/views/errors/501.html.haml +0 -44
- data/views/errors/501.xml.haml +0 -1
- data/views/errors/502.html.haml +0 -44
- data/views/errors/502.xml.haml +0 -1
- data/views/errors/504.html.haml +0 -43
- data/views/errors/504.xml.haml +0 -1
@@ -13,21 +13,13 @@ end
|
|
13
13
|
describe Deltacloud::Helpers::Database do
|
14
14
|
include Deltacloud::DatabaseTestHelper
|
15
15
|
|
16
|
-
Provider = Deltacloud::Database::Provider
|
17
|
-
Entity = Deltacloud::Database::Entity
|
18
|
-
BaseModel = CIMI::Model::Base
|
19
|
-
|
20
16
|
before do
|
21
|
-
|
22
|
-
@
|
23
|
-
@
|
24
|
-
end
|
17
|
+
@provider = Deltacloud::Database::Provider
|
18
|
+
@entity = Deltacloud::Database::Entity
|
19
|
+
@baseModel = CIMI::Model::Base
|
25
20
|
|
26
|
-
|
27
|
-
|
28
|
-
@db.test_environment?.must_equal true
|
29
|
-
ENV['RACK_ENV'] = 'development'
|
30
|
-
@db.test_environment?.must_equal false
|
21
|
+
@db = DatabaseHelper.new
|
22
|
+
@prov = @provider::lookup
|
31
23
|
end
|
32
24
|
|
33
25
|
it 'report if given entity is provided by database' do
|
@@ -40,7 +32,7 @@ describe Deltacloud::Helpers::Database do
|
|
40
32
|
end
|
41
33
|
|
42
34
|
it 'create provider when it does not exists' do
|
43
|
-
@prov.must_be_kind_of
|
35
|
+
@prov.must_be_kind_of @provider
|
44
36
|
@prov.driver.must_equal 'mock'
|
45
37
|
@prov.url.must_equal @db.current_provider
|
46
38
|
@prov.must_respond_to :entities
|
@@ -57,17 +49,17 @@ describe Deltacloud::Helpers::Database do
|
|
57
49
|
:name => 'testMachine1',
|
58
50
|
:description => 'testMachine1 description',
|
59
51
|
:ent_properties => JSON::dump(:key => 'value'),
|
60
|
-
:be_kind =>
|
52
|
+
:be_kind => @baseModel.name,
|
61
53
|
:be_id => 'inst1'
|
62
54
|
)
|
63
55
|
|
64
|
-
check_entity_base_attrs new_entity,
|
56
|
+
check_entity_base_attrs new_entity, @entity, @prov
|
65
57
|
|
66
|
-
result =
|
58
|
+
result = @entity.retrieve(@baseModel.new(:id => 'inst1'))
|
67
59
|
result.must_equal new_entity
|
68
60
|
|
69
61
|
new_entity.destroy
|
70
|
-
result =
|
62
|
+
result = @entity.retrieve(@baseModel.new(:id => 'inst1'))
|
71
63
|
result.exists?.must_equal false
|
72
64
|
end
|
73
65
|
|
@@ -78,13 +70,13 @@ describe Deltacloud::Helpers::Database do
|
|
78
70
|
:name => 'testMachine1',
|
79
71
|
:description => 'testMachine1 description',
|
80
72
|
:ent_properties => JSON::dump(:key => 'value'),
|
81
|
-
:be_kind =>
|
73
|
+
:be_kind => @baseModel.name,
|
82
74
|
:be_id => 'base1'
|
83
75
|
)
|
84
76
|
|
85
|
-
check_entity_base_attrs new_entity,
|
77
|
+
check_entity_base_attrs new_entity, @entity, @prov
|
86
78
|
|
87
|
-
result =
|
79
|
+
result = @entity::retrieve(@baseModel.new(:id => 'base1'))
|
88
80
|
result.name.must_equal new_entity.name
|
89
81
|
result.description.must_equal new_entity.description
|
90
82
|
result.properties.must_equal new_entity.properties
|
@@ -99,15 +91,15 @@ describe Deltacloud::Helpers::Database do
|
|
99
91
|
:name => 'testMachine1',
|
100
92
|
:description => 'testMachine1 description',
|
101
93
|
:ent_properties => JSON::dump(:key => 'value'),
|
102
|
-
:be_kind =>
|
94
|
+
:be_kind => @baseModel.name,
|
103
95
|
:be_id => 'base1'
|
104
96
|
)
|
105
97
|
|
106
|
-
check_entity_base_attrs new_entity,
|
98
|
+
check_entity_base_attrs new_entity, @entity, @prov
|
107
99
|
|
108
|
-
base =
|
100
|
+
base = @baseModel.new(:id => 'base1')
|
109
101
|
base.destroy
|
110
|
-
entity =
|
102
|
+
entity = @entity.retrieve(base)
|
111
103
|
entity.wont_be_nil
|
112
104
|
entity.exists?.must_equal false
|
113
105
|
end
|
data/tests/cimi/db/db_helper.rb
CHANGED
@@ -1,15 +1,4 @@
|
|
1
|
-
|
2
|
-
if RUBY_PLATFORM == 'java'
|
3
|
-
require 'jdbc/sqlite3'
|
4
|
-
Jdbc::SQLite3.load_driver
|
5
|
-
ENV['DATABASE_LOCATION'] = 'jdbc:sqlite::memory:'
|
6
|
-
else
|
7
|
-
ENV['DATABASE_LOCATION'] = 'sqlite:/'
|
8
|
-
end
|
9
|
-
|
10
|
-
ENV['RACK_ENV'] = 'development'
|
11
|
-
|
12
|
-
require_relative '../../../lib/db'
|
1
|
+
require_relative '../../test_helper'
|
13
2
|
|
14
3
|
module Deltacloud
|
15
4
|
module DatabaseTestHelper
|
@@ -7,23 +7,22 @@ require_relative '../spec_helper.rb'
|
|
7
7
|
require_relative './../collections/common.rb'
|
8
8
|
|
9
9
|
describe "Deltacloud::Database::Entity" do
|
10
|
-
Provider = Deltacloud::Database::Provider
|
11
|
-
Entity = Deltacloud::Database::Entity
|
12
|
-
BaseModel = CIMI::Model::Base
|
13
10
|
|
14
11
|
before do
|
15
|
-
|
16
|
-
@
|
12
|
+
@provider = Deltacloud::Database::Provider
|
13
|
+
@entity = Deltacloud::Database::Entity
|
14
|
+
@baseModel = CIMI::Model::Base
|
15
|
+
@prov = @provider::lookup
|
17
16
|
end
|
18
17
|
|
19
18
|
it 'newly created entities have valid ent_properties' do
|
20
|
-
model =
|
21
|
-
ent =
|
19
|
+
model = @baseModel.new(:id => "/base/42")
|
20
|
+
ent = @entity.retrieve(model)
|
22
21
|
ent.properties = nil
|
23
22
|
ent.exists?.must_equal false
|
24
23
|
ent.save
|
25
24
|
|
26
|
-
ent =
|
25
|
+
ent = @entity.retrieve(model)
|
27
26
|
ent.exists?.must_equal true
|
28
27
|
end
|
29
28
|
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
# Licensed to the Apache Software Foundation (ASF) under one or more
|
2
|
+
# contributor license agreements. See the NOTICE file distributed with
|
3
|
+
# this work for additional information regarding copyright ownership. The
|
4
|
+
# ASF licenses this file to you under the Apache License, Version 2.0 (the
|
5
|
+
# "License"); you may not use this file except in compliance with the
|
6
|
+
# License. You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
12
|
+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
13
|
+
# License for the specific language governing permissions and limitations
|
14
|
+
# under the License.
|
15
|
+
#
|
16
|
+
require 'rubygems'
|
17
|
+
require 'require_relative' if RUBY_VERSION < '1.9'
|
18
|
+
|
19
|
+
require_relative '../spec_helper.rb' if require 'minitest/autorun'
|
20
|
+
|
21
|
+
describe "MachineCreate model" do
|
22
|
+
|
23
|
+
before do
|
24
|
+
@xml = read_data_file("machine_create_by_value.xml")
|
25
|
+
end
|
26
|
+
|
27
|
+
it "can be constructed from XML with template by value" do
|
28
|
+
mc = CIMI::Model::MachineCreate.from_xml(@xml)
|
29
|
+
mc.name.must_equal "xml_machine_by_value"
|
30
|
+
mt = mc.machine_template
|
31
|
+
mt.wont_be_nil
|
32
|
+
mt.href.must_be_nil
|
33
|
+
mt.machine_config.href.wont_be_nil
|
34
|
+
end
|
35
|
+
|
36
|
+
it "can be built in code" do
|
37
|
+
mc = CIMI::Model::MachineCreate.new(:name => "from_code")
|
38
|
+
mc.machine_template.href = "/mts/1"
|
39
|
+
mc.machine_template.machine_config.cpu = 42
|
40
|
+
json = JSON::parse(mc.to_json)
|
41
|
+
json["machineTemplate"]["href"].must_equal "/mts/1"
|
42
|
+
json["machineTemplate"]["machineConfig"]["cpu"].must_equal 42
|
43
|
+
end
|
44
|
+
end
|
@@ -29,4 +29,33 @@ describe "MachineTemplate model" do
|
|
29
29
|
should_properly_serialize_model CIMI::Model::MachineTemplate, @xml, @json
|
30
30
|
end
|
31
31
|
|
32
|
+
describe "can have an embedded machineConfig" do
|
33
|
+
MACHINE_CONFIG_ID = "http://cimi.example.org/machine_configs/1"
|
34
|
+
|
35
|
+
it "in XML" do
|
36
|
+
mt = CIMI::Model::MachineTemplate.from_xml(@xml)
|
37
|
+
mt.name.must_equal "My First Template"
|
38
|
+
mt.machine_config.href.must_equal MACHINE_CONFIG_ID
|
39
|
+
mt.machine_config.id.must_be_nil
|
40
|
+
mt.machine_config.cpu = 7
|
41
|
+
|
42
|
+
mc = parse_xml(mt.to_xml)["MachineTemplate"].first["machineConfig"].first
|
43
|
+
mc.wont_be_nil
|
44
|
+
mc["href"].must_equal MACHINE_CONFIG_ID
|
45
|
+
mc["cpu"].first["content"].must_equal "7"
|
46
|
+
end
|
47
|
+
|
48
|
+
it "in JSON" do
|
49
|
+
mt = CIMI::Model::MachineTemplate.from_json(@json)
|
50
|
+
mt.name.must_equal "My First Template"
|
51
|
+
mt.machine_config.href.must_equal MACHINE_CONFIG_ID
|
52
|
+
mt.machine_config.id.must_be_nil
|
53
|
+
mt.machine_config.cpu = 7
|
54
|
+
|
55
|
+
mc = JSON::parse(mt.to_json)["machineConfig"]
|
56
|
+
mc.wont_be_nil
|
57
|
+
mc["href"].must_equal MACHINE_CONFIG_ID
|
58
|
+
mc["cpu"].must_equal 7
|
59
|
+
end
|
60
|
+
end
|
32
61
|
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# Licensed to the Apache Software Foundation (ASF) under one or more
|
2
|
+
# contributor license agreements. See the NOTICE file distributed with
|
3
|
+
# this work for additional information regarding copyright ownership. The
|
4
|
+
# ASF licenses this file to you under the Apache License, Version 2.0 (the
|
5
|
+
# "License"); you may not use this file except in compliance with the
|
6
|
+
# License. You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
12
|
+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
13
|
+
# License for the specific language governing permissions and limitations
|
14
|
+
# under the License.
|
15
|
+
#
|
16
|
+
require 'rubygems'
|
17
|
+
require 'require_relative' if RUBY_VERSION < '1.9'
|
18
|
+
|
19
|
+
require_relative '../spec_helper.rb' if require 'minitest/autorun'
|
20
|
+
|
21
|
+
describe "Resource" do
|
22
|
+
|
23
|
+
class ReqResource < CIMI::Model::Resource
|
24
|
+
scalar :req, :required => true
|
25
|
+
end
|
26
|
+
|
27
|
+
describe "required attributes" do
|
28
|
+
it "should require a value" do
|
29
|
+
obj = ReqResource.from_json({}.to_json)
|
30
|
+
assert_raises CIMI::Model::ValidationError do
|
31
|
+
obj.validate!(:json)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should validate numbers" do
|
36
|
+
obj = ReqResource.from_json({"req" => 42}.to_json)
|
37
|
+
obj.validate!(:json).must_be_nil
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -232,6 +232,43 @@ describe "Schema" do
|
|
232
232
|
@schema.to_xml(obj).must_equal sample_xml
|
233
233
|
end
|
234
234
|
|
235
|
+
describe "of references" do
|
236
|
+
class RefTarget < CIMI::Model::Base
|
237
|
+
text :name
|
238
|
+
end
|
239
|
+
|
240
|
+
class RefArray < CIMI::Model::Base
|
241
|
+
array :things, :ref => RefTarget
|
242
|
+
end
|
243
|
+
|
244
|
+
before do
|
245
|
+
@json = { "things" =>
|
246
|
+
[ { "name" => "first", "href" => "/things/1" },
|
247
|
+
{ "name" => "second", "href" => "/things/2" },
|
248
|
+
{ "href" => "/things/3" } ]}.to_json
|
249
|
+
end
|
250
|
+
|
251
|
+
it "should convert from JSON" do
|
252
|
+
model = RefArray.from_json(@json)
|
253
|
+
check_model(model)
|
254
|
+
end
|
255
|
+
|
256
|
+
it "should convert from XML" do
|
257
|
+
xml = RefArray.from_json(@json).to_xml
|
258
|
+
model = RefArray.from_xml(xml)
|
259
|
+
check_model(model)
|
260
|
+
end
|
261
|
+
|
262
|
+
def check_model(model)
|
263
|
+
model.things.size.must_equal 3
|
264
|
+
model.things.first.must_respond_to :name
|
265
|
+
model.things.first.href.must_equal "/things/1"
|
266
|
+
model.things.first.name.must_equal "first"
|
267
|
+
model.things.last.name.must_be_nil
|
268
|
+
model.things.last.href.must_equal "/things/3"
|
269
|
+
end
|
270
|
+
end
|
271
|
+
|
235
272
|
def check_structs(obj)
|
236
273
|
obj.wont_be_nil
|
237
274
|
obj[:structs].size.must_equal 2
|
data/tests/cimi/spec_helper.rb
CHANGED
@@ -21,7 +21,10 @@ require 'xmlsimple'
|
|
21
21
|
require 'json/pure'
|
22
22
|
require 'require_relative' if RUBY_VERSION < '1.9'
|
23
23
|
|
24
|
+
ENV['API_FRONTEND'] = 'cimi'
|
25
|
+
|
24
26
|
require_relative '../../lib/deltacloud/core_ext.rb'
|
27
|
+
require_relative '../../lib/initialize'
|
25
28
|
require_relative '../../lib/cimi/models.rb'
|
26
29
|
|
27
30
|
DATA_DIR = File::join(File::expand_path(File::dirname(__FILE__)), 'data')
|
@@ -12,7 +12,7 @@ describe Deltacloud::Collections::Buckets do
|
|
12
12
|
end
|
13
13
|
|
14
14
|
it 'has index operation' do
|
15
|
-
@collection.operation(:index).must_equal
|
15
|
+
@collection.operation(:index).must_equal Deltacloud::Rabbit::BucketsCollection::IndexOperation
|
16
16
|
end
|
17
17
|
|
18
18
|
it 'provides URL to specify new bucket' do
|
@@ -11,11 +11,11 @@ describe Deltacloud::Collections::Drivers do
|
|
11
11
|
end
|
12
12
|
|
13
13
|
it 'has index operation' do
|
14
|
-
@collection.operation(:index).must_equal
|
14
|
+
@collection.operation(:index).must_equal Deltacloud::Rabbit::DriversCollection::IndexOperation
|
15
15
|
end
|
16
16
|
|
17
17
|
it 'has show operation' do
|
18
|
-
@collection.operation(:show).must_equal
|
18
|
+
@collection.operation(:show).must_equal Deltacloud::Rabbit::DriversCollection::ShowOperation
|
19
19
|
end
|
20
20
|
|
21
21
|
it 'returns list of drivers in various formats with index operation' do
|
@@ -12,11 +12,11 @@ describe Deltacloud::Collections::HardwareProfiles do
|
|
12
12
|
end
|
13
13
|
|
14
14
|
it 'has index operation' do
|
15
|
-
@collection.operation(:index).must_equal
|
15
|
+
@collection.operation(:index).must_equal Deltacloud::Rabbit::HardwareProfilesCollection::IndexOperation
|
16
16
|
end
|
17
17
|
|
18
18
|
it 'has show operation' do
|
19
|
-
@collection.operation(:show).must_equal
|
19
|
+
@collection.operation(:show).must_equal Deltacloud::Rabbit::HardwareProfilesCollection::ShowOperation
|
20
20
|
end
|
21
21
|
|
22
22
|
it 'returns list of hardware profiles in various formats with index operation' do
|
@@ -12,11 +12,11 @@ describe Deltacloud::Collections::Images do
|
|
12
12
|
end
|
13
13
|
|
14
14
|
it 'has index operation' do
|
15
|
-
@collection.operation(:index).must_equal
|
15
|
+
@collection.operation(:index).must_equal Deltacloud::Rabbit::ImagesCollection::IndexOperation
|
16
16
|
end
|
17
17
|
|
18
18
|
it 'has show operation' do
|
19
|
-
@collection.operation(:show).must_equal
|
19
|
+
@collection.operation(:show).must_equal Deltacloud::Rabbit::ImagesCollection::ShowOperation
|
20
20
|
end
|
21
21
|
|
22
22
|
it 'returns list of images in various formats with index operation' do
|
@@ -12,7 +12,7 @@ describe Deltacloud::Collections::InstanceStates do
|
|
12
12
|
end
|
13
13
|
|
14
14
|
it 'has index operation' do
|
15
|
-
@collection.operation(:index).must_equal
|
15
|
+
@collection.operation(:index).must_equal Deltacloud::Rabbit::InstanceStatesCollection::IndexOperation
|
16
16
|
end
|
17
17
|
|
18
18
|
it 'returns list of states for current driver in various formats with index operation' do
|
@@ -12,7 +12,7 @@ describe Deltacloud::Collections::Instances do
|
|
12
12
|
end
|
13
13
|
|
14
14
|
it 'has index operation' do
|
15
|
-
@collection.operation(:index).must_equal
|
15
|
+
@collection.operation(:index).must_equal Deltacloud::Rabbit::InstancesCollection::IndexOperation
|
16
16
|
end
|
17
17
|
|
18
18
|
it 'provides URL to specify new instance' do
|
@@ -45,13 +45,16 @@ describe Deltacloud::Collections::Instances do
|
|
45
45
|
delete root_url + '/instances/' + instance_id
|
46
46
|
status.must_equal 405
|
47
47
|
# You can't remove RUNNING instance
|
48
|
-
(xml/'error/message').first.text.strip.must_equal '
|
48
|
+
(xml/'error/message').first.text.strip.must_equal 'Method Not Allowed'
|
49
49
|
post root_url + '/instances/' + instance_id + '/reboot'
|
50
50
|
status.must_equal 202
|
51
|
+
(xml/'instance/state').first.text.strip.must_equal 'RUNNING'
|
51
52
|
post root_url + '/instances/' + instance_id + '/stop'
|
52
53
|
status.must_equal 202
|
54
|
+
(xml/'instance/state').first.text.strip.must_equal 'STOPPED'
|
53
55
|
post root_url + '/instances/' + instance_id + '/start'
|
54
56
|
status.must_equal 202
|
57
|
+
(xml/'instance/state').first.text.strip.must_equal 'RUNNING'
|
55
58
|
post root_url + '/instances/' + instance_id + '/stop'
|
56
59
|
status.must_equal 202
|
57
60
|
(xml/'instance/state').first.text.strip.must_equal 'STOPPED'
|
@@ -67,7 +70,7 @@ describe Deltacloud::Collections::Instances do
|
|
67
70
|
get root_url + "/instances/inst1"
|
68
71
|
status.must_equal 200
|
69
72
|
json['instance'].wont_be_empty
|
70
|
-
Instance.attributes.each do |attr|
|
73
|
+
Deltacloud::Instance.attributes.each do |attr|
|
71
74
|
attr = attr.to_s.gsub(/_id$/,'') if attr.to_s =~ /_id$/
|
72
75
|
next if ['launch_time', 'authn_error', 'firewalls', 'keyname', 'username', 'password', 'instance_profile'].include?(attr.to_s)
|
73
76
|
json['instance'].keys.must_include attr.to_s
|
@@ -12,11 +12,11 @@ describe Deltacloud::Collections::Keys do
|
|
12
12
|
end
|
13
13
|
|
14
14
|
it 'has index operation' do
|
15
|
-
@collection.operation(:index).must_equal
|
15
|
+
@collection.operation(:index).must_equal Deltacloud::Rabbit::KeysCollection::IndexOperation
|
16
16
|
end
|
17
17
|
|
18
18
|
it 'has show operation' do
|
19
|
-
@collection.operation(:show).must_equal
|
19
|
+
@collection.operation(:show).must_equal Deltacloud::Rabbit::KeysCollection::ShowOperation
|
20
20
|
end
|
21
21
|
|
22
22
|
it 'returns list of keys in various formats with index operation' do
|
@@ -12,11 +12,11 @@ describe Deltacloud::Collections::Realms do
|
|
12
12
|
end
|
13
13
|
|
14
14
|
it 'has index operation' do
|
15
|
-
@collection.operation(:index).must_equal
|
15
|
+
@collection.operation(:index).must_equal Deltacloud::Rabbit::RealmsCollection::IndexOperation
|
16
16
|
end
|
17
17
|
|
18
18
|
it 'has show operation' do
|
19
|
-
@collection.operation(:show).must_equal
|
19
|
+
@collection.operation(:show).must_equal Deltacloud::Rabbit::RealmsCollection::ShowOperation
|
20
20
|
end
|
21
21
|
|
22
22
|
it 'returns list of realms in various formats with index operation' do
|