Ejemplo n.º 1
0
    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)
Ejemplo n.º 2
0
    def test_create_repo(self):
        """Function:  test_create_repo

        Description:  Test create repo call.

        Arguments:

        """

        self.args["-C"] = self.cfg.repo_name
        self.args["-l"] = self.cfg.repo_dir
        elastic_db_dump.run_program(self.args, self.func_dict)
        self.elr = elastic_class.ElasticSearchRepo(self.cfg.host,
                                                   self.cfg.port,
                                                   repo=self.cfg.repo_name)

        self.assertTrue(self.cfg.repo_name in self.elr.repo_dict)
Ejemplo n.º 3
0
    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)
Ejemplo n.º 4
0
    def test_load_module(self, mock_lock):
        """Function:  test_load_module

        Description:  Test load module call.

        Arguments:

        """

        mock_lock.ProgramLock.side_effect = \
            elastic_db_dump.gen_class.SingleInstanceException()

        self.assertFalse(elastic_db_dump.run_program(self.args,
                                                     self.func_dict))
Ejemplo n.º 5
0
    def test_func_call_zero(self, mock_lock, mock_class, mock_load):
        """Function:  test_func_call_zero

        Description:  Test run_program function with zero calls to function.

        Arguments:

        """

        mock_lock.return_value = self.proglock
        mock_class.return_value = "Elastic_Class"
        mock_load.return_value = self.cfg

        self.assertFalse(elastic_db_dump.run_program(self.args,
                                                     self.func_dict))
Ejemplo n.º 6
0
    def test_func_call_multi(self, mock_lock, mock_class, mock_load):
        """Function:  test_func_call_multi

        Description:  Test run_program function with multiple calls to
            function.

        Arguments:

        """

        self.args["-U"] = True
        self.args["-L"] = True

        mock_lock.return_value = self.proglock
        mock_class.return_value = "Elastic_Class"
        mock_load.return_value = self.cfg

        self.assertFalse(elastic_db_dump.run_program(self.args,
                                                     self.func_dict))
Ejemplo n.º 7
0
    def test_list_repos(self):
        """Function:  test_list_repos

        Description:  Test list repos call.

        Arguments:

        """

        self.args["-R"] = True
        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))

        with gen_libs.no_std_out():
            self.assertFalse(
                elastic_db_dump.run_program(self.args, self.func_dict))
Ejemplo n.º 8
0
    def test_exception_handler(self, mock_lock, mock_class, mock_load):
        """Function:  test_exception_handler

        Description:  Test with exception handler.

        Arguments:

        """

        self.args["-U"] = True
        self.args["-L"] = True

        mock_lock.side_effect = \
            elastic_db_dump.gen_class.SingleInstanceException
        mock_class.return_value = "Elastic_Class"
        mock_load.return_value = self.cfg

        with gen_libs.no_std_out():
            self.assertFalse(
                elastic_db_dump.run_program(self.args, self.func_dict))