Example #1
0
    def test_acquire_port(self):
        start, stop = 15, 20
        self.flags(port_range='%d:%d' % (start, stop), group='serial_console')

        for port in six.moves.range(start, stop):
            self.assertEqual(port, serial.acquire_port('127.0.0.1'))

        for port in six.moves.range(start, stop):
            self.assertEqual(port, serial.acquire_port('127.0.0.2'))

        self.assertTrue(10, len(serial.ALLOCATED_PORTS))
Example #2
0
    def test_acquire_port(self):
        start, stop = 15, 20
        self.flags(
            port_range='%d:%d' % (start, stop),
            group='serial_console')

        for port in six.moves.range(start, stop):
            self.assertEqual(port, serial.acquire_port('127.0.0.1'))

        for port in six.moves.range(start, stop):
            self.assertEqual(port, serial.acquire_port('127.0.0.2'))

        self.assertEqual(10, len(serial.ALLOCATED_PORTS))
Example #3
0
    def test_acquire_port_in_use(self, fake_verify_port):
        def port_10000_already_used(host, port):
            if port == 10000 and host == '127.0.0.1':
                raise exception.SocketPortInUseException(
                    port=port, host=host, error="already in use")

        fake_verify_port.side_effect = port_10000_already_used

        self.assertEqual(10001, serial.acquire_port('127.0.0.1'))
        self.assertEqual(10000, serial.acquire_port('127.0.0.2'))

        self.assertNotIn(('127.0.0.1', 10000), serial.ALLOCATED_PORTS)
        self.assertIn(('127.0.0.1', 10001), serial.ALLOCATED_PORTS)
        self.assertIn(('127.0.0.2', 10000), serial.ALLOCATED_PORTS)
Example #4
0
    def test_acquire_port_in_use(self, fake_verify_port):
        def port_10000_already_used(host, port):
            if port == 10000 and host == '127.0.0.1':
                raise exception.SocketPortInUseException(
                    port=port,
                    host=host,
                    error="already in use")
        fake_verify_port.side_effect = port_10000_already_used

        self.assertEqual(10001, serial.acquire_port('127.0.0.1'))
        self.assertEqual(10000, serial.acquire_port('127.0.0.2'))

        self.assertNotIn(('127.0.0.1', 10000), serial.ALLOCATED_PORTS)
        self.assertIn(('127.0.0.1', 10001), serial.ALLOCATED_PORTS)
        self.assertIn(('127.0.0.2', 10000), serial.ALLOCATED_PORTS)
Example #5
0
    def _setup_serial_proxy_handler(self):
        self._listen_host = (CONF.serial_console.proxyclient_address)
        self._listen_port = serial_console.acquire_port(self._listen_host)

        LOG.info(
            _LI('Initializing serial proxy on '
                '%(addr)s:%(port)s, handling connections '
                'to instance %(instance_name)s.'), {
                    'addr': self._listen_host,
                    'port': self._listen_port,
                    'instance_name': self._instance_name
                })

        # Use this event in order to manage
        # pending queue operations.
        self._client_connected = threading.Event()
        self._input_queue = ioutils.IOQueue(
            client_connected=self._client_connected)
        self._output_queue = ioutils.IOQueue(
            client_connected=self._client_connected)

        self._serial_proxy = serialproxy.SerialProxy(
            self._instance_name, self._listen_host, self._listen_port,
            self._input_queue, self._output_queue, self._client_connected)

        self._workers.append(self._serial_proxy)
Example #6
0
    def _setup_serial_proxy_handler(self):
        self._listen_host = (
            CONF.serial_console.proxyclient_address)
        self._listen_port = serial_console.acquire_port(
            self._listen_host)

        LOG.info(_LI('Initializing serial proxy on '
                     '%(addr)s:%(port)s, handling connections '
                     'to instance %(instance_name)s.'),
                     {'addr': self._listen_host,
                      'port': self._listen_port,
                      'instance_name': self._instance_name})

        # Use this event in order to manage
        # pending queue operations.
        self._client_connected = threading.Event()
        self._input_queue = ioutils.IOQueue(
            client_connected=self._client_connected)
        self._output_queue = ioutils.IOQueue(
            client_connected=self._client_connected)

        self._serial_proxy = serialproxy.SerialProxy(
            self._instance_name, self._listen_host,
            self._listen_port, self._input_queue,
            self._output_queue, self._client_connected)

        self._workers.append(self._serial_proxy)