Exemplo n.º 1
0
    def create_source(source_type: SourceType):
        """Create a source module.

        :param source_type: a source type
        :return: a source module
        """
        if source_type == SourceType.LIVE_OS_IMAGE:
            from pyanaconda.modules.payloads.source.live_os.live_os import LiveOSSourceModule
            return LiveOSSourceModule()
        elif source_type == SourceType.LIVE_IMAGE:
            from pyanaconda.modules.payloads.source.live_image.live_image import \
                LiveImageSourceModule
            return LiveImageSourceModule()
        elif source_type == SourceType.LIVE_TAR:
            from pyanaconda.modules.payloads.source.live_tar.live_tar import LiveTarSourceModule
            return LiveTarSourceModule()
        elif source_type == SourceType.CDROM:
            from pyanaconda.modules.payloads.source.cdrom.cdrom import CdromSourceModule
            return CdromSourceModule()
        elif source_type == SourceType.HMC:
            from pyanaconda.modules.payloads.source.hmc.hmc import HMCSourceModule
            return HMCSourceModule()
        elif source_type == SourceType.REPO_FILES:
            from pyanaconda.modules.payloads.source.repo_files.repo_files import \
                RepoFilesSourceModule
            return RepoFilesSourceModule()
        elif source_type == SourceType.NFS:
            from pyanaconda.modules.payloads.source.nfs.nfs import NFSSourceModule
            return NFSSourceModule()
        elif source_type == SourceType.URL:
            from pyanaconda.modules.payloads.source.url.url import URLSourceModule
            return URLSourceModule()
        elif source_type == SourceType.HDD:
            from pyanaconda.modules.payloads.source.harddrive.harddrive import \
                HardDriveSourceModule
            return HardDriveSourceModule()
        elif source_type == SourceType.CDN:
            from pyanaconda.modules.payloads.source.cdn.cdn import CDNSourceModule
            return CDNSourceModule()
        elif source_type == SourceType.CLOSEST_MIRROR:
            from pyanaconda.modules.payloads.source.closest_mirror.closest_mirror import \
                ClosestMirrorSourceModule
            return ClosestMirrorSourceModule()
        elif source_type == SourceType.RPM_OSTREE:
            from pyanaconda.modules.payloads.source.rpm_ostree.rpm_ostree import \
                RPMOSTreeSourceModule
            return RPMOSTreeSourceModule()
        elif source_type == SourceType.FLATPAK:
            from pyanaconda.modules.payloads.source.flatpak.flatpak import \
                FlatpakSourceModule
            return FlatpakSourceModule()

        raise ValueError("Unknown source type: {}".format(source_type))
 def setUp(self):
     self.module = LiveImageSourceModule()
class LiveImageSourceTestCase(unittest.TestCase):
    """Test the live image source module."""
    def setUp(self):
        self.module = LiveImageSourceModule()

    def type_test(self):
        """Test the type property."""
        self.assertEqual(SourceType.LIVE_IMAGE, self.module.type)

    def network_required_test(self):
        """Test the network_required property."""
        self.assertEqual(self.module.network_required, False)

        self.module.configuration.url = "file://my/path"
        self.assertEqual(self.module.network_required, False)

        self.module.configuration.url = "http://my/path"
        self.assertEqual(self.module.network_required, True)

        self.module.configuration.url = "https://my/path"
        self.assertEqual(self.module.network_required, True)

    def is_local_test(self):
        """Test the is_local property."""
        self.module.configuration.url = "file://my/path"
        self.assertEqual(self.module.is_local, True)

        self.module.configuration.url = "http://my/path"
        self.assertEqual(self.module.is_local, False)

    def get_state_test(self):
        """Test the source state."""
        self.assertEqual(SourceState.NOT_APPLICABLE, self.module.get_state())

    def required_space_test(self):
        """Test the required_space property."""
        self.assertEqual(self.module.required_space, 1024 * 1024 * 1024)

        self.module._required_space = 12345
        self.assertEqual(self.module.required_space, 12345)

    def set_up_with_tasks_test(self):
        """Test the set-up tasks."""
        self.module.configuration.url = "file://my/path"
        tasks = self.module.set_up_with_tasks()
        self.assertEqual(len(tasks), 1)
        self.assertIsInstance(tasks[0], SetUpLocalImageSourceTask)

        self.module.configuration.url = "http://my/path"
        tasks = self.module.set_up_with_tasks()
        self.assertEqual(len(tasks), 1)
        self.assertIsInstance(tasks[0], SetUpRemoteImageSourceTask)

    @patch.object(SetUpLocalImageSourceTask, "run")
    def handle_setup_task_result_test(self, runner):
        """Test the handler of the set-up tasks."""
        self.module.configuration.url = "file://my/path"
        runner.return_value = SetupImageResult(12345)

        tasks = self.module.set_up_with_tasks()
        for task in tasks:
            task.run_with_signals()

        runner.assert_called_once_with()
        self.assertEqual(self.module.required_space, 12345)

    def tear_down_with_tasks_test(self):
        """Test the tear-down tasks."""
        self.assertEqual(self.module.tear_down_with_tasks(), [])

    def repr_test(self):
        """Test the string representation."""
        self.module.configuration.url = "file://my/path"
        self.assertEqual(
            repr(self.module),
            str("Source("
                "type='LIVE_IMAGE', "
                "url='file://my/path'"
                ")"))
 def setUp(self):
     self.module = LiveImageSourceModule()
     self.interface = LiveImageSourceInterface(self.module)
class LiveImageSourceTestCase(unittest.TestCase):
    """Test the live image source module."""
    def setUp(self):
        self.module = LiveImageSourceModule()

    def test_type(self):
        """Test the type property."""
        assert SourceType.LIVE_IMAGE == self.module.type

    def test_network_required(self):
        """Test the network_required property."""
        assert self.module.network_required is False

        self.module.configuration.url = "file://my/path"
        assert self.module.network_required is False

        self.module.configuration.url = "http://my/path"
        assert self.module.network_required is True

        self.module.configuration.url = "https://my/path"
        assert self.module.network_required is True

    def test_is_local(self):
        """Test the is_local property."""
        self.module.configuration.url = "file://my/path"
        assert self.module.is_local is True

        self.module.configuration.url = "http://my/path"
        assert self.module.is_local is False

    def test_get_state(self):
        """Test the source state."""
        assert SourceState.NOT_APPLICABLE == self.module.get_state()

    def test_required_space(self):
        """Test the required_space property."""
        assert self.module.required_space == 1024 * 1024 * 1024

        self.module._required_space = 12345
        assert self.module.required_space == 12345

    def test_set_up_with_tasks(self):
        """Test the set-up tasks."""
        self.module.configuration.url = "file://my/path"
        tasks = self.module.set_up_with_tasks()
        assert len(tasks) == 1
        assert isinstance(tasks[0], SetUpLocalImageSourceTask)

        self.module.configuration.url = "http://my/path"
        tasks = self.module.set_up_with_tasks()
        assert len(tasks) == 1
        assert isinstance(tasks[0], SetUpRemoteImageSourceTask)

    @patch.object(SetUpLocalImageSourceTask, "run")
    def test_handle_setup_task_result(self, runner):
        """Test the handler of the set-up tasks."""
        self.module.configuration.url = "file://my/path"
        runner.return_value = SetupImageResult(12345)

        tasks = self.module.set_up_with_tasks()
        for task in tasks:
            task.run_with_signals()

        runner.assert_called_once_with()
        assert self.module.required_space == 12345

    def test_tear_down_with_tasks(self):
        """Test the tear-down tasks."""
        assert self.module.tear_down_with_tasks() == []

    def test_repr(self):
        """Test the string representation."""
        self.module.configuration.url = "file://my/path"
        assert repr(self.module) == str("Source("
                                        "type='LIVE_IMAGE', "
                                        "url='file://my/path'"
                                        ")")