Пример #1
0
    def test_master_unset(self, is_ready):
        # Master helper returns None when no relation data is set.
        is_ready.return_value = True

        # No connection details present on relation, yet.
        self.assertIsNone(
            client._master(self.log, self.relation, self.local_unit))
        self.assertFalse(is_ready.called)
Пример #2
0
    def test_master_unready(self, is_ready):
        # Master helper returns None when relation app data is set but not yet ready.
        is_ready.return_value = False
        standbys = ["host=standby1", "host=standby2"]
        rd = {"master": "host=master", "standbys": "\n".join(standbys)}
        self.harness.update_relation_data(self.relation_id,
                                          self.remote_app_name, rd)

        self.assertIsNone(
            client._master(self.log, self.relation, self.local_unit))
        self.assertTrue(is_ready.called)
        is_ready.assert_called_once_with(
            self.log,
            self.leadership_data,
            self.relation.data[self.local_unit],
            self.relation.data[self.remote_app],
        )
Пример #3
0
    def test_master_legacy(self, is_ready):
        # Ensure we fall back to using unit relation data if the app relation data is unset.
        is_ready.return_value = True
        standbys = ["host=standby1", "host=standby2"]
        rd = {"master": "host=master", "standbys": "\n".join(standbys)}
        self.harness.update_relation_data(self.relation_id,
                                          self.remote_unit_names[1], rd)

        self.assertEqual(
            client._master(self.log, self.relation, self.local_unit),
            rd["master"])
        self.assertTrue(is_ready.called)
        is_ready.assert_called_once_with(
            self.log,
            self.leadership_data,
            self.relation.data[self.local_unit],
            self.relation.data[self.remote_units[1]],
        )
Пример #4
0
    def test_master_ready(self, is_ready):
        # Master helper returns connection string when relation app data is set and ready.
        is_ready.return_value = True
        standbys = ["host=standby1", "host=standby2"]
        rd = {"master": "host=master", "standbys": "\n".join(standbys)}
        self.harness.update_relation_data(self.relation_id,
                                          self.remote_app_name, rd)

        self.assertEqual(
            client._master(self.log, self.relation, self.local_unit),
            rd["master"])
        self.assertTrue(is_ready.called)
        is_ready.assert_called_once_with(
            self.log,
            self.leadership_data,
            self.relation.data[self.local_unit],
            self.relation.data[self.remote_app],
        )