Skip to content

Commit

Permalink
Add info to flaky tests (#2434)
Browse files Browse the repository at this point in the history
  • Loading branch information
larohra authored Dec 9, 2021
1 parent 3345d1f commit df113e0
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions tests/ga/test_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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(
Expand Down

0 comments on commit df113e0

Please sign in to comment.