def test_install_with_tasks(self): """Test the install_with_tasks method.""" self.assertEqual(self.module.install_with_tasks(), []) rpm_source = SourceFactory.create_source(SourceType.RPM_OSTREE) self.module.set_sources([rpm_source]) tasks = self.module.install_with_tasks() self._assert_is_instance_list(tasks, [ InitOSTreeFsAndRepoTask, ChangeOSTreeRemoteTask, PullRemoteAndDeleteTask, DeployOSTreeTask, SetSystemRootTask, CopyBootloaderDataTask, PrepareOSTreeMountTargetsTask, ]) flatpak_source = SourceFactory.create_source(SourceType.FLATPAK) self.module.set_sources([rpm_source, flatpak_source]) tasks = self.module.install_with_tasks() self._assert_is_instance_list(tasks, [ InitOSTreeFsAndRepoTask, ChangeOSTreeRemoteTask, PullRemoteAndDeleteTask, DeployOSTreeTask, SetSystemRootTask, CopyBootloaderDataTask, PrepareOSTreeMountTargetsTask, InstallFlatpaksTask, ])
def _process_kickstart_sources(self, data): """Process the kickstart sources.""" source_type = SourceFactory.get_rpm_type_for_kickstart(data) if source_type is None: return source = SourceFactory.create_source(source_type) source.process_kickstart(data) self.add_source(source)
def process_kickstart(self, data): """Process the kickstart data.""" source_type = SourceFactory.get_live_image_type_for_kickstart(data) if source_type is None: return source = SourceFactory.create_source(source_type) source.process_kickstart(data) self.add_source(source)
def test_multiple_sources(self): """The live image payload cannot have multiple sources.""" sources = [ SourceFactory.create_source(SourceType.LIVE_IMAGE), SourceFactory.create_source(SourceType.LIVE_IMAGE) ] with pytest.raises(IncompatibleSourceError) as cm: self.module.set_sources(sources) assert str( cm.value) == "You can set only one source for this payload type."
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)
def test_create_source(self): """Test SourceFactory create method.""" for source_type in SourceType: module = SourceFactory.create_source(source_type) assert isinstance(module, PayloadSourceBase) assert isinstance(module.for_publication(), PayloadSourceBaseInterface) assert module.type == source_type
def tear_down_sources_with_task_test(self, publisher): """Test TearDownSourcesWithTask.""" source = SourceFactory.create_source(SourceType.CDROM) self.module.add_source(source) task_path = self.interface.TearDownSourcesWithTask() obj = check_task_creation(self, task_path, publisher, TearDownSourcesTask) self.assertEqual(obj.implementation._sources, [source])
def test_set_up_sources_with_task(self, publisher): """Test SetUpSourcesWithTask.""" source = SourceFactory.create_source(SourceType.CDROM) self.module.add_source(source) task_path = self.interface.SetUpSourcesWithTask() obj = check_task_creation(task_path, publisher, SetUpSourcesTask) assert obj.implementation._sources == [source]
def create_source_test(self): """Test SourceFactory create method.""" for source_type in SourceType: module = SourceFactory.create_source(source_type) self.assertIsInstance(module, PayloadSourceBase) self.assertIsInstance(module.for_publication(), PayloadSourceBaseInterface) self.assertEqual(module.type, source_type)
def test_calculate_required_space(self): """Test the calculate_required_space method.""" assert self.module.calculate_required_space() == 0 source = SourceFactory.create_source(SourceType.LIVE_IMAGE) self.module.add_source(source) assert self.module.calculate_required_space() == 1024 * 1024 * 1024
def test_calculate_required_space(self): """Test the calculate_required_space method.""" self.assertEqual(self.module.calculate_required_space(), 0) source = SourceFactory.create_source(SourceType.LIVE_IMAGE) self.module.add_source(source) self.assertEqual(self.module.calculate_required_space(), 1024 * 1024 * 1024)
def calculate_required_space_test(self): """Test CalculateRequiredTest.""" self.assertEqual(self.live_image_interface.CalculateRequiredSpace(), 0) source = SourceFactory.create_source(SourceType.LIVE_IMAGE) self.live_image_module.add_source(source) self.assertEqual(self.live_image_interface.CalculateRequiredSpace(), 1024 * 1024 * 1024)
def prepare_source(source_type, state=SourceState.READY): """Prepare mock objects which will present given source. :param SourceType source: Enum describing the source type :param SourceState state: mock state of the created source """ source = SourceFactory.create_source(source_type) source.get_state = Mock(return_value=state) return source
def test_install_with_task_from_image(self): """Test installation tasks with an image.""" assert self.module.install_with_tasks() == [] source = SourceFactory.create_source(SourceType.LIVE_IMAGE) self.module.add_source(source) tasks = self.module.install_with_tasks() assert len(tasks) == 1 assert isinstance(tasks[0], InstallLiveImageTask)
def test_post_install_with_tasks(self): """Test the post_install_with_tasks method.""" self.assertEqual(self.module.post_install_with_tasks(), []) rpm_source = SourceFactory.create_source(SourceType.RPM_OSTREE) self.module.set_sources([rpm_source]) tasks = self.module.post_install_with_tasks() self._assert_is_instance_list(tasks, [ ChangeOSTreeRemoteTask, ConfigureBootloader, ])
def test_tear_down_with_tasks(self): """Test the tear_down_with_tasks method.""" rpm_source = SourceFactory.create_source(SourceType.RPM_OSTREE) self.module.set_sources([rpm_source]) self.module._add_internal_mounts(["/path/1", "/path/2"]) tasks = self.module.tear_down_with_tasks() self._assert_is_instance_list( tasks, [TearDownSourcesTask, TearDownOSTreeMountTargetsTask]) self.assertEqual(tasks[0]._sources, [rpm_source]) self.assertEqual(tasks[1]._internal_mounts, ["/path/1", "/path/2"])
def test_collect_mount_points(self): """Collect mount points from successful tasks.""" rpm_source = SourceFactory.create_source(SourceType.RPM_OSTREE) self.module.set_sources([rpm_source]) tasks = self.module.install_with_tasks() for task in tasks: # Fake the task results. task_id = task.__class__.__name__ task._set_result( ["/path/{}/1".format(task_id), "/path/{}/2".format(task_id)]) # Fake the task run. task.succeeded_signal.emit() self.assertEqual(self.module._internal_mounts, [ "/path/PrepareOSTreeMountTargetsTask/1", "/path/PrepareOSTreeMountTargetsTask/2" ])
def test_failed_create_source(self): """Test failed create method of the source factory.""" with self.assertRaises(ValueError): SourceFactory.create_source("INVALID")