def test_default_root(self): os.environ.pop("CDIMAGE_ROOT", None) config = Config(read=False) expected_root = os.path.dirname(__file__) # lib/cdimage/tests expected_root = os.path.dirname(expected_root) # lib/cdimage expected_root = os.path.dirname(expected_root) # lib expected_root = os.path.dirname(expected_root) # . self.assertEqual(os.path.realpath(expected_root), config.root)
def test_get_mirrors_async(self): config = Config(read=False) config.root = self.use_temp_dir() production_path = os.path.join(self.temp_dir, "production", "trigger-mirrors") with mkfile(production_path) as production: print("sync x.example.org", file=production) print("async a.example.org b.example.org", file=production) print("sync y.example.org z.example.org", file=production) print("async c.example.org", file=production) self.assertEqual(["a.example.org", "b.example.org", "c.example.org"], _get_mirrors_async(config)) self.configure_triggers() self.assertEqual(["foo-async", "bar-async"], _get_mirrors_async(self.config)) self.config["UBUNTU_DEFAULTS_LOCALE"] = "zh_CN" self.assertEqual([], _get_mirrors_async(self.config))
def test_missing_config(self): # Even if etc/config is missing, Config still reads values from the # environment. This makes it easier to experiment locally. self.use_temp_dir() os.environ["CDIMAGE_ROOT"] = self.temp_dir os.environ["PROJECT"] = "kubuntu" config = Config() self.assertEqual("kubuntu", config["PROJECT"])
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_fetch_url(self, mock_call): config = Config(read=False) target = os.path.join(self.temp_dir, "target") osextras.fetch(config, "http://example.org/source", target) self.assertEqual(1, mock_call.call_count) self.assertEqual( ["wget", "-nv", "http://example.org/source", "-O", target], mock_call.call_args[0][0])
def test_gnupg_files(self): config = Config(read=False) config["GNUPG_DIR"] = "/path" gpgconf, secring, pubring, trustdb = _gnupg_files(config) self.assertEqual("/path/gpg.conf", gpgconf) self.assertEqual("/path/secring.gpg", secring) self.assertEqual("/path/pubring.gpg", pubring) self.assertEqual("/path/trustdb.gpg", trustdb)
def setUp(self): super(TestChecksumFileSet, self).setUp() self.config = Config(read=False) self.use_temp_dir() self.files_and_commands = { "SHA256SUMS": "sha256sum", } self.cls = ChecksumFileSet
def setUp(self): super(TestCheckInstallable, self).setUp() self.config = Config(read=False) self.config.root = self.use_temp_dir() self.config["PROJECT"] = "ubuntu" self.config["CAPPROJECT"] = "Ubuntu" self.config["IMAGE_TYPE"] = "daily" self.config["DIST"] = "warty" self.config["ARCHES"] = "i386"
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_gnupg_files(self): config = Config(read=False) config["GNUPG_DIR"] = "/path" gpgdir, gpgconf, secring, privkeydir, pubring, trustdb = \ _gnupg_files(config) self.assertEqual("/path", gpgdir) self.assertEqual("/path/gpg.conf", gpgconf) self.assertEqual("/path/secring.gpg", secring) self.assertEqual("/path/private-keys-v1.d", privkeydir) self.assertEqual("/path/pubring.gpg", pubring) self.assertEqual("/path/trustdb.gpg", trustdb)
def test_core_series(self): config = Config(read=False) config["DIST"] = "utopic" self.assertEqual(None, config.core_series) config["DIST"] = "xenial" self.assertEqual("16", config.core_series) config["DIST"] = "yakkety" self.assertEqual("16", config.core_series) config["DIST"] = "zesty" self.assertEqual("16", config.core_series) config["DIST"] = "artful" self.assertEqual("16", config.core_series)
def test_signing_command_two_keys(self): config = Config(read=False) config["GNUPG_DIR"] = "/path" config["SIGNING_KEYID"] = "01234567 89ABCDEF" command = _signing_command(config) self.assertEqual([ "gpg", "--options", "/path/gpg.conf", "--homedir", "/path", "--no-options", "--batch", "--no-tty", "--armour", "--detach-sign", "--digest-algo", "SHA512", "-u", "01234567", "-u", "89ABCDEF", ], command)
def test_read_shell(self): os.environ["CDIMAGE_ROOT"] = self.use_temp_dir() with mkfile(os.path.join(self.temp_dir, "etc", "config")) as f: print(dedent("""\ #! /bin/sh PROJECT=ubuntu CAPPROJECT=Ubuntu """), file=f) config = Config() self.assertEqual("ubuntu", config["PROJECT"]) self.assertEqual("Ubuntu", config["CAPPROJECT"]) self.assertNotIn("DEBUG", config)
def test_core_series(self): config = Config(read=False) config["DIST"] = "utopic" self.assertEqual(None, config.core_series) config["DIST"] = "xenial" self.assertEqual("16", config.core_series) config["DIST"] = "bionic" self.assertEqual("18", config.core_series) config["DIST"] = "cosmic" self.assertEqual("18", config.core_series) config["DIST"] = "disco" self.assertEqual("18", config.core_series) config["DIST"] = "eoan" self.assertEqual("18", config.core_series)
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_trigger_mirror_foreground(self, mock_call): config = Config(read=False) self.capture_logging() _trigger_mirror(config, "id-test", "archvsync", "remote") self.assertLogEqual(["remote:"]) mock_call.assert_called_once_with([ "ssh", "-i", "id-test", "-o", "StrictHostKeyChecking no", "-o", "BatchMode yes", "archvsync@remote", "./releases-sync", ])
def test_init_kwargs_default_arches_subproject(self): os.environ["CDIMAGE_ROOT"] = self.use_temp_dir() os.environ.pop("ARCHES", None) os.environ.pop("CPUARCHES", None) etc_dir = os.path.join(self.temp_dir, "etc") with mkfile(os.path.join(etc_dir, "config")) as f: print(dedent("""\ #! /bin/sh PROJECT=ubuntu DIST=raring """), file=f) with mkfile(os.path.join(etc_dir, "default-arches")) as f: print("ubuntu-wubi\t*\traring\tamd64 i386", file=f) print("*\t*\t*\tamd64 i386 powerpc", file=f) config = Config(SUBPROJECT="wubi", IMAGE_TYPE="wubi") self.assertEqual("amd64 i386", config["ARCHES"])
def test_init_kwargs_default_arches(self): os.environ["CDIMAGE_ROOT"] = self.use_temp_dir() os.environ.pop("ARCHES", None) os.environ.pop("CPUARCHES", None) etc_dir = os.path.join(self.temp_dir, "etc") with mkfile(os.path.join(etc_dir, "config")) as f: print(dedent("""\ #! /bin/sh PROJECT=ubuntu DIST=raring """), file=f) with mkfile(os.path.join(etc_dir, "default-arches")) as f: print("*\tdaily-live\traring\tamd64 amd64+mac i386", file=f) config = Config(IMAGE_TYPE="daily-live") self.assertEqual("daily-live", config["IMAGE_TYPE"]) self.assertEqual("amd64 amd64+mac i386", config["ARCHES"]) self.assertEqual("amd64 i386", config["CPUARCHES"])
def test_sign_cdimage_configured(self, mock_check_call): 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) self.capture_logging() self.assertTrue(sign_cdimage(config, sign_path)) self.assertLogEqual([]) expected_command = [ "gpg", "--options", gpgconf, "--no-default-keyring", "--secret-keyring", secring, "--keyring", pubring, "--trustdb-name", trustdb, "--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_limit_arches(self): # limit_arches reduces ARCHES and CPUARCHES to only those items also # present in the iterable passed as a parameter. self.use_temp_dir() os.environ["CDIMAGE_ROOT"] = self.temp_dir os.environ["ARCHES"] = "amd64 amd64+mac i386 powerpc" config = Config() self.assertEqual(["amd64", "amd64+mac", "i386", "powerpc"], config.arches) self.assertEqual("amd64 amd64+mac i386 powerpc", os.environ["ARCHES"]) self.assertEqual(["amd64", "i386", "powerpc"], config.cpuarches) self.assertEqual("amd64 i386 powerpc", os.environ["CPUARCHES"]) config.limit_arches(["amd64", "amd64+mac", "i386", "sparc"]) self.assertEqual(["amd64", "amd64+mac", "i386"], config.arches) self.assertEqual("amd64 amd64+mac i386", os.environ["ARCHES"]) self.assertEqual(["amd64", "i386"], config.cpuarches) self.assertEqual("amd64 i386", os.environ["CPUARCHES"]) config.limit_arches(["amd64"]) self.assertEqual(["amd64"], config.arches) self.assertEqual("amd64", os.environ["ARCHES"]) self.assertEqual(["amd64"], config.cpuarches) self.assertEqual("amd64", os.environ["CPUARCHES"])
def test_distribution(self): config = Config(read=False) config["DIST"] = "utopic" self.assertEqual("ubuntu", config.distribution) config["DIST"] = "ubuntu-rtm/14.09" self.assertEqual("ubuntu-rtm", config.distribution)
def test_subproject(self): config = Config(read=False) config["SUBPROJECT"] = "wubi" self.assertEqual("wubi", config.subproject)
def test_capproject(self): config = Config(read=False) config["CAPPROJECT"] = "Kubuntu" self.assertEqual("Kubuntu", config.capproject)
def test_project(self): config = Config(read=False) config["PROJECT"] = "kubuntu" self.assertEqual("kubuntu", config.project)
def test_match_series(self): config = Config(read=False) config["DIST"] = "precise" self.assertTrue(config.match_series("*")) self.assertTrue(config.match_series("natty-precise")) self.assertTrue(config.match_series("precise-quantal")) self.assertTrue(config.match_series("natty-quantal")) self.assertFalse(config.match_series("lucid-natty")) self.assertFalse(config.match_series("quantal-raring")) self.assertTrue(config.match_series("precise-")) self.assertFalse(config.match_series("quantal-")) self.assertTrue(config.match_series("-precise")) self.assertFalse(config.match_series("-oneiric")) self.assertFalse(config.match_series("lucid")) self.assertTrue(config.match_series("precise")) self.assertFalse(config.match_series("ubuntu-rtm/*")) self.assertFalse(config.match_series("ubuntu-rtm/14.09-")) config["DIST"] = "ubuntu-rtm/14.09" self.assertTrue(config.match_series("*")) self.assertFalse(config.match_series("ubuntu/*")) self.assertFalse(config.match_series("precise-")) self.assertTrue(config.match_series("ubuntu-rtm/*")) self.assertTrue(config.match_series("ubuntu-rtm/14.09-"))
def test_series(self): config = Config(read=False) config["DIST"] = "warty" self.assertEqual("warty", config.series)
def test_full_series(self): config = Config(read=False) config["DIST"] = "utopic" self.assertEqual("utopic", config.full_series) config["DIST"] = "ubuntu-rtm/14.09" self.assertEqual("ubuntu-rtm/14.09", config.full_series)
def test_default_values(self): config = Config(read=False) self.assertEqual("", config["PROJECT"])
def test_image_type(self): config = Config(read=False) config["IMAGE_TYPE"] = "daily-live" self.assertEqual("daily-live", config.image_type)
def test_init_kwargs(self): config = Config(read=False, IMAGE_TYPE="daily-live") self.assertEqual("daily-live", config["IMAGE_TYPE"])