From df113e09a3f1324571412f4310223173824348a4 Mon Sep 17 00:00:00 2001 From: Laveesh Rohra Date: Thu, 9 Dec 2021 02:59:19 -0800 Subject: [PATCH] Add info to flaky tests (#2434) --- tests/ga/test_update.py | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/tests/ga/test_update.py b/tests/ga/test_update.py index 4619dd208..297b97ba6 100644 --- a/tests/ga/test_update.py +++ b/tests/ga/test_update.py @@ -1643,12 +1643,17 @@ def _mock_popen(cmd, *args, **kwargs): cmd = ["echo", "running"] return _ORIGINAL_POPEN(cmd, *args, **kwargs) - with patch("azurelinuxagent.common.logger.info") as patch_info: - with _get_update_handler(iterations=1) as (update_handler, _): + with _get_update_handler(iterations=1) as (update_handler, _): + with patch("azurelinuxagent.common.logger.info") as patch_info: with patch("azurelinuxagent.common.utils.shellutil.subprocess.Popen", side_effect=_mock_popen): with patch('azurelinuxagent.common.conf.enable_firewall', return_value=False): - update_handler.run(debug=True) + with patch("azurelinuxagent.common.logger.warn") as patch_warn: + update_handler.run(debug=True) + self.assertTrue(update_handler.exit_mock.called, "The process should have exited") + exit_args, _ = update_handler.exit_mock.call_args + self.assertEqual(exit_args[0], 0, "Exit code should be 0; List of all warnings logged by the agent: {0}".format( + patch_warn.call_args_list)) self.assertEqual(0, len(executed_firewall_commands), "firewall-cmd should not be called at all") self.assertTrue(any( "Not setting up persistent firewall rules as OS.EnableFirewall=False" == args[0] for (args, _) in @@ -1668,8 +1673,13 @@ def _mock_popen(cmd, *args, **kwargs): with patch("azurelinuxagent.common.utils.shellutil.subprocess.Popen", side_effect=_mock_popen) as mock_popen: with patch('azurelinuxagent.common.conf.enable_firewall', return_value=True): with patch('azurelinuxagent.common.osutil.systemd.is_systemd', return_value=True): - update_handler.run(debug=True) + with patch("azurelinuxagent.common.logger.warn") as patch_warn: + update_handler.run(debug=True) + self.assertTrue(update_handler.exit_mock.called, "The process should have exited") + exit_args, _ = update_handler.exit_mock.call_args + self.assertEqual(exit_args[0], 0, "Exit code should be 0; List of all warnings logged by the agent: {0}".format( + patch_warn.call_args_list)) # Firewall-cmd should only be called 3 times - 1st to check if running, 2nd & 3rd for the QueryPassThrough cmd self.assertEqual(3, len(executed_commands), "The number of times firewall-cmd should be called is only 3; Executed firewall commands: {0}; All popen calls: {1}".format(