Fix various bugs in snf-image-helper
authorNikos Skalkotos <skalkoto@grnet.gr>
Thu, 10 Nov 2011 16:58:54 +0000 (18:58 +0200)
committerNikos Skalkotos <skalkoto@grnet.gr>
Thu, 10 Nov 2011 16:58:54 +0000 (18:58 +0200)
* In decode-properties.py, use subprocess.Popen method instead of
  subprocess.check_output, which is introduced in python 2.7

* Fix a bug in snf-image-helper where decode-properties.py was not
  properly called

* Fix a bug in FixPartitionTable task

snf-image-helper/decode-properties.py
snf-image-helper/snf-image-helper.in
snf-image-helper/tasks/10FixPartitionTable.in

index a692c50..28af730 100755 (executable)
@@ -46,10 +46,11 @@ def main():
     for key, value in properties.items():
         os.environ['SNF_IMAGE_PROPERTY_' + key] = value
 
-    output = StringIO(subprocess.check_output(['bash', '-c', 'set']))
+    p = subprocess.Popen(['bash', '-c', 'set'], stdout=subprocess.PIPE)
+    output = StringIO(p.communicate()[0]);
     for line in iter(output):
         if line.startswith('SNF_IMAGE_PROPERTY_'):
-            outfh.write(line)
+            outfh.write('export ' + line)
 
     infh.close()
     outfh.close()
index d6dcc2c..384ffe6 100644 (file)
@@ -62,8 +62,8 @@ fi
 if [ -n "$SNF_IMAGE_PROPERTIES" ]; then
     properties=$(mktemp --tmpdir properties.XXXXXX)
     add_cleanup rm "$properties"
-    echo "SNF_IMAGE_PROPERTIES" |
-        "@scriptsdir@/snf-decode-properties.py" > "$properties"
+    echo "$SNF_IMAGE_PROPERTIES" |
+        "@scriptsdir@/decode-properties.py" "$properties"
     source "$properties"
 else
     log_error "SNF_IMAGE_PROPERTIES variable is missing"
index cfa0f3f..5f2d081 100644 (file)
@@ -37,12 +37,17 @@ fi
 
 new_pend=$(get_last_free_sector "$SNF_IMAGE_DEV")
 
-#Extend the partition
+if [ -z "$new_pend" ] ; then
+    # Nothing to do
+    exit 0
+fi
+
+# Extend the partition
 
 $PARTED -s -m "$SNF_IMAGE_DEV" rm "$id"
 $PARTED -s -m "$SNF_IMAGE_DEV" mkpart primary "$ptype" "$pstart" "$new_pend"
 
-#inform the kernel about the changes
+# Inform the kernel about the changes
 partprobe "$SNF_IMAGE_DEV"
 
 exit 0