Beispiel #1
0
    def __init__(self):
        super().__init__()
        self._created_payloads = []
        self.created_payloads_changed = Signal()

        self._active_payload = None
        self.active_payload_changed = Signal()

        self._packages = PackagesModule()
Beispiel #2
0
    def __init__(self):
        super().__init__()
        self._payload = None

        self._packages = PackagesModule()
Beispiel #3
0
class PayloadsService(KickstartService):
    """The Payload service."""

    def __init__(self):
        super().__init__()
        self._payload = None

        self._packages = PackagesModule()

    def publish(self):
        """Publish the module."""
        TaskContainer.set_namespace(PAYLOADS.namespace)

        self._packages.publish()

        DBus.publish_object(PAYLOADS.object_path, PayloadsInterface(self))
        DBus.register_service(PAYLOADS.service_name)

    @property
    def kickstart_specification(self):
        """Return the kickstart specification."""
        return PayloadKickstartSpecification

    @property
    def payload(self):
        """Get payload.

        Payloads are handling the installation process.

        FIXME: Replace this solution by something extensible for multiple payload support.
               Could it be SetPayloads() and using this list to set order of payload installation?

        There are a few types of payloads e.g.: DNF, LiveImage...
        """
        if self._payload is None:
            raise PayloadNotSetError()
        else:
            return self._payload

    def set_payload(self, payload):
        """Set payload."""
        self._payload = payload
        log.debug("Payload %s used.", payload.__class__.__name__)

    def is_payload_set(self):
        """Test if any payload is created and used.

        :rtype: bool
        """
        return self._payload is not None

    def get_active_payload(self):
        """Get active payload.

        FIXME: Merge get_active_payload and payload property. They are doing the same.

        :rtype: instance of active payload
        :raise: PayloadNotSetError if no payload is set
        """
        return self.payload

    def process_kickstart(self, data):
        """Process the kickstart data."""
        log.debug("Processing kickstart data...")

        # create payload if no payload is set already
        if not self.is_payload_set():
            payload = PayloadFactory.create_from_ks_data(data)
            if not payload:
                log.warning("No payload was created. Kickstart data passed in are lost.")
                return

        payload.process_kickstart(data)

        self._packages.process_kickstart(data)

        self.set_payload(payload)
        PayloadContainer.to_object_path(payload)

    def generate_kickstart(self):
        """Return the kickstart string."""
        log.debug("Generating kickstart data...")
        return ""

    def generate_temporary_kickstart(self):
        """Return the kickstart string."""
        log.debug("Generating kickstart data...")
        data = self.get_kickstart_handler()

        try:
            self.payload.setup_kickstart(data)
        except PayloadNotSetError:
            log.warning("Generating kickstart data without payload set - data will be empty!")

        # generate packages section only for DNF module
        if isinstance(self.payload, DNFModule):
            self._packages.setup_kickstart(data)

        return str(data)

    def create_payload(self, payload_type):
        """Create payload based on the passed type.

        :param payload_type: type of the desirable payload
        :type payload_type: value of the payload.base.constants.PayloadType enum
        """
        payload = PayloadFactory.create(payload_type)
        self.set_payload(payload)
        return payload

    def create_source(self, source_type):
        """Create source based on the passed type.

        :param source_type: type of the desirable source
        :type source_type: value of the payload.base.constants.SourceType enum
        """
        return SourceFactory.create(source_type)
Beispiel #4
0
    def setUp(self):
        self.packages_module = PackagesModule()
        self.packages_interface = PackagesInterface(self.packages_module)

        self.callback = PropertiesChangedCallback()
        self.packages_interface.PropertiesChanged.connect(self.callback)
Beispiel #5
0
class PayloadsService(KickstartService):
    """The Payload service."""

    def __init__(self):
        super().__init__()
        self._created_payloads = []
        self.created_payloads_changed = Signal()

        self._active_payload = None
        self.active_payload_changed = Signal()

        self._packages = PackagesModule()

    def publish(self):
        """Publish the module."""
        TaskContainer.set_namespace(PAYLOADS.namespace)

        self._packages.publish()

        DBus.publish_object(PAYLOADS.object_path, PayloadsInterface(self))
        DBus.register_service(PAYLOADS.service_name)

    @property
    def kickstart_specification(self):
        """Return the kickstart specification."""
        return PayloadKickstartSpecification

    @property
    def created_payloads(self):
        """List of all created payload modules."""
        return self._created_payloads

    def _add_created_payload(self, module):
        """Add a created payload module."""
        self._created_payloads.append(module)
        self.created_payloads_changed.emit(module)
        log.debug("Created the payload %s.", module.type)

    @property
    def active_payload(self):
        """The active payload.

        Payloads are handling the installation process.

        FIXME: Replace this solution by something extensible for multiple payload support.
               Could it be SetPayloads() and using this list to set order of payload installation?

        There are a few types of payloads e.g.: DNF, LiveImage...

        :return: a payload module or None
        """
        return self._active_payload

    def activate_payload(self, payload):
        """Activate the payload."""
        self._active_payload = payload
        self.active_payload_changed.emit()
        log.debug("Activated the payload %s.", payload.type)

    def process_kickstart(self, data):
        """Process the kickstart data."""
        # Create a new payload module.
        payload_type = PayloadFactory.get_type_for_kickstart(data)

        if payload_type:
            payload_module = self.create_payload(payload_type)
            payload_module.process_kickstart(data)
            self.activate_payload(payload_module)

    def setup_kickstart(self, data):
        """Set up the kickstart data."""
        if self.active_payload:
            self.active_payload.setup_kickstart(data)

    def generate_kickstart(self):
        """Return a kickstart string."""
        # FIXME: This is a temporary workaround for RPM sources.
        if self.active_payload and self.active_payload.type != PayloadType.DNF:
            log.debug("Generating kickstart... (skip)")
            return ""

        return super().generate_kickstart()

    def generate_temporary_kickstart(self):
        """Return the temporary kickstart string."""
        # FIXME: This is a temporary workaround for testing.
        return super().generate_kickstart()

    def create_payload(self, payload_type):
        """Create payload based on the passed type.

        :param payload_type: type of the desirable payload
        :type payload_type: value of the payload.base.constants.PayloadType enum
        """
        payload = PayloadFactory.create_payload(payload_type)
        self._add_created_payload(payload)
        return payload

    def create_source(self, source_type):
        """Create source based on the passed type.

        :param source_type: type of the desirable source
        :type source_type: value of the payload.base.constants.SourceType enum
        """
        return SourceFactory.create_source(source_type)