def _test_add_nat_rule_helper(self, use_ipv6):
        self.iptables = iptables_manager.IptablesManager(
            use_ipv6=use_ipv6)
        self.execute = mock.patch.object(self.iptables, "execute").start()

        nat_dump = NAT_TEMPLATE % IPTABLES_ARG

        nat_dump_mod = ('# Generated by iptables_manager\n'
                        '*nat\n'
                        ':OUTPUT - [0:0]\n'
                        ':POSTROUTING - [0:0]\n'
                        ':PREROUTING - [0:0]\n'
                        ':neutron-postrouting-bottom - [0:0]\n'
                        ':%(bn)s-OUTPUT - [0:0]\n'
                        ':%(bn)s-POSTROUTING - [0:0]\n'
                        ':%(bn)s-PREROUTING - [0:0]\n'
                        ':%(bn)s-float-snat - [0:0]\n'
                        ':%(bn)s-nat - [0:0]\n'
                        ':%(bn)s-snat - [0:0]\n'
                        '-I OUTPUT 1 -j %(bn)s-OUTPUT\n'
                        '-I POSTROUTING 1 -j %(bn)s-POSTROUTING\n'
                        '-I POSTROUTING 2 -j neutron-postrouting-bottom\n'
                        '-I PREROUTING 1 -j %(bn)s-PREROUTING\n'
                        '-I neutron-postrouting-bottom 1 -j %(bn)s-snat\n'
                        '-I %(bn)s-PREROUTING 1 -d 192.168.0.3 -j '
                        '%(bn)s-nat\n'
                        '-I %(bn)s-nat 1 -p tcp --dport 8080 -j '
                        'REDIRECT --to-port 80\n'
                        '-I %(bn)s-snat 1 -j %(bn)s-float-snat\n'
                        'COMMIT\n'
                        '# Completed by iptables_manager\n' % IPTABLES_ARG)

        raw_dump = RAW_DUMP % IPTABLES_ARG

        expected_calls_and_values = [
            (mock.call(['iptables-save'],
                       run_as_root=True),
             ''),
            (mock.call(['iptables-restore', '-n'],
                       process_input=(FILTER_DUMP + MANGLE_DUMP +
                                      nat_dump_mod + RAW_DUMP),
                       run_as_root=True),
             None),
            (mock.call(['iptables-save'],
                       run_as_root=True),
             ''),
            (mock.call(['iptables-restore', '-n'],
                       process_input=(FILTER_DUMP + MANGLE_DUMP + nat_dump +
                                      RAW_DUMP),
                       run_as_root=True),
             None),
        ]
        if use_ipv6:
            self._extend_with_ip6tables_filter(
                expected_calls_and_values,
                FILTER_DUMP + MANGLE_DUMP_V6 + raw_dump)

        tools.setup_mock_calls(self.execute, expected_calls_and_values)

        self.iptables.ipv4['nat'].add_chain('nat')
        self.iptables.ipv4['nat'].add_rule('PREROUTING',
                                           '-d 192.168.0.3 -j '
                                           '%(bn)s-nat' % IPTABLES_ARG)
        self.iptables.ipv4['nat'].add_rule('nat',
                                           '-p tcp --dport 8080' +
                                           ' -j REDIRECT --to-port 80')

        self.iptables.apply()

        self.iptables.ipv4['nat'].remove_rule('nat',
                                              '-p tcp --dport 8080 -j'
                                              ' REDIRECT --to-port 80')
        self.iptables.ipv4['nat'].remove_rule('PREROUTING',
                                              '-d 192.168.0.3 -j '
                                              '%(bn)s-nat' % IPTABLES_ARG)
        self.iptables.ipv4['nat'].remove_chain('nat')

        self.iptables.apply()

        tools.verify_mock_calls(self.execute, expected_calls_and_values)
dataset/ETHPy150Open openstack/neutron/neutron/tests/unit/agent/linux/test_iptables_manager.py/IptablesManagerStateFulTestCase._test_add_nat_rule_helper/original