diff options
Diffstat (limited to 'tests/common/osutil')
-rw-r--r-- | tests/common/osutil/test_default.py | 55 |
1 files changed, 6 insertions, 49 deletions
diff --git a/tests/common/osutil/test_default.py b/tests/common/osutil/test_default.py index c9fa1de..a73f4b4 100644 --- a/tests/common/osutil/test_default.py +++ b/tests/common/osutil/test_default.py @@ -516,16 +516,6 @@ Match host 192.168.1.2\n\ self.assertEqual(-1, util.get_firewall_dropped_packets("not used")) @patch('azurelinuxagent.common.utils.shellutil.run_get_output') - def test_get_firewall_dropped_packets_transient_error_ignored(self, mock_output): - osutil._enable_firewall = True - util = osutil.DefaultOSUtil() - - mock_output.side_effect = [ - (0, "iptables v{0}".format(osutil.IPTABLES_LOCKING_VERSION)), - (3, "can't initialize iptables table `security': iptables who? (do you need to insmod?)")] - self.assertEqual(0, util.get_firewall_dropped_packets("not used")) - - @patch('azurelinuxagent.common.utils.shellutil.run_get_output') def test_get_firewall_dropped_packets(self, mock_output): osutil._enable_firewall = True util = osutil.DefaultOSUtil() @@ -648,34 +638,6 @@ Chain OUTPUT (policy ACCEPT 104 packets, 43628 bytes) ]) self.assertFalse(osutil._enable_firewall) - @patch('azurelinuxagent.common.utils.shellutil.run_get_output') - @patch('azurelinuxagent.common.utils.shellutil.run') - def test_enable_firewall_checks_for_invalid_iptables_options(self, mock_run, mock_output): - osutil._enable_firewall = True - util = osutil.DefaultOSUtil() - - dst = '1.2.3.4' - version = "iptables v{0}".format(osutil.IPTABLES_LOCKING_VERSION) - wait = "-w" - - # iptables uses the following exit codes - # 0 - correct function - # 1 - other errors - # 2 - errors which appear to be caused by invalid or abused command - # line parameters - mock_run.side_effect = [2] - mock_output.return_value = (0, version) - - self.assertFalse(util.enable_firewall(dst_ip='1.2.3.4', uid=42)) - self.assertFalse(osutil._enable_firewall) - - mock_run.assert_has_calls([ - call(osutil.FIREWALL_DROP.format(wait, "C", dst), chk_err=False), - ]) - mock_output.assert_has_calls([ - call(osutil.IPTABLES_VERSION) - ]) - @patch('os.getuid', return_value=42) @patch('azurelinuxagent.common.utils.shellutil.run_get_output') @patch('azurelinuxagent.common.utils.shellutil.run') @@ -708,15 +670,12 @@ Chain OUTPUT (policy ACCEPT 104 packets, 43628 bytes) version = "iptables v{0}".format(osutil.IPTABLES_LOCKING_VERSION) wait = "-w" - mock_run.side_effect = [0, 1, 0, 1] + mock_run.side_effect = [0, 0] mock_output.side_effect = [(0, version), (0, "Output")] - self.assertTrue(util.remove_firewall(dst, uid)) + self.assertTrue(util.remove_firewall()) mock_run.assert_has_calls([ - call(osutil.FIREWALL_DELETE_CONNTRACK.format(wait, dst), chk_err=False), - call(osutil.FIREWALL_DELETE_CONNTRACK.format(wait, dst), chk_err=False), - call(osutil.FIREWALL_DELETE_OWNER.format(wait, dst, uid), chk_err=False), - call(osutil.FIREWALL_DELETE_OWNER.format(wait, dst, uid), chk_err=False), + call(osutil.FIREWALL_FLUSH.format(wait), chk_err=True) ]) mock_output.assert_has_calls([ call(osutil.IPTABLES_VERSION) @@ -730,17 +689,15 @@ Chain OUTPUT (policy ACCEPT 104 packets, 43628 bytes) osutil._enable_firewall = True util = osutil.DefaultOSUtil() - dst_ip='1.2.3.4' - uid=42 version = "iptables v{0}".format(osutil.IPTABLES_LOCKING_VERSION) wait = "-w" - mock_run.side_effect = [2] + mock_run.side_effect = [1, 0] mock_output.side_effect = [(0, version), (1, "Output")] - self.assertFalse(util.remove_firewall(dst_ip, uid)) + self.assertFalse(util.remove_firewall()) mock_run.assert_has_calls([ - call(osutil.FIREWALL_DELETE_CONNTRACK.format(wait, dst_ip), chk_err=False), + call(osutil.FIREWALL_FLUSH.format(wait), chk_err=True) ]) mock_output.assert_has_calls([ call(osutil.IPTABLES_VERSION) |