Exemple #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)
Exemple #2
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 = jsonutils.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
Exemple #3
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)