Example #1
0
def _make_config_file(program, dir, root_pw, port):
    """Create a temporary config file in the specified directory containing
    the username (root) and password. The file is readable and writable only
    by the current user (at least on unix).

    The program is the name of the program this applies to - e.g. mysql,
    mysqld, or mysqladmin
    """
    return \
      iufile.make_temp_config_file("[%s]\nuser=root\npassword=%s\nport=%d\n" %
                                   (program, root_pw, port), dir)
Example #2
0
def call_mysql(config, user, pwd, input, continue_on_error=False):
    cfg_filename = iufile.make_temp_config_file(
        "[mysql]\nuser=%s\npassword=%s\nport=%d\n" % (user, pwd, config.input_ports.mysql.port), dir=config.home_path
    )
    defaults_file = "--defaults-file=%s" % cfg_filename
    socket_file = "--socket=%s" % config.socket_file
    try:
        rc = iuprocess.run_and_log_program(
            [config.mysql_path, defaults_file, socket_file], {}, logger, cwd=config.home_path, input=input
        )
    finally:
        os.remove(cfg_filename)
    if rc != 0 and not continue_on_error:
        raise AgilefantError(
            ERR_CALL_MYSQL, "Install", config, developer_msg="Return code: '%d', Input: '%s'" % (rc, input)
        )
    return rc