'Mock method for host_call_plugin to be used in unit tests
for the dom0 iptables Firewall drivers for XenAPI'

def host_call_plugin(self, _1, _2, plugin, method, args):

    plugin = plugin.rstrip('.py')
    if ((plugin == 'xenhost') and (method == 'iptables_config')):
        cmd_args = args.get('cmd_args', None)
        cmd = jsonutils.loads(cmd_args)
        if (not cmd):
            ret_str = ''
        else:
            output = ''
            process_input = args.get('process_input', None)
            if (cmd == ['ip6tables-save', '-c']):
                output = '\n'.join(self._in6_filter_rules)
            if (cmd == ['iptables-save', '-c']):
                output = '\n'.join(self._in_rules)
            if (cmd == ['iptables-restore', '-c']):
                lines = process_input.split('\n')
                if ('*filter' in lines):
                    if (self._test_case is not None):
                        self._test_case._out_rules = lines
                    output = '\n'.join(lines)
            if (cmd == ['ip6tables-restore', '-c']):
                lines = process_input.split('\n')
                if ('*filter' in lines):
                    output = '\n'.join(lines)
            ret_str = fake.as_json(out=output, err='')
        return ret_str
    else:
        return super(FakeSessionForVMTests, self).host_call_plugin(_1, _2, plugin, method, args)
