diff options
3 files changed, 58 insertions, 22 deletions
diff --git a/yardstick/benchmark/scenarios/networking/netperf_benchmark.bash b/yardstick/benchmark/scenarios/networking/netperf_benchmark.bash index a425c5df0..f6245c9cd 100755 --- a/yardstick/benchmark/scenarios/networking/netperf_benchmark.bash +++ b/yardstick/benchmark/scenarios/networking/netperf_benchmark.bash @@ -12,6 +12,7 @@ set -e # Commandline arguments +OPTIONS_SIZE="$#" OPTIONS="$@" OUTPUT_FILE=/tmp/netperf-out.log @@ -24,14 +25,40 @@ run_netperf() # write the result to stdout in json format output_json() { - mean=$(awk '/\/s/{print $3}' $OUTPUT_FILE) - troughput=$(awk '/\/s/{print $1}' $OUTPUT_FILE) - unit=$(awk '/\/s/{print $2}' $OUTPUT_FILE) - echo -e "{ \ - \"mean_latency\":\"$mean\", \ - \"troughput\":\"$troughput\", \ - \"troughput_unit\":\"$unit\" \ - }" + #ARR=($OPTIONS) + #declare -p ARR + read -r -a ARR <<< "$OPTIONS" + opt_size=0 + while [ $opt_size -lt "$OPTIONS_SIZE" ] + do + if [ "${ARR[$opt_size]}" = "-O" ] + then + break + fi + opt_size=$((opt_size+1)) + done + opt_size=$((opt_size+1)) + out_opt="${ARR[$opt_size]}" + IFS=, read -r -a PARTS <<< "$out_opt" + #declare -p PARTS + part_num=${#PARTS[*]} + tran_num=0 + for f in "${PARTS[@]}" + do + array_name[$tran_num]=$(echo "$f" | tr '[A-Z]' '[a-z]') + tran_num=$((tran_num+1)) + done + read -r -a DATA_PARTS <<< "$(sed -n '$p' $OUTPUT_FILE)" + out_str="{" + for((i=0;i<part_num-1;i++)) + do + modify_str=\"${array_name[i]}\":\"${DATA_PARTS[i]}\", + out_str=$out_str$modify_str + done + modify_str=\"${array_name[part_num-1]}\":\"${DATA_PARTS[part_num-1]}\" + out_str=$out_str$modify_str"}" + + echo -e "$out_str" } # main entry @@ -44,4 +71,4 @@ main() output_json } -main
\ No newline at end of file +main diff --git a/yardstick/benchmark/scenarios/networking/netperf_install.bash b/yardstick/benchmark/scenarios/networking/netperf_install.bash index eaa9f530a..0e3808f9c 100755 --- a/yardstick/benchmark/scenarios/networking/netperf_install.bash +++ b/yardstick/benchmark/scenarios/networking/netperf_install.bash @@ -11,6 +11,13 @@ set -e +svc="netserver" +if pgrep $svc >/dev/null +then + echo "$svc have existed, exit!" + exit 0 +fi + echo "===Install netperf before test begin!!!===" cp /etc/apt/sources.list /etc/apt/sources.list_bkp cp /etc/resolv.conf /etc/resolv.conf_bkp @@ -30,3 +37,4 @@ sudo apt-get install -y netperf service netperf start echo "===Install netperf before test end!!!===" + diff --git a/yardstick/benchmark/scenarios/networking/netperf_node.py b/yardstick/benchmark/scenarios/networking/netperf_node.py index 1578da7d8..a76982b6f 100755 --- a/yardstick/benchmark/scenarios/networking/netperf_node.py +++ b/yardstick/benchmark/scenarios/networking/netperf_node.py @@ -86,9 +86,8 @@ class NetperfNode(base.Scenario): self.client.wait(timeout=600) # copy script to host - self.client.run("cat > ~/netperf.sh", - stdin=open(self.target_script, "rb")) - + with open(self.target_script, "rb") as file_run: + self.client.run("cat > ~/netperf.sh", stdin=file_run) # copy script to host and client self.install_script = pkg_resources.resource_filename( 'yardstick.benchmark.scenarios.networking', @@ -97,14 +96,14 @@ class NetperfNode(base.Scenario): 'yardstick.benchmark.scenarios.networking', NetperfNode.REMOVE_SCRIPT) - self.server.run("cat > ~/netperf_install.sh", - stdin=open(self.install_script, "rb")) - self.client.run("cat > ~/netperf_install.sh", - stdin=open(self.install_script, "rb")) - self.server.run("cat > ~/netperf_remove.sh", - stdin=open(self.remove_script, "rb")) - self.client.run("cat > ~/netperf_remove.sh", - stdin=open(self.remove_script, "rb")) + with open(self.install_script, "rb") as file_install: + self.server.run("cat > ~/netperf_install.sh", stdin=file_install) + with open(self.install_script, "rb") as file_install: + self.client.run("cat > ~/netperf_install.sh", stdin=file_install) + with open(self.remove_script, "rb") as file_remove: + self.server.run("cat > ~/netperf_remove.sh", stdin=file_remove) + with open(self.remove_script, "rb") as file_remove: + self.client.run("cat > ~/netperf_remove.sh", stdin=file_remove) self.server.execute("sudo bash netperf_install.sh") self.client.execute("sudo bash netperf_install.sh") @@ -131,10 +130,12 @@ class NetperfNode(base.Scenario): else: testlen = 20 - cmd_args = "-H %s -l %s -t %s" % (ipaddr, testlen, testname) + cmd_args = "-H %s -l %s -t %s -c -C" % (ipaddr, testlen, testname) # get test specific options - default_args = "-O 'THROUGHPUT,THROUGHPUT_UNITS,MEAN_LATENCY'" + output_opt = options.get( + "output_opt", "THROUGHPUT,THROUGHPUT_UNITS,MEAN_LATENCY") + default_args = "-O %s" % output_opt cmd_args += " -- %s" % default_args option_pair_list = [("send_msg_size", "-m"), ("recv_msg_size", "-M"), |