Fixing the timout )ssh hanging) on the CsApp.py file

Adding kill_all() method on the CsProcess.py file (not being used yet)
Changing a bit the logic in the merge.py

The changes in the logic might be reverted, but they are causing no harm now.
This commit is contained in:
wilderrodrigues 2015-01-21 17:09:42 +01:00
parent be81d2ffa4
commit 0be56a5ff6
7 changed files with 51 additions and 25 deletions

View File

@ -574,6 +574,5 @@ def main(argv):
mon = CsMonitor("monitorservice", config)
mon.process()
if __name__ == "__main__":
main(sys.argv)

View File

@ -299,9 +299,7 @@ class CsIP:
if " DOWN " in i:
cmd2 = "ip link set %s up" % self.getDevice()
# Do not change the state of ips on a redundant router that are managed by vrrp or CsRedundant
if self.config.cmdline().is_redundant() and self.is_public():
pass
else:
if not self.config.cmdline().is_redundant() and not self.is_public():
CsHelper.execute(cmd2)
def set_mark(self):

View File

@ -71,7 +71,7 @@ class CsPasswdSvc(CsApp):
proc = CsProcess(['/opt/cloud/bin/vpc_passwd_server', self.ip])
if not proc.find():
proc.start("/usr/bin/nohup", "2>&1 &")
proc.start("/usr/bin/nohup", ">/dev/null 2>&1 &")
class CsDnsmasq(CsApp):

View File

@ -33,7 +33,12 @@ class CsProcess(object):
logging.info("Started %s", " ".join(self.search))
os.system("%s %s %s" % (thru, " ".join(self.search), background))
def find(self):
def kill_all(self):
pids = self.find_pid()
for p in pids:
CsHelper.execute("kill -9 %s" % p)
def find_pid(self):
self.pid = []
for i in CsHelper.execute("ps aux"):
items = len(self.search)
@ -41,4 +46,8 @@ class CsProcess(object):
matches = len([m for m in proc if m in self.search])
if matches == items:
self.pid.append(re.split("\s+", i)[1])
return len(self.pid) > 0
return self.pid
def find(self):
has_pid = len(self.find_pid()) > 0
return has_pid

View File

@ -17,16 +17,24 @@
from pprint import pprint
keys = ['eth1', 'eth2', 'eth3', 'eth4', 'eth5', 'eth6', 'eth7', 'eth8', 'eth9']
def merge(dbag, gn):
added = False
for dev in dbag:
if dev == "id":
continue
if len(dbag[dev]) == 0:
continue
if dbag[dev][0]['device'] == gn['device']:
dbag[dev].remove(dbag[dev][0])
if gn['add']:
dbag.setdefault(gn['device'], []).append(gn)
return dbag
device = gn['device']
if not gn['add'] and device in dbag:
if dbag[device]:
device_to_die = dbag[device][0]
try:
dbag[device].remove(device_to_die)
except ValueError, e:
print "[WARN] cs_guestnetwork.py :: Error occurred removing item from databag. => %s" % device_to_die
del(dbag[device])
else:
del(dbag[device])
else:
dbag.setdefault(device, []).append(gn)
return dbag

View File

@ -127,9 +127,6 @@ class updateDataBag:
def processGuestNetwork(self, dbag):
d = self.qFile.data
if not set(['device']).issubset(d):
return dbag
dp = {}
dp['public_ip'] = d['router_guest_ip']
dp['netmask'] = d['router_guest_netmask']

View File

@ -60,9 +60,23 @@ def is_guestnet_configured(guestnet_dict, keys):
if k1 in keys and len(v1) > 0:
existing_keys.append(k1)
if not existing_keys:
'''
It seems all the interfaces have been removed. Let's allow a new configuration to come in.
'''
print "[WARN] update_config.py :: Reconfiguring guest network..."
return False
file = open(jsonCmdConfigPath)
new_guestnet_dict = json.load(file)
if not new_guestnet_dict['add']:
'''
Guest network has to be removed.
'''
print "[INFO] update_config.py :: Removing guest network..."
return False
'''
Check if we have a new guest network ready to be setup
'''
@ -93,7 +107,7 @@ def is_guestnet_configured(guestnet_dict, keys):
return exists
if not (os.path.isfile(jsonCmdConfigPath) and os.access(jsonCmdConfigPath, os.R_OK)):
print "[ERROR]: You are telling me to process %s, but i can't access it" % jsonCmdConfigPath
print "[ERROR] update_config.py :: You are telling me to process %s, but i can't access it" % jsonCmdConfigPath
sys.exit(1)
# If the command line json file is unprocessed process it
@ -110,13 +124,14 @@ if sys.argv[1] == "guest_network.json":
guestnet_dict = json.load(file)
if not is_guestnet_configured(guestnet_dict, ['eth1', 'eth2', 'eth3', 'eth4', 'eth5', 'eth6', 'eth7', 'eth8', 'eth9']):
print "[INFO] Processing Guest Network."
print "[INFO] update_config.py :: Processing Guest Network."
process_file()
else:
print "[INFO] No need to process Guest Network."
print "[INFO] update_config.py :: No need to process Guest Network."
finish_config()
else:
print "[INFO] No GuestNetwork configured yet. Configuring first one now."
print "[INFO] update_config.py :: No GuestNetwork configured yet. Configuring first one now."
process_file()
else:
print "[INFO] update_config.py :: Processing incoming file => %s" % sys.argv[1]
process_file()