Merge ~pjdc/ubuntu-mirror-charm/+git/ubuntu-mirror-charm:symlink-following into ubuntu-mirror-charm:master

Proposed by Paul Collins
Status: Merged
Approved by: Haw Loeung
Approved revision: 0053527401169898f725d20c32374caf12b25c14
Merged at revision: 3ee1f300437dcb10eb7620358e717e207bfaae47
Proposed branch: ~pjdc/ubuntu-mirror-charm/+git/ubuntu-mirror-charm:symlink-following
Merge into: ubuntu-mirror-charm:master
Diff against target: 68 lines (+26/-3)
1 file modified
hooks/hooks.py (+26/-3)
Reviewer Review Type Date Requested Status
Haw Loeung +1 Approve
Canonical IS Reviewers Pending
Review via email: mp+390874@code.launchpad.net

Commit message

stop creating extra symlinks in mirror directories

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
Haw Loeung (hloeung) wrote :

LGTM

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

Change successfully merged at revision 3ee1f300437dcb10eb7620358e717e207bfaae47

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
diff --git a/hooks/hooks.py b/hooks/hooks.py
index 2757b35..4c272f4 100755
--- a/hooks/hooks.py
+++ b/hooks/hooks.py
@@ -5,6 +5,7 @@
55
6import base646import base64
7import datetime7import datetime
8import errno
8import json9import json
9import os10import os
10import os.path11import os.path
@@ -24,7 +25,6 @@ from charmhelpers.core.host import (
24 mkdir,25 mkdir,
25 service_reload,26 service_reload,
26 service_restart,27 service_restart,
27 symlink,
28 user_exists,28 user_exists,
29 write_file,29 write_file,
30)30)
@@ -103,6 +103,29 @@ GET_DEFAULT_ADDRESS_DESTINATIONS = {
103}103}
104104
105105
106def ensure_symlink(target, link_path):
107 """Ensure that link_path is a symlink to target. Do not follow link_path.
108 Raise an exception if link_path exists but is not a symlink."""
109 need_unlink = False
110 try:
111 current = os.readlink(link_path)
112 if current == target:
113 log("Skipping {} - symlink exists and already points to {}".format(link_path, current))
114 return
115 need_unlink = True
116 except OSError as ose:
117 if ose.errno != errno.ENOENT:
118 raise
119 except Exception:
120 raise
121
122 # There's no non-racy way to replace a symlink. Even `ls -sfn target link_path` does this.
123 if need_unlink:
124 os.unlink(link_path)
125 os.symlink(target, link_path)
126 log("Symlink {} at {}, pointing to {}".format("replaced" if need_unlink else "created", link_path, target))
127
128
106def get_default_address(af):129def get_default_address(af):
107 """Determine our default address for the given address family."""130 """Determine our default address for the given address family."""
108 try:131 try:
@@ -486,7 +509,7 @@ def configure_apache(conf, hostname): # noqa: C901
486 tmpl_data["ports"] = [80, 443] if role_config.get('https') else [80]509 tmpl_data["ports"] = [80, 443] if role_config.get('https') else [80]
487 all_ports.update(tmpl_data["ports"])510 all_ports.update(tmpl_data["ports"])
488 file_from_template(mirror['tmpl_file'], sites_available, tmpl_data)511 file_from_template(mirror['tmpl_file'], sites_available, tmpl_data)
489 symlink(sites_available, sites_enabled)512 ensure_symlink(sites_available, sites_enabled)
490513
491 # And make sure the docroot exists514 # And make sure the docroot exists
492 if role == "ubuntu":515 if role == "ubuntu":
@@ -502,7 +525,7 @@ def configure_apache(conf, hostname): # noqa: C901
502 mkdir(mirror["path"])525 mkdir(mirror["path"])
503 os.chmod(mirror["path"], 0o755)526 os.chmod(mirror["path"], 0o755)
504 os.chown(mirror["path"], mirror_userinfo.pw_uid, mirror_userinfo.pw_gid)527 os.chown(mirror["path"], mirror_userinfo.pw_uid, mirror_userinfo.pw_gid)
505 symlink(mirror["path"], linkdest)528 ensure_symlink(mirror["path"], linkdest)
506529
507 # Update ports file530 # Update ports file
508 all_addresses.discard('*') # archive.ubuntu.com must not open port 443.531 all_addresses.discard('*') # archive.ubuntu.com must not open port 443.

Subscribers

People subscribed via source and target branches