Merge lp:~gandelman-a/ubuntu/oneiric/cobbler/lp850880-850866 into lp:ubuntu/oneiric/cobbler

Proposed by Adam Gandelman
Status: Merged
Merge reported by: Stéphane Graber
Merged at revision: not available
Proposed branch: lp:~gandelman-a/ubuntu/oneiric/cobbler/lp850880-850866
Merge into: lp:ubuntu/oneiric/cobbler
Diff against target: 250 lines (+129/-43)
2 files modified
debian/changelog (+11/-0)
debian/cobbler-ubuntu-import (+118/-43)
To merge this branch: bzr merge lp:~gandelman-a/ubuntu/oneiric/cobbler/lp850880-850866
Reviewer Review Type Date Requested Status
Andres Rodriguez (community) Needs Fixing
Scott Moser Needs Fixing
Ubuntu branches Pending
Review via email: mp+78904@code.launchpad.net

Description of the change

This extends and adds some needed functionality:

* -u/--update can be used to download a newer ISO from the archive, import it into cobbler as a new distro. After its imported with a temp. name, sub-profiles of the outdated profile are reassigned to the updated version. The outdated distro is removed and the newer version renamed to match. This whole song and dance is necessary to preserve profiles and systems that are dependent on the root distro within the cobbler resource tree.

* both new imports and update checks are done first against a releases -update pocket and, failing that (404), falls back to the release pocket. This should allow new imports to import the most recent mini.isos, and later runs to check against whats been published since last run. A trivial change to orchestra-import-isos can make use of this and --update to keep cached ISOs up to date between cron'd runs.

* -v existed previously, but the corresponding VERBOSITY variable was never used. Added debug() which is useful for debugging info during some of the more involved stuff

To post a comment you must log in.
Revision history for this message
Scott Moser (smoser) wrote :

Some comments:
 * I don't like the use of globals in update_available and get_isos. I dont have a simple solution for you, and i wouldnt nack it completely based on that, but globals (or lexical scoped variables) are just confusing. If you have to use them, please use upper case names to indicate that they're global.
 * use more quotes:
   Things like '[ -n $md5sum_local ]' should really be '[ -n "$md5sum_local" ]', as the variable md5sum_local could have either shell wildcards or spaces in it which change behavior unexpectedly.
 * there are some white space indentation rather than tab (search for '[ ][ ][ ]' and you'll see).
   Also, you can set vi to read the modelines (the last line of the file) with 'set modeline modelines=3'

Also, I'd like a general "just do the right thing" flag.
So that I could do something like:
  cobbler-ubuntu-import --do-what-i-mean natty-i386 natty-amd64 oneiric-amd64 oneiric-i386

And it would import or update if necessary, and exit success unless an operation failed. It would even make sense to me that that should be the default behavior.

The last comment is that it would be nice if 'cobbler import' had a '--replace' flag. We might want to do that and submit it upstream that did your rename dance inside. It would be able to do more appropriate locking and such to avoid two things attempting the call at the same time.

Thanks for your work, I really hope not to sound negative.

review: Needs Fixing
53. By Adam Gandelman

Better quoting of shell variables

54. By Adam Gandelman

Also remove new, temp. profile after distro has been renamed

55. By Adam Gandelman

Capitalize global variables, lower case locals

56. By Adam Gandelman

Fix up some whitespace

Revision history for this message
Adam Gandelman (gandelman-a) wrote :

Hi Scott-

Just pushed some changes which address your 3 points. I agree global variables suck, but to do anything to properly get rid of them at this point would be a major rewrite of the script itself. Perhaps this is something we should address next cycle, maybe thinking about a better way to go about managing a local ISO cache.

I'd prefer to get these changes worked out and tested before changing the default behavior of the script, but I agree that it should probably do all this by default. And +1 to trying to get the same support in cobbler upstream. In the meantime, the --check and --update stuff should be enough.

Revision history for this message
Andres Rodriguez (andreserl) wrote :

From conversation with Scott, this branch needs fixing:

smoser> * debug() should go to stderr, not stdout

I'll look into fixing it to getting it uploaded.

review: Needs Fixing
57. By Adam Gandelman

debug(): Redirect to stderr instead of stdout

Revision history for this message
James Page (james-page) wrote :

Merged in precise - please can this branch be marked as merged unless we are going to use this branch for the SRU.

---------------

cobbler (2.1.0+git20110602-0ubuntu27) precise; urgency=low

  [ Adam Gandelman ]
  * debian/cobbler-ubuntu-import:
      - Check update pockets for releases on download and update check.
        (LP: #850880 )
      - Allow '-u' to upgrade existing profiles to a newer version of an ISO.
        (LP: #850886)
      - '-v' to allow debug msgs.

  [ Andres Rodriguez ]
  * debian/patches:
    - 42_fix_repomirror_create_sync.patch: Updated to correctly create the
      mirror. (LP: #872926)
  * debian/cobbler-web.postrm: Remove symlinks that were created on
    postinst. (LP: #872892)
 -- Andres Rodriguez <email address hidden> Mon, 24 Oct 2011 19:29:26 -0400

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'debian/changelog'
--- debian/changelog 2011-09-29 23:58:08 +0000
+++ debian/changelog 2011-10-12 20:47:41 +0000
@@ -1,3 +1,14 @@
1cobbler (2.1.0+git20110602-0ubuntu27) UNRELEASED; urgency=low
2
3 * debian/cobbler-ubuntu-import:
4 - Check update pockets for releases on download and update check.
5 (LP: #850880 )
6 - Allow '-u' to upgrade existing profiles to a newer version of an ISO.
7 (LP: #850886)
8 - '-v' to allow debug msgs.
9
10 -- Adam Gandelman <adamg@canonical.com> Mon, 10 Oct 2011 18:44:00 -0700
11
1cobbler (2.1.0+git20110602-0ubuntu26) oneiric; urgency=low12cobbler (2.1.0+git20110602-0ubuntu26) oneiric; urgency=low
213
3 * debian/cobbler-ubuntu-import: Add --check-update and --remove14 * debian/cobbler-ubuntu-import: Add --check-update and --remove
415
=== modified file 'debian/cobbler-ubuntu-import'
--- debian/cobbler-ubuntu-import 2011-09-16 05:10:52 +0000
+++ debian/cobbler-ubuntu-import 2011-10-12 20:47:41 +0000
@@ -10,6 +10,7 @@
10errorp() { printf "$@" 1>&2; }10errorp() { printf "$@" 1>&2; }
11fail() { [ $# -eq 0 ] || error "$@"; exit 1; }11fail() { [ $# -eq 0 ] || error "$@"; exit 1; }
12failp() { [ $# -eq 0 ] || errorp "$@"; exit 1; }12failp() { [ $# -eq 0 ] || errorp "$@"; exit 1; }
13debug() { [ $VERBOSITY -gt 0 ] && echo "[DEBUG] $@" 1>&2; }
1314
14Usage() {15Usage() {
15 cat <<EOF16 cat <<EOF
@@ -26,6 +27,8 @@
26 mirror. exits 0 if an update is needed or iso does27 mirror. exits 0 if an update is needed or iso does
27 not exist in $ISO_DIR28 not exist in $ISO_DIR
28 -r | --remove remove cobbler profile/distro and cached ISO29 -r | --remove remove cobbler profile/distro and cached ISO
30 -u | --update update iso, import, replace outdated distro and profile
31 -v | --verbose increase verbosity
29 Note, arch can be i386, x86_64, or amd64. However,32 Note, arch can be i386, x86_64, or amd64. However,
30 the registered distro and profile will use 'x86_64' rather than 'amd64'.33 the registered distro and profile will use 'x86_64' rather than 'amd64'.
31 This is to keep consistent with cobbler naming.34 This is to keep consistent with cobbler naming.
@@ -37,7 +40,7 @@
3740
38bad_Usage() { Usage 1>&2; [ $# -eq 0 ] || error "$@"; exit 1; }41bad_Usage() { Usage 1>&2; [ $# -eq 0 ] || error "$@"; exit 1; }
39cleanup() {42cleanup() {
40 [ -z "${TEMP_D}" -o ! -d "${TEMP_D}" ] || rm -Rf "${TEMP_D}"43 [ -z "${TEMP_D}" -o ! -d "${TEMP_D}" ] || rm -Rf "${TEMP_D}"
41}44}
4245
43loop_mount() {46loop_mount() {
@@ -49,10 +52,91 @@
49 chown root:disk /dev/loop$loops52 chown root:disk /dev/loop$loops
50 fi53 fi
51 # Do the loop mount54 # Do the loop mount
55 debug "Creating loopback mount from $1 at $2"
52 mount -o loop "$1" "$2"56 mount -o loop "$1" "$2"
53}57}
5458
55short_opts="Dhm:o:vcr"59get_iso() {
60 # first check release's update pocket for an iso.
61 # grab from release pocket if that does not exist.
62 if wget -O "$TEMP_D/$ISO" "$U_UPDATE"; then
63 debug "Downloaded ISO from updates pocket: $U_UPDATE"
64 elif wget -O "$TEMP_D/$ISO" "$U"; then
65 debug "Updating from release pocket: $U"
66 else
67 fail "failed download for $REL-$ARCH"
68 fi
69 { $delete || mv "$TEMP_D/$ISO" "$ISO_DIR/$ISO"; } ||
70 fail "failed to move iso $ISO_DIR/$ISO"
71}
72
73import_iso() {
74 # import iso into cobbler as $DISTRO
75 local mounted
76 local distro="$1"
77 if cobbler distro list | grep -qs " $distro"; then
78 fail "distro '$distro' already exists. cannot import."
79 fi
80 { [ -f "$TEMP_D/$ISO" ] || ln -sf "$ISO_DIR/$ISO" "$TEMP_D/$ISO"; } ||
81 fail "failed to create symlink to existing $ISO_DIR/$ISO"
82 mounted=0 && loop_mount "$TEMP_D/$ISO" "$TEMP_D/mnt" && mounted=1 &&
83 cobbler import --name="$distro" --path="$TEMP_D/mnt" \
84 --breed=ubuntu --os-version="$REL" --arch="$ARCH" &&
85 umount "${TEMP_D}/mnt" && mounted=0 || {
86 [ $mounted -eq 0 ] || umount "$TEMP_D/mnt";
87 fail "failed to import $REL-$ARCH";
88 }
89 echo "imported $distro"
90}
91
92reassign_distro() {
93 # swap out backing distro of profile with a newer, imported
94 # distro. after, remove the original and rename the new distro
95 # to match the previous distro name associated with profile
96 local new_distro="$1"
97 local profile="$2"
98 debug "Reassigning $profile to $new_distro"
99 if ! cobbler profile list | grep -qs " $profile"; then
100 fail "cannot reassign non-existent profile '$profile'"
101 fi
102 if ! cobbler distro list | grep -qs " $profile"; then
103 fail "distro matching profile '$profile' does not exist"
104 fi
105 debug "Renaming old profile '$profile' to 'last-$profile'"
106 cobbler distro rename --name="$profile" --newname="last-$profile" ||
107 fail "could not rename distro '$profile' to 'last-$profile'"
108 debug "Assigning profile $profile to distro $new_distro"
109 cobbler profile edit --name="$profile" --distro="$new_distro" ||
110 fail "could not assign profile '$profile' to distro '$new_distro'"
111 debug "Removing distro last-$profile"
112 cobbler distro remove --name="last-$profile" ||
113 fail "could not remove stale distro 'last-$profile'"
114 debug "Renaming distro $new_distro to $profile"
115 cobbler distro rename --name="$new_distro" --newname="$profile" ||
116 fail "could not rename distro '$new_distro' to '$profile'"
117 debug "Cleaning up temporary profile '$new_distro'"
118 cobbler profile remove --name="$new_distro" ||
119 fail "could not remove temp profile '$new_distro'"
120}
121
122function update_available() {
123 # check MD5SUM first from updates pocket if it exists, then release pocket.
124 # compare netboot mini iso with what is local.
125 local md5sum_local
126 local md5sum_remote
127 [ ! -f "$ISO_DIR/$ISO" ] && return 0
128 md5sum_local=$(md5sum "$ISO_DIR/$ISO") && md5sum_local=${md5sum_local%% *} &&
129 [ -n "$md5sum_local" ] || fail "failed to checksum $ISO_DIR/$ISO: $md5sum_local"
130 debug "local md5sum: $md5sum_local ($ISO_DIR/$ISO)"
131 wget -qO "$TEMP_D/MD5SUMS" "$MD5_UPDATE" || wget -qO "$TEMP_D/MD5SUMS" "$MD5" ||
132 fail "failed to download MD5SUMS for $REL-$ARCH."
133 md5sum_remote=$(awk '$2 == "./netboot/mini.iso" { print $1 }' $TEMP_D/MD5SUMS) &&
134 [ -n "$md5sum_remote" ] || fail "failed to parse checksum from $TEMP_D/MD5SUMS: $md5sum_remote"
135 debug "remote md5sum: $md5sum_remote"
136 [ "$md5sum_local" != "$md5sum_remote" ]
137}
138
139short_opts="Dhm:o:vcru"
56long_opts="delete-iso,help,mirror:,verbose,update-check,remove"140long_opts="delete-iso,help,mirror:,verbose,update-check,remove"
57getopt_out=$(getopt --name "${0##*/}" \141getopt_out=$(getopt --name "${0##*/}" \
58 --options "${short_opts}" --long "${long_opts}" -- "$@") &&142 --options "${short_opts}" --long "${long_opts}" -- "$@") &&
@@ -63,6 +147,7 @@
63check_update=false147check_update=false
64remove=false148remove=false
65mirror=${DEFAULT_MIRROR}149mirror=${DEFAULT_MIRROR}
150do_update=false
66151
67while [ $# -ne 0 ]; do152while [ $# -ne 0 ]; do
68 cur=${1}; next=${2};153 cur=${1}; next=${2};
@@ -73,6 +158,7 @@
73 -v|--verbose) VERBOSITY=$((${VERBOSITY}+1));;158 -v|--verbose) VERBOSITY=$((${VERBOSITY}+1));;
74 -c|--update-check) check_update=true;;159 -c|--update-check) check_update=true;;
75 -r|--remove) remove=true;;160 -r|--remove) remove=true;;
161 -u|--update) do_update=true;;
76 --) shift; break;;162 --) shift; break;;
77 esac163 esac
78 shift;164 shift;
@@ -82,62 +168,51 @@
82[ $# -ne 0 ] || bad_Usage "must provide arguments"168[ $# -ne 0 ] || bad_Usage "must provide arguments"
83169
84TEMP_D=$(mktemp -d "${TMPDIR:-/tmp}/${0##*/}.XXXXXX") ||170TEMP_D=$(mktemp -d "${TMPDIR:-/tmp}/${0##*/}.XXXXXX") ||
85 fail "failed to make tempdir"171 fail "failed to make tempdir"
86trap cleanup EXIT172trap cleanup EXIT
87173
88# program starts here174# program starts here
89if $delete; then175if $delete; then
90 { [ -d "$ISO_DIR" ] || mkdir -p "$ISO_DIR"; } || fail "failed to create $ISO_DIR"176 { [ -d "$ISO_DIR" ] || mkdir -p "$ISO_DIR"; } || fail "failed to create $ISO_DIR"
91fi177fi
92mkdir "$TEMP_D/mnt" || fail "failed to make tempdir/mnt"178mkdir "$TEMP_D/mnt" || fail "failed to make tempdir/mnt"
93179
94for tok in "$@"; do180for tok in "$@"; do
95 rel=${tok%-*}; arch=${tok#*-}181 REL=${tok%-*}; ARCH=${tok#*-}
96 [ "$arch" = "amd64" ] && 182 [ "$ARCH" = "amd64" ] &&
97 { error "Warning: using x86_64 for arch rather than amd64"; arch="x86_64"; }183 { error "Warning: using x86_64 for arch rather than amd64"; arch="x86_64"; }
98 ubuntu_arch=$arch; [ "$arch" = "x86_64" ] && ubuntu_arch=amd64184 ubuntu_arch=$ARCH; [ "$ARCH" = "x86_64" ] && ubuntu_arch=amd64
99 iso=$rel-$arch-mini.iso185 ISO=$REL-$ARCH-mini.iso
100 u=$mirror/dists/$rel/main/installer-$ubuntu_arch/current/images/netboot/mini.iso186 U=$mirror/dists/$REL/main/installer-$ubuntu_arch/current/images/netboot/mini.iso
101 md5=$mirror/dists/$rel/main/installer-$ubuntu_arch/current/images/MD5SUMS187 MD5=$mirror/dists/$REL/main/installer-$ubuntu_arch/current/images/MD5SUMS
188 U_UPDATE=$mirror/dists/$REL-updates/main/installer-$ubuntu_arch/current/images/netboot/mini.iso
189 MD5_UPDATE=$mirror/dists/$REL-updates/main/installer-$ubuntu_arch/current/images/MD5SUMS
102 if $remove; then190 if $remove; then
103 if [ -f "$ISO_DIR/$iso" ]; then191 if [ -f "$ISO_DIR/$ISO" ]; then
104 rm -rf "$ISO_DIR/$iso" ||192 debug "Removing $ISO_DIR/$ISO"
105 fail "Could not delete $ISO_DIR/$iso"193 rm -rf "$ISO_DIR/$ISO" ||
194 fail "Could not delete $ISO_DIR/$ISO"
106 fi195 fi
107 if cobbler distro list | grep -qs " $rel-$arch"; then196 if cobbler distro list | grep -qs " $REL-$ARCH"; then
108 cobbler distro remove --name=$rel-$arch ||197 debug "Removing cobbler distro '$REL-$ARCH'"
109 fail "Could not remove cobbler profile for $rel-$arch"198 cobbler distro remove --name="$REL-$ARCH" ||
199 fail "Could not remove cobbler profile for $REL-$ARCH"
110 fi200 fi
111 exit 0201 exit 0
112 fi202 fi
113 if $check_update; then203 if $check_update; then
114 # compare md5 of the local iso to whats on the mirror.204 update_available && echo "Update for $REL-$ARCH available" && exit 0
115 [ ! -f "$ISO_DIR/$iso" ] && exit 0205 echo "$ISO_DIR/$ISO up to date." && exit 3
116 md5=$mirror/dists/$rel/main/installer-$ubuntu_arch/current/images/MD5SUMS206 fi
117 md5sum_local=$(md5sum "$ISO_DIR/$iso") && md5sum_local=${md5sum_local% *} \207 if $do_update; then
118 && [ -n $md5sum_local ] || fail "failed to checksum $ISO_DIR/$iso"208 update_available || fail "No update available"
119 wget -qO $TEMP_D/MD5SUMS $md5 || fail "failed to download MD5SUMS for $rel-$arch: $u"209 # get iso from either pocket and import it with a tmp name.
120 md5sum_remote=$(awk '$2 == "./netboot/mini.iso" { print $1 }' $TEMP_D/MD5SUMS) &&210 get_iso && import_iso "tmp-$REL-$ARCH"
121 [ -n $md5sum_remote ] || fail "failed to parse checksum from $TEMP_D/MD5SUM"211 reassign_distro "tmp-$REL-$ARCH" "$REL-$ARCH"
122 [ $md5sum_local != $md5sum_remote ] && exit 0212 exit 0
123 error "$ISO_DIR/$iso up to date." && exit 3213 fi
124 fi214 [[ ! -f "$ISO_DIR/$ISO" ]] && get_iso
125 if [ ! -f "$ISO_DIR/$iso" ]; then215 import_iso "$REL-$ARCH" && echo "imported $REL-$ARCH"
126 wget -O "$TEMP_D/$iso" "$u" && [ -s "$TEMP_D/$iso" ] ||
127 fail "failed download for $rel-$arch: $u"
128 { $delete || mv "$TEMP_D/$iso" "$ISO_DIR/$iso"; } ||
129 fail "failed to write to move iso to $ISO_DIR/$iso"
130 fi
131 { [ -f $TEMP_D/$iso ] || ln -sf "$ISO_DIR/$iso" "$TEMP_D/$iso"; } ||
132 fail "failed to create symlink to existing $ISO_DIR/$iso"
133 mounted=0 && loop_mount "$TEMP_D/$iso" "$TEMP_D/mnt" && mounted=1 &&
134 cobbler import --name=$rel-$arch --path="$TEMP_D/mnt" \
135 --breed=ubuntu --os-version=$rel --arch=$arch &&
136 umount "${TEMP_D}/mnt" && mounted=0 || {
137 [ $mounted -eq 0 ] || umount "$TEMP_D/mnt";
138 fail "failed to import $rel-$arch";
139 }
140 echo "imported $rel-$arch"
141done216done
142217
143# vi: ts=4 noexpandtab218# vi: ts=4 noexpandtab

Subscribers

People subscribed via source and target branches