Ubuntu Pastebin

Paste from lazy at Tue, 14 Jun 2016 17:33:54 +0000

Download as text
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
@when('mysql.connected')
def install_mysql_supporting_tools():
    ''' We have a mysql connection, so we should install the tooling now before
        it's ready to consume. This step provides the mysql cli'''
    apt.queue_install(['mysql-client'])

@when('mysql.available', 'apt.mysql-client.installed')
def run_mysql_commands(mysql):
    ''' Run database migrations, not idempotent, and this method will
        require additional work to pass review '''

    # Assume we need to render some template here for your sql, skip if not
    from charms.templating.jinja2 import render
    render('sql-template.sql', './migration-00.sql', {'config': 'dict'})

    # Assemble the command
    cmd = "mysql -h mysql://{0}:{1} -u {2} -p{3} {4} << {5}"
    cmd.format(mysql.host(),mysql.port(), mysql.username(), mysql.password(),
               'sql-template.sql')

    # Import the required modules to format the string as a command and execute
    # returning 0, or raising an exception if the command fails for any reason
    import shlex
    import subprocess
    subprocess.check_call(shlex.split(cmd))
Download as text