Merge lp:~smoser/maas/trunk.import-ephem-fix into lp:~maas-committers/maas/trunk

Proposed by Scott Moser
Status: Merged
Approved by: Scott Moser
Approved revision: no longer in the source branch.
Merged at revision: 1081
Proposed branch: lp:~smoser/maas/trunk.import-ephem-fix
Merge into: lp:~maas-committers/maas/trunk
Diff against target: 123 lines (+25/-37)
1 file modified
scripts/maas-import-ephemerals (+25/-37)
To merge this branch: bzr merge lp:~smoser/maas/trunk.import-ephem-fix
Reviewer Review Type Date Requested Status
Andres Rodriguez (community) Approve
Launchpad code reviewers Pending
Review via email: mp+126543@code.launchpad.net

Commit message

maas-import-ephemerals: cleanups and one bug fix

Bug:
  if you were importing 2 things, the query_local would not re-set the
  'l_dir' (local dir), which caused a sour path to be taken.

cleanups:
 * remove 'arch2u' as we only deal with ubuntu arch now. x86_64 is not
   valid input that should exist anywhere.
 * be less annoying in default output. Now, nothing to do looks like:
     precise/amd64: up to date [maas-precise-daily-amd64-ephemeral-20120924]
     precise/i386: up to date [maas-precise-daily-i386-ephemeral-20120924]
     quantal/amd64: up to date [maas-quantal-daily-amd64-ephemeral-20120926]
     quantal/i386: up to date [maas-quantal-daily-i386-ephemeral-20120926]
 * replace 2 separate install_tftp_image with a single one
 * do not let output of maas-provision to stdout/stderr unless it fails

Description of the change

maas-import-ephemerals: cleanups and one bug fix

Bug:
  if you were importing 2 things, the query_local would not re-set the
  'l_dir' (local dir), which caused a sour path to be taken.

cleanups:
 * remove 'arch2u' as we only deal with ubuntu arch now. x86_64 is not
   valid input that should exist anywhere.
 * be less annoying in default output. Now, nothing to do looks like:
     precise/amd64: up to date [maas-precise-daily-amd64-ephemeral-20120924]
     precise/i386: up to date [maas-precise-daily-i386-ephemeral-20120924]
     quantal/amd64: up to date [maas-quantal-daily-amd64-ephemeral-20120926]
     quantal/i386: up to date [maas-quantal-daily-i386-ephemeral-20120926]
 * replace 2 separate install_tftp_image with a single one
 * do not let output of maas-provision to stdout/stderr unless it fails

To post a comment you must log in.
Revision history for this message
Andres Rodriguez (andreserl) wrote :

Looks good to me.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'scripts/maas-import-ephemerals'
2--- scripts/maas-import-ephemerals 2012-09-12 12:54:09 +0000
3+++ scripts/maas-import-ephemerals 2012-09-26 20:35:24 +0000
4@@ -88,16 +88,6 @@
5 }
6
7
8-arch2u() {
9- # Normalize architecture name to an Ubuntu architecture name.
10- _RET=$1
11- case "$1" in
12- i?86) _RET=i386;;
13- x86_64) _RET=amd64;;
14- esac
15-}
16-
17-
18 query_remote() {
19 # query /query data at REMOTE_IMAGES_MIRROR
20 # returns 7 values prefixed with 'r_'
21@@ -146,7 +136,7 @@
22 [ -n "$f" ] && echo "$PWD/$f/info")
23
24 l_release=""; l_stream=""; l_label=""; l_serial="";
25- l_arch=""; l_url=""; l_name=""
26+ l_arch=""; l_url=""; l_name=""; l_dir="";
27 if [ -n "$found" ]; then
28 . "$found"
29 l_release="$release";
30@@ -296,13 +286,13 @@
31 { error "cp of $filename from $src failed"; return 1; }
32 done
33
34- local cmd
35+ local cmd out=""
36 cmd=( maas-provision install-pxe-image
37 "--arch=$arch" "--subarch=$subarch" "--release=$release"
38 --purpose="commissioning" --image="$tmpdir" )
39- debug 1 "${cmd[@]}"
40- "${cmd[@]}" ||
41- { error "cmd failed:" "${cmd[@]}"; return 1; }
42+ debug 2 "${cmd[@]}"
43+ out=$("${cmd[@]}" 2>&1) ||
44+ { error "cmd failed:" "${cmd[@]}"; error "$out"; return 1; }
45 }
46
47
48@@ -349,35 +339,31 @@
49 updates=0
50 for release in $RELEASES; do
51 for arch in $ARCHES; do
52- arch2u "$arch"; arch_u=$_RET
53
54- query_local "$arch_u" "$release" "$BUILD_NAME" ||
55+ query_local "$arch" "$release" "$BUILD_NAME" ||
56 fail "failed to query local for $release/$arch"
57- query_remote "$arch_u" "$release" "$BUILD_NAME" ||
58+ query_remote "$arch" "$release" "$BUILD_NAME" ||
59 fail "remote query of $REMOTE_IMAGES_MIRROR failed"
60
61- info="rel: $r_release, arch: $r_arch: name: $r_name"
62- if [ -z "$l_dir" ]; then
63- serial_gt "$r_serial" "$l_serial" || {
64- debug 1 "$release-${arch_u} in ${l_dir} is up to date";
65- continue;
66- }
67+ info="rel: $r_release, arch: $arch: name: $r_name"
68+ debug 2 "$info"
69+ debug 2 "local serial=$l_serial l_name=$l_name dir=$l_dir"
70+ debug 2 "remote serial=$r_serial r_name=$r_name url=$r_url"
71
72+ # if remote is newer, need to update. Note that if there is no local
73+ # data, 'l_serial' will be "", which serial_gt considers zero
74+ if serial_gt "$r_serial" "$l_serial"; then
75 # an update is needed remote serial is newer than local
76 updates=$(($updates+1))
77
78- debug 1 "updating $release-$arch ($l_name => $r_name)"
79+ msg="updating [${l_name:+${l_name} to }$r_name]"
80+ debug 0 "$release/$arch: $msg"
81 wd="${TEMP_D}/$release/$arch"
82 prep_dir "$wd" \
83 "$r_release" "$r_stream" "$r_label" \
84 "$r_serial" "$r_arch" "$r_url" "$r_name" ||
85 fail "failed to prepare image for $release/$arch"
86
87- install_tftp_image "$wd" "$r_arch" "generic" "$r_release" ||
88- fail "failed to install ftp image [$info]"
89-
90- target_name="${TARGET_NAME_PREFIX}${r_name}"
91-
92 final_d="${r_release}/${r_stream}/${r_arch}/${r_serial}"
93 fpfinal_d="${DATA_DIR}/${final_d}"
94 mkdir -p "${fpfinal_d}"
95@@ -386,19 +372,21 @@
96 fail "failed to move contents to final directory ${fpfinal_d}"
97 name="${r_name}"
98 else
99+ debug 0 "$release/$arch: up to date [$l_name]"
100+
101 fpfinal_d="${l_dir}"
102 final_d="${l_release}/${l_stream}/${l_arch}/${l_serial}"
103
104- # Even if there was no need to update the image, we make sure it
105- # gets installed.
106- install_tftp_image "$fpfinal_d" "$r_arch" "generic" "$r_release" ||
107- fail "failed to install ftp image [$info]"
108-
109 name="${l_name}"
110- target_name="${TARGET_NAME_PREFIX}${name}"
111- debug 1 "updating ${release}-${arch} $final_d"
112 fi
113
114+ # Even if there was no need to update the image, we make sure it
115+ # gets installed.
116+ debug 1 "adding images for $release/$arch/generic to maas"
117+ install_tftp_image "$fpfinal_d" "$arch" "generic" "$release" ||
118+ fail "failed to install ftp image [$info]"
119+
120+ target_name="${TARGET_NAME_PREFIX}${name}"
121 rel_tgt="../${final_d}/tgt.conf"
122
123 # iscsi_update