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

Proposed by Adam Gandelman
Status: Merged
Merged at revision: 48
Proposed branch: lp:~gandelman-a/ubuntu/oneiric/cobbler/lp850892
Merge into: lp:ubuntu/oneiric/cobbler
Diff against target: 98 lines (+46/-7)
2 files modified
debian/changelog (+8/-0)
debian/cobbler-ubuntu-import (+38/-7)
To merge this branch: bzr merge lp:~gandelman-a/ubuntu/oneiric/cobbler/lp850892
Reviewer Review Type Date Requested Status
Ubuntu branches Pending
Review via email: mp+75650@code.launchpad.net

Description of the change

Adds some functionality to be used by orchestra-import-isos to keep local ISOs in sync and up-to-date with what is on the mirror.

--update-check: Compares the md5 checksum of the local ISO with what is on the mirror, as reported in the corresponding server-side MD5SUMS file (ie, http://archive.ubuntu.com/ubuntu/dists/oneiric/main/installer-amd64/current/images/MD5SUMS). Returns true if checksums differ, or if the local ISO does not exist (it will be downloaded by orchestra-import-isos later)

--remove: If they exist, removes the ISO and/or corresponding cobbler profile from the server in preparation of a resync. Removing the profile is necessary as cobbler will not re-import the ISO if the profile name already exists and does not offer the ability to update a profile/

For a look at how it can be used on the Orchestra side, see: lp:~gandelman-a/ubuntu/oneiric/orchestra/lp850892 Remove

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

Overall this looks good. Some minor nit picks:
 - if (cobbler distro list | grep -qs " $rel-$arch"); then
   you dont' need a subshell there. Ie, no reason for the "()"

 - md5sum_local=`md5sum $ISO_DIR/$iso | awk '{ print $1 }'`
   does not check for failure. maybe try:
    md5sum_local=$(md5sum "$ISO_DIR/$iso") && md5sum_local="${md5sum_local% *}" && [ -n "${md5sum_local}" || fail "failed to checksum"

 - md5sum_remote=`cat $TEMP_D/MD5SUMS | grep '\./netboot/mini.iso' | awk '{ print $1 }'`
   that is a "pointless use of cat"
   try:
   md5sum_remote=$(awk '$2 == "./netboot/mini.iso" { print $1 }) && [ -n "$md5sum_remote" ] || fail "failed to get remote sum"

- probably should exit with a known exit value if "out of date" ratehr than just using "fail"
  100 + [ $md5sum_local != $md5sum_remote ] && exit 0
  101 + error "$ISO_DIR/$iso up to date."
  102 + exit 3

- did you think about trying to fix bug 850880 also ?
  I like the use of the MD5SUMS file, that might help us. I'd say you can just check the -updates first, and if its not there, try the release pocket.

49. By Adam Gandelman

Shell cleanup as per smoser's comments

50. By Adam Gandelman

Whitepace cleanup

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'debian/changelog'
2--- debian/changelog 2011-09-08 13:01:55 +0000
3+++ debian/changelog 2011-09-16 05:15:32 +0000
4@@ -1,3 +1,11 @@
5+cobbler (2.1.0+git20110602-0ubuntu26) UNRELEASED; urgency=low
6+
7+ * debian/cobbler-ubuntu-import: Add --check-update and --remove
8+ functionality. This should help orchestra-import-isos keep local
9+ ISO caches up-to-date. (LP: #850892)
10+
11+ -- Adam Gandelman <adamg@canonical.com> Thu, 15 Sep 2011 16:36:39 -0700
12+
13 cobbler (2.1.0+git20110602-0ubuntu25) oneiric; urgency=low
14
15 * debian/cobbler-common.install: Install missing pxeprofile_arm.template
16
17=== modified file 'debian/cobbler-ubuntu-import'
18--- debian/cobbler-ubuntu-import 2011-08-11 13:02:11 +0000
19+++ debian/cobbler-ubuntu-import 2011-09-16 05:15:32 +0000
20@@ -18,11 +18,14 @@
21 import distro and profile for Ubuntu release-arch
22
23 options:
24- -D | --delete-iso delete the mini iso after downloading. Normally
25- they are kept in $ISO_DIR
26- -m | --mirror M use mirror rather than default for downloading iso
27- default: ${DEFAULT_MIRROR}
28-
29+ -D | --delete-iso delete the mini iso after downloading. Normally
30+ they are kept in $ISO_DIR
31+ -m | --mirror M use mirror rather than default for downloading iso
32+ default: ${DEFAULT_MIRROR}
33+ -c | --update-check check saved ISOs against what is published on the
34+ mirror. exits 0 if an update is needed or iso does
35+ not exist in $ISO_DIR
36+ -r | --remove remove cobbler profile/distro and cached ISO
37 Note, arch can be i386, x86_64, or amd64. However,
38 the registered distro and profile will use 'x86_64' rather than 'amd64'.
39 This is to keep consistent with cobbler naming.
40@@ -49,14 +52,16 @@
41 mount -o loop "$1" "$2"
42 }
43
44-short_opts="Dhm:o:v"
45-long_opts="delete-iso,help,mirror:,verbose"
46+short_opts="Dhm:o:vcr"
47+long_opts="delete-iso,help,mirror:,verbose,update-check,remove"
48 getopt_out=$(getopt --name "${0##*/}" \
49 --options "${short_opts}" --long "${long_opts}" -- "$@") &&
50 eval set -- "${getopt_out}" ||
51 bad_Usage
52
53 delete=false
54+check_update=false
55+remove=false
56 mirror=${DEFAULT_MIRROR}
57
58 while [ $# -ne 0 ]; do
59@@ -66,6 +71,8 @@
60 -m|--mirror) mirror=${2}; shift;;
61 -D|--delete-iso) delete=true;;
62 -v|--verbose) VERBOSITY=$((${VERBOSITY}+1));;
63+ -c|--update-check) check_update=true;;
64+ -r|--remove) remove=true;;
65 --) shift; break;;
66 esac
67 shift;
68@@ -91,6 +98,30 @@
69 ubuntu_arch=$arch; [ "$arch" = "x86_64" ] && ubuntu_arch=amd64
70 iso=$rel-$arch-mini.iso
71 u=$mirror/dists/$rel/main/installer-$ubuntu_arch/current/images/netboot/mini.iso
72+ md5=$mirror/dists/$rel/main/installer-$ubuntu_arch/current/images/MD5SUMS
73+ if $remove; then
74+ if [ -f "$ISO_DIR/$iso" ]; then
75+ rm -rf "$ISO_DIR/$iso" ||
76+ fail "Could not delete $ISO_DIR/$iso"
77+ fi
78+ if cobbler distro list | grep -qs " $rel-$arch"; then
79+ cobbler distro remove --name=$rel-$arch ||
80+ fail "Could not remove cobbler profile for $rel-$arch"
81+ fi
82+ exit 0
83+ fi
84+ if $check_update; then
85+ # compare md5 of the local iso to whats on the mirror.
86+ [ ! -f "$ISO_DIR/$iso" ] && exit 0
87+ md5=$mirror/dists/$rel/main/installer-$ubuntu_arch/current/images/MD5SUMS
88+ md5sum_local=$(md5sum "$ISO_DIR/$iso") && md5sum_local=${md5sum_local% *} \
89+ && [ -n $md5sum_local ] || fail "failed to checksum $ISO_DIR/$iso"
90+ wget -qO $TEMP_D/MD5SUMS $md5 || fail "failed to download MD5SUMS for $rel-$arch: $u"
91+ md5sum_remote=$(awk '$2 == "./netboot/mini.iso" { print $1 }' $TEMP_D/MD5SUMS) &&
92+ [ -n $md5sum_remote ] || fail "failed to parse checksum from $TEMP_D/MD5SUM"
93+ [ $md5sum_local != $md5sum_remote ] && exit 0
94+ error "$ISO_DIR/$iso up to date." && exit 3
95+ fi
96 if [ ! -f "$ISO_DIR/$iso" ]; then
97 wget -O "$TEMP_D/$iso" "$u" && [ -s "$TEMP_D/$iso" ] ||
98 fail "failed download for $rel-$arch: $u"

Subscribers

People subscribed via source and target branches