mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
Merge pull request #1355 from drbrain/openstack_mock_server_user_id
Improve OpenStack server creation mocks
This commit is contained in:
commit
5cad89ddb6
4 changed files with 56 additions and 7 deletions
|
@ -55,10 +55,28 @@ module Fog
|
|||
response = Excon::Response.new
|
||||
response.status = 202
|
||||
|
||||
data = {
|
||||
server_id = Fog::Mock.random_numbers(6).to_s
|
||||
identity = Fog::Identity[:openstack]
|
||||
user = identity.users.find { |u|
|
||||
u.name == @openstack_username
|
||||
}
|
||||
|
||||
user_id = if user then
|
||||
user.id
|
||||
else
|
||||
identity.user.create(:name => @openstack_username,
|
||||
:password => 'password',
|
||||
:email =>
|
||||
"#{@openstack_username}@example",
|
||||
:tenant_id => @openstack_tenant,
|
||||
:enabled => true).id
|
||||
end
|
||||
|
||||
|
||||
mock_data = {
|
||||
'addresses' => {},
|
||||
'flavor' => {"id" => flavor_ref, "links"=>[{"href"=>"http://nova1:8774/admin/flavors/1", "rel"=>"bookmark"}]},
|
||||
'id' => Fog::Mock.random_numbers(6).to_s,
|
||||
'id' => server_id,
|
||||
'image' => {"id" => image_ref, "links"=>[{"href"=>"http://nova1:8774/admin/images/#{image_ref}", "rel"=>"bookmark"}]},
|
||||
'links' => [{"href"=>"http://nova1:8774/v1.1/admin/servers/5", "rel"=>"self"}, {"href"=>"http://nova1:8774/admin/servers/5", "rel"=>"bookmark"}],
|
||||
'hostId' => "123456789ABCDEF01234567890ABCDEF",
|
||||
|
@ -70,11 +88,18 @@ module Fog
|
|||
'status' => 'BUILD',
|
||||
'created' => '2012-09-27T00:04:18Z',
|
||||
'updated' => '2012-09-27T00:04:27Z',
|
||||
'user_id' => @openstack_username,
|
||||
}
|
||||
|
||||
self.data[:last_modified][:servers][data['id']] = Time.now
|
||||
self.data[:servers][data['id']] = data
|
||||
response.body = { 'server' => data.merge({'adminPass' => 'password'}) }
|
||||
response_data = {
|
||||
'adminPass' => 'password',
|
||||
'id' => server_id,
|
||||
'links' => mock_data['links'],
|
||||
}
|
||||
|
||||
self.data[:last_modified][:servers][server_id] = Time.now
|
||||
self.data[:servers][server_id] = mock_data
|
||||
response.body = { 'server' => response_data }
|
||||
response
|
||||
end
|
||||
|
||||
|
|
|
@ -15,7 +15,15 @@ module Fog
|
|||
|
||||
class Mock
|
||||
|
||||
def get_user_by_name(name)
|
||||
response = Excon::Response.new
|
||||
response.status = 200
|
||||
|
||||
response.body = {
|
||||
'users' => self.data[:users].values
|
||||
}
|
||||
response
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
|
|
@ -19,7 +19,15 @@ Shindo.tests('Fog::Compute[:openstack] | server requests', ['openstack']) do
|
|||
'accessIPv6' => Fog::Nullable::String,
|
||||
'links' => Array,
|
||||
'created' => String,
|
||||
'updated' => String
|
||||
'updated' => String,
|
||||
'user_id' => String,
|
||||
}
|
||||
|
||||
@create_format = {
|
||||
'adminPass' => String,
|
||||
'id' => String,
|
||||
'links' => Array,
|
||||
'security_groups' => Fog::Nullable::Array,
|
||||
}
|
||||
|
||||
@image_format = {
|
||||
|
@ -42,7 +50,7 @@ Shindo.tests('Fog::Compute[:openstack] | server requests', ['openstack']) do
|
|||
@snapshot_id = nil
|
||||
@flavor_id = get_flavor_ref
|
||||
|
||||
tests('#create_server("test", #{@image_id} , 19)').formats(@server_format.merge('adminPass' => String), false) do
|
||||
tests('#create_server("test", #{@image_id} , 19)').formats(@create_format, false) do
|
||||
data = Fog::Compute[:openstack].create_server("test", @image_id, @flavor_id).body['server']
|
||||
@server_id = data['id']
|
||||
data
|
||||
|
|
|
@ -17,6 +17,14 @@ Shindo.tests('Fog::Identity[:openstack] | user requests', ['openstack']) do
|
|||
Fog::Identity[:openstack].list_users.body
|
||||
end
|
||||
|
||||
tests('#get_user_by_id').formats(@user_format) do
|
||||
Fog::Identity[:openstack].get_user_by_id(@user['id']).body['user']
|
||||
end
|
||||
|
||||
tests('#get_user_by_name').formats({'users' => [@user_format]}) do
|
||||
Fog::Identity[:openstack].get_user_by_name(@user['name']).body
|
||||
end
|
||||
|
||||
tests("#update_user(#{@user['id']}, :name => 'fogupdateduser')").succeeds do
|
||||
Fog::Identity[:openstack].update_user(@user['id'], :name => 'fogupdateduser', :email => 'fog@test.com')
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue