def set_when_initialized_source_fail_test(self, publisher):
        """Test LiveOS payload can't set new sources if the old ones are initialized."""
        source1 = self._prepare_source()
        source2 = self._prepare_source()

        path = PayloadSourceContainer.to_object_path(source1)
        path2 = PayloadSourceContainer.to_object_path(source2)

        self.live_os_interface.SetSources([path])
        source1.is_ready.return_value = True

        with self.assertRaises(SourceSetupError):
            self.live_os_interface.SetSources([path2])
Esempio n. 2
0
    def CreateSource(self, source_type: Str) -> ObjPath:
        """Create payload source and publish it on DBus.

        source_type could contain these values:
         - LIVE_OS_IMAGE
        """
        return PayloadSourceContainer.to_object_path(
            self.implementation.create_source(SourceType(source_type)))
    def check_sources(self, expected_sources=None):
        """Check what sources are set in payload.

        :param expected_sources: list of expected sources after trying to set;
                                 including when exception raised
        :type expected_sources: list of source instances
        """
        expected_paths = PayloadSourceContainer.to_object_path_list(
            expected_sources)

        self._test.assertEqual(self.payload_interface.Sources, expected_paths)
Esempio n. 4
0
    def SetSources(self, sources: List[ObjPath]):
        """Attach list of sources to this payload.

        Before setting the sources, please make sure the sources are not initialized otherwise
        the SourceSetupError exception will be raised. Payload has to cleanup after itself.

        ..NOTE:
        The SourceSetupError is a reasonable effort to solve the race condition. However,
        there is still a possibility that the task to initialize sources (`SetupSourcesWithTask()`)
        was created with the old list but not run yet. In that case this check will not work and
        the initialization task will run with the old list.

        :raise: IncompatibleSourceError when source is not a supported type
                SourceSetupError when attached sources are initialized
        """
        self.implementation.set_sources(
            PayloadSourceContainer.from_object_path_list(sources))
    def set_sources(self, test_sources, exception=None):
        """Set sources to payload.

        :param test_sources: list of sources for emptiness failed check
        :type test_sources: list of source instances
        :param exception: exception class which will be raised for the given sources
        :return: caught exception if exception raised
        """
        paths = PayloadSourceContainer.to_object_path_list(test_sources)

        if exception:
            with self._test.assertRaises(exception) as cm:
                self.payload_interface.SetSources(paths)
            return cm

        self.payload_interface.SetSources(paths)
        return None
Esempio n. 6
0
    def check_set_sources(self, test_sources, exception=None):
        """Default check to set sources.

        :param test_sources: list of sources for emptiness failed check
        :param exception: exception class which will be raised for the given sources
        """
        paths = PayloadSourceContainer.to_object_path_list(test_sources)

        if exception:
            with self._test.assertRaises(exception):
                self.payload_interface.SetSources(paths)

            self._test.assertEqual(self.payload_interface.Sources, [])
            self._test.assertFalse(self.payload_interface.HasSource())
        else:
            self.payload_interface.SetSources(paths)

            self._test.assertEqual(self.payload_interface.Sources, paths)
            self._test.assertTrue(self.payload_interface.HasSource())
 def Sources(self) -> List[ObjPath]:
     """Get list of sources attached to this payload."""
     return PayloadSourceContainer.to_object_path_list(
         self.implementation.sources
     )