diff --git a/lib/fog/openstack/requests/compute/create_server.rb b/lib/fog/openstack/requests/compute/create_server.rb index 644bc3ca8..bd98b7d91 100644 --- a/lib/fog/openstack/requests/compute/create_server.rb +++ b/lib/fog/openstack/requests/compute/create_server.rb @@ -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 diff --git a/lib/fog/openstack/requests/identity/get_user_by_name.rb b/lib/fog/openstack/requests/identity/get_user_by_name.rb index 7cb4cb77f..ff220c229 100644 --- a/lib/fog/openstack/requests/identity/get_user_by_name.rb +++ b/lib/fog/openstack/requests/identity/get_user_by_name.rb @@ -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 diff --git a/tests/openstack/requests/compute/server_tests.rb b/tests/openstack/requests/compute/server_tests.rb index 4915a328e..11d1cd2d6 100644 --- a/tests/openstack/requests/compute/server_tests.rb +++ b/tests/openstack/requests/compute/server_tests.rb @@ -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 diff --git a/tests/openstack/requests/identity/user_tests.rb b/tests/openstack/requests/identity/user_tests.rb index cf1659298..6954aa707 100644 --- a/tests/openstack/requests/identity/user_tests.rb +++ b/tests/openstack/requests/identity/user_tests.rb @@ -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