Merge lp:~gnuoy/charm-helpers/memcache into lp:charm-helpers

Proposed by Liam Young
Status: Merged
Merged at revision: 664
Proposed branch: lp:~gnuoy/charm-helpers/memcache
Merge into: lp:charm-helpers
Diff against target: 193 lines (+141/-0)
6 files modified
charmhelpers/contrib/openstack/context.py (+21/-0)
charmhelpers/contrib/openstack/templates/memcached.conf (+53/-0)
charmhelpers/contrib/openstack/templates/section-keystone-authtoken-mitaka (+3/-0)
charmhelpers/contrib/openstack/utils.py (+25/-0)
tests/contrib/openstack/test_os_contexts.py (+24/-0)
tests/contrib/openstack/test_os_utils.py (+15/-0)
To merge this branch: bzr merge lp:~gnuoy/charm-helpers/memcache
Reviewer Review Type Date Requested Status
James Page Approve
Review via email: mp+312065@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Felipe Reyes (freyes) wrote :

Hi Liam,

what's rationale to have a locahost only memcached process per unit?, is this to provide some sort of resilience during restart of openstack daemons?

Best,

Revision history for this message
James Page (james-page) wrote :

Felipe

This is to support use of memcache for token auth caching via the keystoneauth middleware that all projects use - the in-process cache is officially deprecated and support will be dropped in Ocata - using a local only memcache instance allows token auth caching across processes improving memory efficiency.

We could use a centralized memcache deployment, but I'd rather keep the failure domain unit centric for this feature.

Revision history for this message
James Page (james-page) wrote :

A few minor comments - other than those looks OK

review: Needs Fixing
lp:~gnuoy/charm-helpers/memcache updated
665. By Liam Young

Add header to memcached.conf to show it is Juju managed
Install python-memcache incase the OpenStack service does not have it down as a dependancy
Enable memcache on Mitaka+ for consistancy

Revision history for this message
James Page (james-page) :
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/context.py'
2--- charmhelpers/contrib/openstack/context.py 2016-11-26 15:31:11 +0000
3+++ charmhelpers/contrib/openstack/context.py 2016-11-30 10:40:30 +0000
4@@ -90,6 +90,7 @@
5 from charmhelpers.contrib.openstack.utils import (
6 config_flags_parser,
7 get_host_ip,
8+ enable_memcache,
9 )
10 from charmhelpers.core.unitdata import kv
11
12@@ -1512,3 +1513,23 @@
13 "".format(self.ctxt['aa_profile'],
14 self.ctxt['aa_profile_mode']))
15 raise e
16+
17+
18+class MemcacheContext(OSContextGenerator):
19+ """Memcache context
20+
21+ This context provides options for configuring a local memcache client and
22+ server
23+ """
24+ def __call__(self):
25+ ctxt = {}
26+ ctxt['use_memcache'] = enable_memcache(config('openstack-origin'))
27+ if ctxt['use_memcache']:
28+ ctxt['memcache_server'] = '::1'
29+ ctxt['memcache_server_formatted'] = '[::1]'
30+ ctxt['memcache_port'] = '11211'
31+ ctxt['memcache_url'] = 'inet6:{}:{}'.format(
32+ ctxt['memcache_server_formatted'],
33+ ctxt['memcache_port'])
34+
35+ return ctxt
36
37=== added file 'charmhelpers/contrib/openstack/templates/memcached.conf'
38--- charmhelpers/contrib/openstack/templates/memcached.conf 1970-01-01 00:00:00 +0000
39+++ charmhelpers/contrib/openstack/templates/memcached.conf 2016-11-30 10:40:30 +0000
40@@ -0,0 +1,53 @@
41+###############################################################################
42+# [ WARNING ]
43+# memcached configuration file maintained by Juju
44+# local changes may be overwritten.
45+###############################################################################
46+
47+# memcached default config file
48+# 2003 - Jay Bonci <jaybonci@debian.org>
49+# This configuration file is read by the start-memcached script provided as
50+# part of the Debian GNU/Linux distribution.
51+
52+# Run memcached as a daemon. This command is implied, and is not needed for the
53+# daemon to run. See the README.Debian that comes with this package for more
54+# information.
55+-d
56+
57+# Log memcached's output to /var/log/memcached
58+logfile /var/log/memcached.log
59+
60+# Be verbose
61+# -v
62+
63+# Be even more verbose (print client commands as well)
64+# -vv
65+
66+# Start with a cap of 64 megs of memory. It's reasonable, and the daemon default
67+# Note that the daemon will grow to this size, but does not start out holding this much
68+# memory
69+-m 64
70+
71+# Default connection port is 11211
72+-p {{ memcache_port }}
73+
74+# Run the daemon as root. The start-memcached will default to running as root if no
75+# -u command is present in this config file
76+-u memcache
77+
78+# Specify which IP address to listen on. The default is to listen on all IP addresses
79+# This parameter is one of the only security measures that memcached has, so make sure
80+# it's listening on a firewalled interface.
81+-l {{ memcache_server }}
82+
83+# Limit the number of simultaneous incoming connections. The daemon default is 1024
84+# -c 1024
85+
86+# Lock down all paged memory. Consult with the README and homepage before you do this
87+# -k
88+
89+# Return error when memory is exhausted (rather than removing items)
90+# -M
91+
92+# Maximize core file limit
93+# -r
94
95=== modified file 'charmhelpers/contrib/openstack/templates/section-keystone-authtoken-mitaka'
96--- charmhelpers/contrib/openstack/templates/section-keystone-authtoken-mitaka 2016-11-11 18:38:30 +0000
97+++ charmhelpers/contrib/openstack/templates/section-keystone-authtoken-mitaka 2016-11-30 10:40:30 +0000
98@@ -14,4 +14,7 @@
99 username = {{ admin_user }}
100 password = {{ admin_password }}
101 signing_dir = {{ signing_dir }}
102+{% if use_memcache == true %}
103+memcached_servers = {{ memcache_url }}
104+{% endif -%}
105 {% endif -%}
106
107=== modified file 'charmhelpers/contrib/openstack/utils.py'
108--- charmhelpers/contrib/openstack/utils.py 2016-11-28 16:54:19 +0000
109+++ charmhelpers/contrib/openstack/utils.py 2016-11-30 10:40:30 +0000
110@@ -1925,3 +1925,28 @@
111 application_version_set(os_release(package))
112 else:
113 application_version_set(application_version)
114+
115+
116+def enable_memcache(source=None, release=None):
117+ """Determine if memcache should be enabled on the local unit
118+
119+ @param source: source string for charm
120+ @param release: release of OpenStack currently deployed
121+ @returns boolean Whether memcache should be enabled
122+ """
123+ if not release:
124+ release = get_os_codename_install_source(source)
125+ return release >= 'mitaka'
126+
127+
128+def token_cache_pkgs(source=None, release=None):
129+ """Determine additional packages needed for token caching
130+
131+ @param source: source string for charm
132+ @param release: release of OpenStack currently deployed
133+ @returns List of package to enable token caching
134+ """
135+ packages = []
136+ if enable_memcache(source=source, release=release):
137+ packages.extend(['memcached', 'python-memcache'])
138+ return packages
139
140=== modified file 'tests/contrib/openstack/test_os_contexts.py'
141--- tests/contrib/openstack/test_os_contexts.py 2016-11-26 15:31:11 +0000
142+++ tests/contrib/openstack/test_os_contexts.py 2016-11-30 10:40:30 +0000
143@@ -3002,3 +3002,27 @@
144 AA.setup_aa_profile()
145 self.check_call.assert_called_with(['aa-disable', 'fake-aa-profile'])
146 AA.manually_disable_aa_profile.assert_called_with()
147+
148+ @patch.object(context, 'enable_memcache')
149+ def test_memcache_context(self, _enable_memcache):
150+ _enable_memcache.return_value = True
151+ config = {'openstack-origin': 'distro'}
152+ self.config.side_effect = fake_config(config)
153+ ctxt = context.MemcacheContext()
154+ self.assertTrue(ctxt()['use_memcache'])
155+ expect = {
156+ 'memcache_port': '11211',
157+ 'memcache_server': '::1',
158+ 'memcache_server_formatted': '[::1]',
159+ 'memcache_url': 'inet6:[::1]:11211',
160+ 'use_memcache': True}
161+ self.assertEqual(ctxt(), expect)
162+
163+ @patch.object(context, 'enable_memcache')
164+ def test_memcache_off_context(self, _enable_memcache):
165+ _enable_memcache.return_value = False
166+ config = {'openstack-origin': 'distro'}
167+ self.config.side_effect = fake_config(config)
168+ ctxt = context.MemcacheContext()
169+ self.assertFalse(ctxt()['use_memcache'])
170+ self.assertEqual(ctxt(), {'use_memcache': False})
171
172=== modified file 'tests/contrib/openstack/test_os_utils.py'
173--- tests/contrib/openstack/test_os_utils.py 2016-10-10 12:06:28 +0000
174+++ tests/contrib/openstack/test_os_utils.py 2016-11-30 10:40:30 +0000
175@@ -154,3 +154,18 @@
176 'my-pkg', fatal=False)
177 mock_git_os_codename_install_source.assert_called_once_with(
178 'cloud-pocket')
179+
180+ @mock.patch.object(utils, 'get_os_codename_install_source')
181+ def test_enable_memcache(self, _get_os_codename_install_source):
182+ _get_os_codename_install_source.return_value = 'icehouse'
183+ self.assertFalse(utils.enable_memcache('distro'))
184+ _get_os_codename_install_source.return_value = 'zebra'
185+ self.assertTrue(utils.enable_memcache('distro'))
186+
187+ @mock.patch.object(utils, 'enable_memcache')
188+ def test_enable_token_cache_pkgs(self, _enable_memcache):
189+ _enable_memcache.return_value = False
190+ self.assertEqual(utils.token_cache_pkgs(source='distro'), [])
191+ _enable_memcache.return_value = True
192+ self.assertEqual(utils.token_cache_pkgs(source='distro'),
193+ ['memcached', 'python-memcache'])

Subscribers

People subscribed via source and target branches