Ejemplo n.º 1
0
 def host_call_plugin(self, _1, _2, plugin, method, _5):
     if (plugin, method) == ("glance", "download_vhd"):
         return fake.as_json(dict(vdi_type="root", vdi_uuid=_make_fake_vdi()))
     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.º 2
0
Archivo: stubs.py Proyecto: xtoddx/nova
 def host_call_plugin(self, _1, _2, plugin, method, _5):
     if (plugin, method) == ('glance', 'download_vhd'):
         return fake.as_json(dict(vdi_type='os', vdi_uuid=_make_fake_vdi()))
     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.º 3
0
    def host_call_plugin(self, _1, _2, plugin, method, args):
        """Mock method four host_call_plugin to be used in unit tests
           for the dom0 iptables Firewall drivers for XenAPI

        """
        if plugin == "xenhost" and method == "iptables_config":
            # The command to execute is a json-encoded list
            cmd_args = args.get('cmd_args', None)
            cmd = json.loads(cmd_args)
            if not cmd:
                ret_str = ''
            else:
                output = ''
                process_input = args.get('process_input', None)
                if cmd == ['ip6tables-save', '-t', 'filter']:
                    output = '\n'.join(self._in6_filter_rules)
                if cmd == ['iptables-save', '-t', 'filter']:
                    output = '\n'.join(self._in_filter_rules)
                if cmd == ['iptables-save', '-t', 'nat']:
                    output = '\n'.join(self._in_nat_rules)
                if cmd == ['iptables-restore', ]:
                    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', ]:
                    lines = process_input.split('\n')
                    if '*filter' in lines:
                        output = '\n'.join(lines)
                ret_str = fake.as_json(out=output, err='')
        return ret_str
Ejemplo n.º 4
0
 def host_call_plugin(self, _1, _2, plugin, method, _5):
     if (plugin, method) == ('glance', 'download_vhd'):
         return fake.as_json(dict(vdi_type='os',
                                  vdi_uuid=_make_fake_vdi()))
     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, 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.º 6
0
    def host_call_plugin(self, _1, _2, plugin, method, args):
        """Mock method four host_call_plugin to be used in unit tests
           for the dom0 iptables Firewall drivers for XenAPI

        """
        if plugin == "xenhost" and method == "iptables_config":
            # The command to execute is a json-encoded list
            cmd_args = args.get("cmd_args", None)
            cmd = json.loads(cmd_args)
            if not cmd:
                ret_str = ""
            else:
                output = ""
                process_input = args.get("process_input", None)
                if cmd == ["ip6tables-save", "-t", "filter"]:
                    output = "\n".join(self._in6_filter_rules)
                if cmd == ["iptables-save", "-t", "filter"]:
                    output = "\n".join(self._in_filter_rules)
                if cmd == ["iptables-save", "-t", "nat"]:
                    output = "\n".join(self._in_nat_rules)
                if cmd == ["iptables-restore"]:
                    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"]:
                    lines = process_input.split("\n")
                    if "*filter" in lines:
                        output = "\n".join(lines)
                ret_str = fake.as_json(out=output, err="")
        return ret_str
Ejemplo n.º 7
0
 def host_call_plugin_swap(self, _1, _2, plugin, method, _5):
     if (plugin, method) == ("glance", "download_vhd"):
         return fake.as_json(
             dict(vdi_type="root", vdi_uuid=_make_fake_vdi()), dict(vdi_type="swap", vdi_uuid=_make_fake_vdi())
         )
     else:
         return super(FakeSessionForVMTests, self).host_call_plugin(_1, _2, plugin, method, _5)
Ejemplo n.º 8
0
    def host_call_plugin(self, _1, _2, plugin, method, args):
        """Mock method four host_call_plugin to be used in unit tests
           for the dom0 iptables Firewall drivers for XenAPI

        """
        if plugin == "xenhost" and method == "iptables_config":
            # The command to execute is a json-encoded list
            cmd_args = args.get('cmd_args', None)
            cmd = json.loads(cmd_args)
            if not cmd:
                ret_str = ''
            else:
                output = ''
                process_input = args.get('process_input', None)
                if cmd == ['ip6tables-save', '-t', 'filter']:
                    output = '\n'.join(self._in6_filter_rules)
                if cmd == ['iptables-save', '-t', 'filter']:
                    output = '\n'.join(self._in_filter_rules)
                if cmd == ['iptables-save', '-t', 'nat']:
                    output = '\n'.join(self._in_nat_rules)
                if cmd == ['iptables-restore', ]:
                    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', ]:
                    lines = process_input.split('\n')
                    if '*filter' in lines:
                        output = '\n'.join(lines)
                ret_str = fake.as_json(out=output, err='')
        return ret_str
Ejemplo n.º 9
0
Archivo: stubs.py Proyecto: xtoddx/nova
 def host_call_plugin_swap(self, _1, _2, plugin, method, _5):
     if (plugin, method) == ('glance', 'download_vhd'):
         return fake.as_json(
             dict(vdi_type='os', vdi_uuid=_make_fake_vdi()),
             dict(vdi_type='swap', vdi_uuid=_make_fake_vdi()))
     else:
         return (super(FakeSessionForVMTests,
                       self).host_call_plugin(_1, _2, plugin, method, _5))
Ejemplo n.º 10
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))
Ejemplo n.º 11
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))
Ejemplo n.º 12
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))