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