update_dut.py: working state, can create and update DUT and notes

This commit is contained in:
Jed Reynolds
2020-10-22 22:04:19 -07:00
parent fa5b0161ad
commit ce34d2f31c

View File

@@ -15,7 +15,7 @@ if 'py-json' not in sys.path:
import argparse
import pprint
from pprint import pprint
from pprint import *
from LANforge.lfcli_base import LFCliBase
from LANforge.LFUtils import *
from LANforge import add_dut
@@ -31,10 +31,16 @@ class UpdateDUT(LFCliBase):
_debug_on=False,
_exit_on_error=False,
_exit_on_fail=False):
super().__init__(host, port, _debug=_debug_on, _halt_on_error=_exit_on_error, _exit_on_fail=_exit_on_fail)
super().__init__(host, port,
_debug=_debug_on,
_halt_on_error=_exit_on_error,
_exit_on_fail=_exit_on_fail,
_local_realm=realm.Realm(lfclient_host=host, lfclient_port=port, debug_=_debug_on))
self.host = host
self.port = port
self.notes = "NA"
self.notes = []
self.append = []
self.params = {}
self.flags = 0x0
self.flags_mask = 0x0
@@ -42,15 +48,28 @@ class UpdateDUT(LFCliBase):
self.url = "/cli-json/add_dut"
def build(self):
self.dut_profile = self.local_realm.new_dut_profile()
self.dut_profile.name = self.name
for param in self.params:
print("param: %s: %s"%(param, self.params[param]))
if (self.debug):
print("param: %s: %s"%(param, self.params[param]))
self.dut_profile.set_param(param, self.params[param])
for flag in self.flags:
print("flags: %s: %s"%(flag, self.flags[flag]))
if (self.debug):
print("flags: %s"%self.flags)
self.dut_profile.flags = self.flags
self.dut_profile.flags_mask = self.flags_mask
if len(self.notes) > 0:
if (self.debug):
pprint.pprint(self.notes)
self.dut_profile.notes = self.notes
if len(self.append) > 0:
if (self.debug):
pprint.pprint(self.append)
self.dut_profile.append = self.append
def start(self, print_pass=False, print_fail=False):
self.json_post(self.url, self.data)
self.dut_profile.create()
self._pass("DUT updated")
pass
@@ -80,7 +99,10 @@ Generic command layout:
python ./{file} --dut [DUT name] # update existing DUT record
--entry [key,value] # update/add entry by specifying key and value
--flag [flag,0|1] # toggle a flag on 1 or off 0
--notes "going to mars...."
--notes "all lines of text"
--notes "are replaced if any"
--notes "line of text is submitted with --notes"
--append "this appends a line of text"
DUT Parameters:
{params}
DUT Flags:
@@ -99,22 +121,57 @@ python3 {file} --mgr 192.168.100.24 --update Pathfinder \
parser.add_argument("-d", "--dut", type=str, help="name of DUT record")
parser.add_argument("-p", "--param", type=str, action="append", help="name,value pair to set parameter")
parser.add_argument("-f", "--flag", type=str, action="append", help="name,1/0/True/False pair to turn parameter on or off")
parser.add_argument("--notes", type=str, help="add notes to the DUT")
parser.add_argument("-n", "--notes", type=str, action="append", help="replace lines of notes in the record")
parser.add_argument("-a", "--append", type=str, action="append", help="append lines of text to the record")
args = parser.parse_args()
if args.dut is None:
raise ValueError("need a name for the dut: --dut something")
update_dut = UpdateDUT(args.mgr, lfjson_port, _debug_on=args.debug)
pprint.pprint(args)
for param in args.param:
(name,value) = param.split(",")
update_dut.params[name] = value
update_dut.name = args.dut
for flag in args.flags:
(name,value) = flag.split(",")
update_dut.flags[name] = (False,True)[value]
update_dut.flags_mask[name] = True
if (args.param is not None):
for param in args.param:
if "," not in param:
raise ValueError("Invalid format for param: %s, please use key,value"%param)
(name,value) = param.split(",")
if (args.debug):
print("name %s = %s"%(name, value))
if add_dut.dut_params.has(name):
update_dut.params[name] = value
else:
raise ValueError("parameter %s not in dut_params"%name)
if (args.notes is not None) and (args.notes != ""):
update_dut.notes = args.notes
flags_sum = 0
flags_mask_sum = 0
if (args.flag is not None):
for flag in args.flag:
if "," not in flag:
raise ValueError("Invalid format for flag: %s, please use flag,(0/1)"%param)
(name,val_str) = flag.split(",")
if (args.debug):
print("name %s = %s"%(name, val_str))
if not add_dut.dut_flags.has(name):
raise ValueError("flag %s not in add_dut.dut_flags"%name)
on_off = (0,1)[val_str=="1"]
if (args.debug):
print("name %s = %s"%(name, on_off))
flags_sum |= (0,add_dut.dut_flags.to_flag(name).value)[on_off]
flags_mask_sum |= add_dut.dut_flags.to_flag(name).value
if args.debug:
print("params %s; flags %s; mask %s"%(",".join(update_dut.params),
hex(flags_sum),
hex(flags_mask_sum)))
if (args.notes is not None) and (len(args.notes) > 0):
update_dut.notes = args.notes.copy()
if (args.append is not None) and (len(args.append) > 0):
update_dut.append = args.append.copy()
update_dut.flags = flags_sum
update_dut.flags_mask = flags_mask_sum
update_dut.build()
update_dut.start()