From 942f49faada18869dda2e97779c8ca24ff39385a Mon Sep 17 00:00:00 2001 From: Praveen Chaudhary Date: Tue, 30 Jun 2020 14:12:56 -0700 Subject: [PATCH] [config/config_mgmt.py]: Fix Conflict problem and put lock related logs to syslog or to clock.echo. (#31) Signed-off-by: Praveen Chaudhary pchaudhary@linkedin.com --- config/config_mgmt.py | 15 --------------- config/main.py | 22 +++++++++++----------- 2 files changed, 11 insertions(+), 26 deletions(-) diff --git a/config/config_mgmt.py b/config/config_mgmt.py index 61add9ab7c..e4a5268e1f 100644 --- a/config/config_mgmt.py +++ b/config/config_mgmt.py @@ -432,21 +432,6 @@ def addPorts(self, ports=list(), portJson=dict(), loadDefConfig=True): return configToLoad, True - """ - Validate current Data Tree - """ - def validateConfigData(self): - - try: - self.sy.validate_data_tree() - except Exception as e: - self.sysLog(msg='Data Validation Failed') - return False - - print('Data Validation successful') - self.sysLog(msg='Data Validation successful') - return True - """ Based on the list of Ports, create a dict to shutdown port, update Config DB. Input: [] of ports. diff --git a/config/main.py b/config/main.py index 4d9ecdc524..f1efe08947 100755 --- a/config/main.py +++ b/config/main.py @@ -668,18 +668,18 @@ def _acquireLock(self): # expire call. if self.client.hsetnx(self.lockName, "PID", self.pid): self.client.expire(self.lockName, self.timeout) - print(":::Lock Acquired:::") + log_debug(":::Lock Acquired:::") # if lock exists but expire timer not running, run expire time and # abort. elif not self.client.ttl(self.lockName): self.client.expire(self.lockName, self.timeout) - print(":::Can not acquire lock, Reset Timer & Abort:::"); + click.echo(":::Can not acquire lock, Reset Timer & Abort:::"); sys.exit(1) else: - print(":::Can not acquire lock, Abort:::"); + click.echo(":::Can not acquire lock, Abort:::"); sys.exit(1) except Exception as e: - print(":::Exception: {}:::".format(e)) + click.echo(":::Exception: {}:::".format(e)) sys.exit(1) return @@ -688,7 +688,7 @@ def reacquireLock(self): # Try to set lock first if self.client.hsetnx(self.lockName, "PID", self.pid): self.client.expire(self.lockName, self.timeout) - print(":::Lock Reacquired:::") + log_debug(":::Lock Reacquired:::") # if lock exists, check who owns it else: p = self.client.pipeline(True) @@ -697,18 +697,18 @@ def reacquireLock(self): # if current process holding then extend the timer if p.hget(self.lockName, "PID") == str(self.pid): self.client.expire(self.lockName, self.timeout) - print(":::Lock Timer Extended:::"); + log_debug(":::Lock Timer Extended:::"); p.unwatch() return else: # some other process is holding the lock. - print(":::Can not acquire lock LOCK PID: {} and self.pid:{}:::".\ + click.echo(":::Can not acquire lock LOCK PID: {} and self.pid:{}:::".\ format(p.hget(self.lockName, "PID"), self.pid)) p.unwatch() sys.exit(1) except Exception as e: - print(":::Exception: {}:::".format(e)) + click.echo(":::Exception: {}:::".format(e)) sys.exit(1) return @@ -722,15 +722,15 @@ def _releaseLock(self): p.multi() p.delete(self.lockName) p.execute() - print(":::Lock Released:::"); + log_debug(":::Lock Released:::"); return else: # some other process s holding the lock. - print(":::Lock PID: {} and self.pid:{}:::".\ + log_debug(":::Lock PID: {} and self.pid:{}:::".\ format(p.hget(self.lockName, "PID"), self.pid)) p.unwatch() except Exception as e: - print("Exception: {}".format(e)) + log_error("Exception: {}".format(e)) return def __del__(self):