~viswesn/charms/trusty/mysql/lint

« back to all changes in this revision

Viewing changes to tests/10-deploy

  • Committer: Marco Ceppi
  • Date: 2015-02-27 17:13:09 UTC
  • mfrom: (133.5.7 mysql)
  • Revision ID: marco@ceppi.net-20150227171309-t1f4woi0bk64c8al
[nicopace] Tests for MySQL
[marcoceppi] Resovled conflicts in Makefile

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/usr/bin/env python3
2
 
 
3
 
import logging
4
 
 
5
 
import amulet
6
 
 
7
 
 
8
 
d = amulet.Deployment()
9
 
 
10
 
d.add('mysql')
11
 
d.expose('mysql')
12
 
 
13
 
try:
14
 
    d.setup(timeout=900)
15
 
    d.sentry.wait()
16
 
except amulet.helpers.TimeoutError:
17
 
    amulet.raise_status(amulet.SKIP, msg="Environment wasn't stood up in time")
18
 
except:
19
 
    raise
20
 
 
21
 
# Check root password
22
 
user = 'root'
23
 
mysql = d.sentry.unit['mysql/0']
24
 
password = mysql.file_contents('/var/lib/mysql/mysql.passwd')
25
 
logging.info('root password: ' + password)
26
 
sql_template = ("echo SELECT DISTINCT User FROM user |"
27
 
                " mysql -u {} --password={} mysql")
28
 
sql_command = (sql_template).format(user, password)
29
 
result, code = mysql.run(sql_command)
30
 
logging.debug('Execution script:' + sql_command)
31
 
logging.debug("Execution Return Code:" + str(code))
32
 
logging.debug('Execution result:' + result)
33
 
result = result.split('\n')[1:]
34
 
u = False
35
 
for r in result:
36
 
    u = u or user in r
37
 
 
38
 
if not u:
39
 
    amulet.raise_status(amulet.FAIL,
40
 
                        'Error connecting to mysql from localhost.')
41
 
else:
42
 
    amulet.raise_status(amulet.PASS,
43
 
                        'Connected through localhost.')