blob: b8d451e8480c9e4eda2cffd53af90ef23ae7f8a3 [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
macauley_chengdc5eb582015-10-26 14:29:17 +08009def apply_dpctl(test, config, cmd):
macauley_cheng420ddce2015-10-26 13:42:23 +080010 switch_ip = config["switch_ip"]
11 if len(switch_ip) == 0:
12 assert(0)
macauley_cheng420ddce2015-10-26 13:42:23 +080013
14 #apply dpctl command
15 subprocess.call("dpctl tcp:"+switch_ip+":6633 "+cmd+" > "+test_tmp_file, shell=True)
16
macauley_chengdc5eb582015-10-26 14:29:17 +080017
18def apply_dpctl_get_cmd(test, config, cmd):
19
20 #create the tmp file
21 if not os.path.isfile(test_tmp_file):
22 open(test_tmp_file, "w").close()
23 subprocess.call(["sudo", "chmod", "a+w", test_tmp_file])
24
25 apply_dpctl(test, config, cmd)
26
27 #parse result
macauley_cheng420ddce2015-10-26 13:42:23 +080028 with open(test_tmp_file) as tmp_file:
29 try:
30 json_result=json.loads(tmp_file.read(), encoding='utf-8')
31 except ValueError:
32 subprocess.call("cat "+ test_tmp_file, shell=True)
33 """
34 https://docs.python.org/2/library/unittest.html#
35 """
36 test.assertTrue(False, "NO json format, dpctl may fail")
37
macauley_chengdc5eb582015-10-26 14:29:17 +080038 return json_result
39
40def apply_dpctl_mod(test, config, cmd):
41 apply_dpctl(test, config, cmd)
42
43