deltacloud-core 1.0.1 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +99 -141
- data/bin/deltacloudd +4 -1
- data/config.ru +13 -6
- data/config/drivers/aruba.yaml +8 -0
- data/config/drivers/fgcp.yaml +3 -2
- data/deltacloud-core.gemspec +13 -9
- data/lib/cimi/collections/cloud_entry_point.rb +1 -1
- data/lib/cimi/models.rb +1 -7
- data/lib/cimi/models/base.rb +1 -4
- data/lib/cimi/models/cloud_entry_point.rb +14 -0
- data/lib/cimi/models/machine.rb +4 -4
- data/lib/cimi/models/machine_admin.rb +1 -0
- data/lib/cimi/models/machine_configuration.rb +4 -4
- data/lib/cimi/models/schema.rb +17 -14
- data/lib/cimi/models/volume_image.rb +1 -1
- data/lib/cimi/server.rb +1 -1
- data/lib/deltacloud/api.rb +55 -3
- data/lib/deltacloud/collections/addresses.rb +1 -1
- data/lib/deltacloud/collections/buckets.rb +12 -10
- data/lib/deltacloud/collections/firewalls.rb +2 -1
- data/lib/deltacloud/collections/hardware_profiles.rb +1 -1
- data/lib/deltacloud/collections/images.rb +2 -2
- data/lib/deltacloud/collections/instance_states.rb +6 -3
- data/lib/deltacloud/collections/instances.rb +2 -1
- data/lib/deltacloud/collections/keys.rb +6 -2
- data/lib/deltacloud/collections/load_balancers.rb +8 -7
- data/lib/deltacloud/collections/metrics.rb +2 -1
- data/lib/deltacloud/collections/realms.rb +1 -1
- data/lib/deltacloud/collections/storage_snapshots.rb +2 -1
- data/lib/deltacloud/collections/storage_volumes.rb +2 -2
- data/lib/deltacloud/core_ext.rb +1 -7
- data/lib/deltacloud/core_ext/hash.rb +7 -5
- data/lib/deltacloud/core_ext/string.rb +1 -0
- data/lib/deltacloud/drivers/aruba/aruba_driver.rb +469 -0
- data/lib/deltacloud/drivers/base_driver.rb +12 -17
- data/lib/deltacloud/drivers/ec2/ec2_driver.rb +50 -22
- data/lib/deltacloud/drivers/eucalyptus/eucalyptus_driver.rb +1 -1
- data/lib/deltacloud/drivers/exceptions.rb +12 -2
- data/lib/deltacloud/drivers/features.rb +8 -0
- data/lib/deltacloud/drivers/fgcp/fgcp_client.rb +21 -6
- data/lib/deltacloud/drivers/fgcp/fgcp_driver.rb +169 -57
- data/lib/deltacloud/drivers/gogrid/gogrid_driver.rb +1 -1
- data/lib/deltacloud/drivers/mock/mock_client.rb +2 -0
- data/lib/deltacloud/drivers/mock/mock_driver.rb +101 -13
- data/lib/deltacloud/drivers/opennebula/occi_client.rb +12 -6
- data/lib/deltacloud/drivers/opennebula/opennebula_driver.rb +10 -18
- data/lib/deltacloud/drivers/openstack/openstack_driver.rb +46 -1
- data/lib/deltacloud/drivers/rhevm/rhevm_driver.rb +17 -17
- data/lib/deltacloud/drivers/vsphere/vsphere_driver.rb +4 -4
- data/lib/deltacloud/helpers.rb +4 -4
- data/lib/deltacloud/helpers/blob_stream_helper.rb +4 -6
- data/lib/deltacloud/helpers/deltacloud_helper.rb +17 -1
- data/lib/deltacloud/helpers/driver_helper.rb +7 -3
- data/lib/deltacloud/helpers/url_helper.rb +4 -4
- data/lib/deltacloud/models/address.rb +1 -1
- data/lib/deltacloud/models/base_model.rb +0 -14
- data/lib/deltacloud/models/bucket.rb +0 -10
- data/lib/deltacloud/models/hardware_profile.rb +5 -26
- data/lib/deltacloud/models/image.rb +0 -12
- data/lib/deltacloud/models/instance.rb +6 -22
- data/lib/deltacloud/models/key.rb +2 -2
- data/lib/deltacloud/models/metric.rb +1 -1
- data/lib/deltacloud/models/storage_snapshot.rb +4 -0
- data/lib/deltacloud/server.rb +8 -2
- data/lib/deltacloud_rack.rb +40 -10
- data/lib/ec2/query_parser.rb +9 -4
- data/lib/ec2/server.rb +1 -1
- data/lib/ec2/views/create_key_pair.haml +3 -0
- data/lib/ec2/views/delete_key_pair.haml +1 -0
- data/lib/ec2/views/describe_availability_zones.haml +6 -0
- data/lib/ec2/views/describe_images.haml +10 -0
- data/lib/ec2/views/describe_instance_set.haml +24 -0
- data/lib/ec2/views/describe_instances.haml +9 -0
- data/lib/ec2/views/describe_key_pairs.haml +5 -0
- data/lib/ec2/views/error.haml +4 -0
- data/lib/ec2/views/instance_action.haml +9 -0
- data/lib/ec2/views/reboot_instances.haml +1 -0
- data/lib/ec2/views/run_instances.haml +7 -0
- data/lib/ec2/views/start_instances.haml +1 -0
- data/lib/ec2/views/stop_instances.haml +1 -0
- data/lib/ec2/views/terminate_instances.haml +9 -0
- data/lib/sinatra.rb +0 -1
- data/lib/sinatra/rack_accept.rb +1 -1
- data/lib/sinatra/rack_driver_select.rb +2 -2
- data/lib/sinatra/rack_etag.rb +5 -1
- data/lib/sinatra/rack_logger.rb +127 -0
- data/lib/sinatra/rack_matrix_params.rb +1 -1
- data/tests/cimi/collections/cloud_entry_point_test.rb +46 -0
- data/tests/cimi/collections/common.rb +17 -0
- data/tests/cimi/collections/machine_images_test.rb +44 -0
- data/tests/cimi/collections/machines_test.rb +41 -0
- data/tests/cimi/spec/cimi/model/machine_admin_spec.rb +35 -0
- data/tests/cimi/spec/cimi/model/machine_configuration_spec.rb +31 -0
- data/tests/cimi/spec/cimi/model/machine_image_spec.rb +33 -0
- data/tests/cimi/spec/cimi/model/machine_spec.rb +32 -0
- data/tests/cimi/spec/cimi/model/machine_template_spec.rb +32 -0
- data/tests/cimi/spec/cimi/model/schema_spec.rb +245 -0
- data/tests/cimi/spec/cimi/model/volume_configuration_spec.rb +34 -0
- data/tests/cimi/spec/cimi/model/volume_image_spec.rb +33 -0
- data/tests/cimi/spec/cimi/model/volume_spec.rb +32 -0
- data/tests/cimi/spec/cimi/model/volume_template_spec.rb +32 -0
- data/tests/cimi/spec/spec_helper.rb +136 -0
- data/tests/deltacloud/base_collection_test.rb +30 -0
- data/tests/deltacloud/collections/buckets_collection_test.rb +65 -0
- data/tests/deltacloud/collections/drivers_collection_test.rb +37 -0
- data/tests/deltacloud/collections/hardware_profiles_collection_test.rb +53 -0
- data/tests/deltacloud/collections/images_collection_test.rb +59 -0
- data/tests/deltacloud/collections/instance_states_collection_test.rb +34 -0
- data/tests/deltacloud/collections/instances_collection_test.rb +63 -0
- data/tests/deltacloud/collections/keys_collection_test.rb +63 -0
- data/tests/deltacloud/collections_test.rb +35 -0
- data/tests/deltacloud/common.rb +14 -0
- data/tests/deltacloud/deltacloud_helper_test.rb +55 -0
- data/tests/deltacloud/drivers_test.rb +73 -0
- data/tests/deltacloud/rack_test.rb +51 -0
- data/tests/deltacloud/server_test.rb +149 -0
- data/tests/{api → deprecated/api}/common.rb +0 -0
- data/tests/{api → deprecated/api}/driver_test.rb +0 -0
- data/tests/deprecated/api/library_test.rb +6 -0
- data/tests/{cimi → deprecated/cimi}/features/step_definitions/common_steps.rb +0 -0
- data/tests/{cimi → deprecated/cimi}/features/step_definitions/machine_images_steps.rb +0 -0
- data/tests/{cimi → deprecated/cimi}/features/step_definitions/machines_steps.rb +0 -0
- data/tests/{cimi → deprecated/cimi}/features/step_definitions/volumes_steps.rb +0 -0
- data/tests/{cimi → deprecated/cimi}/features/support/env.rb +0 -0
- data/tests/{common.rb → deprecated/common.rb} +0 -0
- data/tests/{core_ext → deprecated/core_ext}/string.rb +0 -0
- data/tests/{drivers → deprecated/drivers}/ec2/api_test.rb +0 -0
- data/tests/deprecated/drivers/ec2/common.rb +23 -0
- data/tests/{drivers → deprecated/drivers}/ec2/drivers_test.rb +0 -0
- data/tests/{drivers → deprecated/drivers}/ec2/hardware_profiles_test.rb +0 -0
- data/tests/deprecated/drivers/ec2/images_test.rb +230 -0
- data/tests/{drivers → deprecated/drivers}/ec2/instances_test.rb +0 -0
- data/tests/deprecated/drivers/ec2/keys_test.rb +181 -0
- data/tests/deprecated/drivers/ec2/realms_test.rb +146 -0
- data/tests/{drivers → deprecated/drivers}/fgcp/api_test.rb +0 -0
- data/tests/{drivers → deprecated/drivers}/fgcp/hardware_profiles_test.rb +0 -0
- data/tests/{drivers → deprecated/drivers}/fgcp/realms_test.rb +0 -0
- data/tests/{drivers → deprecated/drivers}/fgcp/setup.rb +0 -0
- data/tests/{drivers → deprecated/drivers}/google/api_test.rb +0 -0
- data/tests/{drivers → deprecated/drivers}/google/buckets_test.rb +0 -0
- data/tests/{drivers → deprecated/drivers}/google/common.rb +2 -2
- data/tests/{drivers → deprecated/drivers}/mock/api_test.rb +0 -0
- data/tests/{drivers → deprecated/drivers}/mock/buckets_test.rb +0 -0
- data/tests/{drivers → deprecated/drivers}/mock/common.rb +0 -0
- data/tests/{drivers → deprecated/drivers}/mock/drivers_test.rb +0 -0
- data/tests/{drivers → deprecated/drivers}/mock/hardware_profiles_test.rb +0 -0
- data/tests/deprecated/drivers/mock/images_test.rb +197 -0
- data/tests/deprecated/drivers/mock/instances_test.rb +343 -0
- data/tests/deprecated/drivers/mock/keys_test.rb +161 -0
- data/tests/deprecated/drivers/mock/realms_test.rb +132 -0
- data/tests/deprecated/drivers/mock/storage_snapshots_test.rb +114 -0
- data/tests/deprecated/drivers/mock/storage_volumes_test.rb +122 -0
- data/tests/{drivers → deprecated/drivers}/openstack/api_test.rb +0 -0
- data/tests/{drivers → deprecated/drivers}/openstack/common.rb +0 -0
- data/tests/{drivers → deprecated/drivers}/openstack/hardware_profiles_test.rb +0 -0
- data/tests/{drivers → deprecated/drivers}/openstack/images_test.rb +0 -0
- data/tests/{drivers → deprecated/drivers}/openstack/instances_test.rb +0 -0
- data/tests/{drivers → deprecated/drivers}/openstack/realms_test.rb +0 -0
- data/tests/{drivers → deprecated/drivers}/rackspace/api_test.rb +0 -0
- data/tests/{drivers → deprecated/drivers}/rackspace/buckets_test.rb +0 -0
- data/tests/{drivers → deprecated/drivers}/rackspace/common.rb +0 -0
- data/tests/{drivers → deprecated/drivers}/rackspace/hardware_profiles_test.rb +0 -0
- data/tests/{drivers → deprecated/drivers}/rackspace/images_test.rb +0 -0
- data/tests/{drivers → deprecated/drivers}/rackspace/instances_test.rb +0 -0
- data/tests/{drivers → deprecated/drivers}/rackspace/realms_test.rb +0 -0
- data/tests/{drivers → deprecated/drivers}/rhevm/api_test.rb +0 -0
- data/tests/deprecated/drivers/rhevm/common.rb +21 -0
- data/tests/{drivers → deprecated/drivers}/rhevm/hardware_profiles_test.rb +0 -0
- data/tests/deprecated/drivers/rhevm/images_test.rb +48 -0
- data/tests/{drivers → deprecated/drivers}/rhevm/instances_test.rb +0 -0
- data/tests/deprecated/drivers/rhevm/realms_test.rb +40 -0
- data/tests/{minitest_common.rb → deprecated/minitest_common.rb} +0 -0
- data/tests/{minitest_common_api_test.rb → deprecated/minitest_common_api_test.rb} +0 -0
- data/tests/{rabbit_test.rb → deprecated/rabbit_test.rb} +0 -0
- data/tests/drivers/base/base_driver_test.rb +124 -0
- data/tests/{api → drivers/base}/library_test.rb +2 -8
- data/tests/drivers/ec2/common.rb +23 -15
- data/tests/drivers/ec2/images_test.rb +30 -211
- data/tests/drivers/ec2/instance_test.rb +104 -0
- data/tests/drivers/ec2/keys_test.rb +32 -161
- data/tests/drivers/ec2/realms_test.rb +26 -128
- data/tests/drivers/ec2/storage_snapshots_test.rb +54 -0
- data/tests/drivers/mock/images_test.rb +37 -179
- data/tests/drivers/mock/instances_test.rb +103 -340
- data/tests/drivers/mock/keys_test.rb +30 -145
- data/tests/drivers/mock/realms_test.rb +23 -118
- data/tests/drivers/mock/storage_snapshots_test.rb +23 -100
- data/tests/drivers/mock/storage_volumes_test.rb +41 -104
- data/tests/drivers/models/address_test.rb +18 -0
- data/tests/drivers/models/base_test.rb +33 -0
- data/tests/drivers/models/blob_test.rb +18 -0
- data/tests/drivers/models/hardware_profile_test.rb +52 -0
- data/tests/drivers/models/instance_address_test.rb +24 -0
- data/tests/drivers/models/instance_profile_test.rb +21 -0
- data/tests/drivers/models/instance_test.rb +29 -0
- data/tests/drivers/models/keys_test.rb +25 -0
- data/tests/drivers/models/metrics_test.rb +20 -0
- data/tests/drivers/rhevm/common.rb +15 -15
- data/tests/drivers/rhevm/images_test.rb +61 -36
- data/tests/drivers/rhevm/instance_test.rb +104 -0
- data/tests/drivers/rhevm/provider_test.rb +48 -0
- data/tests/drivers/rhevm/realms_test.rb +40 -37
- data/tests/ec2/common.rb +24 -0
- data/tests/ec2/query_parser_test.rb +98 -0
- data/tests/ec2/server_test.rb +45 -0
- data/tests/helpers/core_ext/array_test.rb +24 -0
- data/tests/helpers/core_ext/hash_test.rb +42 -0
- data/tests/helpers/core_ext/integer_test.rb +19 -0
- data/tests/helpers/core_ext/string_test.rb +74 -0
- data/tests/test_helper.rb +66 -0
- data/views/api/show.html.haml +1 -2
- data/views/api/show.xml.haml +1 -2
- data/views/blobs/show.xml.haml +1 -2
- data/views/keys/new.html.haml +9 -2
- data/views/load_balancers/new.html.haml +35 -34
- data/views/metrics/index.html.haml +1 -1
- data/views/metrics/show.html.haml +2 -2
- data/views/metrics/show.xml.haml +6 -2
- data/views/storage_volumes/attach.html.haml +1 -1
- data/views/storage_volumes/show.html.haml +1 -1
- metadata +853 -544
- data/lib/sinatra/accept_media_types.rb +0 -154
@@ -0,0 +1,104 @@
|
|
1
|
+
require 'minitest/autorun'
|
2
|
+
|
3
|
+
require_relative File.join('..', '..', '..', 'lib', 'deltacloud', 'api.rb')
|
4
|
+
require_relative 'common.rb'
|
5
|
+
|
6
|
+
describe 'Ec2Driver Instances' do
|
7
|
+
|
8
|
+
before do
|
9
|
+
@driver = Deltacloud::new(:ec2, credentials)
|
10
|
+
VCR.insert_cassette __name__
|
11
|
+
end
|
12
|
+
|
13
|
+
after do
|
14
|
+
VCR.eject_cassette
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'must throw error when wrong credentials' do
|
18
|
+
Proc.new do
|
19
|
+
@driver.backend.images(OpenStruct.new(:user => 'unknown', :password => 'wrong'))
|
20
|
+
end.must_raise Deltacloud::ExceptionHandler::AuthenticationFailure, 'Authentication Failure'
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'must return list of instances' do
|
24
|
+
@driver.instances.wont_be_empty
|
25
|
+
@driver.instances.first.must_be_kind_of Instance
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'must allow to filter instances' do
|
29
|
+
@driver.instances(:id => 'i-4d15f036').wont_be_empty
|
30
|
+
@driver.instances(:id => 'i-4d15f036').must_be_kind_of Array
|
31
|
+
@driver.instances(:id => 'i-4d15f036').size.must_equal 1
|
32
|
+
@driver.instances(:id => 'i-4d15f036').first.id.must_equal 'i-4d15f036'
|
33
|
+
@driver.instances(:owner_id => '293787749884').wont_be_empty
|
34
|
+
@driver.instances(:owner_id => '293787749884').each do |inst|
|
35
|
+
inst.owner_id.must_equal '293787749884'
|
36
|
+
end
|
37
|
+
@driver.instances(:id => 'i-00000000').must_be_empty
|
38
|
+
@driver.instances(:id => 'unknown').must_be_empty
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'must allow to retrieve single instance' do
|
42
|
+
@driver.instance(:id => 'i-4d15f036').wont_be_nil
|
43
|
+
@driver.instance(:id => 'i-4d15f036').must_be_kind_of Instance
|
44
|
+
@driver.instance(:id => 'i-4d15f036').id.must_equal 'i-4d15f036'
|
45
|
+
@driver.instance(:id => 'i-00000000').must_be_nil
|
46
|
+
@driver.instance(:id => 'unknown').must_be_nil
|
47
|
+
end
|
48
|
+
|
49
|
+
it 'must allow to create a new instance if instance supported' do
|
50
|
+
instance = @driver.create_instance('ami-aecd60c7',
|
51
|
+
:realm_id => 'us-east-1a',
|
52
|
+
:hwp_id => 't1.micro',
|
53
|
+
:keyname => 'test1',
|
54
|
+
:user_data => 'test user data',
|
55
|
+
:'firewalls1' => 'default'
|
56
|
+
)
|
57
|
+
instance = instance.wait_for!(@driver, record_retries) { |i| i.is_running? }
|
58
|
+
instance.must_be_kind_of Instance
|
59
|
+
instance.is_running?.must_equal true
|
60
|
+
@driver.instance(:id => instance.id).wont_be_nil
|
61
|
+
@driver.instance(:id => instance.id).id.must_equal instance.id
|
62
|
+
@driver.instance(:id => instance.id).image_id.must_equal 'ami-aecd60c7'
|
63
|
+
@driver.instance(:id => instance.id).name.wont_be_nil
|
64
|
+
@driver.instance(:id => instance.id).instance_profile.name.must_equal 't1.micro'
|
65
|
+
@driver.instance(:id => instance.id).realm_id.must_equal 'us-east-1a'
|
66
|
+
@driver.instance(:id => instance.id).owner_id.must_equal '293787749884'
|
67
|
+
@driver.instance(:id => instance.id).keyname.must_equal 'test1'
|
68
|
+
@driver.instance(:id => instance.id).firewalls.must_include 'default'
|
69
|
+
@driver.instance(:id => instance.id).state.must_equal 'RUNNING'
|
70
|
+
@driver.instance(:id => instance.id).public_addresses.wont_be_empty
|
71
|
+
@driver.instance(:id => instance.id).actions.must_include :reboot
|
72
|
+
@driver.instance(:id => instance.id).actions.must_include :stop
|
73
|
+
@driver.destroy_instance(instance.id)
|
74
|
+
instance.wait_for!(@driver, record_retries('stopped')) { |i| i.is_stopped? }
|
75
|
+
end
|
76
|
+
|
77
|
+
it 'must allow to create multiple instances using the "instance_count" parameter' do
|
78
|
+
instances = @driver.create_instance('ami-aecd60c7',
|
79
|
+
:realm_id => 'us-east-1a',
|
80
|
+
:hwp_id => 't1.micro',
|
81
|
+
:instance_count => '2'
|
82
|
+
)
|
83
|
+
instances.wont_be_empty
|
84
|
+
instances.size.must_equal 2
|
85
|
+
instances.each { |i| i.must_be_kind_of Instance }
|
86
|
+
instances = instances.map { |instance| instance.wait_for!(@driver, record_retries("#{instance.id}-running")) { |i| i.is_running? } }
|
87
|
+
instances.each { |i| i.is_running?.must_equal true }
|
88
|
+
instances.each { |i| @driver.destroy_instance(i.id) }
|
89
|
+
instances = instances.map { |instance| instance.wait_for!(@driver, record_retries("#{instance.id}-stopped")) { |i| i.is_stopped? } }
|
90
|
+
instances.each { |i| i.is_stopped?.must_equal true }
|
91
|
+
end
|
92
|
+
|
93
|
+
it 'must allow to reboot instance in running state' do
|
94
|
+
instance = @driver.create_instance('ami-aecd60c7', :realm_id => 'us-east-1a', :hwp_id => 't1.micro')
|
95
|
+
instance = instance.wait_for!(@driver, record_retries) { |i| i.is_running? }
|
96
|
+
instance.must_be_kind_of Instance
|
97
|
+
instance.is_running?.must_equal true
|
98
|
+
@driver.reboot_instance(instance.id)
|
99
|
+
@driver.instance(:id => instance.id).state.must_equal 'RUNNING'
|
100
|
+
@driver.destroy_instance(instance.id)
|
101
|
+
instance.wait_for!(@driver, record_retries('stopped')) { |i| i.is_stopped? }
|
102
|
+
end
|
103
|
+
|
104
|
+
end
|
@@ -1,10 +1,12 @@
|
|
1
|
-
|
2
|
-
require 'tests/drivers/ec2/common'
|
1
|
+
require 'minitest/autorun'
|
3
2
|
|
4
|
-
|
3
|
+
require_relative File.join('..', '..', '..', 'lib', 'deltacloud', 'api.rb')
|
4
|
+
require_relative 'common.rb'
|
5
|
+
|
6
|
+
describe 'Ec2Driver Instances' do
|
5
7
|
|
6
8
|
before do
|
7
|
-
|
9
|
+
@driver = Deltacloud::new(:ec2, credentials)
|
8
10
|
VCR.insert_cassette __name__
|
9
11
|
end
|
10
12
|
|
@@ -12,170 +14,39 @@ describe 'Deltacloud API Keys' do
|
|
12
14
|
VCR.eject_cassette
|
13
15
|
end
|
14
16
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
(xml_response/'api/link[@rel=keys]').wont_be_empty
|
20
|
-
end
|
21
|
-
|
22
|
-
it 'must require authentication to access the "key" collection' do
|
23
|
-
get collection_url(:keys)
|
24
|
-
last_response.status.must_equal 401
|
25
|
-
end
|
26
|
-
|
27
|
-
it 'should respond with HTTP_OK when accessing the :keys collection with authentication' do
|
28
|
-
authenticate
|
29
|
-
get collection_url(:keys)
|
30
|
-
last_response.status.must_equal 200
|
31
|
-
end
|
32
|
-
|
33
|
-
it 'should support the JSON media type' do
|
34
|
-
authenticate
|
35
|
-
header 'Accept', 'application/json'
|
36
|
-
get collection_url(:keys)
|
37
|
-
last_response.status.must_equal 200
|
38
|
-
last_response.headers['Content-Type'].must_equal 'application/json'
|
39
|
-
end
|
40
|
-
|
41
|
-
it 'must include the ETag in HTTP headers' do
|
42
|
-
authenticate
|
43
|
-
get collection_url(:keys)
|
44
|
-
last_response.headers['ETag'].wont_be_nil
|
45
|
-
end
|
46
|
-
|
47
|
-
it 'must have the "keys" element on top level' do
|
48
|
-
authenticate
|
49
|
-
get collection_url(:keys)
|
50
|
-
xml_response.root.name.must_equal 'keys'
|
51
|
-
end
|
52
|
-
|
53
|
-
it 'must have some "key" elements inside "keys"' do
|
54
|
-
authenticate
|
55
|
-
get collection_url(:keys)
|
56
|
-
(xml_response/'keys/key').wont_be_empty
|
57
|
-
end
|
58
|
-
|
59
|
-
it 'must tell the kind of "key" elements inside "keys"' do
|
60
|
-
authenticate
|
61
|
-
get collection_url(:keys)
|
62
|
-
(xml_response/'keys/key').each do |k|
|
63
|
-
k[:type].must_match /(key|password)/
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
it 'must provide the :id attribute for each key in collection' do
|
68
|
-
authenticate
|
69
|
-
get collection_url(:keys)
|
70
|
-
(xml_response/'keys/key').each do |r|
|
71
|
-
r[:id].wont_be_nil
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
|
-
it 'must include the :href attribute for each "key" element in collection' do
|
76
|
-
authenticate
|
77
|
-
get collection_url(:keys)
|
78
|
-
(xml_response/'keys/key').each do |r|
|
79
|
-
r[:href].wont_be_nil
|
80
|
-
end
|
81
|
-
end
|
82
|
-
|
83
|
-
it 'must use the absolute URL in each :href attribute' do
|
84
|
-
authenticate
|
85
|
-
get collection_url(:keys)
|
86
|
-
(xml_response/'keys/key').each do |r|
|
87
|
-
r[:href].must_match /^http/
|
88
|
-
end
|
89
|
-
end
|
90
|
-
|
91
|
-
it 'must have the URL ending with the :id of the key' do
|
92
|
-
authenticate
|
93
|
-
get collection_url(:keys)
|
94
|
-
(xml_response/'keys/key').each do |r|
|
95
|
-
r[:href].must_match /#{r[:id]}$/
|
96
|
-
end
|
97
|
-
end
|
98
|
-
|
99
|
-
it 'must return the list of valid parameters for the :index action' do
|
100
|
-
authenticate
|
101
|
-
options collection_url(:keys) + '/index'
|
102
|
-
last_response.headers['Allow'].wont_be_nil
|
103
|
-
end
|
104
|
-
|
105
|
-
it 'must have the "name" element defined for each key in collection' do
|
106
|
-
authenticate
|
107
|
-
get collection_url(:keys)
|
108
|
-
(xml_response/'keys/key').each do |r|
|
109
|
-
(r/'name').wont_be_empty
|
110
|
-
end
|
111
|
-
end
|
112
|
-
|
113
|
-
|
114
|
-
it 'must return the full "key" when following the URL in key element' do
|
115
|
-
authenticate
|
116
|
-
get collection_url(:keys)
|
117
|
-
(xml_response/'keys/key').each do |r|
|
118
|
-
get collection_url(:keys) + '/' + r[:id]
|
119
|
-
last_response.status.must_equal 200
|
120
|
-
end
|
17
|
+
it 'must throw error when wrong credentials' do
|
18
|
+
Proc.new do
|
19
|
+
@driver.backend.images(OpenStruct.new(:user => 'unknown', :password => 'wrong'))
|
20
|
+
end.must_raise Deltacloud::ExceptionHandler::AuthenticationFailure, 'Authentication Failure'
|
121
21
|
end
|
122
22
|
|
123
|
-
it 'must
|
124
|
-
|
125
|
-
|
126
|
-
(xml_response/'keys/key').each do |r|
|
127
|
-
VCR.use_cassette "#{__name__}_key_#{r[:id]}" do
|
128
|
-
get collection_url(:keys) + '/' + r[:id]
|
129
|
-
end
|
130
|
-
(xml_response/'name').wont_be_empty
|
131
|
-
(xml_response/'name').first.text.must_equal((r/'name').first.text)
|
132
|
-
end
|
23
|
+
it 'must return list of keys' do
|
24
|
+
@driver.keys.wont_be_empty
|
25
|
+
@driver.keys.first.must_be_kind_of Key
|
133
26
|
end
|
134
27
|
|
135
|
-
it 'must
|
136
|
-
|
137
|
-
|
138
|
-
(
|
139
|
-
|
140
|
-
|
141
|
-
end
|
142
|
-
(xml_response/'state').wont_be_empty
|
143
|
-
(xml_response/'state').first.text.must_equal((r/'state').first.text)
|
144
|
-
end
|
28
|
+
it 'must allow to filter keys' do
|
29
|
+
@driver.keys(:id => 'test1').wont_be_empty
|
30
|
+
@driver.keys(:id => 'test1').must_be_kind_of Array
|
31
|
+
@driver.keys(:id => 'test1').size.must_equal 1
|
32
|
+
@driver.keys(:id => 'test1').first.id.must_equal 'test1'
|
33
|
+
@driver.keys(:id => 'unknown').must_be_empty
|
145
34
|
end
|
146
35
|
|
147
|
-
it '
|
148
|
-
|
149
|
-
|
150
|
-
(
|
151
|
-
|
152
|
-
get collection_url(:keys) + '/' + r[:id]
|
153
|
-
end
|
154
|
-
(xml_response/'actions/link').wont_be_empty
|
155
|
-
(xml_response/'actions/link').each do |l|
|
156
|
-
l[:href].wont_be_nil
|
157
|
-
l[:href].must_match /^http/
|
158
|
-
l[:method].wont_be_nil
|
159
|
-
l[:rel].wont_be_nil
|
160
|
-
end
|
161
|
-
end
|
36
|
+
it 'must allow to retrieve single key' do
|
37
|
+
@driver.key(:id => 'test1').wont_be_nil
|
38
|
+
@driver.key(:id => 'test1').must_be_kind_of Key
|
39
|
+
@driver.key(:id => 'test1').id.must_equal 'test1'
|
40
|
+
@driver.key(:id => 'unknown').must_be_nil
|
162
41
|
end
|
163
42
|
|
164
|
-
it '
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
VCR.use_cassette "#{__name__}_key_#{key_name}" do
|
172
|
-
get collection_url(:keys) + '/' + 'test_key_'+key_name
|
173
|
-
end
|
174
|
-
last_response.status.must_equal 200 # HTTP_OK
|
175
|
-
VCR.use_cassette "#{__name__}_delete_key_#{key_name}" do
|
176
|
-
delete collection_url(:keys) + '/' + 'test_key_'+key_name
|
177
|
-
end
|
178
|
-
last_response.status.must_equal 204 # HTTP_NO_CONTENT
|
43
|
+
it 'must allow to create a new key' do
|
44
|
+
key = @driver.create_key(:key_name => 'test-key-1')
|
45
|
+
key.wont_be_nil
|
46
|
+
key.must_be_kind_of Key
|
47
|
+
Proc.new { @driver.create_key(:key_name => 'test-key-1') }.must_raise Deltacloud::ExceptionHandler::ProviderError, 'KeyExist'
|
48
|
+
@driver.destroy_key :id => key.id
|
49
|
+
@driver.key(:id => key.id).must_be_nil
|
179
50
|
end
|
180
51
|
|
181
|
-
end
|
52
|
+
end
|
@@ -1,9 +1,12 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
require 'minitest/autorun'
|
2
|
+
|
3
|
+
require_relative File.join('..', '..', '..', 'lib', 'deltacloud', 'api.rb')
|
4
|
+
require_relative 'common.rb'
|
5
|
+
|
6
|
+
describe 'Ec2Driver Realms' do
|
3
7
|
|
4
|
-
describe 'Deltacloud API Realms' do
|
5
8
|
before do
|
6
|
-
|
9
|
+
@driver = Deltacloud::new(:ec2, credentials)
|
7
10
|
VCR.insert_cassette __name__
|
8
11
|
end
|
9
12
|
|
@@ -11,136 +14,31 @@ describe 'Deltacloud API Realms' do
|
|
11
14
|
VCR.eject_cassette
|
12
15
|
end
|
13
16
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
(xml_response/'api/link[@rel=realms]').wont_be_empty
|
19
|
-
end
|
20
|
-
|
21
|
-
it 'must require authentication to access the "realm" collection' do
|
22
|
-
get collection_url(:realms)
|
23
|
-
last_response.status.must_equal 401
|
24
|
-
end
|
25
|
-
|
26
|
-
it 'should respond with HTTP_OK when accessing the :realms collection with authentication' do
|
27
|
-
authenticate
|
28
|
-
get collection_url(:realms)
|
29
|
-
last_response.status.must_equal 200
|
30
|
-
end
|
31
|
-
|
32
|
-
it 'should support the JSON media type' do
|
33
|
-
authenticate
|
34
|
-
header 'Accept', 'application/json'
|
35
|
-
get collection_url(:realms)
|
36
|
-
last_response.status.must_equal 200
|
37
|
-
last_response.headers['Content-Type'].must_equal 'application/json'
|
38
|
-
end
|
39
|
-
|
40
|
-
it 'must include the ETag in HTTP headers' do
|
41
|
-
authenticate
|
42
|
-
get collection_url(:realms)
|
43
|
-
last_response.headers['ETag'].wont_be_nil
|
44
|
-
end
|
45
|
-
|
46
|
-
it 'must have the "realms" element on top level' do
|
47
|
-
authenticate
|
48
|
-
get collection_url(:realms)
|
49
|
-
xml_response.root.name.must_equal 'realms'
|
50
|
-
end
|
51
|
-
|
52
|
-
it 'must have some "realm" elements inside "realms"' do
|
53
|
-
authenticate
|
54
|
-
get collection_url(:realms)
|
55
|
-
(xml_response/'realms/realm').wont_be_empty
|
17
|
+
it 'must throw error when wrong credentials' do
|
18
|
+
Proc.new do
|
19
|
+
@driver.backend.realms(OpenStruct.new(:user => 'unknown', :password => 'wrong'))
|
20
|
+
end.must_raise Deltacloud::ExceptionHandler::AuthenticationFailure, 'Authentication Failure'
|
56
21
|
end
|
57
22
|
|
58
|
-
it 'must
|
59
|
-
|
60
|
-
|
61
|
-
(xml_response/'realms/realm').each do |r|
|
62
|
-
r[:id].wont_be_nil
|
63
|
-
end
|
23
|
+
it 'must return list of realms' do
|
24
|
+
@driver.realms.wont_be_empty
|
25
|
+
@driver.realms.first.must_be_kind_of Realm
|
64
26
|
end
|
65
27
|
|
66
|
-
it 'must
|
67
|
-
|
68
|
-
|
69
|
-
(
|
70
|
-
|
71
|
-
|
28
|
+
it 'must allow to filter realms' do
|
29
|
+
@driver.realms(:id => 'us-east-1a').wont_be_empty
|
30
|
+
@driver.realms(:id => 'us-east-1a').must_be_kind_of Array
|
31
|
+
@driver.realms(:id => 'us-east-1a').size.must_equal 1
|
32
|
+
@driver.realms(:id => 'us-east-1a').first.id.must_equal 'us-east-1a'
|
33
|
+
@driver.realms(:id => 'unknown').must_be_empty
|
72
34
|
end
|
73
35
|
|
74
|
-
it 'must
|
75
|
-
|
76
|
-
|
77
|
-
(
|
78
|
-
|
79
|
-
end
|
80
|
-
end
|
81
|
-
|
82
|
-
it 'must have the URL ending with the :id of the realm' do
|
83
|
-
authenticate
|
84
|
-
get collection_url(:realms)
|
85
|
-
(xml_response/'realms/realm').each do |r|
|
86
|
-
r[:href].must_match /#{r[:id]}$/
|
87
|
-
end
|
88
|
-
end
|
89
|
-
|
90
|
-
it 'must return the list of valid parameters for the :index action' do
|
91
|
-
authenticate
|
92
|
-
options collection_url(:realms) + '/index'
|
93
|
-
last_response.headers['Allow'].wont_be_nil
|
94
|
-
end
|
95
|
-
|
96
|
-
it 'must have the "name" element defined for each realm in collection' do
|
97
|
-
authenticate
|
98
|
-
get collection_url(:realms)
|
99
|
-
(xml_response/'realms/realm').each do |r|
|
100
|
-
(r/'name').wont_be_empty
|
101
|
-
end
|
102
|
-
end
|
103
|
-
|
104
|
-
it 'must have the "state" element defined for each realm in collection' do
|
105
|
-
authenticate
|
106
|
-
get collection_url(:realms)
|
107
|
-
(xml_response/'realms/realm').each do |r|
|
108
|
-
(r/'state').wont_be_empty
|
109
|
-
end
|
110
|
-
end
|
111
|
-
it 'must return the full "realm" when following the URL in realm element' do
|
112
|
-
authenticate
|
113
|
-
get collection_url(:realms)
|
114
|
-
(xml_response/'realms/realm').each do |r|
|
115
|
-
VCR.use_cassette "#{__name__}_realm_id" do
|
116
|
-
get collection_url(:realms) + '/' + r[:id]
|
117
|
-
end
|
118
|
-
last_response.status.must_equal 200
|
119
|
-
end
|
120
|
-
end
|
121
|
-
|
122
|
-
it 'must have the "name" element for the realm and it should match with the one in collection' do
|
123
|
-
authenticate
|
124
|
-
get collection_url(:realms)
|
125
|
-
(xml_response/'realms/realm').each do |r|
|
126
|
-
VCR.use_cassette "#{__name__}_realm_#{r[:id]}" do
|
127
|
-
get collection_url(:realms) + '/' + r[:id]
|
128
|
-
end
|
129
|
-
(xml_response/'name').wont_be_empty
|
130
|
-
(xml_response/'name').first.text.must_equal((r/'name').first.text)
|
131
|
-
end
|
132
|
-
end
|
133
|
-
|
134
|
-
it 'must have the "state" element for the realm and it should match with the one in collection' do
|
135
|
-
authenticate
|
136
|
-
get collection_url(:realms)
|
137
|
-
(xml_response/'realms/realm').each do |r|
|
138
|
-
VCR.use_cassette "#{__name__}_realm_r[:id]" do
|
139
|
-
get collection_url(:realms) + '/' + r[:id]
|
140
|
-
end
|
141
|
-
(xml_response/'state').wont_be_empty
|
142
|
-
(xml_response/'state').first.text.must_equal((r/'state').first.text)
|
143
|
-
end
|
36
|
+
it 'must allow to retrieve single realm' do
|
37
|
+
@driver.realm(:id => 'us-east-1a').wont_be_nil
|
38
|
+
@driver.realm(:id => 'us-east-1a').must_be_kind_of Realm
|
39
|
+
@driver.realm(:id => 'us-east-1b').id.must_equal 'us-east-1b'
|
40
|
+
@driver.realm(:id => 'unknown').must_be_nil
|
144
41
|
end
|
145
42
|
|
146
43
|
end
|
44
|
+
|