File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11#!/usr/bin/env python
22
33try :
4+ import os
45 import time
56 import syslog
7+ import logging
8+ import logging .config
9+ import yaml
610
711 from sonic_platform_base .chassis_base import ChassisBase
812 from sonic_platform .sfp import Sfp
913 from sonic_platform .psu import psu_list_get
1014 from sonic_platform .fan_drawer import fan_drawer_list_get
1115 from sonic_platform .thermal import thermal_list_get
1216 from eeprom import Eeprom
17+ from platform_utils import file_create
1318
1419 from sonic_platform .platform_thrift_client import pltfm_mgr_ready
1520 from sonic_platform .platform_thrift_client import thrift_try
@@ -47,6 +52,11 @@ def __init__(self):
4752 self .qsfp_interval = self .QSFP_CHECK_INTERVAL
4853 self .__initialize_components ()
4954
55+ with open (os .path .dirname (__file__ ) + "/logging.conf" , 'r' ) as f :
56+ config_dict = yaml .load (f , yaml .SafeLoader )
57+ file_create (config_dict ['handlers' ]['file' ]['filename' ], '646' )
58+ logging .config .dictConfig (config_dict )
59+
5060 @property
5161 def _eeprom (self ):
5262 if self .__eeprom is None :
Original file line number Diff line number Diff line change 11try :
2+ import os
23 import subprocess
34 from sonic_platform_base .component_base import ComponentBase
45 from platform_thrift_client import thrift_try
@@ -16,9 +17,12 @@ def get_bios_version():
1617 A string containing the firmware version of the BIOS
1718 """
1819 try :
19- return subprocess .check_output (['dmidecode' , '-s' , 'bios-version' ]).strip ().decode ()
20+ cmd = ['dmidecode' , '-s' , 'bios-version' ]
21+ if os .geteuid () != 0 :
22+ cmd .insert (0 , 'sudo' )
23+ return subprocess .check_output (cmd ).strip ().decode ()
2024 except subprocess .CalledProcessError as e :
21- raise RuntimeError ("Failed to getget BIOS version" )
25+ raise RuntimeError ("Failed to get BIOS version" )
2226
2327def get_bmc_version ():
2428 """
Original file line number Diff line number Diff line change 11try :
22 import os
33 import sys
4- import errno
54 import datetime
6- import logging
7- import logging .config
8- import yaml
95 import re
106
117 sys .path .append (os .path .dirname (__file__ ))
1713
1814 from sonic_platform_base .sonic_eeprom import eeprom_base
1915 from sonic_platform_base .sonic_eeprom import eeprom_tlvinfo
16+ from platform_utils import file_create
2017
2118 from platform_thrift_client import thrift_try
2219except ImportError as e :
4542
4643class Eeprom (eeprom_tlvinfo .TlvInfoDecoder ):
4744 def __init__ (self ):
48- with open (os .path .dirname (__file__ ) + "/logging.conf" , 'r' ) as f :
49- config_dict = yaml .load (f , yaml .SafeLoader )
50- logging .config .dictConfig (config_dict )
51-
52- if not os .path .exists (os .path .dirname (_EEPROM_SYMLINK )):
53- try :
54- os .makedirs (os .path .dirname (_EEPROM_SYMLINK ))
55- except OSError as e :
56- if e .errno != errno .EEXIST :
57- raise
58-
59- open (_EEPROM_SYMLINK , 'a' ).close ()
45+ file_create (_EEPROM_SYMLINK , '646' )
46+ file_create (_EEPROM_STATUS , '646' )
6047 with open (_EEPROM_STATUS , 'w' ) as f :
6148 f .write ("initializing.." )
6249
@@ -152,3 +139,4 @@ def modelstr(self):
152139
153140 def revision_str (self ):
154141 return self .__tlv_get (self ._TLV_CODE_LABEL_REVISION )
142+
Original file line number Diff line number Diff line change 1+ #!/usr/bin/env python
2+
3+ try :
4+ import os
5+ import subprocess
6+
7+ except ImportError as e :
8+ raise ImportError (str (e ) + "- required module not found" )
9+
10+ def file_create (path , mode = None ):
11+ def run_cmd (cmd ):
12+ if os .geteuid () != 0 :
13+ cmd .insert (0 , 'sudo' )
14+ subprocess .check_output (cmd )
15+
16+ file_path = os .path .dirname (path )
17+ if not os .path .exists (file_path ):
18+ run_cmd (['mkdir' , '-p' , file_path ])
19+ if not os .path .isfile (path ):
20+ run_cmd (['touch' , path ])
21+ if (mode is not None ):
22+ run_cmd (['chmod' , mode , path ])
You can’t perform that action at this time.
0 commit comments