Merge ~deej/ubuntu-mirror-charm/+git/add-user-fix:master into ubuntu-mirror-charm:master

Proposed by David Lawson
Status: Merged
Approved by: David Lawson
Approved revision: a6a4f763981a80fae887e4f7605fb600a0dee5e4
Merged at revision: 67efd529c3684cddcfbfcbeb92f5b1874aa27fb4
Proposed branch: ~deej/ubuntu-mirror-charm/+git/add-user-fix:master
Merge into: ubuntu-mirror-charm:master
Diff against target: 65 lines (+31/-5)
1 file modified
hooks/hooks.py (+31/-5)
Reviewer Review Type Date Requested Status
Tom Haddon Approve
Canonical IS Reviewers Pending
Canonical IS Reviewers Pending
Review via email: mp+380445@code.launchpad.net

Commit message

Break out user and root directory creation into their own functions called both from the install hook and config-changed ala the other configuration functions.

Description of the change

Break out user and root directory creation into their own functions called both from the install hook and config-changed ala the other configuration functions.

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
Tom Haddon (mthaddon) wrote :

One comment inline

Revision history for this message
Tom Haddon (mthaddon) wrote :

LGTM, nit about trailing comma on write_file

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

Change successfully merged at revision 67efd529c3684cddcfbfcbeb92f5b1874aa27fb4

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/hooks/hooks.py b/hooks/hooks.py
2index 6790005..eab6c23 100755
3--- a/hooks/hooks.py
4+++ b/hooks/hooks.py
5@@ -16,7 +16,19 @@ import sys
6 import yaml
7 import platform
8
9-from charmhelpers.core.host import service_start, service_stop, service_reload, service_restart, adduser, symlink, mkdir, write_file, lsb_release
10+from charmhelpers.core.host import (
11+ adduser,
12+ chownr,
13+ lsb_release,
14+ mkdir,
15+ service_start,
16+ service_stop,
17+ service_reload,
18+ service_restart,
19+ symlink,
20+ user_exists,
21+ write_file,
22+)
23 from charmhelpers.core.hookenv import Hooks, log, charm_dir, relation_set, local_unit, is_relation_made, relation_id, relation_ids
24 from charmhelpers.core import sysctl
25 from charmhelpers.fetch import apt_install
26@@ -725,14 +737,26 @@ def configure_sysctl():
27 sysctl.create(yaml.dump(sysctl_settings), '/etc/sysctl.d/90-ubuntu-mirror.conf')
28
29
30+def configure_user():
31+ if not user_exists(conf.mirror_user()):
32+ mirror_userinfo = adduser(conf.mirror_user(), system_user=True)
33+ if not os.path.isdir(mirror_userinfo.pw_dir):
34+ mkdir(mirror_userinfo.pw_dir, owner=conf.mirror_user())
35+ copy_files()
36+
37+
38+def configure_directories():
39+ if not os.path.isdir("/srv/ftp.root"):
40+ mkdir("/srv/ftp.root")
41+ chownr("/srv/ftp.root", conf.mirror_user(), conf.mirror_user())
42+
43+
44 @hooks.hook("install.real")
45 def install():
46 log("CHARM: Installing {}".format(conf.app_name()))
47 apt_install(required_pkgs, options=['--force-yes'])
48- mirror_userinfo = adduser(conf.mirror_user(), system_user=True)
49- mkdir(mirror_userinfo.pw_dir, owner=conf.mirror_user())
50- copy_files()
51- mkdir("/srv/ftp.root")
52+ configure_user()
53+ configure_directories()
54 for module in apache_modules:
55 check_call(["/usr/sbin/a2enmod", module])
56
57@@ -740,6 +764,8 @@ def install():
58 @hooks.hook("config-changed")
59 def config_changed():
60 log("CHARM: Configuring {}".format(conf.app_name()))
61+ configure_user()
62+ configure_directories()
63 configure_rsync_client()
64 configure_rsync_server()
65 configure_apache()

Subscribers

People subscribed via source and target branches