Search code examples
bashubuntuopenstackkeystone

Kyestone client commands fails when called inside bash script


I am making a small bash script that tries to install keystone and create the initial admin user, tenant, etc.. I tried it with various keystone subcommands and they all fail saying:

Unable to establish connection to httx://10.0.2.100:35357/v2.0/tenants

I tried sourcing the env variables via a file, using export and in last resort even running the command with --os-token and --os-endpoint. Here is the latest version that I used inside the script:

keystone --debug --os-token secret --os-endpoint httx://10.0.2.100:35357/v2.0 tenant-list

The full message with debug is the following:

WARNING: Bypassing authentication using a token & endpoint (authentication credentials are being ignored).
DEBUG:keystoneclient.session:REQ: curl -i -X GET httx://10.0.2.100:35357/v2.0/tenants -H "User-Agent: python-keystoneclient" -H "X-Auth-Token: secret"
INFO:urllib3.connectionpool:Starting new HTTP connection (1): 10.0.2.100 Unable to establish connection to httx://10.0.2.100:35357/v2.0/tenants

But if I ran the same command directly on the bash shell I have no issues. Here is the debug output for it:

keystone --debug --os-token secret --os-endpoint httx://10.0.2.100:35357/v2.0 tenant-list WARNING: Bypassing authentication using a token & endpoint (authentication credentials are being ignored).
DEBUG:keystoneclient.session:REQ: curl -i -X GET httx://10.0.2.100:35357/v2.0/tenants -H "User-Agent: python-keystoneclient" -H "X-Auth-Token: secret" INFO:urllib3.connectionpool:Starting new HTTP connection (1): 10.0.2.100 DEBUG:urllib3.connectionpool:Setting read timeout to 600.0 DEBUG:urllib3.connectionpool:"GET /v2.0/tenants HTTP/1.1" 200 256 DEBUG:keystoneclient.session:RESP: [200] {'date': 'Tue, 17 Mar 2015 14:28:20 GMT', 'vary': 'X-Auth-Token', 'content-length': '256', 'content-type': 'application/json', 'x-distribution': 'Ubuntu'} RESP BODY: {"tenants_links": [], "tenants": [{"description": "Admin Tenant", "enabled": true, "id": "17008f66b9b54ca39654846e0b5e7af2", "name": "admin"}, {"description": "Service Tenant", "enabled": true, "id": "3a6823c10e454f4294aebdfec8b0c5dd", "name": "service"}]} +----------------------------------+---------+---------+ | id | name | enabled | +----------------------------------+---------+---------+ | 17008f66b9b54ca39654846e0b5e7af2 | admin | True | | 3a6823c10e454f4294aebdfec8b0c5dd | service | True | +----------------------------------+---------+---------+

So it seems that only when the script tries to run the command it fails... I cannot figure out why...Any help is appreciated.

PS. I had to replace http with httx in order to be able to post as I do not have enough reputation points.


Solution

  • A few hours later... I have finally figured out what is wrong. In my script I first restart the keystone service so that the changes to the "/etc/keystone/keystone.conf" file would be taken into account and I run the keystone commands right after. It seems that it does take some time for keystone to be up before answering my commands. I added "sleep 1" in between the two commands and now it works. Maybe it will be useful to somebody :-)