44
55import paramiko
66import requests
7- import yaml
8- from importlib_resources import files
7+
98from osfv .libs .models import Models
109from osfv .libs .rtectrl_api import rtectrl
11- from voluptuous import Any , Optional , Required , Schema
10+ from osfv . libs . utils import OSFVException
1211
1312
1413class RTE (rtectrl ):
@@ -46,9 +45,8 @@ def __init__(self, rte_ip, dut_model, sonoff):
4645 self .sonoff = sonoff
4746 if not self .sonoff_sanity_check ():
4847 raise SonoffNotFound (
49- exit (
50- f"Missing value for 'sonoff_ip' or Sonoff not found "
51- f"in SnipeIT"
48+ sys .exit (
49+ "Missing value for 'sonoff_ip' or Sonoff not found in SnipeIT"
5250 )
5351 )
5452
@@ -202,12 +200,12 @@ def psu_on(self):
202200 self .sonoff .turn_on ()
203201 state = self .sonoff .get_state ()
204202 if state != self .PSU_STATE_ON :
205- raise Exception ("Failed to power control ON" )
203+ raise OSFVException ("Failed to power control ON" )
206204 elif self .dut_data ["pwr_ctrl" ]["relay" ] is True :
207205 self .relay_set (self .PSU_STATE_ON )
208206 state = self .relay_get ()
209207 if state != self .PSU_STATE_ON :
210- raise Exception ("Failed to power control ON" )
208+ raise OSFVException ("Failed to power control ON" )
211209 time .sleep (5 )
212210
213211 def psu_off (self ):
@@ -226,12 +224,12 @@ def psu_off(self):
226224 self .sonoff .turn_off ()
227225 state = self .sonoff .get_state ()
228226 if state != self .PSU_STATE_OFF :
229- raise Exception ("Failed to power control OFF" )
227+ raise OSFVException ("Failed to power control OFF" )
230228 elif self .dut_data ["pwr_ctrl" ]["relay" ] is True :
231229 self .relay_set (self .PSU_STATE_OFF )
232230 state = self .relay_get ()
233231 if state != self .PSU_STATE_OFF :
234- raise Exception ("Failed to power control OFF" )
232+ raise OSFVException ("Failed to power control OFF" )
235233 time .sleep (2 )
236234
237235 def psu_get (self ):
@@ -302,7 +300,7 @@ def pwr_ctrl_before_flash(self, programmer, power_state):
302300 if self .dut_data ["pwr_ctrl" ]["discharge_psu" ]:
303301 self .discharge_psu ()
304302 else :
305- exit (
303+ sys . exit (
306304 f"Power state: '{ power_state } ' is not supported. Please check "
307305 f"model config."
308306 )
@@ -341,11 +339,11 @@ def create_layout_file(self):
341339 layout_content += f"{ region ['range' ]} { region ['name' ]} \n "
342340
343341 # Create temporary file
344- temp_file = tempfile .NamedTemporaryFile (
342+ with tempfile .NamedTemporaryFile (
345343 mode = "w" , suffix = ".txt" , delete = False
346- )
347- temp_file .write (layout_content )
348- temp_file .close ()
344+ ) as temp_file :
345+ temp_file .write (layout_content )
346+ temp_file .close ()
349347
350348 return temp_file .name
351349
@@ -476,12 +474,14 @@ def flash_create_args(self, extra_args=""):
476474 args = ""
477475
478476 # Set chip explicitly, if defined in model configuration
479- if "flash_chip" in self .dut_data :
480- if "model" in self .dut_data ["flash_chip" ]:
481- args = " " .join (["-c" , self .dut_data ["flash_chip" ]["model" ]])
477+ if (
478+ "flash_chip" in self .dut_data
479+ and "model" in self .dut_data ["flash_chip" ]
480+ ):
481+ args = " " .join (["-c" , self .dut_data ["flash_chip" ]["model" ]])
482482
483483 if extra_args :
484- args = " " . join ([ args , extra_args ])
484+ args = f" { args } { extra_args } "
485485
486486 return args
487487
@@ -522,7 +522,7 @@ def flash_erase(self):
522522 Returns:
523523 int: The return code from the flashrom command execution.
524524 """
525- args = self .flash_create_args (f "-E" )
525+ args = self .flash_create_args ("-E" )
526526 return self .flash_cmd (args )
527527
528528 def flash_write (self , write_file , bios = False ):
@@ -557,9 +557,11 @@ def flash_write(self, write_file, bios=False):
557557 rc = self .flash_cmd (args , write_file = write_file )
558558 time .sleep (2 )
559559
560- if "reset_cmos" in self .dut_data :
561- if self .dut_data ["reset_cmos" ] == True :
562- self .reset_cmos ()
560+ if (
561+ "reset_cmos" in self .dut_data
562+ and self .dut_data ["reset_cmos" ] == True
563+ ):
564+ self .reset_cmos ()
563565 return rc
564566
565567 def sonoff_sanity_check (self ):
0 commit comments