mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-05 00:33:55 -06:00
Python: add utility function for retrieving port redirection
Slightly different versions for the same utility code are currently present on different locations. This unifies them all, giving preference to the version from virtiofs_submounts.py, because of the last tweaks added to it. While at it, this adds a "qemu.utils" module to host the utility function and a test. Signed-off-by: Cleber Rosa <crosa@redhat.com> Reviewed-by: Wainer dos Santos Moschetta <wainersm@redhat.com> Reviewed-by: Eric Auger <eric.auger@redhat.com> Reviewed-by: Willian Rampazzo <willianr@redhat.com> Message-Id: <20210412044644.55083-4-crosa@redhat.com> Signed-off-by: John Snow <jsnow@redhat.com> [Squashed in below fix. --js] Signed-off-by: John Snow <jsnow@redhat.com> Signed-off-by: Cleber Rosa <crosa@redhat.com> Message-Id: <20210601154546.130870-2-crosa@redhat.com> Signed-off-by: John Snow <jsnow@redhat.com>
This commit is contained in:
parent
c028691e65
commit
976218cbe7
5 changed files with 79 additions and 33 deletions
|
@ -9,6 +9,8 @@ from avocado_qemu import LinuxTest, BUILD_DIR
|
|||
from avocado_qemu import wait_for_console_pattern
|
||||
from avocado.utils import ssh
|
||||
|
||||
from qemu.utils import get_info_usernet_hostfwd_port
|
||||
|
||||
|
||||
def run_cmd(args):
|
||||
subp = subprocess.Popen(args,
|
||||
|
@ -73,27 +75,14 @@ class VirtiofsSubmountsTest(LinuxTest):
|
|||
:avocado: tags=accel:kvm
|
||||
"""
|
||||
|
||||
def get_portfwd(self):
|
||||
port = None
|
||||
|
||||
def ssh_connect(self, username, keyfile):
|
||||
self.ssh_logger = logging.getLogger('ssh')
|
||||
res = self.vm.command('human-monitor-command',
|
||||
command_line='info usernet')
|
||||
for line in res.split('\r\n'):
|
||||
match = \
|
||||
re.search(r'TCP.HOST_FORWARD.*127\.0\.0\.1\s+(\d+)\s+10\.',
|
||||
line)
|
||||
if match is not None:
|
||||
port = int(match[1])
|
||||
break
|
||||
|
||||
port = get_info_usernet_hostfwd_port(res)
|
||||
self.assertIsNotNone(port)
|
||||
self.assertGreater(port, 0)
|
||||
self.log.debug('sshd listening on port: %d', port)
|
||||
return port
|
||||
|
||||
def ssh_connect(self, username, keyfile):
|
||||
self.ssh_logger = logging.getLogger('ssh')
|
||||
port = self.get_portfwd()
|
||||
self.ssh_session = ssh.Session('127.0.0.1', port=port,
|
||||
user=username, key=keyfile)
|
||||
for i in range(10):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue