def spin_locks(): try: while not (os.path.exists("/var/lib/load-balancer-servo/ntp.lock")): time.sleep(2) log.debug('waiting on ntp setup (reboot if continued)') os.remove("/var/lib/load-balancer-servo/ntp.lock") except Exception, err: log.error('failed to spin on locks: %s' % err)
def run_with_grep(cmd, grep): proc1 = subprocess.Popen(shlex.split(cmd), stdout=subprocess.PIPE) proc2 = subprocess.Popen(shlex.split('grep %s' % grep), stdin=proc1.stdout, stderr=subprocess.PIPE) proc1.stdout.close() output = proc2.communicate() if proc2.returncode != 0: log.debug(output) return proc2.returncode
def run(cmd): p = subprocess.Popen(shlex.split(cmd), stderr=subprocess.PIPE) output = p.communicate() if p.returncode != 0: log.debug(output) return p.returncode