Exemple #1
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)
Exemple #2
0
    def setUp(self):
        """Function:  setUp

        Description:  Initialization for unit testing.

        Arguments:

        """

        self.base_dir = "test/integration/elastic_db_dump"
        self.test_path = os.path.join(os.getcwd(), self.base_dir)
        self.config_path = os.path.join(self.test_path, "config")
        self.cfg = gen_libs.load_module("elastic", self.config_path)
        self.phy_repo_dir = os.path.join(self.cfg.phy_repo_dir,
                                         self.cfg.repo_name)
        self.elr = elastic_class.ElasticSearchRepo(self.cfg.host,
                                                   self.cfg.port)

        if self.elr.repo_dict:
            print("ERROR: Test environment not clean - repositories exist.")
            self.skipTest("Pre-conditions not met.")

        else:
            _, _ = self.elr.create_repo(
                self.cfg.repo_name,
                os.path.join(self.cfg.repo_dir, self.cfg.repo_name))

            self.els = elastic_class.ElasticSearchDump(self.cfg.host,
                                                       self.cfg.port,
                                                       repo=self.cfg.repo_name)
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"])

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

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

        del prog_lock

    except gen_class.SingleInstanceException:
        print("WARNING:  elastic_db_dump lock in place for: %s" % (cfg.host))
    def test_initate_dump_i_option(self):
        """Function:  test_initate_dump_i_option

        Description:  Test initiate dump call -i option.

        Arguments:

        """

        els = elastic_class.ElasticSearchDump(self.cfg.host, self.cfg.port)

        # Capture the first database/indice name in Elasticsearch.
        dbs = [
            str([x.split() for x in els.els.cat.indices().splitlines()][0][2])
        ]
        self.args["-D"] = self.cfg.repo_name
        self.args["-i"] = dbs
        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.run_program(self.args, self.func_dict)
        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)
Exemple #5
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)
Exemple #6
0
def print_dumps(els, repo, **kwargs):
    """Function:  print_dumps

    Description:  Print the dumps in the current repository.

    Arguments:
        (input) els -> Elasticsearch class instance.
        (input) repo -> Repository name.

    """

    esd = elastic_class.ElasticSearchDump(els.hosts, repo=repo, port=els.port)
    print("Repository: {0:25}".format(repo))
    elastic_libs.list_dumps(esd.dump_list)
    def setUp(self):
        """Function:  setUp

        Description:  Initialization for unit testing.

        Arguments:

        """

        self.base_dir = "test/integration/elastic_db_dump"
        self.test_path = os.path.join(os.getcwd(), self.base_dir)
        self.config_path = os.path.join(self.test_path, "config")
        self.cfg = gen_libs.load_module("elastic", self.config_path)
        self.els = elastic_class.ElasticSearchDump(self.cfg.host,
                                                   self.cfg.port)
Exemple #8
0
def print_failures(els, repo, **kwargs):
    """Function:  print_failures

    Description:  Print the failed dumps in the current repository.

    Arguments:
        (input) els -> Elasticsearch class instance.
        (input) repo -> Repository name.

    """

    failed_list = []
    esd = elastic_class.ElasticSearchDump(els.hosts, repo, els.port)
    print("Repository: {0:25}".format(repo))

    for dmp in esd.dump_list:
        if dmp[1] == "FAILED" or dmp[9] != 0:
            failed_list.append(dmp)

    elastic_libs.list_dumps(failed_list)
    def test_initate_dump(self):
        """Function:  test_initate_dump

        Description:  Test initiate dump call.

        Arguments:

        """

        self.args["-D"] = self.cfg.repo_name
        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.run_program(self.args, self.func_dict)
        els = elastic_class.ElasticSearchDump(self.cfg.host,
                                              self.cfg.port,
                                              repo=self.cfg.repo_name)

        self.assertTrue(els.dump_list)
    def test_repo_dict(self):
        """Function:  test_repo_dict

        Description:  Get dumps using pull from dictionary.

        Arguments:

        """

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

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

        else:
            with gen_libs.no_std_out():
                self.assertFalse(elastic_db_repo.list_dumps(self.els))
Exemple #11
0
    def test_initate_dump(self):
        """Function:  test_initate_dump

        Description:  Test initiate dump call.

        Arguments:

        """

        cmdline = gen_libs.get_inst(sys)
        self.argv_list.append("-D")
        self.argv_list.append(self.cfg.repo_name)
        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()
        els = elastic_class.ElasticSearchDump(self.cfg.host,
                                              self.cfg.port,
                                              repo=self.cfg.repo_name)

        self.assertTrue(els.dump_list)