Exemple #1
0
 def start(self):
     log.info("Starting Pytest Event Forwarder Engine(forwarding to %s)",
              self.returner_address)
     self.io_loop = ioloop.IOLoop()
     self.io_loop.make_current()
     self.io_loop.add_callback(self._start)
     atexit.register(self.stop)
     self.io_loop.start()
Exemple #2
0
def wait():
    """Wait for a watched file to change, then restart the process.

    Intended to be used at the end of scripts like unit test runners,
    to run the tests again after any source file changes (but see also
    the command-line interface in `main`)
    """
    io_loop = ioloop.IOLoop()
    start(io_loop)
    io_loop.start()
Exemple #3
0
def test_message_client_cleanup_on_close(client_socket, temp_salt_master):
    """
    test message client cleanup on close
    """
    orig_loop = ioloop.IOLoop()
    orig_loop.make_current()

    opts = temp_salt_master.config.copy()
    client = salt.transport.tcp.SaltMessageClient(opts,
                                                  client_socket.listen_on,
                                                  client_socket.port)

    # Mock the io_loop's stop method so we know when it has been called.
    orig_loop.real_stop = orig_loop.stop
    orig_loop.stop_called = False

    def stop(*args, **kwargs):
        orig_loop.stop_called = True
        orig_loop.real_stop()

    orig_loop.stop = stop
    try:
        assert client.io_loop == orig_loop
        client.io_loop.run_sync(client.connect)

        # Ensure we are testing the _read_until_future and io_loop teardown
        assert client._stream is not None
        assert client._read_until_future is not None
        assert orig_loop.stop_called is True

        # The run_sync call will set stop_called, reset it
        orig_loop.stop_called = False
        client.close()

        # Stop should be called again, client's io_loop should be None
        assert orig_loop.stop_called is True
        assert client.io_loop is None
    finally:
        orig_loop.stop = orig_loop.real_stop
        del orig_loop.real_stop
        del orig_loop.stop_called
        orig_loop.clear_current()
        orig_loop.close(all_fds=True)
Exemple #4
0
def call_ami_action(action, timeout=5):
    """
    Send AMI action and wait for reply.
    CLI Example: salt-call asterisk.call_ami_action {"Action": "Ping"}
    """
    # Fire an action event to asterisk_ami engine and wait for a reply event.
    async  def fire():
        # Wait for waiter to start waiting :-))
        await waiter.wait()
        await sleep(0.01)
        # Ok we started a reply channel listening, fire!
        __salt__['event.fire'](action, 'ami_action')
    # Start a reply event listener before sending.
    async def wait_reply():
        event = salt.utils.event.MinionEvent(__opts__)
        # Generate a random reply channel
        reply_channel = action['reply_channel'] = uuid.uuid4().hex
        started = time.time()
        # Now send s signal to fire!
        waiter.set()
        # Wait until timeout.
        while started + timeout > time.time():
            ret = event.get_event(
                no_block=True, full=True,
                tag='ami_reply/{}'.format(reply_channel))
            if ret is None:
                await sleep(0.01)
            else:
                # Get a reply from the other side and return it.
                return ret['data']['Reply']
    # Synchronize callbacks not to miss a reply if it comes too quick.
    waiter = locks.Event()
    loop = ioloop.IOLoop(make_current=False)
    loop.spawn_callback(fire)
    res = loop.run_sync(wait_reply)
    return res
Exemple #5
0
 def start(self):
     self.io_loop = ioloop.IOLoop()
     self.io_loop.make_current()
     self.io_loop.add_callback(self._start)
     self.io_loop.start()