95
109
"wal_buffers": "-1",
96
110
"checkpoint_segments": 3,
97
111
"random_page_cost": 4.0,
98
"volume_ephemeral_storage": True,
100
113
"volume_dev_regexp": "/dev/db[b-z]",
101
114
"backup_dir": "/var/lib/postgresql/backups",
102
115
"backup_schedule": "13 4 * * *",
103
116
"backup_retention_count": 7,
104
117
"nagios_context": "juju",
119
"install_sources": "",
105
121
"extra_archives": "",
106
122
"advisory_lock_restart_key": 765}
108
124
def relation_set(self, *args, **kwargs):
110
Capture result of relation_set into _relation_data, which
126
Capture result of relation_set into _outgoing_relation_data, which
111
127
can then be checked later.
113
129
if "relation_id" in kwargs:
114
130
del kwargs["relation_id"]
115
self._relation_data = dict(self._relation_data, **kwargs)
117
133
(key, value) = arg.split("=")
118
self._relation_data[key] = value
134
self._outgoing_relation_data = (
135
self._outgoing_relation_data + ((key, value),))
120
137
def relation_ids(self, relation_name="db-admin"):
156
173
def juju_log(self, *args, **kwargs):
159
def log(self, *args, **kwargs):
176
def log(self, message, level=None):
179
log = getattr(self, "_log_%s" % level)
180
setattr(self, "_log_%s" % level, log + (message,))
162
182
def config(self, scope=None):
163
183
if scope is None:
210
234
class TestHooksService(TestHooks):
236
def test_data_relation_departed_stops_postgresql(self):
238
When the storage subordinate charm relation departs firing the
239
C{data-relation-departed} hook, the charm stops the postgresql service
242
postgresql_stop = self.mocker.replace(hooks.postgresql_stop)
245
hooks.stop_postgres_on_data_relation_departed()
246
message = "Data relation departing. Stopping PostgreSQL"
248
message, hooks.hookenv._log_DEBUG, "Not logged- %s" % message)
250
def test_data_relation_joined_requests_configured_mountpoint(self):
252
When postgresql is related to the storage subordinate charm via the
253
'data' relation it will read the configured C{storage_mount_point} and
254
set C{mountpoint} in the relation in order to request a specific
255
mountpoint from the storage charm.
257
mount = hooks.external_volume_mount
258
hooks.data_relation_joined()
259
message = "Setting mount point in the relation: %s" % mount
261
message, hooks.hookenv._log_DEBUG, "Not logged- %s" % message)
263
def test_data_relation_changed_waits_for_data_relation_mountpoint(self):
265
C{data_relation_changed} will wait for the storage charm to respond
266
with the properly configured C{mountpoint} in the 'data' relation
267
before calling C{config_changed}.
269
mount = hooks.external_volume_mount
270
hooks.hookenv._config["storage_mount_point"] = mount
271
self.assertEqual(hooks.hookenv._incoming_relation_data, ())
272
hooks.data_relation_changed()
273
message = "Waiting for mountpoint from the relation: %s" % mount
275
message, hooks.hookenv._log_DEBUG, "Not logged- %s" % message)
277
def test_data_relation_changed_mountpoint_present(self):
279
C{data_relation_changed} will call C{config_changed} when it receives
280
the successfuly mounted C{mountpoint} from storage charm.
282
mount = hooks.external_volume_mount
284
setattr, hooks.hookenv, "_incoming_relation_data", ())
285
hooks.hookenv._incoming_relation_data = (("mountpoint", mount),)
286
config_changed = self.mocker.replace(hooks.config_changed)
287
config_changed(mount_point=mount)
290
hooks.data_relation_changed()
291
message = "Storage ready and mounted"
293
message, hooks.hookenv._log_DEBUG, "Not logged- %s" % message)
212
295
def test_create_postgresql_config_wal_no_replication(self):
214
297
When postgresql is in C{standalone} mode, and participates in no