Merge lp:~jacekn/charms/trusty/mysql/mysql-storage into lp:charms/trusty/mysql

Proposed by Jacek Nykis
Status: Merged
Merged at revision: 136
Proposed branch: lp:~jacekn/charms/trusty/mysql/mysql-storage
Merge into: lp:charms/trusty/mysql
Prerequisite: lp:~jacekn/charms/trusty/mysql/mysql-backups
Diff against target: 129 lines (+76/-1)
5 files modified
config.yaml (+1/-1)
hooks/common.py (+26/-0)
hooks/data-relation.py (+31/-0)
metadata.yaml (+3/-0)
templates/apparmor.j2 (+15/-0)
To merge this branch: bzr merge lp:~jacekn/charms/trusty/mysql/mysql-storage
Reviewer Review Type Date Requested Status
Tim Van Steenburgh (community) Approve
Jacek Nykis (community) Needs Resubmitting
Adam Israel (community) Approve
Review Queue (community) automated testing Approve
Review via email: mp+245744@code.launchpad.net

Description of the change

This change improves persistent storage support.

MySQL data will be kept in persistent storage if it's present.

To post a comment you must log in.
Revision history for this message
uosci-testing-bot (uosci-testing-bot) wrote :

charm_lint_check #582 trusty-mysql for jacekn mp245744
    LINT OK: passed

Build: http://10.245.162.77:8080/job/charm_lint_check/582/

Revision history for this message
uosci-testing-bot (uosci-testing-bot) wrote :

charm_unit_test #611 trusty-mysql for jacekn mp245744
    UNIT FAIL: unit-test missing

UNIT Results (max last 2 lines):
INFO:root:Search string not found in makefile target commands.
ERROR:root:No make target was executed.

Full unit test output: http://paste.ubuntu.com/9687881/
Build: http://10.245.162.77:8080/job/charm_unit_test/611/

Revision history for this message
Review Queue (review-queue) wrote :

The results (PASS) are in and available here: http://reports.vapour.ws/charm-tests/charm-bundle-test-10874-results

review: Approve (automated testing)
Revision history for this message
Adam Israel (aisrael) wrote :

Hi Jacek,

Thanks for your work on improving the mysql charm! I've had the opportunity to review this merge proposal. I've successfully tested this addition, with the caveat that it was done with the 'storage' charm under the local provider. More testing may be needed, but as of now this LGTM. You've got my +1.

review: Approve
Revision history for this message
Jacek Nykis (jacekn) wrote :

Hello,

Is there anything I need to do before this can be merged?

review: Needs Resubmitting
Revision history for this message
Tim Van Steenburgh (tvansteenburgh) wrote :

+1 LGTM.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'config.yaml'
2--- config.yaml 2015-01-07 14:31:43 +0000
3+++ config.yaml 2015-01-07 14:31:43 +0000
4@@ -123,7 +123,7 @@
5 type: string
6 description: "mysql bind host address"
7 backup_dir:
8- default: "/srv/backups"
9+ default: "/var/lib/mysql/backups"
10 type: string
11 description: "Directory where bakcups will be stored"
12 backup_schedule:
13
14=== modified file 'hooks/common.py'
15--- hooks/common.py 2014-08-15 06:31:44 +0000
16+++ hooks/common.py 2015-01-07 14:31:43 +0000
17@@ -3,6 +3,9 @@
18 import os
19 import MySQLdb
20 import subprocess
21+import shutil
22+from charmhelpers.core import hookenv, host
23+from charmhelpers.core.templating import render
24
25
26 def get_service_user_file(service):
27@@ -120,3 +123,26 @@
28 remote_ip))
29 finally:
30 cursor.close()
31+
32+
33+def migrate_to_mount(new_path):
34+ """Invoked when new mountpoint appears. This function safely migrates
35+ MySQL data from local disk to persistent storage (only if needed)
36+ """
37+ old_path = '/var/lib/mysql'
38+ if os.path.islink(old_path):
39+ hookenv.log('{} is already a symlink, skipping migration'.format(
40+ old_path))
41+ return True
42+ os.chmod(new_path, 0700)
43+ if os.path.isdir('/etc/apparmor.d/local'):
44+ render('apparmor.j2', '/etc/apparmor.d/local/usr.sbin.mysqld',
45+ context={'path': os.path.join(new_path, '')})
46+ host.service_reload('apparmor')
47+ host.service_stop('mysql')
48+ host.rsync(os.path.join(old_path, ''), # Ensure we have trailing slashes
49+ os.path.join(new_path, ''),
50+ options=['--archive'])
51+ shutil.rmtree(old_path)
52+ os.symlink(new_path, old_path)
53+ host.service_start('mysql')
54
55=== added symlink 'hooks/data-relation-changed'
56=== target is u'data-relation.py'
57=== added symlink 'hooks/data-relation-departed'
58=== target is u'data-relation.py'
59=== added symlink 'hooks/data-relation-joined'
60=== target is u'data-relation.py'
61=== added file 'hooks/data-relation.py'
62--- hooks/data-relation.py 1970-01-01 00:00:00 +0000
63+++ hooks/data-relation.py 2015-01-07 14:31:43 +0000
64@@ -0,0 +1,31 @@
65+#!/usr/bin/env python
66+
67+import sys
68+
69+import common
70+from charmhelpers.core import hookenv, host
71+
72+
73+hooks = hookenv.Hooks()
74+mountpoint = '/srv/mysql'
75+
76+
77+@hooks.hook('data-relation-joined', 'data-relation-changed')
78+def data_relation():
79+ if hookenv.relation_get('mountpoint') == mountpoint:
80+ # Other side of relation is ready
81+ common.migrate_to_mount(mountpoint)
82+ else:
83+ # Other side not ready yet, provide mountpoint
84+ hookenv.log('Requesting storage for {}'.format(mountpoint))
85+ hookenv.relation_set(mountpoint=mountpoint)
86+
87+
88+@hooks.hook('data-relation-departed', 'data-relation-broken')
89+def data_relation_gone():
90+ hookenv.log('Data relation no longer present, stopping MysQL.')
91+ host.service_stop('mysql')
92+
93+
94+if __name__ == '__main__':
95+ hooks.execute(sys.argv)
96
97=== modified file 'metadata.yaml'
98--- metadata.yaml 2014-05-08 11:23:53 +0000
99+++ metadata.yaml 2015-01-07 14:31:43 +0000
100@@ -27,6 +27,9 @@
101 nrpe-external-master:
102 interface: nrpe-external-master
103 scope: container
104+ data:
105+ interface: block-storage
106+ scope: container
107 peers:
108 cluster:
109 interface: mysql-ha
110
111=== added file 'templates/apparmor.j2'
112--- templates/apparmor.j2 1970-01-01 00:00:00 +0000
113+++ templates/apparmor.j2 2015-01-07 14:31:43 +0000
114@@ -0,0 +1,15 @@
115+#
116+# " "
117+# mmm m m mmm m m
118+# # # # # # #
119+# # # # # # #
120+# # "mm"# # "mm"#
121+# # #
122+# "" ""
123+# This file is managed by Juju. Do not make local changes.
124+
125+# Site-specific additions and overrides for usr.sbin.mysqld.
126+# For more details, please see /etc/apparmor.d/local/README.
127+
128+{{path}} r,
129+{{path}}** rwk,

Subscribers

People subscribed via source and target branches

to all changes: