223
223
self.addCleanup(mock_gmtime.stop)
224
224
self.epoch_date = "Thu Jan 1 00:00:00 UTC 1970"
226
@mock.patch("cdimage.sign.sign_cdimage")
226
227
@mock.patch("cdimage.osextras.fetch")
227
def test_livecd_base(self, mock_fetch):
228
def test_livecd_base(self, mock_fetch, mock_sign):
228
229
def fetch_side_effect(config, source, target):
229
230
tail = os.path.basename(target).split(".", 1)[1]
230
231
if tail in ("manifest", "squashfs"):
249
258
self.assertTrue(os.path.isdir(live_dir))
250
259
self.assertCountEqual(
251
["i386.manifest", "i386.squashfs"], os.listdir(live_dir))
260
["i386.manifest", "i386.squashfs", "i386.squashfs.gpg"],
261
os.listdir(live_dir))
253
263
@mock.patch("cdimage.osextras.fetch")
254
def test_ubuntu_core(self, mock_fetch):
264
def test_ubuntu_base(self, mock_fetch):
255
265
def fetch_side_effect(config, source, target):
256
266
if (target.endswith(".manifest") or
257
267
target.endswith(".rootfs.tar.gz")):
260
270
raise osextras.FetchError
262
272
mock_fetch.side_effect = fetch_side_effect
273
self.config["PROJECT"] = "ubuntu-base"
274
self.config["DIST"] = "raring"
275
self.config["IMAGE_TYPE"] = "daily"
276
self.config["ARCHES"] = "i386"
277
self.capture_logging()
278
build_livecd_base(self.config)
279
self.assertLogEqual([
280
"===== Downloading live filesystem images =====",
282
"===== Copying images to debian-cd output directory =====",
285
output_dir = os.path.join(
286
self.temp_dir, "scratch", "ubuntu-base", "raring", "daily",
288
self.assertTrue(os.path.isdir(output_dir))
289
self.assertCountEqual([
290
"raring-base-i386.manifest",
291
"raring-base-i386.raw",
292
"raring-base-i386.type",
293
], os.listdir(output_dir))
294
with open(os.path.join(output_dir, "raring-base-i386.type")) as f:
295
self.assertEqual("tar archive\n", f.read())
297
@mock.patch("cdimage.osextras.fetch")
298
def test_ubuntu_server_preinstalled_raspi2(self, mock_fetch):
299
def fetch_side_effect(config, source, target):
300
if (target.endswith(".manifest") or
301
target.endswith(".disk1.img.xz")):
304
raise osextras.FetchError
306
mock_fetch.side_effect = fetch_side_effect
307
self.config["CDIMAGE_PREINSTALLED"] = "1"
308
self.config["PROJECT"] = "ubuntu-server"
309
self.config["DIST"] = "xenial"
310
self.config["IMAGE_TYPE"] = "daily-preinstalled"
311
self.config["ARCHES"] = "armhf+raspi2"
312
self.capture_logging()
313
build_livecd_base(self.config)
314
self.assertLogEqual([
315
"===== Downloading live filesystem images =====",
317
"===== Copying images to debian-cd output directory =====",
320
output_dir = os.path.join(
321
self.temp_dir, "scratch", "ubuntu-server", "xenial",
322
"daily-preinstalled", "debian-cd", "armhf+raspi2")
323
self.assertTrue(os.path.isdir(output_dir))
324
self.assertCountEqual([
325
"xenial-preinstalled-server-armhf+raspi2.manifest",
326
"xenial-preinstalled-server-armhf+raspi2.raw",
327
"xenial-preinstalled-server-armhf+raspi2.type",
328
], os.listdir(output_dir))
330
@mock.patch("cdimage.osextras.fetch")
331
def test_ubuntu_core_raspi3(self, mock_fetch):
332
def fetch_side_effect(config, source, target):
333
if (target.endswith(".model-assertion") or
334
target.endswith(".manifest") or
335
target.endswith(".img.xz")):
338
raise osextras.FetchError
340
mock_fetch.side_effect = fetch_side_effect
341
self.config["CDIMAGE_LIVE"] = "1"
263
342
self.config["PROJECT"] = "ubuntu-core"
264
self.config["DIST"] = "raring"
265
self.config["IMAGE_TYPE"] = "daily"
266
self.config["ARCHES"] = "i386"
343
self.config["DIST"] = "xenial"
344
self.config["IMAGE_TYPE"] = "daily-live"
345
self.config["ARCHES"] = "armhf+raspi3"
267
346
self.capture_logging()
268
347
build_livecd_base(self.config)
269
348
self.assertLogEqual([
275
354
output_dir = os.path.join(
276
self.temp_dir, "scratch", "ubuntu-core", "raring", "daily",
355
self.temp_dir, "scratch", "ubuntu-core", "xenial",
356
"daily-live", "live")
278
357
self.assertTrue(os.path.isdir(output_dir))
279
358
self.assertCountEqual([
280
"raring-core-i386.manifest",
281
"raring-core-i386.raw",
282
"raring-core-i386.type",
359
"armhf+raspi3.img.xz",
360
"armhf+raspi3.model-assertion",
361
"armhf+raspi3.manifest",
283
362
], os.listdir(output_dir))
284
with open(os.path.join(output_dir, "raring-core-i386.type")) as f:
285
self.assertEqual("tar archive\n", f.read())
287
364
@mock.patch("cdimage.osextras.fetch")
288
def test_ubuntu_touch(self, mock_fetch):
365
def _perform_ubuntu_touch_testing(self, project, mock_fetch):
366
'''Convenience function for testing ubuntu-touch* builds.'''
289
367
def fetch_side_effect(config, source, target):
290
368
if (target.endswith(".manifest") or
291
369
target.endswith(".rootfs.tar.gz") or
312
390
output_dir = os.path.join(
313
self.temp_dir, "scratch", "ubuntu-touch", "saucy",
391
self.temp_dir, "scratch", project, "saucy",
314
392
"daily-preinstalled", "debian-cd", "armhf")
315
393
self.assertTrue(os.path.isdir(output_dir))
316
394
touch_files = ["saucy-preinstalled-boot-%s+%s.img" % (
344
422
self.assertTrue(os.path.exists(
345
423
os.path.join(output_dir, recovery_img)))
347
@mock.patch("cdimage.osextras.fetch")
348
def test_ubuntu_pd(self, mock_fetch):
349
def fetch_side_effect(config, source, target):
350
if (target.endswith(".manifest") or
351
target.endswith(".rootfs.tar.gz") or
352
target.endswith(".custom.tar.gz") or
353
target.endswith(".img")):
356
raise osextras.FetchError
425
def test_ubuntu_touch(self):
426
self._perform_ubuntu_touch_testing("ubuntu-touch")
358
mock_fetch.side_effect = fetch_side_effect
359
self.config["CDIMAGE_PREINSTALLED"] = "1"
360
self.config["PROJECT"] = "ubuntu-pd"
361
self.config["DIST"] = "vivid"
362
self.config["IMAGE_TYPE"] = "daily-preinstalled"
363
self.config["ARCHES"] = "armhf"
364
self.capture_logging()
365
build_livecd_base(self.config)
366
self.assertLogEqual([
367
"===== Downloading live filesystem images =====",
369
"===== Copying images to debian-cd output directory =====",
372
output_dir = os.path.join(
373
self.temp_dir, "scratch", "ubuntu-pd", "vivid",
374
"daily-preinstalled", "debian-cd", "armhf")
375
self.assertTrue(os.path.isdir(output_dir))
376
touch_files = ["vivid-preinstalled-boot-%s+%s.img" % (
377
touch_target.ubuntu_arch, touch_target.subarch)
378
for touch_target in Touch.list_targets_by_ubuntu_arch("armhf")]
379
touch_files.extend(["vivid-preinstalled-recovery-%s+%s.img" % (
380
touch_target.android_arch, touch_target.subarch)
381
for touch_target in Touch.list_targets_by_ubuntu_arch("armhf")])
382
touch_files.extend(["vivid-preinstalled-system-%s+%s.img" % (
383
touch_target.android_arch, touch_target.subarch)
384
for touch_target in Touch.list_targets_by_ubuntu_arch("armhf")])
386
"vivid-preinstalled-pd-armhf.manifest",
387
"vivid-preinstalled-pd-armhf.raw",
388
"vivid-preinstalled-pd-armhf.type",
389
"vivid-preinstalled-pd-armhf.tar.gz",
390
"vivid-preinstalled-pd-armhf.custom.tar.gz",
392
self.assertCountEqual(touch_files, os.listdir(output_dir))
393
with open(os.path.join(
394
output_dir, "vivid-preinstalled-pd-armhf.type")
396
self.assertEqual("tar archive\n", f.read())
397
for touch_target in Touch.list_targets_by_ubuntu_arch("armhf"):
398
system_img = "vivid-preinstalled-system-%s+%s.img" % (
399
touch_target.android_arch, touch_target.subarch)
400
recovery_img = "vivid-preinstalled-recovery-%s+%s.img" % (
401
touch_target.android_arch, touch_target.subarch)
402
self.assertTrue(os.path.exists(
403
os.path.join(output_dir, system_img)))
404
self.assertTrue(os.path.exists(
405
os.path.join(output_dir, recovery_img)))
428
def test_ubuntu_touch_custom(self):
429
self._perform_ubuntu_touch_testing("ubuntu-touch-custom")
407
431
@mock.patch("cdimage.osextras.fetch")
408
432
def test_ubuntu_desktop_next_system_image(self, mock_fetch):
546
570
("lubuntu", "raring", False, True),
547
571
("ubuntukylin", "raring", False, True),
548
572
("ubuntu-gnome", "raring", False, True),
573
("ubuntu-budgie", "zesty", False, True),
549
574
("ubuntu-mate", "vivid", False, True),
550
575
("ubuntu-moblin-remix", "raring", False, True),
551
576
("ubuntu-desktop-next", "utopic", False, False),
727
752
mock.call(expected_rsync_base + [
728
753
"--exclude", "Packages*", "--exclude", "Sources*",
729
754
"--exclude", "Release*", "--exclude", "InRelease",
755
"--include", "i18n/by-hash/**", "--exclude", "i18n/*",
730
756
"--exclude", "foo",
731
757
"rsync.example.org::ubuntu/", "%s/" % target,
732
758
], stdout=mock.ANY, stderr=subprocess.STDOUT, env=mock.ANY),
1205
1231
self.config["IMAGE_TYPE"] = "daily"
1206
1232
lock_path = os.path.join(
1207
1233
self.temp_dir, "etc", ".lock-build-image-set-ubuntu-raring-daily")
1208
semaphore_path = os.path.join(
1209
self.temp_dir, "etc", ".sem-build-image-set")
1234
multipidfile_path = os.path.join(
1235
self.temp_dir, "etc", ".build-image-set-pids")
1210
1236
os.makedirs(os.path.dirname(lock_path))
1211
1237
self.assertRaises(
1212
1238
KeyboardInterrupt, build_image_set, self.config, None)
1213
1239
self.assertFalse(os.path.exists(lock_path))
1214
self.assertFalse(os.path.exists(semaphore_path))
1240
self.assertFalse(os.path.exists(multipidfile_path))
1216
1242
@mock.patch("cdimage.build.build_image_set_locked")
1217
1243
def test_build_image_set_terminated(self, mock_build_image_set_locked):
1220
1246
self.config["IMAGE_TYPE"] = "daily"
1221
1247
lock_path = os.path.join(
1222
1248
self.temp_dir, "etc", ".lock-build-image-set-ubuntu-raring-daily")
1223
semaphore_path = os.path.join(
1224
self.temp_dir, "etc", ".sem-build-image-set")
1249
multipidfile_path = os.path.join(
1250
self.temp_dir, "etc", ".build-image-set-pids")
1225
1251
os.makedirs(os.path.dirname(lock_path))
1227
def side_effect(config, options, semaphore_state):
1253
def side_effect(config, options, multipidfile_state):
1228
1254
os.kill(os.getpid(), signal.SIGTERM)
1230
1256
mock_build_image_set_locked.side_effect = side_effect
1243
1269
self.config["IMAGE_TYPE"] = "daily"
1244
1270
lock_path = os.path.join(
1245
1271
self.temp_dir, "etc", ".lock-build-image-set-ubuntu-raring-daily")
1246
semaphore_path = os.path.join(
1247
self.temp_dir, "etc", ".sem-build-image-set")
1272
multipidfile_path = os.path.join(
1273
self.temp_dir, "etc", ".build-image-set-pids")
1248
1274
os.makedirs(os.path.dirname(lock_path))
1250
def side_effect(config, options, semaphore_state):
1276
def side_effect(config, options, multipidfile_state):
1251
1277
self.assertTrue(os.path.exists(lock_path))
1252
1278
self.assertIsNone(options)
1253
self.assertEqual(0, semaphore_state)
1254
with open(semaphore_path) as semaphore:
1255
self.assertEqual("1\n", semaphore.read())
1279
self.assertEqual(set(), multipidfile_state)
1280
with open(multipidfile_path) as multipidfile:
1281
self.assertEqual("%d\n" % os.getpid(), multipidfile.read())
1257
1283
mock_build_image_set_locked.side_effect = side_effect
1258
1284
build_image_set(self.config, None)