Example #1
0
    def patched_until(self, timeout, deltas):
        iterator = until_timeout(timeout)

        def now_iter():
            for d in deltas:
                yield iterator.start + d
            assert False
        now_iter_i = now_iter()
        with patch.object(iterator, 'now', lambda: next(now_iter_i)):
            yield iterator
Example #2
0
    def patched_until(self, timeout, deltas):
        iterator = until_timeout(timeout)

        def now_iter():
            for d in deltas:
                yield iterator.start + d
            assert False

        now_iter_i = now_iter()
        with patch.object(iterator, 'now', lambda: next(now_iter_i)):
            yield iterator
Example #3
0
    def test_no_timeout(self):

        iterator = until_timeout(0)

        def now_iter():
            yield iterator.start
            yield iterator.start
            assert False

        with patch.object(iterator, 'now', lambda: next(now_iter())):
            for x in iterator:
                self.assertIs(None, x)
                break
Example #4
0
    def test_no_timeout(self):

        iterator = until_timeout(0)

        def now_iter():
            yield iterator.start
            yield iterator.start
            assert False

        with patch.object(iterator, 'now', lambda: next(now_iter())):
            for x in iterator:
                self.assertIs(None, x)
                break
Example #5
0
 def perform(cls, client, machine_id):
     """Add and remove many containers using the cli."""
     up_since = cls.get_up_since(client, machine_id)
     client.juju('run', ('--machine', machine_id, 'sudo', 'reboot'),
                 check=False)
     for x in until_timeout(300):
         try:
             reboot_up_since = cls.get_up_since(client, machine_id)
         except subprocess.CalledProcessError:
             pass
         else:
             if up_since != reboot_up_since:
                 break
     else:
         raise AssertionError('Unable to retrieve uptime.')
Example #6
0
def wait_for_port(host, port, closed=False, timeout=30):
    family = socket.AF_INET6 if is_ipv6_address(host) else socket.AF_INET
    for remaining in until_timeout(timeout):
        try:
            addrinfo = socket.getaddrinfo(host, port, family,
                                          socket.SOCK_STREAM)
        except socket.error as e:
            if e.errno not in (socket.EAI_NODATA, WSANO_DATA):
                raise
            if closed:
                return
            else:
                continue
        sockaddr = addrinfo[0][4]
        # Treat Azure messed-up address lookup as a closed port.
        if sockaddr[0] == '0.0.0.0':
            if closed:
                return
            else:
                continue
        conn = socket.socket(*addrinfo[0][:3])
        conn.settimeout(max(remaining or 0, 5))
        try:
            conn.connect(sockaddr)
        except socket.timeout:
            if closed:
                return
        except socket.error as e:
            if e.errno not in (errno.ECONNREFUSED, errno.ENETUNREACH,
                               errno.ETIMEDOUT, errno.EHOSTUNREACH):
                raise
            if closed:
                return
        except socket.gaierror as e:
            print_now(str(e))
        except Exception as e:
            print_now('Unexpected {!r}: {}'.format((type(e), e)))
            raise
        else:
            conn.close()
            if not closed:
                return
            sleep(1)
    raise PortTimeoutError('Timed out waiting for port.')
Example #7
0
 def test_start(self):
     now = datetime.now() + timedelta(days=1)
     now_iter = iter([now, now, now + timedelta(10)])
     with patch('utility.until_timeout.now',
                side_effect=lambda: next(now_iter)):
         self.assertEqual(list(until_timeout(10, now - timedelta(10))), [])
Example #8
0
 def test_start(self):
     now = datetime.now() + timedelta(days=1)
     now_iter = iter([now, now, now + timedelta(10)])
     with patch('utility.until_timeout.now',
                side_effect=lambda: next(now_iter)):
         self.assertEqual(list(until_timeout(10, now - timedelta(10))), [])