Ejemplo n.º 1
0
    def host_call_plugin(self, _1, _2, plugin, method, args):
        """Mock method for host_call_plugin to be used in unit tests
           for the dom0 iptables Firewall drivers for XenAPI

        """
        plugin = plugin.rstrip('.py')

        if plugin == 'xenhost' and method == 'iptables_config':
            # The command to execute is a json-encoded list
            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))
Ejemplo n.º 2
0
    def host_call_plugin(self, _1, _2, plugin, method, args):
        """Mock method for host_call_plugin to be used in unit tests
           for the dom0 iptables Firewall drivers for XenAPI

        """
        plugin = plugin.rstrip('.py')

        if plugin == 'xenhost' and method == 'iptables_config':
            # The command to execute is a json-encoded list
            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))
Ejemplo n.º 3
0
 def host_call_plugin(self, _1, _2, plugin, method, _5):
     if plugin == 'glance' and method in ('download_vhd2'):
         root_uuid = _make_fake_vdi()
         return pickle.dumps(dict(root=dict(uuid=root_uuid)))
     elif (plugin, method) == ("xenhost", "iptables_config"):
         return fake.as_json(out=self._fake_iptables_save_output, err='')
     else:
         return (super(FakeSessionForVMTests,
                       self).host_call_plugin(_1, _2, plugin, method, _5))
Ejemplo n.º 4
0
 def host_call_plugin(self, _1, _2, plugin, method, _5):
     if (plugin, method) == ('glance', 'download_vhd'):
         root_uuid = _make_fake_vdi()
         return pickle.dumps(dict(root=dict(uuid=root_uuid)))
     elif (plugin, method) == ("xenhost", "iptables_config"):
         return fake.as_json(out=self._fake_iptables_save_output,
                             err='')
     else:
         return (super(FakeSessionForVMTests, self).
                 host_call_plugin(_1, _2, plugin, method, _5))
Ejemplo n.º 5
0
    def host_call_plugin(self, _1, _2, plugin, method, _5):
        plugin = plugin.rstrip('.py')

        if plugin == 'glance' and method in ('download_vhd2'):
            root_uuid = _make_fake_vdi()
            return pickle.dumps(dict(root=dict(uuid=root_uuid)))
        elif (plugin, method) == ('xenhost', 'iptables_config'):
            return fake.as_json(out=self._fake_iptables_save_output,
                                err='')
        else:
            return (super(FakeSessionForVMTests, self).
                    host_call_plugin(_1, _2, plugin, method, _5))