def test_list_seeds_base(self): self.write_ubuntu_structure() output = GerminateOutput(self.config, self.temp_dir) for series in all_series[6:]: self.config["DIST"] = series self.assertEqual(["boot", "required", "minimal", "standard"], list(output.list_seeds("base")))
def test_master_seeds_onlysource(self): self.write_ubuntu_structure() output = GerminateOutput(self.config, self.temp_dir) self.config["CDIMAGE_ONLYSOURCE"] = "1" self.assertEqual([ "required", "minimal", "boot", "standard", "desktop-common", "d-i-requirements", "installer", "live-common", "desktop", "dns-server", "lamp-server", "openssh-server", "print-server", "samba-server", "postgresql-server", "mail-server", "tomcat-server", "virt-host", "server", "server-ship", "ship", "live", "ship-live", "usb", "usb-live", "usb-langsupport", "usb-ship-live", ], list(output.master_seeds()))
def test_list_seeds_debootstrap(self): self.write_ubuntu_structure() output = GerminateOutput(self.config, self.temp_dir) for series in all_series[6:]: self.config["DIST"] = series self.assertEqual(["required", "minimal"], list(output.list_seeds("debootstrap")))
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_list_seeds_tasks_ubuntu_server(self): self.write_ubuntu_structure() output = GerminateOutput(self.config, self.temp_dir) self.config["PROJECT"] = "ubuntu-server" expected = [ "boot", "installer", "required", "minimal", "standard", "dns-server", "lamp-server", "openssh-server", "print-server", "samba-server", "postgresql-server", "mail-server", "server", "tomcat-server", "virt-host", "d-i-requirements", "server-ship", ] for series in all_series[4:]: self.config["DIST"] = series self.assertEqual(expected, list(output.list_seeds("tasks")))
def test_inheritance_recurses(self): """_inheritance recurses properly.""" self.write_structure([["a", []], ["b", ["a"]], ["c", ["b"]]]) output = GerminateOutput(self.config, self.temp_dir) self.assertEqual(["a"], output._inheritance("a")) self.assertEqual(["a", "b"], output._inheritance("b")) self.assertEqual(["a", "b", "c"], output._inheritance("c"))
def test_task_packages_plain(self): self.write_structure([["base", []]]) self.write_seed_output("i386", "base", ["base-files", "base-passwd"]) output = GerminateOutput(self.config, self.temp_dir) self.assertEqual( ["base-files", "base-passwd"], list(output.task_packages("i386", "base", "base")))
def test_without_inheritance(self): self.write_structure( [["a", []], ["b", ["a"]], ["c", ["b"]], ["d", ["a", "c"]]]) output = GerminateOutput(self.config, self.temp_dir) inheritance = output._inheritance("d") self.assertEqual(["a", "b", "c", "d"], inheritance) self.assertEqual( ["c", "d"], output._without_inheritance("b", inheritance))
def test_master_seeds_dvd_ubuntu_raring(self): self.write_ubuntu_structure() output = GerminateOutput(self.config, self.temp_dir) self.config["PROJECT"] = "ubuntu" self.config["DIST"] = "raring" self.config["CDIMAGE_DVD"] = "1" self.assertEqual( ["usb-langsupport", "usb-ship-live"], list(output.master_seeds()))
def test_tasks_output_dir(self): self.write_ubuntu_structure() output = GerminateOutput(self.config, self.temp_dir) self.config["DIST"] = "trusty" self.config["IMAGE_TYPE"] = "daily" self.assertEqual( os.path.join(self.temp_dir, "scratch", "ubuntu", "trusty", "daily", "tasks"), output.tasks_output_dir("ubuntu"))
def test_list_seeds_installer(self): self.write_structure([["installer", []], ["casper", []]]) output = GerminateOutput(self.config, self.temp_dir) self.config["CDIMAGE_INSTALL_BASE"] = "1" self.assertEqual(["installer"], list(output.list_seeds("installer"))) del self.config["CDIMAGE_INSTALL_BASE"] self.config["CDIMAGE_LIVE"] = "1" self.config["DIST"] = "precise" self.assertEqual([], list(output.list_seeds("installer")))
def test_list_seeds_tasks_jeos(self): self.write_structure([ ["required", []], ["minimal", ["required"]], ["jeos", ["minimal"]], ]) output = GerminateOutput(self.config, self.temp_dir) self.config["PROJECT"] = "jeos" self.assertEqual( ["required", "minimal", "jeos"], list(output.list_seeds("tasks")))
def test_master_seeds_live_ubuntu_raring(self): self.write_ubuntu_structure() output = GerminateOutput(self.config, self.temp_dir) self.config["PROJECT"] = "ubuntu" self.config["DIST"] = "raring" self.config["CDIMAGE_INSTALL_BASE"] = "1" self.config["CDIMAGE_LIVE"] = "1" self.assertEqual([ "installer", "boot", "required", "minimal", "standard", "ship-live", ], list(output.master_seeds()))
def test_list_seeds_tasks_kubuntu_active(self): self.write_kubuntu_structure() output = GerminateOutput(self.config, self.temp_dir) self.config["PROJECT"] = "kubuntu-active" self.config["DIST"] = "raring" expected = [ "boot", "installer", "required", "minimal", "standard", "desktop-common", "desktop", "d-i-requirements", "ship", "active-ship", ] self.assertEqual(expected, list(output.list_seeds("tasks")))
def test_list_seeds_tasks_ubuntu(self): self.write_ubuntu_structure() output = GerminateOutput(self.config, self.temp_dir) self.config["PROJECT"] = "ubuntu" self.config["DIST"] = "raring" expected = [ "boot", "installer", "required", "minimal", "standard", "desktop-common", "desktop", "d-i-requirements", "ship", ] self.assertEqual(expected, list(output.list_seeds("tasks"))) self.config["CDIMAGE_DVD"] = "1" expected.extend(["dns-server", "lamp-server"]) self.assertEqual(expected, list(output.list_seeds("tasks")))
def test_task_packages_installer(self): # kernel-image-* is excluded from the installer seed. self.write_structure([["installer", []]]) self.write_seed_output( "i386", "installer", [ "block-modules-3.8.0-6-generic-di", "kernel-image-3.8.0-6-generic-di", ]) self.config["CDIMAGE_INSTALL_BASE"] = "1" output = GerminateOutput(self.config, self.temp_dir) self.assertEqual( ["block-modules-3.8.0-6-generic-di"], list(output.task_packages("i386", "installer", "installer")))
def test_list_seeds_task_ubuntu_server_squashfs(self): self.write_ubuntu_structure() output = GerminateOutput(self.config, self.temp_dir) self.config["PROJECT"] = "ubuntu-server" self.config["DIST"] = "raring" self.config["CDIMAGE_SQUASHFS_BASE"] = "1" expected = [ "boot", "installer", "standard", "dns-server", "lamp-server", "openssh-server", "print-server", "samba-server", "postgresql-server", "mail-server", "server", "tomcat-server", "virt-host", "d-i-requirements", "server-ship", ] self.assertEqual(expected, list(output.list_seeds("tasks")))
def test_master_task_entries(self, mock_master_seeds): def side_effect(): yield "required" yield "minimal" self.write_ubuntu_structure() output = GerminateOutput(self.config, self.temp_dir) self.config["DIST"] = "raring" mock_master_seeds.side_effect = side_effect self.assertEqual([ "#include <ubuntu/raring/required>", "#include <ubuntu/raring/minimal>", ], list(output.master_task_entries("ubuntu")))
def test_task_packages_squashfs(self): self.write_ubuntu_structure() self.config["PROJECT"] = "ubuntu-server" self.config["DIST"] = "raring" self.write_seed_output( "i386", "installer", ["base-installer", "bootstrap-base"]) output = GerminateOutput(self.config, self.temp_dir) self.assertEqual( ["base-installer", "bootstrap-base"], list(output.task_packages("i386", "installer", "installer"))) self.config["CDIMAGE_SQUASHFS_BASE"] = "1" self.assertEqual( ["base-installer", "live-installer"], list(output.task_packages("i386", "installer", "installer")))
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_common_initrd_packages(self): self.write_ubuntu_structure() manifest_path = os.path.join( self.temp_dir, "ftp", "dists", "raring", "main", "installer-i386", "current", "images", "MANIFEST.udebs") with mkfile(manifest_path) as manifest: print(dedent("""\ cdrom/initrd.gz \tanna 1.45ubuntu1 i386 \tcdrom-detect 1.43ubuntu1 all netboot/netboot.tar.gz \tanna 1.45ubuntu1 i386 \tnet-retriever 1.32ubuntu1 i386"""), file=manifest) self.config["DIST"] = "raring" output = GerminateOutput(self.config, self.temp_dir) self.assertEqual(set(["anna"]), output.common_initrd_packages("i386"))
def test_seed_task_mapping(self): self.write_ubuntu_structure() seed_dir = os.path.join(self.temp_dir, "i386") with mkfile(os.path.join(seed_dir, "standard.seedtext")) as seedtext: print("Task-Key: ubuntu-standard", file=seedtext) with mkfile(os.path.join(seed_dir, "desktop.seedtext")) as seedtext: print(dedent("""\ Task-Per-Derivative: 1 Task-Seeds: desktop-common"""), file=seedtext) self.config["DIST"] = "raring" output = GerminateOutput(self.config, self.temp_dir) expected = [ (["standard"], "standard"), (["desktop", "desktop-common"], "ubuntu-desktop"), ] self.assertEqual( expected, list(output.seed_task_mapping("ubuntu", "i386")))
def test_master_seeds_install_ubuntu_trusty(self): self.write_ubuntu_structure() output = GerminateOutput(self.config, self.temp_dir) self.config["PROJECT"] = "ubuntu" self.config["DIST"] = "trusty" self.config["CDIMAGE_INSTALL"] = "1" self.config["CDIMAGE_INSTALL_BASE"] = "1" self.assertEqual([ "installer", "boot", "required", "minimal", "standard", "desktop-common", "desktop", "d-i-requirements", "ship", ], list(output.master_seeds()))
def test_task_headers(self): self.write_ubuntu_structure() seedtext_path = os.path.join(self.temp_dir, "i386", "desktop.seedtext") with mkfile(seedtext_path) as seedtext: print(dedent("""\ Task-Per-Derivative: 1 Task-Key: ubuntu-desktop Task-Seeds: desktop-common = Seed text starts here ="""), file=seedtext) output = GerminateOutput(self.config, self.temp_dir) expected = { "per-derivative": "1", "key": "ubuntu-desktop", "seeds": "desktop-common", } self.assertEqual(expected, output.task_headers("i386", "desktop")) self.assertEqual({}, output.task_headers("i386", "missing"))
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_task_packages_gutsy_ps3_hack(self): self.write_structure([["boot", []], ["installer", []]]) self.write_seed_output( "powerpc+ps3", "boot", ["linux-image-2.6.22-14-powerpc64-smp"]) self.write_seed_output( "powerpc+ps3", "installer", [ "block-modules-2.6.22-14-powerpc-di", "block-modules-2.6.22-14-powerpc64-smp-di", ]) self.config["DIST"] = "gutsy" self.config["CDIMAGE_INSTALL_BASE"] = "1" output = GerminateOutput(self.config, self.temp_dir) self.assertEqual( ["linux-image-2.6.22-14-cell"], list(output.task_packages("powerpc+ps3", "boot", "boot"))) self.assertEqual( ["block-modules-2.6.22-14-cell-di"], list(output.task_packages( "powerpc+ps3", "installer", "installer")))
def test_task_packages_precise_kernels(self): self.write_structure([["boot", []], ["installer", []]]) self.write_seed_output( "i386", "boot", ["linux-image-3.2.0-23-generic-pae"]) self.write_seed_output( "i386", "installer", ["block-modules-3.2.0-23-generic-pae-di"]) self.config["DIST"] = "precise" self.config["CDIMAGE_INSTALL_BASE"] = "1" output = GerminateOutput(self.config, self.temp_dir) for project, flavour in ( ("ubuntu", "generic-pae"), ("xubuntu", "generic"), ("lubuntu", "generic"), ): self.config["PROJECT"] = project self.assertEqual( ["linux-image-3.2.0-23-%s" % flavour], list(output.task_packages("i386", "boot", "boot"))) self.assertEqual( ["block-modules-3.2.0-23-%s-di" % flavour], list(output.task_packages("i386", "installer", "installer")))
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_write_tasks_project(self): self.write_ubuntu_structure() for arch in "amd64", "i386": seed_dir = os.path.join(self.temp_dir, arch) self.write_seed_output(arch, "required", ["base-files-%s" % arch]) self.write_seed_output(arch, "minimal", ["adduser-%s" % arch]) self.write_seed_output(arch, "desktop", ["xterm", "firefox"]) self.write_seed_output(arch, "live", ["xterm"]) with mkfile(os.path.join( seed_dir, "minimal.seedtext")) as seedtext: print("Task-Seeds: required", file=seedtext) with mkfile(os.path.join( seed_dir, "desktop.seedtext")) as seedtext: print("Task-Per-Derivative: 1", file=seedtext) with mkfile(os.path.join(seed_dir, "live.seedtext")) as seedtext: print("Task-Per-Derivative: 1", file=seedtext) self.config["DIST"] = "raring" self.config["ARCHES"] = "amd64 i386" self.config["IMAGE_TYPE"] = "daily-live" self.config["CDIMAGE_LIVE"] = "1" output = GerminateOutput(self.config, self.temp_dir) output.write_tasks_project("ubuntu") output_dir = os.path.join( self.temp_dir, "scratch", "ubuntu", "raring", "daily-live", "tasks") self.assertCountEqual([ "required", "minimal", "desktop", "live", "override.amd64", "override.i386", "important.amd64", "important.i386", "MASTER", ], os.listdir(output_dir)) with open(os.path.join(output_dir, "required")) as f: self.assertEqual( dedent("""\ #ifdef ARCH_amd64 base-files-amd64 #endif /* ARCH_amd64 */ #ifdef ARCH_i386 base-files-i386 #endif /* ARCH_i386 */ """), f.read()) with open(os.path.join(output_dir, "minimal")) as f: self.assertEqual( dedent("""\ #ifdef ARCH_amd64 adduser-amd64 #endif /* ARCH_amd64 */ #ifdef ARCH_i386 adduser-i386 #endif /* ARCH_i386 */ """), f.read()) with open(os.path.join(output_dir, "desktop")) as f: self.assertEqual( dedent("""\ #ifdef ARCH_amd64 firefox xterm #endif /* ARCH_amd64 */ #ifdef ARCH_i386 firefox xterm #endif /* ARCH_i386 */ """), f.read()) with open(os.path.join(output_dir, "live")) as f: self.assertEqual( dedent("""\ #ifdef ARCH_amd64 xterm #endif /* ARCH_amd64 */ #ifdef ARCH_i386 xterm #endif /* ARCH_i386 */ """), f.read()) with open(os.path.join(output_dir, "override.amd64")) as f: self.assertEqual( dedent("""\ adduser-amd64 Task minimal base-files-amd64 Task minimal firefox Task ubuntu-desktop xterm Task ubuntu-desktop, ubuntu-live """), f.read()) with open(os.path.join(output_dir, "override.i386")) as f: self.assertEqual( dedent("""\ adduser-i386 Task minimal base-files-i386 Task minimal firefox Task ubuntu-desktop xterm Task ubuntu-desktop, ubuntu-live """), f.read()) with open(os.path.join(output_dir, "important.amd64")) as f: self.assertEqual("adduser-amd64\nbase-files-amd64\n", f.read()) with open(os.path.join(output_dir, "important.i386")) as f: self.assertEqual("adduser-i386\nbase-files-i386\n", f.read()) with open(os.path.join(output_dir, "MASTER")) as f: self.assertEqual("#include <ubuntu/raring/ship-live>\n", f.read())
def test_master_task_entries_no_seeds(self, mock_master_seeds): self.write_ubuntu_structure() output = GerminateOutput(self.config, self.temp_dir) self.config["DIST"] = "raring" self.assertRaises( NoMasterSeeds, list, output.master_task_entries("ubuntu"))