From 1e079258e74a8b607da8c202ca900ebf91555d78 Mon Sep 17 00:00:00 2001 From: dweinholz Date: Thu, 26 Oct 2023 15:25:29 +0200 Subject: [PATCH] fixed timeout and condition --- VirtualMachineService/VirtualMachineHandler.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/VirtualMachineService/VirtualMachineHandler.py b/VirtualMachineService/VirtualMachineHandler.py index ce3d4a6e..3b2a7e66 100644 --- a/VirtualMachineService/VirtualMachineHandler.py +++ b/VirtualMachineService/VirtualMachineHandler.py @@ -1879,7 +1879,7 @@ def check_server_status(self, openstack_id: str) -> VM: serv = server.to_dict() try: - if serv["status"] == self.ACTIVE: + if serv["status"] == self.ACTIVE and serv["task_state"] not in ["powering-off", "powering-on"]: host = self.get_server(openstack_id).floating_ip port = self.SSH_PORT @@ -2528,8 +2528,10 @@ def netcat(self, host, port): :return: True if successfully connected, False if not """ self.LOG.info(f"Checking SSH Connection {host}:{port}") + if serv["status"] == self.ACTIVE and serv["task_state"] not in ["powering-off", "powering-on"]: + with closing(socket.socket(socket.AF_INET, socket.SOCK_STREAM)) as sock: - sock.settimeout(2500) + sock.settimeout(5) try: r = sock.connect_ex((host, port)) self.LOG.info(f"Checking SSH Connection {host}:{port} Result = {r}")