openstack 1.0.4 → 1.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.rdoc +1 -1
- data/VERSION +1 -1
- data/lib/openstack/connection.rb +3 -1
- data/test/authentication_test.rb +134 -0
- data/test/connection_test.rb +39 -0
- data/test/exception_test.rb +49 -0
- data/test/metadata_test.rb +210 -0
- data/test/servers_test.rb +210 -0
- data/test/test_helper.rb +22 -0
- metadata +40 -2
data/README.rdoc
CHANGED
@@ -6,7 +6,7 @@ Ruby Openstack Compute and Object-Store bindings for the v1.0 OSAPI.
|
|
6
6
|
|
7
7
|
Currently supports both v1.0 and v2.0 (keystone) auth.
|
8
8
|
|
9
|
-
Use OpenStack::Connection.create to get a handle to an OpenStack service - set the :service_type parameter to either 'compute' or 'object-store' (defaults to 'compute')
|
9
|
+
Use OpenStack::Connection.create to get a handle to an OpenStack service - set the :service_type parameter to either 'compute' or 'object-store' (defaults to 'compute'). If the requested service is not deployed the gem will throw a OpenStack::Exception::NotImplemented (501) - e.g. :service_type is 'object-store' but swift service isn't deployed.
|
10
10
|
|
11
11
|
The OpenStack::Connection.create class method is a factory constructor which will return the appropriate Connection object, depending on the ':service_type' parameter passed with the options hash: set to either 'compute' or 'object-store' (defaults to 'compute') - see below for examples.
|
12
12
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.0.
|
1
|
+
1.0.6
|
data/lib/openstack/connection.rb
CHANGED
@@ -245,7 +245,6 @@ end
|
|
245
245
|
|
246
246
|
class AuthV20
|
247
247
|
attr_reader :uri
|
248
|
-
|
249
248
|
def initialize(connection)
|
250
249
|
begin
|
251
250
|
server = Net::HTTP::Proxy(connection.proxy_host, connection.proxy_port).new(connection.auth_host, connection.auth_port)
|
@@ -275,6 +274,9 @@ class AuthV20
|
|
275
274
|
if (response.code =~ /^20./)
|
276
275
|
resp_data=JSON.parse(response.body)
|
277
276
|
connection.authtoken = resp_data['access']['token']['id']
|
277
|
+
implemented_services = resp_data["access"]["serviceCatalog"].inject([]){|res, current| res << current["type"] ;res}
|
278
|
+
raise OpenStack::Exception::NotImplemented.new("The requested service: \"#{connection.service_type}\" is not present " +
|
279
|
+
"in the returned service catalogue.", 501, "#{resp_data["access"]["serviceCatalog"]}") unless implemented_services.include?(connection.service_type)
|
278
280
|
resp_data['access']['serviceCatalog'].each do |service|
|
279
281
|
if service['type'] == connection.service_type
|
280
282
|
endpoints = service["endpoints"]
|
@@ -0,0 +1,134 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/test_helper'
|
2
|
+
|
3
|
+
class AuthenticationTest < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def test_good_authentication
|
6
|
+
response = {'x-server-management-url' => 'http://server-manage.example.com/path', 'x-auth-token' => 'dummy_token'}
|
7
|
+
response.stubs(:code).returns('204')
|
8
|
+
server = mock(:use_ssl= => true, :verify_mode= => true, :start => true, :finish => true)
|
9
|
+
server.stubs(:get).returns(response)
|
10
|
+
Net::HTTP.stubs(:new).returns(server)
|
11
|
+
connection = stub(:authuser => 'good_user',:authtenant => {:type=>"tenantName", :value=>'good_tenant'}, :authkey => 'bad_key', :auth_host => "a.b.c", :auth_port => "443", :auth_scheme => "https", :auth_path => "/v1.0", :service_type=>"compute", :authok= => true, :authtoken= => true, :service_host= => "", :service_path= => "", :service_path => "", :service_port= => "", :service_scheme= => "", :proxy_host => nil, :proxy_port => nil, :api_path => '/foo')
|
12
|
+
result = OpenStack::Authentication.init(connection)
|
13
|
+
assert_equal result.class, OpenStack::AuthV10
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_bad_authentication
|
17
|
+
response = mock()
|
18
|
+
response.stubs(:code).returns('499')
|
19
|
+
server = mock(:use_ssl= => true, :verify_mode= => true, :start => true)
|
20
|
+
server.stubs(:get).returns(response)
|
21
|
+
Net::HTTP.stubs(:new).returns(server)
|
22
|
+
connection = stub(:authuser => 'bad_user', :authtenant => {:type=>"tenantName", :value=>'good_tenant'}, :authkey => 'bad_key', :auth_host => "a.b.c", :auth_port => "443", :auth_scheme => "https", :auth_path => "/v1.0", :authok= => true, :authtoken= => true, :proxy_host => nil, :proxy_port => nil, :api_path => '/foo')
|
23
|
+
assert_raises(OpenStack::Exception::Authentication) do
|
24
|
+
result = OpenStack::Authentication.init(connection)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_bad_hostname
|
29
|
+
Net::HTTP.stubs(:new).raises(OpenStack::Exception::Connection)
|
30
|
+
connection = stub(:authuser => 'bad_user', :authtenant => {:type=>"tenantName", :value=>'good_tenant'}, :authkey => 'bad_key', :auth_host => "a.b.c", :auth_port => "443", :auth_scheme => "https", :auth_path => "/v1.0", :authok= => true, :authtoken= => true, :proxy_host => nil, :proxy_port => nil, :api_path => '/foo')
|
31
|
+
assert_raises(OpenStack::Exception::Connection) do
|
32
|
+
result = OpenStack::Authentication.init(connection)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_service_region
|
37
|
+
server = get_test_auth_server
|
38
|
+
Net::HTTP.stubs(:new).returns(server)
|
39
|
+
server.stubs(:started?).returns(true)
|
40
|
+
connection = stub(:authuser => 'good_user', :auth_method => "password",:authtenant => {:type=>"tenantName", :value=>'good_tenant'} , :authkey => 'bad_key', :auth_host => "a.b.c", :auth_port => "443", :auth_scheme => "https", :auth_path => "/v2.0", :authok= => true, :authtoken= => true, :service_host= => "", :service_path= => "", :service_path => "", :service_port= => "", :service_scheme= => "", :proxy_host => nil, :proxy_port => nil, :api_path => '/foo', :service_type => "compute", :service_name => "cloudServers", :region => "South")
|
41
|
+
result = OpenStack::Authentication.init(connection)
|
42
|
+
assert_equal("compute.south.host", result.uri.host)
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_service_name
|
46
|
+
server = get_test_auth_server
|
47
|
+
Net::HTTP.stubs(:new).returns(server)
|
48
|
+
server.stubs(:started?).returns(true)
|
49
|
+
connection = stub(:authuser => 'good_user', :auth_method=>"password", :authtenant => {:type=>"tenantName", :value=>'good_tenant'}, :authkey => 'bad_key', :auth_host => "a.b.c", :auth_port => "443", :auth_scheme => "https", :auth_path => "/v2.0", :authok= => true, :authtoken= => true, :service_host= => "", :service_path= => "", :service_path => "", :service_port= => "", :service_scheme= => "", :proxy_host => nil, :proxy_port => nil, :api_path => '/foo', :service_type => "nova", :service_name => "cloudCompute", :region => "South")
|
50
|
+
result = OpenStack::Authentication.init(connection)
|
51
|
+
assert_equal("nova.south.host", result.uri.host)
|
52
|
+
end
|
53
|
+
|
54
|
+
def test_service_type
|
55
|
+
server = get_test_auth_server
|
56
|
+
Net::HTTP.stubs(:new).returns(server)
|
57
|
+
server.stubs(:started?).returns(true)
|
58
|
+
connection = stub(:authuser => 'good_user', :auth_method => "password", :authtenant => {:type=>"tenantName", :value=>'good_tenant'}, :authkey => 'bad_key', :auth_host => "a.b.c", :auth_port => "443", :auth_scheme => "https", :auth_path => "/v2.0", :authok= => true, :authtoken= => true, :service_host= => "", :service_path= => "", :service_path => "", :service_port= => "", :service_scheme= => "", :proxy_host => nil, :proxy_port => nil, :api_path => '/foo', :service_type => "nova", :service_name => nil, :region => "North")
|
59
|
+
result = OpenStack::Authentication.init(connection)
|
60
|
+
assert_equal("nova.north.host", result.uri.host)
|
61
|
+
end
|
62
|
+
|
63
|
+
|
64
|
+
private
|
65
|
+
def get_test_auth_server
|
66
|
+
json_response = %{{
|
67
|
+
"access":{
|
68
|
+
"token":{
|
69
|
+
"id":"asdasdasd-adsasdads-asdasdasd-adsadsasd",
|
70
|
+
"expires":"2010-11-01T03:32:15-05:00"
|
71
|
+
},
|
72
|
+
"user":{
|
73
|
+
"id":"123",
|
74
|
+
"name":"testName",
|
75
|
+
"roles":[{
|
76
|
+
"id":"234",
|
77
|
+
"name":"compute:admin"
|
78
|
+
},
|
79
|
+
{
|
80
|
+
"id":"235",
|
81
|
+
"name":"object-store:admin",
|
82
|
+
"tenantId":"1"
|
83
|
+
}
|
84
|
+
],
|
85
|
+
"roles_links":[]
|
86
|
+
},
|
87
|
+
"serviceCatalog":[{
|
88
|
+
"name":"cloudServers",
|
89
|
+
"type":"compute",
|
90
|
+
"endpoints":[{
|
91
|
+
"publicURL":"https://compute.north.host/v1.1",
|
92
|
+
"region":"North"
|
93
|
+
},
|
94
|
+
{
|
95
|
+
"publicURL":"https://compute.south.host/v1.1",
|
96
|
+
"region":"South"
|
97
|
+
}
|
98
|
+
],
|
99
|
+
"endpoints_links":[]
|
100
|
+
},
|
101
|
+
{
|
102
|
+
"name":"cloudCompute",
|
103
|
+
"type":"nova",
|
104
|
+
"endpoints":[{
|
105
|
+
"publicURL":"https://nova.north.host/v1.1",
|
106
|
+
"region":"North"
|
107
|
+
},
|
108
|
+
{
|
109
|
+
"publicURL":"https://nova.south.host/v1.1",
|
110
|
+
"region":"South"
|
111
|
+
}
|
112
|
+
],
|
113
|
+
"endpoints_links":[{
|
114
|
+
"rel":"next",
|
115
|
+
"href":"https://identity.north.host/v2.0/endpoints?marker=2"
|
116
|
+
}
|
117
|
+
]
|
118
|
+
}
|
119
|
+
],
|
120
|
+
"serviceCatalog_links":[{
|
121
|
+
"rel":"next",
|
122
|
+
"href":"https://identity.host/v2.0/endpoints?session=2hfh8Ar&marker=2"
|
123
|
+
}
|
124
|
+
]
|
125
|
+
}
|
126
|
+
}}
|
127
|
+
|
128
|
+
response = {'x-server-management-url' => 'http://server-manage.example.com/path', 'x-auth-token' => 'dummy_token'}
|
129
|
+
response.stubs(:code => "200", :body => json_response)
|
130
|
+
server = mock(:use_ssl= => true, :verify_mode= => true, :start => true, :finish => true)
|
131
|
+
server.stubs(:post).returns(response)
|
132
|
+
return server
|
133
|
+
end
|
134
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/test_helper'
|
2
|
+
|
3
|
+
class ComputeConnectionTest < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def setup
|
6
|
+
connection = stub()
|
7
|
+
OpenStack::Authentication.stubs(:init).returns(connection)
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_init_connection_no_credentials
|
11
|
+
assert_raises(OpenStack::Exception::MissingArgument) do
|
12
|
+
conn = OpenStack::Connection.create(:api_key => "AABBCCDD11", :auth_url => "a.b.c")
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_init_connection_no_password
|
17
|
+
assert_raises(OpenStack::Exception::MissingArgument) do
|
18
|
+
conn = OpenStack::Connection.create(:username => "test_account", :auth_url => "a.b.c")
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_init_connection_no_auth_url
|
23
|
+
assert_raises(OpenStack::Exception::MissingArgument) do
|
24
|
+
conn = OpenStack::Connection.create(:username => "test_account", :api_key => "AABBCCDD11")
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_init_connection_bad_auth_url
|
29
|
+
assert_raises(OpenStack::Exception::InvalidArgument) do
|
30
|
+
conn = OpenStack::Connection.create(:username => "test_account", :api_key => "AABBCCDD11", :auth_url => "***")
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_init_connection
|
35
|
+
conn = OpenStack::Connection.create(:username => "test_account", :api_key => "AABBCCDD11", :auth_url => "https://a.b.c")
|
36
|
+
assert_not_nil conn, "Connection.new returned nil."
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/test_helper'
|
2
|
+
|
3
|
+
class ExceptionTest < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def test_400_cloud_servers_fault
|
6
|
+
response = mock()
|
7
|
+
response.stubs(:code => "400", :body => "{\"ComputeFault\":{\"message\":\"422 Unprocessable Entity: We could not process your request at this time. We have been notified and are looking into the issue. [E03]\",\"details\":\"com.rackspace.cloud.service.servers.OpenStack::ComputeFault: Fault occured\",\"code\":400}}" )
|
8
|
+
exception=nil
|
9
|
+
begin
|
10
|
+
OpenStack::Exception.raise_exception(response)
|
11
|
+
rescue Exception => e
|
12
|
+
exception=e
|
13
|
+
end
|
14
|
+
assert_equal(OpenStack::Exception::ComputeFault, e.class)
|
15
|
+
assert_equal("400", e.response_code)
|
16
|
+
assert_not_nil(e.response_body)
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_413_over_limit
|
20
|
+
response = mock()
|
21
|
+
response.stubs(:code => "413", :body => "{\"overLimit\":{\"message\":\"Too many requests...\",\"code\":413,\"retryAfter\":\"2010-08-25T10:47:57.890-05:00\"}}")
|
22
|
+
exception=nil
|
23
|
+
begin
|
24
|
+
OpenStack::Exception.raise_exception(response)
|
25
|
+
rescue Exception => e
|
26
|
+
exception=e
|
27
|
+
end
|
28
|
+
assert_equal(OpenStack::Exception::OverLimit, e.class)
|
29
|
+
assert_equal("413", e.response_code)
|
30
|
+
assert_not_nil(e.response_body)
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_other
|
34
|
+
response = mock()
|
35
|
+
body="{\"blahblah\":{\"message\":\"Failed...\",\"code\":500}}"
|
36
|
+
response.stubs(:code => "500", :body => body)
|
37
|
+
exception=nil
|
38
|
+
begin
|
39
|
+
OpenStack::Exception.raise_exception(response)
|
40
|
+
rescue Exception => e
|
41
|
+
exception=e
|
42
|
+
end
|
43
|
+
assert_equal(OpenStack::Exception::Other, exception.class)
|
44
|
+
assert_equal("500", exception.response_code)
|
45
|
+
assert_not_nil(exception.response_body)
|
46
|
+
assert_equal(body, exception.response_body)
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
@@ -0,0 +1,210 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/test_helper'
|
2
|
+
|
3
|
+
class MetadataTest < Test::Unit::TestCase
|
4
|
+
|
5
|
+
include TestConnection
|
6
|
+
|
7
|
+
def setup
|
8
|
+
@compute=get_test_connection
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_metadata_uses_initial_values
|
12
|
+
data = {'key1' => 'value1', 'key2' => 'value2'}
|
13
|
+
metadata = OpenStack::Compute::Metadata.new(@conn, 'blah', data)
|
14
|
+
assert_equal('value1', metadata['key1'])
|
15
|
+
assert_equal('value2', metadata['key2'])
|
16
|
+
assert_equal(nil, metadata['key0'])
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_metadata_presents_saved_values
|
20
|
+
metadata = OpenStack::Compute::Metadata.new(@conn, 'blah')
|
21
|
+
metadata['key3'] = 'value3'
|
22
|
+
assert_equal('value3', metadata['key3'])
|
23
|
+
assert_equal(nil, metadata['key0'])
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_metadata_presents_stored_values
|
27
|
+
metadata = OpenStack::Compute::Metadata.new(@conn, 'blah')
|
28
|
+
metadata.store('key3', 'value3')
|
29
|
+
assert_equal('value3', metadata['key3'])
|
30
|
+
assert_equal(nil, metadata['key0'])
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_metadata_looks_up_values_if_none_provided
|
34
|
+
data = {'metadata' => {'key4' => 'value4'}}
|
35
|
+
json = JSON.generate(data)
|
36
|
+
response = mock()
|
37
|
+
response.stubs(:code => "200", :body => json)
|
38
|
+
conn = mock()
|
39
|
+
@compute.stubs(:connection).returns(conn)
|
40
|
+
conn.stubs(:req).returns(response)
|
41
|
+
metadata = OpenStack::Compute::Metadata.new(@compute, 'blah')
|
42
|
+
assert_equal('value4', metadata['key4'])
|
43
|
+
assert_equal(nil, metadata['key0'])
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_metadata_save_nil
|
47
|
+
conn = mock()
|
48
|
+
metadata = OpenStack::Compute::Metadata.new(conn, 'blah')
|
49
|
+
metadata.save # do nothing or we'd likely be deleting unintentionally
|
50
|
+
end
|
51
|
+
|
52
|
+
def test_metadata_save
|
53
|
+
data = {'key1' => 'value1', 'key3' => 'value3'}
|
54
|
+
json = JSON.generate({'metadata' => data})
|
55
|
+
response = mock()
|
56
|
+
response.stubs(:code => "200", :body => json)
|
57
|
+
compute = mock()
|
58
|
+
conn = mock()
|
59
|
+
compute.stubs(:connection).returns(conn)
|
60
|
+
conn.expects(:req).with('PUT', 'blah/metadata', :data => json).returns(response)
|
61
|
+
metadata = OpenStack::Compute::Metadata.new(compute, 'blah', data)
|
62
|
+
metadata.save
|
63
|
+
end
|
64
|
+
|
65
|
+
def test_metadata_update_all
|
66
|
+
data_in = {'key5' => 'value5', 'key6' => 'value6'}
|
67
|
+
data_out = {'key5' => 'value5', 'key6' => 'value6', 'key7' => 'value7'}
|
68
|
+
json_in = JSON.generate({'metadata' => data_in})
|
69
|
+
json_out = JSON.generate({'metadata' => data_out})
|
70
|
+
response = mock()
|
71
|
+
response.stubs(:code => "200", :body => json_out)
|
72
|
+
compute = mock()
|
73
|
+
conn = mock()
|
74
|
+
compute.stubs(:connection).returns(conn)
|
75
|
+
conn.expects(:req).with('POST', 'blah/metadata', :data => json_in).returns(response)
|
76
|
+
metadata = OpenStack::Compute::Metadata.new(compute, 'blah')
|
77
|
+
metadata['key5'] = 'value5'
|
78
|
+
metadata['key6'] = 'value6'
|
79
|
+
metadata.update
|
80
|
+
assert_equal('value5', metadata['key5'])
|
81
|
+
assert_equal('value6', metadata['key6'])
|
82
|
+
assert_equal('value7', metadata['key7'])
|
83
|
+
end
|
84
|
+
|
85
|
+
def test_metadata_update_some_keys
|
86
|
+
json1 = JSON.generate({'meta' => {'key1' => 'value1'}})
|
87
|
+
response1 = mock()
|
88
|
+
response1.stubs(:code => "200", :body => json1)
|
89
|
+
json2 = JSON.generate({'meta' => {'key2' => 'value2'}})
|
90
|
+
response2 = mock()
|
91
|
+
response2.stubs(:code => "200", :body => json2)
|
92
|
+
conn = mock()
|
93
|
+
compute = mock()
|
94
|
+
compute.stubs(:connection).returns(conn)
|
95
|
+
conn.expects(:req).with('PUT', 'blah/metadata/key1', :data => json1).returns(response1)
|
96
|
+
conn.expects(:req).with('PUT', 'blah/metadata/key2', :data => json2).returns(response2)
|
97
|
+
data = {'key1' => 'value1', 'key2' => 'value2', 'key3' => 'value3'}
|
98
|
+
metadata = OpenStack::Compute::Metadata.new(compute, 'blah', data)
|
99
|
+
metadata.update(['key1', 'key2'])
|
100
|
+
end
|
101
|
+
|
102
|
+
def test_metadata_update_one_key
|
103
|
+
json = JSON.generate({'meta' => {'key2' => 'value2'}})
|
104
|
+
response = mock()
|
105
|
+
response.stubs(:code => "200", :body => json)
|
106
|
+
compute = mock()
|
107
|
+
conn = mock()
|
108
|
+
compute.stubs(:connection).returns(conn)
|
109
|
+
conn.expects(:req).with('PUT', 'blah/metadata/key2', :data => json).returns(response)
|
110
|
+
data = {'key1' => 'value1', 'key2' => 'value2'}
|
111
|
+
metadata = OpenStack::Compute::Metadata.new(compute, 'blah', data)
|
112
|
+
metadata.update(['key2'])
|
113
|
+
end
|
114
|
+
|
115
|
+
def test_metadata_update_nonexistent_key
|
116
|
+
data = {'key1' => 'value1', 'key2' => 'value2'}
|
117
|
+
compute = mock()
|
118
|
+
conn = mock()
|
119
|
+
compute.stubs(:connection).returns(conn)
|
120
|
+
metadata = OpenStack::Compute::Metadata.new(compute, 'blah', data)
|
121
|
+
metadata.update(['key3']) # just asserting nothing is called on conn
|
122
|
+
end
|
123
|
+
|
124
|
+
def test_metadata_update_nil
|
125
|
+
compute = mock()
|
126
|
+
conn = mock()
|
127
|
+
compute.stubs(:connection).returns(conn)
|
128
|
+
metadata = OpenStack::Compute::Metadata.new(compute, 'blah')
|
129
|
+
metadata.update # just asserting nothing is called on the connection
|
130
|
+
end
|
131
|
+
|
132
|
+
def test_refresh_one_key
|
133
|
+
json = JSON.generate({'meta' => {'key1' => 'value1'}})
|
134
|
+
response = mock()
|
135
|
+
response.stubs(:code => "200", :body => json)
|
136
|
+
compute = mock()
|
137
|
+
conn = mock()
|
138
|
+
compute.stubs(:connection).returns(conn)
|
139
|
+
conn.expects(:req).with('GET', 'blah/metadata/key1').returns(response)
|
140
|
+
metadata = OpenStack::Compute::Metadata.new(compute, 'blah')
|
141
|
+
metadata.refresh(['key1'])
|
142
|
+
assert_equal('value1', metadata['key1'])
|
143
|
+
end
|
144
|
+
|
145
|
+
def test_refresh_some_keys_with_key_not_found
|
146
|
+
json = JSON.generate({'meta' => {'key1' => 'value1'}})
|
147
|
+
response = mock()
|
148
|
+
response.stubs(:code => "200", :body => json)
|
149
|
+
not_found = mock()
|
150
|
+
not_found.stubs(:code => "404")
|
151
|
+
compute = mock()
|
152
|
+
conn = mock()
|
153
|
+
compute.stubs(:connection).returns(conn)
|
154
|
+
conn.expects(:req).with('GET', 'blah/metadata/key1').returns(response)
|
155
|
+
conn.expects(:req).with('GET', 'blah/metadata/key0').returns(not_found)
|
156
|
+
metadata = OpenStack::Compute::Metadata.new(compute, 'blah')
|
157
|
+
metadata.refresh(['key1', 'key0'])
|
158
|
+
assert_equal('value1', metadata['key1'])
|
159
|
+
assert(metadata['key0'].nil?)
|
160
|
+
end
|
161
|
+
|
162
|
+
def test_delete_a_key
|
163
|
+
response = mock()
|
164
|
+
response.stubs(:code => "204")
|
165
|
+
connection = mock()
|
166
|
+
compute = mock()
|
167
|
+
compute.stubs(:connection).returns(connection)
|
168
|
+
connection.expects(:req).with('DELETE', 'blah/metadata/key1').returns(response)
|
169
|
+
metadata = OpenStack::Compute::Metadata.new(compute, 'blah')
|
170
|
+
metadata.delete!(['key1'])
|
171
|
+
end
|
172
|
+
|
173
|
+
def test_delete_a_key_with_prior_information
|
174
|
+
response = mock()
|
175
|
+
response.stubs(:code => "204")
|
176
|
+
comp = mock()
|
177
|
+
conn = mock()
|
178
|
+
comp.stubs(:connection).returns(conn)
|
179
|
+
conn.expects(:req).with('DELETE', 'blah/metadata/key1').returns(response)
|
180
|
+
data = {'key1' => 'value1', 'key2' => 'value2'}
|
181
|
+
metadata = OpenStack::Compute::Metadata.new(comp, 'blah', data)
|
182
|
+
metadata.delete!(['key1'])
|
183
|
+
assert(metadata['key1'].nil?)
|
184
|
+
assert_equal('value2', metadata['key2'])
|
185
|
+
end
|
186
|
+
##
|
187
|
+
def test_delete_keys_softly
|
188
|
+
comp = mock()
|
189
|
+
conn = mock()
|
190
|
+
comp.stubs(:connection).returns(conn)
|
191
|
+
data = {'key1' => 'value1', 'key2' => 'value2', 'key3' => 'value3'}
|
192
|
+
metadata = OpenStack::Compute::Metadata.new(comp, 'blah', data)
|
193
|
+
metadata.delete(['key1', 'key3'])
|
194
|
+
assert(metadata['key1'].nil?)
|
195
|
+
assert_equal('value2', metadata['key2'])
|
196
|
+
assert(metadata['key3'].nil?)
|
197
|
+
end
|
198
|
+
|
199
|
+
def test_each_pair
|
200
|
+
comp = mock()
|
201
|
+
conn = mock()
|
202
|
+
comp.stubs(:connection).returns(conn)
|
203
|
+
data = {'key1' => 'value1', 'key2' => 'value2', 'key3' => 'value3'}
|
204
|
+
metadata = OpenStack::Compute::Metadata.new(comp, 'blah', data)
|
205
|
+
metadata.each_pair do |k,v|
|
206
|
+
assert_equal v, data[k]
|
207
|
+
end
|
208
|
+
end
|
209
|
+
|
210
|
+
end
|
@@ -0,0 +1,210 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/test_helper'
|
2
|
+
|
3
|
+
class ServersTest < Test::Unit::TestCase
|
4
|
+
|
5
|
+
include TestConnection
|
6
|
+
|
7
|
+
def setup
|
8
|
+
@comp=get_test_connection
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_list_servers
|
12
|
+
|
13
|
+
json_response = %{{
|
14
|
+
"servers" : [
|
15
|
+
{
|
16
|
+
"id" : 1234,
|
17
|
+
"name" : "sample-server",
|
18
|
+
"image" : { "id": "2" },
|
19
|
+
"flavor" : { "id" : "1" },
|
20
|
+
"hostId" : "e4d909c290d0fb1ca068ffaddf22cbd0",
|
21
|
+
"status" : "BUILD",
|
22
|
+
"progress" : 60,
|
23
|
+
"addresses" : {
|
24
|
+
"public" : [
|
25
|
+
{ "version" : 4, "addr" : "67.23.10.132" },
|
26
|
+
{ "version" : 4, "addr" : "67.23.10.131" }
|
27
|
+
],
|
28
|
+
"private" : [
|
29
|
+
{ "version" : 4, "addr" : "10.176.42.16" }
|
30
|
+
]
|
31
|
+
},
|
32
|
+
"metadata" : {
|
33
|
+
"Server Label" : "Web Head 1",
|
34
|
+
"Image Version" : "2.1"
|
35
|
+
}
|
36
|
+
},
|
37
|
+
{
|
38
|
+
"id" : 5678,
|
39
|
+
"name" : "sample-server2",
|
40
|
+
"image" : { "id": "2" },
|
41
|
+
"flavor" : { "id" : "1" },
|
42
|
+
"hostId" : "9e107d9d372bb6826bd81d3542a419d6",
|
43
|
+
"status" : "ACTIVE",
|
44
|
+
"addresses" : {
|
45
|
+
"public" : [
|
46
|
+
{ "version" : 4, "addr" : "67.23.10.133" }
|
47
|
+
],
|
48
|
+
"private" : [
|
49
|
+
{ "version" : 4, "addr" : "10.176.42.17" }
|
50
|
+
]
|
51
|
+
},
|
52
|
+
"metadata" : {
|
53
|
+
"Server Label" : "DB 1"
|
54
|
+
}
|
55
|
+
}
|
56
|
+
]
|
57
|
+
}}
|
58
|
+
response = mock()
|
59
|
+
response.stubs(:code => "200", :body => json_response)
|
60
|
+
@comp.connection.stubs(:csreq).returns(response)
|
61
|
+
servers=@comp.list_servers
|
62
|
+
assert_equal 2, servers.size
|
63
|
+
assert_equal 1234, servers[0][:id]
|
64
|
+
assert_equal "sample-server", servers[0][:name]
|
65
|
+
end
|
66
|
+
|
67
|
+
def test_get_server
|
68
|
+
|
69
|
+
server=get_test_server
|
70
|
+
assert_equal "sample-server", server.name
|
71
|
+
assert_equal "2", server.image['id']
|
72
|
+
assert_equal "1", server.flavor['id']
|
73
|
+
assert_equal "e4d909c290d0fb1ca068ffaddf22cbd0", server.hostId
|
74
|
+
assert_equal "BUILD", server.status
|
75
|
+
assert_equal 60, server.progress
|
76
|
+
assert_equal "67.23.10.132", server.addresses[:public][0].address
|
77
|
+
assert_equal "67.23.10.131", server.addresses[:public][1].address
|
78
|
+
assert_equal "10.176.42.16", server.addresses[:private][0].address
|
79
|
+
|
80
|
+
end
|
81
|
+
|
82
|
+
def test_rebuild_server
|
83
|
+
|
84
|
+
json_response = %{{
|
85
|
+
"server": {
|
86
|
+
"id": "52415800-8b69-11e0-9b19-734f565bc83b",
|
87
|
+
"tenantId": "1234",
|
88
|
+
"userId": "5678",
|
89
|
+
"name": "newName",
|
90
|
+
"created": "2010-11-11T12:00:00Z",
|
91
|
+
"hostId": "e4d909c290d0fb1ca068ffaddf22cbd0",
|
92
|
+
"accessIPv4" : "67.23.10.138",
|
93
|
+
"accessIPv6" : "::babe:67.23.10.138",
|
94
|
+
"progress": 0,
|
95
|
+
"status": "REBUILD",
|
96
|
+
"adminPass": "GFf1j9aP",
|
97
|
+
"image" : {
|
98
|
+
"id": "52415800-8b69-11e0-9b19-734f6f006e54",
|
99
|
+
"name": "CentOS 5.2",
|
100
|
+
"links": [
|
101
|
+
{
|
102
|
+
"rel": "self",
|
103
|
+
"href": "http://servers.api.openstack.org/v1.1/1234/images/52415800-8b69-11e0-9b19-734f6f006e54"
|
104
|
+
},
|
105
|
+
{
|
106
|
+
"rel": "bookmark",
|
107
|
+
"href": "http://servers.api.openstack.org/1234/images/52415800-8b69-11e0-9b19-734f6f006e54"
|
108
|
+
}
|
109
|
+
]
|
110
|
+
},
|
111
|
+
"flavor" : {
|
112
|
+
"id": "52415800-8b69-11e0-9b19-734f1195ff37",
|
113
|
+
"name": "256 MB Server",
|
114
|
+
"links": [
|
115
|
+
{
|
116
|
+
"rel": "self",
|
117
|
+
"href": "http://servers.api.openstack.org/v1.1/1234/flavors/52415800-8b69-11e0-9b19-734f1195ff37"
|
118
|
+
},
|
119
|
+
{
|
120
|
+
"rel": "bookmark",
|
121
|
+
"href": "http://servers.api.openstack.org/1234/flavors/52415800-8b69-11e0-9b19-734f1195ff37"
|
122
|
+
}
|
123
|
+
]
|
124
|
+
},
|
125
|
+
"metadata": {
|
126
|
+
"My Server Name": "Apache1"
|
127
|
+
},
|
128
|
+
"addresses": {
|
129
|
+
"public" : [
|
130
|
+
{
|
131
|
+
"version": 4,
|
132
|
+
"addr": "67.23.10.138"
|
133
|
+
},
|
134
|
+
{
|
135
|
+
"version": 6,
|
136
|
+
"addr": "2001:0db8:85a3:0000:0000:8a2e:0370:7334"
|
137
|
+
}
|
138
|
+
],
|
139
|
+
"private" : [
|
140
|
+
{
|
141
|
+
"version": 4,
|
142
|
+
"addr": "10.176.42.19"
|
143
|
+
},
|
144
|
+
{
|
145
|
+
"version": 6,
|
146
|
+
"addr": "fe80:0000:0000:0000:0202:b3ff:fe1e:8329"
|
147
|
+
}
|
148
|
+
]
|
149
|
+
},
|
150
|
+
"links": [
|
151
|
+
{
|
152
|
+
"rel": "self",
|
153
|
+
"href": "http://servers.api.openstack.org/v1.1/1234/servers/52415800-8b69-11e0-9b19-734fcece0043"
|
154
|
+
},
|
155
|
+
{
|
156
|
+
"rel": "bookmark",
|
157
|
+
"href": "http://servers.api.openstack.org/1234/servers/52415800-8b69-11e0-9b19-734fcece0043"
|
158
|
+
}
|
159
|
+
]
|
160
|
+
}
|
161
|
+
}}
|
162
|
+
|
163
|
+
server=get_test_server
|
164
|
+
|
165
|
+
response = mock()
|
166
|
+
response.stubs(:code => "200", :body => json_response)
|
167
|
+
|
168
|
+
@comp.connection.stubs(:csreq).returns(response)
|
169
|
+
server.rebuild!(:name => "newName")
|
170
|
+
|
171
|
+
assert_not_nil server.adminPass
|
172
|
+
assert_equal "newName", server.name
|
173
|
+
|
174
|
+
end
|
175
|
+
|
176
|
+
private
|
177
|
+
def get_test_server
|
178
|
+
|
179
|
+
json_response = %{{
|
180
|
+
"server" : {
|
181
|
+
"id" : 1234,
|
182
|
+
"name" : "sample-server",
|
183
|
+
"image" : { "id": "2" },
|
184
|
+
"flavor" : { "id" : "1" },
|
185
|
+
"hostId" : "e4d909c290d0fb1ca068ffaddf22cbd0",
|
186
|
+
"status" : "BUILD",
|
187
|
+
"progress" : 60,
|
188
|
+
"addresses" : {
|
189
|
+
"public" : [
|
190
|
+
{ "version" : 4, "addr" : "67.23.10.132" },
|
191
|
+
{ "version" : 4, "addr" : "67.23.10.131" }
|
192
|
+
],
|
193
|
+
"private" : [
|
194
|
+
{ "version" : 4, "addr" : "10.176.42.16" }
|
195
|
+
]
|
196
|
+
},
|
197
|
+
"metadata" : {
|
198
|
+
"Server Label" : "Web Head 1",
|
199
|
+
"Image Version" : "2.1"
|
200
|
+
}
|
201
|
+
}
|
202
|
+
}}
|
203
|
+
|
204
|
+
response = mock()
|
205
|
+
response.stubs(:code => "200", :body => json_response)
|
206
|
+
@comp.connection.stubs(:csreq).returns(response)
|
207
|
+
return @comp.server(1234)
|
208
|
+
end
|
209
|
+
|
210
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'test/unit'
|
3
|
+
require 'mocha'
|
4
|
+
$:.unshift File.dirname(__FILE__) + '/../lib'
|
5
|
+
require 'openstack'
|
6
|
+
|
7
|
+
module TestConnection
|
8
|
+
|
9
|
+
def get_test_connection
|
10
|
+
|
11
|
+
conn_response = {'x-server-management-url' => 'http://server-manage.example.com/path', 'x-auth-token' => 'dummy_token'}
|
12
|
+
conn_response.stubs(:code).returns('204')
|
13
|
+
#server = mock(:use_ssl= => true, :verify_mode= => true, :start => true, :finish => true)
|
14
|
+
server = mock(:start => true, :finish => true)
|
15
|
+
server.stubs(:get => conn_response, :use_ssl= => true, :verify_mode= => true)
|
16
|
+
#server.stubs(:get).returns(conn_response)
|
17
|
+
Net::HTTP.stubs(:new).returns(server)
|
18
|
+
OpenStack::Connection.create(:username => "test_account", :api_key => "AABBCCDD11", :auth_url => "http://a.b.c")
|
19
|
+
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: openstack
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.6
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,8 +10,40 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2012-09-
|
13
|
+
date: 2012-09-13 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: mocha
|
17
|
+
requirement: !ruby/object:Gem::Requirement
|
18
|
+
none: false
|
19
|
+
requirements:
|
20
|
+
- - ! '>='
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '0'
|
23
|
+
type: :development
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
none: false
|
27
|
+
requirements:
|
28
|
+
- - ! '>='
|
29
|
+
- !ruby/object:Gem::Version
|
30
|
+
version: '0'
|
31
|
+
- !ruby/object:Gem::Dependency
|
32
|
+
name: test-unit
|
33
|
+
requirement: !ruby/object:Gem::Requirement
|
34
|
+
none: false
|
35
|
+
requirements:
|
36
|
+
- - ! '>='
|
37
|
+
- !ruby/object:Gem::Version
|
38
|
+
version: '0'
|
39
|
+
type: :development
|
40
|
+
prerelease: false
|
41
|
+
version_requirements: !ruby/object:Gem::Requirement
|
42
|
+
none: false
|
43
|
+
requirements:
|
44
|
+
- - ! '>='
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '0'
|
15
47
|
- !ruby/object:Gem::Dependency
|
16
48
|
name: json
|
17
49
|
requirement: !ruby/object:Gem::Requirement
|
@@ -52,6 +84,12 @@ files:
|
|
52
84
|
- lib/openstack/swift/connection.rb
|
53
85
|
- lib/openstack/swift/container.rb
|
54
86
|
- lib/openstack/swift/storage_object.rb
|
87
|
+
- test/authentication_test.rb
|
88
|
+
- test/connection_test.rb
|
89
|
+
- test/exception_test.rb
|
90
|
+
- test/metadata_test.rb
|
91
|
+
- test/servers_test.rb
|
92
|
+
- test/test_helper.rb
|
55
93
|
homepage: https://github.com/ruby-openstack/ruby-openstack
|
56
94
|
licenses: []
|
57
95
|
post_install_message:
|