fix: handle Alibaba request error logging (#1262)

Signed-off-by: semih702 <semih702@users.noreply.github.com>
Co-authored-by: semih702 <semih702@users.noreply.github.com>
This commit is contained in:
Semih702
2026-05-04 09:10:22 -04:00
committed by GitHub
co-authored by semih702
parent 95530dfe55
commit e296565e4b
2 changed files with 11 additions and 5 deletions
@@ -52,7 +52,7 @@ class Alibaba:
response_detail = json.loads(response_str)
return response_detail
except Exception as e:
logging.error("ERROR sending request %s with message %S" % (request, e))
logging.error("ERROR sending request %s with message %s", request, e)
# output the instance owned in current region.
def list_instances(self):
+10 -4
View File
@@ -84,10 +84,16 @@ class TestAlibaba(unittest.TestCase):
mock_request = Mock()
alibaba.compute_client.do_action.side_effect = Exception("API error")
# The actual code has a bug in the format string (%S instead of %s)
# So we expect this to raise a ValueError
with self.assertRaises(ValueError):
alibaba._send_request(mock_request)
result = alibaba._send_request(mock_request)
self.assertIsNone(result)
mock_request.set_accept_format.assert_called_once_with('json')
alibaba.compute_client.do_action.assert_called_once_with(mock_request)
mock_logging.assert_called_once_with(
"ERROR sending request %s with message %s",
mock_request,
alibaba.compute_client.do_action.side_effect,
)
@patch('krkn.scenario_plugins.node_actions.alibaba_node_scenarios.AcsClient')
def test_list_instances_success(self, mock_acs_client):