示例#1
0
 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)
示例#2
0
 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))
示例#3
0
 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])
示例#6
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)
示例#7
0
 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
示例#8
0
 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"
示例#9
0
 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."])
示例#10
0
 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)
示例#11
0
 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)
示例#12
0
 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)
示例#13
0
 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)
示例#14
0
 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)
示例#15
0
 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))
示例#16
0
 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",
     ])
示例#17
0
 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"])
示例#18
0
 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"])
示例#19
0
 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)
示例#20
0
    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"])
示例#21
0
 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)
示例#22
0
 def test_subproject(self):
     config = Config(read=False)
     config["SUBPROJECT"] = "wubi"
     self.assertEqual("wubi", config.subproject)
示例#23
0
 def test_capproject(self):
     config = Config(read=False)
     config["CAPPROJECT"] = "Kubuntu"
     self.assertEqual("Kubuntu", config.capproject)
示例#24
0
 def test_project(self):
     config = Config(read=False)
     config["PROJECT"] = "kubuntu"
     self.assertEqual("kubuntu", config.project)
示例#25
0
 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-"))
示例#26
0
 def test_series(self):
     config = Config(read=False)
     config["DIST"] = "warty"
     self.assertEqual("warty", config.series)
示例#27
0
 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)
示例#28
0
 def test_default_values(self):
     config = Config(read=False)
     self.assertEqual("", config["PROJECT"])
示例#29
0
 def test_image_type(self):
     config = Config(read=False)
     config["IMAGE_TYPE"] = "daily-live"
     self.assertEqual("daily-live", config.image_type)
示例#30
0
 def test_init_kwargs(self):
     config = Config(read=False, IMAGE_TYPE="daily-live")
     self.assertEqual("daily-live", config["IMAGE_TYPE"])