예제 #1
0
    def real_parsing_and_adding_test(self):
        """Test file spec handling in KernelArguments."""

        ka = KernelArguments()
        self.assertEqual(ka.read(["/proc/cmdlin*", "/nonexistent/file"]), ["/proc/cmdline"])
        self.assertEqual(ka.read("/another/futile/attempt"), [])
        self.assertTrue(ka.getbool("root"))  # expect this to be set in most environments
예제 #2
0
    def test_real_parsing_and_adding(self):
        """Test file spec handling in KernelArguments."""

        ka = KernelArguments()
        self.assertEqual(ka.read(["/proc/cmdlin*", "/nonexistent/file"]),
                         ["/proc/cmdline"])
        self.assertEqual(ka.read("/another/futile/attempt"), [])
예제 #3
0
    def test_addrepo(self):
        # Test invalid options.
        with pytest.raises(ValueError):
            self._parseCmdline(["--addrepo=r1"])

        with pytest.raises(ValueError):
            self._parseCmdline(["--addrepo=http://url/1"])

        # Test cmdline options.
        opts, _removed = self._parseCmdline(["--addrepo=r1,http://url/1"])
        assert opts.addRepo == [("r1", "http://url/1")]

        opts, _removed = self._parseCmdline([
            "--addrepo=r1,http://url/1",
            "--addrepo=r2,http://url/2",
            "--addrepo=r3,http://url/3",
        ])
        assert opts.addRepo == [
            ("r1", "http://url/1"),
            ("r2", "http://url/2"),
            ("r3", "http://url/3"),
        ]

        # Test invalid boot options.
        boot_cmdline = KernelArguments.from_string("inst.addrepo=r1")
        with pytest.raises(ValueError) as cm:
            self._parseCmdline([], boot_cmdline)

        expected = \
            "The addrepo option has incorrect format ('r1'). " \
            "Use: inst.addrepo=<name>,<url>"

        assert str(cm.value) == expected

        boot_cmdline = KernelArguments.from_string("inst.addrepo=http://url/1")
        with pytest.raises(ValueError):
            self._parseCmdline([], boot_cmdline)

        # Test boot options.
        boot_cmdline = KernelArguments.from_string(
            "inst.addrepo=r1,http://url/1")
        opts, _removed = self._parseCmdline([], boot_cmdline)
        assert opts.addRepo == [("r1", "http://url/1")]

        boot_cmdline = KernelArguments.from_string(
            "inst.addrepo=r1,http://url/1 "
            "inst.addrepo=r2,http://url/2 "
            "inst.addrepo=r3,http://url/3 ")
        opts, _removed = self._parseCmdline([], boot_cmdline)
        assert opts.addRepo == [
            ("r1", "http://url/1"),
            ("r2", "http://url/2"),
            ("r3", "http://url/3"),
        ]
예제 #4
0
    def test_without_inst_prefix(self):
        boot_cmdline = KernelArguments.from_string("stage2=http://cool.server.com/test")
        opts, removed = self._parseCmdline([], boot_cmdline=boot_cmdline)
        assert opts.stage2 is None
        assert removed == ["stage2"]

        boot_cmdline = KernelArguments.from_string("stage2=http://cool.server.com/test "
                                                   "vnc")
        opts, removed = self._parseCmdline([], boot_cmdline=boot_cmdline)
        assert opts.stage2 is None
        assert not opts.vnc
        assert removed == ["stage2", "vnc"]
예제 #5
0
    def without_inst_prefix_test(self):
        boot_cmdline = KernelArguments.from_string("stage2=http://cool.server.com/test")
        opts, removed = self._parseCmdline([], boot_cmdline=boot_cmdline)
        self.assertEqual(opts.stage2, None)
        self.assertEqual(removed, ["stage2"])

        boot_cmdline = KernelArguments.from_string("stage2=http://cool.server.com/test "
                                                   "vnc")
        opts, removed = self._parseCmdline([], boot_cmdline=boot_cmdline)
        self.assertEqual(opts.stage2, None)
        self.assertFalse(opts.vnc)
        self.assertListEqual(removed, ["stage2", "vnc"])
예제 #6
0
    def with_inst_prefix_test(self):
        boot_cmdline = KernelArguments.from_string("inst.stage2=http://cool.server.com/test")
        opts, removed = self._parseCmdline([], boot_cmdline=boot_cmdline)
        self.assertEqual(opts.stage2, "http://cool.server.com/test")
        self.assertEqual(removed, [])

        boot_cmdline = KernelArguments.from_string("inst.stage2=http://cool.server.com/test "
                                                   "inst.vnc")
        opts, removed = self._parseCmdline([], boot_cmdline=boot_cmdline)
        self.assertEqual(opts.stage2, "http://cool.server.com/test")
        self.assertTrue(opts.vnc)
        self.assertEqual(removed, [])
예제 #7
0
    def test_with_inst_prefix(self):
        boot_cmdline = KernelArguments.from_string("inst.stage2=http://cool.server.com/test")
        opts, removed = self._parseCmdline([], boot_cmdline=boot_cmdline)
        assert opts.stage2 == "http://cool.server.com/test"
        assert removed == []

        boot_cmdline = KernelArguments.from_string("inst.stage2=http://cool.server.com/test "
                                                   "inst.vnc")
        opts, removed = self._parseCmdline([], boot_cmdline=boot_cmdline)
        assert opts.stage2 == "http://cool.server.com/test"
        assert opts.vnc
        assert removed == []
예제 #8
0
    def display_mode_test(self):
        opts, _deprecated = self._parseCmdline(['--cmdline'])
        self.assertEqual(opts.display_mode, DisplayModes.TUI)
        self.assertTrue(opts.noninteractive)

        opts, _deprecated = self._parseCmdline(['--graphical'])
        self.assertEqual(opts.display_mode, DisplayModes.GUI)
        self.assertFalse(opts.noninteractive)

        opts, _deprecated = self._parseCmdline(['--text'])
        self.assertEqual(opts.display_mode, DisplayModes.TUI)
        self.assertFalse(opts.noninteractive)

        opts, _deprecated = self._parseCmdline(['--noninteractive'])
        self.assertTrue(opts.noninteractive)

        # Test the default
        opts, _deprecated = self._parseCmdline([])
        self.assertEqual(opts.display_mode, DisplayModes.GUI)
        self.assertFalse(opts.noninteractive)

        # console=whatever in the boot args defaults to --text
        boot_cmdline = KernelArguments.from_string("console=/dev/ttyS0")
        opts, _deprecated = self._parseCmdline([], boot_cmdline=boot_cmdline)
        self.assertEqual(opts.display_mode, DisplayModes.TUI)
예제 #9
0
    def test_value_retrieval(self):
        """KernelArguments value retrieval test."""

        ka = KernelArguments.from_string(
            "inst.blah foo=anything inst.bar=1 baz=0 nowhere inst.nothing=indeed beep=off "
            "derp=no nobody=0")

        # test using "in" operator on the class
        assert "blah" in ka
        assert "foo" in ka
        assert not ("thisisnotthere" in ka)
        assert not ("body" in ka)
        assert "nobody" in ka

        # test the get() method
        assert ka.get("foo") == "anything"
        assert ka.get("thisisnotthere") is None
        assert ka.get("thisisnotthere", "fallback") == "fallback"

        # test the is_enabled() method
        assert ka.is_enabled("blah")  # present
        assert ka.is_enabled("foo")  # any value
        assert ka.is_enabled("bar")  # 1 = any value
        assert not ka.is_enabled("baz")  # 0
        assert ka.is_enabled("nowhere")  # present
        assert ka.is_enabled("nothing")  # present
        assert not ka.is_enabled("beep")  # off
        assert ka.is_enabled("derp")  # no = any value
        assert not ka.is_enabled("nobody")  # 0
        assert not ka.is_enabled("thing")  # not present
        assert not ka.is_enabled("where")  # not present
예제 #10
0
    def test_value_retrieval(self):
        """KernelArguments value retrieval test."""

        ka = KernelArguments.from_string(
            "inst.blah foo=anything inst.bar=1 baz=0 nowhere inst.nothing=indeed beep=off "
            "derp=no nobody=0")

        # test using "in" operator on the class
        self.assertTrue("blah" in ka)
        self.assertTrue("foo" in ka)
        self.assertFalse("thisisnotthere" in ka)
        self.assertFalse("body" in ka)
        self.assertTrue("nobody" in ka)

        # test the get() method
        self.assertEqual(ka.get("foo"), "anything")
        self.assertIsNone(ka.get("thisisnotthere"))
        self.assertEqual(ka.get("thisisnotthere", "fallback"), "fallback")

        # test the is_enabled() method
        self.assertTrue(ka.is_enabled("blah"))  # present
        self.assertTrue(ka.is_enabled("foo"))  # any value
        self.assertTrue(ka.is_enabled("bar"))  # 1 = any value
        self.assertFalse(ka.is_enabled("baz"))  # 0
        self.assertTrue(ka.is_enabled("nowhere"))  # present
        self.assertTrue(ka.is_enabled("nothing"))  # present
        self.assertFalse(ka.is_enabled("beep"))  # off
        self.assertTrue(ka.is_enabled("derp"))  # no = any value
        self.assertFalse(ka.is_enabled("nobody"))  # 0
        self.assertFalse(ka.is_enabled("thing"))  # not present
        self.assertFalse(ka.is_enabled("where"))  # not present
예제 #11
0
    def test_display_mode(self):
        opts, _removed = self._parseCmdline(['--cmdline'])
        assert opts.display_mode == DisplayModes.TUI
        assert opts.noninteractive

        opts, _removed = self._parseCmdline(['--graphical'])
        assert opts.display_mode == DisplayModes.GUI
        assert not opts.noninteractive

        opts, _removed = self._parseCmdline(['--text'])
        assert opts.display_mode == DisplayModes.TUI
        assert not opts.noninteractive

        opts, _removed = self._parseCmdline(['--noninteractive'])
        assert opts.noninteractive

        # Test the default
        opts, _removed = self._parseCmdline([])
        assert opts.display_mode == DisplayModes.GUI
        assert not opts.noninteractive

        # console=whatever in the boot args defaults to --text
        boot_cmdline = KernelArguments.from_string("console=/dev/ttyS0")
        opts, _removed = self._parseCmdline([], boot_cmdline=boot_cmdline)
        assert opts.display_mode == DisplayModes.TUI
예제 #12
0
 def __init__(self):
     self.__dict__['_in_init'] = True
     self.usevnc = False
     self.vncquestion = True
     self.mpath = True
     self.debug = False
     self.preexisting_x11 = False
     self.noverifyssl = False
     self.automatedInstall = False
     self.eject = True
     # ksprompt is whether or not to prompt for missing ksdata
     self.ksprompt = True
     self.rescue_mode = False
     self.kexec = False
     # nosave options
     self.nosave_input_ks = False
     self.nosave_output_ks = False
     self.nosave_logs = False
     # single language options
     self.singlelang = False
     # enable SE/HMC
     self.hmc = False
     # current runtime environments
     self.environs = [ANACONDA_ENVIRON]
     # parse the boot commandline
     self.cmdline = KernelArguments.from_defaults()
     # Lock it down: no more creating new flags!
     self.__dict__['_in_init'] = False
예제 #13
0
 def test_inst_prefix_mixed(self):
     boot_cmdline = KernelArguments.from_string(
         "inst.stage2=http://cool.server.com/test "
         "vnc")
     opts, removed = self._parseCmdline([], boot_cmdline=boot_cmdline)
     self.assertEqual(opts.stage2, "http://cool.server.com/test")
     self.assertFalse(opts.vnc)
     self.assertListEqual(removed, ["vnc"])
예제 #14
0
    def special_argument_handling_test(self):
        """Test handling of special arguments in KernelArguments."""

        ka = KernelArguments.from_string("modprobe.blacklist=floppy modprobe.blacklist=reiserfs")
        self.assertEqual(ka.get("modprobe.blacklist"), "floppy reiserfs")
        ka.read_string("inst.addrepo=yum inst.addrepo=dnf")
        self.assertEqual(ka.get("addrepo"), ["yum", "dnf"])
        ka.read_string("inst.ks=kickstart")
        self.assertEqual(ka.get("ks"), "kickstart")
예제 #15
0
    def test_special_argument_handling(self):
        """Test handling of special arguments in KernelArguments."""

        ka = KernelArguments.from_string(
            "modprobe.blacklist=floppy modprobe.blacklist=reiserfs")
        assert ka.get("modprobe.blacklist") == "floppy reiserfs"
        ka.read_string("inst.addrepo=yum inst.addrepo=dnf")
        assert ka.get("addrepo") == ["yum", "dnf"]
        ka.read_string("inst.ks=kickstart")
        assert ka.get("ks") == "kickstart"
예제 #16
0
    def test_items(self):
        """Test KernelArguments access to contents with iterator."""

        ka = KernelArguments.from_defaults()
        it = ka.items()
        assert isinstance(it, Iterable)
        root_seen = False
        for k, v in it:  # pylint: disable=unused-variable
            if k == "root":
                root_seen = True
        assert root_seen
예제 #17
0
    def items_test(self):
        """Test KernelArguments access to contents with iterator."""

        ka = KernelArguments.from_defaults()
        it = ka.items()
        self.assertIsInstance(it, collections.Iterable)
        root_seen = False
        for k, v in it:  # pylint: disable=unused-variable
            if k == "root":
                root_seen = True
        self.assertTrue(root_seen)
예제 #18
0
    def value_retrieval_test(self):
        """KernelArguments value retrieval test."""

        ka = KernelArguments.from_string(
            "blah foo=anything bar=1 baz=0 nowhere nothing=indeed beep=off derp=no nobody=0")

        # test using "in" operator on the class
        self.assertTrue("blah" in ka)
        self.assertTrue("foo" in ka)
        self.assertFalse("thisisnotthere" in ka)
        self.assertFalse("body" in ka)
        self.assertTrue("nobody" in ka)

        # test the get() method
        self.assertEqual(ka.get("foo"), "anything")
        self.assertIsNone(ka.get("thisisnotthere"))
        self.assertEqual(ka.get("thisisnotthere", "fallback"), "fallback")

        # test the getbool() method - presence
        self.assertTrue(ka.getbool("blah"))  # is present
        self.assertTrue(ka.getbool("foo"))  # has any value

        # test the getbool() method - simple names and values
        self.assertTrue(ka.getbool("bar"))  # 1
        self.assertFalse(ka.getbool("baz"))  # 0
        self.assertFalse(ka.getbool("beep"))  # off
        self.assertFalse(ka.getbool("derp"))  # no

        # test the getbool() method - the super magical "no" prefix
        self.assertFalse(ka.getbool("where"))  # is present with no-prefix
        self.assertFalse(ka.getbool("thing"))  # is set and has no-prefix
        self.assertTrue(ka.getbool("nothing"))  # full name incl. the "no" prefix = is present
        self.assertFalse(ka.getbool("nobody"))  # full name incl. the "no" prefix, value is 0
        self.assertFalse(ka.get("body"))  # no-prefix and has a value

        # test the is_enabled() method
        self.assertTrue(ka.is_enabled("blah"))  # present
        self.assertTrue(ka.is_enabled("foo"))  # any value
        self.assertTrue(ka.is_enabled("bar"))  # 1 = any value
        self.assertFalse(ka.is_enabled("baz"))  # 0
        self.assertTrue(ka.is_enabled("nowhere"))  # present
        self.assertTrue(ka.is_enabled("nothing"))  # present
        self.assertFalse(ka.is_enabled("beep"))  # off
        self.assertTrue(ka.is_enabled("derp"))  # no = any value
        self.assertFalse(ka.is_enabled("nobody"))  # 0
        self.assertFalse(ka.is_enabled("thing"))  # not present
        self.assertFalse(ka.is_enabled("where"))  # not present
예제 #19
0
파일: flags.py 프로젝트: jamin-hon/anaconda
    def __init__(self):
        self.__dict__['_in_init'] = True
        self.livecdInstall = False
        self.ibft = True
        self.nonibftiscsiboot = False
        self.usevnc = False
        self.vncquestion = True
        self.mpath = True
        self.dmraid = True

        self.selinux = SELINUX_DEFAULT

        if not selinux.is_selinux_enabled():
            self.selinux = SELINUX_DISABLED

        self.debug = False
        self.armPlatform = None
        self.preexisting_x11 = False
        self.noverifyssl = False
        self.imageInstall = False
        self.automatedInstall = False
        self.dirInstall = False
        self.askmethod = False
        self.eject = True
        self.extlinux = False
        self.nombr = False
        self.gpt = False
        self.leavebootorder = False
        self.mpathFriendlyNames = True
        # ksprompt is whether or not to prompt for missing ksdata
        self.ksprompt = True
        self.rescue_mode = False
        self.kexec = False
        # nosave options
        self.nosave_input_ks = False
        self.nosave_output_ks = False
        self.nosave_logs = False
        # single language options
        self.singlelang = False
        # enable SE/HMC
        self.hmc = False
        # current runtime environments
        self.environs = [ANACONDA_ENVIRON]
        # parse the boot commandline
        self.cmdline = KernelArguments.from_defaults()
        # Lock it down: no more creating new flags!
        self.__dict__['_in_init'] = False
예제 #20
0
    def test_items_raw(self):
        """Test KernelArguments access to raw contents with iterator."""

        ka = KernelArguments.from_string(
            "blah inst.foo=anything inst.nothing=indeed")
        it = ka.items_raw()

        self.assertIsInstance(it, Iterable)

        res = dict()
        for k, v in it:
            res[k] = v

        self.assertIn("inst.foo", res)
        self.assertIn("blah", res)
        self.assertIn("inst.nothing", res)

        self.assertEqual(res["inst.nothing"], "indeed")
예제 #21
0
    def test_items_raw(self):
        """Test KernelArguments access to raw contents with iterator."""

        ka = KernelArguments.from_string(
            "blah inst.foo=anything inst.nothing=indeed")
        it = ka.items_raw()

        assert isinstance(it, Iterable)

        res = dict()
        for k, v in it:
            res[k] = v

        assert "inst.foo" in res
        assert "blah" in res
        assert "inst.nothing" in res

        assert res["inst.nothing"] == "indeed"
예제 #22
0
    def parse_boot_cmdline(self, boot_cmdline):
        """
        Parse the boot cmdline and create an appropriate Namespace instance
        according to the option definitions set by add_argument.

        boot_cmdline can be given as a string (to be parsed by KernelArguments), or a
        dict (or any object with .items()) of {bootarg:value} pairs.

        If boot_cmdline is None, the boot_cmdline data will be whatever KernelArguments reads
        by default (/proc/cmdline, /run/initramfs/etc/cmdline, /etc/cmdline).

        If an option requires a value but the boot arg doesn't provide one,
        we'll quietly not set anything in the Namespace. We also skip any boot options
        that were not specified by add_argument as we don't care about them
        (there will usually be quite a lot of them (rd.*, etc.).

        :param boot_cmdline: the Anaconda boot command line arguments
        :type boot_cmdline: string, dict or None

        :returns: an argparse Namespace instance
        :rtype: Namespace
        """
        namespace = Namespace()

        if boot_cmdline is None:
            bootargs = KernelArguments.from_defaults()
        elif isinstance(boot_cmdline, str):
            bootargs = KernelArguments.from_string(boot_cmdline)
        else:
            bootargs = boot_cmdline

        self.deprecated_bootargs = []
        # go over all options corresponding to current boot cmdline
        # and do any modifications necessary
        # NOTE: program cmdline overrides boot cmdline
        for arg, val in bootargs.items():
            option = self._get_bootarg_option(arg)
            if option is None:
                # this boot option is unknown to Anaconda, skip it
                continue
            if option.nargs != 0 and val is None:
                # nargs == 0 -> the option expects one or more arguments but the
                # boot option was not given any, so we skip it
                log.warning(
                    "boot option specified without expected number of "
                    "arguments and will be ignored: %s", arg)
                continue
            elif option.nargs == 0 and option.const is not None:
                # nargs == 0 & constr == True -> store_true
                # (we could also check the class, but it begins with an
                # underscore, so it would be ugly)
                # special case: "mpath=0" would otherwise set mpath to True
                if option.const is True and val in ("0", "no", "off"):
                    setattr(namespace, option.dest, False)
                # Set all other set_const cases to the const specified
                else:
                    setattr(namespace, option.dest, option.const)

                # anaconda considers cases such as noselinux=off to be a negative
                # concord, which is to say that selinux will be set to False and
                # we hate you.

                continue
            elif type(val) is list:
                for item in val:
                    option(self, namespace, item)
                continue

            option(self, namespace, val)
        return namespace
예제 #23
0
    def parse_boot_cmdline(self, boot_cmdline):
        """
        Parse the boot cmdline and create an appropriate Namespace instance
        according to the option definitions set by add_argument.

        boot_cmdline can be given as a string (to be parsed by KernelArguments), or a
        dict (or any object with .items()) of {bootarg:value} pairs.

        If boot_cmdline is None, the boot_cmdline data will be whatever KernelArguments reads
        by default (/proc/cmdline, /run/initramfs/etc/cmdline, /etc/cmdline).

        If an option requires a value but the boot arg doesn't provide one,
        we'll quietly not set anything in the Namespace. We also skip any boot options
        that were not specified by add_argument as we don't care about them
        (there will usually be quite a lot of them (rd.*, etc.).

        :param boot_cmdline: the Anaconda boot command line arguments
        :type boot_cmdline: string, dict or None

        :returns: an argparse Namespace instance
        :rtype: Namespace
        """
        namespace = Namespace()

        if boot_cmdline is None:
            bootargs = KernelArguments.from_defaults()
        elif isinstance(boot_cmdline, str):
            bootargs = KernelArguments.from_string(boot_cmdline)
        else:
            bootargs = boot_cmdline

        self.deprecated_bootargs = []
        # go over all options corresponding to current boot cmdline
        # and do any modifications necessary
        # NOTE: program cmdline overrides boot cmdline
        for arg, val in bootargs.items():
            option = self._get_bootarg_option(arg)
            if option is None:
                # this boot option is unknown to Anaconda, skip it
                continue
            if option.nargs != 0 and val is None:
                # nargs == 0 -> the option expects one or more arguments but the
                # boot option was not given any, so we skip it
                log.warning("boot option specified without expected number of "
                            "arguments and will be ignored: %s", arg)
                continue
            elif option.nargs == 0 and option.const is not None:
                # nargs == 0 & constr == True -> store_true
                # (we could also check the class, but it begins with an
                # underscore, so it would be ugly)
                # special case: "mpath=0" would otherwise set mpath to True
                if option.const is True and val in ("0", "no", "off"):
                    setattr(namespace, option.dest, False)
                # Set all other set_const cases to the const specified
                else:
                    setattr(namespace, option.dest, option.const)

                # anaconda considers cases such as noselinux=off to be a negative
                # concord, which is to say that selinux will be set to False and
                # we hate you.

                continue
            elif type(val) is list:
                for item in val:
                    option(self, namespace, item)
                continue

            option(self, namespace, val)
        return namespace