Example #1
0
    def runTest(self):

        # Test that everything in version.versionMap has a handler, except
        # for DEVEL.
        for (name, vers) in list(versionMap.items()):
            if name == "DEVEL":
                continue

            self.assertEqual(returnClassForVersion(vers).version, vers)

        # test that unknown version will raise an exception
        import pykickstart.version as ver
        orig_versionToString = ver.versionToString
        with self.assertRaises(KickstartVersionError):
            def fake_versionToString(version, skipDevel=False):
                return "-1"

            ver.versionToString = fake_versionToString
            ver.returnClassForVersion(-1)
        ver.versionToString = orig_versionToString

        # Load the handlers
        _path = os.path.join(os.path.dirname(__file__), "..", "pykickstart", "handlers")
        _path = os.path.abspath(_path)
        for module in loadModules(_path, cls_pattern="Handler", skip_list=["control"]):
            if module.__name__.endswith("Handler") and module.__name__ not in ["BaseHandler"]:
                # What is the version of the handler?
                vers = module.__name__.replace("Handler", "")
                self.assertTrue(vers in versionMap)
                # Ensure that returnClassForVersion returns what we expect
                self.assertEqual(getClassName(returnClassForVersion(versionMap[vers])), getClassName(module))
Example #2
0
def read_kickstart(path):
    """Parse a kickstart file and return a KickstartParser instance.

    This is a simple utility function which takes a path to a kickstart file,
    parses it and returns a pykickstart KickstartParser instance which can
    be then passed to an ImageCreator constructor.

    If an error occurs, a CreatorError exception is thrown.
    """

    # version = ksversion.makeVersion()
    # ks = ksparser.KickstartParser(version)

    using_version = ksversion.DEVEL
    commandMap[using_version]["bootloader"] = wicboot.Wic_Bootloader
    commandMap[using_version]["part"] = partition.Wic_Partition
    commandMap[using_version]["partition"] = partition.Wic_Partition
    dataMap[using_version]["PartData"] = partition.Wic_PartData
    superclass = ksversion.returnClassForVersion(version=using_version)

    class KSHandlers(superclass):
        def __init__(self):
            superclass.__init__(self, mapping=commandMap[using_version])

    kickstart = ksparser.KickstartParser(KSHandlers(), errorsAreFatal=True)

    try:
        kickstart.readKickstart(path)
    except (kserrors.KickstartParseError, kserrors.KickstartError), err:
        msger.warning("Errors occurred when parsing kickstart file: %s\n" % path)
        msger.error("%s" % err)
Example #3
0
File: __init__.py Project: csdb/mic
def read_kickstart(path):
    """Parse a kickstart file and return a KickstartParser instance.

    This is a simple utility function which takes a path to a kickstart file,
    parses it and returns a pykickstart KickstartParser instance which can
    be then passed to an ImageCreator constructor.

    If an error occurs, a CreatorError exception is thrown.

    """
    #version = ksversion.makeVersion()
    #ks = ksparser.KickstartParser(version)

    using_version = ksversion.DEVEL
    commandMap[using_version]["desktop"] = desktop.Moblin_Desktop
    commandMap[using_version]["repo"] = moblinrepo.Moblin_Repo
    commandMap[using_version]["bootloader"] = micboot.Moblin_Bootloader
    dataMap[using_version]["RepoData"] = moblinrepo.Moblin_RepoData
    superclass = ksversion.returnClassForVersion(version=using_version)

    class KSHandlers(superclass):
        def __init__(self, mapping={}):
            superclass.__init__(self, mapping=commandMap[using_version])

    ks = ksparser.KickstartParser(KSHandlers())

    try:
        ks.readKickstart(path)
    except kserrors.KickstartError, e:
        raise errors.KsError("'%s': %s" % (path, str(e)))
Example #4
0
    def test_bootloader_in_kickstart(self):
        '''
        test that a bootloader such as prepboot/biosboot shows up
        in the kickstart data
        '''

        with patch('blivet.osinstall.InstallerStorage.bootloader_device', new_callable=PropertyMock) as mock_bootloader_device:
            with patch('blivet.osinstall.InstallerStorage.mountpoints', new_callable=PropertyMock) as mock_mountpoints:
                # set up prepboot partition
                bootloader_device_obj = PartitionDevice("test_partition_device")
                bootloader_device_obj.size = Size('5 MiB')
                bootloader_device_obj.format = formats.get_format("prepboot")

                blivet_obj = InstallerStorage()

                # mountpoints must exist for update_ksdata to run
                mock_bootloader_device.return_value = bootloader_device_obj
                mock_mountpoints.values.return_value = []

                # initialize ksdata
                test_ksdata = returnClassForVersion()()
                blivet_obj.ksdata = test_ksdata
                blivet_obj.update_ksdata()

        self.assertTrue("part prepboot" in str(blivet_obj.ksdata))
Example #5
0
def build_kickstart(base_ks, packages=[], groups=[], projects=[]):
    """Build a kickstart file using the handler class, with custom kickstart,
    packages, groups and projects.

    :param base_ks: Full path to the original kickstart file
    :param packages: list of packagenames
    :param groups: list of groupnames
    :param projects: list of rpm repository URLs

    :returns: Validated kickstart with any extra packages, groups or repourls
       added
    """
    ver = ksversion.DEVEL
    commandMap[ver]["desktop"] = Moblin_Desktop
    commandMap[ver]["repo"] = Moblin_Repo
    commandMap[ver]["bootloader"] = Moblin_Bootloader
    commandMap[ver]["btrfs"] = BTRFS

    dataMap[ver]["RepoData"] = Moblin_RepoData
    dataMap[ver]["PartData"] = MeeGo_PartData
    dataMap[ver]["BTRFSData"] = BTRFSData

    superclass = ksversion.returnClassForVersion(version=ver)

    class KSHandlers(superclass):
        def __init__(self, mapping={}):
            superclass.__init__(
                self, mapping=commandMap[ver], dataMapping=dataMap[ver])
            self.prepackages = PrePackages()
            self.attachment = Attachment()

        def __str__(self):
            retval = superclass.__str__(self)
            if self.prepackages:
                retval += self.prepackages.__str__()
            if self.attachment:
                retval += self.attachment.__str__()
            return retval

    ks = ksparser.KickstartParser(KSHandlers(), errorsAreFatal=False)
    ks.registerSection(PackScriptSection(ks.handler, dataObj=PackScript))
    ks.registerSection(PrepackageSection(ks.handler))
    ks.registerSection(AttachmentSection(ks.handler))

    ks.readKickstart(str(base_ks))
    ks.handler.packages.add(packages)
    ks.handler.packages.add(groups)
    for prj in projects:
        name = urlparse(prj).path
        name = name.replace(":/", "_")
        name = name.replace("/", "_")
        name = re.sub('@[A-Z]*@', '_', name)
        repo = Moblin_RepoData(baseurl=prj, name=name, save=True)
        ks.handler.repo.repoList.append(repo)

    ks_txt = str(ks.handler)
    return ks_txt
Example #6
0
    def runTest(self):
        try:
            # will force another import
            del sys.modules['pykickstart.version']
            del sys.modules['importlib']

            import pykickstart.version as ver
            from pykickstart.handlers.f23 import F23Handler

            cls = ver.returnClassForVersion(ver.F23)

            # assert the names; b/c of how the importlib.import_module() works
            # asserting both classes being equal fails
            self.assertEqual(cls.__name__, F23Handler.__name__)
        finally:
            # force import to reload these modules
            del sys.modules['pykickstart.version']
            del sys.modules['importlib']
Example #7
0
File: __init__.py Project: lbt/mic
def read_kickstart(path):
    """Parse a kickstart file and return a KickstartParser instance.

    This is a simple utility function which takes a path to a kickstart file,
    parses it and returns a pykickstart KickstartParser instance which can
    be then passed to an ImageCreator constructor.

    If an error occurs, a CreatorError exception is thrown.
    """

    #version = ksversion.makeVersion()
    #ks = ksparser.KickstartParser(version)

    using_version = ksversion.DEVEL
    commandMap[using_version]["desktop"] = desktop.Moblin_Desktop
    commandMap[using_version]["repo"] = moblinrepo.Moblin_Repo
    commandMap[using_version]["bootloader"] = micboot.Moblin_Bootloader
    commandMap[using_version]["part"] = partition.MeeGo_Partition
    commandMap[using_version]["partition"] = partition.MeeGo_Partition
    dataMap[using_version]["RepoData"] = moblinrepo.Moblin_RepoData
    dataMap[using_version]["PartData"] = partition.MeeGo_PartData
    superclass = ksversion.returnClassForVersion(version=using_version)

    class KSHandlers(superclass):
        def __init__(self, mapping={}):
            superclass.__init__(self, mapping=commandMap[using_version])
            self.prepackages = ksparser.Packages()
            self.attachment = ksparser.Packages()

    ks = ksparser.KickstartParser(KSHandlers())
    ks.registerSection(PrepackageSection(ks.handler))
    ks.registerSection(AttachmentSection(ks.handler))

    try:
        ks.readKickstart(path)
    except kserrors.KickstartParseError, e:
        msgptn = re.compile("^\D*(\d+).*(Section does not end with.*)$", re.S)
        m = msgptn.match(str(e))
        if m:
            lineno = m.group(1)
            wrnmsg = m.group(2)
            msger.warning("'%s:%s': %s" % (path, lineno, wrnmsg))
        else:
            raise errors.KsError("'%s': %s" % (path, str(e)))
Example #8
0
def read_kickstart(path):
    """Parse a kickstart file and return a KickstartParser instance.

    This is a simple utility function which takes a path to a kickstart file,
    parses it and returns a pykickstart KickstartParser instance which can
    be then passed to an ImageCreator constructor.

    If an error occurs, a CreatorError exception is thrown.
    """

    #version = ksversion.makeVersion()
    #ks = ksparser.KickstartParser(version)

    using_version = ksversion.DEVEL
    commandMap[using_version]["desktop"] = desktop.Mic_Desktop
    commandMap[using_version]["repo"] = micrepo.Mic_Repo
    commandMap[using_version]["bootloader"] = micboot.Mic_Bootloader
    commandMap[using_version]["part"] = partition.Mic_Partition
    commandMap[using_version]["partition"] = partition.Mic_Partition
    commandMap[using_version]["installerfw_plugins"] = installerfw.Mic_installerfw
    dataMap[using_version]["RepoData"] = micrepo.Mic_RepoData
    dataMap[using_version]["PartData"] = partition.Mic_PartData
    superclass = ksversion.returnClassForVersion(version=using_version)

    class KSHandlers(superclass):
        def __init__(self):
            superclass.__init__(self, mapping=commandMap[using_version])
            self.prepackages = ksparser.Packages()
            self.attachment = ksparser.Packages()

    ks = ksparser.KickstartParser(KSHandlers(), errorsAreFatal=False)
    ks.registerSection(PrepackageSection(ks.handler))
    ks.registerSection(AttachmentSection(ks.handler))

    try:
        ks.readKickstart(path)
    except (kserrors.KickstartParseError, kserrors.KickstartError), err:
        if msger.ask("Errors occured on kickstart file, skip and continue?"):
            msger.warning("%s" % err)
            pass
        else:
            raise errors.KsError("%s" % err)
Example #9
0
 def handler(self):
     return returnClassForVersion(DEVEL)
Example #10
0
 def handler(self):
     version = self.__class__.__name__.split("_")[0]
     return returnClassForVersion(version)
Example #11
0
    "sshkey": SshKey,
    "skipx": UselessCommand,
    "snapshot": Snapshot,
    "timezone": Timezone,
    "user": User,
    "volgroup": VolGroup,
    "xconfig": XConfig,
    "zerombr": UselessCommand,
    "zfcp": UselessCommand,
}

dataMap = {
    "RepoData": RepoData,
}

superclass = returnClassForVersion(VERSION)

class AnacondaKSHandler(superclass):
    AddonClassType = AddonData

    def __init__(self, addon_paths=None, commandUpdates=None, dataUpdates=None):
        if addon_paths is None:
            addon_paths = []

        if commandUpdates is None:
            commandUpdates = commandMap

        if dataUpdates is None:
            dataUpdates = dataMap

        super().__init__(commandUpdates=commandUpdates, dataUpdates=dataUpdates)
Example #12
0
        return retval

class MeeGo_Partition(FC4_Partition):
    removedKeywords = FC4_Partition.removedKeywords
    removedAttrs = FC4_Partition.removedAttrs

    def _getParser(self):
        op = FC4_Partition._getParser(self)
        # The alignment value is given in kBytes. e.g., value 8 means that
        # the partition is aligned to start from 8096 byte boundary.
        op.add_option("--align", type="int", action="store", dest="align",
                      default=None)
        return op
#################################################################

KSCLASS = ksversion.returnClassForVersion(version=ksversion.DEVEL)

class KSHandlers(KSCLASS):
    """Helper class for parsing a kickstart file"""
    def __init__(self):
        ver = ksversion.DEVEL
        commandMap[ver]["desktop"] = Moblin_Desktop
        commandMap[ver]["repo"] = Moblin_Repo
        commandMap[ver]["bootloader"] = Moblin_Bootloader
        dataMap[ver]["RepoData"] = Moblin_RepoData
        KSCLASS.__init__(self, mapping=commandMap[ver])
    
def build_kickstart(base_ks, packages=[], groups=[], projects=[]):
    """Build a kickstart file using the handler class, with custom kickstart,
    packages, groups and projects.
Example #13
0
    "sshkey": UselessCommand,
    "skipx": UselessCommand,
    "snapshot": UselessCommand,
    "timezone": UselessCommand,
    "user": UselessCommand,
    "volgroup": UselessCommand,
    "xconfig": UselessCommand,
    "zerombr": UselessCommand,
    "zfcp": UselessCommand,
}

dataMap = {
    "RepoData": RepoData,
}

superclass = returnClassForVersion(VERSION)


class AnacondaKSHandler(superclass):
    AddonClassType = AddonData

    def __init__(self,
                 addon_paths=None,
                 commandUpdates=None,
                 dataUpdates=None):
        if addon_paths is None:
            addon_paths = []

        if commandUpdates is None:
            commandUpdates = commandMap
Example #14
0
 def handler(self):
     version = self.__class__.__name__.split("_")[0]
     return returnClassForVersion(version)
Example #15
0
 def handler(self):
     return returnClassForVersion(DEVEL)