示例#1
0
def configMySqlToAllowOutsideConnection():
    comment('/etc/mysql/my.cnf', r'^bind-address', use_sudo=True)
    mysql.query(
        "GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'secret';",
        mysql_user='******',
        mysql_password='******')
    sudo("service mysql restart")
示例#2
0
def test_run_query_without_supplying_the_password(mysql_server, mysql_user):

    from fabtools.mysql import query

    try:
        require_file('.my.cnf', contents="[mysql]\npassword=foo")
        with settings(mysql_user='******'):
            query('select 2;')
    finally:
        run('rm -f .my.cnf')
示例#3
0
def test_require_database(mysql_server, mysql_user):

    from fabtools.mysql import database_exists, query
    from fabtools.require.mysql import database

    with settings(mysql_user='******', mysql_password=MYSQL_ROOT_PASSWORD):
        try:
            database('mydb', owner='myuser')
            assert database_exists('mydb')
        finally:
            query('DROP DATABASE mydb;')
示例#4
0
def test_require_user(mysql_server):

    from fabtools.mysql import query, user_exists
    from fabtools.require.mysql import user

    with settings(mysql_user='******', mysql_password=MYSQL_ROOT_PASSWORD):
        try:
            user('myuser', 'foo')
            assert user_exists('myuser')
        finally:
            query('DROP USER myuser@localhost;')
示例#5
0
def test_run_query_without_supplying_the_password(mysql_server, mysql_user):

    from fabtools.mysql import query

    username, password = mysql_user

    try:
        require_file('.my.cnf', contents="[mysql]\npassword={0}".format(password))
        with settings(mysql_user=username):
            query('select 2;', use_sudo=False)
    finally:
        run('rm -f .my.cnf')
示例#6
0
def test_create_user(mysql_server):

    from fabtools.mysql import create_user, query, user_exists

    with settings(mysql_user='******', mysql_password=MYSQL_ROOT_PASSWORD):
        try:
            create_user('bob', 'password', host='host1')
            create_user('bob', 'password', host='host2')
            assert user_exists('bob', host='host1')
            assert user_exists('bob', host='host2')
            assert not user_exists('bob', host='localhost')
        finally:
            query('DROP USER bob@host1;')
            query('DROP USER bob@host2;')
示例#7
0
def mysql_user():

    from fabtools.mysql import query
    from fabtools.require.mysql import user

    username = '******'
    password = '******'

    with settings(mysql_user='******', mysql_password=MYSQL_ROOT_PASSWORD):
        user(username, password)

    yield username, password

    with settings(mysql_user='******', mysql_password=MYSQL_ROOT_PASSWORD):
        query('DROP USER {0}@localhost;'.format(username))
示例#8
0
def grant_all(name, host='localhost', **kwargs):
    """
    GRANT ALL
    """
    with settings(hide('running', 'stdout', 'stderr', 'warnings'),
                  warn_only=True):
        res = query(
            """
            use mysql;
            GRANT ALL PRIVILEGES ON * . * TO '%(name)s'@'%(host)s';
            """ % {
                'name': name,
                'host': host
            }, **kwargs)
    return res.succeeded
示例#9
0
def sdstore_optimise_db():
    mysql.query("USE {} ALTER TABLE sd_store_sensorreading ADD KEY ix1(sensor_id, channel_id, timestamp, id, value);".format(Settings.DB_NAME))
示例#10
0
def test_run_query_as_a_specific_user(mysql_server, mysql_user):

    from fabtools.mysql import query

    with settings(mysql_user='******', mysql_password='******'):
        query('select 1;')
示例#11
0
def configMySqlToAllowOutsideConnection():
    comment('/etc/mysql/my.cnf', r'^bind-address', use_sudo=True)
    mysql.query("GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'secret';",mysql_user='******', mysql_password='******')
    sudo("service mysql restart")
示例#12
0
 def drop_user():
     with settings(mysql_user='******', mysql_password=MYSQL_ROOT_PASSWORD):
         query('DROP USER myuser@localhost;')