def test_mkemptydir_previously_populated(self): new_dir = os.path.join(self.temp_dir, "dir") os.mkdir(new_dir) touch(os.path.join(new_dir, "file")) osextras.mkemptydir(new_dir) self.assertTrue(os.path.isdir(new_dir)) self.assertEqual([], os.listdir(new_dir))
def test_manifest_file_allowed_fails_bad_extensions(self): paths = [ os.path.join(self.temp_dir, name) for name in ("foo.txt", "foo")] for path in paths: touch(path) self.assertFalse(self.tree.manifest_file_allowed(path))
def test_diff_tasks(self, mock_call): self.write_ubuntu_structure() self.config["PROJECT"] = "ubuntu" self.config["DIST"] = "raring" self.config["IMAGE_TYPE"] = "daily-live" output_dir = os.path.join( self.temp_dir, "scratch", "ubuntu", "raring", "daily-live", "tasks") touch(os.path.join(output_dir, "required")) touch(os.path.join(output_dir, "minimal")) touch(os.path.join(output_dir, "standard")) touch(os.path.join("%s-previous" % output_dir, "minimal")) touch(os.path.join("%s-previous" % output_dir, "standard")) output = GerminateOutput(self.config, self.temp_dir) output.diff_tasks() self.assertEqual(2, mock_call.call_count) mock_call.assert_has_calls([ mock.call([ "diff", "-u", os.path.join("%s-previous" % output_dir, "minimal"), os.path.join(output_dir, "minimal")]), mock.call([ "diff", "-u", os.path.join("%s-previous" % output_dir, "standard"), os.path.join(output_dir, "standard")]), ])
def test_checksum_directory(self): old_dir = os.path.join(self.temp_dir, "old") old_iso_hppa_path = os.path.join(old_dir, "foo-hppa.raw") with mkfile(old_iso_hppa_path) as old_iso_hppa: print("foo-hppa.raw", end="", file=old_iso_hppa) old_iso_i386_path = os.path.join(old_dir, "foo-i386.raw") with mkfile(old_iso_i386_path) as old_iso_i386: print("foo-i386.raw", end="", file=old_iso_i386) self.create_checksum_files(["foo-hppa.raw", "foo-i386.raw"], directory=old_dir) iso_amd64_path = os.path.join(self.temp_dir, "foo-amd64.iso") with mkfile(iso_amd64_path) as iso_amd64: print("foo-amd64.iso", end="", file=iso_amd64) touch(os.path.join(self.temp_dir, "foo-amd64.list")) shutil.copy(old_iso_hppa_path, os.path.join(self.temp_dir, "foo-hppa.iso")) shutil.copy(old_iso_i386_path, os.path.join(self.temp_dir, "foo-i386.iso")) checksum_directory(self.config, self.temp_dir, old_directories=[old_dir], sign=False, map_expr=r"s/\.iso$/.raw/") with open(os.path.join(self.temp_dir, "SHA256SUMS")) as sha256sums: digests = ( hashlib.sha256(b"foo-amd64.iso").hexdigest(), hashlib.sha256(b"foo-hppa.raw").hexdigest(), hashlib.sha256(b"foo-i386.raw").hexdigest(), ) self.assertEqual( dedent("""\ %s *foo-amd64.iso %s *foo-hppa.iso %s *foo-i386.iso """) % digests, sha256sums.read())
def test_sign_cdimage_configured(self, mock_check_call): config = Config(read=False) config["GNUPG_DIR"] = self.use_temp_dir() config["SIGNING_KEYID"] = "01234567" gpgdir, gpgconf, secring, privkeydir, pubring, trustdb = \ _gnupg_files(config) sign_path = os.path.join(self.temp_dir, "to-sign") for path in gpgconf, secring, pubring, trustdb, sign_path: touch(path) self.capture_logging() self.assertTrue(sign_cdimage(config, sign_path)) self.assertLogEqual([]) expected_command = [ "gpg", "--options", gpgconf, "--homedir", config["GNUPG_DIR"], "--no-options", "--batch", "--no-tty", "--armour", "--detach-sign", "--digest-algo", "SHA512", "-u", "01234567", ] mock_check_call.assert_called_once_with( expected_command, stdin=mock.ANY, stdout=mock.ANY) call = mock_check_call.call_args self.assertEqual(sign_path, call[1]["stdin"].name) self.assertEqual("%s.gpg" % sign_path, call[1]["stdout"].name)
def test_merge_all(self): old_dir = os.path.join(self.temp_dir, "old") os.mkdir(old_dir) old_iso_hppa_path = os.path.join(self.temp_dir, "old", "foo-hppa.raw") with open(old_iso_hppa_path, "w") as old_iso_hppa: print("foo-hppa.raw", end="", file=old_iso_hppa) old_iso_i386_path = os.path.join(self.temp_dir, "old", "foo-i386.raw") with open(old_iso_i386_path, "w") as old_iso_i386: print("foo-i386.raw", end="", file=old_iso_i386) self.create_checksum_files( ["foo-hppa.raw", "foo-i386.raw"], directory=old_dir) iso_amd64_path = os.path.join(self.temp_dir, "foo-amd64.iso") with open(iso_amd64_path, "w") as iso_amd64: print("foo-amd64.iso", end="", file=iso_amd64) touch(os.path.join(self.temp_dir, "foo-amd64.list")) shutil.copy( old_iso_hppa_path, os.path.join(self.temp_dir, "foo-hppa.iso")) shutil.copy( old_iso_i386_path, os.path.join(self.temp_dir, "foo-i386.iso")) checksum_files = self.cls(self.config, self.temp_dir) checksum_files.merge_all([old_dir], map_expr=r"s/\.iso$/.raw/") self.assertChecksumsEqual({ "foo-amd64.iso": "foo-amd64.iso", "foo-hppa.iso": "foo-hppa.raw", "foo-i386.iso": "foo-i386.raw", }, checksum_files)
def test_checksum_directory(self): old_dir = os.path.join(self.temp_dir, "old") old_iso_i386_path = os.path.join(old_dir, "foo-i386.iso") with mkfile(old_iso_i386_path) as old_iso_i386: print("foo-i386.iso", end="", file=old_iso_i386) old_metalink_i386_path = os.path.join(old_dir, "foo-i386.metalink") with mkfile(old_metalink_i386_path) as old_metalink_i386: print("foo-i386.metalink", end="", file=old_metalink_i386) self.create_checksum_files(["foo-i386.metalink"], directory=old_dir) metalink_amd64_path = os.path.join(self.temp_dir, "foo-amd64.metalink") with mkfile(metalink_amd64_path) as metalink_amd64: print("foo-amd64.metalink", end="", file=metalink_amd64) touch(os.path.join(self.temp_dir, "foo-amd64.list")) shutil.copy(old_metalink_i386_path, os.path.join(self.temp_dir, "foo-i386.metalink")) metalink_checksum_directory(self.config, self.temp_dir, old_directories=[old_dir], sign=False) with open(os.path.join(self.temp_dir, "MD5SUMS-metalink")) as md5sums: digests = ( hashlib.md5(b"foo-amd64.metalink").hexdigest(), hashlib.md5(b"foo-i386.metalink").hexdigest(), ) self.assertEqual( dedent("""\ %s *foo-amd64.metalink %s *foo-i386.metalink """) % digests, md5sums.read())
def test_fetch_url_removes_target_on_failure(self, *args): config = Config(read=False) target = os.path.join(self.temp_dir, "target") touch(target) self.assertRaises(osextras.FetchError, osextras.fetch, config, "http://example.org/source", target) self.assertFalse(os.path.exists(target))
def test_checksum_directory(self): old_dir = os.path.join(self.temp_dir, "old") os.mkdir(old_dir) old_iso_hppa_path = os.path.join(self.temp_dir, "old", "foo-hppa.raw") with open(old_iso_hppa_path, "w") as old_iso_hppa: print("foo-hppa.raw", end="", file=old_iso_hppa) old_iso_i386_path = os.path.join(self.temp_dir, "old", "foo-i386.raw") with open(old_iso_i386_path, "w") as old_iso_i386: print("foo-i386.raw", end="", file=old_iso_i386) self.create_checksum_files( ["foo-hppa.raw", "foo-i386.raw"], directory=old_dir) iso_amd64_path = os.path.join(self.temp_dir, "foo-amd64.iso") with open(iso_amd64_path, "w") as iso_amd64: print("foo-amd64.iso", end="", file=iso_amd64) touch(os.path.join(self.temp_dir, "foo-amd64.list")) shutil.copy( old_iso_hppa_path, os.path.join(self.temp_dir, "foo-hppa.iso")) shutil.copy( old_iso_i386_path, os.path.join(self.temp_dir, "foo-i386.iso")) checksum_directory( self.config, self.temp_dir, old_directories=[old_dir], map_expr=r"s/\.iso$/.raw/") with open(os.path.join(self.temp_dir, "MD5SUMS")) as md5sums: digests = ( hashlib.md5("foo-amd64.iso").hexdigest(), hashlib.md5("foo-hppa.raw").hexdigest(), hashlib.md5("foo-i386.raw").hexdigest(), ) self.assertEqual(dedent("""\ %s *foo-amd64.iso %s *foo-hppa.iso %s *foo-i386.iso """) % digests, md5sums.read())
def test_checksum_directory(self): old_dir = os.path.join(self.temp_dir, "old") os.mkdir(old_dir) old_iso_i386_path = os.path.join(self.temp_dir, "old", "foo-i386.iso") with open(old_iso_i386_path, "w") as old_iso_i386: print("foo-i386.iso", end="", file=old_iso_i386) old_metalink_i386_path = os.path.join( self.temp_dir, "old", "foo-i386.metalink") with open(old_metalink_i386_path, "w") as old_metalink_i386: print("foo-i386.metalink", end="", file=old_metalink_i386) self.create_checksum_files( ["foo-i386.metalink"], directory=old_dir) metalink_amd64_path = os.path.join(self.temp_dir, "foo-amd64.metalink") with open(metalink_amd64_path, "w") as metalink_amd64: print("foo-amd64.metalink", end="", file=metalink_amd64) touch(os.path.join(self.temp_dir, "foo-amd64.list")) shutil.copy( old_metalink_i386_path, os.path.join(self.temp_dir, "foo-i386.metalink")) metalink_checksum_directory( self.config, self.temp_dir, old_directories=[old_dir]) with open(os.path.join(self.temp_dir, "MD5SUMS-metalink")) as md5sums: digests = ( hashlib.md5("foo-amd64.metalink").hexdigest(), hashlib.md5("foo-i386.metalink").hexdigest(), ) self.assertEqual(dedent("""\ %s *foo-amd64.metalink %s *foo-i386.metalink """) % digests, md5sums.read())
def test_path_to_manifest(self): iso = "kubuntu/hoary-install-i386.iso" iso_path = os.path.join(self.temp_dir, iso) os.makedirs(os.path.dirname(iso_path)) touch(iso_path) self.assertEqual( "kubuntu\thoary\t/%s\t0" % iso, self.tree.path_to_manifest(iso))
def test_merge_all(self): old_dir = os.path.join(self.temp_dir, "old") os.mkdir(old_dir) old_iso_i386_path = os.path.join(self.temp_dir, "old", "foo-i386.iso") with open(old_iso_i386_path, "w") as old_iso_i386: print("foo-i386.iso", end="", file=old_iso_i386) old_metalink_i386_path = os.path.join( self.temp_dir, "old", "foo-i386.metalink") with open(old_metalink_i386_path, "w") as old_metalink_i386: print("foo-i386.metalink", end="", file=old_metalink_i386) self.create_checksum_files( ["foo-i386.metalink"], directory=old_dir) metalink_amd64_path = os.path.join(self.temp_dir, "foo-amd64.metalink") with open(metalink_amd64_path, "w") as metalink_amd64: print("foo-amd64.metalink", end="", file=metalink_amd64) touch(os.path.join(self.temp_dir, "foo-amd64.list")) shutil.copy( old_metalink_i386_path, os.path.join(self.temp_dir, "foo-i386.metalink")) checksum_files = self.cls(self.config, self.temp_dir) checksum_files.merge_all([old_dir]) self.assertChecksumsEqual({ "foo-amd64.metalink": "foo-amd64.metalink", "foo-i386.metalink": "foo-i386.metalink", }, checksum_files)
def test_link_present(self): source = os.path.join(self.temp_dir, "source") touch(source) target = os.path.join(self.temp_dir, "target") touch(target) osextras.link_force(source, target) self.assertEqual(os.stat(source), os.stat(target))
def test_find_on_path_present_executable(self): bin_dir = os.path.join(self.temp_dir, "bin") program = os.path.join(bin_dir, "program") touch(program) os.chmod(program, 0o755) os.environ["PATH"] = bin_dir self.assertTrue(osextras.find_on_path("program"))
def test_merge_all(self): old_dir = os.path.join(self.temp_dir, "old") old_iso_hppa_path = os.path.join(old_dir, "foo-hppa.raw") with mkfile(old_iso_hppa_path) as old_iso_hppa: print("foo-hppa.raw", end="", file=old_iso_hppa) old_iso_i386_path = os.path.join(old_dir, "foo-i386.raw") with mkfile(old_iso_i386_path) as old_iso_i386: print("foo-i386.raw", end="", file=old_iso_i386) self.create_checksum_files(["foo-hppa.raw", "foo-i386.raw"], directory=old_dir) iso_amd64_path = os.path.join(self.temp_dir, "foo-amd64.iso") with mkfile(iso_amd64_path) as iso_amd64: print("foo-amd64.iso", end="", file=iso_amd64) touch(os.path.join(self.temp_dir, "foo-amd64.list")) shutil.copy(old_iso_hppa_path, os.path.join(self.temp_dir, "foo-hppa.iso")) shutil.copy(old_iso_i386_path, os.path.join(self.temp_dir, "foo-i386.iso")) checksum_files = self.cls(self.config, self.temp_dir) checksum_files.merge_all([old_dir], map_expr=r"s/\.iso$/.raw/") self.assertChecksumsEqual( { "foo-amd64.iso": b"foo-amd64.iso", "foo-hppa.iso": b"foo-hppa.raw", "foo-i386.iso": b"foo-i386.raw", }, checksum_files)
def test_output(self): self.config.root = self.use_temp_dir() self.config["DIST"] = "precise" output_dir = self.germination.output_dir("ubuntu") touch(os.path.join(output_dir, "STRUCTURE")) output = self.germination.output("ubuntu") self.assertEqual(self.config, output.config) self.assertEqual(output_dir, output.directory)
def test_fetch_file(self): config = Config(read=False) source = os.path.join(self.temp_dir, "source") touch(source) target = os.path.join(self.temp_dir, "target") osextras.fetch(config, source, target) self.assertTrue(os.path.exists(target)) self.assertEqual(os.stat(target), os.stat(source))
def test_manifest_files_includes_current(self): daily = os.path.join(self.temp_dir, "daily") os.makedirs(os.path.join(daily, "20120806")) os.symlink("20120806", os.path.join(daily, "current")) touch(os.path.join(daily, "20120806", "warty-install-i386.iso")) self.assertEqual( ["daily/current/warty-install-i386.iso"], list(self.tree.manifest_files()))
def test_find_on_path_present_not_executable(self): bin_dir = os.path.join(self.temp_dir, "bin") os.mkdir(bin_dir) program = os.path.join(bin_dir, "program") touch(program) with EnvironmentVarGuard() as env: env["PATH"] = bin_dir self.assertFalse(osextras.find_on_path("program"))
def test_new_publish_dir_skips_different_series(self): publisher = self.make_publisher("ubuntu", "daily") publish_current = os.path.join(publisher.publish_base, "current") osextras.ensuredir(publish_current) image = "warty-alternate-i386.iso" touch(os.path.join(publish_current, image)) publisher.new_publish_dir("20120807") self.assertEqual( [], os.listdir(os.path.join(publisher.publish_base, "20120807")))
def test_sign_cdimage_missing_signing_keyid(self): config = Config(read=False) self.use_temp_dir() for tail in "secring.gpg", "pubring.gpg", "trustdb.gpg": touch(os.path.join(self.temp_dir, tail)) config["GNUPG_DIR"] = self.temp_dir self.capture_logging() self.assertFalse(sign_cdimage(config, "dummy")) self.assertLogEqual(["No keys found; not signing images."])
def test_merge_takes_other_names(self): old_dir = os.path.join(self.temp_dir, "old") touch(os.path.join(self.temp_dir, "entry")) with mkfile(os.path.join(old_dir, "MD5SUMS")) as old_md5sums: print("checksum *other-entry", file=old_md5sums) checksum_file = ChecksumFile(self.config, self.temp_dir, "MD5SUMS", hashlib.md5) checksum_file.merge([old_dir], "entry", ["other-entry"]) self.assertEqual({"entry": "checksum"}, checksum_file.entries)
def test_manifest_file_allowed_passes_good_extensions(self): paths = [ os.path.join(self.temp_dir, name) for name in ( "foo.iso", "foo.img", "foo.img.gz", "foo.tar.gz", "foo.tar.xz", )] for path in paths: touch(path) self.assertTrue(self.tree.manifest_file_allowed(path))
def test_notify_addresses_path(self): self.assertIsNone(_notify_addresses_path(self.config)) path = os.path.join(self.temp_dir, "etc", "notify-addresses") touch(path) self.assertEqual(path, _notify_addresses_path(self.config)) path = os.path.join(self.temp_dir, "production", "notify-addresses") touch(path) self.assertEqual(path, _notify_addresses_path(self.config))
def test_new_publish_dir_honours_no_copy(self): self.config["CDIMAGE_NOCOPY"] = "1" publisher = self.make_publisher("ubuntu", "daily") publish_current = os.path.join(publisher.publish_base, "current") osextras.ensuredir(publish_current) touch(os.path.join( publish_current, "%s-alternate-i386.iso" % self.config.series)) publisher.new_publish_dir("20120807") self.assertEqual( [], os.listdir(os.path.join(publisher.publish_base, "20120807")))
def test_new_publish_dir_copies_same_series(self): publisher = self.make_publisher("ubuntu", "daily") publish_current = os.path.join(publisher.publish_base, "current") osextras.ensuredir(publish_current) image = "%s-alternate-i386.iso" % self.config.series touch(os.path.join(publish_current, image)) publisher.new_publish_dir("20120807") self.assertEqual( [image], os.listdir(os.path.join(publisher.publish_base, "20120807")))
def test_merge_takes_other_names(self): old_dir = os.path.join(self.temp_dir, "old") os.mkdir(old_dir) touch(os.path.join(self.temp_dir, "entry")) with open(os.path.join(old_dir, "MD5SUMS"), "w") as old_md5sums: print("checksum *other-entry", file=old_md5sums) checksum_file = ChecksumFile( self.config, self.temp_dir, "MD5SUMS", hashlib.md5) checksum_file.merge([old_dir], "entry", ["other-entry"]) self.assertEqual({"entry": "checksum"}, checksum_file.entries)
def test_germinate_arch(self, mock_check_call): self.config.root = self.use_temp_dir() germinate_path = os.path.join(self.temp_dir, "germinate", "bin", "germinate") touch(germinate_path) os.chmod(germinate_path, 0o755) self.config["DIST"] = "trusty" self.config["IMAGE_TYPE"] = "daily" output_dir = "%s/scratch/ubuntu/trusty/daily/germinate" % self.temp_dir expected_files = [] for dist in "trusty", "trusty-security", "trusty-updates": for suffix in ( "binary-amd64/Packages.gz", "source/Sources.gz", "debian-installer/binary-amd64/Packages.gz", ): for component in "main", "restricted": path = os.path.join(self.temp_dir, "ftp", "dists", dist, component, suffix) os.makedirs(os.path.dirname(path)) with gzip.GzipFile(path, "wb"): pass expected_files.append( os.path.join(output_dir, "dists", dist, "main", suffix)) def check_call_side_effect(*args, **kwargs): touch(os.path.join(output_dir, "amd64+mac", "structure")) mock_check_call.side_effect = check_call_side_effect self.germination.germinate_arch("ubuntu", "amd64+mac") for expected_file in expected_files: self.assertTrue(os.path.exists(expected_file)) expected_command = [ germinate_path, "--seed-source", "https://git.launchpad.net/~ubuntu-core-dev/ubuntu-seeds/+git/", "--mirror", "file://%s/" % output_dir, "--seed-dist", "ubuntu.trusty", "--dist", "trusty,trusty-security,trusty-updates", "--arch", "amd64", "--components", "main", "--no-rdepends", "--vcs=auto", ] self.assertEqual(1, mock_check_call.call_count) self.assertEqual(expected_command, mock_check_call.call_args[0][0]) self.assertEqual("%s/amd64+mac" % output_dir, mock_check_call.call_args[1]["cwd"])
def check_manifest_pass(self): config = Config(read=False) config.root = self.use_temp_dir() manifest = os.path.join(self.temp_dir, "www", "simple", ".manifest") with mkfile(manifest) as f: print( "ubuntu\tprecise\t/precise/ubuntu-12.04.2-desktop-i386.iso\t" "726970368", file=f) touch( os.path.join(self.temp_dir, "www", "simple", "precise", "ubuntu-12.04.2-desktop-i386.iso"))
def test_merge_ignores_stale_checksums(self): old_dir = os.path.join(self.temp_dir, "old") with mkfile(os.path.join(old_dir, "MD5SUMS")) as old_md5sums: print("checksum *entry", file=old_md5sums) entry_path = os.path.join(self.temp_dir, "entry") touch(entry_path) next_minute = time.time() + 60 os.utime(entry_path, (next_minute, next_minute)) checksum_file = ChecksumFile(self.config, self.temp_dir, "MD5SUMS", hashlib.md5) checksum_file.merge([old_dir], "entry", ["entry"]) self.assertEqual({}, checksum_file.entries)
def test_manifest_files_prefers_non_pool(self): pool = os.path.join(self.temp_dir, ".pool") os.mkdir(pool) touch(os.path.join(pool, "ubuntu-4.10-install-i386.iso")) dist = os.path.join(self.temp_dir, "warty") os.mkdir(dist) os.symlink( os.path.join(os.pardir, ".pool", "ubuntu-4.10-install-i386.iso"), os.path.join(dist, "ubuntu-4.10-install-i386.iso")) self.assertEqual( ["warty/ubuntu-4.10-install-i386.iso"], list(self.tree.manifest_files()))
def test_merge_ignores_stale_checksums(self): old_dir = os.path.join(self.temp_dir, "old") os.mkdir(old_dir) with open(os.path.join(old_dir, "MD5SUMS"), "w") as old_md5sums: print("checksum *entry", file=old_md5sums) entry_path = os.path.join(self.temp_dir, "entry") touch(entry_path) next_minute = time.time() + 60 os.utime(entry_path, (next_minute, next_minute)) checksum_file = ChecksumFile( self.config, self.temp_dir, "MD5SUMS", hashlib.md5) checksum_file.merge([old_dir], "entry", ["entry"]) self.assertEqual({}, checksum_file.entries)
def test_update_tasks_no_recipients(self, mock_diff_tasks, mock_send_mail): self.write_ubuntu_structure() self.config["PROJECT"] = "ubuntu" self.config["DIST"] = "raring" self.config["IMAGE_TYPE"] = "daily-live" output = GerminateOutput(self.config, self.temp_dir) os.makedirs(output.tasks_output_dir("ubuntu")) output.update_tasks("20130319") self.assertEqual(0, mock_send_mail.call_count) task_mail_path = os.path.join(self.temp_dir, "etc", "task-mail") touch(task_mail_path) output.update_tasks("20130319") self.assertEqual(0, mock_send_mail.call_count)
def test_manifest(self): daily = os.path.join(self.temp_dir, "daily") os.makedirs(os.path.join(daily, "20120806")) os.symlink("20120806", os.path.join(daily, "current")) touch(os.path.join(daily, "20120806", "hoary-install-i386.iso")) daily_live = os.path.join(self.temp_dir, "daily-live") os.makedirs(os.path.join(daily_live, "20120806")) os.symlink("20120806", os.path.join(daily_live, "current")) touch(os.path.join(daily_live, "20120806", "hoary-live-i386.iso")) self.assertEqual([ "ubuntu\thoary\t/daily-live/current/hoary-live-i386.iso\t0", "ubuntu\thoary\t/daily/current/hoary-install-i386.iso\t0", ], self.tree.manifest())
def test_sign_cdimage_subprocess_error(self, mock_check_call): mock_check_call.side_effect = subprocess.CalledProcessError(1, "") config = Config(read=False) config["GNUPG_DIR"] = self.use_temp_dir() config["SIGNING_KEYID"] = "01234567" gpgconf, secring, pubring, trustdb = _gnupg_files(config) sign_path = os.path.join(self.temp_dir, "to-sign") for path in gpgconf, secring, pubring, trustdb, sign_path: touch(path) touch("%s.gpg" % sign_path) self.capture_logging() self.assertRaises(subprocess.CalledProcessError, sign_cdimage, config, sign_path) self.assertLogEqual([]) self.assertFalse(os.path.exists("%s.gpg" % sign_path))
def test_merge_handles_symlinks(self): old_dir = os.path.join(self.temp_dir, "old") touch(os.path.join(old_dir, "entry")) with mkfile(os.path.join(old_dir, "MD5SUMS")) as old_md5sums: print("correct-checksum *entry", file=old_md5sums) new_dir = os.path.join(self.temp_dir, "new") os.mkdir(new_dir) os.symlink(os.path.join(os.pardir, "old", "entry"), os.path.join(new_dir, "entry")) with mkfile(os.path.join(new_dir, "MD5SUMS")) as new_md5sums: print("wrong-checksum *entry", file=new_md5sums) checksum_file = ChecksumFile(self.config, new_dir, "MD5SUMS", hashlib.md5) checksum_file.merge([new_dir, old_dir], "entry", ["entry"]) self.assertEqual({"entry": "correct-checksum"}, checksum_file.entries)
def test_update_tasks_sends_mail(self, mock_send_mail): original_call = subprocess.call def call_side_effect(command, *args, **kwargs): if (len(command) >= 4 and command[:2] == ["diff", "-u"] and "stdout" in kwargs): old = os.path.basename(command[2]) new = os.path.basename(command[3]) original_call( ["printf", "%s\\n", "--- %s" % old], *args, **kwargs) original_call( ["printf", "%s\\n", "+++ %s" % new], *args, **kwargs) return 1 else: return original_call(command, *args, **kwargs) self.write_ubuntu_structure() self.config["PROJECT"] = "ubuntu" self.config["CAPPROJECT"] = "Ubuntu" self.config["DIST"] = "raring" self.config["IMAGE_TYPE"] = "daily-live" output_dir = os.path.join( self.temp_dir, "scratch", "ubuntu", "raring", "daily-live", "tasks") touch(os.path.join(output_dir, "required")) touch(os.path.join(output_dir, "minimal")) touch(os.path.join(output_dir, "standard")) touch(os.path.join("%s-previous" % output_dir, "minimal")) touch(os.path.join("%s-previous" % output_dir, "standard")) task_mail_path = os.path.join(self.temp_dir, "etc", "task-mail") with mkfile(task_mail_path) as task_mail: print("*****@*****.**", file=task_mail) mock_send_mail.side_effect = partial( self.send_mail_to_file, os.path.join(self.temp_dir, "mail")) output = GerminateOutput(self.config, self.temp_dir) with mock.patch("subprocess.call", side_effect=call_side_effect): output.update_tasks("20130319") with open(os.path.join(self.temp_dir, "mail")) as mail: self.assertEqual(dedent("""\ To: [email protected] Subject: Task changes for Ubuntu daily-live/raring on 20130319 X-Generated-By: update-tasks --- minimal +++ minimal --- standard +++ standard """), mail.read())
def test_germinate_path(self): self.config.root = self.use_temp_dir() self.assertRaises( GerminateNotInstalled, getattr, self.germination, "germinate_path") germinate_dir = os.path.join(self.temp_dir, "germinate") old_germinate = os.path.join(germinate_dir, "germinate.py") touch(old_germinate) os.chmod(old_germinate, 0o755) self.assertEqual(old_germinate, self.germination.germinate_path) new_germinate = os.path.join(germinate_dir, "bin", "germinate") touch(new_germinate) os.chmod(new_germinate, 0o755) self.assertEqual(new_germinate, self.germination.germinate_path)
def test_manifest(self): pool = os.path.join(self.temp_dir, "kubuntu", ".pool") os.makedirs(pool) touch(os.path.join(pool, "kubuntu-5.04-install-i386.iso")) touch(os.path.join(pool, "kubuntu-5.04-live-i386.iso")) dist = os.path.join(self.temp_dir, "kubuntu", "hoary") os.makedirs(dist) os.symlink( os.path.join(os.pardir, ".pool", "kubuntu-5.04-install-i386.iso"), os.path.join(dist, "kubuntu-5.04-install-i386.iso")) os.symlink( os.path.join(os.pardir, ".pool", "kubuntu-5.04-live-i386.iso"), os.path.join(dist, "kubuntu-5.04-live-i386.iso")) self.assertEqual([ "kubuntu\thoary\t/kubuntu/hoary/kubuntu-5.04-install-i386.iso\t0", "kubuntu\thoary\t/kubuntu/hoary/kubuntu-5.04-live-i386.iso\t0", ], self.tree.manifest())
def test_update_tasks_no_mail(self, mock_diff_tasks): self.write_ubuntu_structure() self.config["PROJECT"] = "ubuntu" self.config["DIST"] = "trusty" self.config["IMAGE_TYPE"] = "daily-live" output_dir = os.path.join(self.temp_dir, "scratch", "ubuntu", "trusty", "daily-live", "tasks") touch(os.path.join(output_dir, "required")) touch(os.path.join(output_dir, "minimal")) output = GerminateOutput(self.config, self.temp_dir) output.update_tasks("20130319") self.assertCountEqual(["required", "minimal"], os.listdir( os.path.join(self.temp_dir, "debian-cd", "tasks", "auto", "daily-live", "ubuntu", "trusty"))) self.assertCountEqual(["required", "minimal"], os.listdir("%s-previous" % output_dir))
def test_publish_binary(self): publisher = self.make_publisher( "ubuntu", "daily-live", try_zsyncmake=False) source_dir = os.path.join(publisher.image_output, "i386") os.mkdir(source_dir) touch(os.path.join( source_dir, "%s-desktop-i386.raw" % self.config.series)) touch(os.path.join( source_dir, "%s-desktop-i386.list" % self.config.series)) touch(os.path.join( source_dir, "%s-desktop-i386.manifest" % self.config.series)) self.capture_logging() list(publisher.publish_binary("desktop", "i386", "20120807")) self.assertLogEqual([ "Publishing i386 ...", "Unknown file type 'empty'; assuming .iso", "Publishing i386 live manifest ...", ]) target_dir = os.path.join(publisher.publish_base, "20120807") self.assertEqual([], os.listdir(source_dir)) self.assertEqual([ "%s-desktop-i386.iso" % self.config.series, "%s-desktop-i386.list" % self.config.series, "%s-desktop-i386.manifest" % self.config.series, ], sorted(os.listdir(target_dir)))
def test_merge_all(self): old_dir = os.path.join(self.temp_dir, "old") old_iso_i386_path = os.path.join(old_dir, "foo-i386.iso") with mkfile(old_iso_i386_path) as old_iso_i386: print("foo-i386.iso", end="", file=old_iso_i386) old_metalink_i386_path = os.path.join(old_dir, "foo-i386.metalink") with mkfile(old_metalink_i386_path) as old_metalink_i386: print("foo-i386.metalink", end="", file=old_metalink_i386) self.create_checksum_files(["foo-i386.metalink"], directory=old_dir) metalink_amd64_path = os.path.join(self.temp_dir, "foo-amd64.metalink") with mkfile(metalink_amd64_path) as metalink_amd64: print("foo-amd64.metalink", end="", file=metalink_amd64) touch(os.path.join(self.temp_dir, "foo-amd64.list")) shutil.copy(old_metalink_i386_path, os.path.join(self.temp_dir, "foo-i386.metalink")) checksum_files = self.cls(self.config, self.temp_dir) checksum_files.merge_all([old_dir]) self.assertChecksumsEqual( { "foo-amd64.metalink": b"foo-amd64.metalink", "foo-i386.metalink": b"foo-i386.metalink", }, checksum_files)
def test_publish(self): self.config["ARCHES"] = "i386" self.config["CDIMAGE_INSTALL_BASE"] = "1" publisher = self.make_publisher( "ubuntu", "daily-live", try_zsyncmake=False) source_dir = os.path.join(publisher.image_output, "i386") os.mkdir(source_dir) touch(os.path.join( source_dir, "%s-desktop-i386.raw" % self.config.series)) touch(os.path.join( source_dir, "%s-desktop-i386.list" % self.config.series)) touch(os.path.join( source_dir, "%s-desktop-i386.manifest" % self.config.series)) touch(os.path.join( publisher.britney_report, "%s_probs.html" % self.config.series)) # TODO: until make-web-indices is converted to Python bin_dir = os.path.join(self.config.root, "bin") os.mkdir(bin_dir) os.symlink("/bin/true", os.path.join(bin_dir, "make-web-indices")) os.symlink("/bin/true", os.path.join(bin_dir, "make-metalink")) os.symlink("/bin/true", os.path.join(bin_dir, "post-qa")) os.mkdir(os.path.join(self.config.root, "etc")) self.capture_logging() publisher.publish("20120807") self.assertLogEqual([ "Publishing i386 ...", "Unknown file type 'empty'; assuming .iso", "Publishing i386 live manifest ...", "No keys found; not signing images.", "No keys found; not signing images.", ]) target_dir = os.path.join(publisher.publish_base, "20120807") self.assertEqual([], os.listdir(source_dir)) self.assertEqual(sorted([ "MD5SUMS", "SHA1SUMS", "SHA256SUMS", "%s-desktop-i386.iso" % self.config.series, "%s-desktop-i386.list" % self.config.series, "%s-desktop-i386.manifest" % self.config.series, "report.html", ]), sorted(os.listdir(target_dir)))
def test_mkemptydir_previously_populated(self): new_dir = os.path.join(self.temp_dir, "dir") touch(os.path.join(new_dir, "file")) osextras.mkemptydir(new_dir) self.assertTrue(os.path.isdir(new_dir)) self.assertEqual([], os.listdir(new_dir))
def test_unlink_file_present(self): path = os.path.join(self.temp_dir, "file") touch(path) osextras.unlink_force(path) self.assertFalse(os.path.exists(path))
def test_listdir_directory_present(self): new_dir = os.path.join(self.temp_dir, "dir") os.mkdir(new_dir) touch(os.path.join(new_dir, "file")) self.assertEqual(["file"], osextras.listdir_force(new_dir))
def check_call_side_effect(*args, **kwargs): touch(os.path.join(output_dir, "amd64+mac", "structure"))
def test_symlink_file_present(self): path = os.path.join(self.temp_dir, "link") touch(path) osextras.symlink_force("source", path) self.assertTrue(os.path.islink(path)) self.assertEqual("source", os.readlink(path))
def test_listdir_oserror(self): not_dir = os.path.join(self.temp_dir, "file") touch(not_dir) self.assertRaises(OSError, osextras.listdir_force, not_dir)
def test_listdir_directory_present(self): new_dir = os.path.join(self.temp_dir, "dir") touch(os.path.join(new_dir, "file")) self.assertEqual(["file"], osextras.listdir_force(new_dir))
def test_publish_source(self): publisher = self.make_publisher( "ubuntu", "daily-live", try_zsyncmake=False) source_dir = os.path.join(publisher.image_output, "src") os.mkdir(source_dir) touch(os.path.join(source_dir, "%s-src-1.raw" % self.config.series)) touch(os.path.join(source_dir, "%s-src-1.list" % self.config.series)) touch(os.path.join(source_dir, "%s-src-1.jigdo" % self.config.series)) touch(os.path.join( source_dir, "%s-src-1.template" % self.config.series)) touch(os.path.join(source_dir, "%s-src-2.raw" % self.config.series)) touch(os.path.join(source_dir, "%s-src-2.list" % self.config.series)) touch(os.path.join(source_dir, "%s-src-2.jigdo" % self.config.series)) touch(os.path.join( source_dir, "%s-src-2.template" % self.config.series)) self.capture_logging() list(publisher.publish_source("20120807")) self.assertLogEqual([ "Publishing source 1 ...", "Publishing source 1 jigdo ...", "Publishing source 2 ...", "Publishing source 2 jigdo ...", ]) target_dir = os.path.join(publisher.publish_base, "20120807", "source") self.assertEqual([], os.listdir(source_dir)) self.assertEqual([ "%s-src-1.iso" % self.config.series, "%s-src-1.jigdo" % self.config.series, "%s-src-1.list" % self.config.series, "%s-src-1.template" % self.config.series, "%s-src-2.iso" % self.config.series, "%s-src-2.jigdo" % self.config.series, "%s-src-2.list" % self.config.series, "%s-src-2.template" % self.config.series, ], sorted(os.listdir(target_dir)))
def test_find_on_path_present_not_executable(self): bin_dir = os.path.join(self.temp_dir, "bin") touch(os.path.join(bin_dir, "program")) os.environ["PATH"] = bin_dir self.assertFalse(osextras.find_on_path("program"))