def main(): """ Run LOND commands """ argc = len(sys.argv) if argc < 2: cmdline = None elif argc == 2: # lond -h # lond --help # lond command if sys.argv[1] == "-h" or sys.argv[1] == "--help": usage() sys.exit(0) cmdline = sys.argv[1] else: cmdline = "" for arg_index in range(1, argc): if cmdline != "": cmdline += " " cmdline += sys.argv[arg_index] log = clog.get_log(simple_console=True) interact = LondInteract(log) ret = interact.li_loop(cmdline) sys.exit(ret)
def main(): """ Query ESMON influxdb """ # pylint: disable=unused-variable log = clog.get_log() reload(sys) sys.setdefaultencoding("utf-8") if len(sys.argv) != 4: usage() sys.exit(-1) influx_server = sys.argv[1] influx_database = sys.argv[2] query_string = sys.argv[3] identity = time_util.local_strftime(time_util.utcnow(), "%Y-%m-%d-%H_%M_%S") print("Querying influxdb [%s] on server [%s] with query [%s] " % (influx_database, influx_server, query_string)) ret = esmon_influxdb_query(log, influx_server, influx_database, query_string) if ret: log.cl_error("Influxdb query failed") sys.exit(ret) sys.exit(0)
def main(): """ Run the console """ # pylint: disable=unused-variable now = time_util.utcnow() workspace = (LTEST_CONSOLE_LOG_DIR + "/" + time_util.local_strftime(now, ('%Y-%m-%d-%H:%M:%S'))) ret = utils.run("mkdir -p %s" % workspace) if ret.cr_exit_status != 0: logging.error("failed to create directory [%s]", workspace) sys.exit(1) log = clog.get_log(resultsdir=workspace) argc = len(sys.argv) if argc == 1: server = "http://localhost:1234" elif argc == 2: arg = sys.argv[1] if arg == "-h" or arg == "--help": usage() sys.exit(0) server = arg if not server.startswith("http://"): server = "http://" + server if server.count(":") != 2: server = server + ":" + str(ltest_scheduler.TEST_SCHEDULER_PORT) log.cl_info("connecting to server [%s]", server) proxy = xmlrpclib.ServerProxy(server, allow_none=True) tconsole_input_init() tconsole_input_loop(proxy) tconsole_input_fini()
def main(): """ Check the source code files """ log = clog.get_log() for arg in sys.argv[1:]: log.cl_info("checking file [%s]", arg) ret = check_import(log, arg) if ret: log.cl_error("file [%s] imported wrong library", arg) sys.exit(-1) sys.exit(0)
def main(): """ Generate clownfish_test.conf """ # pylint: disable=bare-except log = clog.get_log() reload(sys) sys.setdefaultencoding("utf-8") if len(sys.argv) != 2: usage() sys.exit(-1) config_fpath = sys.argv[1] config = {} config[cstr.CSTR_VIRT_CONFIG] = lvirt.LVIRT_CONFIG config[cstr.CSTR_SKIP_VIRT] = False config[cstr.CSTR_SKIP_INSTALL] = False config[cstr.CSTR_CONFIG_FPATH] = constants.CLOWNFISH_CONFIG install_server = {} install_server[cstr.CSTR_HOSTNAME] = "install_host" install_server[cstr.CSTR_SSH_IDENTITY_FILE] = "/root/.ssh/id_dsa" config[cstr.CSTR_INSTALL_SERVER] = install_server tests = [] for test_funct in clownfish_test.CLOWNFISH_TESTS: tests.append(test_funct.__name__) config[cstr.CSTR_ONLY_TESTS] = tests config_string = ("""# # Configuration file for testing Clownfish from DDN # # Please comment the test names under "%s" if want to skip some tests # # Please set "%s" to true if Clownfish is already installed and # properly running. # # Please set "%s" to true if the virtual machines are already # installed and properly running. # """ % (cstr.CSTR_ONLY_TESTS, cstr.CSTR_SKIP_INSTALL, cstr.CSTR_SKIP_VIRT)) config_string += yaml.dump(config, Dumper=lyaml.YamlDumper, default_flow_style=False) try: with open(config_fpath, 'w') as yaml_file: yaml_file.write(config_string) except: log.cl_error("""Failed to save the config file. To avoid data lose, please save the following config manually:""") sys.stdout.write(config_string) sys.exit(-1) log.cl_info("Config file saved to file [%s]", config_fpath) sys.exit(0)
def main(): """ Install Clownfish """ # pylint: disable=unused-variable log = clog.get_log() missing_dependencies = [] try: import yaml except ImportError: missing_dependencies.append("PyYAML") try: import filelock except ImportError: missing_dependencies.append("python2-filelock") try: import dateutil except ImportError: missing_dependencies.append("python-dateutil") local_host = ssh_host.SSHHost("localhost", local=True) for dependent_rpm in install_common.CLOWNFISH_INSTALL_DEPENDENT_RPMS: ret = local_host.sh_rpm_query(log, dependent_rpm) if ret != 0: missing_dependencies.append(dependent_rpm) if len(missing_dependencies): log.cl_info("installing dependency RPMs of %s", missing_dependencies) ret = install_common.dependency_install(log, local_host, constants.CLOWNFISH_CONFIG, missing_dependencies, "Clownfish", "clownfish-*.iso") if ret: log.cl_error( "not able to install Clownfish because some depdendency " "RPMs are missing and not able to be installed: %s", missing_dependencies) sys.exit(-1) from pyclownfish import clownfish_install_nodeps clownfish_install_nodeps.main()
def main(default_config_fpath, default_log_parent, main_func, usage_func=None, parse_func=None, console_level=logging.INFO, lock=True): """ The main function of a command """ # pylint: disable=too-many-locals,too-many-branches,too-many-statements # pylint: disable=too-many-arguments reload(sys) sys.setdefaultencoding("utf-8") if parse_func is None: options, args = getopt.getopt(sys.argv[1:], "c:i:h", ["config=", "help", "logdir="]) config_fpath = None workspace = None private = None for opt, arg in options: if opt == '-c' or opt == "--config" or opt == "-config": config_fpath = arg elif opt == '-l' or opt == "--logdir" or opt == "-logdir": workspace = arg elif opt == '-h' or opt == "--help" or opt == "-help": usage(usage_func) sys.exit(0) else: usage(usage_func) sys.exit(1) if len(args) != 0: usage(usage_func) sys.exit(1) else: workspace, config_fpath, private = parse_func() if workspace is None: identity = time_util.local_strftime(time_util.utcnow(), "%Y-%m-%d-%H_%M_%S") workspace = default_log_parent + "/" + identity if config_fpath is None: config_fpath = default_config_fpath command = "mkdir -p %s" % workspace retval = utils.run(command) if retval.cr_exit_status != 0: utils.eprint("failed to run command [%s], " "ret = [%d], stdout = [%s], stderr = [%s]" % (command, retval.cr_exit_status, retval.cr_stdout, retval.cr_stderr)) sys.exit(-1) log = clog.get_log(resultsdir=workspace, exclusive=False, console_level=console_level) log.cl_info("starting to run [%s] using config [%s], " "please check [%s] for more log" % (main_func.__name__, config_fpath, workspace)) if not os.path.exists(config_fpath): log.cl_error("config [%s] doesn't exist, using empty config", config_fpath) ret = main_func(log, workspace, None) sys.exit(ret) elif not os.path.isfile(config_fpath): log.cl_error("config [%s] is not a file", config_fpath) sys.exit(-1) config_fname = os.path.basename(config_fpath) save_fpath = workspace + "/" + config_fname log.cl_debug("copying config file from [%s] to [%s]", config_fpath, save_fpath) if config_fpath != save_fpath: shutil.copyfile(config_fpath, save_fpath) if lock: lock_file = config_fpath + ".lock" lock = filelock.FileLock(lock_file) try: with lock.acquire(timeout=0): try: if parse_func is None: ret = main_func(log, workspace, config_fpath) else: ret = main_func(log, workspace, config_fpath, private) except: ret = -1 log.cl_error("exception: %s", traceback.format_exc()) lock.release() except filelock.Timeout: ret = -1 log.cl_error( "someone else is holding lock of file [%s], aborting " "to prevent conflicts", lock_file) else: try: if parse_func is None: ret = main_func(log, workspace, config_fpath) else: ret = main_func(log, workspace, config_fpath, private) except: ret = -1 log.cl_error("exception: %s", traceback.format_exc()) sys.exit(ret)
def main(): """ Start clownfish """ # pylint: disable=unused-variable,too-many-statements,too-many-branches reload(sys) sys.setdefaultencoding("utf-8") argc = len(sys.argv) if argc == 1: # clownfish <localhost> server_url = ("tcp://localhost:%s" % constants.CLOWNFISH_DEFAULT_SERVER_PORT) cmdline = None elif argc == 2: # clownfish_console host # clownfish_console -h # clownfish_console --help if sys.argv[1] == "-h" or sys.argv[1] == "--help": usage() sys.exit(0) server_url = sys.argv[1] if ":" not in server_url: server_url += ":" + str(constants.CLOWNFISH_DEFAULT_SERVER_PORT) server_url = "tcp://" + server_url cmdline = None elif argc == 3: # clownfish_console host cmdline server_url = sys.argv[1] if ":" not in server_url: server_url += ":" + str(constants.CLOWNFISH_DEFAULT_SERVER_PORT) server_url = "tcp://" + server_url cmdline = sys.argv[2] elif argc == 4: # clownfish_console -P 3002 host # clownfish_console host cmdline1 cmdline2 if sys.argv[1] == "-P": port_string = sys.argv[2] host = sys.argv[3] if ":" in host: usage() sys.exit(-1) cmdline = None server_url = "tcp://%s:%s" % (host, port_string) else: server_url = sys.argv[1] if ":" not in server_url: server_url += ":" + str( constants.CLOWNFISH_DEFAULT_SERVER_PORT) server_url = "tcp://" + server_url cmdline = sys.argv[2] + " " + sys.argv[3] elif argc >= 5: # clownfish_console -P 3002 host cmdline... # clownfish_console host cmdline1 cmdline2 cmdline3... if sys.argv[1] == "-P": port_string = sys.argv[2] host = sys.argv[3] if ":" in host: usage() sys.exit(-1) cmdline_start = 4 server_url = "tcp://%s:%s" % (host, port_string) else: server_url = sys.argv[1] if ":" not in server_url: server_url += ":" + str( constants.CLOWNFISH_DEFAULT_SERVER_PORT) server_url = "tcp://" + server_url cmdline_start = 2 cmdline = "" for arg_index in range(cmdline_start, argc): if cmdline != "": cmdline += " " cmdline += sys.argv[arg_index] identity = time_util.local_strftime(time_util.utcnow(), "%Y-%m-%d-%H_%M_%S") workspace = CLOWNFISH_CONSOLE_LOG_DIR + "/" + identity if not os.path.exists(CLOWNFISH_CONSOLE_LOG_DIR): ret = utils.mkdir(CLOWNFISH_CONSOLE_LOG_DIR) if ret: sys.stderr.write("failed to create directory [%s]" % CLOWNFISH_CONSOLE_LOG_DIR) sys.exit(-1) elif not os.path.isdir(CLOWNFISH_CONSOLE_LOG_DIR): sys.stderr.write("[%s] is not a directory" % CLOWNFISH_CONSOLE_LOG_DIR) sys.exit(-1) if not os.path.exists(workspace): ret = utils.mkdir(workspace) if ret: sys.stderr.write("failed to create directory [%s]" % workspace) sys.exit(-1) elif not os.path.isdir(workspace): sys.stderr.write("[%s] is not a directory" % workspace) sys.exit(-1) if cmdline is None: print("Starting Clownfish console to server [%s], " "please check [%s] for more log" % (server_url, workspace)) log = clog.get_log(resultsdir=workspace, simple_console=True) ret = clownfish_console_loop(log, workspace, server_url, cmdline=cmdline) if ret: log.cl_error( "Clownfish console exited with failure, please check [%s] for " "more log", workspace) sys.exit(ret) if cmdline is None: log.cl_info("Clownfish console exited, please check [%s] for more log", workspace) sys.exit(0)