Hi Guy
Thanks for the detailed report! Definitely sounds like a fix that we'd
want to have in the code.
Hopefully, one of the devs that work more on the OpenStack providers can
add some thoughts on how best to get this included, or whether there are
some other aspects that need to be considered.
Regards
ap
On 2015-11-17 14:04, Guy Dumouchel wrote:
Hi,
jclouds version: v1.9.1
Cloud and API version: OpenStack Kilo 2015.1.0, Keystone API v2.0
Operating System version: Red Hat Enterprise Linux Server release 6.5
(Santiago)
Java version: v1.8.0.45
Problem description:
When I use jclouds client code "UserAdminApi.create()" method with the
"CreateUserOptions" object and supply a valid tenantId, the new user
gets created but the project ID is blank in OpenStack as seen in
Horizon:
USER OVERVIEW
INFORMATION
-------------------------
User Name testU1 ID d4a18274e9c94ba0b30a14e56d9f2ca0 Email
[email protected] Enabled True Project ID None
Code details:
1) setup a
"org.jclouds.openstack.keystone.v2_0.options.CreateUserOptions" object
and call the UserAdminApi.create() method as follows:
import org.jclouds.openstack.keystone.v2_0.extensions.UserAdminApi;
import org.jclouds.openstack.keystone.v2_0.options.CreateUserOptions;
...
private void createUser(Tenant aInTenant, String aInUserName) {
CreateUserOptions userOptions = CreateUserOptions.Builder
.tenant(aInTenant.getId())
.email("[email protected]")
.enabled(true);
User user = userAdminApi.create(aInUserName, "abc123",
userOptions);
CreateUserOptions userOptions = CreateUserOptions.Builder
.tenant(aInTenant.getId())
<------- aInTenant is a "
.email("[email protected]")
.enabled(true);
User user = userAdminApi.create(aInUserName, "abc123",
userOptions);
...
2) I see the following in the console:
[main] DEBUG o.j.rest.internal.InvokeHttpMethod - >> invoking
user:create
13:12:48.092 [main] DEBUG o.j.h.i.JavaUrlHttpCommandExecutorService -
Sending request 907780534: POST http://<ourIdentityURL>/v2.0/users
HTTP/1.1
13:12:48.092 [main] DEBUG jclouds.wire - >>
"{"user":{"name":"testU1","tenant":"2062a44f6ef64cbd89688a8a0feb2c18","password":"abc123","email":"[email protected]","enabled":true}}"
13:12:48.093 [main] DEBUG jclouds.headers - >> POST
http://<ourIdentityURL>/v2.0/users HTTP/1.1
13:12:48.093 [main] DEBUG jclouds.headers - >> Accept:
application/json
13:12:48.093 [main] DEBUG jclouds.headers - >> X-Auth-Token: <myToken>
13:12:48.093 [main] DEBUG jclouds.headers - >> Content-Type:
application/json
13:12:48.093 [main] DEBUG jclouds.headers - >> Content-Length: 137
Nov 17, 2015 1:12:48 PM com.SomeClassManager main
INFO: SomeClassManager User Management terminated successfully
13:12:48.180 [main] DEBUG o.j.h.i.JavaUrlHttpCommandExecutorService -
Receiving response 907780534: HTTP/1.1 200 OK
13:12:48.181 [main] DEBUG jclouds.headers - << HTTP/1.1 200 OK
13:12:48.181 [main] DEBUG jclouds.headers - << Connection: keep-alive
13:12:48.181 [main] DEBUG jclouds.headers - << X-Openstack-Request-Id:
req-0162d808-632a-408e-a5f6-5d073ee9d551
13:12:48.181 [main] DEBUG jclouds.headers - << Vary: X-Auth-Token
13:12:48.181 [main] DEBUG jclouds.headers - << Date: Tue, 17 Nov 2015
18:12:48 GMT
13:12:48.181 [main] DEBUG jclouds.headers - << Content-Type:
application/json
13:12:48.181 [main] DEBUG jclouds.headers - << Content-Length: 189
13:12:48.181 [main] DEBUG jclouds.wire - << "{"user": {"username":
"testU1", "name": "testU1", "enabled": true, "email":
"[email protected]", "tenant": "2062a44f6ef64cbd89688a8a0feb2c18",
"id": "d4a18274e9c94ba0b30a14e56d9f2ca0"}}"
In the above you see that the JSON data passed on the wire has
provided "tenant":"2062a44f6ef64cbd89688a8a0feb2c18" for the tenantId
portion but according to the OpenStack Identity Admin API v2 API
(http://developer.openstack.org/api-ref-identity-admin-v2.html), the
POST /v2.0/users API request parameters for the optional tenantId
should be called "tenantId" not "tenant".
3) To fix this I modified the
"org.jclouds.openstack.keystone.v2_0.options.CreateUserOptions.java"
file to change the class' private data member "private String tenant;"
to "private String tenantId;" as follows:
public class CreateUserOptions implements MapBinder{
@Inject
private BindToJsonPayload jsonBinder;
private String tenantId;
private String password;
private String email;
private boolean enabled;
And then run my test again and this time the new user has it ProjectId
set properly:
Debug traces seen with fix:
13:58:44.963 [main] DEBUG o.j.rest.internal.InvokeHttpMethod - >>
invoking user:create
13:58:44.963 [main] DEBUG o.j.h.i.JavaUrlHttpCommandExecutorService -
Sending request 2007647985: POST http://<ourIdentityUrl>/v2.0/users
HTTP/1.1
13:58:44.963 [main] DEBUG jclouds.wire - >>
"{"user":{"name":"testU1","tenantId":"3eafa84a23bf4c50b3683b53ab27045d","password":"abc123","email":"[email protected]","enabled":true}}"
13:58:44.963 [main] DEBUG jclouds.headers - >> POST
http://<ourIdentityUrl>/v2.0/users HTTP/1.1
13:58:44.963 [main] DEBUG jclouds.headers - >> Accept:
application/json
13:58:44.963 [main] DEBUG jclouds.headers - >> X-Auth-Token: <mytoken>
13:58:44.963 [main] DEBUG jclouds.headers - >> Content-Type:
application/json
13:58:44.963 [main] DEBUG jclouds.headers - >> Content-Length: 139
13:58:45.021 [main] DEBUG o.j.h.i.JavaUrlHttpCommandExecutorService -
Receiving response 2007647985: HTTP/1.1 200 OK
13:58:45.021 [main] DEBUG jclouds.headers - << HTTP/1.1 200 OK
13:58:45.021 [main] DEBUG jclouds.headers - << Connection: keep-alive
13:58:45.021 [main] DEBUG jclouds.headers - << X-Openstack-Request-Id:
req-42d5d719-4e99-44b3-81b1-ef9b9d4b5135
13:58:45.021 [main] DEBUG jclouds.headers - << Vary: X-Auth-Token
13:58:45.021 [main] DEBUG jclouds.headers - << Date: Tue, 17 Nov 2015
18:58:44 GMT
13:58:45.021 [main] DEBUG jclouds.headers - << Content-Type:
application/json
13:58:45.021 [main] DEBUG jclouds.headers - << Content-Length: 191
13:58:45.021 [main] DEBUG jclouds.wire - << "{"user": {"username":
"testU1", "name": "testU1", "id": "bf6831041ced4b16aa25103012690962",
"enabled": true, "email": "[email protected]", "tenantId":
"3eafa84a23bf4c50b3683b53ab27045d"}}"
New Horizon data for new user object:
USER OVERVIEW
INFORMATION
-------------------------
User Name testU1 ID bf6831041ced4b16aa25103012690962 Email
[email protected] Enabled True Project ID
3eafa84a23bf4c50b3683b53ab27045d
Thanks
Guy