From 0be56a5ff6b4642297a8c3b9c682822a0393bf69 Mon Sep 17 00:00:00 2001 From: wilderrodrigues Date: Wed, 21 Jan 2015 17:09:42 +0100 Subject: [PATCH] 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. --- .../debian/config/opt/cloud/bin/configure.py | 1 - .../config/opt/cloud/bin/cs/CsAddress.py | 4 +-- .../debian/config/opt/cloud/bin/cs/CsApp.py | 2 +- .../config/opt/cloud/bin/cs/CsProcess.py | 13 ++++++-- .../config/opt/cloud/bin/cs_guestnetwork.py | 30 ++++++++++++------- .../debian/config/opt/cloud/bin/merge.py | 3 -- .../config/opt/cloud/bin/update_config.py | 23 +++++++++++--- 7 files changed, 51 insertions(+), 25 deletions(-) diff --git a/systemvm/patches/debian/config/opt/cloud/bin/configure.py b/systemvm/patches/debian/config/opt/cloud/bin/configure.py index 4031c556efd..b04da829d3d 100755 --- a/systemvm/patches/debian/config/opt/cloud/bin/configure.py +++ b/systemvm/patches/debian/config/opt/cloud/bin/configure.py @@ -574,6 +574,5 @@ def main(argv): mon = CsMonitor("monitorservice", config) mon.process() - if __name__ == "__main__": main(sys.argv) diff --git a/systemvm/patches/debian/config/opt/cloud/bin/cs/CsAddress.py b/systemvm/patches/debian/config/opt/cloud/bin/cs/CsAddress.py index 2e2a117a45b..e8d751daad1 100644 --- a/systemvm/patches/debian/config/opt/cloud/bin/cs/CsAddress.py +++ b/systemvm/patches/debian/config/opt/cloud/bin/cs/CsAddress.py @@ -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): diff --git a/systemvm/patches/debian/config/opt/cloud/bin/cs/CsApp.py b/systemvm/patches/debian/config/opt/cloud/bin/cs/CsApp.py index 4aa988a0825..d680bde443f 100644 --- a/systemvm/patches/debian/config/opt/cloud/bin/cs/CsApp.py +++ b/systemvm/patches/debian/config/opt/cloud/bin/cs/CsApp.py @@ -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): diff --git a/systemvm/patches/debian/config/opt/cloud/bin/cs/CsProcess.py b/systemvm/patches/debian/config/opt/cloud/bin/cs/CsProcess.py index 75ebd6f9449..e768852f513 100644 --- a/systemvm/patches/debian/config/opt/cloud/bin/cs/CsProcess.py +++ b/systemvm/patches/debian/config/opt/cloud/bin/cs/CsProcess.py @@ -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 \ No newline at end of file diff --git a/systemvm/patches/debian/config/opt/cloud/bin/cs_guestnetwork.py b/systemvm/patches/debian/config/opt/cloud/bin/cs_guestnetwork.py index 4f9f3a06912..6cb29a1a293 100644 --- a/systemvm/patches/debian/config/opt/cloud/bin/cs_guestnetwork.py +++ b/systemvm/patches/debian/config/opt/cloud/bin/cs_guestnetwork.py @@ -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 \ No newline at end of file diff --git a/systemvm/patches/debian/config/opt/cloud/bin/merge.py b/systemvm/patches/debian/config/opt/cloud/bin/merge.py index 602841511fe..722925456fd 100755 --- a/systemvm/patches/debian/config/opt/cloud/bin/merge.py +++ b/systemvm/patches/debian/config/opt/cloud/bin/merge.py @@ -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'] diff --git a/systemvm/patches/debian/config/opt/cloud/bin/update_config.py b/systemvm/patches/debian/config/opt/cloud/bin/update_config.py index ea21455919a..e84fd09208d 100755 --- a/systemvm/patches/debian/config/opt/cloud/bin/update_config.py +++ b/systemvm/patches/debian/config/opt/cloud/bin/update_config.py @@ -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() \ No newline at end of file