Example #1
0
    def test_delete_dnat_rule(self):
        """Test dnat rule deletion."""
        iptables.delete_dnat_rule(
            firewall.DNATRule('1.1.1.1', 123, '2.2.2.2', 345), 'SOME_RULE')

        treadmill.iptables.delete_raw_rule.assert_called_with(
            'nat', 'SOME_RULE', ('-d 1.1.1.1 -p tcp -m tcp --dport 123'
                                 ' -j DNAT --to-destination 2.2.2.2:345'))
Example #2
0
    def test_delete_raw_rule(self):
        """Test deleting an iptable rule."""
        iptables.delete_dnat_rule(
            firewall.DNATRule('1.1.1.1', 123, '2.2.2.2', 345), 'SOME_RULE')

        treadmill.subproc.check_call.assert_called_with([
            'iptables', '-t', 'nat', '-D', 'SOME_RULE', '-d', '1.1.1.1', '-p',
            'tcp', '-m', 'tcp', '--dport', '123', '-j', 'DNAT',
            '--to-destination', '2.2.2.2:345'
        ])
Example #3
0
    def test_delete_dnat_rule(self):
        """Test dnat rule deletion."""
        iptables.delete_dnat_rule(
            firewall.DNATRule(proto='tcp',
                              dst_ip='1.1.1.1',
                              dst_port=123,
                              new_ip='2.2.2.2',
                              new_port=345), 'SOME_RULE')

        treadmill.iptables.delete_raw_rule.assert_called_with(
            'nat', 'SOME_RULE',
            ('-s 0.0.0.0/0 -d 1.1.1.1 -p tcp -m tcp --dport 123'
             ' -j DNAT --to-destination 2.2.2.2:345'))
Example #4
0
    def test_delete_rule_nonexist(self):
        """Test dnat rule deleting when the rule does not exist."""
        treadmill.subproc.check_call.side_effect = \
            subprocess.CalledProcessError(returncode=1, output='', cmd='')

        iptables.delete_dnat_rule(
            firewall.DNATRule('1.1.1.1', 123, '2.2.2.2', 345), 'SOME_RULE')

        treadmill.subproc.check_call.assert_called_with([
            'iptables', '-t', 'nat', '-D', 'SOME_RULE', '-d', '1.1.1.1', '-p',
            'tcp', '-m', 'tcp', '--dport', '123', '-j', 'DNAT',
            '--to-destination', '2.2.2.2:345'
        ])