def cleanup(self): c = self.get_client() for bind_ip, _, port in self.srvs: try: c.stop_srv(bind_ip, port) except Exception as e: log.error("EXCEPTION %s" % e) for d in self.devs: try: c.rem_dev(d) except Exception as e: log.error("EXCEPTION %s" % e) try: if self.load_mods: cmd.exec_cmd2("cd " + settings.PROJ_DIR + " && scripts/unload_mods.sh", throw=True, elog=log) except Exception as e: log.error("EXCEPTION %s" % e) try: cmd.exec_cmd2("cd " + settings.PROJ_DIR + " && scripts/loop_dev_del.sh", throw=True, elog=log) except Exception as e: log.error("EXCEPTION %s" % e)
def __init__(self, log, ip, key_path, rootdir, user='******'): self.ip = ip self.log = log self.key_path = key_path self.wdir = os.path.join(rootdir, 'node_' + ip) exec_cmd2('mkdir -p ' + self.wdir, throw = True, elog = log) self.user = user
def __init__(self, log, ip, key_path, rootdir, user='******'): self.ip = ip self.log = log self.key_path = key_path self.wdir = os.path.join(rootdir, 'node_' + ip) exec_cmd2('mkdir -p ' + self.wdir, throw=True, elog=log) self.user = user
def cleanup(): global IN_TMP_DIR global OUT_TMP_DIR shutil.rmtree(IN_TMP_DIR) shutil.rmtree(OUT_TMP_DIR) cmd.exec_cmd2("cd " + settings.PROJ_DIR + " && ./stop.sh", throw=True)
def prepare(): global IN_TMP_DIR global OUT_TMP_DIR IN_TMP_DIR = tempfile.mkdtemp(dir=CURR_DIR) + "/" OUT_TMP_DIR = tempfile.mkdtemp(dir=CURR_DIR) + "/" cmd.exec_cmd2("cd " + settings.PROJ_DIR + " && ./start.sh", throw=True)
def prepare(self): if self.load_mods: cmd.exec_cmd2("cd " + settings.PROJ_DIR + " && scripts/load_mods.sh", throw=True, elog=log) cmd.exec_cmd2("cd " + settings.PROJ_DIR + " && scripts/loop_dev_create.sh", throw=True, elog=log) c = self.get_client() self.srvs = [(self.bind_ip, self.ext_ip, PORT)] for bind_ip, ext_ip, port in self.srvs: c.start_srv(bind_ip, ext_ip, port) for d in DEVS: c.add_dev(d, True) self.devs.append(d)
def put_file(self, fpath): rc, std_out, std_err, c = exec_cmd2(self.cli_cmd("put") + " -f " + fpath, throw = True, elog = log) return std_out[0]
def stop_srv(self, bind_ip, port): exec_cmd2(self.ctl_cmd("srv_stop") + " -b " + bind_ip + " -p " + str(port), throw = True, elog = log)
def start_srv(self, bind_ip, ext_ip, port): exec_cmd2(self.ctl_cmd("srv_start") + " -b " + bind_ip + " -e " + ext_ip + " -p " + str(port), throw = True, elog = log)
def query_dev(self, dev): rc, std_out, std_err, c = exec_cmd2(self.ctl_cmd("dev_query") + " -d " + dev, throw = True, elog = log) return std_out
def rem_dev(self, dev): exec_cmd2(self.ctl_cmd("dev_rem") + " -d " + dev, throw = True, elog = log)
def add_dev(self, dev, fmt = False): task = self.ctl_cmd("dev_add") + " -d " + dev if fmt: task+= " -f" exec_cmd2(task, throw = True, elog = log)
def put_file(file_name): obj_id = cmd.exec_cmd2(DS_CLIENT_PUT_CMD + file_name, throw=True) return obj_id[1][0]
n.neigh_add(m.ip) if __name__=="__main__": i = 0 ips = [] for arg in sys.argv: if i > 0: ips.append(sys.argv[i]) i+= 1 if len(ips) == 0: raise Exception("No ips specified") rootdir = os.path.abspath('amzn_tests') exec_cmd2('rm -rf ' + rootdir, throw = True) exec_cmd2('mkdir ' + rootdir, throw = True) settings.init_logging(log_dir = rootdir, log_name = 'test.log') log = logging.getLogger('main') log.info('starting') nodes = [] for ip in ips: n = AmznNode(log, ip, AmznNodeKeyPath().get(), rootdir) nodes.append(n) try: multi_process([n.prepare_nkfs for n in nodes]) multi_process([n.start_nkfs for n in nodes]) nodes_connect(nodes) log.info('will sleep 20 secs to simulate run') time.sleep(20) #catch hbt
n.neigh_add(m.ip) if __name__ == "__main__": i = 0 ips = [] for arg in sys.argv: if i > 0: ips.append(sys.argv[i]) i += 1 if len(ips) == 0: raise Exception("No ips specified") rootdir = os.path.abspath('amzn_tests') exec_cmd2('rm -rf ' + rootdir, throw=True) exec_cmd2('mkdir ' + rootdir, throw=True) settings.init_logging(log_dir=rootdir, log_name='test.log') log = logging.getLogger('main') log.info('starting') nodes = [] for ip in ips: n = AmznNode(log, ip, AmznNodeKeyPath().get(), rootdir) nodes.append(n) try: multi_process([n.prepare_nkfs for n in nodes]) multi_process([n.start_nkfs for n in nodes]) nodes_connect(nodes) log.info('will sleep 20 secs to simulate run') time.sleep(20) #catch hbt
def get_file(self, obj_id, out_fpath): exec_cmd2(self.cli_cmd("get") + " -f " + out_fpath + " -i " + obj_id, throw = True, elog = log)
def del_file(self, obj_id): exec_cmd2(self.cli_cmd("delete") + " -i " + obj_id, throw = True, elog = log)
def get_file(out_file_name): cmd.exec_cmd2(DS_CLIENT_GET_CMD + out_file_name, throw=True)