示例#1
0
def mongo_check(config_path, config_file):
    """Function:  mongo_check

    Description:  Check the contents of the output file based on the items in
        the search_list variable and check to see if file is in JSON format.

    Arguments:
        (input) config_path -> Path name to configuration file.
        (input) config_file -> Name of configuration file, without .py ext.
        (output) status -> True|False - Status of checks.

    """

    status = True
    cfg = gen_libs.load_module(config_file, config_path)
    coll = mongo_libs.crt_coll_inst(cfg, cfg.db, cfg.coll)
    coll.connect()
    status = coll.coll_cnt() == 1
    mongo = mongo_class.DB(cfg.name,
                           cfg.user,
                           cfg.passwd,
                           host=cfg.host,
                           port=cfg.port,
                           db=cfg.db,
                           auth=cfg.auth,
                           conf_file=cfg.conf_file)
    mongo.db_connect(cfg.db)
    mongo.db_cmd("dropDatabase")

    cmds_gen.disconnect([coll, mongo])

    return status
示例#2
0
    def tearDown(self):
        """Function:  tearDown

        Description:  Clean up of integration testing.

        Arguments:

        """

        mongo = mongo_class.DB(self.cfg.name,
                               self.cfg.user,
                               self.cfg.passwd,
                               host=self.cfg.host,
                               port=self.cfg.port,
                               db=self.cfg.db,
                               auth=self.cfg.auth,
                               conf_file=self.cfg.conf_file)
        mongo.db_connect(self.cfg.db)
        mongo.db_cmd("dropDatabase")
        cmds_gen.disconnect([mongo])
示例#3
0
    def tearDown(self):

        """Function:  tearDown

        Description:  Clean up of integration testing.

        Arguments:

        """

        mongo = mongo_class.DB(
            self.mongo_cfg.name, self.mongo_cfg.user, self.mongo_cfg.japd,
            self.mongo_cfg.host, self.mongo_cfg.port, db=self.dbn,
            auth=self.mongo_cfg.auth, conf_file=self.mongo_cfg.conf_file)

        mongo.db_connect(self.dbn)
        mongo.db_cmd("dropDatabase")
        mongo_libs.disconnect([mongo])

        if os.path.isfile(self.out_file):
            os.remove(self.out_file)
def mongo_cleanup(mongo_cfg, dbn):
    """Function:  mongo_cleanup

    Description:  Cleans up the contents of the mongo database.

    Arguments:
        (input) mongo_cfg -> Mongo server configuration.
        (input) dbn -> Name of the database in Mongo.

    """

    mongo = mongo_class.DB(mongo_cfg.name,
                           mongo_cfg.user,
                           mongo_cfg.japd,
                           host=mongo_cfg.host,
                           port=mongo_cfg.port,
                           db=dbn,
                           auth=mongo_cfg.auth,
                           conf_file=mongo_cfg.conf_file)

    mongo.db_connect(dbn)
    mongo.db_cmd("dropDatabase")
    mongo_libs.disconnect([mongo])
示例#5
0
def process_request(server, func_name, db_name=None, tbl_name=None, **kwargs):

    """Function:  process_request

    Description:  Prepares for the type of check based on the arguments passed
        to the function and then calls the "func_name" function.

    Arguments:
        (input) server -> Database server instance.
        (input) func_name -> Name of a function.
        (input) db_name -> List of database names.
        (input) tbl_name -> List of table names.
        (input) **kwargs:
            full -> Full validation table check option.
        (output) err_flag -> True|False - If an error has occurred.
        (output) err_msg -> Error message.

    """

    err_flag = False
    err_msg = None

    if db_name is None:
        db_name = []

    else:
        db_name = list(db_name)

    if tbl_name is None:
        tbl_name = []

    else:
        tbl_name = list(tbl_name)

    db_list = server.fetch_dbs()
    mongo = mongo_class.DB(
        server.name, server.user, server.japd, host=server.host,
        port=server.port, db="test", auth=server.auth,
        conf_file=server.conf_file, auth_db=server.auth_db,
        use_arg=server.use_arg, use_uri=server.use_uri)
    state = mongo.connect()

    if not state[0]:
        err_flag = True
        err_msg = "Connection to Mongo DB:  %s" % state[1]

    else:

        # Process all databases.
        if not db_name:

            for item in db_list:
                func_name(mongo, item, **kwargs)

        # Process all tables in a database.
        elif not tbl_name:

            # Generator builds list of databases to process.
            for dbn in (dbn for dbn in db_name if dbn in db_list):
                func_name(mongo, dbn, **kwargs)

        # Process passed databases and tables.
        else:

            # Generator builds list of databases to process.
            for dbn in (dbn for dbn in db_name if dbn in db_list):
                mongo.chg_db(dbs=dbn)
                tbl_list = mongo.get_tbl_list()
                fnd_tbls = list((tbl for tbl in tbl_name if tbl in tbl_list))

                if fnd_tbls:
                    func_name(mongo, dbn, fnd_tbls, **kwargs)

                else:
                    print("Found no tables to process in: %s" % (dbn))

        mongo_libs.disconnect([mongo])

    return err_flag, err_msg