Merge lp:~hggdh2/testdrive/testdrive-cache into lp:testdrive

Proposed by C de-Avillez
Status: Merged
Merged at revision: not available
Proposed branch: lp:~hggdh2/testdrive/testdrive-cache
Merge into: lp:testdrive
Diff against target: 143 lines (+52/-18)
2 files modified
testdrive (+40/-18)
testdriverc (+12/-0)
To merge this branch: bzr merge lp:~hggdh2/testdrive/testdrive-cache
Reviewer Review Type Date Requested Status
Dustin Kirkland  Pending
Review via email: mp+21492@code.launchpad.net

Description of the change

use CACHE_IMG and CACHE_ISO (defaulting to $CACHE/img and $CACHE/iso if not specified).

Introduce CLEAN_IMG to forcefully remove the image at end of run. Default is to keep the image, unless CACHE_IMG == /dev/shm.

To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'testdrive'
2--- testdrive 2010-03-15 20:51:26 +0000
3+++ testdrive 2010-03-16 21:10:29 +0000
4@@ -30,7 +30,10 @@
5 ISO_URL = os.getenv("ISO_URL", "")
6 DESKTOP = os.getenv("DESKTOP", "")
7 VIRT = os.getenv("VIRT", "")
8-CACHE = os.getenv("CACHE", "")
9+CACHE = os.getenv("CACHE", None)
10+CACHE_ISO = os.getenv("CACHE_ISO", None)
11+CACHE_IMG = os.getenv("CACHE_IMG", None)
12+CLEAN_IMG = os.getenv("CLEAN_IMG", None)
13 MEM = os.getenv("MEM", "")
14 DISK_FILE = os.getenv("DISK_FILE", "")
15 DISK_SIZE = os.getenv("DISK_SIZE", "")
16@@ -203,6 +206,7 @@
17 if opt.url:
18 hasOptions = True
19 ISO_URL = is_iso(opt.url)
20+
21 if opt.desktop:
22 hasOptions = True
23 DESKTOP = 1
24@@ -222,15 +226,29 @@
25
26 # Set defaults where undefined
27
28-if len(CACHE) == 0:
29+if CACHE is None:
30 CACHE = "%s/.cache/%s" % (HOME, PKG)
31-for i in ("iso", "img"):
32- if not os.path.exists("%s/%s" % (CACHE, i)):
33- os.makedirs("%s/%s" % (CACHE, i), 0700)
34+
35+if CACHE_IMG is None:
36+ CACHE_IMG = '%s/img' % CACHE
37+if not os.path.exists(CACHE_IMG):
38+ os.makedirs(CACHE_IMG, 0700)
39+# if running the image from /dev/shm, remove the image when done
40+# (unless CLEAN_IMG is set)
41+if CLEAN_IMG is None:
42+ if CACHE_IMG == '/dev/shm':
43+ CLEAN_IMG = True
44+ else:
45+ CLEAN_IMG = False
46+
47+if CACHE_ISO is None:
48+ CACHE_ISO = '%s/iso' % CACHE
49+if not os.path.exists(CACHE_ISO):
50+ os.makedirs(CACHE_ISO, 0700)
51
52 ISO_NAME = os.path.basename(ISO_URL)
53 PROTO = ISO_URL.partition(":")[0]
54-PATH_TO_ISO = "%s/iso/%s" % (CACHE, ISO_NAME)
55+PATH_TO_ISO = "%s/%s" % (CACHE_ISO, ISO_NAME)
56
57 if len(MEM) == 0:
58 total = commands.getoutput("grep ^MemTotal /proc/meminfo | awk '{print $2}'")
59@@ -242,8 +260,7 @@
60 MEM = 256
61
62 if len(DISK_FILE) == 0:
63- DISK_FILE = tempfile.mkstemp(".img", "testdrive-disk-", "%s/img" % CACHE)[1]
64- info('disk file=%s' % DISK_FILE)
65+ DISK_FILE = tempfile.mkstemp(".img", "testdrive-disk-", "%s" % CACHE_IMG)[1]
66
67 if len(DISK_SIZE) == 0:
68 DISK_SIZE = "6G"
69@@ -266,7 +283,7 @@
70 error("ISO not found at [%s]" % ISO_URL)
71 ZSYNC_WORKED = 0
72 if commands.getstatusoutput("which zsync")[0] == 0:
73- if run("cd %s/iso && zsync %s.zsync" % (CACHE, ISO_URL)) != 0:
74+ if run("cd %s && zsync %s.zsync" % (CACHE_ISO, ISO_URL)) != 0:
75 # If the zsync failed, use wget
76 run_or_die("wget %s -O %s" % (ISO_URL, PATH_TO_ISO))
77 else:
78@@ -367,28 +384,33 @@
79 else:
80 error("Unsupported virtualization method [%s]" % VIRT)
81
82+# if requested to clean out the image mark it to be done
83+if CLEAN_IMG:
84+ rm_disk = True
85+else:
86+ rm_disk = False
87+
88 # If disk image is stock (e.g., you just ran a LiveCD, no installation),
89 # purge it automatically.
90-rm_disk = 0
91 if os.path.exists(DISK_FILE):
92 if os.path.getsize(DISK_FILE) == 262144 and md5sum(DISK_FILE) == "1da7553f642332ec9fb58a6094d2c8ef":
93 # Clean up kvm qcow2 image
94- rm_disk = 1
95+ rm_disk = True
96 if os.path.getsize(DISK_FILE) == 24576:
97 # Clean up vbox image
98- rm_disk = 1
99+ rm_disk = True
100 elif os.path.getsize(DISK_FILE) == 0:
101 # Clean up empty file
102- rm_disk = 1
103- if rm_disk == 1:
104- info("Cleaning up empty disk image [%s]..." % DISK_FILE)
105+ rm_disk = True
106+ if rm_disk:
107+ info("Cleaning up disk image [%s]..." % DISK_FILE)
108 os.unlink(DISK_FILE)
109
110 # Remind about cache cleanup
111 info("You may wish to clean up the cache directory...")
112-print(" %s" % CACHE)
113-#run("ls -HhalF %s/iso %s/img" % (CACHE, CACHE))
114-#run("du -sh --apparent-size %s 2>/dev/null || du -sh %s" % (CACHE, CACHE))
115+print(" %s and %s" % (CACHE_ISO, CACHE_IMG))
116+#run("ls -HhalF %s %s" % (CACHE_ISO, CACHE_IMG))
117+#run("du -sh --apparent-size %s %s 2>/dev/null || du -sh %s %s" % (CACHE_ISO, CACHE_IMG))
118
119 if DESKTOP == 1:
120 if os.path.exists("/usr/bin/usb-creator-gtk"):
121
122=== modified file 'testdriverc'
123--- testdriverc 2010-03-02 03:41:39 +0000
124+++ testdriverc 2010-03-16 21:10:29 +0000
125@@ -5,6 +5,18 @@
126 # Default: $HOME/.cache/testdrive
127 #CACHE = "/path/to/your/cache"
128
129+# CACHE_IMG and CACHE_ISO will default to $CACHE/img and $CACHE/iso, respectively.
130+# You can set them explicitly if you want (specially interesting if you are
131+# trying to run the image off /dev/shm.
132+#CACHE_IMG = "/dev/shm"
133+
134+# CLEAN_IMG will remove the just-generated image at the end of run. By default the image
135+# is kept, unless nothing was changed (i.e., the disk image was created, but no installation
136+# was actually tried.
137+# If running the image off /dev/shm, then *by default* the image will be removed (memory is a
138+# restricted resource, and we should not over-allocate it)
139+#CLEAN_IMG = True
140+
141 # ISO_URL is the complete path to the ISO
142 # Default: $PROTO://$MIRROR/$DIR/$CODENAME-$TYPE-$ARCH.iso
143 #ISO_URL = "http://cdimage.ubuntu.com/ubuntu-netbook/daily-live/current/lucid-netbook-i386.iso"

Subscribers

People subscribed via source and target branches