blob: 4163377a5d3b9d4af1f63262defad6f51357e602 [file] [log] [blame]
macauley_cheng420ddce2015-10-26 13:42:23 +08001import subprocess
2import json
3import os
4from pprint import pprint
macauley_cheng0a0a7f62015-11-06 11:36:50 +08005import time
macauley_cheng420ddce2015-10-26 13:42:23 +08006
7test_tmp_file=os.getcwd()+os.sep+"dpctloutputtmp.tmp"
8
9
macauley_chengdc5eb582015-10-26 14:29:17 +080010def apply_dpctl(test, config, cmd):
macauley_cheng420ddce2015-10-26 13:42:23 +080011 switch_ip = config["switch_ip"]
12 if len(switch_ip) == 0:
13 assert(0)
macauley_cheng420ddce2015-10-26 13:42:23 +080014
15 #apply dpctl command
macauley_cheng31507392015-11-06 13:26:50 +080016 #subprocess.call(os.getcwd()+"/dpctl tcp:"+switch_ip+":6633 "+cmd+" > "+test_tmp_file, shell=True)
17 subprocess.call("dpctl tcp:"+switch_ip+":6633 "+cmd+" > "+test_tmp_file, shell=True)
macauley_cheng0a0a7f62015-11-06 11:36:50 +080018 time.sleep(0.2)
macauley_chengdc5eb582015-10-26 14:29:17 +080019
20def apply_dpctl_get_cmd(test, config, cmd):
21
22 #create the tmp file
23 if not os.path.isfile(test_tmp_file):
24 open(test_tmp_file, "w").close()
25 subprocess.call(["sudo", "chmod", "a+w", test_tmp_file])
26
27 apply_dpctl(test, config, cmd)
macauley_cheng0a0a7f62015-11-06 11:36:50 +080028
macauley_chengdc5eb582015-10-26 14:29:17 +080029 #parse result
macauley_cheng420ddce2015-10-26 13:42:23 +080030 with open(test_tmp_file) as tmp_file:
31 try:
32 json_result=json.loads(tmp_file.read(), encoding='utf-8')
33 except ValueError:
34 subprocess.call("cat "+ test_tmp_file, shell=True)
35 """
36 https://docs.python.org/2/library/unittest.html#
37 """
38 test.assertTrue(False, "NO json format, dpctl may fail")
39
macauley_chengdc5eb582015-10-26 14:29:17 +080040 return json_result
41
42def apply_dpctl_mod(test, config, cmd):
43 apply_dpctl(test, config, cmd)
44
45