Ejemplo n.º 1
0
    def is_stable(self):
        """Does the process continue to run with the same pid?

        (5 times in a row, with a gap of 0.1s between each check)
        """
        pid = yield self.get_pid()
        if pid is None:
            returnValue(False)
        for _ in range(4):
            yield sleep(0.1)
            if pid != (yield self.get_pid()):
                returnValue(False)
        returnValue(True)
Ejemplo n.º 2
0
    def _internal_connect(self, share):
        """Attempt connection to one of the ZK nodes."""
        candidates = yield self._provider.get_zookeeper_machines()
        assigned = [machine for machine in candidates if machine.dns_name]
        if not assigned:
            yield sleep(1)  # Momentarily backoff
            raise EnvironmentPending("No machines have assigned addresses")

        chosen = random.choice(assigned)
        log.debug("Connecting to environment using %s...", chosen.dns_name)
        try:
            client = yield SSHClient().connect(
                chosen.dns_name + ":2181", timeout=30, share=share)
        except (NoConnection, ConnectionTimeoutException) as e:
            raise EnvironmentPending(
                "Cannot connect to environment using %s "
                "(perhaps still initializing): %s" % (
                    chosen.dns_name, str(e)))

        yield self.wait_for_initialization(client)
        returnValue(client)
Ejemplo n.º 3
0
 def test_sleep(self):
     """Directly test deferred sleep."""
     start = time.time()
     yield sleep(0.1)
     self.assertGreaterEqual(time.time() - start, 0.1)