Merge "Adding timeout parameters to init-keystone"

This commit is contained in:
Jenkins 2014-09-02 12:58:30 +00:00 committed by Gerrit Code Review
commit ab6136bb91
4 changed files with 26 additions and 12 deletions

View File

@ -17,8 +17,9 @@ registers the initial identity endpoint.
.. note::
init-keystone will wait up to 10 minutes for a Keystone service to be
running on the specified host.
init-keystone will wait for a user-specified amount of time for a Keystone
service to be running on the specified host. The default is a 10 minute
wait time with 10 seconds between poll attempts.
For example::

View File

@ -28,8 +28,9 @@ def parse_args():
initial identity endpoint, after which Keystone may be used with normal
authentication.
This command will wait up to 10 minutes for a Keystone service to be
running on the specified host.
This command will wait for a user-specified amount of time for a Keystone
service to be running on the specified host. The default is a 10 minute
wait time with 10 seconds between poll attempts.
""")
parser = argparse.ArgumentParser(
formatter_class=argparse.RawDescriptionHelpFormatter,
@ -56,6 +57,11 @@ def parse_args():
"the default is not suitable")
parser.add_argument('-u', '--user', dest='user', required=True,
help="user to connect to the Keystone node via ssh")
parser.add_argument('--timeout', dest='timeout', default=600, type=int,
help="Total seconds to wait for keystone to be ready")
parser.add_argument('--poll-interval', dest='pollinterval',
default=10, type=int,
help="Seconds to wait between keystone checks")
return parser.parse_args()
@ -63,4 +69,4 @@ def main():
args = parse_args()
initialize(args.host, args.admin_token, args.admin_email,
args.admin_password, args.region, args.ssl, args.public,
args.user)
args.user, args.timeout, args.pollinterval)

View File

@ -31,4 +31,4 @@ class InitKeystoneTest(base.TestCase):
init_keystone.main()
initialize_mock.assert_called_once_with(
'hostname', 'token', 'admin@example.com', 'password', 'regionOne',
None, None, 'root')
None, None, 'root', 600, 10)

View File

@ -103,7 +103,8 @@ SERVICES = {
def initialize(host, admin_token, admin_email, admin_password,
region='regionOne', ssl=None, public=None, user='root'):
region='regionOne', ssl=None, public=None, user='root',
timeout=600, poll_interval=10):
"""Perform post-heat initialization of Keystone.
:param host: ip/hostname of node where Keystone is running
@ -115,11 +116,13 @@ def initialize(host, admin_token, admin_email, admin_password,
:param public: ip/hostname to use as the public endpoint, if the default
is not suitable
:param user: user to use to connect to the node where Keystone is running
:param timeout: Total seconds to wait for keystone to be running
:param poll_interval: Seconds to wait between keystone poll attempts
"""
keystone = _create_admin_client(host, admin_token)
_create_roles(keystone)
_create_roles(keystone, timeout, poll_interval)
_create_tenants(keystone)
_create_admin_user(keystone, admin_email, admin_password)
_create_keystone_endpoint(keystone, host, region, ssl, public)
@ -372,19 +375,23 @@ def _create_admin_client(host, admin_token):
return ksclient.Client(endpoint=admin_url, token=admin_token)
def _create_roles(keystone):
def _create_roles(keystone, timeout=600, poll_interval=10):
"""Create initial roles in Keystone.
:param keystone: keystone v2 client
:param timeout: total seconds to wait for keystone
:param poll_interval: seconds to wait between keystone checks
"""
for count in range(60):
wait_cycles = int(timeout / poll_interval)
for count in range(wait_cycles):
try:
LOG.debug('Creating admin role, try %d.' % count)
_create_role(keystone, 'admin')
break
except (exceptions.ConnectionRefused, exceptions.ServiceUnavailable):
LOG.debug('Unable to create, sleeping for 10 seconds.')
time.sleep(10)
LOG.debug('Unable to create, sleeping for %d seconds.'
% poll_interval)
time.sleep(poll_interval)
_create_role(keystone, 'Member')