def test_check_command_valid(self): e = self.assertRaises(ValueError, validation.check_command_dict, { "interpreter": "foobar", "script_file": "foo", "script_inline": "bar" }) self.assertIn("Exactly one of ", str(e)) e = self.assertRaises(ValueError, validation.check_command_dict, {"script_file": "foobar"}) self.assertIn("Supplied dict specifies no", str(e)) command = {"script_inline": "foobar", "interpreter": "foo"} result = validation.check_command_dict(command) self.assertIsNone(result) e = self.assertRaises(ValueError, validation.check_command_dict, { "script_inline": "foobar", "interpreter": "foo", "local_path": "bar" }) self.assertIn("When uploading an interpreter its path", str(e)) result = validation.check_command_dict({ "script_inline": "foobar", "interpreter": ["ENV=bar", "/bin/foo"], "local_path": "bar", "remote_path": "/bin/foo" }) self.assertIsNone(result)
def test_check_command_valid(self): e = self.assertRaises( ValueError, validation.check_command_dict, { "interpreter": "foobar", "script_file": "foo", "script_inline": "bar" }) self.assertIn("Exactly one of ", str(e)) e = self.assertRaises( ValueError, validation.check_command_dict, {"script_file": "foobar"}) self.assertIn("Supplied dict specifies no", str(e)) command = {"script_inline": "foobar", "interpreter": "foo"} result = validation.check_command_dict(command) self.assertIsNone(result) e = self.assertRaises( ValueError, validation.check_command_dict, { "script_inline": "foobar", "interpreter": "foo", "local_path": "bar" }) self.assertIn("When uploading an interpreter its path", str(e)) result = validation.check_command_dict({ "script_inline": "foobar", "interpreter": ["ENV=bar", "/bin/foo"], "local_path": "bar", "remote_path": "/bin/foo" }) self.assertIsNone(result)
def test_check_command_dict(self, command=None, raises_message=None): if raises_message: e = self.assertRaises( ValueError, validation.check_command_dict, command) self.assertIn(raises_message, str(e)) else: self.assertIsNone(validation.check_command_dict(command))
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 `rally info find VMTasks.boot_runcommand_delete' parameter `command' docstring for explanation. :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 if command.get("local_path"): remote_path = cmd[-1] if isinstance(cmd, (tuple, list)) else cmd ssh.put_file(command["local_path"], remote_path, mode=self.USER_RWX_OTHERS_RX_ACCESS_MODE) if command.get("command_args"): if not isinstance(cmd, (list, tuple)): cmd = [cmd] # NOTE(pboldin): `ssh.execute' accepts either a string interpreted # as a command name or the list of strings that are converted into # single-line command with arguments. cmd = cmd + list(command["command_args"]) return ssh.execute(cmd, stdin=stdin)