Merge lp:~mwhudson/lava-deployment-tool/add-upgrade-staging-script into lp:~linaro-validation/lava-deployment-tool/trunk

Proposed by Michael Hudson-Doyle
Status: Merged
Merged at revision: 168
Proposed branch: lp:~mwhudson/lava-deployment-tool/add-upgrade-staging-script
Merge into: lp:~linaro-validation/lava-deployment-tool/trunk
Diff against target: 163 lines (+111/-11)
3 files modified
_compare_manifests.py (+45/-0)
lava-deployment-tool (+5/-11)
upgrade-staging (+61/-0)
To merge this branch: bzr merge lp:~mwhudson/lava-deployment-tool/add-upgrade-staging-script
Reviewer Review Type Date Requested Status
Linaro Validation Team Pending
Review via email: mp+104324@code.launchpad.net

Description of the change

Hi,

This adds a script that I intend to use to automatically update staging on control.

It does two other things: stop l-d-t bundle from asking questions and improves the output of l-d-t preview.

If the code doesn't make sense, this box isn't the place to fix that problem :-)

Cheers,
mwh

To post a comment you must log in.
Revision history for this message
Michael Hudson-Doyle (mwhudson) wrote :

Hm, it seems that using a bundle made with -e bzr:... lines does not interact entirely as expected with l-d-t upgrade. More investigation required.

176. By Michael Hudson-Doyle

a different approach, check out all the branches, build tarballs from them include those tarballs in the requirements file

177. By Michael Hudson-Doyle

actually install the bundle

178. By Michael Hudson-Doyle

have install_config_app start the instance

Revision history for this message
Michael Hudson-Doyle (mwhudson) wrote :

Ok, here is a new approach that seems more promising: don't let pip see anything to do with bzr, instead check out each bzr branch, run sdist and include the tarball in the requirements file that we feed to l-d-t bundle (this has the advantage that we don't need to include the hacked version of pip in the venv we build the bundle in).

179. By Michael Hudson-Doyle

remove code instead of just commenting it out

Revision history for this message
Michael Hudson-Doyle (mwhudson) wrote :

I should say that we probably should keep mirrors of the launchpad branches around to make this faster. But that can be a follow up improvement.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added file '_compare_manifests.py'
2--- _compare_manifests.py 1970-01-01 00:00:00 +0000
3+++ _compare_manifests.py 2012-05-03 00:26:18 +0000
4@@ -0,0 +1,45 @@
5+#!/usr/bin/python
6+
7+import sys
8+
9+def load(fname):
10+ d = {}
11+ for line in open(fname):
12+ line = line.strip()
13+ if line.startswith('-e'):
14+ # This bit is a total hack.
15+ _, stuff = line.split('#egg=')
16+ package, version, _ = stuff.split('-', 2)
17+ package = package.replace('_', '-')
18+ else:
19+ package, version = line.split('==')
20+ d[package] = version
21+ return d
22+
23+cur = load(sys.argv[1])
24+new = load(sys.argv[2])
25+
26+not_present = set(cur) - set(new)
27+new_packaged = set(new) - set(cur)
28+changed = {}
29+for package in set(cur) & set(new):
30+ if cur[package] != new[package]:
31+ changed[package] = (cur[package], new[package])
32+
33+if not_present:
34+ print "Already installed, but not in bundle:"
35+ w1 = max(len(p) for p in not_present)
36+ for k in sorted(not_present):
37+ print " %-*s %s" % (w1, k, cur[k])
38+if changed:
39+ print "To be upgraded:"
40+ w1 = max(len(p) for p in changed)
41+ w2 = max(len(t[0]) for t in changed.itervalues())
42+ w3 = max(len(t[1]) for t in changed.itervalues())
43+ for k in sorted(changed):
44+ print " %-*s %-*s -> %-*s" % (w1, k, w2, changed[k][0], w3, changed[k][1])
45+if new_packaged:
46+ print "To be installed:"
47+ w1 = max(len(p) for p in new_packaged)
48+ for k in sorted(new_packaged):
49+ print " %-*s %s" % (w1, k, new[k])
50
51=== modified file 'lava-deployment-tool'
52--- lava-deployment-tool 2012-04-25 08:02:22 +0000
53+++ lava-deployment-tool 2012-05-03 00:26:18 +0000
54@@ -1020,8 +1020,10 @@
55 # Get out of virtualenv
56 deactivate
57
58- echo "Your instance is now ready, please start (or re-start) it with"
59- echo "sudo start lava-instance LAVA_INSTANCE=$LAVA_INSTANCE"
60+ echo "Starting instance again..."
61+ set -x
62+ sudo start lava-instance LAVA_INSTANCE=$LAVA_INSTANCE
63+ set +x
64 }
65
66
67@@ -1745,7 +1747,6 @@
68 cmd_bundle() {
69 LAVA_REQUIREMENT=${1:-requirements/requirements.txt}
70 LAVA_BUNDLE=${2:-lava.pybundle}
71- unset PIP_DOWNLOAD_CACHE
72 local step
73 for step in $LAVA_INSTALL_STEPS; do
74 defaults_$step
75@@ -1754,13 +1755,6 @@
76 for step in $LAVA_INSTALL_STEPS; do
77 pkglist_$step >> "$LAVA_FULL_REQUIREMENT"
78 done
79- echo "The resulting file can be copied for off-line installation"
80- echo "Do you wnt to create $LAVA_BUNDLE with the following packages:"
81- echo
82- cat "$LAVA_FULL_REQUIREMENT"
83- echo
84- read -p "Type BUNDLE to continue: " RESPONSE
85- test "$RESPONSE" = 'BUNDLE' || return
86 set -x
87 pip bundle "$LAVA_BUNDLE" $PIP_PROXY_OPTION --timeout=30 --use-mirrors --requirement="$LAVA_FULL_REQUIREMENT" || die "Failed to create bundle"
88 set +x
89@@ -1783,7 +1777,7 @@
90 unzip -qc "${_bundle}" pip-manifest.txt | grep -v '^#' | tr '[A-Z]' '[a-z]' | sort > bundle-versions.txt
91 $LAVA_PREFIX/$LAVA_INSTANCE/bin/pip freeze | tr '[A-Z]' '[a-z]' | sort > installed-versions.txt
92
93- diff -y installed-versions.txt bundle-versions.txt
94+ $(dirname $(readlink -f "$0"))/_compare_manifests.py installed-versions.txt bundle-versions.txt
95 }
96
97 is_vhost(){
98
99=== added file 'upgrade-staging'
100--- upgrade-staging 1970-01-01 00:00:00 +0000
101+++ upgrade-staging 2012-05-03 00:26:18 +0000
102@@ -0,0 +1,61 @@
103+#!/bin/bash
104+
105+# 1. Make virtualenv
106+# 2. Patch pip in virtualenv
107+# 3. Install bzrlib in virtualenv.
108+# 4. Activate virtualenv
109+# 5. Make bundle in virtualenv using requirements/requirements-trunk.txt
110+# 6. Deactivate virtualenv
111+# 7. Optionally run l-d-t preview and ask for confirmation
112+# 8. Run l-d-t upgrade with bundle made in step 5.
113+
114+set -uxe
115+
116+allow-badness () {
117+ set +uxe;
118+ "$@";
119+ set -uxe;
120+}
121+
122+TARGET_INSTANCE="${1:-staging}"
123+
124+LAVA_ROOT=/srv/lava
125+
126+LDT_DIR="$(dirname $(readlink -f $0))"
127+SOURCE_REQUIREMENTS="${LDT_DIR}/requirements/requirements-latest.txt"
128+LDT="${LDT_DIR}/lava-deployment-tool"
129+
130+SCRATCH_DIR="$(mktemp -d)"
131+
132+trap "rm -rf \"${SCRATCH_DIR}\"" EXIT
133+
134+VENV="${SCRATCH_DIR}/env"
135+BUNDLE="${SCRATCH_DIR}/lava.pybundle"
136+REQS="${SCRATCH_DIR}/requirements.txt"
137+
138+virtualenv "${VENV}"
139+
140+allow-badness . "${VENV}/bin/activate"
141+
142+export PIP_DOWNLOAD_CACHE=$LAVA_ROOT/.downloads
143+
144+pip install -q bzr
145+
146+mkdir "${SCRATCH_DIR}/src"
147+
148+while read line
149+do
150+ bzr branch --stacked "lp:$line" "${SCRATCH_DIR}/src/$line"
151+ pushd "${SCRATCH_DIR}/src/$line"
152+ python setup.py sdist
153+ echo $(readlink -f dist/*) >> "${REQS}"
154+ popd
155+done < "${SOURCE_REQUIREMENTS}"
156+
157+"${LDT}" bundle "${REQS}" "${BUNDLE}"
158+
159+allow-badness deactivate
160+
161+"${LDT}" preview "${TARGET_INSTANCE}" "${BUNDLE}"
162+
163+"${LDT}" upgrade "${TARGET_INSTANCE}" "${BUNDLE}"

Subscribers

People subscribed via source and target branches