Merge lp:~stub/charms/trusty/cassandra/ensure-thrift into lp:~stub/charms/trusty/cassandra/spike

Proposed by Stuart Bishop
Status: Superseded
Proposed branch: lp:~stub/charms/trusty/cassandra/ensure-thrift
Merge into: lp:~stub/charms/trusty/cassandra/spike
Diff against target: 259 lines (+144/-12)
5 files modified
Makefile (+8/-2)
README.md (+1/-1)
hooks/helpers.py (+32/-8)
tests/test_helpers.py (+92/-1)
tests/test_integration.py (+11/-0)
To merge this branch: bzr merge lp:~stub/charms/trusty/cassandra/ensure-thrift
Reviewer Review Type Date Requested Status
Stuart Bishop Pending
Review via email: mp+279868@code.launchpad.net

Description of the change

Fix Bug #1523546 by supporting Cassandra 2.2.

Note that Cassandra 2.1 is still the release series recommended for production use.

To post a comment you must log in.
370. By Stuart Bishop

Turn on Cassandra 2.2 tests

371. By Stuart Bishop

Cassandra 2.2 is now recommended upstream, so switch it to the default

372. By Stuart Bishop

Cassandra 3.0 support, switch to OpenJDK 8

373. By Stuart Bishop

Rollup unlanded features, resolving conflicts

374. By Stuart Bishop

Merge rsync-port

375. By Stuart Bishop

Merge noauthentication

376. By Stuart Bishop

Fix 3.0 test

377. By Stuart Bishop

Fix defaults in config.yaml

378. By Stuart Bishop

delint

379. By Stuart Bishop

Merge trunk

Unmerged revisions

379. By Stuart Bishop

Merge trunk

378. By Stuart Bishop

delint

377. By Stuart Bishop

Fix defaults in config.yaml

376. By Stuart Bishop

Fix 3.0 test

375. By Stuart Bishop

Merge noauthentication

374. By Stuart Bishop

Merge rsync-port

373. By Stuart Bishop

Rollup unlanded features, resolving conflicts

372. By Stuart Bishop

Cassandra 3.0 support, switch to OpenJDK 8

371. By Stuart Bishop

Cassandra 2.2 is now recommended upstream, so switch it to the default

370. By Stuart Bishop

Turn on Cassandra 2.2 tests

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'Makefile'
2--- Makefile 2015-08-19 09:57:40 +0000
3+++ Makefile 2015-12-08 10:18:39 +0000
4@@ -70,12 +70,18 @@
5 AMULET_TIMEOUT=5400 \
6 $(NOSETESTS) tests.test_integration:Test1UnitDeployment 2>&1 | ts
7
8-20test: unittest Test21Deployment
9+20test: unittest Test20Deployment
10 Test20Deployment: deps
11 date
12 AMULET_TIMEOUT=5400 \
13 $(NOSETESTS) tests.test_integration:Test20Deployment 2>&1 | ts
14-
15+
16+22test: unittest Test22Deployment
17+Test22Deployment: deps
18+ date
19+ AMULET_TIMEOUT=5400 \
20+ $(NOSETESTS) tests.test_integration:Test22Deployment 2>&1 | ts
21+
22 3test: unittest Test3UnitDeployment
23 Test3UnitDeployment: deps
24 date
25
26=== modified file 'README.md'
27--- README.md 2015-10-20 09:41:37 +0000
28+++ README.md 2015-12-08 10:18:39 +0000
29@@ -13,7 +13,7 @@
30
31 # Editions
32
33-This charm supports Apache Cassandra 2.0, Apache Cassandra 2.1, and
34+This charm supports Apache Cassandra 2.0, 2.1 & 2.2, and
35 Datastax Enterprise 4.8. The default is Apache Cassandra 2.1.
36
37 To use Apache Cassandra 2.0, specify the Apache Cassandra 2.0 archive source
38
39=== modified file 'hooks/helpers.py'
40--- hooks/helpers.py 2015-09-11 05:07:47 +0000
41+++ hooks/helpers.py 2015-12-08 10:18:39 +0000
42@@ -16,6 +16,7 @@
43 import configparser
44 from contextlib import contextmanager
45 from datetime import timedelta
46+from distutils.version import LooseVersion
47 import errno
48 from functools import wraps
49 import io
50@@ -303,10 +304,20 @@
51
52 def get_cassandra_version():
53 if get_cassandra_edition() == 'dse':
54- return '2.1' if get_package_version('dse-full') else None
55+ dse_ver = get_package_version('dse-full')
56+ if not dse_ver:
57+ return None
58+ elif LooseVersion(dse_ver) >= LooseVersion('4.7'):
59+ return '2.1'
60+ else:
61+ return '2.0'
62 return get_package_version('cassandra')
63
64
65+def has_cassandra_version(minimum_ver):
66+ return LooseVersion(get_cassandra_version()) >= LooseVersion(minimum_ver)
67+
68+
69 def get_cassandra_config_dir():
70 if get_cassandra_edition() == 'dse':
71 return '/etc/dse/cassandra'
72@@ -523,13 +534,21 @@
73 hookenv.log('Creating SUPERUSER {}'.format(username))
74 else:
75 hookenv.log('Creating user {}'.format(username))
76- query(session,
77- 'INSERT INTO system_auth.users (name, super) VALUES (%s, %s)',
78- ConsistencyLevel.ALL, (username, superuser))
79- query(session,
80- 'INSERT INTO system_auth.credentials (username, salted_hash) '
81- 'VALUES (%s, %s)',
82- ConsistencyLevel.ALL, (username, encrypted_password))
83+ if has_cassandra_version('2.2'):
84+ query(session,
85+ 'INSERT INTO system_auth.roles '
86+ '(role, can_login, is_superuser, salted_hash) '
87+ 'VALUES (%s, TRUE, %s, %s)',
88+ ConsistencyLevel.ALL,
89+ (username, superuser, encrypted_password))
90+ else:
91+ query(session,
92+ 'INSERT INTO system_auth.users (name, super) VALUES (%s, %s)',
93+ ConsistencyLevel.ALL, (username, superuser))
94+ query(session,
95+ 'INSERT INTO system_auth.credentials (username, salted_hash) '
96+ 'VALUES (%s, %s)',
97+ ConsistencyLevel.ALL, (username, encrypted_password))
98
99
100 @logged
101@@ -714,6 +733,11 @@
102 # with the system_auth keyspace replication settings.
103 cassandra_yaml['endpoint_snitch'] = 'GossipingPropertyFileSnitch'
104
105+ # Per Bug #1523546 and CASSANDRA-9319, Thrift is disabled by default in
106+ # Cassandra 2.2. Ensure it is enabled if rpc_port is non-zero.
107+ if int(config['rpc_port']) > 0:
108+ cassandra_yaml['start_rpc'] = True
109+
110 cassandra_yaml.update(overrides)
111
112 write_cassandra_yaml(cassandra_yaml)
113
114=== modified file 'tests/test_helpers.py'
115--- tests/test_helpers.py 2015-09-04 11:12:27 +0000
116+++ tests/test_helpers.py 2015-12-08 10:18:39 +0000
117@@ -731,8 +731,10 @@
118 sentinel.consistency, sentinel.args)
119 self.assertEqual(session.execute.call_count, 4)
120
121+ @patch('helpers.get_cassandra_version')
122 @patch('helpers.query')
123- def test_ensure_user(self, query):
124+ def test_ensure_user(self, query, ver):
125+ ver.return_value = '2.1'
126 helpers.ensure_user(sentinel.session,
127 sentinel.username, sentinel.pwhash,
128 superuser=sentinel.supflag)
129@@ -746,6 +748,21 @@
130 ConsistencyLevel.ALL,
131 (sentinel.username, sentinel.pwhash))])
132
133+ @patch('helpers.get_cassandra_version')
134+ @patch('helpers.query')
135+ def test_ensure_user_22(self, query, ver):
136+ ver.return_value = '2.2'
137+ helpers.ensure_user(sentinel.session,
138+ sentinel.username, sentinel.pwhash,
139+ superuser=sentinel.supflag)
140+ query.assert_called_once_with(sentinel.session,
141+ 'INSERT INTO system_auth.roles (role, '
142+ 'can_login, is_superuser, salted_hash) '
143+ 'VALUES (%s, TRUE, %s, %s)',
144+ ConsistencyLevel.ALL,
145+ (sentinel.username, sentinel.supflag,
146+ sentinel.pwhash))
147+
148 @patch('helpers.ensure_user')
149 @patch('helpers.encrypt_password')
150 @patch('helpers.nodetool')
151@@ -992,6 +1009,79 @@
152 stream_throughput_outbound_megabits_per_sec: 200
153 tombstone_warn_threshold: 1000
154 tombstone_failure_threshold: 100000
155+ start_rpc: true
156+ ''')
157+ self.maxDiff = None
158+ self.assertEqual(yaml.safe_load(new_config),
159+ yaml.safe_load(expected_config))
160+
161+ # Confirm we can use an explicit cluster_name too.
162+ write_file.reset_mock()
163+ hookenv.config()['cluster_name'] = 'fubar'
164+ helpers.configure_cassandra_yaml()
165+ new_config = write_file.call_args[0][1]
166+ self.assertEqual(yaml.safe_load(new_config)['cluster_name'],
167+ 'fubar')
168+
169+ @patch('helpers.get_cassandra_version')
170+ @patch('helpers.get_cassandra_yaml_file')
171+ @patch('helpers.get_seed_ips')
172+ @patch('charmhelpers.core.host.write_file')
173+ def test_configure_cassandra_yaml_22(self, write_file, seed_ips, yaml_file,
174+ get_cassandra_version):
175+ get_cassandra_version.return_value = '2.0'
176+ hookenv.config().update(dict(num_tokens=128,
177+ cluster_name='test_cluster_name',
178+ partitioner='test_partitioner'))
179+
180+ seed_ips.return_value = ['10.20.0.1', '10.20.0.2', '10.20.0.3']
181+
182+ existing_config = '''
183+ seed_provider:
184+ - class_name: blah.SimpleSeedProvider
185+ parameters:
186+ - seeds: 127.0.0.1 # Comma separated list.
187+ start_rpc: false # Defaults to False starting 2.2
188+ '''
189+
190+ with tempfile.TemporaryDirectory() as tmpdir:
191+ yaml_config = os.path.join(tmpdir, 'c.yaml')
192+ yaml_file.return_value = yaml_config
193+ with open(yaml_config, 'w', encoding='UTF-8') as f:
194+ f.write(existing_config)
195+
196+ helpers.configure_cassandra_yaml()
197+
198+ self.assertEqual(write_file.call_count, 2)
199+ new_config = write_file.call_args[0][1]
200+
201+ expected_config = dedent('''\
202+ start_rpc: true
203+ cluster_name: test_cluster_name
204+ authenticator: PasswordAuthenticator
205+ num_tokens: 128
206+ partitioner: test_partitioner
207+ listen_address: 10.20.0.1
208+ rpc_address: 0.0.0.0
209+ rpc_port: 9160
210+ native_transport_port: 9042
211+ storage_port: 7000
212+ ssl_storage_port: 7001
213+ authorizer: AllowAllAuthorizer
214+ seed_provider:
215+ - class_name: blah.SimpleSeedProvider
216+ parameters:
217+ # No whitespace in seeds is important.
218+ - seeds: '10.20.0.1,10.20.0.2,10.20.0.3'
219+ endpoint_snitch: GossipingPropertyFileSnitch
220+ data_file_directories:
221+ - /var/lib/cassandra/data
222+ commitlog_directory: /var/lib/cassandra/commitlog
223+ saved_caches_directory: /var/lib/cassandra/saved_caches
224+ compaction_throughput_mb_per_sec: 16
225+ stream_throughput_outbound_megabits_per_sec: 200
226+ tombstone_warn_threshold: 1000
227+ tombstone_failure_threshold: 100000
228 ''')
229 self.maxDiff = None
230 self.assertEqual(yaml.safe_load(new_config),
231@@ -1044,6 +1134,7 @@
232 listen_address: 10.20.0.1
233 rpc_address: 0.0.0.0
234 broadcast_rpc_address: 10.30.0.1
235+ start_rpc: true
236 rpc_port: 9160
237 native_transport_port: 9042
238 storage_port: 7000
239
240=== modified file 'tests/test_integration.py'
241--- tests/test_integration.py 2015-11-13 05:35:42 +0000
242+++ tests/test_integration.py 2015-12-08 10:18:39 +0000
243@@ -556,6 +556,17 @@
244 install_keys=yaml.safe_dump([None]))
245
246
247+class Test22Deployment(Test1UnitDeployment):
248+ """Tests run on a single node Apache Cassandra 2.2 cluster.
249+ """
250+ rf = 1
251+ test_config = dict(
252+ edition='community',
253+ install_sources=yaml.safe_dump([
254+ 'deb http://www.apache.org/dist/cassandra/debian 22x main']),
255+ install_keys=yaml.safe_dump([None]))
256+
257+
258 # Bug #1417097 means we need to monkey patch Amulet for now.
259 real_juju = amulet.helpers.juju
260

Subscribers

People subscribed via source and target branches

to all changes: