blob: 757d889accf9577e9d0a2f823f666246f2be8f6c [file] [log] [blame]
macauley_cheng420ddce2015-10-26 13:42:23 +08001import subprocess
2import json
3import os
4from pprint import pprint
5
6test_tmp_file=os.getcwd()+os.sep+"dpctloutputtmp.tmp"
7
8
9def apply_dpctl_cmd(test, config, cmd):
10 switch_ip = config["switch_ip"]
11 if len(switch_ip) == 0:
12 assert(0)
13
14 #create the tmp file
15 try:
16 subprocess.check_call(["ls", test_tmp_file])
17 except subprocess.CalledProcessError:
18 open(test_tmp_file, "w").close()
19 subprocess.call(["sudo", "chmod", "a+w", test_tmp_file])
20
21 #apply dpctl command
22 subprocess.call("dpctl tcp:"+switch_ip+":6633 "+cmd+" > "+test_tmp_file, shell=True)
23
24 with open(test_tmp_file) as tmp_file:
25 try:
26 json_result=json.loads(tmp_file.read(), encoding='utf-8')
27 except ValueError:
28 subprocess.call("cat "+ test_tmp_file, shell=True)
29 """
30 https://docs.python.org/2/library/unittest.html#
31 """
32 test.assertTrue(False, "NO json format, dpctl may fail")
33
34 return json_result