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

Proposed by Liam Young
Status: Merged
Merged at revision: 665
Proposed branch: lp:~gnuoy/charm-helpers/memcache-amulet
Merge into: lp:charm-helpers
Diff against target: 69 lines (+62/-0)
1 file modified
charmhelpers/contrib/openstack/amulet/utils.py (+62/-0)
To merge this branch: bzr merge lp:~gnuoy/charm-helpers/memcache-amulet
Reviewer Review Type Date Requested Status
Alex Kavanagh Approve
charmers Pending
Review via email: mp+312459@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Alex Kavanagh (ajkavanagh) wrote :

Comment re: style.

666. By Liam Young

Fixed up style after mp feedback

Revision history for this message
Alex Kavanagh (ajkavanagh) wrote :

LGTM. Thanks!

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/amulet/utils.py'
2--- charmhelpers/contrib/openstack/amulet/utils.py 2016-10-12 21:09:17 +0000
3+++ charmhelpers/contrib/openstack/amulet/utils.py 2016-12-07 10:34:55 +0000
4@@ -1133,3 +1133,65 @@
5 else:
6 msg = 'No message retrieved.'
7 amulet.raise_status(amulet.FAIL, msg)
8+
9+ def validate_memcache(self, sentry_unit, conf, os_release,
10+ earliest_release=5, section='keystone_authtoken',
11+ check_kvs=None):
12+ """Check Memcache is running and is configured to be used
13+
14+ Example call from Amulet test:
15+
16+ def test_110_memcache(self):
17+ u.validate_memcache(self.neutron_api_sentry,
18+ '/etc/neutron/neutron.conf',
19+ self._get_openstack_release())
20+
21+ :param sentry_unit: sentry unit
22+ :param conf: OpenStack config file to check memcache settings
23+ :param os_release: Current OpenStack release int code
24+ :param earliest_release: Earliest Openstack release to check int code
25+ :param section: OpenStack config file section to check
26+ :param check_kvs: Dict of settings to check in config file
27+ :returns: None
28+ """
29+ if os_release < earliest_release:
30+ self.log.debug('Skipping memcache checks for deployment. {} <'
31+ 'mitaka'.format(os_release))
32+ return
33+ _kvs = check_kvs or {'memcached_servers': 'inet6:[::1]:11211'}
34+ self.log.debug('Checking memcached is running')
35+ ret = self.validate_services_by_name({sentry_unit: ['memcached']})
36+ if ret:
37+ amulet.raise_status(amulet.FAIL, msg='Memcache running check'
38+ 'failed {}'.format(ret))
39+ else:
40+ self.log.debug('OK')
41+ self.log.debug('Checking memcache url is configured in {}'.format(
42+ conf))
43+ if self.validate_config_data(sentry_unit, conf, section, _kvs):
44+ message = "Memcache config error in: {}".format(conf)
45+ amulet.raise_status(amulet.FAIL, msg=message)
46+ else:
47+ self.log.debug('OK')
48+ self.log.debug('Checking memcache configuration in '
49+ '/etc/memcached.conf')
50+ contents = self.file_contents_safe(sentry_unit, '/etc/memcached.conf',
51+ fatal=True)
52+ expected = {
53+ '-p': '11211',
54+ '-l': '::1'}
55+ found = []
56+ for key, value in expected.items():
57+ for line in contents.split('\n'):
58+ if line.startswith(key):
59+ self.log.debug('Checking {} is set to {}'.format(
60+ key,
61+ value))
62+ assert value == line.split()[-1]
63+ self.log.debug(line.split()[-1])
64+ found.append(key)
65+ if sorted(found) == sorted(expected.keys()):
66+ self.log.debug('OK')
67+ else:
68+ message = "Memcache config error in: /etc/memcached.conf"
69+ amulet.raise_status(amulet.FAIL, msg=message)

Subscribers

People subscribed via source and target branches