1eeba3d73SThomas Huth#!/usr/bin/env python3 2eeba3d73SThomas Huth# 3976218cbSCleber Rosa# Test for the hmp command "info usernet" 4976218cbSCleber Rosa# 5976218cbSCleber Rosa# Copyright (c) 2021 Red Hat, Inc. 6976218cbSCleber Rosa# 7976218cbSCleber Rosa# Author: 8976218cbSCleber Rosa# Cleber Rosa <crosa@redhat.com> 9976218cbSCleber Rosa# 10976218cbSCleber Rosa# This work is licensed under the terms of the GNU GPL, version 2 or 11976218cbSCleber Rosa# later. See the COPYING file in the top-level directory. 12976218cbSCleber Rosa 13eeba3d73SThomas Huthfrom qemu_test import QemuSystemTest 14*9fa4fc23SThomas Huthfrom qemu_test.utils import get_usernet_hostfwd_port 15976218cbSCleber Rosa 16976218cbSCleber Rosa 172283b627SPhilippe Mathieu-Daudéclass InfoUsernet(QemuSystemTest): 18976218cbSCleber Rosa 19976218cbSCleber Rosa def test_hostfwd(self): 200fc389feSThomas Huth self.require_netdev('user') 21eeba3d73SThomas Huth self.set_machine('none') 22976218cbSCleber Rosa self.vm.add_args('-netdev', 'user,id=vnet,hostfwd=:127.0.0.1:0-:22') 23976218cbSCleber Rosa self.vm.launch() 24*9fa4fc23SThomas Huth 25*9fa4fc23SThomas Huth port = get_usernet_hostfwd_port(self.vm) 26976218cbSCleber Rosa self.assertIsNotNone(port, 27976218cbSCleber Rosa ('"info usernet" output content does not seem to ' 28976218cbSCleber Rosa 'contain the redirected port')) 29976218cbSCleber Rosa self.assertGreater(port, 0, 30976218cbSCleber Rosa ('Found a redirected port that is not greater than' 31976218cbSCleber Rosa ' zero')) 32eeba3d73SThomas Huth 33eeba3d73SThomas Huthif __name__ == '__main__': 34eeba3d73SThomas Huth QemuSystemTest.main() 35