Merge lp:~hloeung/turku/include-metadata into lp:turku

Proposed by Haw Loeung
Status: Merged
Approved by: Haw Loeung
Approved revision: 42
Merged at revision: 42
Proposed branch: lp:~hloeung/turku/include-metadata
Merge into: lp:turku
Diff against target: 69 lines (+12/-2)
2 files modified
turku_storage/ping.py (+10/-1)
turku_storage/update_config.py (+2/-1)
To merge this branch: bzr merge lp:~hloeung/turku/include-metadata
Reviewer Review Type Date Requested Status
Barry Price Approve
Review via email: mp+465911@code.launchpad.net

Commit message

Include environment name and write out metadata file - LP:2004450

Description of the change

Upstream - https://github.com/rfinnie/turku-storage/pull/2

There can be more environments where they can have same or similar unit names. This includes the environment name to make it easier to tell which unit from which environment.

Also, for each machine directory on disk, we write out metadata info so it's easier to tell what backups the files on disk are for. See https://bugs.launchpad.net/turku/+bug/2004450

Example:

```
ubuntu@juju-86e177-prod-turku-4:~$ cat /media/turku_storage_0-turku_storage/e07b063d-5b36-4acf-9e52-11509491260f/.turku-storage-metadata.txt
unit_name: cassandra-ps5-r2/0
service_name: cassandra
environment_name: stg-ols-cassandra
ubuntu@juju-86e177-prod-turku-4:~$
```

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
Barry Price (barryprice) wrote :

LGTM +1

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

Change successfully merged at revision 42

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'turku_storage/ping.py'
--- turku_storage/ping.py 2022-02-01 02:35:22 +0000
+++ turku_storage/ping.py 2024-05-10 08:56:58 +0000
@@ -193,17 +193,20 @@
193 os.makedirs(machine_dir)193 os.makedirs(machine_dir)
194194
195 machine_symlink = machine["unit_name"]195 machine_symlink = machine["unit_name"]
196 meta = ["unit_name: %s" % (machine['unit_name'])]
196 if "service_name" in machine and machine["service_name"]:197 if "service_name" in machine and machine["service_name"]:
197 machine_symlink = machine["service_name"] + "-" + machine_symlink198 machine_symlink = machine["service_name"] + "-" + machine_symlink
199 meta.append("service_name: %s" % (machine['service_name']))
198 if "environment_name" in machine and machine["environment_name"]:200 if "environment_name" in machine and machine["environment_name"]:
199 machine_symlink = machine["environment_name"] + "-" + machine_symlink201 machine_symlink = machine["environment_name"] + "-" + machine_symlink
202 meta.append("environment_name: %s" % (machine['environment_name']))
200 machine_symlink = machine_symlink.replace("/", "_")203 machine_symlink = machine_symlink.replace("/", "_")
201 if os.path.islink(os.path.join(var_machines, machine_symlink)):204 if os.path.islink(os.path.join(var_machines, machine_symlink)):
202 os.unlink(os.path.join(var_machines, machine_symlink))205 os.unlink(os.path.join(var_machines, machine_symlink))
203 if not os.path.exists(os.path.join(var_machines, machine_symlink)):206 if not os.path.exists(os.path.join(var_machines, machine_symlink)):
204 os.symlink(machine["uuid"], os.path.join(var_machines, machine_symlink))207 os.symlink(machine["uuid"], os.path.join(var_machines, machine_symlink))
205208
206 self.logger.info("Begin: %s %s" % (machine["unit_name"], source_name))209 self.logger.info("Begin: %s %s (%s)" % (machine["unit_name"], source_name, machine.get("environment_name")))
207210
208 rsync_args = [211 rsync_args = [
209 "rsync",212 "rsync",
@@ -278,6 +281,7 @@
278 snapshot_name = None281 snapshot_name = None
279 summary_output = None282 summary_output = None
280 if success:283 if success:
284 meta.append("status: Success!")
281 if snapshot_mode == "link-dest":285 if snapshot_mode == "link-dest":
282 summary_output = ""286 summary_output = ""
283 if base_snapshot:287 if base_snapshot:
@@ -310,6 +314,7 @@
310 summary_output + "Removed old snapshot: %s\n" % snapshot314 summary_output + "Removed old snapshot: %s\n" % snapshot
311 )315 )
312 else:316 else:
317 meta.append("status: Failed!")
313 summary_output = "rsync exited with return code %d" % returncode318 summary_output = "rsync exited with return code %d" % returncode
314319
315 time_end = time.time()320 time_end = time.time()
@@ -340,6 +345,10 @@
340 self.logger.info("Done")345 self.logger.info("Done")
341 lock.close()346 lock.close()
342347
348 meta_path = os.path.join(machine_dir, ".turku-storage-metadata.txt")
349 with open(meta_path, "w") as f:
350 f.write("\n".join(meta) + "\n")
351
343 def main(self):352 def main(self):
344 try:353 try:
345 return self.process_ping()354 return self.process_ping()
346355
=== modified file 'turku_storage/update_config.py'
--- turku_storage/update_config.py 2020-06-21 21:29:35 +0000
+++ turku_storage/update_config.py 2024-05-10 08:56:58 +0000
@@ -101,11 +101,12 @@
101 authorized_keys_out += f.read()101 authorized_keys_out += f.read()
102 for machine_uuid in api_reply["machines"]:102 for machine_uuid in api_reply["machines"]:
103 machine = api_reply["machines"][machine_uuid]103 machine = api_reply["machines"][machine_uuid]
104 authorized_keys_out += '%s,command="%s %s" %s (%s)\n' % (104 authorized_keys_out += '%s,command="%s %s" %s (%s %s)\n' % (
105 "no-pty,no-agent-forwarding,no-X11-forwarding,no-user-rc",105 "no-pty,no-agent-forwarding,no-X11-forwarding,no-user-rc",
106 config["authorized_keys_command"],106 config["authorized_keys_command"],
107 machine_uuid,107 machine_uuid,
108 machine["ssh_public_key"],108 machine["ssh_public_key"],
109 machine.get("environment_name", ""),
109 machine["unit_name"],110 machine["unit_name"],
110 )111 )
111112

Subscribers

People subscribed via source and target branches

to all changes: