def split(self, path): """Split the kickstart given by path into elements.""" self._elements = None self._kickstart_path = path handler = makeVersion() ksparser = SplitKickstartParser(handler, valid_sections=VALID_SECTIONS_ANACONDA) try: result = ksparser.split(path) except KickstartParseError as e: raise SplitKickstartSectionParsingError(e) except KickstartError as e: raise SplitKickstartMissingIncludeError(e) self._elements = result
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
def _split_to_elements(self, path): """Split the kickstart given by path into elements.""" handler = makeVersion() parser = SplitKickstartParser(handler, valid_sections=VALID_SECTIONS_ANACONDA) return parser.split(path)