Merge ~cjwatson/launchpad:charm-ppa-publisher-archives-dir into launchpad:master

Proposed by Colin Watson
Status: Merged
Approved by: Colin Watson
Approved revision: 7832cb5533b996c3b7d6307a614a8c51f5b5c970
Merge reported by: Otto Co-Pilot
Merged at revision: not available
Proposed branch: ~cjwatson/launchpad:charm-ppa-publisher-archives-dir
Merge into: launchpad:master
Diff against target: 46 lines (+11/-0)
2 files modified
charm/launchpad-ppa-publisher/reactive/launchpad-ppa-publisher.py (+10/-0)
charm/launchpad-ppa-publisher/templates/launchpad-ppa-publisher-lazr.conf.j2 (+1/-0)
Reviewer Review Type Date Requested Status
Ines Almeida Approve
Review via email: mp+450825@code.launchpad.net

Commit message

charm: Set archives_dir for PPA publisher

Description of the change

The PPA publisher mostly doesn't use this, but it's still used to construct `lp.archivepublisher.config.Config.temproot`, and we need to make sure that that's on the same filesystem as the published archive, otherwise `os.rename` will fail.

To post a comment you must log in.
Revision history for this message
Ines Almeida (ines-almeida) wrote :

By "mostly doesn't use this" does that mean that the directory itself won' be used? Would it make sense to provide an existing directory instead of creating a new empty one?

Revision history for this message
Colin Watson (cjwatson) wrote :

The place to look here is `lib/lp/archivepublisher/config.py`. It's unreasonably complex for historical reasons, but if you boil it down, it _mostly_ uses directories under `ppa_config.root` or `ppa_config.private_root` in the PPA case - all the key directories such as `distsroot` and `poolroot` end up under there. However, `temproot` ends up under a path derived from the `PublisherConfig` table.

Up to now, this mostly hasn't mattered. It's only temporary, as the name implies: files get dropped in there briefly until they're renamed into place in wherever they're actually supposed to live.

Until very recently, Ubuntu's `PublisherConfig.root_dir` in production was "/srv/launchpad.net/ubuntu-archive/", and hence `temproot` was "/srv/launchpad.net/ubuntu-archive/ubuntu-temp". This apparently existed on the PPA publisher and was on the same filesystem as `ppa_config.{root,private_root}`, so all was well.

However, because one of my early design decisions for our charms was to use "/srv/launchpad/" for everything rather than having things like "/srv/launchpad.net/", "/srv/staging.launchpad.net/", etc. depending on the application and environment, having "/srv/launchpad.net/" hardcoded in the database was problematic, especially for migration; we ran into this when deploying the qastaging ftpmaster. I changed Launchpad to automatically prepend `config.archivepublisher.archives_dir` to `PublisherConfig.root_dir`, set that to appropriate values in various places, and changed the database to drop the "/srv/launchpad.net/" prefix. But this caused the production outage that you can see in https://chat.canonical.com/canonical/pl/gfs13ina87rfzc9xrx1ncuf8zh, in particular:

  OSError: [Errno 18] Invalid cross-device link: '/var/tmp/archives/ubuntu-archive/ubuntu-temp/temp-download.3z8mk9bd' -> '/srv/launchpad.net/ppa-archive/ubuntu-elisp/ppa/ubuntu/pool/main/e/emacs-snapshot/emacs-snapshot_107161-dd818ed821f~ubuntu20.04.1.tar.gz'

I fixed the legacy PPA publisher deployment in https://code.launchpad.net/~cjwatson/lp-production-configs/ppa-archives-dir/+merge/450824, and I think we should do the same here. `temproot` needs to end up somewhere under `data_dir`, since we intend to mount that as a separate filesystem. The reason I went for creating a new subdirectory of `data_dir` was that I was a little concerned that if we're building the `temproot` path from a combination of `config.archivepublisher.archives_dir` and a database column then it might be possible to accidentally collide with something else; a subdirectory seemed like a simple way to avoid that problem without having to think about it too hard.

Revision history for this message
Ines Almeida (ines-almeida) wrote :

Thanks for the context and details!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/charm/launchpad-ppa-publisher/reactive/launchpad-ppa-publisher.py b/charm/launchpad-ppa-publisher/reactive/launchpad-ppa-publisher.py
2index e3c5b75..9118203 100644
3--- a/charm/launchpad-ppa-publisher/reactive/launchpad-ppa-publisher.py
4+++ b/charm/launchpad-ppa-publisher/reactive/launchpad-ppa-publisher.py
5@@ -32,6 +32,12 @@ def get_data_dir():
6 return os.path.join(base.base_dir(), "data")
7
8
9+def archives_dir():
10+ # Used by `lp.archivepublisher.config.getPubConfig` to construct
11+ # `Config.temproot`, even for PPAs.
12+ return os.path.join(get_data_dir(), "archives")
13+
14+
15 def ppa_archive_root():
16 return os.path.join(get_data_dir(), "ppa-archive")
17
18@@ -53,6 +59,7 @@ def configure():
19 ppa_keys_root = os.path.join(data_dir, "ppa-signing-keys")
20 oval_data_root = os.path.join(data_dir, "oval-data")
21
22+ config["archives_dir"] = archives_dir()
23 config["ppa_archive_root"] = ppa_archive_root()
24 config["ppa_archive_private_root"] = ppa_archive_private()
25 config["ppa_signing_keys_root"] = ppa_keys_root
26@@ -60,6 +67,9 @@ def configure():
27
28 host.mkdir(data_dir, owner=base.user(), group=base.user(), perms=0o775)
29 host.mkdir(
30+ archives_dir(), owner=base.user(), group=base.user(), perms=0o775
31+ )
32+ host.mkdir(
33 ppa_archive_root(), owner=base.user(), group=base.user(), perms=0o775
34 )
35 host.mkdir(
36diff --git a/charm/launchpad-ppa-publisher/templates/launchpad-ppa-publisher-lazr.conf.j2 b/charm/launchpad-ppa-publisher/templates/launchpad-ppa-publisher-lazr.conf.j2
37index 0a9e514..a0e08e8 100644
38--- a/charm/launchpad-ppa-publisher/templates/launchpad-ppa-publisher-lazr.conf.j2
39+++ b/charm/launchpad-ppa-publisher/templates/launchpad-ppa-publisher-lazr.conf.j2
40@@ -12,6 +12,7 @@
41 extends: ../launchpad-db-lazr.conf
42
43 [archivepublisher]
44+archives_dir: {{ archives_dir }}
45 {{- opt("oval_data_rsync_endpoint", oval_data_rsync_endpoint) }}
46 oval_data_root: {{ base_dir }}/oval-data
47

Subscribers

People subscribed via source and target branches

to status/vote changes: