diff options
| author | Felipe Reyes <felipe.reyes@canonical.com> | 2018-05-18 14:58:22 +0000 | 
|---|---|---|
| committer | Felipe Reyes <felipe.reyes@canonical.com> | 2018-05-18 15:14:17 +0000 | 
| commit | eca7ebd98976404e20bcefc659a19be5568565b6 (patch) | |
| tree | 0a2cae48d0cf23dd7c35ef92462c799983b9229c /unit_tests | |
| parent | 669bf1971e494548bdb5d4dd9eba4f1d00962424 (diff) | |
update-status: check replica set status when relation is made
The replica set state has to be queried and exposed in the workload message only when the replica-set relation has peers, otherwise mongodb's replica set is not initialized, for example when the user is using shardening. 
Diffstat (limited to 'unit_tests')
| -rw-r--r-- | unit_tests/test_hooks.py | 11 | 
1 files changed, 8 insertions, 3 deletions
| diff --git a/unit_tests/test_hooks.py b/unit_tests/test_hooks.py index 7cc7f41..354d104 100644 --- a/unit_tests/test_hooks.py +++ b/unit_tests/test_hooks.py @@ -36,6 +36,7 @@ class MongoHooksTest(CharmTestCase):  self.config.side_effect = self.test_config.get  self.relation_get.side_effect = self.test_relation.get + @patch.object(hooks, 'is_relation_made')  @patch.object(hooks, 'get_replicaset_status')  @patch.object(hooks, 'restart_mongod')  @patch.object(hooks, 'enable_replset') @@ -43,8 +44,8 @@ class MongoHooksTest(CharmTestCase):  # additional parameter sent into the function  @patch.dict('os.environ', JUJU_UNIT_NAME='fake-unit/0')  def test_replica_set_relation_joined(self, mock_enable_replset, - mock_restart, - mock_get_replset_status): + mock_restart, mock_get_replset_status, + mock_is_rel_made):  self.unit_get.return_value = 'private.address'  self.test_config.set('port', '1234')  self.test_config.set('replicaset', 'fake-replicaset') @@ -52,6 +53,7 @@ class MongoHooksTest(CharmTestCase):  mock_enable_replset.return_value = False  mock_get_replset_status.return_value = 'PRIMARY' + mock_is_rel_made.return_value = True  hooks.replica_set_relation_joined() @@ -279,6 +281,7 @@ class MongoHooksTest(CharmTestCase):  mock_subprocess.assert_called_once_with(expected_cmd, shell=True)  self.assertFalse(rv) + @patch.object(hooks, 'is_relation_made')  @patch.object(hooks, 'run_admin_command')  @patch.object(hooks, 'is_leader')  @patch.object(hooks, 'get_replicaset_status') @@ -294,7 +297,8 @@ class MongoHooksTest(CharmTestCase):  mock_is_primary,  mock_get_replset_status,  mock_is_leader, - mock_run_admin_cmd): + mock_run_admin_cmd, + mock_is_rel_made):  # set the unit_get('private-address')  mock_unit_get.return_value = 'juju-local-unit-0.local'  mock_relation_get.return_value = None @@ -309,6 +313,7 @@ class MongoHooksTest(CharmTestCase):  mock_is_leader.return_value = False  mock_run_admin_cmd.return_value = {'myState': hooks.MONGO_PRIMARY}  mock_get_replset_status.return_value = 'PRIMARY' + mock_is_rel_made.return_value = True  hooks.replica_set_relation_changed() | 
