1*eeba3d73SThomas Huth#!/usr/bin/env python3
2*eeba3d73SThomas Huth#
3*eeba3d73SThomas Huth# Test for the hmp command "info usernet"
4*eeba3d73SThomas Huth#
5*eeba3d73SThomas Huth# Copyright (c) 2021 Red Hat, Inc.
6*eeba3d73SThomas Huth#
7*eeba3d73SThomas Huth# Author:
8*eeba3d73SThomas Huth#  Cleber Rosa <crosa@redhat.com>
9*eeba3d73SThomas Huth#
10*eeba3d73SThomas Huth# This work is licensed under the terms of the GNU GPL, version 2 or
11*eeba3d73SThomas Huth# later.  See the COPYING file in the top-level directory.
12*eeba3d73SThomas Huth
13*eeba3d73SThomas Huthfrom qemu_test import QemuSystemTest
14*eeba3d73SThomas Huth
15*eeba3d73SThomas Huthfrom qemu.utils import get_info_usernet_hostfwd_port
16*eeba3d73SThomas Huth
17*eeba3d73SThomas Huth
18*eeba3d73SThomas Huthclass InfoUsernet(QemuSystemTest):
19*eeba3d73SThomas Huth
20*eeba3d73SThomas Huth    def test_hostfwd(self):
21*eeba3d73SThomas Huth        self.require_netdev('user')
22*eeba3d73SThomas Huth        self.set_machine('none')
23*eeba3d73SThomas Huth        self.vm.add_args('-netdev', 'user,id=vnet,hostfwd=:127.0.0.1:0-:22')
24*eeba3d73SThomas Huth        self.vm.launch()
25*eeba3d73SThomas Huth        res = self.vm.cmd('human-monitor-command',
26*eeba3d73SThomas Huth                          command_line='info usernet')
27*eeba3d73SThomas Huth        port = get_info_usernet_hostfwd_port(res)
28*eeba3d73SThomas Huth        self.assertIsNotNone(port,
29*eeba3d73SThomas Huth                             ('"info usernet" output content does not seem to '
30*eeba3d73SThomas Huth                              'contain the redirected port'))
31*eeba3d73SThomas Huth        self.assertGreater(port, 0,
32*eeba3d73SThomas Huth                           ('Found a redirected port that is not greater than'
33*eeba3d73SThomas Huth                            ' zero'))
34*eeba3d73SThomas Huth
35*eeba3d73SThomas Huthif __name__ == '__main__':
36*eeba3d73SThomas Huth    QemuSystemTest.main()
37