Esempio n. 1
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;')
Esempio n. 2
0
def setup_mysql():
    sudo('apt-get install -y mysql-server python-mysqldb')
    with virtualenv(Settings.DIR_VENV):
        run('pip install mysqlclient')
    if not mysql.user_exists(Settings.DB_USER_NAME):
        mysql.create_user(Settings.DB_USER_NAME, password=Settings.DB_PASSWORD)
    if not mysql.database_exists(Settings.DB_NAME):
        mysql.create_database(Settings.DB_NAME, Settings.DB_USER_NAME)
Esempio n. 3
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;')
Esempio n. 4
0
def user(name, password, **kwargs):
    """
    Require a MySQL user.

    Extra arguments will be passed to :py:func:`fabtools.mysql.create_user`.

    Example::

        from fabtools import require

        require.mysql.user('dbuser', 'somerandomstring')

    """
    if not user_exists(name, **kwargs):
        create_user(name, password, **kwargs)
Esempio n. 5
0
def user(name, password, **kwargs):
    """
    Require a MySQL user.

    Extra arguments will be passed to :py:func:`fabtools.mysql.create_user`.

    Example::

        from fabric.api import settings
        from fabtools import require

        with settings(mysql_user='******', mysql_password='******'):
            require.mysql.user('dbuser', 'somerandomstring')

    """
    if not user_exists(name, **kwargs):
        create_user(name, password, **kwargs)
Esempio n. 6
0
def user(name, password, **kwargs):
    """
    Require a MySQL user.

    Extra arguments will be passed to :py:func:`fabtools.mysql.create_user`.

    Example::

        from fabric.api import settings
        from fabtools import require

        with settings(mysql_user='******', mysql_password='******'):
            require.mysql.user('dbuser', 'somerandomstring')

    """
    if not user_exists(name, **kwargs):
        create_user(name, password, **kwargs)
Esempio n. 7
0
def db_init():
    if not mysql.user_exists('featuring'):
        mysql.create_user('featuring', '123123')
    if not mysql.database_exists('featuring'):
        mysql.create_database('featuring', owner='featuring')