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