deltacloud-client 1.0.5 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/tests/buckets_test.rb +141 -0
- data/tests/client_test.rb +59 -0
- data/tests/content_negotiation_test.rb +127 -0
- data/tests/errors_test.rb +57 -0
- data/tests/hardware_profiles_test.rb +75 -0
- data/tests/images_test.rb +102 -0
- data/tests/instance_states_test.rb +66 -0
- data/tests/instances_test.rb +203 -0
- data/tests/keys_test.rb +81 -0
- data/tests/realms_test.rb +64 -0
- data/tests/storage_snapshot_test.rb +76 -0
- data/tests/storage_volume_test.rb +86 -0
- data/tests/test_helper.rb +16 -0
- metadata +29 -3
@@ -0,0 +1,141 @@
|
|
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\.8/
|
18
|
+
|
19
|
+
require_relative './test_helper.rb'
|
20
|
+
|
21
|
+
describe "Buckets" do
|
22
|
+
|
23
|
+
it "should allow retrieval of all buckets" do
|
24
|
+
DeltaCloud.new( API_NAME, API_PASSWORD, API_URL ) do |client|
|
25
|
+
buckets = client.buckets
|
26
|
+
buckets.wont_be_empty
|
27
|
+
buckets.each do |bucket|
|
28
|
+
bucket.uri.wont_be_nil
|
29
|
+
bucket.uri.must_be_kind_of String
|
30
|
+
bucket.name.wont_be_nil
|
31
|
+
bucket.name.must_be_kind_of String
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should allow retrieval of a named bucket" do
|
37
|
+
DeltaCloud.new( API_NAME, API_PASSWORD, API_URL ) do |client|
|
38
|
+
bucket = client.bucket("bucket1")
|
39
|
+
bucket.wont_be_nil
|
40
|
+
bucket.uri.must_equal API_URL + "/buckets/bucket1"
|
41
|
+
bucket.size.must_equal 3.0
|
42
|
+
bucket.name.wont_be_nil
|
43
|
+
bucket.name.must_be_kind_of String
|
44
|
+
blob_list = bucket.blob_list.split(", ")
|
45
|
+
blob_list.size.must_equal bucket.size.to_i
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
50
|
+
|
51
|
+
describe "Operations on buckets" do
|
52
|
+
|
53
|
+
it "should allow creation of a new bucket" do
|
54
|
+
DeltaCloud.new( API_NAME, API_PASSWORD, API_URL ) do |client|
|
55
|
+
new_bucket = client.create_bucket({'id' => "my_new_bucket"})
|
56
|
+
new_bucket.wont_be_nil
|
57
|
+
new_bucket.uri.must_equal API_URL + "/buckets/my_new_bucket"
|
58
|
+
new_bucket.name.wont_be_nil
|
59
|
+
new_bucket.name.must_be_kind_of String
|
60
|
+
new_bucket.name.must_equal "my_new_bucket"
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
it "should allow deletion of an existing bucket" do
|
65
|
+
DeltaCloud.new( API_NAME, API_PASSWORD, API_URL ) do |client|
|
66
|
+
new_bucket = client.bucket("my_new_bucket")
|
67
|
+
new_bucket.wont_be_nil
|
68
|
+
new_bucket.name.must_equal "my_new_bucket"
|
69
|
+
client.destroy_bucket('id' => "my_new_bucket").must_be_nil
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
it "should throw error if you delete a non existing bucket" do
|
74
|
+
DeltaCloud.new( API_NAME, API_PASSWORD, API_URL ) do |client|
|
75
|
+
lambda {
|
76
|
+
client.destroy_bucket({'id' => "i_dont_exist"}).must_be_nil
|
77
|
+
}.must_raise DeltaCloud::HTTPError::DeltacloudError
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
end
|
82
|
+
|
83
|
+
describe "Blobs" do
|
84
|
+
|
85
|
+
it "should allow retrieval of a bucket's blobs" do
|
86
|
+
DeltaCloud.new( API_NAME, API_PASSWORD, API_URL ) do |client|
|
87
|
+
bucket = client.bucket("bucket1")
|
88
|
+
bucket.wont_be_nil
|
89
|
+
blob_list = bucket.blob_list.split(", ")
|
90
|
+
blob_list.size.must_equal bucket.size.to_i
|
91
|
+
blob_list.each do |b_id|
|
92
|
+
blob = client.blob("bucket" => bucket.name, :id => b_id)
|
93
|
+
blob.bucket.wont_be_nil
|
94
|
+
blob.bucket.must_be_kind_of String
|
95
|
+
blob.bucket.must_equal bucket.name
|
96
|
+
blob.content_length.wont_be_nil
|
97
|
+
blob.content_length.must_be_kind_of Float
|
98
|
+
blob.content_length.must_be :'>=', 0
|
99
|
+
blob_data = client.blob_data("bucket" => bucket.name, :id => b_id)
|
100
|
+
blob_data.size.to_f.must_equal blob.content_length
|
101
|
+
blob.last_modified.wont_be_nil
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
end
|
107
|
+
|
108
|
+
describe "Operations on blobs" do
|
109
|
+
|
110
|
+
it "should successfully create a new blob" do
|
111
|
+
DeltaCloud.new( API_NAME, API_PASSWORD, API_URL ) do |client|
|
112
|
+
blob_data = File.new("./blob_data_file", "w+")
|
113
|
+
blob_data.write("this is some blob data \n")
|
114
|
+
blob_data.rewind
|
115
|
+
some_new_blob = client.create_blob(
|
116
|
+
:id => "some_new_blob",
|
117
|
+
'bucket' => "bucket1",
|
118
|
+
'file_path' => blob_data.path
|
119
|
+
)
|
120
|
+
some_new_blob.wont_be_nil
|
121
|
+
some_new_blob.content_length.wont_be_nil
|
122
|
+
some_new_blob.content_length.must_equal 24.0
|
123
|
+
File.delete(blob_data.path)
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
it "should allow deletion of an existing blob" do
|
128
|
+
DeltaCloud.new( API_NAME, API_PASSWORD, API_URL ) do |client|
|
129
|
+
client.destroy_blob(:id=>"some_new_blob", 'bucket'=>"bucket1").must_be_nil
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
it "should throw error if you delete a non existing blob" do
|
134
|
+
DeltaCloud.new( API_NAME, API_PASSWORD, API_URL ) do |client|
|
135
|
+
lambda {
|
136
|
+
client.destroy_blob(:id=>"no_such_blob", 'bucket'=>"bucket1").must_be_nil
|
137
|
+
}.must_raise DeltaCloud::HTTPError::DeltacloudError
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
end
|
@@ -0,0 +1,59 @@
|
|
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\.8/
|
18
|
+
|
19
|
+
require_relative './test_helper.rb'
|
20
|
+
|
21
|
+
describe "initializing the client" do
|
22
|
+
|
23
|
+
it "should parse valid API URIs" do
|
24
|
+
client = DeltaCloud.new( API_NAME, API_PASSWORD, API_URL )
|
25
|
+
client.api_host.must_equal API_HOST
|
26
|
+
client.api_port.must_equal API_PORT.to_i
|
27
|
+
client.api_path.must_equal API_PATH
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should discover entry points upon connection" do
|
31
|
+
DeltaCloud.new( "name", "password", API_URL ) do |client|
|
32
|
+
client.entry_points[:hardware_profiles].must_equal "#{API_URL}/hardware_profiles"
|
33
|
+
client.entry_points[:images].must_equal "#{API_URL}/images"
|
34
|
+
client.entry_points[:instances].must_equal "#{API_URL}/instances"
|
35
|
+
client.entry_points[:storage_volumes].must_equal "#{API_URL}/storage_volumes"
|
36
|
+
client.entry_points[:storage_snapshots].must_equal "#{API_URL}/storage_snapshots"
|
37
|
+
client.entry_points[:buckets].must_equal "#{API_URL}/buckets"
|
38
|
+
client.entry_points[:keys].must_equal "#{API_URL}/keys"
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
it "should provide the current driver name via client" do
|
43
|
+
DeltaCloud.new( "name", "password", API_URL ) do |client|
|
44
|
+
client.driver_name.must_equal 'mock'
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
it "should provide the current driver name without client" do
|
49
|
+
DeltaCloud.driver_name( API_URL ).must_equal 'mock'
|
50
|
+
end
|
51
|
+
|
52
|
+
describe "without a block" do
|
53
|
+
it "should connect without a block" do
|
54
|
+
client = DeltaCloud.new( API_NAME, API_PASSWORD, API_URL )
|
55
|
+
client.images.wont_be_nil
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
@@ -0,0 +1,127 @@
|
|
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\.8/
|
18
|
+
|
19
|
+
require_relative './test_helper.rb'
|
20
|
+
|
21
|
+
def client; RestClient::Resource.new(API_URL); end
|
22
|
+
|
23
|
+
def headers(header)
|
24
|
+
encoded_credentials = ["#{API_NAME}:#{API_PASSWORD}"].pack("m0").gsub(/\n/,'')
|
25
|
+
{ :authorization => "Basic " + encoded_credentials }.merge(header)
|
26
|
+
end
|
27
|
+
|
28
|
+
describe "return JSON" do
|
29
|
+
|
30
|
+
it 'should return JSON when using application/json, */*' do
|
31
|
+
header_hash = {
|
32
|
+
# FIXME: There is a bug in rack-accept that cause to respond with HTML
|
33
|
+
# to the configuration below.
|
34
|
+
#
|
35
|
+
# 'Accept' => "application/json, */*"
|
36
|
+
'Accept' => "application/json"
|
37
|
+
}
|
38
|
+
client.get(header_hash) do |response, request, &block|
|
39
|
+
response.code.must_equal 200
|
40
|
+
response.headers[:content_type].must_match /^application\/json/
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'should return JSON when using just application/json' do
|
45
|
+
header_hash = {
|
46
|
+
'Accept' => "application/json"
|
47
|
+
}
|
48
|
+
client.get(header_hash) do |response, request, &block|
|
49
|
+
response.code.must_equal 200
|
50
|
+
response.headers[:content_type].must_match /^application\/json/
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
|
56
|
+
describe "return HTML in different browsers" do
|
57
|
+
|
58
|
+
it "wants XML using format parameter" do
|
59
|
+
client.get(:params => { 'format' => 'xml' }, 'Accept' => 'application/xhtml+xml') do |response, request, &block|
|
60
|
+
response.code.must_equal 200
|
61
|
+
response.headers[:content_type].must_match /^application\/xml/
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
it "raise 406 error on wrong accept" do
|
66
|
+
client['hardware_profiles'].get('Accept' => 'image/png;q=1') do |response, request, &block|
|
67
|
+
response.code.must_equal 406
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
it "wants HTML using format parameter and accept set to XML" do
|
72
|
+
client.get(:params => { 'format' => 'html'}, 'Accept' => 'application/xml') do |response, request, &block|
|
73
|
+
response.code.must_equal 200
|
74
|
+
response.headers[:content_type].must_match /^text\/html/
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
it "doesn't have accept header" do
|
79
|
+
client.get('Accept' => '') do |response, request, &block|
|
80
|
+
response.code.must_equal 200
|
81
|
+
response.headers[:content_type].must_match /^application\/xml/
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
it "can handle unknown formats" do
|
86
|
+
client.get('Accept' => 'format/unknown') do |response, request, &block|
|
87
|
+
response.code.must_equal 406
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
it "wants explicitly XML" do
|
92
|
+
client.get('Accept' => 'application/xml') do |response, request, &block|
|
93
|
+
response.code.must_equal 200
|
94
|
+
response.headers[:content_type].must_match /^application\/xml/
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
it "Internet Explorer" do
|
99
|
+
header_hash = {
|
100
|
+
'Accept' => "image/gif, image/jpeg, image/pjpeg, image/pjpeg, application/x-shockwave-flash, application/x-ms-application, application/x-ms-xbap, application/vnd.ms-xpsdocument, application/xaml+xml, */*",
|
101
|
+
'User-agent' => "Mozilla/5.0 (Windows; U; MSIE 9.0; Windows NT 9.0; en-US)"
|
102
|
+
}
|
103
|
+
client.get(header_hash) do |response, request, &block|
|
104
|
+
response.code.must_equal 200
|
105
|
+
response.headers[:content_type].must_match /^text\/html/
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
it "Mozilla Firefox" do
|
110
|
+
client.get('Accept' => "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8") do |response, request, &block|
|
111
|
+
response.code.must_equal 200
|
112
|
+
response.headers[:content_type].must_match /^text\/html/
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
it "Opera" do
|
117
|
+
header_hash = {
|
118
|
+
'Accept' => "text/html, application/xml;q=0.9, application/xhtml+xml, image/png, image/jpeg, image/gif, image/x-xbitmap, */*;q=0.1",
|
119
|
+
'User-agent' => "Opera/9.80 (X11; Linux i686; U; ru) Presto/2.8.131 Version/11.11"
|
120
|
+
}
|
121
|
+
client.get(header_hash) do |response, request, &block|
|
122
|
+
response.code.must_equal 200
|
123
|
+
response.headers[:content_type].must_match /^text\/html/
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
end
|
@@ -0,0 +1,57 @@
|
|
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\.8/
|
18
|
+
|
19
|
+
require_relative './test_helper.rb'
|
20
|
+
|
21
|
+
describe "server error handler" do
|
22
|
+
|
23
|
+
it 'should capture HTTP 500 error as DeltacloudError' do
|
24
|
+
DeltaCloud.new( API_NAME, API_PASSWORD, API_URL ) do |client|
|
25
|
+
lambda { client.realm('500') }.must_raise DeltaCloud::HTTPError::DeltacloudError
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'should capture HTTP 502 error as ProviderError' do
|
30
|
+
DeltaCloud.new( API_NAME, API_PASSWORD, API_URL ) do |client|
|
31
|
+
lambda { client.realm('502') }.must_raise DeltaCloud::HTTPError::ProviderError
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'should capture HTTP 501 error as NotImplemented' do
|
36
|
+
DeltaCloud.new( API_NAME, API_PASSWORD, API_URL ) do |client|
|
37
|
+
lambda { client.realm('501') }.must_raise DeltaCloud::HTTPError::NotImplemented
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'should capture HTTP 504 error as ProviderTimeout' do
|
42
|
+
DeltaCloud.new( API_NAME, API_PASSWORD, API_URL ) do |client|
|
43
|
+
lambda { client.realm('504') }.must_raise DeltaCloud::HTTPError::ProviderTimeout
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
|
49
|
+
describe "client error handler" do
|
50
|
+
|
51
|
+
it 'should capture HTTP 404 error as NotFound' do
|
52
|
+
DeltaCloud.new( API_NAME, API_PASSWORD, API_URL ) do |client|
|
53
|
+
lambda { client.realm('non-existing-realm') }.must_raise DeltaCloud::HTTPError::NotFound
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
@@ -0,0 +1,75 @@
|
|
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\.8/
|
18
|
+
|
19
|
+
require_relative './test_helper.rb'
|
20
|
+
|
21
|
+
def prop_check(prop, value_class)
|
22
|
+
if prop.present?
|
23
|
+
prop.value.wont_be_nil
|
24
|
+
prop.value.must_be_kind_of value_class
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
describe "Hardware Profiles" do
|
29
|
+
|
30
|
+
it "should allow retrieval of all hardware profiles" do
|
31
|
+
DeltaCloud.new( API_NAME, API_PASSWORD, API_URL ) do |client|
|
32
|
+
hardware_profiles = client.hardware_profiles
|
33
|
+
hardware_profiles.wont_be_empty
|
34
|
+
hardware_profiles.each do |hwp|
|
35
|
+
hwp.uri.wont_be_nil
|
36
|
+
hwp.uri.must_be_kind_of String
|
37
|
+
prop_check(hwp.architecture, String) unless hwp.name.eql?("opaque")
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
it "should allow filtering of hardware_profiles by architecture" do
|
43
|
+
DeltaCloud.new( API_NAME, API_PASSWORD, API_URL ) do |client|
|
44
|
+
hardware_profiles = client.hardware_profiles( :architecture=>'i386' )
|
45
|
+
hardware_profiles.wont_be_empty
|
46
|
+
hardware_profiles.size.must_equal 1
|
47
|
+
hardware_profiles.first.architecture.value.must_equal 'i386'
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
it "should allow fetching a hardware_profile by id" do
|
52
|
+
DeltaCloud.new( API_NAME, API_PASSWORD, API_URL ) do |client|
|
53
|
+
hwp = client.hardware_profile( 'm1-small' )
|
54
|
+
hwp.wont_be_nil
|
55
|
+
hwp.id.must_equal 'm1-small'
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
it "should allow fetching different hardware_profiles" do
|
60
|
+
client = DeltaCloud.new( API_NAME, API_PASSWORD, API_URL )
|
61
|
+
hwp1 = client.hardware_profile( 'm1-small' )
|
62
|
+
hwp2 = client.hardware_profile( 'm1-large' )
|
63
|
+
hwp1.storage.value.wont_equal hwp2.storage.value
|
64
|
+
hwp1.memory.value.wont_equal hwp2.memory.value
|
65
|
+
end
|
66
|
+
|
67
|
+
it "should allow fetching a hardware_profile by URI" do
|
68
|
+
DeltaCloud.new( API_NAME, API_PASSWORD, API_URL ) do |client|
|
69
|
+
hwp = client.fetch_hardware_profile( API_URL + '/hardware_profiles/m1-small' )
|
70
|
+
hwp.wont_be_nil
|
71
|
+
hwp.id.must_equal 'm1-small'
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
end
|
@@ -0,0 +1,102 @@
|
|
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\.8/
|
18
|
+
|
19
|
+
require_relative './test_helper.rb'
|
20
|
+
|
21
|
+
describe "Images" do
|
22
|
+
|
23
|
+
it "should allow retrieval of all images" do
|
24
|
+
DeltaCloud.new( API_NAME, API_PASSWORD, API_URL ) do |client|
|
25
|
+
images = client.images
|
26
|
+
images.wont_be_empty
|
27
|
+
images.size.must_equal 3
|
28
|
+
images.each do |image|
|
29
|
+
image.uri.wont_be_nil
|
30
|
+
image.uri.must_be_kind_of String
|
31
|
+
image.description.wont_be_nil
|
32
|
+
image.description.must_be_kind_of String
|
33
|
+
image.architecture.wont_be_nil
|
34
|
+
image.architecture.must_be_kind_of String
|
35
|
+
image.owner_id.wont_be_nil
|
36
|
+
image.owner_id.must_be_kind_of String
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should allow retrieval of my own images" do
|
42
|
+
DeltaCloud.new( API_NAME, API_PASSWORD, API_URL ) do |client|
|
43
|
+
images = client.images( :owner_id=>:self )
|
44
|
+
images.wont_be_empty
|
45
|
+
images.size.must_equal 1
|
46
|
+
images.each do |image|
|
47
|
+
image.uri.wont_be_nil
|
48
|
+
image.uri.must_be_kind_of String
|
49
|
+
image.description.wont_be_nil
|
50
|
+
image.description.must_be_kind_of String
|
51
|
+
image.architecture.wont_be_nil
|
52
|
+
image.architecture.must_be_kind_of String
|
53
|
+
image.owner_id.wont_be_nil
|
54
|
+
image.owner_id.must_be_kind_of String
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
it "should allow retrieval of a single image by ID" do
|
60
|
+
DeltaCloud.new( API_NAME, API_PASSWORD, API_URL ) do |client|
|
61
|
+
image = client.image( 'img1' )
|
62
|
+
image.wont_be_nil
|
63
|
+
image.uri.must_equal API_URL + '/images/img1'
|
64
|
+
image.id.must_equal 'img1'
|
65
|
+
image.architecture.must_equal 'x86_64'
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
it "should allow retrieval of a single image by URI" do
|
70
|
+
DeltaCloud.new( API_NAME, API_PASSWORD, API_URL ) do |client|
|
71
|
+
image = client.fetch_image( API_URL + '/images/img1' )
|
72
|
+
image.wont_be_nil
|
73
|
+
image.uri.must_equal API_URL + '/images/img1'
|
74
|
+
image.id.must_equal 'img1'
|
75
|
+
image.architecture.must_equal 'x86_64'
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
describe "filtering by architecture" do
|
80
|
+
it "return matching images" do
|
81
|
+
DeltaCloud.new( API_NAME, API_PASSWORD, API_URL ) do |client|
|
82
|
+
images = client.images( :architecture=>'x86_64' )
|
83
|
+
images.wont_be_empty
|
84
|
+
images.each do |image|
|
85
|
+
image.architecture.must_equal 'x86_64'
|
86
|
+
end
|
87
|
+
images = client.images( :architecture=>'i386' )
|
88
|
+
images.wont_be_empty
|
89
|
+
images.each do |image|
|
90
|
+
image.architecture.must_equal 'i386'
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
it "should return an empty array for no matches" do
|
96
|
+
DeltaCloud.new( API_NAME, API_PASSWORD, API_URL ) do |client|
|
97
|
+
images = client.images( :architecture=>'8088' )
|
98
|
+
images.must_be_empty
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
@@ -0,0 +1,66 @@
|
|
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\.8/
|
18
|
+
|
19
|
+
require_relative './test_helper.rb'
|
20
|
+
|
21
|
+
describe "Instance States" do
|
22
|
+
|
23
|
+
it "should allow retrieval of instance-state information" do
|
24
|
+
DeltaCloud.new( API_NAME, API_PASSWORD, API_URL ) do |client|
|
25
|
+
instance_states = client.instance_states
|
26
|
+
instance_states.wont_be_nil
|
27
|
+
instance_states.wont_be_empty
|
28
|
+
|
29
|
+
instance_states[0].name.must_equal 'start'
|
30
|
+
instance_states[0].transitions.size.must_equal 1
|
31
|
+
instance_states[0].transitions[0].wont_equal :auto
|
32
|
+
|
33
|
+
instance_states[1].name.must_equal 'pending'
|
34
|
+
instance_states[1].transitions.size.must_equal 1
|
35
|
+
instance_states[1].transitions[0].wont_equal :auto
|
36
|
+
|
37
|
+
instance_states[2].name.must_equal 'running'
|
38
|
+
instance_states[2].transitions.size.must_equal 2
|
39
|
+
includes_transition( instance_states[2].transitions, :reboot, :running ).must_equal true
|
40
|
+
includes_transition( instance_states[2].transitions, :stop, :stopped ).must_equal true
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
it "should allow retrieval of a single instance-state blob" do
|
45
|
+
DeltaCloud.new( API_NAME, API_PASSWORD, API_URL ) do |client|
|
46
|
+
instance_state = client.instance_state( :pending )
|
47
|
+
instance_state.wont_be_nil
|
48
|
+
instance_state.name.must_equal 'pending'
|
49
|
+
instance_state.transitions.size.must_equal 1
|
50
|
+
instance_state.transitions[0].wont_equal :auto
|
51
|
+
|
52
|
+
instance_state = client.instance_state( :running )
|
53
|
+
instance_state.name.must_equal 'running'
|
54
|
+
instance_state.transitions.size.must_equal 2
|
55
|
+
includes_transition( instance_state.transitions, :reboot, :running ).must_equal true
|
56
|
+
includes_transition( instance_state.transitions, :stop, :stopped ).must_equal true
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def includes_transition( transitions, action, to )
|
61
|
+
found = transitions.find{|e| e.action.to_s == action.to_s && e.to.to_s == to.to_s }
|
62
|
+
! found.nil?
|
63
|
+
end
|
64
|
+
|
65
|
+
|
66
|
+
end
|
@@ -0,0 +1,203 @@
|
|
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\.8/
|
18
|
+
|
19
|
+
require_relative './test_helper.rb'
|
20
|
+
|
21
|
+
describe "Instances" do
|
22
|
+
|
23
|
+
it "should allow retrieval of all instances" do
|
24
|
+
DeltaCloud.new( API_NAME, API_PASSWORD, API_URL ) do |client|
|
25
|
+
instances = client.instances
|
26
|
+
instances.wont_be_empty
|
27
|
+
instances.each do |instance|
|
28
|
+
instance.uri.wont_be_nil
|
29
|
+
instance.uri.must_be_kind_of String
|
30
|
+
instance.owner_id.wont_be_nil
|
31
|
+
instance.owner_id.must_be_kind_of String
|
32
|
+
instance.image.wont_be_nil
|
33
|
+
instance.image.to_s.must_match /DeltaCloud::API::.*::Image/
|
34
|
+
instance.hardware_profile.wont_be_nil
|
35
|
+
instance.hardware_profile.must_be_kind_of DeltaCloud::API::Base::HardwareProfile
|
36
|
+
instance.state.wont_be_nil
|
37
|
+
instance.state.must_be_kind_of String
|
38
|
+
instance.public_addresses.wont_be_nil
|
39
|
+
instance.public_addresses.wont_be_empty
|
40
|
+
instance.public_addresses.must_be_kind_of Array
|
41
|
+
instance.private_addresses.wont_be_nil
|
42
|
+
instance.private_addresses.wont_be_empty
|
43
|
+
instance.private_addresses.must_be_kind_of Array
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
it "should allow navigation from instance to image" do
|
49
|
+
DeltaCloud.new( API_NAME, API_PASSWORD, API_URL ) do |client|
|
50
|
+
instances = client.instances
|
51
|
+
instances.wont_be_empty
|
52
|
+
instance = instances.first
|
53
|
+
instance.image.wont_be_nil
|
54
|
+
instance.image.description.wont_be_nil
|
55
|
+
instance.image.description.must_be_kind_of String
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
it "should allow retrieval of a single instance" do
|
60
|
+
DeltaCloud.new( API_NAME, API_PASSWORD, API_URL ) do |client|
|
61
|
+
instance = client.instance( "inst0" )
|
62
|
+
instance.wont_be_nil
|
63
|
+
instance.name.wont_be_nil
|
64
|
+
instance.name.must_equal 'Mock Instance With Profile Change'
|
65
|
+
instance.uri.wont_be_nil
|
66
|
+
instance.uri.must_be_kind_of String
|
67
|
+
instance.owner_id.must_equal "mockuser"
|
68
|
+
instance.public_addresses.first.class.must_equal Hash
|
69
|
+
instance.public_addresses.first[:type].must_equal 'hostname'
|
70
|
+
instance.public_addresses.first[:address].must_equal 'img1.inst0.public.com'
|
71
|
+
instance.image.wont_be_nil
|
72
|
+
instance.image.uri.must_equal API_URL + "/images/img1"
|
73
|
+
instance.hardware_profile.wont_be_nil
|
74
|
+
instance.hardware_profile.wont_be_nil
|
75
|
+
instance.hardware_profile.uri.must_equal API_URL + "/hardware_profiles/m1-large"
|
76
|
+
instance.hardware_profile.memory.value.must_equal '10240'
|
77
|
+
instance.hardware_profile.storage.value.must_equal '850'
|
78
|
+
instance.state.must_equal "RUNNING"
|
79
|
+
instance.actions.wont_be_nil
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
it "should allow creation of new instances with reasonable defaults" do
|
84
|
+
DeltaCloud.new( API_NAME, API_PASSWORD, API_URL ) do |client|
|
85
|
+
instance = client.create_instance( 'img1', :name=>'TestInstance', :hardware_profile => 'm1-large' )
|
86
|
+
instance.wont_be_nil
|
87
|
+
instance.uri.must_match %r{#{API_URL}/instances/inst[0-9]+}
|
88
|
+
instance.id.must_match /inst[0-9]+/
|
89
|
+
instance.name.must_equal 'TestInstance'
|
90
|
+
instance.image.id.must_equal 'img1'
|
91
|
+
instance.hardware_profile.id.must_equal 'm1-large'
|
92
|
+
instance.realm.id.must_equal 'us'
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
it "should allow creation of new instances with specific realm" do
|
97
|
+
DeltaCloud.new( API_NAME, API_PASSWORD, API_URL ) do |client|
|
98
|
+
instance = client.create_instance( 'img1', :realm=>'eu', :hardware_profile => 'm1-large' )
|
99
|
+
instance.wont_be_nil
|
100
|
+
instance.uri.must_match %r{#{API_URL}/instances/inst[0-9]+}
|
101
|
+
instance.id.must_match /inst[0-9]+/
|
102
|
+
instance.image.id.must_equal 'img1'
|
103
|
+
instance.hardware_profile.id.must_equal 'm1-large'
|
104
|
+
instance.realm.id.must_equal 'eu'
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
it "should allow creation of new instances with specific hardware profile" do
|
109
|
+
DeltaCloud.new( API_NAME, API_PASSWORD, API_URL ) do |client|
|
110
|
+
instance = client.create_instance( 'img1',
|
111
|
+
:hardware_profile=>'m1-xlarge' )
|
112
|
+
instance.wont_be_nil
|
113
|
+
instance.uri.must_match %r{#{API_URL}/instances/inst[0-9]+}
|
114
|
+
instance.id.must_match /inst[0-9]+/
|
115
|
+
instance.image.id.must_equal 'img1'
|
116
|
+
instance.hardware_profile.id.must_equal 'm1-xlarge'
|
117
|
+
instance.realm.id.must_equal 'us'
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
it "should allow creation of new instances with specific hardware profile overriding memory" do
|
122
|
+
DeltaCloud.new( API_NAME, API_PASSWORD, API_URL ) do |client|
|
123
|
+
hwp = { :id => 'm1-xlarge', :memory => 32768 }
|
124
|
+
instance = client.create_instance( 'img1', :hardware_profile=> hwp )
|
125
|
+
instance.wont_be_nil
|
126
|
+
instance.uri.must_match %r{#{API_URL}/instances/inst[0-9]+}
|
127
|
+
instance.id.must_match /inst[0-9]+/
|
128
|
+
instance.image.id.must_equal 'img1'
|
129
|
+
instance.hardware_profile.id.must_equal 'm1-xlarge'
|
130
|
+
instance.hardware_profile.memory.value.must_equal'12288'
|
131
|
+
instance.realm.id.must_equal 'us'
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
it "should allow creation of new instances with specific realm and hardware profile" do
|
136
|
+
DeltaCloud.new( API_NAME, API_PASSWORD, API_URL ) do |client|
|
137
|
+
instance = client.create_instance( 'img1', :realm=>'eu',
|
138
|
+
:hardware_profile=>'m1-xlarge' )
|
139
|
+
instance.wont_be_nil
|
140
|
+
instance.uri.must_match %r{#{API_URL}/instances/inst[0-9]+}
|
141
|
+
instance.id.must_match /inst[0-9]+/
|
142
|
+
instance.image.id.must_equal 'img1'
|
143
|
+
instance.hardware_profile.id.must_equal 'm1-xlarge'
|
144
|
+
instance.realm.id.must_equal 'eu'
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
it "should allow fetching of instances by id" do
|
149
|
+
DeltaCloud.new( API_NAME, API_PASSWORD, API_URL ) do |client|
|
150
|
+
instance = client.instance( 'inst1' )
|
151
|
+
instance.wont_be_nil
|
152
|
+
instance.uri.wont_be_nil
|
153
|
+
instance.uri.must_be_kind_of String
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
it "should allow fetching of instances by URI" do
|
158
|
+
DeltaCloud.new( API_NAME, API_PASSWORD, API_URL ) do |client|
|
159
|
+
instance = client.fetch_instance( API_URL + '/instances/inst1' )
|
160
|
+
instance.wont_be_nil
|
161
|
+
instance.uri.must_equal API_URL + '/instances/inst1'
|
162
|
+
instance.id.must_equal 'inst1'
|
163
|
+
end
|
164
|
+
end
|
165
|
+
|
166
|
+
describe "performing actions on instances" do
|
167
|
+
it "should allow actions that are valid" do
|
168
|
+
DeltaCloud.new( API_NAME, API_PASSWORD, API_URL ) do |client|
|
169
|
+
instance = client.instance( 'inst1' )
|
170
|
+
instance.wont_be_nil
|
171
|
+
instance.state.must_equal "RUNNING"
|
172
|
+
instance.uri.must_equal API_URL + '/instances/inst1'
|
173
|
+
instance.id.must_equal 'inst1'
|
174
|
+
instance.stop!
|
175
|
+
instance.state.must_equal "STOPPED"
|
176
|
+
instance.start!
|
177
|
+
instance.state.must_equal "RUNNING"
|
178
|
+
end
|
179
|
+
end
|
180
|
+
|
181
|
+
it "should not allow actions that are invalid" do
|
182
|
+
DeltaCloud.new( API_NAME, API_PASSWORD, API_URL ) do |client|
|
183
|
+
instance = client.instance( 'inst1' )
|
184
|
+
instance.wont_be_nil
|
185
|
+
unless instance.state.eql?("RUNNING")
|
186
|
+
instance.start!
|
187
|
+
end
|
188
|
+
instance.state.must_equal "RUNNING"
|
189
|
+
lambda{instance.start!}.must_raise NoMethodError
|
190
|
+
end
|
191
|
+
end
|
192
|
+
|
193
|
+
it "should not throw exception when destroying an instance" do
|
194
|
+
DeltaCloud.new( API_NAME, API_PASSWORD, API_URL ) do |client|
|
195
|
+
instance = client.create_instance( 'img1',
|
196
|
+
:name=>'TestDestroyInstance',
|
197
|
+
:hardware_profile => 'm1-xlarge' )
|
198
|
+
instance.stop!
|
199
|
+
instance.destroy!.must_be_nil
|
200
|
+
end
|
201
|
+
end
|
202
|
+
end
|
203
|
+
end
|
data/tests/keys_test.rb
ADDED
@@ -0,0 +1,81 @@
|
|
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\.8/
|
18
|
+
|
19
|
+
require_relative './test_helper.rb'
|
20
|
+
|
21
|
+
def check_key(the_key, key_name = "")
|
22
|
+
the_key.wont_be_nil
|
23
|
+
the_key.id.must_be_kind_of String
|
24
|
+
the_key.id.must_equal key_name
|
25
|
+
the_key.actions.wont_be_nil
|
26
|
+
the_key.actions.size.must_equal 1
|
27
|
+
the_key.actions.first[0].must_equal "destroy"
|
28
|
+
the_key.actions.first[1].must_equal "#{API_URL}/keys/#{key_name}"
|
29
|
+
the_key.fingerprint.wont_be_nil
|
30
|
+
the_key.fingerprint.must_be_kind_of String
|
31
|
+
the_key.pem.wont_be_nil
|
32
|
+
the_key.pem.must_be_kind_of String
|
33
|
+
end
|
34
|
+
|
35
|
+
def create_key_if_necessary(client, key_name)
|
36
|
+
the_key = client.key(key_name)
|
37
|
+
unless the_key
|
38
|
+
client.create_key()
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
|
43
|
+
describe "Keys" do
|
44
|
+
it "should allow retrieval of all keys" do
|
45
|
+
DeltaCloud.new( API_NAME, API_PASSWORD, API_URL ) do |client|
|
46
|
+
client.keys.wont_be_empty
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
describe "Operations on Keys" do
|
52
|
+
|
53
|
+
it "should allow successful creation and destroy of a new key" do
|
54
|
+
DeltaCloud.new( API_NAME, API_PASSWORD, API_URL ) do |client|
|
55
|
+
new_key = client.create_key({:name => "my_new_key"})
|
56
|
+
check_key(new_key, "my_new_key")
|
57
|
+
the_key = client.key('my_new_key')
|
58
|
+
the_key.destroy!.must_be_nil
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
it "should allow retrieval of an existing named key" do
|
63
|
+
DeltaCloud.new( API_NAME, API_PASSWORD, API_URL ) do |client|
|
64
|
+
key_name = "test-key"
|
65
|
+
create_key_if_necessary(client, key_name)
|
66
|
+
the_key = client.key(key_name)
|
67
|
+
check_key(the_key, key_name)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
it "should raise error if you create a key with the same name as an existing key" do
|
72
|
+
DeltaCloud.new( API_NAME, API_PASSWORD, API_URL ) do |client|
|
73
|
+
name = "test-key"
|
74
|
+
create_key_if_necessary(client, name)
|
75
|
+
lambda{
|
76
|
+
client.create_key({:name => name})
|
77
|
+
}.must_raise DeltaCloud::HTTPError::Forbidden
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
end
|
@@ -0,0 +1,64 @@
|
|
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\.8/
|
18
|
+
|
19
|
+
require_relative './test_helper.rb'
|
20
|
+
|
21
|
+
describe "Realms" do
|
22
|
+
|
23
|
+
before do
|
24
|
+
@client = DeltaCloud.new(API_NAME, API_PASSWORD, API_URL)
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should allow retrieval of all realms" do
|
28
|
+
realms = @client.realms
|
29
|
+
realms.wont_be_empty
|
30
|
+
realms.each do |realm|
|
31
|
+
realm.uri.wont_be_nil
|
32
|
+
realm.uri.must_be_kind_of String
|
33
|
+
realm.id.wont_be_nil
|
34
|
+
realm.id.must_be_kind_of String
|
35
|
+
realm.name.wont_be_nil
|
36
|
+
realm.name.must_be_kind_of String
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
|
41
|
+
it "should allow fetching a realm by id" do
|
42
|
+
DeltaCloud.new( API_NAME, API_PASSWORD, API_URL ) do |client|
|
43
|
+
realm = client.realm( 'us' )
|
44
|
+
realm.wont_be_nil
|
45
|
+
realm.id.must_equal 'us'
|
46
|
+
realm.name.must_equal 'United States'
|
47
|
+
realm.state.must_equal 'AVAILABLE'
|
48
|
+
realm = client.realm( 'eu' )
|
49
|
+
realm.wont_be_nil
|
50
|
+
realm.id.must_equal 'eu'
|
51
|
+
realm.name.must_equal 'Europe'
|
52
|
+
realm.state.must_equal 'AVAILABLE'
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
it "should allow fetching a realm by URI" do
|
57
|
+
DeltaCloud.new( API_NAME, API_PASSWORD, API_URL ) do |client|
|
58
|
+
realm = client.fetch_realm( API_URL + '/realms/us' )
|
59
|
+
realm.wont_be_nil
|
60
|
+
realm.id.must_equal 'us'
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
end
|
@@ -0,0 +1,76 @@
|
|
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\.8/
|
18
|
+
|
19
|
+
require_relative './test_helper.rb'
|
20
|
+
|
21
|
+
describe "Storage Snapshot" do
|
22
|
+
|
23
|
+
it "allow retrieval of all storage volumes owned by the current user" do
|
24
|
+
client = DeltaCloud.new( API_NAME, API_PASSWORD, API_URL )
|
25
|
+
client.connect do |c|
|
26
|
+
storage_snapshots = c.storage_snapshots
|
27
|
+
storage_snapshots.wont_be_nil
|
28
|
+
storage_snapshots.wont_be_empty
|
29
|
+
ids = storage_snapshots.collect{|e| e.id}
|
30
|
+
ids.size.must_equal 3
|
31
|
+
ids.must_include 'snap2'
|
32
|
+
ids.must_include 'snap3'
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should allow fetching of storage volume by id" do
|
37
|
+
client = DeltaCloud.new( API_NAME, API_PASSWORD, API_URL )
|
38
|
+
client.connect do |c|
|
39
|
+
storage_snapshot = c.storage_snapshot( 'snap2' )
|
40
|
+
storage_snapshot.wont_be_nil
|
41
|
+
storage_snapshot.id.must_equal 'snap2'
|
42
|
+
storage_snapshot.storage_volume.capacity.must_equal 1.0
|
43
|
+
storage_snapshot.storage_volume.id.must_equal 'vol2'
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
it "should allow fetching of storage volume by URI" do
|
48
|
+
client = DeltaCloud.new( API_NAME, API_PASSWORD, API_URL )
|
49
|
+
client.connect do |c|
|
50
|
+
storage_snapshot = c.fetch_storage_snapshot( API_URL + '/storage_snapshots/snap2' )
|
51
|
+
storage_snapshot.wont_be_nil
|
52
|
+
storage_snapshot.id.must_equal 'snap2'
|
53
|
+
storage_snapshot.storage_volume.capacity.must_equal 1.0
|
54
|
+
storage_snapshot.storage_volume.id.must_equal 'vol2'
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
it "should return nil for unknown storage volume by ID" do
|
59
|
+
client = DeltaCloud.new( API_NAME, API_PASSWORD, API_URL )
|
60
|
+
lambda {
|
61
|
+
client.connect do |c|
|
62
|
+
c.storage_snapshot( "bogus" )
|
63
|
+
end
|
64
|
+
}.must_raise DeltaCloud::HTTPError::NotFound
|
65
|
+
end
|
66
|
+
|
67
|
+
it "should return nil for unknown storage volume by URI" do
|
68
|
+
client = DeltaCloud.new( API_NAME, API_PASSWORD, API_URL )
|
69
|
+
lambda {
|
70
|
+
client.connect do |c|
|
71
|
+
c.fetch_storage_snapshot( API_URL + '/storage_snapshots/bogus' )
|
72
|
+
end
|
73
|
+
}.must_raise DeltaCloud::HTTPError::NotFound
|
74
|
+
end
|
75
|
+
|
76
|
+
end
|
@@ -0,0 +1,86 @@
|
|
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\.8/
|
18
|
+
|
19
|
+
require_relative './test_helper.rb'
|
20
|
+
|
21
|
+
describe "Storage Volumes" do
|
22
|
+
|
23
|
+
it "allow retrieval of all storage volumes owned by the current user" do
|
24
|
+
client = DeltaCloud.new( API_NAME, API_PASSWORD, API_URL )
|
25
|
+
client.connect do |c|
|
26
|
+
storage_volumes = c.storage_volumes
|
27
|
+
storage_volumes.wont_be_nil
|
28
|
+
storage_volumes.wont_be_nil
|
29
|
+
ids = storage_volumes.collect{|e| e.id}
|
30
|
+
ids.size.must_equal 3
|
31
|
+
ids.must_include 'vol1'
|
32
|
+
ids.must_include 'vol3'
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should allow fetching of storage volume by id" do
|
37
|
+
client = DeltaCloud.new( API_NAME, API_PASSWORD, API_URL )
|
38
|
+
client.connect do |c|
|
39
|
+
storage_volume = c.storage_volume( 'vol3' )
|
40
|
+
storage_volume.id.must_equal 'vol3'
|
41
|
+
storage_volume.uri.must_equal API_URL + '/storage_volumes/vol3'
|
42
|
+
storage_volume.capacity.must_equal 1.0
|
43
|
+
storage_volume.device.must_equal '/dev/sda1'
|
44
|
+
storage_volume.instance.wont_be_nil
|
45
|
+
storage_volume.instance.id.must_equal 'inst1'
|
46
|
+
ip = storage_volume.instance
|
47
|
+
ip.hardware_profile.architecture.value.must_equal 'i386'
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
it "should allow fetching of storage volume by URI" do
|
52
|
+
client = DeltaCloud.new( API_NAME, API_PASSWORD, API_URL )
|
53
|
+
client.connect do |c|
|
54
|
+
storage_volume = c.fetch_storage_volume( API_URL + '/storage_volumes/vol3' )
|
55
|
+
storage_volume.wont_be_nil
|
56
|
+
storage_volume.id.must_equal 'vol3'
|
57
|
+
storage_volume.uri.must_equal API_URL + '/storage_volumes/vol3'
|
58
|
+
storage_volume.capacity.must_equal 1.0
|
59
|
+
storage_volume.device.must_equal '/dev/sda1'
|
60
|
+
storage_volume.instance.wont_be_nil
|
61
|
+
storage_volume.instance.id.must_equal 'inst1'
|
62
|
+
ip = storage_volume.instance
|
63
|
+
ip.hardware_profile.architecture.value.must_equal 'i386'
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
it "should raise exception for unknown storage volume by ID" do
|
68
|
+
client = DeltaCloud.new( API_NAME, API_PASSWORD, API_URL )
|
69
|
+
lambda {
|
70
|
+
client.connect do |c|
|
71
|
+
c.storage_volume( 'bogus' )
|
72
|
+
end
|
73
|
+
}.must_raise DeltaCloud::HTTPError::NotFound
|
74
|
+
end
|
75
|
+
|
76
|
+
it "should raise exception for unknown storage volume by URI" do
|
77
|
+
client = DeltaCloud.new( API_NAME, API_PASSWORD, API_URL )
|
78
|
+
lambda {
|
79
|
+
client.connect do |c|
|
80
|
+
client.fetch_storage_volume( API_URL + '/storage_volumes/bogus' )
|
81
|
+
end
|
82
|
+
}.must_raise DeltaCloud::HTTPError::NotFound
|
83
|
+
end
|
84
|
+
|
85
|
+
|
86
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'require_relative' if RUBY_VERSION =~ /^1\.8/
|
3
|
+
require 'minitest/autorun'
|
4
|
+
|
5
|
+
require_relative '../lib/deltacloud.rb'
|
6
|
+
|
7
|
+
# Configuration:
|
8
|
+
|
9
|
+
API_HOST = 'localhost'
|
10
|
+
API_PORT = '3001'
|
11
|
+
API_PATH = '/api'
|
12
|
+
|
13
|
+
API_NAME = 'mockuser'
|
14
|
+
API_PASSWORD = 'mockpassword'
|
15
|
+
|
16
|
+
API_URL = "http://#{API_HOST}:#{API_PORT}#{API_PATH}"
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: deltacloud-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2013-02-05 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rest-client
|
@@ -76,6 +76,19 @@ files:
|
|
76
76
|
- lib/instance_state.rb
|
77
77
|
- lib/client_bucket_methods.rb
|
78
78
|
- lib/errors.rb
|
79
|
+
- tests/realms_test.rb
|
80
|
+
- tests/content_negotiation_test.rb
|
81
|
+
- tests/images_test.rb
|
82
|
+
- tests/instances_test.rb
|
83
|
+
- tests/errors_test.rb
|
84
|
+
- tests/storage_snapshot_test.rb
|
85
|
+
- tests/storage_volume_test.rb
|
86
|
+
- tests/keys_test.rb
|
87
|
+
- tests/hardware_profiles_test.rb
|
88
|
+
- tests/buckets_test.rb
|
89
|
+
- tests/instance_states_test.rb
|
90
|
+
- tests/client_test.rb
|
91
|
+
- tests/test_helper.rb
|
79
92
|
- LICENSE
|
80
93
|
- NOTICE
|
81
94
|
homepage: http://www.deltacloud.org
|
@@ -102,4 +115,17 @@ rubygems_version: 1.8.23
|
|
102
115
|
signing_key:
|
103
116
|
specification_version: 3
|
104
117
|
summary: Deltacloud REST Client
|
105
|
-
test_files:
|
118
|
+
test_files:
|
119
|
+
- tests/realms_test.rb
|
120
|
+
- tests/content_negotiation_test.rb
|
121
|
+
- tests/images_test.rb
|
122
|
+
- tests/instances_test.rb
|
123
|
+
- tests/errors_test.rb
|
124
|
+
- tests/storage_snapshot_test.rb
|
125
|
+
- tests/storage_volume_test.rb
|
126
|
+
- tests/keys_test.rb
|
127
|
+
- tests/hardware_profiles_test.rb
|
128
|
+
- tests/buckets_test.rb
|
129
|
+
- tests/instance_states_test.rb
|
130
|
+
- tests/client_test.rb
|
131
|
+
- tests/test_helper.rb
|