Merge lp:~pwlars/qa-iso-static-validation-test/pep8 into lp:qa-iso-static-validation-test

Proposed by Paul Larson
Status: Merged
Merged at revision: 15
Proposed branch: lp:~pwlars/qa-iso-static-validation-test/pep8
Merge into: lp:qa-iso-static-validation-test
Diff against target: 330 lines (+71/-67)
1 file modified
iso_static_validation.py (+71/-67)
To merge this branch: bzr merge lp:~pwlars/qa-iso-static-validation-test/pep8
Reviewer Review Type Date Requested Status
Para Siva Approve
Review via email: mp+124925@code.launchpad.net

Description of the change

No other changes or cleanups in this branch, just enough to make it pass
pep8 compliance.

To post a comment you must log in.
Revision history for this message
Para Siva (psivaa) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'iso_static_validation.py'
--- iso_static_validation.py 2012-08-30 08:57:30 +0000
+++ iso_static_validation.py 2012-09-18 13:39:20 +0000
@@ -28,20 +28,19 @@
28import subprocess28import subprocess
29import hashlib29import hashlib
30import unittest30import unittest
31import time
32import datetime
33import re31import re
34import tempfile32import tempfile
35import shutil33import shutil
3634
37# Defaults35# Defaults
38#DEFAULT_ISOROOT = os.path.expanduser('/var/lib/ubuntu-server-iso-testing/isos/ubuntu/')36#DEFAULT_ISOROOT = os.path.expanduser(
37# '/var/lib/ubuntu-server-iso-testing/isos/ubuntu/')
39DEFAULT_URL = 'http://cdimage.ubuntu.com/'38DEFAULT_URL = 'http://cdimage.ubuntu.com/'
4039
41#constants40#constants
42ONE_MB_BLOCK=2**2041ONE_MB_BLOCK = 2 ** 20
43PRECISE_SIZE_LIMIT_MB=73714892842PRECISE_SIZE_LIMIT_MB = 737148928
44QUANTAL_SIZE_LIMIT_MB=83886080043QUANTAL_SIZE_LIMIT_MB = 838860800
4544
46#Read the iso name and initialise global variables45#Read the iso name and initialise global variables
47parser = argparse.ArgumentParser()46parser = argparse.ArgumentParser()
@@ -49,10 +48,11 @@
49parser.add_argument('--name')48parser.add_argument('--name')
50args = parser.parse_args()49args = parser.parse_args()
5150
52logging.basicConfig(level = logging.INFO)51logging.basicConfig(level=logging.INFO)
5352
54if args.name == None or '.iso' not in args.name or args.isoroot == None:53if args.name == None or '.iso' not in args.name or args.isoroot == None:
55 print 'The usage:', sys.argv[0], '--name release-variant-arch.iso --isoroot ~/iso_location'54 print('The usage:', sys.argv[0],
55 '--name release-variant-arch.iso --isoroot ~/iso_location')
56 sys.exit(1)56 sys.exit(1)
57else:57else:
58 st_name = args.name.rstrip('.iso')58 st_name = args.name.rstrip('.iso')
@@ -68,6 +68,7 @@
68else:68else:
69 ubiquity_image = False69 ubiquity_image = False
7070
71
71class TestValidateISO(unittest.TestCase):72class TestValidateISO(unittest.TestCase):
72 @classmethod73 @classmethod
73 def setUpClass(cls):74 def setUpClass(cls):
@@ -76,7 +77,7 @@
76 except OSError:77 except OSError:
77 logging.error("Creating temp dirrectory failed")78 logging.error("Creating temp dirrectory failed")
78 unittest.fail("Setup error")79 unittest.fail("Setup error")
79 80
80 def setUp(self):81 def setUp(self):
81 self.iso_name = args.name82 self.iso_name = args.name
82 self.block_size = ONE_MB_BLOCK83 self.block_size = ONE_MB_BLOCK
@@ -84,7 +85,7 @@
84 self.st_release = st_release85 self.st_release = st_release
85 self.st_variant = st_variant86 self.st_variant = st_variant
86 self.st_arch = st_arch87 self.st_arch = st_arch
87 88
88 if self.st_release != 'precise':89 if self.st_release != 'precise':
89 self.url = DEFAULT_URL90 self.url = DEFAULT_URL
90 else:91 else:
@@ -100,7 +101,7 @@
100 if self.st_release == 'precise':101 if self.st_release == 'precise':
101 self.url = os.path.join(DEFAULT_URL, 'ubuntu-server',102 self.url = os.path.join(DEFAULT_URL, 'ubuntu-server',
102 'precise', 'daily')103 'precise', 'daily')
103 else: # current dev release104 else: # current dev release
104 self.url = os.path.join(DEFAULT_URL, 'ubuntu-server', 'daily')105 self.url = os.path.join(DEFAULT_URL, 'ubuntu-server', 'daily')
105 else:106 else:
106 self.fail("Image name be in the form of release-variant-arch.iso")107 self.fail("Image name be in the form of release-variant-arch.iso")
@@ -134,10 +135,10 @@
134 sha256 = hashlib.sha256()135 sha256 = hashlib.sha256()
135 with open(self.iso_location) as f:136 with open(self.iso_location) as f:
136 while True:137 while True:
137 data = f.read(self.block_size)138 data = f.read(self.block_size)
138 if not data:139 if not data:
139 break140 break
140 sha256.update(data)141 sha256.update(data)
141 sha256 = sha256.hexdigest()142 sha256 = sha256.hexdigest()
142 logging.debug("Expected Checksum: '%s'", iso_sha256)143 logging.debug("Expected Checksum: '%s'", iso_sha256)
143 logging.debug("Local File Checksum: '%s'", sha256)144 logging.debug("Local File Checksum: '%s'", sha256)
@@ -146,13 +147,13 @@
146 # Test if the list file in the repository matches the content of the iso147 # Test if the list file in the repository matches the content of the iso
147 def test_files_list(self):148 def test_files_list(self):
148 if self.st_variant == 'server':149 if self.st_variant == 'server':
149 list_url = os.path.join(self.url, 'current', 150 list_url = os.path.join(self.url, 'current',
150 self.st_release + '-' + 'server' + '-' +151 self.st_release + '-' + 'server' + '-' +
151 self.st_arch + '.list')152 self.st_arch + '.list')
152 else:153 else:
153 list_url = os.path.join(self.url, 'current', 154 list_url = os.path.join(self.url, 'current',
154 self.st_release + '-' +155 self.st_release + '-' +
155 self.st_variant + '-' + 156 self.st_variant + '-' +
156 self.st_arch + '.list')157 self.st_arch + '.list')
157158
158 try:159 try:
@@ -164,9 +165,9 @@
164165
165 logging.debug('Extracting list file info from ISO')166 logging.debug('Extracting list file info from ISO')
166 cmd = ["bsdtar", "-tf", self.iso_location]167 cmd = ["bsdtar", "-tf", self.iso_location]
167 output = subprocess.Popen(cmd, stdout = subprocess.PIPE,168 output = subprocess.Popen(cmd, stdout=subprocess.PIPE,
168 stderr = subprocess.PIPE)169 stderr=subprocess.PIPE)
169 (stdout, stderr) = output.communicate ()170 (stdout, stderr) = output.communicate()
170 logging.debug('Checking for error in extracting the file list')171 logging.debug('Checking for error in extracting the file list')
171 self.assertEqual(stderr, '')172 self.assertEqual(stderr, '')
172173
@@ -175,12 +176,12 @@
175 self.assertIn(list_entry[1:].rstrip(), stdout)176 self.assertIn(list_entry[1:].rstrip(), stdout)
176177
177 # Test if the manfest is the same as that is given in the server178 # Test if the manfest is the same as that is given in the server
178 @unittest.skipUnless(ubiquity_image, 179 @unittest.skipUnless(ubiquity_image,
179 "manifest only for ubiquity based images")180 "manifest only for ubiquity based images")
180 def test_manifest(self):181 def test_manifest(self):
181 manifest_url = os.path.join(self.url, 'current', 182 manifest_url = os.path.join(self.url, 'current',
182 self.st_release + '-' +183 self.st_release + '-' +
183 self.st_variant + '-' + 184 self.st_variant + '-' +
184 self.st_arch + '.manifest')185 self.st_arch + '.manifest')
185 try:186 try:
186 manifest = urllib2.urlopen(manifest_url)187 manifest = urllib2.urlopen(manifest_url)
@@ -192,9 +193,9 @@
192 logging.debug('Extracting manifest from the iso')193 logging.debug('Extracting manifest from the iso')
193 cmd = ["bsdtar", "-xf", self.iso_location, "-C", self.temp_dir,194 cmd = ["bsdtar", "-xf", self.iso_location, "-C", self.temp_dir,
194 "casper/filesystem.manifest"]195 "casper/filesystem.manifest"]
195 output = subprocess.Popen(cmd, stdout = subprocess.PIPE,196 output = subprocess.Popen(cmd, stdout=subprocess.PIPE,
196 stderr = subprocess.PIPE)197 stderr=subprocess.PIPE)
197 (stdout, stderr) = output.communicate ()198 (stdout, stderr) = output.communicate()
198 logging.debug('Check for error in extracting manifest info from iso')199 logging.debug('Check for error in extracting manifest info from iso')
199 self.assertEqual(stderr, '')200 self.assertEqual(stderr, '')
200201
@@ -212,9 +213,9 @@
212 logging.debug('Extract distro information of the image from the iso')213 logging.debug('Extract distro information of the image from the iso')
213 cmd = ["bsdtar", "-xf", self.iso_location, "-C",214 cmd = ["bsdtar", "-xf", self.iso_location, "-C",
214 self.temp_dir, "./.disk/info"]215 self.temp_dir, "./.disk/info"]
215 output = subprocess.Popen(cmd, stdout = subprocess.PIPE,216 output = subprocess.Popen(cmd, stdout=subprocess.PIPE,
216 stderr = subprocess.PIPE)217 stderr=subprocess.PIPE)
217 (stdout, stderr) = output.communicate ()218 (stdout, stderr) = output.communicate()
218 logging.debug('Checking for error in extracting distro info from iso')219 logging.debug('Checking for error in extracting distro info from iso')
219 self.assertEqual(stderr, '')220 self.assertEqual(stderr, '')
220221
@@ -240,36 +241,36 @@
240 self.assertIn(id_server, build_info_line)241 self.assertIn(id_server, build_info_line)
241242
242 # Test if wubi is present for desktop or dvd and it is a valid PE243 # Test if wubi is present for desktop or dvd and it is a valid PE
243 @unittest.skipUnless(st_variant =='desktop' and 244 @unittest.skipUnless(st_variant == 'desktop' and
244 st_arch != 'powerpc', "Skipping non ubiquity images")245 st_arch != 'powerpc', "Skipping non ubiquity images")
245 def test_wubi(self):246 def test_wubi(self):
246 logging.debug('Extracting wubi from the desktop images')247 logging.debug('Extracting wubi from the desktop images')
247 cmd = ["bsdtar", "-xf", self.iso_location, "-C", 248 cmd = ["bsdtar", "-xf", self.iso_location, "-C",
248 self.temp_dir, "./wubi.exe"]249 self.temp_dir, "./wubi.exe"]
249 output = subprocess.Popen(cmd, stdout = subprocess.PIPE,250 output = subprocess.Popen(cmd, stdout=subprocess.PIPE,
250 stderr = subprocess.PIPE)251 stderr=subprocess.PIPE)
251 (stdout, stderr) = output.communicate ()252 (stdout, stderr) = output.communicate()
252 logging.debug('Check for error in extracting wubi.exe from the iso')253 logging.debug('Check for error in extracting wubi.exe from the iso')
253 self.assertEqual(stderr, '')254 self.assertEqual(stderr, '')
254255
255 wubi_path = os.path.join(self.temp_dir, './wubi.exe')256 wubi_path = os.path.join(self.temp_dir, './wubi.exe')
256257
257 cmd = ["file", wubi_path]258 cmd = ["file", wubi_path]
258 output = subprocess.Popen(cmd, stdout = subprocess.PIPE,259 output = subprocess.Popen(cmd, stdout=subprocess.PIPE,
259 stderr = subprocess.PIPE)260 stderr=subprocess.PIPE)
260 (stdout, stderr) = output.communicate ()261 (stdout, stderr) = output.communicate()
261 logging.debug('Check that wubi has a valid PE header')262 logging.debug('Check that wubi has a valid PE header')
262 self.assertEqual(stderr, '')263 self.assertEqual(stderr, '')
263 self.assertIn(" PE32 executable (GUI)", stdout)264 self.assertIn(" PE32 executable (GUI)", stdout)
264265
265 # Test if the relevant files are present in the iso for desktop iso266 # Test if the relevant files are present in the iso for desktop iso
266 @unittest.skipUnless(st_variant == 'desktop' and 267 @unittest.skipUnless(st_variant == 'desktop' and
267 st_arch != 'powerpc', "Skipping for non desktop iso")268 st_arch != 'powerpc', "Skipping for non desktop iso")
268 def test_files_ubiquity(self):269 def test_files_ubiquity(self):
269 cmd = ["bsdtar", "-tf", self.iso_location]270 cmd = ["bsdtar", "-tf", self.iso_location]
270 output = subprocess.Popen(cmd, stdout = subprocess.PIPE,271 output = subprocess.Popen(cmd, stdout=subprocess.PIPE,
271 stderr = subprocess.PIPE)272 stderr=subprocess.PIPE)
272 (stdout, stderr) = output.communicate ()273 (stdout, stderr) = output.communicate()
273 logging.debug('Check for error in extracting file list from the iso')274 logging.debug('Check for error in extracting file list from the iso')
274 self.assertEqual(stderr, '')275 self.assertEqual(stderr, '')
275 files_list = open("data/file_list_ubiquity")276 files_list = open("data/file_list_ubiquity")
@@ -282,9 +283,9 @@
282 "This file list test is only specific for dvd")283 "This file list test is only specific for dvd")
283 def test_files_ubiquity_dvd(self):284 def test_files_ubiquity_dvd(self):
284 cmd = ["bsdtar", "-tf", self.iso_location]285 cmd = ["bsdtar", "-tf", self.iso_location]
285 output = subprocess.Popen(cmd, stdout = subprocess.PIPE,286 output = subprocess.Popen(cmd, stdout=subprocess.PIPE,
286 stderr = subprocess.PIPE)287 stderr=subprocess.PIPE)
287 (stdout, stderr) = output.communicate ()288 (stdout, stderr) = output.communicate()
288 logging.debug('Check for error in extracting file list from the iso')289 logging.debug('Check for error in extracting file list from the iso')
289 self.assertEqual(stderr, '')290 self.assertEqual(stderr, '')
290 files_list = open("data/file_list_ubiquity_dvd")291 files_list = open("data/file_list_ubiquity_dvd")
@@ -300,15 +301,15 @@
300 @unittest.skipIf(ubiquity_image, "Skipping for ubiquity images")301 @unittest.skipIf(ubiquity_image, "Skipping for ubiquity images")
301 def test_files_di(self):302 def test_files_di(self):
302 cmd = ["bsdtar", "-tf", self.iso_location]303 cmd = ["bsdtar", "-tf", self.iso_location]
303 output = subprocess.Popen(cmd, stdout = subprocess.PIPE,304 output = subprocess.Popen(cmd, stdout=subprocess.PIPE,
304 stderr = subprocess.PIPE)305 stderr=subprocess.PIPE)
305 (stdout, stderr) = output.communicate ()306 (stdout, stderr) = output.communicate()
306 logging.debug('Check for error in extracting file list from the iso')307 logging.debug('Check for error in extracting file list from the iso')
307 self.assertEqual(stderr, '')308 self.assertEqual(stderr, '')
308309
309 if self.st_arch == 'powerpc' or self.st_arch == 'amd64+mac':310 if self.st_arch == 'powerpc' or self.st_arch == 'amd64+mac':
310 files_list = open("data/file_list_di_powerpc")311 files_list = open("data/file_list_di_powerpc")
311 else: #i386 or amd64312 else: # i386 or amd64
312 files_list = open("data/file_list_di")313 files_list = open("data/file_list_di")
313314
314 for list_server in files_list:315 for list_server in files_list:
@@ -321,42 +322,43 @@
321 def test_vmlinuz(self):322 def test_vmlinuz(self):
322 cmd = ["bsdtar", "-xf", self.iso_location, "-C",323 cmd = ["bsdtar", "-xf", self.iso_location, "-C",
323 self.temp_dir, "casper/vmlinuz"]324 self.temp_dir, "casper/vmlinuz"]
324 output = subprocess.Popen(cmd, stdout = subprocess.PIPE,325 output = subprocess.Popen(cmd, stdout=subprocess.PIPE,
325 stderr = subprocess.PIPE)326 stderr=subprocess.PIPE)
326 (stdout, stderr) = output.communicate ()327 (stdout, stderr) = output.communicate()
327 logging.debug('Asserting that vmlinuz is present in the iso')328 logging.debug('Asserting that vmlinuz is present in the iso')
328 self.assertEqual(stderr, '')329 self.assertEqual(stderr, '')
329330
330 vmlinuz_path = os.path.join(self.temp_dir, 'casper/vmlinuz')331 vmlinuz_path = os.path.join(self.temp_dir, 'casper/vmlinuz')
331332
332 cmd = ["file", vmlinuz_path]333 cmd = ["file", vmlinuz_path]
333 output = subprocess.Popen(cmd, stdout = subprocess.PIPE,334 output = subprocess.Popen(cmd, stdout=subprocess.PIPE,
334 stderr = subprocess.PIPE)335 stderr=subprocess.PIPE)
335 (stdout, stderr) = output.communicate ()336 (stdout, stderr) = output.communicate()
336 logging.debug('Check if vmlinuz present in the iso is a Linux kernel')337 logging.debug('Check if vmlinuz present in the iso is a Linux kernel')
337 self.assertEqual(stderr, '')338 self.assertEqual(stderr, '')
338 self.assertIn("Linux kernel", stdout)339 self.assertIn("Linux kernel", stdout)
339340
340 # Test if filesystem.squashfs is present and 341 # Test if filesystem.squashfs is present and
341 # if that is a squash fs for ubiquity based images342 # if that is a squash fs for ubiquity based images
342 @unittest.skipUnless(ubiquity_image, "Skipping for non ubiquity images")343 @unittest.skipUnless(ubiquity_image, "Skipping for non ubiquity images")
343 def test_filesystem_squashfs(self):344 def test_filesystem_squashfs(self):
344 logging.debug('Extracting the filesystem.squashfs')345 logging.debug('Extracting the filesystem.squashfs')
345 cmd = ["bsdtar", "-xf" , self.iso_location, "-C",346 cmd = ["bsdtar", "-xf", self.iso_location, "-C",
346 self.temp_dir, "casper/filesystem.squashfs"]347 self.temp_dir, "casper/filesystem.squashfs"]
347 output = subprocess.Popen(cmd, stdout = subprocess.PIPE,348 output = subprocess.Popen(cmd, stdout=subprocess.PIPE,
348 stderr = subprocess.PIPE)349 stderr=subprocess.PIPE)
349 (stdout, stderr) = output.communicate ()350 (stdout, stderr) = output.communicate()
350 logging.debug('Check for error in extracting filesystem.squashfs')351 logging.debug('Check for error in extracting filesystem.squashfs')
351 self.assertEqual(stderr, '')352 self.assertEqual(stderr, '')
352353
353 squashfs_path = os.path.join(self.temp_dir, 'casper/filesystem.squashfs')354 squashfs_path = os.path.join(self.temp_dir,
355 'casper/filesystem.squashfs')
354356
355 logging.debug('Checking the file is an actual .squashfs')357 logging.debug('Checking the file is an actual .squashfs')
356 cmd = ["file", squashfs_path]358 cmd = ["file", squashfs_path]
357 output = subprocess.Popen(cmd, stdout = subprocess.PIPE,359 output = subprocess.Popen(cmd, stdout=subprocess.PIPE,
358 stderr = subprocess.PIPE)360 stderr=subprocess.PIPE)
359 (stdout, stderr) = output.communicate ()361 (stdout, stderr) = output.communicate()
360 logging.debug('Check if signature contains \"Squashfs filesystem\"')362 logging.debug('Check if signature contains \"Squashfs filesystem\"')
361 self.assertEqual(stderr, '')363 self.assertEqual(stderr, '')
362 self.assertIn("Squashfs filesystem", stdout)364 self.assertIn("Squashfs filesystem", stdout)
@@ -369,7 +371,7 @@
369 #self.assertEqual(stderr, '')371 #self.assertEqual(stderr, '')
370 #self.assertIn("created 1 directories", stdout)372 #self.assertIn("created 1 directories", stdout)
371373
372 # Test if the report.html exists for the d-i based images 374 # Test if the report.html exists for the d-i based images
373 # and that it does not have any conflicting packages375 # and that it does not have any conflicting packages
374 @unittest.skipIf(ubiquity_image, "Skipping for ubiquity based images")376 @unittest.skipIf(ubiquity_image, "Skipping for ubiquity based images")
375 def test_report_html(self):377 def test_report_html(self):
@@ -392,10 +394,12 @@
392394
393 if(self.st_release == 'precise'):395 if(self.st_release == 'precise'):
394 # check if the size of the image fits a 703MB cd for precise396 # check if the size of the image fits a 703MB cd for precise
395 self.assertTrue(statinfo.st_size < PRECISE_SIZE_LIMIT_MB, "Size: %s" % (statinfo.st_size))397 self.assertTrue(statinfo.st_size < PRECISE_SIZE_LIMIT_MB,
398 "Size: %s" % (statinfo.st_size))
396 else:399 else:
397 # check if the size of the image fits a 800MB cd for quantal400 # check if the size of the image fits a 800MB cd for quantal
398 self.assertTrue(statinfo.st_size < QUANTAL_SIZE_LIMIT_MB, "Size: %s" % (statinfo.st_size))401 self.assertTrue(statinfo.st_size < QUANTAL_SIZE_LIMIT_MB,
402 "Size: %s" % (statinfo.st_size))
399403
400 # clean up404 # clean up
401 @classmethod405 @classmethod

Subscribers

People subscribed via source and target branches

to all changes: