Merge lp:~gnuoy/charms/precise/daisy-retracer/add-upgrade-charm into lp:~daisy-pluckers/charms/precise/daisy-retracer/trunk

Proposed by Liam Young
Status: Merged
Merged at revision: 29
Proposed branch: lp:~gnuoy/charms/precise/daisy-retracer/add-upgrade-charm
Merge into: lp:~daisy-pluckers/charms/precise/daisy-retracer/trunk
Diff against target: 138 lines (+62/-13)
5 files modified
config.yaml (+10/-0)
hooks/common (+35/-0)
hooks/config-changed (+1/-0)
hooks/install (+2/-8)
hooks/upgrade-charm (+14/-5)
To merge this branch: bzr merge lp:~gnuoy/charms/precise/daisy-retracer/add-upgrade-charm
Reviewer Review Type Date Requested Status
Evan (community) Approve
Review via email: mp+162329@code.launchpad.net
To post a comment you must log in.
30. By Liam Young

Variables used by templates need to be exported

Revision history for this message
Evan (ev) wrote :

This looks good. I'm just going to change upgrade-charm to cd in a subshell, in case we add code later that has expectations about $(pwd).

review: Approve
Revision history for this message
Evan (ev) wrote :

Landed as r29, fixed up as r30.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'config.yaml'
2--- config.yaml 2013-05-03 00:27:01 +0000
3+++ config.yaml 2013-05-03 14:12:24 +0000
4@@ -86,6 +86,16 @@
5 type: string
6 default: 'i386 amd64 armhf'
7 description: Space separated list of architectures for which to process reports.
8+ daisy_code_dirs:
9+ type: int
10+ default: 3
11+ description: |
12+ How many old copies of daisy code to retain (candidates for backouts)
13+ apport_code_dirs:
14+ type: int
15+ default: 3
16+ description: |
17+ How many old copies of apport code to retain (candidates for backouts)
18 repository:
19 type: string
20 default: 'ppa:daisy-pluckers/daisy-seeds'
21
22=== modified file 'hooks/common'
23--- hooks/common 2013-05-03 00:27:01 +0000
24+++ hooks/common 2013-05-03 14:12:24 +0000
25@@ -16,6 +16,8 @@
26 APPORT_LOCATION="$DEPLOY_ROOT/apport"
27 CACHE_DIR="$DEPLOY_ROOT/cache"
28 VAR_DIR="$DEPLOY_ROOT/var"
29+DAISY_CODE_DIRS="$(config-get daisy_code_dirs)"
30+APPORT_CODE_DIRS="$(config-get apport_code_dirs)"
31
32 save_setting () {
33 key="$1"
34@@ -62,3 +64,36 @@
35
36 done
37 }
38+
39+deploy_code () {
40+ local tarball="$1"
41+ local codedir="$2"
42+ local codedir_count="$3"
43+ local codename=$(basename "$codedir")
44+ local coderoot=$(dirname "$codedir")
45+ local tmpdir=$(mktemp -d --tmpdir="${coderoot}")
46+ tar -C ${tmpdir} -xf ${tarball}
47+ local coderevno=$(bzr revno ${tmpdir})
48+ if [[ -d "${coderoot}/${codename}-${coderevno}" ]]; then
49+ juju-log "${coderevno} of ${codename} already deployed"
50+ rm -rf ${tmpdir}
51+ else
52+ juju-log "Deploying ${coderevno} of ${codename}"
53+ chown -R $USER_CODE_OWNER:$USER_CODE_RUNNER "${tmpdir}"
54+ mv "${tmpdir}" "${coderoot}/${codename}-${coderevno}"
55+ [ -d "${coderoot}/${codename}" ] && rm -rf "${coderoot}/${codename}"
56+ ln -s "${coderoot}/${codename}-${coderevno}" "${coderoot}/${codename}"
57+ remove_old_codedirs $codedir_count "${coderoot}/${codename}-*"
58+ fi
59+}
60+
61+remove_old_codedirs () {
62+ local codedir_count="$1"
63+ local codedir_regex="$2"
64+ local current_code_dirs=$(ls -d ${codedir_regex} | wc -l)
65+ if [[ $current_code_dirs -gt $codedir_count ]]; then
66+ juju-log "More than $codedir_count found, deleting:"
67+ juju-log "$(ls -td ${codedir_regex} | tail -n +$(($codedir_count+1)))"
68+ ls -1rd ${codedir_regex} | tail -n +$(($codedir_count+1)) | xargs rm -rf
69+ fi
70+}
71
72=== modified file 'hooks/config-changed'
73--- hooks/config-changed 2013-05-03 00:39:11 +0000
74+++ hooks/config-changed 2013-05-03 14:12:24 +0000
75@@ -35,6 +35,7 @@
76 #sed -i "s|cassandra_hosts =.*|cassandra_hosts = []|" $LOCAL_CONFIG_PATH
77
78 for x in templates/*.cron.tmpl; do
79+ export CODE_LOCATION DEPLOY_ROOT DUPLICATE_DB LOCAL_CONFIG_LOCATION USER_CODE_RUNNER VAR_DIR
80 n="$(echo "$(basename $x)" | sed 's/.cron.tmpl//')"
81 cheetah fill --env -p $x >/etc/cron.d/$n
82 done
83
84=== modified file 'hooks/install'
85--- hooks/install 2013-05-03 00:27:01 +0000
86+++ hooks/install 2013-05-03 14:12:24 +0000
87@@ -33,11 +33,7 @@
88
89 # Unpack tarred Daisy code
90 charm_dir="$(pwd)"
91-tarball="$charm_dir/files/daisy.tgz"
92-
93-if [ -f "$tarball" ]; then
94- tar -C "$CODE_LOCATION" -xvf "$tarball"
95-fi
96+deploy_code "$charm_dir/files/daisy.tgz" $CODE_LOCATION $DAISY_CODE_DIRS
97
98 if [ ! -e "$LOCAL_CONFIG_PATH" ]; then
99 cp "$CODE_LOCATION/daisy/configuration.py" "$LOCAL_CONFIG_PATH"
100@@ -45,10 +41,8 @@
101
102 # Unpack tarred Apport snapshot
103 apport="$charm_dir/files/apport.tgz"
104-
105 if [ -f "$apport" ]; then
106- tar -C "$APPORT_LOCATION" -xvf "$apport"
107-
108+ deploy_code "$apport" $APPORT_LOCATION $APPORT_CODE_DIRS
109 # set up the apt/dpkg Apport packaging backend; setup.py build would need more
110 # dependencies
111 cd "$APPORT_LOCATION"
112
113=== modified file 'hooks/upgrade-charm'
114--- hooks/upgrade-charm 2013-03-22 02:15:05 +0000
115+++ hooks/upgrade-charm 2013-05-03 14:12:24 +0000
116@@ -1,8 +1,17 @@
117 #!/bin/bash
118-set -e
119-
120+set -eux
121 home=$(dirname $0)
122-juju-log "Upgrading charm by running install hook again."
123-$home/install
124-juju-log "Finishing charm upgrade by reconfiguring."
125+
126+. hooks/common
127+charm_dir="$(pwd)"
128+deploy_code "$charm_dir/files/daisy.tgz" $CODE_LOCATION $DAISY_CODE_DIRS
129+
130+apport="$charm_dir/files/apport.tgz"
131+if [ -f "$apport" ]; then
132+ deploy_code "$apport" $APPORT_LOCATION $APPORT_CODE_DIRS
133+ cd "$APPORT_LOCATION"
134+ rm -f apport/packaging_impl.py
135+ ln -s ../backends/packaging-apt-dpkg.py apport/packaging_impl.py
136+fi
137 $home/config-changed
138+retracer_restart

Subscribers

People subscribed via source and target branches

to all changes: