netperf_node test case improvement. 25/24925/6
authorliyin <liyin11@huawei.com>
Sat, 26 Nov 2016 06:58:52 +0000 (14:58 +0800)
committerAce Lee <liyin11@huawei.com>
Wed, 30 Nov 2016 01:11:53 +0000 (01:11 +0000)
JIRA: YARDSTICK-423

In the netperf test testcase, input and output parameters are stipulated.
in this submit, add parameters as a output, you could write the output parameters at yaml file.
and the second is if there is a netperf software at target machine,
this machine won't install this software again.

Change-Id: If4def77acbbd5c97e7b5ce9c2e454ecb5bcb12bb
Signed-off-by: liyin <liyin11@huawei.com>
yardstick/benchmark/scenarios/networking/netperf_benchmark.bash
yardstick/benchmark/scenarios/networking/netperf_install.bash
yardstick/benchmark/scenarios/networking/netperf_node.py

index a425c5d..f6245c9 100755 (executable)
@@ -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
index eaa9f53..0e3808f 100755 (executable)
 
 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!!!==="
+
index 1578da7..a76982b 100755 (executable)
@@ -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"),