Merge ~mthaddon/charm-mongodb/+git/mongodb-charm:fix-tests into ~mongodb-charmers/charm-mongodb:master

Proposed by Tom Haddon
Status: Merged
Approved by: Jamon Camisso
Approved revision: 0e8598b5a985f3b20ce9ffefbaf6f6dc702724e0
Merged at revision: f04914ab678d2808d0bd8d22386fe5f2f3657470
Proposed branch: ~mthaddon/charm-mongodb/+git/mongodb-charm:fix-tests
Merge into: ~mongodb-charmers/charm-mongodb:master
Diff against target: 49 lines (+17/-2)
2 files modified
hooks/hooks.py (+1/-1)
unit_tests/test_hooks.py (+16/-1)
Reviewer Review Type Date Requested Status
Martin Hilton (community) Approve
MongoDB Charm Maintainers Pending
Review via email: mp+358641@code.launchpad.net

Commit message

Fix unit tests for bionic and later lp#1802926

Description of the change

Fix unit tests for bionic and later lp#1802926

Drive-by typo fix in hooks/hooks.py

To post a comment you must log in.
Revision history for this message
🤖 Canonical IS Merge Bot (canonical-is-mergebot) wrote :

This merge proposal is being monitored by mergebot. Change the status to Approved to merge.

Revision history for this message
Martin Hilton (martin-hilton) wrote :

LGTM

review: Approve
Revision history for this message
Jamon Camisso (jamon) wrote :

Looks good, tests pass, +1'ed.

Revision history for this message
🤖 Canonical IS Merge Bot (canonical-is-mergebot) wrote :

Change successfully merged at revision f04914ab678d2808d0bd8d22386fe5f2f3657470

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
diff --git a/hooks/hooks.py b/hooks/hooks.py
index fe4c4de..54902f5 100755
--- a/hooks/hooks.py
+++ b/hooks/hooks.py
@@ -539,7 +539,7 @@ def run_admin_command(client, cmdstr):
539539
540540
541def join_replset(master_node=None, host=None):541def join_replset(master_node=None, host=None):
542 # TODO: This methoud shouldn't accept any arguments becase we don't care542 # TODO: This method shouldn't accept any arguments because we don't care
543 # about master_node - we always run replset admin commands on543 # about master_node - we always run replset admin commands on
544 # localhost.544 # localhost.
545 # However, that might break other code calling this method.545 # However, that might break other code calling this method.
diff --git a/unit_tests/test_hooks.py b/unit_tests/test_hooks.py
index 354d104..3432cfb 100644
--- a/unit_tests/test_hooks.py
+++ b/unit_tests/test_hooks.py
@@ -114,8 +114,13 @@ class MongoHooksTest(CharmTestCase):
114114
115 self.assertEqual(2, mock_run_admin_command.call_count)115 self.assertEqual(2, mock_run_admin_command.call_count)
116116
117 @patch.object(hooks, 'run')
118 @patch.object(hooks, 'juju_log')
119 @patch.object(hooks, 'is_bionic_or_greater')
117 @patch.object(hooks, 'mongo_client_smart')120 @patch.object(hooks, 'mongo_client_smart')
118 def test_join_replset(self, mock_mongo_client):121 def test_join_replset(self, mock_mongo_client, mock_is_bionic_or_greater, mock_juju_log, mock_run):
122 # Test with OS version not bionic or greater first.
123 mock_is_bionic_or_greater.return_value = False
119 hooks.join_replset()124 hooks.join_replset()
120 self.assertFalse(mock_mongo_client.called)125 self.assertFalse(mock_mongo_client.called)
121126
@@ -131,6 +136,16 @@ class MongoHooksTest(CharmTestCase):
131 hooks.join_replset(master_node='mongo.local', host='fake-host')136 hooks.join_replset(master_node='mongo.local', host='fake-host')
132 mock_mongo_client.assert_called_with('localhost',137 mock_mongo_client.assert_called_with('localhost',
133 'rs.add("fake-host")')138 'rs.add("fake-host")')
139 # Also test with bionic or greater.
140 old_mcr = hooks.MONGO_CLIENT_RETRIES
141 hooks.MONGO_CLIENT_RETRIES = 0
142 mock_is_bionic_or_greater.return_value = True
143 mock_mongo_client.reset_mock()
144 hooks.join_replset(master_node='mongo.local', host='fake-host')
145 expected_run = ['mongo', '--quiet', '--host', "localhost", '--eval', 'printjson(rs.add("fake-host"))']
146 mock_run.assert_called_with(expected_run)
147 # Restore mongo client retries for other tests.
148 hooks.MONGO_CLIENT_RETRIES = old_mcr
134149
135 @patch.object(hooks, 'mongo_client')150 @patch.object(hooks, 'mongo_client')
136 def test_leave_replset(self, mock_mongo_client):151 def test_leave_replset(self, mock_mongo_client):

Subscribers

People subscribed via source and target branches

to status/vote changes: