Merge lp:~niedbalski/charms/trusty/rabbitmq-server/fix-lp-1500552 into lp:~openstack-charmers-archive/charms/trusty/rabbitmq-server/next

Proposed by Jorge Niedbalski
Status: Work in progress
Proposed branch: lp:~niedbalski/charms/trusty/rabbitmq-server/fix-lp-1500552
Merge into: lp:~openstack-charmers-archive/charms/trusty/rabbitmq-server/next
Diff against target: 82 lines (+39/-0)
3 files modified
hooks/rabbit_utils.py (+5/-0)
hooks/rabbitmq_server_relations.py (+6/-0)
unit_tests/test_rabbit_utils.py (+28/-0)
To merge this branch: bzr merge lp:~niedbalski/charms/trusty/rabbitmq-server/fix-lp-1500552
Reviewer Review Type Date Requested Status
Ryan Beisner (community) Needs Resubmitting
Review via email: mp+272666@code.launchpad.net

Description of the change

Fix for LP: #1500552

To post a comment you must log in.
116. By Jorge Niedbalski

Skip update nrpe checks if no relation nrpe-relation-changed has been made

Revision history for this message
Ryan Beisner (1chb1n) wrote :

Thank you for your work on this. This proposal, or its refactored equivalent, will need to be proposed as a gerrit change if it is to be exercised and reviewed.

review: Needs Resubmitting

Unmerged revisions

116. By Jorge Niedbalski

Skip update nrpe checks if no relation nrpe-relation-changed has been made

115. By Jorge Niedbalski

- Fix for LP: #1500552
- Adds an exception retry block on 'create_vhost' method.
- Adds unit test for rabbit_utils.create_vhost method.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'hooks/rabbit_utils.py'
2--- hooks/rabbit_utils.py 2015-09-16 17:56:59 +0000
3+++ hooks/rabbit_utils.py 2015-09-28 21:40:59 +0000
4@@ -11,6 +11,10 @@
5 get_hostname,
6 )
7
8+from charmhelpers.core.decorators import (
9+ retry_on_exception,
10+)
11+
12 from charmhelpers.core.hookenv import (
13 config,
14 relation_ids,
15@@ -99,6 +103,7 @@
16 return vhost in list_vhosts()
17
18
19+@retry_on_exception(3, base_delay=3, exc_type=subprocess.CalledProcessError)
20 def create_vhost(vhost):
21 if vhost_exists(vhost):
22 return
23
24=== modified file 'hooks/rabbitmq_server_relations.py'
25--- hooks/rabbitmq_server_relations.py 2015-09-22 13:55:23 +0000
26+++ hooks/rabbitmq_server_relations.py 2015-09-28 21:40:59 +0000
27@@ -546,6 +546,12 @@
28
29 @hooks.hook('nrpe-external-master-relation-changed')
30 def update_nrpe_checks():
31+
32+ if not is_relation_made("nrpe-external-master"):
33+ log("Not found relation nrpe-external-master, skipping update nrpe checks",
34+ level=WARN)
35+ return
36+
37 if os.path.isdir(NAGIOS_PLUGINS):
38 rsync(os.path.join(os.getenv('CHARM_DIR'), 'scripts',
39 'check_rabbitmq.py'),
40
41=== modified file 'unit_tests/test_rabbit_utils.py'
42--- unit_tests/test_rabbit_utils.py 2015-04-13 15:42:57 +0000
43+++ unit_tests/test_rabbit_utils.py 2015-09-28 21:40:59 +0000
44@@ -3,6 +3,7 @@
45 import unittest
46 import tempfile
47 import sys
48+import subprocess
49
50 import rabbit_utils
51 sys.modules['MySQLdb'] = mock.Mock()
52@@ -69,3 +70,30 @@
53 self.assertEqual(lines[0], "#somedata\n")
54 self.assertEqual(lines[1], "%s %s\n" % (map.items()[0]))
55 self.assertEqual(lines[4], "%s %s\n" % (map.items()[3]))
56+
57+ @mock.patch("rabbit_utils.log")
58+ @mock.patch("rabbit_utils.vhost_exists")
59+ @mock.patch("rabbit_utils.subprocess.check_call")
60+ def test_create_vhost(self, check_call, vhost, log):
61+ vhost.return_value = False
62+ rabbit_utils.create_vhost("rabbit")
63+ check_call.assert_called_once_with([rabbit_utils.RABBITMQ_CTL,
64+ 'add_vhost',
65+ "rabbit"])
66+
67+ @mock.patch("charmhelpers.core.decorators.log")
68+ @mock.patch("rabbit_utils.log")
69+ @mock.patch("rabbit_utils.vhost_exists")
70+ @mock.patch("rabbit_utils.subprocess.check_call")
71+ def test_create_vhost_exc(self, check_call, vhost, log, *a, **k):
72+ vhost.return_value = False
73+
74+ def f(*a, **k):
75+ raise subprocess.CalledProcessError(-1, "")
76+
77+ check_call.side_effect = f
78+
79+ try:
80+ rabbit_utils.create_vhost("rabbit")
81+ except:
82+ self.assertTrue(len(check_call.mock_calls) > 1)

Subscribers

People subscribed via source and target branches