openstack 1.1.2 → 2.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG +58 -0
- data/README.md +19 -0
- data/VERSION +1 -0
- data/lib/openstack.rb +5 -19
- data/lib/openstack/compute/connection.rb +74 -31
- data/lib/openstack/compute/flavor.rb +18 -30
- data/lib/openstack/compute/server.rb +98 -0
- data/lib/openstack/connection.rb +45 -8
- data/lib/openstack/core_ext/to_query.rb +84 -0
- data/lib/openstack/identity/connection.rb +69 -0
- data/lib/openstack/identity/tenant.rb +17 -0
- data/lib/openstack/identity/user.rb +19 -0
- data/lib/openstack/network/network.rb +21 -22
- data/lib/openstack/network/router.rb +3 -5
- data/lib/openstack/swift/connection.rb +10 -4
- data/lib/openstack/volume/connection.rb +25 -0
- data/test/runner.rb +10 -0
- data/test/test_helper.rb +6 -9
- metadata +33 -35
- data/README.rdoc +0 -462
- data/lib/openstack/version.rb +0 -3
- data/test/authentication_test.rb +0 -120
- data/test/connection_test.rb +0 -39
- data/test/exception_test.rb +0 -49
- data/test/metadata_test.rb +0 -210
- data/test/servers_test.rb +0 -210
data/lib/openstack/version.rb
DELETED
data/test/authentication_test.rb
DELETED
@@ -1,120 +0,0 @@
|
|
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_uri
|
37
|
-
server = get_test_auth_server
|
38
|
-
Net::HTTP.stubs(:new).returns(server)
|
39
|
-
server.stubs(:started?).returns(true)
|
40
|
-
connection = v2_auth_connection_stub
|
41
|
-
result = OpenStack::Authentication.init(connection)
|
42
|
-
assert_equal("compute.south.host", result.uri.host)
|
43
|
-
end
|
44
|
-
|
45
|
-
private
|
46
|
-
|
47
|
-
def v2_auth_connection_stub
|
48
|
-
stub(:authuser => 'good_user', :auth_method => "password",:authtenant => {:type=>"tenantName", :value=>'good_tenant'} , :regions_list => {"North"=> [{:service=>"compute", :versionId=>nil}, {:service=>"nova", :versionId=>nil}], "South"=>[{:service=>"compute", :versionId=>nil}, {:service=>"nova", :versionId=>nil}] }, :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")
|
49
|
-
end
|
50
|
-
|
51
|
-
def get_test_auth_server
|
52
|
-
json_response = %{{
|
53
|
-
"access":{
|
54
|
-
"token":{
|
55
|
-
"id":"asdasdasd-adsasdads-asdasdasd-adsadsasd",
|
56
|
-
"expires":"2010-11-01T03:32:15-05:00"
|
57
|
-
},
|
58
|
-
"user":{
|
59
|
-
"id":"123",
|
60
|
-
"name":"testName",
|
61
|
-
"roles":[{
|
62
|
-
"id":"234",
|
63
|
-
"name":"compute:admin"
|
64
|
-
},
|
65
|
-
{
|
66
|
-
"id":"235",
|
67
|
-
"name":"object-store:admin",
|
68
|
-
"tenantId":"1"
|
69
|
-
}
|
70
|
-
],
|
71
|
-
"roles_links":[]
|
72
|
-
},
|
73
|
-
"serviceCatalog":[{
|
74
|
-
"name":"cloudServers",
|
75
|
-
"type":"compute",
|
76
|
-
"endpoints":[{
|
77
|
-
"publicURL":"https://compute.north.host/v1.1",
|
78
|
-
"region":"North"
|
79
|
-
},
|
80
|
-
{
|
81
|
-
"publicURL":"https://compute.south.host/v1.1",
|
82
|
-
"region":"South"
|
83
|
-
}
|
84
|
-
],
|
85
|
-
"endpoints_links":[]
|
86
|
-
},
|
87
|
-
{
|
88
|
-
"name":"cloudCompute",
|
89
|
-
"type":"nova",
|
90
|
-
"endpoints":[{
|
91
|
-
"publicURL":"https://nova.north.host/v1.1",
|
92
|
-
"region":"North"
|
93
|
-
},
|
94
|
-
{
|
95
|
-
"publicURL":"https://nova.south.host/v1.1",
|
96
|
-
"region":"South"
|
97
|
-
}
|
98
|
-
],
|
99
|
-
"endpoints_links":[{
|
100
|
-
"rel":"next",
|
101
|
-
"href":"https://identity.north.host/v2.0/endpoints?marker=2"
|
102
|
-
}
|
103
|
-
]
|
104
|
-
}
|
105
|
-
],
|
106
|
-
"serviceCatalog_links":[{
|
107
|
-
"rel":"next",
|
108
|
-
"href":"https://identity.host/v2.0/endpoints?session=2hfh8Ar&marker=2"
|
109
|
-
}
|
110
|
-
]
|
111
|
-
}
|
112
|
-
}}
|
113
|
-
|
114
|
-
response = {'x-server-management-url' => 'http://server-manage.example.com/path', 'x-auth-token' => 'dummy_token'}
|
115
|
-
response.stubs(:code => "200", :body => json_response)
|
116
|
-
server = mock(:use_ssl= => true, :verify_mode= => true, :start => true, :finish => true)
|
117
|
-
server.stubs(:post).returns(response)
|
118
|
-
return server
|
119
|
-
end
|
120
|
-
end
|
data/test/connection_test.rb
DELETED
@@ -1,39 +0,0 @@
|
|
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
|
data/test/exception_test.rb
DELETED
@@ -1,49 +0,0 @@
|
|
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
|
data/test/metadata_test.rb
DELETED
@@ -1,210 +0,0 @@
|
|
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
|
data/test/servers_test.rb
DELETED
@@ -1,210 +0,0 @@
|
|
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
|