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.util" module to host the utility
function and a test.
Signed-off-by: Cleber Rosa <crosa@redhat.com>
---
python/qemu/utils.py | 35 ++++++++++++++++++++++++
tests/acceptance/info_usernet.py | 29 ++++++++++++++++++++
tests/acceptance/linux_ssh_mips_malta.py | 16 +++++------
tests/acceptance/virtiofs_submounts.py | 20 +++-----------
tests/vm/basevm.py | 7 ++---
5 files changed, 77 insertions(+), 30 deletions(-)
create mode 100644 python/qemu/utils.py
create mode 100644 tests/acceptance/info_usernet.py
diff --git a/python/qemu/utils.py b/python/qemu/utils.py
new file mode 100644
index 0000000000..89a246ab30
--- /dev/null
+++ b/python/qemu/utils.py
@@ -0,0 +1,35 @@
+"""
+QEMU utility library
+
+This offers miscellaneous utility functions, which may not be easily
+distinguishable or numerous to be in their own module.
+"""
+
+# Copyright (C) 2021 Red Hat Inc.
+#
+# Authors:
+# Cleber Rosa <crosa@redhat.com>
+#
+# This work is licensed under the terms of the GNU GPL, version 2. See
+# the COPYING file in the top-level directory.
+#
+
+import re
+from typing import Optional
+
+
+def get_info_usernet_hostfwd_port(info_usernet_output: str) -> Optional[int]:
+ """
+ Returns the port given to the hostfwd parameter via info usernet
+
+ :param info_usernet_output: output generated by hmp command "info usernet"
+ :param info_usernet_output: str
+ :return: the port number allocated by the hostfwd option
+ :rtype: int