Ejemplo n.º 1
0
    def _run_command_over_ssh(self, ssh, command):
        """Run command inside an instance.

        This is a separate function so that only script execution is timed.

        :param ssh: A SSHClient instance.
        :param command: Dictionary specifying command to execute.
            See `validation.valid_command' docstring for details.

        :returns: tuple (exit_status, stdout, stderr)
        """
        validation.check_command_dict(command)

        # NOTE(pboldin): Here we `get' the values and not check for the keys
        # due to template-driven configuration generation that can leave keys
        # defined but values empty.
        if command.get("script_file") or command.get("script_inline"):
            cmd = command["interpreter"]
            if command.get("script_file"):
                stdin = open(command["script_file"], "rb")
            elif command.get("script_inline"):
                stdin = six.moves.StringIO(command["script_inline"])
        elif command.get("remote_path"):
            cmd = command["remote_path"]
            stdin = None

        return ssh.execute(cmd, stdin=stdin)
Ejemplo n.º 2
0
    def _run_command_over_ssh(self, ssh, command):
        """Run command inside an instance.

        This is a separate function so that only script execution is timed.

        :param ssh: A SSHClient instance.
        :param command: Dictionary specifying command to execute.
            See `validation.valid_command' docstring for details.

        :returns: tuple (exit_status, stdout, stderr)
        """
        validation.check_command_dict(command)

        # NOTE(pboldin): Here we `get' the values and not check for the keys
        # due to template-driven configuration generation that can leave keys
        # defined but values empty.
        if command.get("script_file") or command.get("script_inline"):
            cmd = command["interpreter"]
            if command.get("script_file"):
                stdin = open(command["script_file"], "rb")
            elif command.get("script_inline"):
                stdin = six.moves.StringIO(command["script_inline"])
        elif command.get("remote_path"):
            cmd = command["remote_path"]
            stdin = None

        return ssh.execute(cmd, stdin=stdin)
Ejemplo n.º 3
0
    def test_check_command_valid(self):

        e = self.assertRaises(ValueError, validation.check_command_dict, {
            "script_file": "foo",
            "remote_path": "bar"
        })
        self.assertIn("Exactly one of ", str(e))

        e = self.assertRaises(ValueError, validation.check_command_dict,
                              {"script_file": "foobar"})
        self.assertIn("An `interpreter' is required for", str(e))

        e = self.assertRaises(ValueError, validation.check_command_dict,
                              {"script_inline": "foobar"})
        self.assertIn("An `interpreter' is required for", str(e))

        command = {"script_inline": "foobar", "interpreter": "foo"}
        result = validation.check_command_dict(command)
        self.assertIsNone(result)
Ejemplo n.º 4
0
    def test_check_command_valid(self):

        e = self.assertRaises(
            ValueError, validation.check_command_dict,
            {"script_file": "foo", "remote_path": "bar"})
        self.assertIn("Exactly one of ", str(e))

        e = self.assertRaises(
            ValueError, validation.check_command_dict,
            {"script_file": "foobar"})
        self.assertIn("An `interpreter' is required for", str(e))

        e = self.assertRaises(
            ValueError, validation.check_command_dict,
            {"script_inline": "foobar"})
        self.assertIn("An `interpreter' is required for", str(e))

        command = {"script_inline": "foobar", "interpreter": "foo"}
        result = validation.check_command_dict(command)
        self.assertIsNone(result)