def test_raising_kickstarts_split(self):
     """Test of kickstarts expected to raise KickstartParseError."""
     valid_sections = VALID_SECTIONS_ANACONDA
     handler = makeVersion()
     ksparser = SplitKickstartParser(handler, valid_sections)
     for kickstart_files in self._flat_kickstarts_raising:
         _filename, content = kickstart_files[0]
         with pytest.raises(KickstartParseError):
             ksparser.split_from_string(content)
Esempio n. 2
0
    def test_missing_include(self):
        """Test behaviour for missing kickstart include files."""
        ks_content = """
network --device=ens3
%include missing_include.cfg
""".strip()

        handler = makeVersion()
        ksparser = SplitKickstartParser(handler)
        # By default raises error
        self.assertRaises(KickstartError, ksparser.split_from_string, ks_content)
        # But can be configured not to
        ksparser = SplitKickstartParser(handler, missing_include_is_fatal=False)
        ksparser.split_from_string(ks_content)
    def test_split_from_string_filename(self):
        """Test splitting kickstart supplied by string."""
        valid_sections = VALID_SECTIONS_ANACONDA
        handler = makeVersion()
        ksparser = SplitKickstartParser(handler, valid_sections)

        kickstart_files, _output = self._kickstart_flat
        filename, content = kickstart_files[0]

        # Kickstart from string has "<MAIN>" as filename
        result = ksparser.split_from_string(content)
        for element in result.all_elements:
            assert element.filename == SplitKickstartParser.unknown_filename
        # Or the value supplied by filename optional argument
        result = ksparser.split_from_string(content, filename=filename)
        for element in result.all_elements:
            assert element.filename == filename
Esempio n. 4
0
    def test_valid_sections(self):
        """Test setting of valid sections for the parser."""
        valid_sections = VALID_SECTIONS_ANACONDA
        handler = makeVersion()
        ksparser = SplitKickstartParser(handler, valid_sections)
        kickstart_files, _output = self._kickstart_flat
        _filename, content = kickstart_files[0]

        returned_valid_sections = ksparser.valid_sections
        # valid_sections returns new list, not a reference to the internal object
        returned_valid_sections.append("%test")
        self.assertNotEqual(returned_valid_sections, ksparser.valid_sections)

        ksparser.valid_sections = ["%packages"]
        # Invalid section raises exception
        self.assertRaises(KickstartParseError, ksparser.split_from_string, content)
        # setting valid sections back to the original, the exception is gone
        ksparser.valid_sections = valid_sections
        ksparser.split_from_string(content)
    def test_invalid_command(self):
        """Test invalid command or option in kickstart.

        Invalid command or command option in kickstart does not raise
        KickstartParseError because commands are not parsed in the filter.
        """
        ks_content = """
network --device=ens3 --activate
netork --device=ens5 --activate
network --device=ens7 --activate
network --devce=ens9 --activate
""".strip()

        handler = makeVersion()
        ksparser = SplitKickstartParser(handler)
        result = ksparser.split_from_string(ks_content)
        assert len(result.all_elements) == 4
    def test_conflicting_commands(self):
        """Test conflicting commands in kickstart.

        Conflicting commands in kickstart do not raise KickstartParseError
        because commands are not parsed in the filter.
        """
        ks_content = """
# Partitioning conflicts with autopart
part /boot --fstype=xfs --onpart=vda1
part pv.100000 --size=18436 --ondisk=vda
volgroup Vol00 --pesize=4096 pv.100000
logvol / --fstype=xfs --name=lv_root --vgname=Vol00 --size=15360
logvol /home --fstype=xfs --name=lv_home --vgname=Vol00 --size=1024
logvol swap --fstype=swap --name=lv_swap --vgname=Vol00 --size=2048

autopart --encrypted --passphrase=starost --type=lvm
""".strip()

        handler = makeVersion()
        ksparser = SplitKickstartParser(handler)
        result = ksparser.split_from_string(ks_content)
        assert len(result.all_elements) == 7
    def test_simple_split_kickstart_parser(self):
        """This test should demonstrate usage and output of the parser."""
        ks_content = """
%pre
echo PRE
%end
network --device=ens3 --activate
network --device=ens4 --activate
%addon pony --fly=True
%end
firewall --enabled
%addon scorched --planet=Earth
nuke
%end
%post --nochroot --interpreter /usr/bin/bash
echo POST1
%end
""".lstrip()

        element1 = ("pre", "%pre\necho PRE\n%end\n", 1)
        element2 = ("network", "network --device=ens3 --activate\n", 4)
        element3 = ("network", "network --device=ens4 --activate\n", 5)
        element4 = ("pony", "%addon pony --fly=True\n%end\n", 6)
        element5 = ("firewall", "firewall --enabled\n", 8)
        element6 = ("scorched", "%addon scorched --planet=Earth\nnuke\n%end\n",
                    9)
        element7 = (
            "post",
            "%post --nochroot --interpreter /usr/bin/bash\necho POST1\n%end\n",
            12)
        expected_result = [
            element1, element2, element3, element4, element5, element6,
            element7
        ]

        filename = "ks.test.simple.cfg"

        valid_sections = VALID_SECTIONS_ANACONDA

        handler = makeVersion()
        ksparser = SplitKickstartParser(handler, valid_sections)

        # Reading kickstart from file

        with open(filename, "w") as f:
            f.write(ks_content)
        result = ksparser.split(filename)
        os.remove(filename)

        for element, expected in zip(result.all_elements, expected_result):
            assert element.filename == filename
            assert (element.name, element.content, element.lineno) == expected

        assert result.get_kickstart_from_elements(
            result.all_elements) == ks_content

        # Reading kickstart from string

        filename = ksparser.unknown_filename
        result = ksparser.split_from_string(ks_content)

        for element, expected in zip(result.all_elements, expected_result):
            assert element.filename == filename
            assert (element.name, element.content, element.lineno) == expected

        assert result.get_kickstart_from_elements(
            result.all_elements) == ks_content

        # Reading kickstart from string supplying filename

        filename = "MY_FILENAME"
        result = ksparser.split_from_string(ks_content, filename=filename)

        for element, expected in zip(result.all_elements, expected_result):
            assert element.filename == filename
            assert (element.name, element.content, element.lineno) == expected

        # Dumping kickstart

        assert result.get_kickstart_from_elements(
            result.all_elements) == ks_content