diff --git a/simple_vm_client/openstack_connector/openstack_connector.py b/simple_vm_client/openstack_connector/openstack_connector.py index 1045ca1..da86003 100644 --- a/simple_vm_client/openstack_connector/openstack_connector.py +++ b/simple_vm_client/openstack_connector/openstack_connector.py @@ -1366,6 +1366,7 @@ def delete_server(self, openstack_id: str) -> None: def rescue_server(self, openstack_id: str, admin_pass: str = None, image_ref: str = None) -> None: logger.info(f"Rescue Server {openstack_id}") + try: server: Server = self.get_server(openstack_id=openstack_id) if not server: @@ -1374,12 +1375,11 @@ def rescue_server(self, openstack_id: str, admin_pass: str = None, image_ref: st message=f"Instance {openstack_id} not found", name_or_id=openstack_id, ) - self.openstack_connection.compute.rescue_server(server.id, admin_pass, image_ref) + self.openstack_connection.compute.rescue_server(server, admin_pass, image_ref) except ConflictException as e: - logger.error(f"Rescue Server {openstack_id} failed!") - - raise OpenStackConflictException(message=e.message) + logger.exception(f"Rescue Server {openstack_id} failed!") + raise OpenStackConflictException(message=str(e)) def unrescue_server(self, openstack_id: str) -> None: logger.info(f"Unrescue Server {openstack_id}") @@ -1392,12 +1392,11 @@ def unrescue_server(self, openstack_id: str) -> None: name_or_id=openstack_id, ) - self.openstack_connection.compute.unrescue_server(server.id,) + self.openstack_connection.compute.unrescue_server(server) except ConflictException as e: - logger.error(f"Unrescue Server {openstack_id} failed!") - - raise OpenStackConflictException(message=e.message) + logger.exception(f"Unrescue Server {openstack_id} failed!") + raise OpenStackConflictException(message=str(e)) def _calculate_vm_ports(self, server: Server): fixed_ip = server.private_v4 diff --git a/simple_vm_client/test_openstack_connector.py b/simple_vm_client/test_openstack_connector.py index 9d4a993..a6fdf7c 100644 --- a/simple_vm_client/test_openstack_connector.py +++ b/simple_vm_client/test_openstack_connector.py @@ -2308,6 +2308,8 @@ def test_get_server_openstack_exception(self): with self.assertRaises(DefaultException): self.openstack_connector.get_server("someid") + + @patch.object(OpenStackConnector, "get_server") def test_rescue_server_success(self, mock_get_server): # Arrange @@ -2319,7 +2321,7 @@ def test_rescue_server_success(self, mock_get_server): # Assert # Ensure the stop_server method is called with the correct server self.openstack_connector.openstack_connection.compute.rescue_server.assert_called_once_with( - server_mock + server_mock, None, None ) @patch.object(OpenStackConnector, "get_server") @@ -2330,7 +2332,8 @@ def test_rescue_server_conflict_exception( # Arrange server_mock = fakes.generate_fake_resource(server.Server) mock_get_server.return_value = server_mock - self.openstack_connector.openstack_connection.compute.rescue_server.side_effect = ConflictException( + self.openstack_connector.openstack_connection.compute.rescue_server.side_effect = ConflictException + ( "Unit Test" ) # Act @@ -2370,7 +2373,7 @@ def test_unrescue_server_conflict_exception( self.openstack_connector.unrescue_server(openstack_id="some_openstack_id") mock_logger_exception.assert_called_once_with( "Unrescue Server some_openstack_id failed!" - ) + ) @patch.object(OpenStackConnector, "get_server")