Example #1
0
    def test_execute_remote_iptables_cmd_no_rule_spec(self):
        fake_client = mock.Mock()
        fake_client.ssh.return_value = (0, 'fake_out', 'fake_err')

        ret, out, err = iptables.execute_iptables_cmd('fake_table',
                                                      'fake_action',
                                                      'fake_chain',
                                                      client=fake_client)
        self.assertEqual(ret, 0)
        fake_client.ssh.assert_called_once_with(
            "iptables -t fake_table "
            "fake_action fake_chain",
            allowed_return_codes=[0])
Example #2
0
    def test_execute_local_iptables_cmd_no_rule_spec(self, mock_execute):
        mock_execute.return_value = (0, 'fake_out', 'fake_err')

        ret, out, err = iptables.execute_iptables_cmd('fake_table',
                                                      'fake_action',
                                                      'fake_chain')
        self.assertEqual(ret, 0)
        mock_execute.assert_called_once_with('iptables',
                                             '-t',
                                             'fake_table',
                                             'fake_action',
                                             'fake_chain',
                                             allowed_return_codes=[0])
Example #3
0
    def test_execute_remote_iptables_cmd_expect_failed(self):
        fake_client = mock.Mock()
        fake_rule_spec = 'fake_rule'
        fake_client.ssh.return_value = (1, 'fake_out', 'fake_err')

        ret, out, err = iptables.execute_iptables_cmd('fake_table',
                                                      'fake_action',
                                                      'fake_chain',
                                                      fake_rule_spec,
                                                      fake_client, [0, 1])
        self.assertEqual(ret, 1)
        fake_client.ssh.assert_called_once_with('iptables -t fake_table ' +
                                                'fake_action fake_chain ' +
                                                fake_rule_spec,
                                                allowed_return_codes=[0, 1])
Example #4
0
    def test_execute_local_iptables_cmd_expect_failed(self, mock_execute):
        fake_rule_spec = 'fake_rule'
        mock_execute.return_value = (1, 'fake_out', 'fake_err')

        ret, out, err = iptables.execute_iptables_cmd(
            'fake_table',
            'fake_action',
            'fake_chain',
            rule_spec=fake_rule_spec,
            client=None,
            allowed_return_codes=[0, 1])
        self.assertEqual(ret, 1)
        mock_execute.assert_called_once_with('iptables',
                                             '-t',
                                             'fake_table',
                                             'fake_action',
                                             'fake_chain',
                                             fake_rule_spec,
                                             allowed_return_codes=[0, 1])