Add command-dict option to specify command args
Add a command-dict option `command_args' that can be used to specify a remote command arguments. Change-Id: I8eab6ea604c111561f34e5534ec04cdeb69ccfe1 Implements: blueprint vm-workloads-framework
This commit is contained in:
@@ -1,12 +1,13 @@
|
||||
#!/bin/sh
|
||||
time_seconds(){ (time -p $1 ) 2>&1 |awk '/real/{print $2}'; }
|
||||
file=/tmp/test.img
|
||||
c=100 #100M
|
||||
c=${1:-$SIZE}
|
||||
c=${c:-1000} #default is 1GB
|
||||
write_seq=$(time_seconds "dd if=/dev/zero of=$file bs=1M count=$c")
|
||||
read_seq=$(time_seconds "dd if=$file of=/dev/null bs=1M count=$c")
|
||||
[ -f $file ] && rm $file
|
||||
|
||||
echo "{
|
||||
\"write_seq\": $write_seq,
|
||||
\"read_seq\": $read_seq
|
||||
\"write_seq_${c}m\": $write_seq,
|
||||
\"read_seq_${c}m\": $read_seq
|
||||
}"
|
||||
|
||||
@@ -74,6 +74,14 @@ class VMScenario(base.Scenario):
|
||||
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)
|
||||
|
||||
def _boot_server_with_fip(self, image, flavor,
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
#!/bin/sh
|
||||
time_seconds(){ (time -p $1 ) 2>&1 |awk '/real/{print $2}'; }
|
||||
file=/tmp/test.img
|
||||
c=1000 #1GB
|
||||
write_seq_1gb=$(time_seconds "dd if=/dev/zero of=$file bs=1M count=$c")
|
||||
read_seq_1gb=$(time_seconds "dd if=$file of=/dev/null bs=1M count=$c")
|
||||
c=${1:-$SIZE}
|
||||
c=${c:-1000} #default is 1GB
|
||||
write_seq=$(time_seconds "dd if=/dev/zero of=$file bs=1M count=$c")
|
||||
read_seq=$(time_seconds "dd if=$file of=/dev/null bs=1M count=$c")
|
||||
[ -f $file ] && rm $file
|
||||
|
||||
echo "{
|
||||
\"write_seq_1gb\": $write_seq_1gb,
|
||||
\"read_seq_1gb\": $read_seq_1gb
|
||||
\"write_seq_${c}m\": $write_seq,
|
||||
\"read_seq_${c}m\": $read_seq
|
||||
}"
|
||||
|
||||
@@ -37,10 +37,11 @@ class VMScenarioTestCase(test.ScenarioTestCase):
|
||||
{
|
||||
"script_file": "foobar",
|
||||
"interpreter": ["interpreter", "interpreter_arg"],
|
||||
"command_args": ["arg1", "arg2"]
|
||||
}
|
||||
)
|
||||
mock_ssh.execute.assert_called_once_with(
|
||||
["interpreter", "interpreter_arg"],
|
||||
["interpreter", "interpreter_arg", "arg1", "arg2"],
|
||||
stdin=mock_open.side_effect())
|
||||
mock_open.assert_called_once_with("foobar", "rb")
|
||||
|
||||
@@ -53,10 +54,11 @@ class VMScenarioTestCase(test.ScenarioTestCase):
|
||||
{
|
||||
"script_inline": "foobar",
|
||||
"interpreter": ["interpreter", "interpreter_arg"],
|
||||
"command_args": ["arg1", "arg2"]
|
||||
}
|
||||
)
|
||||
mock_ssh.execute.assert_called_once_with(
|
||||
["interpreter", "interpreter_arg"],
|
||||
["interpreter", "interpreter_arg", "arg1", "arg2"],
|
||||
stdin=mock_string_io.return_value)
|
||||
mock_string_io.assert_called_once_with("foobar")
|
||||
|
||||
@@ -67,10 +69,11 @@ class VMScenarioTestCase(test.ScenarioTestCase):
|
||||
mock_ssh,
|
||||
{
|
||||
"remote_path": ["foo", "bar"],
|
||||
"command_args": ["arg1", "arg2"]
|
||||
}
|
||||
)
|
||||
mock_ssh.execute.assert_called_once_with(
|
||||
["foo", "bar"],
|
||||
["foo", "bar", "arg1", "arg2"],
|
||||
stdin=None)
|
||||
|
||||
def test__run_command_over_ssh_remote_path_copy(self):
|
||||
@@ -80,14 +83,15 @@ class VMScenarioTestCase(test.ScenarioTestCase):
|
||||
mock_ssh,
|
||||
{
|
||||
"remote_path": ["foo", "bar"],
|
||||
"local_path": "/bin/false"
|
||||
"local_path": "/bin/false",
|
||||
"command_args": ["arg1", "arg2"]
|
||||
}
|
||||
)
|
||||
mock_ssh.put_file.assert_called_once_with(
|
||||
"/bin/false", "bar", mode=0o755
|
||||
)
|
||||
mock_ssh.execute.assert_called_once_with(
|
||||
["foo", "bar"],
|
||||
["foo", "bar", "arg1", "arg2"],
|
||||
stdin=None)
|
||||
|
||||
def test__run_command_over_ssh_fails(self):
|
||||
|
||||
Reference in New Issue
Block a user