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.
Files changed (220) hide show
  1. data/Rakefile +40 -28
  2. data/bin/deltacloud-db-upgrade +24 -0
  3. data/bin/deltacloudd +20 -9
  4. data/config.ru +12 -53
  5. data/db/migrations/1_add_realm_to_machine_template.rb +23 -0
  6. data/deltacloud-core.gemspec +11 -5
  7. data/lib/cimi/collections.rb +4 -31
  8. data/lib/cimi/collections/address_templates.rb +2 -5
  9. data/lib/cimi/collections/addresses.rb +2 -5
  10. data/lib/cimi/collections/base.rb +18 -6
  11. data/lib/cimi/collections/credentials.rb +2 -5
  12. data/lib/cimi/collections/machine_images.rb +2 -1
  13. data/lib/cimi/collections/machine_templates.rb +2 -5
  14. data/lib/cimi/collections/machines.rb +6 -9
  15. data/lib/cimi/collections/network_ports.rb +3 -3
  16. data/lib/cimi/collections/networks.rb +5 -8
  17. data/lib/cimi/collections/system_templates.rb +72 -0
  18. data/lib/cimi/collections/systems.rb +194 -0
  19. data/lib/cimi/collections/volume_configurations.rb +1 -1
  20. data/lib/cimi/collections/volume_images.rb +2 -1
  21. data/lib/cimi/collections/volume_templates.rb +3 -2
  22. data/lib/cimi/collections/volumes.rb +2 -2
  23. data/lib/cimi/dependencies.rb +0 -2
  24. data/lib/cimi/helpers/cimi_helper.rb +12 -57
  25. data/lib/cimi/helpers/database_helper.rb +0 -4
  26. data/lib/cimi/models.rb +25 -14
  27. data/lib/cimi/models/address.rb +4 -31
  28. data/lib/cimi/models/address_create.rb +51 -0
  29. data/lib/cimi/models/address_template.rb +8 -52
  30. data/lib/cimi/models/address_template_create.rb +44 -0
  31. data/lib/cimi/models/base.rb +44 -6
  32. data/lib/cimi/models/cloud_entry_point.rb +1 -1
  33. data/lib/cimi/models/credential.rb +1 -1
  34. data/lib/cimi/models/credential_create.rb +46 -0
  35. data/lib/cimi/models/credential_template.rb +24 -0
  36. data/lib/cimi/models/machine.rb +1 -71
  37. data/lib/cimi/models/machine_configuration.rb +3 -3
  38. data/lib/cimi/models/machine_create.rb +49 -0
  39. data/lib/cimi/models/machine_image.rb +2 -25
  40. data/lib/cimi/models/machine_image_create.rb +41 -0
  41. data/lib/cimi/models/machine_template.rb +14 -34
  42. data/lib/cimi/models/machine_template_create.rb +33 -0
  43. data/lib/cimi/models/network.rb +0 -38
  44. data/lib/cimi/models/network_create.rb +43 -0
  45. data/lib/cimi/models/network_port.rb +17 -17
  46. data/lib/cimi/models/network_template.rb +2 -3
  47. data/lib/cimi/models/resource.rb +22 -3
  48. data/lib/cimi/models/schema.rb +94 -8
  49. data/lib/cimi/models/system.rb +67 -0
  50. data/lib/cimi/models/system_template.rb +63 -0
  51. data/lib/cimi/models/volume.rb +2 -42
  52. data/lib/cimi/models/volume_configuration.rb +4 -4
  53. data/lib/cimi/models/volume_create.rb +58 -0
  54. data/lib/cimi/models/volume_image.rb +8 -17
  55. data/lib/cimi/models/volume_image_create.rb +47 -0
  56. data/lib/cimi/models/volume_template.rb +6 -19
  57. data/lib/cimi/models/volume_template_create.rb +33 -0
  58. data/lib/db.rb +14 -22
  59. data/lib/db/volume_template.rb +1 -1
  60. data/lib/deltacloud/api.rb +6 -5
  61. data/lib/deltacloud/collections.rb +4 -27
  62. data/lib/deltacloud/collections/base.rb +4 -0
  63. data/lib/deltacloud/collections/images.rb +1 -1
  64. data/lib/deltacloud/collections/instances.rb +2 -2
  65. data/lib/deltacloud/core_ext/array.rb +1 -0
  66. data/lib/deltacloud/core_ext/integer.rb +13 -9
  67. data/lib/deltacloud/core_ext/string.rb +45 -28
  68. data/lib/deltacloud/drivers/arubacloud/arubacloud_driver.rb +0 -9
  69. data/lib/deltacloud/drivers/base_driver.rb +45 -16
  70. data/lib/deltacloud/drivers/digitalocean/digitalocean_driver.rb +78 -8
  71. data/lib/deltacloud/drivers/ec2/ec2_driver.rb +13 -9
  72. data/lib/deltacloud/drivers/fgcp/fgcp_client.rb +44 -0
  73. data/lib/deltacloud/drivers/fgcp/fgcp_driver.rb +164 -90
  74. data/lib/deltacloud/drivers/fgcp/fgcp_driver_cimi_methods.rb +74 -0
  75. data/lib/deltacloud/drivers/mock/data/instances/inst0.yml +3 -3
  76. data/lib/deltacloud/drivers/mock/data/instances/inst1.yml +3 -3
  77. data/lib/deltacloud/drivers/mock/data/instances/inst2.yml +3 -3
  78. data/lib/deltacloud/drivers/mock/mock_client.rb +17 -1
  79. data/lib/deltacloud/drivers/mock/mock_driver.rb +161 -204
  80. data/lib/deltacloud/drivers/mock/mock_driver_cimi_methods.rb +80 -0
  81. data/lib/deltacloud/drivers/opennebula/opennebula_driver.rb +6 -1
  82. data/lib/deltacloud/drivers/openstack/openstack_driver.rb +61 -68
  83. data/lib/deltacloud/drivers/rackspace/rackspace_driver.rb +0 -9
  84. data/lib/deltacloud/drivers/rhevm/rhevm_driver.rb +11 -6
  85. data/lib/deltacloud/drivers/terremark/terremark_driver.rb +0 -8
  86. data/lib/deltacloud/drivers/vsphere/vsphere_client.rb +11 -4
  87. data/lib/deltacloud/drivers/vsphere/vsphere_driver.rb +0 -12
  88. data/lib/deltacloud/helpers/collection_helper.rb +106 -0
  89. data/lib/deltacloud/helpers/deltacloud_helper.rb +12 -8
  90. data/lib/deltacloud/models/address.rb +19 -17
  91. data/lib/deltacloud/models/base_model.rb +29 -26
  92. data/lib/deltacloud/models/blob.rb +22 -20
  93. data/lib/deltacloud/models/bucket.rb +21 -16
  94. data/lib/deltacloud/models/firewall.rb +18 -16
  95. data/lib/deltacloud/models/firewall_rule.rb +22 -20
  96. data/lib/deltacloud/models/image.rb +29 -28
  97. data/lib/deltacloud/models/instance.rb +92 -94
  98. data/lib/deltacloud/models/instance_address.rb +42 -40
  99. data/lib/deltacloud/models/instance_profile.rb +28 -26
  100. data/lib/deltacloud/models/key.rb +47 -45
  101. data/lib/deltacloud/models/load_balancer.rb +32 -31
  102. data/lib/deltacloud/models/metric.rb +76 -29
  103. data/lib/deltacloud/models/provider.rb +15 -13
  104. data/lib/deltacloud/models/realm.rb +15 -21
  105. data/lib/deltacloud/models/storage_snapshot.rb +23 -19
  106. data/lib/deltacloud/models/storage_volume.rb +35 -34
  107. data/lib/deltacloud/version.rb +1 -1
  108. data/lib/deltacloud_rack.rb +22 -0
  109. data/lib/initialize.rb +28 -0
  110. data/lib/initializers/database_initialize.rb +76 -0
  111. data/lib/initializers/frontend_initialize.rb +42 -0
  112. data/lib/initializers/mock_initialize.rb +33 -0
  113. data/lib/sinatra/rack_logger.rb +35 -24
  114. data/tests/cimi/collections/cloud_entry_point_test.rb +1 -7
  115. data/tests/cimi/collections/machine_images_test.rb +2 -2
  116. data/tests/cimi/collections/machine_templates_test.rb +75 -0
  117. data/tests/cimi/collections/machines_test.rb +2 -2
  118. data/tests/cimi/collections/system_templates_test.rb +41 -0
  119. data/tests/cimi/collections/systems_test.rb +50 -0
  120. data/tests/cimi/db/database_helper_test.rb +17 -25
  121. data/tests/cimi/db/db_helper.rb +1 -12
  122. data/tests/cimi/db/entity_test.rb +7 -8
  123. data/tests/cimi/model/machine_create_spec.rb +44 -0
  124. data/tests/cimi/model/machine_template_spec.rb +29 -0
  125. data/tests/cimi/model/resource_spec.rb +40 -0
  126. data/tests/cimi/model/schema_spec.rb +37 -0
  127. data/tests/cimi/spec_helper.rb +3 -0
  128. data/tests/deltacloud/collections/buckets_collection_test.rb +1 -1
  129. data/tests/deltacloud/collections/drivers_collection_test.rb +2 -2
  130. data/tests/deltacloud/collections/hardware_profiles_collection_test.rb +2 -2
  131. data/tests/deltacloud/collections/images_collection_test.rb +2 -2
  132. data/tests/deltacloud/collections/instance_states_collection_test.rb +1 -1
  133. data/tests/deltacloud/collections/instances_collection_test.rb +6 -3
  134. data/tests/deltacloud/collections/keys_collection_test.rb +2 -2
  135. data/tests/deltacloud/collections/realms_collection_test.rb +2 -2
  136. data/tests/deltacloud/collections/storage_snapshots_collection_test.rb +2 -2
  137. data/tests/deltacloud/collections/storage_volumes_collection_test.rb +2 -2
  138. data/tests/deltacloud/collections_test.rb +5 -5
  139. data/tests/deltacloud/common.rb +2 -13
  140. data/tests/deltacloud/launcher_test.rb +3 -3
  141. data/tests/deltacloud/rack_test.rb +2 -2
  142. data/tests/deltacloud/server_test.rb +1 -1
  143. data/tests/drivers/base/base_driver_test.rb +5 -5
  144. data/tests/drivers/base/common.rb +2 -12
  145. data/tests/drivers/ec2/buckets_test.rb +1 -1
  146. data/tests/drivers/ec2/images_test.rb +2 -2
  147. data/tests/drivers/ec2/instance_test.rb +6 -6
  148. data/tests/drivers/ec2/keys_test.rb +3 -3
  149. data/tests/drivers/ec2/realms_test.rb +2 -2
  150. data/tests/drivers/ec2/storage_snapshots_test.rb +1 -1
  151. data/tests/drivers/fgcp/common.rb +32 -0
  152. data/tests/drivers/fgcp/firewall_test.rb +70 -0
  153. data/tests/drivers/fgcp/hardware_profiles_test.rb +61 -0
  154. data/tests/drivers/fgcp/images_test.rb +46 -0
  155. data/tests/drivers/fgcp/provider_test.rb +27 -0
  156. data/tests/drivers/fgcp/realms_test.rb +53 -0
  157. data/tests/drivers/fgcp/storage_volumes_test.rb +58 -0
  158. data/tests/drivers/gogrid/images_test.rb +2 -2
  159. data/tests/drivers/gogrid/instances_test.rb +2 -2
  160. data/tests/drivers/gogrid/realms_test.rb +2 -2
  161. data/tests/drivers/mock/images_test.rb +4 -4
  162. data/tests/drivers/mock/instances_test.rb +9 -9
  163. data/tests/drivers/mock/keys_test.rb +3 -3
  164. data/tests/drivers/mock/realms_test.rb +2 -2
  165. data/tests/drivers/mock/storage_snapshots_test.rb +2 -2
  166. data/tests/drivers/mock/storage_volumes_test.rb +4 -4
  167. data/tests/drivers/models/instance_test.rb +2 -2
  168. data/tests/drivers/openstack/images_test.rb +2 -2
  169. data/tests/drivers/openstack/instances_test.rb +2 -3
  170. data/tests/drivers/openstack/keys_test.rb +1 -1
  171. data/tests/drivers/openstack/realms_test.rb +2 -11
  172. data/tests/drivers/rhevm/common.rb +33 -12
  173. data/tests/drivers/rhevm/images_test.rb +20 -12
  174. data/tests/drivers/rhevm/instance_test.rb +62 -46
  175. data/tests/drivers/rhevm/provider_test.rb +12 -6
  176. data/tests/drivers/rhevm/realms_test.rb +15 -9
  177. data/tests/ec2/query_parser_test.rb +1 -1
  178. data/tests/test_helper.rb +68 -12
  179. data/views/addresses/show.html.haml +1 -1
  180. data/views/buckets/show.html.haml +1 -1
  181. data/views/errors/{500.html.haml → common.html.haml} +0 -0
  182. data/views/errors/common.xml.haml +17 -0
  183. data/views/firewalls/index.xml.haml +2 -2
  184. data/views/firewalls/new.html.haml +2 -2
  185. data/views/images/show.html.haml +1 -1
  186. data/views/instances/run_command.html.haml +1 -1
  187. data/views/instances/show.html.haml +3 -3
  188. data/views/keys/index.html.haml +1 -0
  189. data/views/keys/show.html.haml +8 -4
  190. data/views/keys/show.xml.haml +3 -2
  191. data/views/load_balancers/new.html.haml +1 -1
  192. data/views/load_balancers/show.html.haml +2 -2
  193. data/views/metrics/show.html.haml +1 -1
  194. data/views/realms/index.html.haml +0 -2
  195. data/views/realms/show.html.haml +0 -4
  196. data/views/realms/show.xml.haml +0 -3
  197. data/views/storage_snapshots/index.html.haml +1 -1
  198. data/views/storage_snapshots/new.html.haml +1 -1
  199. data/views/storage_volumes/new.html.haml +2 -2
  200. data/views/storage_volumes/show.html.haml +3 -3
  201. metadata +90 -41
  202. data/views/errors/400.html.haml +0 -41
  203. data/views/errors/400.xml.haml +0 -3
  204. data/views/errors/401.html.haml +0 -26
  205. data/views/errors/401.xml.haml +0 -3
  206. data/views/errors/403.html.haml +0 -42
  207. data/views/errors/403.xml.haml +0 -9
  208. data/views/errors/404.html.haml +0 -28
  209. data/views/errors/404.xml.haml +0 -3
  210. data/views/errors/405.html.haml +0 -29
  211. data/views/errors/405.xml.haml +0 -5
  212. data/views/errors/409.html.haml +0 -47
  213. data/views/errors/409.xml.haml +0 -11
  214. data/views/errors/500.xml.haml +0 -13
  215. data/views/errors/501.html.haml +0 -44
  216. data/views/errors/501.xml.haml +0 -1
  217. data/views/errors/502.html.haml +0 -44
  218. data/views/errors/502.xml.haml +0 -1
  219. data/views/errors/504.html.haml +0 -43
  220. 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
- ENV['RACK_ENV'] = 'development'
22
- @db = DatabaseHelper.new
23
- @prov = Provider::lookup
24
- end
17
+ @provider = Deltacloud::Database::Provider
18
+ @entity = Deltacloud::Database::Entity
19
+ @baseModel = CIMI::Model::Base
25
20
 
26
- it 'report if application is running under test environment' do
27
- ENV['RACK_ENV'] = 'test'
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 Deltacloud::Database::Provider
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 => BaseModel.name,
52
+ :be_kind => @baseModel.name,
61
53
  :be_id => 'inst1'
62
54
  )
63
55
 
64
- check_entity_base_attrs new_entity, Entity, @prov
56
+ check_entity_base_attrs new_entity, @entity, @prov
65
57
 
66
- result = Entity.retrieve(BaseModel.new(:id => 'inst1'))
58
+ result = @entity.retrieve(@baseModel.new(:id => 'inst1'))
67
59
  result.must_equal new_entity
68
60
 
69
61
  new_entity.destroy
70
- result = Entity.retrieve(BaseModel.new(:id => 'inst1'))
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 => BaseModel.name,
73
+ :be_kind => @baseModel.name,
82
74
  :be_id => 'base1'
83
75
  )
84
76
 
85
- check_entity_base_attrs new_entity, Entity, @prov
77
+ check_entity_base_attrs new_entity, @entity, @prov
86
78
 
87
- result = Entity::retrieve(BaseModel.new(:id => 'base1'))
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 => BaseModel.name,
94
+ :be_kind => @baseModel.name,
103
95
  :be_id => 'base1'
104
96
  )
105
97
 
106
- check_entity_base_attrs new_entity, Entity, @prov
98
+ check_entity_base_attrs new_entity, @entity, @prov
107
99
 
108
- base = BaseModel.new(:id => 'base1')
100
+ base = @baseModel.new(:id => 'base1')
109
101
  base.destroy
110
- entity = Entity.retrieve(base)
102
+ entity = @entity.retrieve(base)
111
103
  entity.wont_be_nil
112
104
  entity.exists?.must_equal false
113
105
  end
@@ -1,15 +1,4 @@
1
- # Memory database
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
- ENV['RACK_ENV'] = 'development'
16
- @prov = Provider::lookup
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 = BaseModel.new(:id => "/base/42")
21
- ent = Entity.retrieve(model)
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 = Entity.retrieve(model)
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
@@ -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 Sinatra::Rabbit::BucketsCollection::IndexOperation
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 Sinatra::Rabbit::DriversCollection::IndexOperation
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 Sinatra::Rabbit::DriversCollection::ShowOperation
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 Sinatra::Rabbit::HardwareProfilesCollection::IndexOperation
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 Sinatra::Rabbit::HardwareProfilesCollection::ShowOperation
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 Sinatra::Rabbit::ImagesCollection::IndexOperation
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 Sinatra::Rabbit::ImagesCollection::ShowOperation
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 Sinatra::Rabbit::InstanceStatesCollection::IndexOperation
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 Sinatra::Rabbit::InstancesCollection::IndexOperation
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 'Requested method not allowed'
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 Sinatra::Rabbit::KeysCollection::IndexOperation
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 Sinatra::Rabbit::KeysCollection::ShowOperation
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 Sinatra::Rabbit::RealmsCollection::IndexOperation
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 Sinatra::Rabbit::RealmsCollection::ShowOperation
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