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
=== modified file 'hooks/rabbit_utils.py'
--- hooks/rabbit_utils.py 2015-09-16 17:56:59 +0000
+++ hooks/rabbit_utils.py 2015-09-28 21:40:59 +0000
@@ -11,6 +11,10 @@
11 get_hostname,11 get_hostname,
12)12)
1313
14from charmhelpers.core.decorators import (
15 retry_on_exception,
16)
17
14from charmhelpers.core.hookenv import (18from charmhelpers.core.hookenv import (
15 config,19 config,
16 relation_ids,20 relation_ids,
@@ -99,6 +103,7 @@
99 return vhost in list_vhosts()103 return vhost in list_vhosts()
100104
101105
106@retry_on_exception(3, base_delay=3, exc_type=subprocess.CalledProcessError)
102def create_vhost(vhost):107def create_vhost(vhost):
103 if vhost_exists(vhost):108 if vhost_exists(vhost):
104 return109 return
105110
=== modified file 'hooks/rabbitmq_server_relations.py'
--- hooks/rabbitmq_server_relations.py 2015-09-22 13:55:23 +0000
+++ hooks/rabbitmq_server_relations.py 2015-09-28 21:40:59 +0000
@@ -546,6 +546,12 @@
546546
547@hooks.hook('nrpe-external-master-relation-changed')547@hooks.hook('nrpe-external-master-relation-changed')
548def update_nrpe_checks():548def update_nrpe_checks():
549
550 if not is_relation_made("nrpe-external-master"):
551 log("Not found relation nrpe-external-master, skipping update nrpe checks",
552 level=WARN)
553 return
554
549 if os.path.isdir(NAGIOS_PLUGINS):555 if os.path.isdir(NAGIOS_PLUGINS):
550 rsync(os.path.join(os.getenv('CHARM_DIR'), 'scripts',556 rsync(os.path.join(os.getenv('CHARM_DIR'), 'scripts',
551 'check_rabbitmq.py'),557 'check_rabbitmq.py'),
552558
=== modified file 'unit_tests/test_rabbit_utils.py'
--- unit_tests/test_rabbit_utils.py 2015-04-13 15:42:57 +0000
+++ unit_tests/test_rabbit_utils.py 2015-09-28 21:40:59 +0000
@@ -3,6 +3,7 @@
3import unittest3import unittest
4import tempfile4import tempfile
5import sys5import sys
6import subprocess
67
7import rabbit_utils8import rabbit_utils
8sys.modules['MySQLdb'] = mock.Mock()9sys.modules['MySQLdb'] = mock.Mock()
@@ -69,3 +70,30 @@
69 self.assertEqual(lines[0], "#somedata\n")70 self.assertEqual(lines[0], "#somedata\n")
70 self.assertEqual(lines[1], "%s %s\n" % (map.items()[0]))71 self.assertEqual(lines[1], "%s %s\n" % (map.items()[0]))
71 self.assertEqual(lines[4], "%s %s\n" % (map.items()[3]))72 self.assertEqual(lines[4], "%s %s\n" % (map.items()[3]))
73
74 @mock.patch("rabbit_utils.log")
75 @mock.patch("rabbit_utils.vhost_exists")
76 @mock.patch("rabbit_utils.subprocess.check_call")
77 def test_create_vhost(self, check_call, vhost, log):
78 vhost.return_value = False
79 rabbit_utils.create_vhost("rabbit")
80 check_call.assert_called_once_with([rabbit_utils.RABBITMQ_CTL,
81 'add_vhost',
82 "rabbit"])
83
84 @mock.patch("charmhelpers.core.decorators.log")
85 @mock.patch("rabbit_utils.log")
86 @mock.patch("rabbit_utils.vhost_exists")
87 @mock.patch("rabbit_utils.subprocess.check_call")
88 def test_create_vhost_exc(self, check_call, vhost, log, *a, **k):
89 vhost.return_value = False
90
91 def f(*a, **k):
92 raise subprocess.CalledProcessError(-1, "")
93
94 check_call.side_effect = f
95
96 try:
97 rabbit_utils.create_vhost("rabbit")
98 except:
99 self.assertTrue(len(check_call.mock_calls) > 1)

Subscribers

People subscribed via source and target branches