예제 #1
0
 def test_no_args(self):
     """Test calling bdebstrap without arguments."""
     args = parse_args([])
     self.assertEqual(
         args.__dict__,
         {
             "aptopt": None,
             "architectures": None,
             "cleanup_hook": None,
             "components": None,
             "config": [],
             "customize_hook": None,
             "dpkgopt": None,
             "env": {},
             "essential_hook": None,
             "force": False,
             "hostname": None,
             "install_recommends": False,
             "keyring": None,
             "log_level": logging.WARNING,
             "mirrors": [],
             "mode": None,
             "name": None,
             "output_base_dir": ".",
             "output": None,
             "packages": None,
             "setup_hook": None,
             "simulate": False,
             "suite": None,
             "target": None,
             "tmpdir": None,
             "variant": None,
         },
     )
예제 #2
0
 def test_split(self):
     """Test splitting comma and space separated values."""
     args = parse_args([
         "--packages",
         "distro-info ionit,netconsole",
         "--include",
         "openssh-server,restricted-ssh-commands",
         "--components",
         "main,non-free contrib",
         "--architectures",
         "amd64,i386",
     ])
     self.assertEqual(
         get_subset(args.__dict__,
                    {"architectures", "components", "packages"}),
         {
             "architectures": ["amd64", "i386"],
             "components": ["main", "non-free", "contrib"],
             "packages": [
                 "distro-info",
                 "ionit",
                 "netconsole",
                 "openssh-server",
                 "restricted-ssh-commands",
             ],
         },
     )
예제 #3
0
 def test_positional_args(self):
     """Test positional arguments (overwriting optional ones)."""
     args = parse_args([
         "--suite",
         "bullseye",
         "--target",
         "bullseye.tar",
         "--mirrors",
         "deb http://deb.debian.org/debian unstable main,"
         "deb http://deb.debian.org/debian unstable non-free",
         "unstable",
         "unstable.tar",
         "deb http://deb.debian.org/debian unstable contrib",
     ])
     self.assertEqual(
         get_subset(args.__dict__, {"mirrors", "suite", "target"}),
         {
             "mirrors": [
                 "deb http://deb.debian.org/debian unstable main",
                 "deb http://deb.debian.org/debian unstable non-free",
                 "deb http://deb.debian.org/debian unstable contrib",
             ],
             "suite":
             "unstable",
             "target":
             "unstable.tar",
         },
     )
예제 #4
0
 def test_config_and_arguments(self):
     """Test Config.add_command_line_arguments() with config file and arguments."""
     args = parse_args([
         "-c",
         os.path.join(EXAMPLE_CONFIG_DIR, "Debian-unstable.yaml"),
         "--name",
         "Debian-unstable",
         "--variant",
         "standard",
         "--mode",
         "root",
         "--aptopt",
         'Apt::Install-Recommends "0"',
         "--keyring",
         "/usr/share/keyrings",
         "--dpkgopt",
         "force-confdef",
         "--dpkgopt",
         "force-confold",
         "--include",
         "ionit,netconsole",
         "--components",
         "main,non-free",
         "--architectures",
         "i386",
         "--mirrors",
         "http://deb.debian.org/debian",
         "unstable",
         "unstable.tar",
     ])
     config = Config()
     config.add_command_line_arguments(args)
     self.assertDictEqual(
         config,
         {
             "mmdebstrap": {
                 "aptopts": ['Apt::Install-Recommends "0"'],
                 "architectures": ["i386"],
                 "components": ["main", "non-free"],
                 "dpkgopts": ["force-confdef", "force-confold"],
                 "keyrings": [
                     "/usr/share/keyrings/debian-archive-keyring.gpg",
                     "/usr/share/keyrings",
                 ],
                 "mirrors": ["http://deb.debian.org/debian"],
                 "mode":
                 "root",
                 "packages": ["ionit", "netconsole"],
                 "suite":
                 "unstable",
                 "target":
                 "unstable.tar",
                 "variant":
                 "standard",
             },
             "name": "Debian-unstable",
         },
     )
예제 #5
0
 def test_empty_args(self):
     """Test setting arguments to empty strings."""
     args = parse_args([
         "--aptopt=",
         "--architectures=",
         "--cleanup-hook=",
         "--components=",
         "--config=",
         "--customize-hook=",
         "--dpkgopt=",
         "--essential-hook=",
         "--keyring=",
         "--mirrors=",
         "--packages=",
         "--setup-hook=",
     ])
     self.assertEqual(
         get_subset(
             args.__dict__,
             {
                 "aptopt",
                 "architectures",
                 "cleanup_hook",
                 "components",
                 "config",
                 "customize_hook",
                 "dpkgopt",
                 "essential_hook",
                 "keyring",
                 "mirrors",
                 "packages",
                 "setup_hook",
             },
         ),
         {
             "aptopt": [],
             "architectures": [],
             "cleanup_hook": [],
             "components": [],
             "config": [],
             "customize_hook": [],
             "dpkgopt": [],
             "essential_hook": [],
             "keyring": [],
             "mirrors": [],
             "packages": [],
             "setup_hook": [],
         },
     )
예제 #6
0
 def test_mirrors_with_spaces(self):
     """Test --mirrors with leading/trailing spaces."""
     args = parse_args([
         "--mirrors",
         "  deb http://deb.debian.org/debian unstable main\t ,  \t, "
         "deb http://deb.debian.org/debian unstable non-free\t",
         "--mirrors",
         "\tdeb http://deb.debian.org/debian unstable contrib ",
     ])
     self.assertEqual(
         args.mirrors,
         [
             "deb http://deb.debian.org/debian unstable main",
             "deb http://deb.debian.org/debian unstable non-free",
             "deb http://deb.debian.org/debian unstable contrib",
         ],
     )
예제 #7
0
 def test_add_command_line_arguments(self):
     """Test Config.add_command_line_arguments()."""
     args = parse_args([
         "-c",
         os.path.join(EXAMPLE_CONFIG_DIR, "Debian-unstable.yaml"),
         "--name",
         "Debian-unstable",
     ])
     config = Config()
     config.add_command_line_arguments(args)
     self.assertEqual(
         config,
         {
             "mmdebstrap": {
                 "keyrings":
                 ["/usr/share/keyrings/debian-archive-keyring.gpg"],
                 "mode": "unshare",
                 "suite": "unstable",
                 "target": "root.tar.xz",
                 "variant": "minbase",
             },
             "name": "Debian-unstable",
         },
     )
예제 #8
0
 def test_debug(self):
     """Test --debug argument parsing."""
     args = parse_args(["--debug"])
     self.assertEqual(args.log_level, logging.DEBUG)
예제 #9
0
 def test_malformed_env(self):
     """Test malformed --env parameter (missing equal sign)."""
     stderr = io.StringIO()
     with contextlib.redirect_stderr(stderr), self.assertRaises(SystemExit):
         parse_args(["--env", "invalid"])
     self.assertIn("Failed to parse --env 'invalid'.", stderr.getvalue())
예제 #10
0
 def test_parse_env(self):
     """Test parsing --env parameters."""
     args = parse_args(["-e", "KEY=VALUE", "--env", "FOO=bar"])
     self.assertEqual(args.env, {"FOO": "bar", "KEY": "VALUE"})