Пример #1
0
    def test_file(self):
        """Function:  test_file

        Description:  Test file log.

        Arguments:

        """

        self.argv_list.extend(["-f", self.log_file2, "-o", self.test_out])
        cmdline = gen_libs.get_inst(sys)
        cmdline.argv = self.argv_list

        with gen_libs.no_std_out():
            check_log.main()

        if os.path.isfile(self.test_out):
            with open(self.test_out) as f_hdlr:
                out_str = f_hdlr.read()

            self.assertEqual(
                out_str, "This is the sixth line\nThis is the seventh line\n")

        else:
            self.assertTrue(False)
Пример #2
0
    def test_initate_dump_i_option(self):
        """Function:  test_initate_dump_i_option

        Description:  Test initiate dump call -i option.

        Arguments:

        """

        cmdline = gen_libs.get_inst(sys)
        els = elastic_class.ElasticSearchDump(self.cfg.host, self.cfg.port)
        self.argv_list.append("-D")
        self.argv_list.append(self.cfg.repo_name)
        self.argv_list.append("-i")
        self.argv_list.append(
            str([x.split() for x in els.els.cat.indices().splitlines()][0][2]))
        cmdline.argv = self.argv_list
        self.elr = elastic_class.ElasticSearchRepo(self.cfg.host,
                                                   self.cfg.port)
        _, _ = self.elr.create_repo(
            self.cfg.repo_name,
            os.path.join(self.cfg.repo_dir, self.cfg.repo_name))
        elastic_db_dump.main()
        dir_path = os.path.join(self.cfg.phy_repo_dir, self.cfg.repo_name,
                                "indices")

        # Count number of databases/indices dumped to repository.
        cnt = len([
            name for name in os.listdir(dir_path)
            if os.path.isdir(os.path.join(dir_path, name))
        ])

        self.assertEqual(cnt, 1)
Пример #3
0
    def test_main_repo_mongo(self, mock_date, mock_host, mock_data):
        """Function:  test_main_repo_mongo

        Description:  Test writing to Mongo database for repo option.

        Arguments:

        """

        mock_date.datetime.strftime.return_value = self.time_str
        mock_data.return_value = self.repo_data
        mock_host.return_value = self.hostname

        cmdline = gen_libs.get_inst(sys)
        self.argv_list3.append("-R")
        cmdline.argv = self.argv_list3

        package_admin.main()

        mongo = mongo_libs.crt_coll_inst(self.mongo_cfg, self.dbn, self.tbl)
        mongo.connect()

        status = \
            True if mongo.coll_find1()["Server"] == self.hostname else False

        mongo_libs.disconnect([mongo])

        self.assertTrue(status)
Пример #4
0
def run_program(args_array, func_dict, **kwargs):

    """Function:  run_program

    Description:  Creates class instance and controls flow of the program.
        Create a program lock to prevent other instantiations from running.

    Arguments:
        (input) args_array -> Dict of command line options and values.
        (input) func_dict -> Dictionary list of functions and options.

    """

    cmdline = gen_libs.get_inst(sys)
    args_array = dict(args_array)
    func_dict = dict(func_dict)
    cfg = gen_libs.load_module(args_array["-c"], args_array["-d"])
    hostname = socket.gethostname().strip().split(".")[0]

    try:
        prog_lock = gen_class.ProgramLock(cmdline.argv, hostname)

        # Find which functions to call.
        for opt in set(args_array.keys()) & set(func_dict.keys()):
            els = elastic_class.ElasticSearchRepo(cfg.host, cfg.port,
                                                  repo=args_array.get("-L"))
            func_dict[opt](els, args_array=args_array, **kwargs)

        del prog_lock

    except gen_class.SingleInstanceException:
        print("WARNING:  elastic_db_repo lock in place for: %s" % (hostname))
Пример #5
0
def main():
    """Function:  main

    Description:  Initializes program-wide used variables and processes command
        line arguments and values.

    Variables:
        opt_multi_list -> contains the options that will have multiple values.
        opt_req_list -> contains the options that are required for the program.
        opt_val_list -> contains options which require values.

    Arguments:
        (input) argv -> Arguments from the command line.

    """

    cmdline = gen_libs.get_inst(sys)
    file_chk_list = ["-i"]
    opt_multi_list = ["-t", "-s"]
    opt_req_list = ["-s", "-t"]
    opt_val_list = ["-s", "-t", "-f", "-i"]

    # Process argument list from command line.
    args_array = arg_parser.arg_parse2(cmdline.argv,
                                       opt_val_list,
                                       multi_val=opt_multi_list)

    if not gen_libs.help_func(args_array, __version__, help_message) \
       and not arg_parser.arg_require(args_array, opt_req_list) \
       and not arg_parser.arg_file_chk(args_array, file_chk_list):
        run_program(args_array)
Пример #6
0
def main():

    """Function:  main

    Description:  Initializes program-wide used variables and processes command
        line arguments and values.

    Variables:
        dir_chk_list -> contains options which will be directories.
        opt_req_list -> contains options that are required for the program.
        opt_val_list -> contains options which require values.

    Arguments:
        (input) argv -> Arguments from the command line.

    """

    cmdline = gen_libs.get_inst(sys)
    dir_chk_list = ["-d"]
    opt_req_list = ["-c", "-d"]
    opt_val_list = ["-c", "-d"]

    # Process argument list from command line.
    args_array = arg_parser.arg_parse2(cmdline.argv, opt_val_list)

    if not gen_libs.help_func(args_array, __version__, help_message):
        if gen_libs.root_run():
            if not arg_parser.arg_require(args_array, opt_req_list) \
               and not arg_parser.arg_dir_chk_crt(args_array, dir_chk_list):
                run_program(args_array)

        else:
            print("Error:  Must run program as root.")
Пример #7
0
def main(**kwargs):
    """Function:  main

    Description:  Initializes program-wide variables and processes command
        line arguments and values.

    Variables:
        dir_chk_list -> contains options which will be directories.
        func_dict -> dictionary list for the function calls or other options.
        opt_req_list -> contains options that are required for the program.
        opt_val_list -> contains options which require values.

    Arguments:
        (input) sys.argv -> Arguments from the command line.
        (input) **kwargs:
            argv_list -> List of arguments from another program.

    """

    cmdline = gen_libs.get_inst(sys)
    cmdline.argv = list(kwargs.get("argv_list", cmdline.argv))
    dir_chk_list = ["-d"]
    func_dict = {"-M": monitor_queue}
    opt_req_list = ["-c", "-d"]
    opt_val_list = ["-c", "-d"]

    # Process argument list from command line.
    args_array = arg_parser.arg_parse2(cmdline.argv, opt_val_list)

    if not gen_libs.help_func(args_array, __version__, help_message) \
       and not arg_parser.arg_require(args_array, opt_req_list) \
       and not arg_parser.arg_dir_chk_crt(args_array, dir_chk_list):
        run_program(args_array, func_dict)
Пример #8
0
def run_program(args_array, **kwargs):

    """Function:  run_program

    Description:  Creates class instance and controls flow of the program.
        Create a program lock to prevent other instantiations from running.

    Arguments:
        (input) args_array -> Dictionary of command line options and values.

    """

    cmdline = gen_libs.get_inst(sys)
    args_array = dict(args_array)
    cfg = gen_libs.load_module(args_array["-c"], args_array["-d"])
    server = gen_class.System()
    server.set_host_name()

    try:
        prog_lock = gen_class.ProgramLock(cmdline.argv, server.host_name)
        proc_data = get_svr_info(server)
        proc_data.update(get_svr_mem())
        proc_data["processes"] = get_proc_mem(cfg.memory_threshold)
        post_process(proc_data, args_array, cfg)
        del prog_lock

    except gen_class.SingleInstanceException:
        print("WARNING:  server_usage lock in place for: %s"
              % (server.host_name))
def main():

    """Function:  main

    Description:  Initializes program-wide used variables and processes command
        line arguments and values.

    Variables:
        dir_chk_list -> contains options which will be directories.
        file_chk_list -> contains the options which will have files included.
        file_crt_list -> contains options which require files to be created.
        func_dict -> dictionary list for the function calls or other options.
        opt_con_req_list -> contains the options that require other options.
        opt_def_dict -> contains options with their default values.
        opt_or_dict_list -> contains list of options that are OR and required.
        opt_req_list -> contains the options that are required for the program.
        opt_val_list -> contains options which require values.

    Arguments:
        (input) argv -> Arguments from the command line.

    """

    cmdline = gen_libs.get_inst(sys)
    dir_chk_list = ["-d", "-p"]
    file_chk_list = ["-o"]
    file_crt_list = ["-o"]
    func_dict = {"-A": ["-C", "-S", "-E", "-T", "-O"], "-B": rpt_mst_log,
                 "-D": rpt_slv_log, "-C": chk_mst_log, "-S": chk_slv_thr,
                 "-E": chk_slv_err, "-T": chk_slv_time, "-O": chk_slv_other}
    opt_con_req_list = {"-b": ["-m"], "-u": ["-t"], "-A": ["-s"], "-B": ["-c"],
                        "-C": ["-c", "-s"], "-D": ["-s"], "-E": ["-s"],
                        "-O": ["-s"], "-T": ["-c", "-s"]}
    opt_def_dict = {"-b": "sysmon:mysql_rep_lag"}
    opt_multi_list = ["-u", "-t"]
    opt_or_dict_list = {"-c": ["-s"]}
    opt_req_list = ["-d"]
    opt_val_list = ["-d", "-c", "-p", "-s", "-o", "-b", "-m", "-u", "-t", "-y"]

    # Process argument list from command line.
    args_array = arg_parser.arg_parse2(cmdline.argv, opt_val_list,
                                       opt_def_dict, multi_val=opt_multi_list)

    if not gen_libs.help_func(args_array, __version__, help_message) \
       and arg_parser.arg_req_or_lst(args_array, opt_or_dict_list) \
       and not arg_parser.arg_require(args_array, opt_req_list) \
       and arg_parser.arg_cond_req(args_array, opt_con_req_list) \
       and not arg_parser.arg_dir_chk_crt(args_array, dir_chk_list) \
       and not arg_parser.arg_file_chk(args_array, file_chk_list,
                                       file_crt_list):

        try:
            proglock = gen_class.ProgramLock(cmdline.argv,
                                             args_array.get("-y", ""))
            run_program(args_array, func_dict)
            del proglock

        except gen_class.SingleInstanceException:
            print("WARNING:  lock in place for mysql_rep_admin with id of: %s"
                  % (args_array.get("-y", "")))
Пример #10
0
    def test_stdin_marker_empty(self, mock_atty):
        """Function:  test_stdin_marker_empty

        Description:  Test with standard in with an empty marker file.

        Arguments:

        """

        mock_atty.isatty.return_value = False
        self.argv_list.extend([
            "-o", self.test_out, "-n", "-z", "-m",
            os.path.join(self.test_path, self.base_marker3)
        ])
        cmdline = gen_libs.get_inst(sys)
        cmdline.argv = self.argv_list

        check_log.main()

        if os.path.isfile(self.test_out):
            with open(self.test_out) as f_hdlr:
                out_str = f_hdlr.read().rstrip()

            self.assertEqual(out_str, "Line one\nLine two")

        else:
            self.assertTrue(False)
Пример #11
0
    def test_main_repo_mongo_file(self, mock_date, mock_host, mock_data,
                                  mock_distro):
        """Function:  test_main_repo_mongo_file

        Description:  Test writing to Mongo database and to a file for repo
            option.

        Arguments:

        """

        mock_date.datetime.strftime.return_value = self.time_str
        mock_data.return_value = self.repo_data
        mock_host.return_value = self.hostname
        mock_distro.return_value = self.distro

        cmdline = gen_libs.get_inst(sys)
        self.argv_list.append("-R")
        cmdline.argv = self.argv_list

        package_admin.main()

        mongo = mongo_libs.crt_coll_inst(self.mongo_cfg, self.dbn, self.tbl)
        mongo.connect()

        if mongo.coll_find1()["Server"] == self.hostname:
            status = filecmp.cmp(self.out_file, self.repo_non_json_file)

        else:
            status = False

        mongo_libs.disconnect([mongo])

        self.assertTrue(status)
Пример #12
0
def main():
    """Function:  main

    Description:  Initializes program-wide used variables and processes command
        line arguments and values.

    Variables:
        dir_chk_list -> contains options which will be directories.
        func_dict -> dictionary list for the function calls or other options.
        opt_req_list -> contains options that are required for the program.
        opt_val_list -> contains options which require values.
        opt_xor_dict -> contains dict with key that is xor with it's values.

    Arguments:
        (input) argv -> Arguments from the command line.

    """

    cmdline = gen_libs.get_inst(sys)
    dir_chk_list = ["-d"]
    func_dict = {"-M": process_message, "-C": check_nonprocess}
    opt_req_list = ["-c", "-d"]
    opt_val_list = ["-c", "-d", "-y"]
    opt_xor_dict = {"-M": ["-C"], "-C": ["-M"]}

    # Process argument list from command line.
    args_array = arg_parser.arg_parse2(cmdline.argv, opt_val_list)

    if not gen_libs.help_func(args_array, __version__, help_message) \
       and not arg_parser.arg_require(args_array, opt_req_list) \
       and arg_parser.arg_xor_dict(args_array, opt_xor_dict) \
       and not arg_parser.arg_dir_chk_crt(args_array, dir_chk_list):
        run_program(args_array, func_dict)
Пример #13
0
    def test_main_repo_file_json(self, mock_date, mock_host, mock_data,
                                 mock_distro):
        """Function:  test_main_repo_file_json

        Description:  Test writing to file in JSON format for repo option.

        Arguments:

        """

        mock_date.datetime.strftime.return_value = self.time_str
        mock_data.return_value = self.repo_data
        mock_host.return_value = self.hostname
        mock_distro.return_value = self.distro

        cmdline = gen_libs.get_inst(sys)
        self.argv_list2.append("-R")
        self.argv_list2.append("-f")
        cmdline.argv = self.argv_list2

        package_admin.main()

        status = filecmp.cmp(self.out_file, self.repo_json_file)

        self.assertTrue(status)
Пример #14
0
def run_program(args_array, func_dict, **kwargs):
    """Function:  run_program

    Description:  Creates class instance and controls flow of the program.
        Create a program lock to prevent other instantiations from running.

    Arguments:
        (input) args_array -> Dict of command line options and values.
        (input) func_dict -> Dictionary list of functions and options.
        (input) **kwargs:
            status_call -> Contains class method names for the '-D' option.
            check_call -> Contains class method names for the '-C' option.

    """

    cmdline = gen_libs.get_inst(sys)
    args_array = dict(args_array)
    func_dict = dict(func_dict)
    cfg = gen_libs.load_module(args_array["-c"], args_array["-d"])

    try:
        prog_lock = gen_class.ProgramLock(cmdline.argv, cfg.host)

        # Intersect args_array & func_dict to find which functions to call.
        for opt in set(args_array.keys()) & set(func_dict.keys()):
            els = elastic_class.ElasticSearchStatus(cfg.host, cfg.port,
                                                    **kwargs)
            func_dict[opt](els, args_array=args_array, cfg=cfg, **kwargs)

        del prog_lock

    except gen_class.SingleInstanceException:
        print("Warning:  elastic_db_admin lock in place for: %s" % (cfg.host))
Пример #15
0
    def setUp(self):
        """Function:  setUp

        Description:  Initialization for unit testing.

        Arguments:

        """

        rem = gen_libs.get_inst(re)
        self.master = Server()
        self.slave = Slave()
        self.filehandler = ["binlog1"]
        self.binlog_files = [{"Log_name": "binlog1"}, {"Log_name": "binlog2"}]
        self.binlog_files2 = [{
            "Log_name": "binlog1"
        }, {
            "Log_name": "binlog2"
        }, {
            "Log_name": "binlog3"
        }]
        self.opt_arg_list = ["--force-read", "--read-from-remote-server"]
        self.start_dt = "start_datetime_format"
        self.stop_dt = "end_datetime_format"
        self.fetch_log = ["data line here"]

        self.match1 = rem.match(r"(?P<type>\w+)\s+(?P<epos>\w+)", "Start line")
        self.match2 = rem.match(r"(?P<type>\w+)\s+(?P<epos>\w+)", "Query 123")
Пример #16
0
    def test_create_repo(self):
        """Function:  test_create_repo

        Description:  Test create repo call.

        Arguments:

        """

        cmdline = gen_libs.get_inst(sys)
        self.argv_list.append("-C")
        self.argv_list.append(self.repo_name)
        self.argv_list.append("-l")
        self.argv_list.append(self.repo_dir)
        cmdline.argv = self.argv_list
        elastic_db_repo.main()
        self.els = elastic_class.ElasticSearchRepo(self.cfg.host,
                                                   self.cfg.port,
                                                   repo=self.repo_name)

        if self.repo_name in self.els.repo_dict:
            status = True

        else:
            status = False

        self.assertTrue(status)
Пример #17
0
    def test_list_dumps(self):
        """Function:  test_list_dumps

        Description:  Test list dumps call.

        Arguments:

        """

        global SKIP_PRINT
        global PRT_TEMPLATE
        global ERROR_PRINT

        cmdline = gen_libs.get_inst(sys)
        self.argv_list.append("-L")
        self.argv_list.append(self.repo_name)
        cmdline.argv = self.argv_list
        self.els = elastic_class.ElasticSearchRepo(self.cfg.host,
                                                   self.cfg.port)
        status, msg = self.els.create_repo(self.repo_name, self.repo_dir)

        if status:
            print(ERROR_PRINT)
            print(PRT_TEMPLATE % (msg))
            self.skipTest(SKIP_PRINT)

        with gen_libs.no_std_out():
            self.assertFalse(elastic_db_repo.main())
Пример #18
0
    def test_disk_usage(self):
        """Function:  test_disk_usage

        Description:  Test disk usage call.

        Arguments:

        """

        global SKIP_PRINT
        global PRT_TEMPLATE
        global ERROR_PRINT

        cmdline = gen_libs.get_inst(sys)
        self.argv_list.append("-U")
        cmdline.argv = self.argv_list
        self.els = elastic_class.ElasticSearchRepo(self.cfg.host,
                                                   self.cfg.port)
        status, msg = self.els.create_repo(self.repo_name, self.repo_dir)

        if status:
            print(ERROR_PRINT)
            print(PRT_TEMPLATE % (msg))
            self.skipTest(SKIP_PRINT)

        # Wait until the repo dir has been created.
        while True:
            if not os.path.isdir(self.phy_repo_dir):
                time.sleep(1)

            else:
                break

        with gen_libs.no_std_out():
            self.assertFalse(elastic_db_repo.main())
Пример #19
0
def main():
    """Function:  main

    Description:  Initializes program-wide used variables and processes command
        line arguments and values.

    Variables:
        dir_chk_list -> contains options which will be directories.
        func_dict -> dictionary list for the function calls or other options.
        opt_con_req_list -> contains the options that require other options.
        xor_noreq_list -> contains options that are XOR, but are not required.
        ord_prec_array -> holds options in order of precedence to be executed.
        opt_req_list -> contains the options that are required for the program.
        opt_val_list -> contains options which require values.

    Arguments:
        (input) argv -> Arguments from the command line.

    """

    cmdline = gen_libs.get_inst(sys)
    dir_chk_list = ["-d", "-l", "-o"]
    func_dict = {
        "-F": flush_log_bkp,
        "-K": missing_log,
        "-M": bkp_log_miss,
        "-A": bkp_log_all,
        "-S": purge_log_day,
        "-R": purge_log_name
    }
    opt_con_req_list = {
        "-F": ["-o", "-l"],
        "-M": ["-o", "-l"],
        "-A": ["-o", "-l"],
        "-K": ["-o"]
    }
    xor_noreq_list = {"-S": "-R", "-M": "-A"}
    ord_prec_list = ["-F", "-K", "-M", "-A", "-S", "-R"]
    opt_req_list = ["-c", "-d"]
    opt_val_list = ["-c", "-d", "-l", "-o", "-R", "-S", "-y"]

    # Process argument list from command line.
    args_array = arg_parser.arg_parse2(cmdline.argv, opt_val_list)

    if not gen_libs.help_func(args_array, __version__, help_message) \
       and not arg_parser.arg_require(args_array, opt_req_list) \
       and arg_parser.arg_noreq_xor(args_array, xor_noreq_list) \
       and arg_parser.arg_cond_req(args_array, opt_con_req_list) \
       and not arg_parser.arg_dir_chk_crt(args_array, dir_chk_list):

        try:
            prog_lock = gen_class.ProgramLock(cmdline.argv,
                                              args_array.get("-y", ""))
            run_program(args_array, func_dict, ord_prec_list)
            del prog_lock

        except gen_class.SingleInstanceException:
            print("WARNING:  lock in place for mysql_binlog with id of: %s" %
                  (args_array.get("-y", "")))
Пример #20
0
def main():
    """Function:  main

    Description:  Initializes program-wide variables, processes command line
        arguments, sets up pidfile, and contols the running of the daemon.

    Variables:
        opt_req_list -> contains options that are required for the program.
        opt_val_list -> contains options which require values.

    Arguments:
        (input) sys.argv -> Arguments from the command line.

    """

    cmdline = gen_libs.get_inst(sys)
    opt_val_list = ["-a", "-c", "-d"]
    opt_req_list = ["-a", "-c", "-d"]
    proc_name = "daemon_rmq_2_sy"

    # Process argument list from command line.
    args_array = arg_parser.arg_parse2(cmdline.argv, opt_val_list)
    f_name = "rmq2sysmon_daemon_" + args_array.get("-c", "") + ".pid"
    pid_file = os.path.join(gen_libs.get_base_dir(__file__), "tmp", f_name)
    daemon = Rmq2SysmonDaemon(pid_file, argv_list=cmdline.argv)

    if not arg_parser.arg_require(args_array, opt_req_list):

        if args_array["-a"] == "start":

            if os.path.isfile(pid_file) and is_active(pid_file, proc_name):

                print("Warning:  Pidfile %s exists and process is running." %
                      (pid_file))

            elif os.path.isfile(pid_file):
                os.remove(pid_file)
                daemon.start()

            else:
                daemon.start()

        elif args_array["-a"] == "stop":
            daemon.stop()

        elif args_array["-a"] == "restart":
            daemon.restart()

        else:
            print("Unknown command")
            sys.exit(2)

        sys.exit(0)

    else:
        print("Usage: %s -a start|stop|restart -c module -d directory/config \
{rmq_2_sysmon options}" % cmdline.argv[0])
        sys.exit(2)
Пример #21
0
def main():
    """Function:  main

    Description:  Initializes program-wide used variables and processes command
        line arguments and values.

    Variables:
        dir_chk_list -> contains options which will be directories.
        ign_db_tbl -> contains list of databases and tables to be ignored.
        opt_con_req_list -> contains the options that require other options.
        opt_multi_list -> contains the options that will have multiple values.
        opt_req_list -> contains the options that are required for the program.
        opt_req_xor_list -> contains a list of options that are required XOR.
        opt_val_list -> contains options which require values.
        sys_ign_db -> contains a list of system databases to be ignored.

    Arguments:
        (input) argv -> Arguments from the command line.

    """

    cmdline = gen_libs.get_inst(sys)
    dir_chk_list = ["-d"]
    ign_db_tbl = {
        "mysql": [
            "innodb_index_stats", "innodb_table_stats", "slave_master_info",
            "slave_relay_log_info", "slave_worker_info"
        ]
    }
    opt_con_req_list = {"-t": ["-B"], "-s": ["-e"], "-u": ["-e"]}
    opt_multi_list = ["-B", "-e", "-s", "-t"]
    opt_req_list = ["-r", "-c", "-d"]
    opt_req_xor_list = {"-A": "-B"}
    opt_val_list = ["-r", "-c", "-d", "-e", "-s", "-y"]
    sys_ign_db = ["performance_schema", "information_schema"]

    # Process argument list from command line.
    args_array = arg_parser.arg_parse2(cmdline.argv,
                                       opt_val_list,
                                       multi_val=opt_multi_list)

    if not gen_libs.help_func(args_array, __version__, help_message) \
       and arg_parser.arg_req_xor(args_array, opt_req_xor_list) \
       and not arg_parser.arg_require(args_array, opt_req_list) \
       and arg_parser.arg_cond_req(args_array, opt_con_req_list) \
       and not arg_parser.arg_dir_chk_crt(args_array, dir_chk_list):

        try:
            prog_lock = gen_class.ProgramLock(cmdline.argv,
                                              args_array.get("-y", ""))
            run_program(args_array, sys_ign_db, ign_db_tbl=ign_db_tbl)
            del prog_lock

        except gen_class.SingleInstanceException:
            print("WARNING:  lock in place for mysql_rep_cmp with id of: %s" %
                  (args_array.get("-y", "")))
Пример #22
0
def fetch_binlog(server,
                 start_dt=None,
                 stop_dt=None,
                 binlog_files=None,
                 opt_arg_list=None,
                 bin_path="",
                 **kwargs):
    """Function:  fetch_binlog

    Description:  Returns a list of binary log entries based on the binary log
        file names passed and/or the start and/or stop datetimes.
        Returns the entries as a file.

    Arguments:
        (input) server -> Server instance.
        (input) start_dt -> Start datetime.
        (input) stop_dr -> Stop datetime.
        (input) binlog_files -> List of binary log names.
        (input) opt_arg_list ->  Arguments to be added to command line.
        (input) bin_path -> Path to Mysql binary directory.
        (output) -> File handler to list of log entries.

    """

    subp = gen_libs.get_inst(subprocess)

    if opt_arg_list is None:
        opt_arg_list = list()

    else:
        opt_arg_list = list(opt_arg_list)

    if binlog_files is None:
        # List of binary logs.
        binlog_files = [
            row["Log_name"] for row in mysql_libs.fetch_logs(server)
        ]

    else:
        binlog_files = list(binlog_files)

    cmd = mysql_libs.crt_cmd(server, bin_path + "mysqlbinlog")

    if opt_arg_list:
        for arg in opt_arg_list:
            cmd = cmds_gen.add_cmd(cmd, arg=arg)

    if start_dt:
        cmd = cmds_gen.add_cmd(cmd, arg="--start-datetime=%s" % (start_dt))

    if stop_dt:
        cmd = cmds_gen.add_cmd(cmd, arg="--stop-datetime=%s" % (stop_dt))

    # Return a file handler with log entries.
    return iter(subp.Popen(cmd + binlog_files, stdout=subp.PIPE).stdout)
Пример #23
0
def main():
    """Function:  main

    Description:  Initializes program-wide used variables and processes command
        line arguments and values.

    Variables:
        file_chk_list -> contains the options which will have files included.
        file_crt_list -> contains options which require files to be created.
        opt_con_req_dict -> contains options requiring other options.
        opt_multi_list -> contains the options that will have multiple values.
        opt_val_list -> contains options which require values.
        opt_valid_val -> contains options with their valid values.

    Arguments:
        (input) argv -> Arguments from the command line.

    """

    file_chk_list = ["-f", "-i", "-m", "-F"]
    file_crt_list = ["-m"]
    opt_con_req_dict = {"-c": ["-m"], "-s": ["-t"]}
    opt_multi_list = ["-f", "-s", "-t", "-S"]
    opt_val_list = ["-i", "-m", "-o", "-s", "-t", "-y", "-F", "-S", "-k", "-g"]
    opt_valid_val = {"-k": ["and", "or"], "-g": ["a", "w"]}
    cmdline = gen_libs.get_inst(sys)

    # Process argument list from command line.
    args_array = arg_parser.arg_parse2(cmdline.argv,
                                       opt_val_list,
                                       multi_val=opt_multi_list)

    # Set default search logic.
    if "-S" in args_array.keys() and "-k" not in args_array.keys():
        args_array["-k"] = "or"

    # Set default write file mode.
    if "-g" not in args_array.keys():
        args_array["-g"] = "w"

    if not gen_libs.help_func(args_array, __version__, help_message) \
       and arg_parser.arg_cond_req_or(args_array, opt_con_req_dict) \
       and not arg_parser.arg_file_chk(args_array, file_chk_list,
                                       file_crt_list) \
       and arg_parser.arg_valid_val(args_array, opt_valid_val):

        try:
            prog_lock = gen_class.ProgramLock(cmdline.argv,
                                              args_array.get("-y", ""))
            run_program(args_array)
            del prog_lock

        except gen_class.SingleInstanceException:
            print("WARNING:  lock in place for check_log with id of: %s" %
                  (args_array.get("-y", "")))
Пример #24
0
def run_program(args_array, func_dict, **kwargs):
    """Function:  run_program

    Description:  Creates class instance and controls flow of the program.
        Set a program lock to prevent other instantiations from running.

    Arguments:
        (input) args_array -> Dict of command line options and values.
        (input) func_dict -> Dict of function calls and associated options.

    """

    cmdline = gen_libs.get_inst(sys)
    args_array = dict(args_array)
    func_dict = dict(func_dict)
    cfg = gen_libs.load_module(args_array["-c"], args_array["-d"])
    cfg.mongo = gen_libs.load_module(cfg.mongo_cfg, args_array["-d"])
    cfg, status_flag, err_msg = validate_create_settings(cfg)

    if status_flag:
        log = gen_class.Logger(cfg.log_file, cfg.log_file, "INFO",
                               "%(asctime)s %(levelname)s %(message)s",
                               "%Y-%m-%dT%H:%M:%SZ")
        str_val = "=" * 80
        log.log_info("%s:%s Initialized" % (cfg.host, cfg.exchange_name))
        log.log_info("%s" % (str_val))
        log.log_info("Exchange Name:  %s" % (cfg.exchange_name))
        log.log_info("Queue Configuration:")

        for queue in cfg.queue_list:
            log.log_info("\tQueue Name:  %s, Routing Key: %s" %
                         (queue["queue"], queue["routing_key"]))

        log.log_info("To Email:  %s" % (cfg.to_line))
        log.log_info("%s" % (str_val))

        try:
            flavor_id = cfg.exchange_name
            prog_lock = gen_class.ProgramLock(cmdline.argv, flavor_id)

            # Intersect args_array & func_dict to find which functions to call.
            for opt in set(args_array.keys()) & set(func_dict.keys()):
                func_dict[opt](cfg, log, **kwargs)

            del prog_lock

        except gen_class.SingleInstanceException:
            log.log_warn("rmq_metadata lock in place for: %s" % (flavor_id))

        log.log_close()

    else:
        print("Error:  Problem in configuration file or directory setup.")
        print(err_msg)
Пример #25
0
def main():
    """Function:  main

    Description:  Initializes program-wide used variables and processes command
        line arguments and values.

    Variables:
        dir_chk_list -> contains options which will be directories.
        func_dict -> dictionary list for the function calls or other options.
        opt_arg_list -> contains arguments to add to command line by default.
        opt_con_req_list -> contains the options that require other options.
        opt_req_list -> contains the options that are required for the program.
        opt_val_list -> contains options which require values.
        opt_valid_val -> contains list of types of values to be validated.
        opt_xor_dict -> contains options which are XOR with its values.

    Arguments:
        (input) argv -> Arguments from the command line.

    """

    cmdline = gen_libs.get_inst(sys)
    dir_chk_list = ["-d", "-p"]
    func_dict = {"-L": fetch_log_pos, "-D": fetch_log_entries, "-R": load_log}
    opt_arg_list = ["--force-read", "--read-from-remote-server"]
    opt_con_req_list = {"-R": ["-e"]}
    opt_req_list = ["-c", "-d"]
    opt_val_list = ["-c", "-e", "-d", "-f", "-g", "-p", "-s", "-t", "-y"]
    opt_valid_val = {
        "-s": gen_libs.validate_date,
        "-t": gen_libs.validate_date
    }
    opt_xor_dict = {"-L": ["-D", "-R"], "-D": ["-L", "-R"], "-R": ["-D", "-L"]}

    # Process argument list from command line.
    args_array = arg_parser.arg_parse2(cmdline.argv, opt_val_list)

    if not gen_libs.help_func(args_array, __version__, help_message) \
       and not arg_parser.arg_require(args_array, opt_req_list) \
       and arg_parser.arg_xor_dict(args_array, opt_xor_dict) \
       and not arg_parser.arg_dir_chk_crt(args_array, dir_chk_list) \
       and arg_parser.arg_validate(args_array, opt_valid_val) \
       and arg_parser.arg_cond_req(args_array, opt_con_req_list):

        try:
            prog_lock = gen_class.ProgramLock(cmdline.argv,
                                              args_array.get("-y", ""))
            run_program(args_array, func_dict, opt_arg_list)
            del prog_lock

        except gen_class.SingleInstanceException:
            print(
                "WARNING:  lock in place for mysql_log_admin with id of: %s" %
                (args_array.get("-y", "")))
def main():
    """Function:  main

    Description:  Initializes program-wide used variables and processes command
        line arguments and values.

    Variables:
        dir_chk_list -> contains options which will be directories.
        func_dict -> dictionary list for the function calls or other options.
        opt_req_list -> contains the options that are required for the program.
        opt_val_list -> contains options which require values.
        opt_xor_dict -> contains dict with key that is xor with it's values.

    Arguments:
        (input) argv -> Arguments from the command line.

    """

    cmdline = gen_libs.get_inst(sys)
    dir_chk_list = ["-d"]
    func_dict = {
        "-B": show_best_slave,
        "-D": show_slave_delays,
        "-F": promote_best_slave,
        "-G": promote_designated_slave
    }
    opt_req_list = ["-d", "-s"]
    opt_val_list = ["-d", "-s", "-G", "-y"]
    opt_xor_dict = {
        "-B": ["-D", "-F", "-G"],
        "-D": ["-B", "-F", "-G"],
        "-F": ["-B", "-D", "-G"],
        "-G": ["-B", "-D", "-F"]
    }

    # Process argument list from command line.
    args_array = arg_parser.arg_parse2(cmdline.argv, opt_val_list)

    if not gen_libs.help_func(args_array, __version__, help_message) \
       and not arg_parser.arg_require(args_array, opt_req_list) \
       and arg_parser.arg_xor_dict(args_array, opt_xor_dict) \
       and not arg_parser.arg_dir_chk_crt(args_array, dir_chk_list):

        try:
            prog_lock = gen_class.ProgramLock(cmdline.argv,
                                              args_array.get("-y", ""))
            run_program(args_array, func_dict)
            del prog_lock

        except gen_class.SingleInstanceException:
            print(
                "WARNING:  Lock in place for mysql_rep_failover with id: %s" %
                (args_array.get("-y", "")))
Пример #27
0
def main():
    """Function:  main

    Description:  Initializes program-wide used variables and processes command
        line arguments and values.

    Variables:
        dir_chk_list -> contains options which will be directories.
        func_dict -> dictionary list for the function calls or other options.
        opt_con_req_dict -> contains options requiring other options.
        opt_multi_list -> contains the options that will have multiple values.
        opt_req_list -> contains options that are required for the program.
        opt_val -> List of options that allow 0 or 1 value for option.
        opt_val_list -> contains options which require values.
        opt_xor_dict -> contains dict with key that is xor with it's values.

    Arguments:
        (input) argv -> Arguments from the command line.

    """

    cmdline = gen_libs.get_inst(sys)
    dir_chk_list = ["-d"]
    func_dict = {
        "-C": create_repo,
        "-D": initate_dump,
        "-L": list_dumps,
        "-R": list_repos
    }
    opt_con_req_dict = {"-C": ["-l"], "-i": ["-D"]}
    opt_multi_list = ["-i"]
    opt_req_list = ["-c", "-d"]
    opt_val = ["-D", "-L"]
    opt_val_list = ["-c", "-d", "-i", "-l", "-C"]
    opt_xor_dict = {
        "-C": ["-D", "-L", "-R"],
        "-D": ["-C", "-L", "-R"],
        "-L": ["-C", "-D", "-R"],
        "-R": ["-C", "-D", "-L"]
    }

    # Process argument list from command line.
    args_array = arg_parser.arg_parse2(cmdline.argv,
                                       opt_val_list,
                                       opt_val=opt_val,
                                       multi_val=opt_multi_list)

    if not gen_libs.help_func(args_array, __version__, help_message) \
       and not arg_parser.arg_require(args_array, opt_req_list) \
       and arg_parser.arg_xor_dict(args_array, opt_xor_dict) \
       and arg_parser.arg_cond_req_or(args_array, opt_con_req_dict) \
       and not arg_parser.arg_dir_chk_crt(args_array, dir_chk_list):
        run_program(args_array, func_dict)
Пример #28
0
    def test_delete_dump(self):
        """Function:  test_delete_dump

        Description:  Test delete dump call.

        Arguments:

        """

        global SKIP_PRINT
        global PRT_TEMPLATE
        global ERROR_PRINT

        cmdline = gen_libs.get_inst(sys)
        self.els = elastic_class.ElasticSearchRepo(self.cfg.host,
                                                   self.cfg.port)
        status, msg = self.els.create_repo(self.repo_name, self.repo_dir)

        if status:
            print(ERROR_PRINT)
            print(PRT_TEMPLATE % (msg))
            self.skipTest(SKIP_PRINT)

        els = elastic_class.ElasticSearchDump(self.cfg.host,
                                              repo=self.repo_name)
        els.dump_name = self.dump_name
        status, msg = els.dump_db()

        if status:
            print("Error detected for dump in repository: %s" %
                  (self.repo_name))
            print(PRT_TEMPLATE % (msg))
            self.skipTest("Dump failed")

        self.argv_list.append("-S")
        self.argv_list.append(self.dump_name)
        self.argv_list.append("-r")
        self.argv_list.append(self.repo_name)
        cmdline.argv = self.argv_list
        elastic_db_repo.main()
        self.els = elastic_class.ElasticSearchRepo(self.cfg.host,
                                                   self.cfg.port,
                                                   repo=self.repo_name)

        if self.dump_name not in elastic_class.get_dump_list(
                self.els.els, self.repo_name):
            status = True

        else:
            status = False

        self.assertTrue(status)
Пример #29
0
def main():
    """Function:  main

    Description:  Initializes program-wide used variables and processes command
        line arguments and values.

    Variables:
        dir_chk_list -> contains options which will be directories.
        file_chk_list -> contains the options which will have files included.
        file_crt_list -> contains options which require files to be created.
        func_dict -> dictionary list for the function calls or other options.
        opt_con_req_list -> contains the options that require other options.
        opt_def_dict -> contains options with their default values.
        opt_req_list -> contains the options that are required for the program.
        opt_val_list -> contains options which require values.

    Arguments:
        (input) argv -> Arguments from the command line.

    """

    cmdline = gen_libs.get_inst(sys)
    dir_chk_list = ["-d"]
    file_chk_list = ["-o"]
    file_crt_list = ["-o"]
    func_dict = {
        "-L": chk_rep_lag,
        "-M": fetch_members,
        "-S": chk_rep_stat,
        "-P": fetch_priority,
        "-T": prt_rep_stat,
        "-N": node_chk
    }
    opt_con_req_list = {"-i": ["-m"], "-s": ["-e"]}
    opt_def_dict = {"-j": False, "-i": "sysmon:mongo_rep_lag"}
    opt_multi_list = ["-e", "-s"]
    opt_req_list = ["-c", "-d"]
    opt_val_list = ["-c", "-d", "-i", "-m", "-o", "-e", "-s"]

    # Process argument list from command line.
    args_array = arg_parser.arg_parse2(cmdline.argv,
                                       opt_val_list,
                                       opt_def_dict,
                                       multi_val=opt_multi_list)

    if not gen_libs.help_func(args_array, __version__, help_message) \
       and not arg_parser.arg_require(args_array, opt_req_list) \
       and arg_parser.arg_cond_req(args_array, opt_con_req_list) \
       and not arg_parser.arg_dir_chk_crt(args_array, dir_chk_list) \
       and not arg_parser.arg_file_chk(args_array, file_chk_list,
                                       file_crt_list):
        run_program(args_array, func_dict)
Пример #30
0
def main():
    """Function:  main

    Description:  Initializes program-wide used variables and processes command
        line arguments and values.

    Variables:
        dir_chk_list -> contains options which will be directories.
        file_chk_list -> contains the options which will have files included.
        file_crt_list -> contains options which require files to be created.
        func_dict -> dictionary list for the function calls or other options.
        opt_def_dict -> contains options with their default values.
        opt_con_req_list -> contains the options that require other options.
        opt_multi_list -> contains the options that will have multiple values.
        opt_val_list -> contains options which require values.

    Arguments:
        (input) argv -> Arguments from the command line.

    """

    cmdline = gen_libs.get_inst(sys)
    dir_chk_list = ["-d"]
    file_chk_list = ["-o"]
    file_crt_list = ["-o"]
    func_dict = {"-L": list_ins_pkg, "-U": list_upd_pkg, "-R": list_repo}
    opt_def_dict = {"-i": "sysmon:server_pkgs"}
    opt_con_req_list = {"-i": ["-c", "-d"], "-s": ["-e"], "-u": ["-e"]}
    opt_multi_list = ["-e", "-s"]
    opt_val_list = ["-c", "-d", "-i", "-o", "-e", "-s", "-y"]

    # Process argument list from command line.
    args_array = arg_parser.arg_parse2(cmdline.argv,
                                       opt_val_list,
                                       opt_def_dict,
                                       multi_val=opt_multi_list)

    if not gen_libs.help_func(args_array, __version__, help_message) \
       and arg_parser.arg_cond_req(args_array, opt_con_req_list) \
       and not arg_parser.arg_dir_chk_crt(args_array, dir_chk_list) \
       and not arg_parser.arg_file_chk(args_array, file_chk_list,
                                       file_crt_list):

        try:
            proglock = gen_class.ProgramLock(cmdline.argv,
                                             args_array.get("-y", ""))
            run_program(args_array, func_dict)
            del proglock

        except gen_class.SingleInstanceException:
            print("WARNING:  Lock in place for package_admin with id of: %s" %
                  (args_array.get("-y", "")))