Beispiel #1
0
        def poll_rebooting_machine(count=1):
            max_tries = calculate_max_tries_for_interval_and_delay(interval=self.ssh_poll_max_seconds,
                                                                   delay=yadtshell.constants.SSH_POLL_DELAY)
            logger.info("%s: polling for ssh connect, try %i of %i" %
                        (self.uri, count, max_tries))
            poll_command = self.remote_call('uptime', '%s_poll' % self.hostname)
            poll_protocol = YadtProcessProtocol(self, poll_command, out_log_level=logging.INFO)
            poll_protocol.ssh_poll_count = count
            if (count * yadtshell.constants.SSH_POLL_DELAY) < self.ssh_poll_max_seconds:
                poll_protocol.deferred.addErrback(
                    lambda x: task.deferLater(reactor,
                                              yadtshell.constants.SSH_POLL_DELAY,
                                              poll_rebooting_machine,
                                              count + 1)
                )
            cmdline = shlex.split(poll_protocol.cmd)
            reactor.spawnProcess(poll_protocol, cmdline[0], cmdline, None)

            return poll_protocol.deferred
        def poll_rebooting_machine(count=1):
            max_tries = calculate_max_tries_for_interval_and_delay(
                interval=self.ssh_poll_max_seconds,
                delay=yadtshell.constants.SSH_POLL_DELAY)
            logger.info("%s: polling for ssh connect, try %i of %i" %
                        (self.uri, count, max_tries))
            poll_command = self.remote_call('uptime',
                                            '%s_poll' % self.hostname)
            poll_protocol = YadtProcessProtocol(self,
                                                poll_command,
                                                out_log_level=logging.INFO)
            poll_protocol.ssh_poll_count = count
            if (count * yadtshell.constants.SSH_POLL_DELAY
                ) < self.ssh_poll_max_seconds:
                poll_protocol.deferred.addErrback(lambda x: task.deferLater(
                    reactor, yadtshell.constants.SSH_POLL_DELAY,
                    poll_rebooting_machine, count + 1))
            cmdline = shlex.split(poll_protocol.cmd)
            reactor.spawnProcess(poll_protocol, cmdline[0], cmdline, None)

            return poll_protocol.deferred
Beispiel #3
0
    def test_should_not_make_tries_when_interval_is_zero(self):
        max_tries = calculate_max_tries_for_interval_and_delay(0, 5)

        self.assertEqual(max_tries, 0)
Beispiel #4
0
    def test_should_at_least_make_one_try_when_delay_is_longer_than_interval(self):
        max_tries = calculate_max_tries_for_interval_and_delay(1, 5)

        self.assertEqual(max_tries, 1)
Beispiel #5
0
    def test_should_increase_interval_when_remainder_found(self):
        max_tries = calculate_max_tries_for_interval_and_delay(10, 6)

        self.assertEqual(max_tries, 2)  # now waits 12 seconds instead of 10
Beispiel #6
0
    def test_should_return_divisor_when_division_without_remainder_is_possible(self):
        max_tries = calculate_max_tries_for_interval_and_delay(10, 5)

        self.assertEqual(max_tries, 2)