Merge lp:~hopem/charm-helpers/add-rbd-cache-config-support into lp:charm-helpers

Proposed by Edward Hope-Morley
Status: Merged
Merged at revision: 457
Proposed branch: lp:~hopem/charm-helpers/add-rbd-cache-config-support
Merge into: lp:charm-helpers
Diff against target: 130 lines (+77/-6)
2 files modified
charmhelpers/contrib/openstack/templates/ceph.conf (+6/-0)
tests/contrib/openstack/test_os_contexts.py (+71/-6)
To merge this branch: bzr merge lp:~hopem/charm-helpers/add-rbd-cache-config-support
Reviewer Review Type Date Requested Status
Liam Young (community) Approve
Review via email: mp+264538@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Liam Young (gnuoy) wrote :

Approve

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'charmhelpers/contrib/openstack/templates/ceph.conf'
2--- charmhelpers/contrib/openstack/templates/ceph.conf 2015-06-24 21:26:59 +0000
3+++ charmhelpers/contrib/openstack/templates/ceph.conf 2015-07-14 09:18:37 +0000
4@@ -13,3 +13,9 @@
5 err to syslog = {{ use_syslog }}
6 clog to syslog = {{ use_syslog }}
7
8+[client]
9+{% if rbd_client_cache_settings -%}
10+{% for key, value in rbd_client_cache_settings.iteritems() -%}
11+{{ key }} = {{ value }}
12+{% endfor -%}
13+{%- endif %}
14\ No newline at end of file
15
16=== modified file 'tests/contrib/openstack/test_os_contexts.py'
17--- tests/contrib/openstack/test_os_contexts.py 2015-04-29 12:52:18 +0000
18+++ tests/contrib/openstack/test_os_contexts.py 2015-07-14 09:18:37 +0000
19@@ -989,9 +989,14 @@
20 @patch('os.mkdir')
21 @patch.object(context, 'ensure_packages')
22 def test_ceph_context_with_data(self, ensure_packages, mkdir, isdir,
23- config):
24+ mock_config):
25 '''Test ceph context with all relation data'''
26- config.return_value = True
27+ config_dict = {'use-syslog': True}
28+
29+ def fake_config(key):
30+ return config_dict.get(key)
31+
32+ mock_config.side_effect = fake_config
33 isdir.return_value = False
34 relation = FakeRelation(relation_data=CEPH_RELATION)
35 self.relation_get.side_effect = relation.get
36@@ -1031,11 +1036,16 @@
37 @patch('os.mkdir')
38 @patch.object(context, 'ensure_packages')
39 def test_ceph_context_with_public_addr(
40- self, ensure_packages, mkdir, isdir, config):
41+ self, ensure_packages, mkdir, isdir, mock_config):
42 '''Test ceph context in host with multiple networks with all
43 relation data'''
44 isdir.return_value = False
45- config.return_value = True
46+ config_dict = {'use-syslog': True}
47+
48+ def fake_config(key):
49+ return config_dict.get(key)
50+
51+ mock_config.side_effect = fake_config
52 relation = FakeRelation(relation_data=CEPH_RELATION_WITH_PUBLIC_ADDR)
53 self.relation_get.side_effect = relation.get
54 self.relation_ids.side_effect = relation.relation_ids
55@@ -1053,6 +1063,56 @@
56 mkdir.assert_called_with('/etc/ceph')
57
58 @patch.object(context, 'config')
59+ @patch('os.path.isdir')
60+ @patch('os.mkdir')
61+ @patch.object(context, 'ensure_packages')
62+ def test_ceph_context_with_rbd_cache(self, ensure_packages, mkdir, isdir,
63+ mock_config):
64+ isdir.return_value = False
65+ config_dict = {'rbd-client-cache': 'enabled',
66+ 'use-syslog': False}
67+
68+ def fake_config(key):
69+ return config_dict.get(key)
70+
71+ mock_config.side_effect = fake_config
72+ relation = FakeRelation(relation_data=CEPH_RELATION_WITH_PUBLIC_ADDR)
73+ self.relation_get.side_effect = relation.get
74+ self.relation_ids.side_effect = relation.relation_ids
75+ self.related_units.side_effect = relation.relation_units
76+
77+ class CephContextWithRBDCache(context.CephContext):
78+ def __call__(self):
79+ ctxt = super(CephContextWithRBDCache, self).__call__()
80+
81+ rbd_cache = fake_config('rbd-client-cache') or ""
82+ if rbd_cache.lower() == "enabled":
83+ ctxt['rbd_client_cache_settings'] = \
84+ {'rbd cache': 'true',
85+ 'rbd cache writethrough until flush': 'true'}
86+ elif rbd_cache.lower() == "disabled":
87+ ctxt['rbd_client_cache_settings'] = \
88+ {'rbd cache': 'false'}
89+
90+ return ctxt
91+
92+ ceph = CephContextWithRBDCache()
93+ result = ceph()
94+ expected = {
95+ 'mon_hosts': '192.168.1.10 192.168.1.11',
96+ 'auth': 'foo',
97+ 'key': 'bar',
98+ 'use_syslog': 'false',
99+ }
100+ expected['rbd_client_cache_settings'] = \
101+ {'rbd cache': 'true',
102+ 'rbd cache writethrough until flush': 'true'}
103+
104+ self.assertDictEqual(result, expected)
105+ ensure_packages.assert_called_with(['ceph-common'])
106+ mkdir.assert_called_with('/etc/ceph')
107+
108+ @patch.object(context, 'config')
109 def test_sysctl_context_with_config(self, config):
110 self.charm_name.return_value = 'test-charm'
111 config.return_value = '{ kernel.max_pid: "1337"}'
112@@ -1080,11 +1140,16 @@
113 @patch('os.mkdir')
114 @patch.object(context, 'ensure_packages')
115 def test_ceph_context_missing_public_addr(
116- self, ensure_packages, mkdir, isdir, config):
117+ self, ensure_packages, mkdir, isdir, mock_config):
118 '''Test ceph context in host with multiple networks with no
119 ceph-public-addr in relation data'''
120 isdir.return_value = False
121- config.return_value = True
122+ config_dict = {'use-syslog': True}
123+
124+ def fake_config(key):
125+ return config_dict.get(key)
126+
127+ mock_config.side_effect = fake_config
128 relation = deepcopy(CEPH_RELATION_WITH_PUBLIC_ADDR)
129 del relation['ceph:0']['ceph/0']['ceph-public-address']
130 relation = FakeRelation(relation_data=relation)

Subscribers

People subscribed via source and target branches