parameters: (ctx, config)
docstring: Wait for a service to be fully started
  
        tasks:
          - cephadm.wait_for_service:
              service: rgw.foo
              timeout: 60    # defaults to 300
docstring_summary: Wait for a service to be fully started
docstring_tokens: Wait for a service to be fully started
function: def wait_for_service(ctx, config):
      """
      Wait for a service to be fully started
  
        tasks:
          - cephadm.wait_for_service:
              service: rgw.foo
              timeout: 60    # defaults to 300
  
      """
      cluster_name = config.get('cluster', 'ceph')
      timeout = config.get('timeout', 300)
      service = config.get('service')
      assert service
  
      log.info(
          f'Waiting for {cluster_name} service {service} to start (timeout {timeout})...'
      )
      with contextutil.safe_while(sleep=1, tries=timeout) as proceed:
          while proceed():
              r = _shell(
                  ctx=ctx,
                  cluster_name=cluster_name,
                  remote=ctx.ceph[cluster_name].bootstrap_remote,
                  args=[
                      'ceph', 'orch', 'ls', '-f', 'json',
                  ],
                  stdout=StringIO(),
              )
              j = json.loads(r.stdout.getvalue())
              svc = None
              for s in j:
                  if s['service_name'] == service:
                      svc = s
                      break
              if svc:
                  log.info(
                      f"{service} has {s['status']['running']}/{s['status']['size']}"
                  )
                  if s['status']['running'] == s['status']['size']:
                      break
function_tokens: def wait_for_service ( ctx , config ) : cluster_name = config . get ( 'cluster' , 'ceph' ) timeout = config . get ( 'timeout' , 300 ) service = config . get ( 'service' ) assert service log . info ( f'Waiting for {cluster_name} service {service} to start (timeout {timeout})...' ) with contextutil . safe_while ( sleep = 1 , tries = timeout ) as proceed : while proceed ( ) : r = _shell ( ctx = ctx , cluster_name = cluster_name , remote = ctx . ceph [ cluster_name ] . bootstrap_remote , args = [ 'ceph' , 'orch' , 'ls' , '-f' , 'json' , ] , stdout = StringIO ( ) , ) j = json . loads ( r . stdout . getvalue ( ) ) svc = None for s in j : if s [ 'service_name' ] == service : svc = s break if svc : log . info ( f"{service} has {s['status']['running']}/{s['status']['size']}" ) if s [ 'status' ] [ 'running' ] == s [ 'status' ] [ 'size' ] : break