Merge lp:~ovais-tariq/twindb-agent/bug-1407376 into lp:twindb-agent

Proposed by Ovais Tariq
Status: Merged
Approved by: Aleksandr Kuzminsky
Approved revision: 8
Merged at revision: 9
Proposed branch: lp:~ovais-tariq/twindb-agent/bug-1407376
Merge into: lp:twindb-agent
Diff against target: 81 lines (+45/-1)
2 files modified
.bzrignore (+1/-0)
twindb.py (+44/-1)
To merge this branch: bzr merge lp:~ovais-tariq/twindb-agent/bug-1407376
Reviewer Review Type Date Requested Status
TwinDB Developers Pending
Review via email: mp+250541@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Ovais Tariq (ovais-tariq) wrote :

Test results:

       Command "whoami"
         stdout
           should match /root/

       twindb package is installed
         Package "twindb"
           should be installed

       twindb service is configured and running
         Service "twindb"
           should be enabled
           should be enabled
           should be running

       twindb agent is initially unregistered
         Command "sudo -i /usr/bin/twindb --user root --password root --dispatcher dispatcher.twindb.com --is-registered"
           stdout
             should match /NO/

       twindb agent is able to register
         Command "sudo -i /usr/bin/twindb --user root --password root --dispatcher dispatcher.twindb.com --register 0f6714f735a06a488ec9279f59d0a3f2"
           exit_status
             should eq 0
         Command "sudo -i /usr/bin/twindb --user root --password root --dispatcher dispatcher.twindb.com --is-registered"
           stdout
             should match /YES/

       twindb agent is able to do backup
         Command "sudo -i /usr/bin/twindb --user root --password root --dispatcher dispatcher.twindb.com --backup"
           exit_status
             should eq 0
           stdout
             should match /Backup job is complete/

       twindb agent is able to unregister
         Command "sudo -i /usr/bin/twindb --user root --password root --dispatcher dispatcher.twindb.com --unregister --delete-backups"
           exit_status
             should eq 0
         Command "sudo -i /usr/bin/twindb --user root --password root --dispatcher dispatcher.twindb.com --is-registered"
           stdout
             should match /NO/

       Finished in 39.24 seconds (files took 0.55168 seconds to load)
       12 examples, 0 failures

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added file '.bzrignore'
2--- .bzrignore 1970-01-01 00:00:00 +0000
3+++ .bzrignore 2015-02-22 02:25:57 +0000
4@@ -0,0 +1,1 @@
5+.idea
6
7=== modified file 'twindb.py'
8--- twindb.py 2015-01-24 21:00:01 +0000
9+++ twindb.py 2015-02-22 02:25:57 +0000
10@@ -183,6 +183,7 @@
11 logger.error("Unexpected error: %s,%s" % sys.exc_info()[:2]);
12 return None
13 return conn
14+
15 # Checks if TwinDB API public key is installed
16 # Returns
17 # True - if the key is installed
18@@ -1017,13 +1018,48 @@
19 return None
20 return result
21
22+
23+def has_mysql_access():
24+ has_required_grants = False
25+
26+ try:
27+ conn = get_mysql_connection()
28+ if conn:
29+ cursor = conn.cursor(dictionary=True)
30+ else:
31+ return False
32+
33+ # Fetch the current user and matching host part as it could either be
34+ # connecting using localhost or using '%'
35+ cursor.execute("SELECT CURRENT_USER() as curr_user")
36+ row = cursor.fetchone()
37+ username, hostname = row['curr_user'].split('@')
38+
39+ sql = ("SELECT * FROM mysql.user WHERE user='%s' "
40+ "AND host='%s'" % (username, hostname))
41+ cursor.execute(sql)
42+ user_info = cursor.fetchone()
43+
44+ has_required_grants = True
45+ for privilege in ['Reload_priv', 'Lock_tables_priv',
46+ 'Repl_client_priv', 'Super_priv',
47+ 'Create_tablespace_priv', 'Grant_priv']:
48+ if user_info[privilege] != 'Y':
49+ has_required_grants = False
50+ break
51+ except:
52+ logger.error("Could not read the grants information from MySQL")
53+ logger.error(u"Unexpected error: {0:s},{1:s}".format(sys.exc_info()[:2]))
54+
55+ return has_required_grants
56+
57+
58 # Registers this server in TwinDB dispatcher
59 # Inputs
60 # code - string with secret registration code
61 # Returns
62 # True - if server was successfully registered
63 # Exits if error happened
64-
65 def action_handler_register(code):
66 global logger
67 global init_config
68@@ -1035,6 +1071,13 @@
69 global mysql_password
70
71 check_env()
72+
73+ # Check early to see that the MySQL user passed to the agent has enough
74+ # privileges to create a separate MySQL user needed by TwinDB
75+ if not has_mysql_access():
76+ logger.error("The MySQL user %s does not have enough privileges" % mysql_user)
77+ return False
78+
79 logger.info("Registering TwinDB agent with code %s" % code)
80 logger.info("The agent needs to generate cryptographically strong keys.")
81 logger.info("It may take really, really long time. Please be patient.")

Subscribers

People subscribed via source and target branches