Check config file not empty after modify it in hostcfgd.
This commit is contained in:
parent
9b3d8b7f81
commit
b268b55198
@ -168,11 +168,26 @@ class AaaCfg(object):
|
||||
def tacacs_server_update(self, key):
|
||||
self.modify_conf_file()
|
||||
|
||||
def check_file_not_empty(self, filename):
|
||||
exists = os.path.exists(filename)
|
||||
if not exists:
|
||||
syslog.syslog(syslog.LOG_ERR, "file size check failed: {} is missing".format(filename))
|
||||
return
|
||||
|
||||
size = os.path.getsize(filename)
|
||||
if size == 0:
|
||||
syslog.syslog(syslog.LOG_ERR, "file size check failed: {} is empty, file corrupted".format(filename))
|
||||
return
|
||||
|
||||
syslog.syslog(syslog.LOG_INFO, "file size check pass: {} size is ({}) bytes".format(filename, size))
|
||||
|
||||
def modify_single_file(self, filename, operations=None):
|
||||
if operations:
|
||||
cmd = "sed -e {0} {1} > {1}.new; mv -f {1} {1}.old; mv -f {1}.new {1}".format(' -e '.join(operations), filename)
|
||||
os.system(cmd)
|
||||
|
||||
self.check_file_not_empty(filename)
|
||||
|
||||
def modify_conf_file(self):
|
||||
with lock_mgr():
|
||||
self.auth = self.config_db.get_table('AAA').get("authentication", {})
|
||||
|
Loading…
Reference in New Issue
Block a user