Skip to content

Commit

Permalink
[config/config_mgmt.py]: Fix Conflict problem and put lock related lo…
Browse files Browse the repository at this point in the history
…gs to syslog or to clock.echo. (sonic-net#31)

Signed-off-by: Praveen Chaudhary [email protected]
  • Loading branch information
Praveen Chaudhary authored Jun 30, 2020
1 parent c2e4eac commit 942f49f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 26 deletions.
15 changes: 0 additions & 15 deletions config/config_mgmt.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
22 changes: 11 additions & 11 deletions config/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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)
Expand All @@ -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

Expand All @@ -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):
Expand Down

0 comments on commit 942f49f

Please sign in to comment.