* [PATCH v2] tests/avocado: starts PhoneServer upfront
@ 2022-03-11 17:11 Beraldo Leal
2022-03-14 9:55 ` Thomas Huth
2022-03-16 11:49 ` Cleber Rosa
0 siblings, 2 replies; 3+ messages in thread
From: Beraldo Leal @ 2022-03-11 17:11 UTC (permalink / raw)
To: qemu-devel
Cc: thuth, berrange, Beraldo Leal, Philippe Mathieu-Daudé,
Wainer dos Santos Moschetta, Cleber Rosa
Race conditions can happen with the current code, because the port that
was available might not be anymore by the time the server is started.
By setting the port to 0, PhoneServer it will use the OS default
behavior to get a free port, then we save this information so we can
later configure the guest.
Suggested-by: Daniel P. Berrangé <berrange@redhat.com>
Signed-off-by: Beraldo Leal <bleal@redhat.com>
---
tests/avocado/avocado_qemu/__init__.py | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/tests/avocado/avocado_qemu/__init__.py b/tests/avocado/avocado_qemu/__init__.py
index 9b056b5ce5..ac85e36a4d 100644
--- a/tests/avocado/avocado_qemu/__init__.py
+++ b/tests/avocado/avocado_qemu/__init__.py
@@ -18,7 +18,7 @@
import uuid
import avocado
-from avocado.utils import cloudinit, datadrainer, network, process, ssh, vmimage
+from avocado.utils import cloudinit, datadrainer, process, ssh, vmimage
from avocado.utils.path import find_command
#: The QEMU build root directory. It may also be the source directory
@@ -602,9 +602,6 @@ def prepare_cloudinit(self, ssh_pubkey=None):
self.log.info('Preparing cloudinit image')
try:
cloudinit_iso = os.path.join(self.workdir, 'cloudinit.iso')
- self.phone_home_port = network.find_free_port()
- if not self.phone_home_port:
- self.cancel('Failed to get a free port')
pubkey_content = None
if ssh_pubkey:
with open(ssh_pubkey) as pubkey:
@@ -614,7 +611,7 @@ def prepare_cloudinit(self, ssh_pubkey=None):
password=self.password,
# QEMU's hard coded usermode router address
phone_home_host='10.0.2.2',
- phone_home_port=self.phone_home_port,
+ phone_home_port=self.phone_server.server_port,
authorized_key=pubkey_content)
except Exception:
self.cancel('Failed to prepare the cloudinit image')
@@ -625,6 +622,8 @@ def set_up_boot(self):
self.vm.add_args('-drive', 'file=%s' % path)
def set_up_cloudinit(self, ssh_pubkey=None):
+ self.phone_server = cloudinit.PhoneHomeServer(('0.0.0.0', 0),
+ self.name)
cloudinit_iso = self.prepare_cloudinit(ssh_pubkey)
self.vm.add_args('-drive', 'file=%s,format=raw' % cloudinit_iso)
@@ -635,7 +634,9 @@ def launch_and_wait(self, set_up_ssh_connection=True):
logger=self.log.getChild('console'))
console_drainer.start()
self.log.info('VM launched, waiting for boot confirmation from guest')
- cloudinit.wait_for_phone_home(('0.0.0.0', self.phone_home_port), self.name)
+ while not self.phone_server.instance_phoned_back:
+ self.phone_server.handle_request()
+
if set_up_ssh_connection:
self.log.info('Setting up the SSH connection')
self.ssh_connect(self.username, self.ssh_key)
--
2.31.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH v2] tests/avocado: starts PhoneServer upfront
2022-03-11 17:11 [PATCH v2] tests/avocado: starts PhoneServer upfront Beraldo Leal
@ 2022-03-14 9:55 ` Thomas Huth
2022-03-16 11:49 ` Cleber Rosa
1 sibling, 0 replies; 3+ messages in thread
From: Thomas Huth @ 2022-03-14 9:55 UTC (permalink / raw)
To: Beraldo Leal, qemu-devel
Cc: berrange, Philippe Mathieu-Daudé,
Wainer dos Santos Moschetta, Cleber Rosa
On 11/03/2022 18.11, Beraldo Leal wrote:
> Race conditions can happen with the current code, because the port that
> was available might not be anymore by the time the server is started.
>
> By setting the port to 0, PhoneServer it will use the OS default
> behavior to get a free port, then we save this information so we can
> later configure the guest.
>
> Suggested-by: Daniel P. Berrangé <berrange@redhat.com>
> Signed-off-by: Beraldo Leal <bleal@redhat.com>
> ---
> tests/avocado/avocado_qemu/__init__.py | 13 +++++++------
> 1 file changed, 7 insertions(+), 6 deletions(-)
>
> diff --git a/tests/avocado/avocado_qemu/__init__.py b/tests/avocado/avocado_qemu/__init__.py
> index 9b056b5ce5..ac85e36a4d 100644
> --- a/tests/avocado/avocado_qemu/__init__.py
> +++ b/tests/avocado/avocado_qemu/__init__.py
> @@ -18,7 +18,7 @@
> import uuid
>
> import avocado
> -from avocado.utils import cloudinit, datadrainer, network, process, ssh, vmimage
> +from avocado.utils import cloudinit, datadrainer, process, ssh, vmimage
> from avocado.utils.path import find_command
>
> #: The QEMU build root directory. It may also be the source directory
> @@ -602,9 +602,6 @@ def prepare_cloudinit(self, ssh_pubkey=None):
> self.log.info('Preparing cloudinit image')
> try:
> cloudinit_iso = os.path.join(self.workdir, 'cloudinit.iso')
> - self.phone_home_port = network.find_free_port()
> - if not self.phone_home_port:
> - self.cancel('Failed to get a free port')
> pubkey_content = None
> if ssh_pubkey:
> with open(ssh_pubkey) as pubkey:
> @@ -614,7 +611,7 @@ def prepare_cloudinit(self, ssh_pubkey=None):
> password=self.password,
> # QEMU's hard coded usermode router address
> phone_home_host='10.0.2.2',
> - phone_home_port=self.phone_home_port,
> + phone_home_port=self.phone_server.server_port,
> authorized_key=pubkey_content)
> except Exception:
> self.cancel('Failed to prepare the cloudinit image')
> @@ -625,6 +622,8 @@ def set_up_boot(self):
> self.vm.add_args('-drive', 'file=%s' % path)
>
> def set_up_cloudinit(self, ssh_pubkey=None):
> + self.phone_server = cloudinit.PhoneHomeServer(('0.0.0.0', 0),
> + self.name)
> cloudinit_iso = self.prepare_cloudinit(ssh_pubkey)
> self.vm.add_args('-drive', 'file=%s,format=raw' % cloudinit_iso)
>
> @@ -635,7 +634,9 @@ def launch_and_wait(self, set_up_ssh_connection=True):
> logger=self.log.getChild('console'))
> console_drainer.start()
> self.log.info('VM launched, waiting for boot confirmation from guest')
> - cloudinit.wait_for_phone_home(('0.0.0.0', self.phone_home_port), self.name)
> + while not self.phone_server.instance_phoned_back:
> + self.phone_server.handle_request()
> +
> if set_up_ssh_connection:
> self.log.info('Setting up the SSH connection')
> self.ssh_connect(self.username, self.ssh_key)
Thank you very much, this indeed fixes my problem with find_free_port() in
the related tests:
Tested-by: Thomas Huth <thuth@redhat.com>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v2] tests/avocado: starts PhoneServer upfront
2022-03-11 17:11 [PATCH v2] tests/avocado: starts PhoneServer upfront Beraldo Leal
2022-03-14 9:55 ` Thomas Huth
@ 2022-03-16 11:49 ` Cleber Rosa
1 sibling, 0 replies; 3+ messages in thread
From: Cleber Rosa @ 2022-03-16 11:49 UTC (permalink / raw)
To: Beraldo Leal
Cc: thuth, berrange, qemu-devel, Wainer dos Santos Moschetta,
Philippe Mathieu-Daudé
Beraldo Leal <bleal@redhat.com> writes:
> Race conditions can happen with the current code, because the port that
> was available might not be anymore by the time the server is started.
>
> By setting the port to 0, PhoneServer it will use the OS default
> behavior to get a free port, then we save this information so we can
> later configure the guest.
>
> Suggested-by: Daniel P. Berrangé <berrange@redhat.com>
> Signed-off-by: Beraldo Leal <bleal@redhat.com>
> ---
> tests/avocado/avocado_qemu/__init__.py | 13 +++++++------
> 1 file changed, 7 insertions(+), 6 deletions(-)
Reviewed-by: Cleber Rosa <crosa@redhat.com>
Tested-by: Cleber Rosa <crosa@redhat.com>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2022-03-16 11:52 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-03-11 17:11 [PATCH v2] tests/avocado: starts PhoneServer upfront Beraldo Leal
2022-03-14 9:55 ` Thomas Huth
2022-03-16 11:49 ` Cleber Rosa
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).