From a343dfb677d8e9a0851b38e878c1dd316de36eaa Mon Sep 17 00:00:00 2001 From: David Weinholz Date: Thu, 5 Nov 2020 14:16:37 +0100 Subject: [PATCH 1/2] fix(Playbook):if machine gets deleted switch to not found --- VirtualMachineService/VirtualMachineHandler.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/VirtualMachineService/VirtualMachineHandler.py b/VirtualMachineService/VirtualMachineHandler.py index 58104ccb..2bcc6051 100644 --- a/VirtualMachineService/VirtualMachineHandler.py +++ b/VirtualMachineService/VirtualMachineHandler.py @@ -93,6 +93,7 @@ class VirtualMachineHandler(Iface): BUILD = "BUILD" ACTIVE = "ACTIVE" ERROR = "ERROR" + NOT_FOUND="NOT FOUND" PREPARE_PLAYBOOK_BUILD = "PREPARE_PLAYBOOK_BUILD" BUILD_PLAYBOOK = "BUILD_PLAYBOOK" PLAYBOOK_FAILED = "PLAYBOOK_FAILED" @@ -599,7 +600,7 @@ def get_server(self, openstack_id): server = self.conn.compute.get_server(openstack_id) except Exception as e: LOG.exception("No Server found {0} | Error {1}".format(openstack_id, e)) - return VM(status="NOT FOUND") + return VM(status=self.NOT_FOUND) serv = server.to_dict() @@ -1729,12 +1730,15 @@ def check_server_status(self, openstack_id): server = self.conn.compute.get_server(openstack_id) except Exception: LOG.exception("No Server with id {0} ".format(openstack_id)) - return None + return VM(status=self.NOT_FOUND) + if server is None: LOG.exception("No Server with id {0} ".format(openstack_id)) - return None + return VM(status=self.NOT_FOUND) + serv = server.to_dict() + try: if serv["status"] == self.ACTIVE: host = self.get_server(openstack_id).floating_ip @@ -1785,7 +1789,8 @@ def check_server_status(self, openstack_id): return server except Exception as e: LOG.exception("Check Status VM {0} error: {1}".format(openstack_id, e)) - return None + return VM(status=self.ERROR) + def openstack_server_to_thrift_server(self, server): LOG.info("Convert server {} to thrift server".format(server)) From 043227826759352d2f5ddd0359d8ad7733997319 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Thu, 5 Nov 2020 13:18:03 +0000 Subject: [PATCH 2/2] fix(Linting):blacked code --- VirtualMachineService/VirtualMachineHandler.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/VirtualMachineService/VirtualMachineHandler.py b/VirtualMachineService/VirtualMachineHandler.py index 2bcc6051..18cd38b9 100644 --- a/VirtualMachineService/VirtualMachineHandler.py +++ b/VirtualMachineService/VirtualMachineHandler.py @@ -93,7 +93,7 @@ class VirtualMachineHandler(Iface): BUILD = "BUILD" ACTIVE = "ACTIVE" ERROR = "ERROR" - NOT_FOUND="NOT FOUND" + NOT_FOUND = "NOT FOUND" PREPARE_PLAYBOOK_BUILD = "PREPARE_PLAYBOOK_BUILD" BUILD_PLAYBOOK = "BUILD_PLAYBOOK" PLAYBOOK_FAILED = "PLAYBOOK_FAILED" @@ -1738,7 +1738,6 @@ def check_server_status(self, openstack_id): serv = server.to_dict() - try: if serv["status"] == self.ACTIVE: host = self.get_server(openstack_id).floating_ip @@ -1791,7 +1790,6 @@ def check_server_status(self, openstack_id): LOG.exception("Check Status VM {0} error: {1}".format(openstack_id, e)) return VM(status=self.ERROR) - def openstack_server_to_thrift_server(self, server): LOG.info("Convert server {} to thrift server".format(server)) fixed_ip = None