lf_ap_auto_test: Fix lf_attenmod_test

Signed-off-by: Matthew Stidham <stidmatt@gmail.com>
This commit is contained in:
Matthew Stidham
2021-11-18 15:26:14 -08:00
parent edb7bb2e90
commit 2979b00cdb

View File

@@ -18,15 +18,15 @@ class ATTENUATORProfile(LFCliBase):
super().__init__(lfclient_host, lfclient_port, debug_) super().__init__(lfclient_host, lfclient_port, debug_)
self.lfclient_host = lfclient_host self.lfclient_host = lfclient_host
self.COMMANDS = ["show_attenuators", "set_attenuator"] self.COMMANDS = ["show_attenuators", "set_attenuator"]
self.atten_serno = "" self.atten_serno = None
self.atten_idx = "" self.atten_idx = None
self.atten_val = "" self.atten_val = None
self.atten_data = { self.atten_data = {
"shelf": 1, "shelf": 1,
"resource": 1, "resource": 1,
"serno": None, "serno": self.atten_serno,
"atten_idx": None, "atten_idx": self.atten_idx,
"val": None, "val": self.atten_val,
"mode": None, "mode": None,
"pulse_width_us5": None, "pulse_width_us5": None,
"pulse_interval_ms": None, "pulse_interval_ms": None,
@@ -37,10 +37,10 @@ class ATTENUATORProfile(LFCliBase):
def set_command_param(self, command_name, param_name, param_value): def set_command_param(self, command_name, param_name, param_value):
# we have to check what the param name is # we have to check what the param name is
if (command_name is None) or (command_name == ""): if not command_name:
return raise ValueError("Command Name is required")
if (param_name is None) or (param_name == ""): if not param_name:
return raise ValueError("Paramater is required")
if command_name not in self.COMMANDS: if command_name not in self.COMMANDS:
raise ValueError("Command name name [%s] not defined in %s" % (command_name, self.COMMANDS)) raise ValueError("Command name name [%s] not defined in %s" % (command_name, self.COMMANDS))
if command_name == "set_attenuator": if command_name == "set_attenuator":
@@ -53,19 +53,27 @@ class ATTENUATORProfile(LFCliBase):
if response is None: if response is None:
print(response) print(response)
raise ValueError("Cannot find any endpoints") raise ValueError("Cannot find any endpoints")
else: elif 'attenuator' or 'attenuators' in response.keys():
attenuator_resp = response["attenuators"] try:
attenuator_resp = response["attenuators"]
except KeyError:
attenuator_resp = [response["attenuator"]]
for attenuator in attenuator_resp: for attenuator in attenuator_resp:
for key, val in attenuator.items(): for key, val in attenuator.items():
if key == "entity id": if key == "entity id":
serial_num = val.split(".") serial_num = val.split(".")
print("Serial-num : %s" % serial_num[-1]) print("Serial-num : %s" % serial_num[-1])
print("%s : %s" % (key, val)) print("%s : %s" % (key, val))
print("\n") print('\n')
else:
raise ValueError('No attenuators in response')
def create(self): def create(self):
if type(self.atten_serno) == str or len(self.atten_idx) == 0 or type(self.atten_val) == str: if int(self.atten_val) > 955:
print("ERROR: Must specify atten_serno, atten_idx, and atten_val when setting attenuator.\n") raise ValueError("Attenuation ddB value must be 955 or less")
if int(self.atten_idx) > 7:
raise ValueError("Attenuation ddB value must be 7 or less")
print("Setting Attenuator...") print("Setting Attenuator...")
self.set_command_param("set_attenuator", "serno", self.atten_serno) self.set_command_param("set_attenuator", "serno", self.atten_serno)
self.set_command_param("set_attenuator", "atten_idx", self.atten_idx) self.set_command_param("set_attenuator", "atten_idx", self.atten_idx)
@@ -73,7 +81,6 @@ class ATTENUATORProfile(LFCliBase):
set_attenuators = LFRequest.LFRequest(self.lfclient_url + "/cli-json/set_attenuator", debug_=self.debug) set_attenuators = LFRequest.LFRequest(self.lfclient_url + "/cli-json/set_attenuator", debug_=self.debug)
set_attenuators.addPostData(self.atten_data) set_attenuators.addPostData(self.atten_data)
time.sleep(0.01) time.sleep(0.01)
json_response = set_attenuators.jsonPost(self.debug) set_attenuators.jsonPost(self.debug)
time.sleep(10) time.sleep(10)
print("\n") print("\n")