@mock.patch('nova.console.serial._verify_port')
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)
@mock.patch('nova.console.serial._verify_port')
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)