コード例 #1
0
    def test_dumps_are_deleted(self):
        """Function:  test_dumps_are_deleted

        Description:  Test to see if dumps are deleted.

        Arguments:

        """

        esr = elastic_class.ElasticSearchRepo(self.cfg.host,
                                              repo=self.repo_name,
                                              repo_dir=self.repo_dir)
        esr.create_repo()

        esd = elastic_class.ElasticSearchDump(self.cfg.host,
                                              repo=self.repo_name)
        esd.dump_name = self.dump_name
        esd.dump_db()
        esd.dump_name = self.dump_name2
        esd.dump_db()

        status, msg = esr.delete_dump_all(dump_name=self.dump_name)

        esd2 = elastic_class.ElasticSearchDump(self.cfg.host,
                                               repo=self.repo_name)

        esr.delete_repo()

        self.assertEqual((status, msg, len(esd2.dump_list)), (False, None, 0))
コード例 #2
0
    def test_dbs_is_successful(self):

        """Function:  test_dbs_is_successful

        Description:  Test dumping single database.

        Arguments:

        """

        esr = elastic_class.ElasticSearchRepo(
            self.cfg.host, repo=self.repo_name, repo_dir=self.repo_dir)
        esr.create_repo()

        esd = elastic_class.ElasticSearchDump(self.cfg.host,
                                              repo=self.repo_name)

        # Capture the first database/indice name in Elasticsearch.
        dbs = str([name.split()
                   for name in esd.els.cat.indices().splitlines()][0][2])

        err_flag, _ = esd.dump_db(dbs)

        dir_path = os.path.join(self.phy_repo_dir, "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))])

        esr.delete_repo()

        self.assertFalse(err_flag)
        self.assertEqual(cnt, 1)
コード例 #3
0
    def test_in_progress_dump(self, mock_es, mock_list, mock_nodes,
                              mock_health):
        """Function:  test_in_progress_dump

        Description:  Test with dump returning In Progress/Success.

        Arguments:

        """

        mock_es.return_value = self.els
        mock_list.side_effect = [["dump1", "dump2"],
                                 [["dump1"], ["dump2"],
                                  [
                                      "dump3", "IN_PROGRESS", None, None, None,
                                      None, None, None, None, 0
                                  ],
                                  [
                                      "dump3", "SUCCESS", None, None, None,
                                      None, None, None, None, 0
                                  ]]]
        mock_nodes.return_value = self.nodes_data
        mock_health.return_value = self.health_data

        els = elastic_class.ElasticSearchDump(self.host_list, repo=self.repo)
        els.dump_name = "dump3"
        self.assertEqual(els._chk_status(self.break_flag), (False, None, True))
コード例 #4
0
    def test_dbs_multi_names(self):

        """Function:  test_dbs_multi_names

        Description:  Test dumping two databases.

        Arguments:

        """

        esr = elastic_class.ElasticSearchRepo(
            self.cfg.host, repo=self.repo_name, repo_dir=self.repo_dir)
        esr.create_repo()

        esd = elastic_class.ElasticSearchDump(self.cfg.host,
                                              repo=self.repo_name)

        # Capture 2 databases/indices name in Elasticsearch.
        dbs = ','.join(
            [str(y[2]) for y in [
                x.split() for x in esd.els.cat.indices().splitlines()]][0:2])

        err_flag, _ = esd.dump_db(dbs)

        dir_path = os.path.join(self.phy_repo_dir, "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))])

        esr.delete_repo()

        self.assertFalse(err_flag)
        self.assertEqual(cnt, 2)
コード例 #5
0
    def test_incompatible_dump(self, mock_es, mock_list, mock_nodes,
                               mock_health):
        """Function:  test_incompatible_dump

        Description:  Test with dump returning Incompatible.

        Arguments:

        """

        mock_es.return_value = self.els
        mock_list.side_effect = [["dump1", "dump2"],
                                 [["dump1"], ["dump2"],
                                  [
                                      "dump3", "INCOMPATIBLE", None, None,
                                      None, None, None, None, None, 0
                                  ]]]
        mock_nodes.return_value = self.nodes_data
        mock_health.return_value = self.health_data

        els = elastic_class.ElasticSearchDump(self.host_list, repo=self.repo)
        els.dump_name = "dump3"
        self.assertEqual(
            els._chk_status(self.break_flag),
            (True, "Older version of ES detected: reponame", False))
コード例 #6
0
    def test_connect(self):
        """Function:  test_connect

        Description:  Test to successfully connect to Elasticsearch.

        Arguments:

        """

        esd = elastic_class.ElasticSearchDump(self.cfg.host)

        self.assertTrue(not esd.repo_name and not esd.type)
コード例 #7
0
    def test_repo_not_set(self):
        """Function:  test_repo_not_set

        Description:  Test if repo name is not set and type is not set.

        Arguments:

        """

        esd = elastic_class.ElasticSearchDump(self.cfg.host)

        self.assertTrue(not esd.type)
コード例 #8
0
    def test_repo_not_passed(self):
        """Function:  test_repo_not_passed

        Description:  Test if repo name is not passed to program.

        Arguments:

        """

        esd = elastic_class.ElasticSearchDump(self.cfg.host)

        self.assertTrue(not esd.repo_name and not esd.type)
コード例 #9
0
    def test_repo_not_exist(self):
        """Function:  test_repo_not_exist

        Description:  Test if repo name does not exist.

        Arguments:

        """

        esd = elastic_class.ElasticSearchDump(self.cfg.host,
                                              repo=self.repo_name)

        self.assertTrue(not esd.repo_name and not esd.type)
コード例 #10
0
    def test_dump_list_is_set(self):
        """Function:  test_dump_list_is_set

        Description:  Test if dump list has data in it.

        Arguments:

        """

        esr = elastic_class.ElasticSearchRepo(self.cfg.host,
                                              repo=self.repo_name,
                                              repo_dir=self.repo_dir)
        esr.create_repo()
        esd = elastic_class.ElasticSearchDump(self.cfg.host,
                                              repo=self.repo_name)
        esd.dump_db()
        esd2 = elastic_class.ElasticSearchDump(self.cfg.host,
                                               repo=self.repo_name)

        self.assertTrue(esd2.dump_list)

        esr.delete_repo()
コード例 #11
0
    def test_default(self):
        """Function:  test_default

        Description:  Test with default settings.

        Arguments:

        """

        els = elastic_class.ElasticSearchDump(self.host_list, repo=self.repo)
        self.assertEqual(
            (els.hosts, els.dump_list, els.repo_name, els.last_dump_name),
            (self.host_list, self.dump_list, self.repo, self.last_dump))
コード例 #12
0
    def test_init(self):
        """Function:  test_init

        Description:  Test to see if class instance is created.

        Arguments:

        """

        host_list = "Host_Name"

        with gen_libs.no_std_out():
            esd = elastic_class.ElasticSearchDump(host_list)

        self.assertTrue(not esd.dump_name)
コード例 #13
0
    def test_repo_name_not_set(self):

        """Function:  test_repo_name_not_set

        Description:  Test repo name is not set for dump.

        Arguments:

        """

        esd = elastic_class.ElasticSearchDump(self.cfg.host)

        err_flag, status_msg = esd.dump_db()

        self.assertEqual((err_flag, status_msg), (True, self.msg))
コード例 #14
0
    def test_repo_name_is_set(self):

        """Function:  test_repo_name_is_set

        Description:  Test repo name is set, but not present.

        Arguments:

        """

        esd = elastic_class.ElasticSearchDump(self.cfg.host,
                                              repo=self.repo_name)

        err_flag, status_msg = esd.dump_db()

        self.assertEqual((err_flag, status_msg), (True, self.msg))
コード例 #15
0
    def test_default(self, mock_es, mock_list, mock_nodes, mock_health):
        """Function:  test_default

        Description:  Test with default settings.

        Arguments:

        """

        mock_es.return_value = self.els
        mock_list.return_value = self.dump_list
        mock_nodes.return_value = self.nodes_data
        mock_health.return_value = self.health_data

        els = elastic_class.ElasticSearchDump(self.host_list, repo=self.repo)
        self.assertEqual(
            (els.hosts, els.dump_list, els.repo_name, els.last_dump_name),
            (self.host_list, self.dump_list, self.repo, self.last_dump))
コード例 #16
0
    def test_single_repo(self):
        """Function:  test_single_repo

        Description:  Test if single repo is present.

        Arguments:

        """

        esr = elastic_class.ElasticSearchRepo(self.cfg.host,
                                              repo=self.repo_name,
                                              repo_dir=self.repo_dir)
        esr.create_repo()
        esd = elastic_class.ElasticSearchDump(self.cfg.host)

        self.assertTrue(esd.repo_name == self.repo_name)

        esr.delete_repo()
コード例 #17
0
    def test_repo_is_set(self):
        """Function:  test_repo_is_set

        Description:  Test if dump location is set.

        Arguments:

        """

        esr = elastic_class.ElasticSearchRepo(self.cfg.host,
                                              repo=self.repo_name,
                                              repo_dir=self.repo_dir)
        esr.create_repo()
        esd = elastic_class.ElasticSearchDump(self.cfg.host)

        self.assertTrue(esd.dump_loc == self.repo_dir)

        esr.delete_repo()
コード例 #18
0
    def test_dump_list_is_empty(self):
        """Function:  test_dump_list_is_empty

        Description:  Test if dump list is empty.

        Arguments:

        """

        esr = elastic_class.ElasticSearchRepo(self.cfg.host,
                                              repo=self.repo_name,
                                              repo_dir=self.repo_dir)
        esr.create_repo()
        esd = elastic_class.ElasticSearchDump(self.cfg.host)

        self.assertTrue(not esd.dump_list)

        esr.delete_repo()
コード例 #19
0
    def test_default(self, mock_es, mock_list, mock_nodes, mock_health):

        """Function:  test_default

        Description:  Test with default settings.

        Arguments:

        """

        mock_es.return_value = self.els
        mock_list.side_effect = [["dump1", "dump2"],
                                 ["dump1", "dump2", "dump3"]]
        mock_nodes.return_value = self.nodes_data
        mock_health.return_value = self.health_data

        els = elastic_class.ElasticSearchDump(self.host_list, repo=self.repo)
        self.assertEqual(els.dump_db(self.dbs), (False, None))
コード例 #20
0
    def test_repo_not_present(self, mock_es, mock_list, mock_nodes,
                              mock_health):
        """Function:  test_repo_not_present

        Description:  Test with repo not present.

        Arguments:

        """

        mock_es.return_value = self.els
        mock_list.return_value = self.dump_list
        mock_nodes.return_value = self.nodes_data
        mock_health.return_value = self.health_data

        els = elastic_class.ElasticSearchDump(self.host_list, repo=self.repo2)
        self.assertEqual(
            (els.hosts, els.dump_list, els.repo_name, els.last_dump_name),
            (self.host_list, [], None, None))
コード例 #21
0
    def test_dupe_name(self, mock_es, mock_list, mock_date, mock_nodes,
                       mock_health):
        """Function:  test_dupe_name

        Description:  Test with duplicate dump name.

        Arguments:

        """

        mock_es.return_value = self.els
        mock_list.return_value = self.dump_list
        mock_date.strftime.side_effect = ["dump2", "dump3"]
        mock_nodes.return_value = self.nodes_data
        mock_health.return_value = self.health_data

        els = elastic_class.ElasticSearchDump(self.host_list, repo=self.repo)
        self.assertEqual(
            (els.hosts, els.dump_list, els.repo_name, els.last_dump_name),
            (self.host_list, self.dump_list, self.repo, self.last_dump))
コード例 #22
0
    def test_multi_repo(self):
        """Function:  test_multi_repo

        Description:  Test if multiple repos are present.

        Arguments:

        """

        esr = elastic_class.ElasticSearchRepo(self.cfg.host,
                                              repo=self.repo_name,
                                              repo_dir=self.repo_dir)
        esr.create_repo()
        esr.create_repo(repo_name=self.repo_name2, repo_dir=self.repo_dir2)
        esd = elastic_class.ElasticSearchDump(self.cfg.host)

        self.assertTrue(esd.repo_name is None)

        esr.delete_repo()
        esr.delete_repo(repo_name=self.repo_name2)
コード例 #23
0
    def test_bad_db_name(self, mock_es, mock_list, mock_nodes, mock_health):

        """Function:  test_bad_db_name

        Description:  Test with bad database name.

        Arguments:

        """

        mock_es.return_value = self.els
        mock_list.side_effect = [["dump1", "dump2"],
                                 ["dump1", "dump2", "dump3"]]
        mock_nodes.return_value = self.nodes_data
        mock_health.return_value = self.health_data

        els = elastic_class.ElasticSearchDump(self.host_list, repo=self.repo)
        self.assertEqual(
            els.dump_db(self.dbs2),
            (True, "ERROR:  Database name(s) is not a string: ['dbname']"))
コード例 #24
0
    def test_dbs_is_not_str(self):

        """Function:  test_dbs_is_not_str

        Description:  Test database name is not a string.

        Arguments:

        """

        esr = elastic_class.ElasticSearchRepo(
            self.cfg.host, repo=self.repo_name, repo_dir=self.repo_dir)

        esr.create_repo()

        esd = elastic_class.ElasticSearchDump(self.cfg.host,
                                              repo=self.repo_name)

        err_flag, status_msg = esd.dump_db(self.dbs_err)

        self.assertEqual((err_flag, status_msg), (True, self.msg2))
コード例 #25
0
    def test_repo_not_passed2(self, mock_es, mock_list, mock_nodes,
                              mock_health):
        """Function:  test_repo_not_passed2

        Description:  Test with repo not passed and multiple repos.

        Arguments:

        """

        self.els.snapshot = Repo2()

        mock_es.return_value = self.els
        mock_list.return_value = self.dump_list
        mock_nodes.return_value = self.nodes_data
        mock_health.return_value = self.health_data

        els = elastic_class.ElasticSearchDump(self.host_list)
        self.assertEqual(
            (els.hosts, els.dump_list, els.repo_name, els.last_dump_name),
            (self.host_list, [], None, None))
コード例 #26
0
    def test_no_repo_name(self, mock_es, mock_list, mock_nodes, mock_health):

        """Function:  test_no_repo_name

        Description:  Test with no repo name set.

        Arguments:

        """

        mock_es.return_value = self.els
        mock_list.side_effect = [["dump1", "dump2"],
                                 ["dump1", "dump2", "dump3"]]
        mock_nodes.return_value = self.nodes_data
        mock_health.return_value = self.health_data

        els = elastic_class.ElasticSearchDump(self.host_list, repo=self.repo)
        els.repo_name = None
        self.assertEqual(
            els.dump_db(self.dbs),
            (True, "ERROR:  Repository name not set."))
コード例 #27
0
    def test_dump_succesful(self):

        """Function:  test_dump_succesful

        Description:  Test dump of database is successful.

        Arguments:

        """

        esr = elastic_class.ElasticSearchRepo(
            self.cfg.host, repo=self.repo_name, repo_dir=self.repo_dir)

        esr.create_repo()

        esd = elastic_class.ElasticSearchDump(self.cfg.host,
                                              repo=self.repo_name)

        err_flag, status_msg = esd.dump_db()

        esr.delete_repo()

        self.assertEqual((err_flag, status_msg), (False, None))
コード例 #28
0
    def test_partial_dump(self, mock_es, mock_list, mock_nodes, mock_health):
        """Function:  test_partial_dump

        Description:  Test with dump returning Partial.

        Arguments:

        """

        mock_es.return_value = self.els
        mock_list.side_effect = [["dump1", "dump2"],
                                 [["dump1"], ["dump2"],
                                  [
                                      "dump3", "PARTIAL", None, None, None,
                                      None, None, None, None, 0
                                  ]]]
        mock_nodes.return_value = self.nodes_data
        mock_health.return_value = self.health_data

        els = elastic_class.ElasticSearchDump(self.host_list, repo=self.repo)
        els.dump_name = "dump3"
        self.assertEqual(els._chk_status(self.break_flag),
                         (True, "Partial dump completed on reponame", False))
コード例 #29
0
    def test_dump_is_deleted(self):
        """Function:  test_dump_is_deleted

        Description:  Test to see if dump is deleted.

        Arguments:

        """

        esr = elastic_class.ElasticSearchRepo(self.cfg.host,
                                              repo=self.repo_name,
                                              repo_dir=self.repo_dir)
        esr.create_repo()

        esd = elastic_class.ElasticSearchDump(self.cfg.host,
                                              repo=self.repo_name)
        esd.dump_name = self.dump_name
        esd.dump_db()

        status, msg = esr.delete_dump(dump_name=self.dump_name)

        esr.delete_repo()

        self.assertEqual((status, msg), (False, None))
コード例 #30
0
    def test_dump_list_updated(self):

        """Function:  test_dump_list_updated

        Description:  Test dump list is updated after dump.

        Arguments:

        """

        esr = elastic_class.ElasticSearchRepo(
            self.cfg.host, repo=self.repo_name, repo_dir=self.repo_dir)

        esr.create_repo()

        esd = elastic_class.ElasticSearchDump(self.cfg.host,
                                              repo=self.repo_name)

        err_flag, _ = esd.dump_db()

        esr.delete_repo()

        self.assertFalse(err_flag)
        self.assertEqual(len(esd.dump_list), 1)