def setup_package(): """ Setup method at the tests module level (init) :return: """ # Check all services (including midolman) are online api_host = service.get_container_by_hostname('cluster1') api_host.wait_for_status('up') for type, hosts in service.get_all_containers().items(): for host in hosts: LOG.debug("Checking liveness of %s" % host.get_hostname()) host.wait_for_status('up', timeout=conf.service_status_timeout()) # Wait until bindings do not fail, at that point, mdts is ready for test max_attempts = 10 for current_attempts in xrange(max_attempts): topology = build_simple_topology() try: destroy_simple_topology(topology) LOG.debug("MDTS ready to run tests.") return except: destroy_simple_topology(topology) current_attempts += 1 LOG.debug("MDTS failed to bind port... check again. Attempt: %d" % current_attempts) raise RuntimeError("MDTS was unable to bind a single port... Exiting.")
def manage_service(self, operation="start", wait=False, timeout=conf.service_status_timeout(), wait_time=5, raise_error=True): status = "up" if "start" in operation else "down" self.exec_command('service %s %s' % (self.get_service_name(), operation)) if wait: return self.wait_for_status(status=status, timeout=timeout, wait_time=wait_time, raise_error=raise_error) return True
def __init__(self, container_id): self.container_id = container_id self.info = cli.inspect_container(container_id) timeout = conf.service_status_timeout() wait_time = 1 # Check first that the container is running while not self.is_container_running(): if timeout == 0: raise RuntimeError( "Container %s: timeout waiting to be running" % (self.get_name())) timeout -= wait_time time.sleep(wait_time)
def __init__(self, container_id): self.container_id = container_id self.info = cli.inspect_container(container_id) timeout = conf.service_status_timeout() wait_time = 1 # Check first that the container is running while not self.is_container_running(): if timeout == 0: raise RuntimeError("Container %s: timeout waiting to be running" % ( self.get_name() )) timeout -= wait_time time.sleep(wait_time)
def wait_for_status(self, status, timeout=conf.service_status_timeout(), wait_time=5, raise_error=True): init_timeout = timeout while self.get_service_status() != status: if init_timeout == 0: if raise_error: raise RuntimeError("Service %s: timeout waiting to be %s" % ( self.get_hostname(), status)) else: LOG.debug("Service %s: timeout waiting to be %s" % ( self.get_hostname(), status)) return False init_timeout -= wait_time time.sleep(wait_time) LOG.debug("Service %s: status is now %s" % (self.get_name(), status)) return True