<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def ensure_connectable(self, nailgun):
 """Ensures that a nailgun client is connectable or raises NailgunError."""

    attempt_count = 1
    while 1:
      try:
        with closing(nailgun.try_connect()) as sock:
          logger.debug('Verified new ng server is connectable at {}'.format(sock.getpeername()))
          return
      except nailgun.NailgunConnectionError:
        if attempt_count >= self._connect_attempts:
          logger.debug('Failed to connect to ng after {} attempts'.format(self._connect_attempts))
          raise     # Re-raise the NailgunConnectionError which provides more context to the user.

      attempt_count += 1
      time.sleep(self.WAIT_INTERVAL_SEC)