class ServicesTasksTestCase(unittest.TestCase): """Test the services tasks.""" def setUp(self): """Set up the services module.""" # Set up the services module. self.services_module = ServicesService() self.services_interface = ServicesInterface(self.services_module) @patch( 'pyanaconda.modules.services.installation.get_anaconda_version_string') def test_enable_post_install_tools(self, version_getter): version_getter.return_value = "1.0" content = dedent(""" # This file has been generated by the Anaconda Installer 1.0 [General] post_install_tools_disabled = 0 """) with tempfile.TemporaryDirectory() as sysroot: os.makedirs(os.path.join(sysroot, "etc/sysconfig")) ConfigurePostInstallationToolsTask(sysroot=sysroot, tools_enabled=True).run() with open(os.path.join(sysroot, "etc/sysconfig/anaconda")) as f: assert f.read().strip() == content.strip() @patch( 'pyanaconda.modules.services.installation.get_anaconda_version_string') def test_disable_post_install_tools(self, version_getter): version_getter.return_value = "1.0" content = dedent(""" # This file has been generated by the Anaconda Installer 1.0 [General] post_install_tools_disabled = 1 """) print(content) with tempfile.TemporaryDirectory() as sysroot: os.makedirs(os.path.join(sysroot, "etc/sysconfig")) ConfigurePostInstallationToolsTask(sysroot=sysroot, tools_enabled=False).run() with open(os.path.join(sysroot, "etc/sysconfig/anaconda")) as f: assert f.read().strip() == content.strip() @patch('pyanaconda.modules.services.installation.conf') def test_skip_post_install_tools(self, conf): with tempfile.TemporaryDirectory() as sysroot: os.makedirs(os.path.join(sysroot, "etc/sysconfig")) task = ConfigurePostInstallationToolsTask(sysroot=sysroot, tools_enabled=True) conf.target.is_directory = False conf.target.is_image = True task.run() assert not os.path.isfile( os.path.join(sysroot, "etc/sysconfig/anaconda")) conf.target.is_directory = True conf.target.is_image = False task.run() assert not os.path.isfile( os.path.join(sysroot, "etc/sysconfig/anaconda")) @patch_dbus_publish_object def test_install_with_tasks_default(self, publisher): """Test default install tasks behavior.""" tasks = self.services_interface.InstallWithTasks() is_task_path = tasks[0] post_install_tools_task = tasks[1] services_task_path = tasks[2] target_task_path = tasks[3] desktop_task_path = tasks[4] publisher.assert_called() # Initial Setup configuration object_path = publisher.call_args_list[0][0][0] obj = publisher.call_args_list[0][0][1] assert is_task_path == object_path assert isinstance(obj, TaskInterface) assert isinstance(obj.implementation, ConfigureInitialSetupTask) assert obj.implementation._setup_on_boot == SetupOnBootAction.DEFAULT # post install tools configuration object_path = publisher.call_args_list[1][0][0] obj = publisher.call_args_list[1][0][1] assert post_install_tools_task == object_path assert isinstance(obj, TaskInterface) assert isinstance(obj.implementation, ConfigurePostInstallationToolsTask) assert obj.implementation._tools_enabled is True # Services configuration object_path = publisher.call_args_list[2][0][0] obj = publisher.call_args_list[2][0][1] assert services_task_path == object_path assert isinstance(obj, TaskInterface) assert isinstance(obj.implementation, ConfigureServicesTask) assert obj.implementation._enabled_services == [] assert obj.implementation._disabled_services == [] # Default systemd target configuration object_path = publisher.call_args_list[3][0][0] obj = publisher.call_args_list[3][0][1] assert target_task_path == object_path assert isinstance(obj, TaskInterface) assert isinstance(obj.implementation, ConfigureSystemdDefaultTargetTask) assert obj.implementation._default_target == "" # Default desktop configuration object_path = publisher.call_args_list[4][0][0] obj = publisher.call_args_list[4][0][1] assert desktop_task_path == object_path assert isinstance(obj, TaskInterface) assert isinstance(obj.implementation, ConfigureDefaultDesktopTask) assert obj.implementation._default_desktop == "" @patch_dbus_publish_object def test_initial_setup_config_task_enable(self, publisher): """Test the Initial Setup conifg task - enable.""" self.services_interface.SetupOnBoot = SETUP_ON_BOOT_ENABLED tasks = self.services_interface.InstallWithTasks() is_task_path = tasks[0] publisher.assert_called() # Initial Setup configuration object_path = publisher.call_args_list[0][0][0] obj = publisher.call_args_list[0][0][1] assert is_task_path == object_path assert isinstance(obj, TaskInterface) assert isinstance(obj.implementation, ConfigureInitialSetupTask) assert obj.implementation._setup_on_boot == SetupOnBootAction.ENABLED @patch_dbus_publish_object def test_initial_setup_config_task_disable(self, publisher): """Test the Initial Setup config task - disable.""" self.services_interface.SetupOnBoot = SETUP_ON_BOOT_DISABLED tasks = self.services_interface.InstallWithTasks() is_task_path = tasks[0] publisher.assert_called() # Initial Setup configuration object_path = publisher.call_args_list[0][0][0] obj = publisher.call_args_list[0][0][1] assert is_task_path == object_path assert isinstance(obj, TaskInterface) assert isinstance(obj.implementation, ConfigureInitialSetupTask) assert obj.implementation._setup_on_boot == SetupOnBootAction.DISABLED @patch_dbus_publish_object def test_initial_setup_config_task_reconfig(self, publisher): """Test the Initial Setup config task - reconfig.""" self.services_interface.SetupOnBoot = SETUP_ON_BOOT_RECONFIG tasks = self.services_interface.InstallWithTasks() is_task_path = tasks[0] publisher.assert_called() # Initial Setup configuration object_path = publisher.call_args_list[0][0][0] obj = publisher.call_args_list[0][0][1] assert is_task_path == object_path assert isinstance(obj, TaskInterface) assert isinstance(obj.implementation, ConfigureInitialSetupTask) assert obj.implementation._setup_on_boot == SetupOnBootAction.RECONFIG @patch_dbus_publish_object def test_configure_services_task(self, publisher): """Test the services configuration task.""" self.services_interface.EnabledServices = ["a", "b", "c"] self.services_interface.DisabledServices = ["c", "e", "f"] tasks = self.services_interface.InstallWithTasks() services_task_path = tasks[2] publisher.assert_called() # Services configuration object_path = publisher.call_args_list[2][0][0] obj = publisher.call_args_list[2][0][1] assert services_task_path == object_path assert isinstance(obj, TaskInterface) assert isinstance(obj.implementation, ConfigureServicesTask) assert obj.implementation._enabled_services == ["a", "b", "c"] assert obj.implementation._disabled_services == ["c", "e", "f"] @patch_dbus_publish_object def test_configure_systemd_target_task_text(self, publisher): """Test the systemd default traget configuration task - text.""" self.services_interface.DefaultTarget = TEXT_ONLY_TARGET tasks = self.services_interface.InstallWithTasks() target_task_path = tasks[3] publisher.assert_called() # Default systemd target configuration object_path = publisher.call_args_list[3][0][0] obj = publisher.call_args_list[3][0][1] assert target_task_path == object_path assert isinstance(obj, TaskInterface) assert isinstance(obj.implementation, ConfigureSystemdDefaultTargetTask) assert obj.implementation._default_target == TEXT_ONLY_TARGET @patch_dbus_publish_object def test_configure_systemd_target_task_graphical(self, publisher): """Test the systemd default traget configuration task - graphical.""" self.services_interface.DefaultTarget = GRAPHICAL_TARGET tasks = self.services_interface.InstallWithTasks() target_task_path = tasks[3] publisher.assert_called() # Default systemd target configuration object_path = publisher.call_args_list[3][0][0] obj = publisher.call_args_list[3][0][1] assert target_task_path == object_path assert isinstance(obj, TaskInterface) assert isinstance(obj.implementation, ConfigureSystemdDefaultTargetTask) assert obj.implementation._default_target == GRAPHICAL_TARGET @patch_dbus_publish_object def test_configure_default_desktop_task(self, publisher): """Test the default desktop configuration task.""" self.services_interface.DefaultDesktop = "GNOME" tasks = self.services_interface.InstallWithTasks() desktop_task_path = tasks[4] publisher.assert_called() # Default desktop configuration object_path = publisher.call_args_list[4][0][0] obj = publisher.call_args_list[4][0][1] assert desktop_task_path == object_path assert isinstance(obj, TaskInterface) assert isinstance(obj.implementation, ConfigureDefaultDesktopTask) assert obj.implementation._default_desktop == "GNOME"
class ServicesTasksTestCase(unittest.TestCase): """Test the services tasks.""" def setUp(self): """Set up the services module.""" # Set up the services module. self.services_module = ServicesModule() self.services_interface = ServicesInterface(self.services_module) # Connect to the properties changed signal. self.callback = Mock() self.services_interface.PropertiesChanged.connect(self.callback) @patch('pyanaconda.modules.services.installation.get_anaconda_version_string') def enable_post_install_tools_test(self, version_getter): version_getter.return_value = "1.0" content = dedent(""" # This file has been generated by the Anaconda Installer 1.0 [General] post_install_tools_disabled = 0 """) with tempfile.TemporaryDirectory() as sysroot: os.makedirs(os.path.join(sysroot, "etc/sysconfig")) ConfigurePostInstallationToolsTask( sysroot=sysroot, tools_enabled=True ).run() with open(os.path.join(sysroot, "etc/sysconfig/anaconda")) as f: self.assertEqual(f.read().strip(), content.strip()) @patch('pyanaconda.modules.services.installation.get_anaconda_version_string') def disable_post_install_tools_test(self, version_getter): version_getter.return_value = "1.0" content = dedent(""" # This file has been generated by the Anaconda Installer 1.0 [General] post_install_tools_disabled = 1 """) print(content) with tempfile.TemporaryDirectory() as sysroot: os.makedirs(os.path.join(sysroot, "etc/sysconfig")) ConfigurePostInstallationToolsTask( sysroot=sysroot, tools_enabled=False ).run() with open(os.path.join(sysroot, "etc/sysconfig/anaconda")) as f: self.assertEqual(f.read().strip(), content.strip()) @patch('pyanaconda.modules.services.installation.conf') def skip_post_install_tools_test(self, conf): with tempfile.TemporaryDirectory() as sysroot: os.makedirs(os.path.join(sysroot, "etc/sysconfig")) task = ConfigurePostInstallationToolsTask( sysroot=sysroot, tools_enabled=True ) conf.target.is_directory = False conf.target.is_image = True task.run() self.assertFalse(os.path.isfile(os.path.join(sysroot, "etc/sysconfig/anaconda"))) conf.target.is_directory = True conf.target.is_image = False task.run() self.assertFalse(os.path.isfile(os.path.join(sysroot, "etc/sysconfig/anaconda"))) @patch_dbus_publish_object def install_with_tasks_default_test(self, publisher): """Test default install tasks behavior.""" tasks = self.services_interface.InstallWithTasks() is_task_path = tasks[0] post_install_tools_task = tasks[1] services_task_path = tasks[2] target_task_path = tasks[3] desktop_task_path = tasks[4] publisher.assert_called() # Initial Setup configuration object_path = publisher.call_args_list[0][0][0] obj = publisher.call_args_list[0][0][1] self.assertEqual(is_task_path, object_path) self.assertIsInstance(obj, TaskInterface) self.assertIsInstance(obj.implementation, ConfigureInitialSetupTask) self.assertEqual(obj.implementation._setup_on_boot, SetupOnBootAction.DEFAULT) # post install tools configuration object_path = publisher.call_args_list[1][0][0] obj = publisher.call_args_list[1][0][1] self.assertEqual(post_install_tools_task, object_path) self.assertIsInstance(obj, TaskInterface) self.assertIsInstance(obj.implementation, ConfigurePostInstallationToolsTask) self.assertEqual(obj.implementation._tools_enabled, True) # Services configuration object_path = publisher.call_args_list[2][0][0] obj = publisher.call_args_list[2][0][1] self.assertEqual(services_task_path, object_path) self.assertIsInstance(obj, TaskInterface) self.assertIsInstance(obj.implementation, ConfigureServicesTask) self.assertEqual(obj.implementation._enabled_services, []) self.assertEqual(obj.implementation._disabled_services, []) # Default systemd target configuration object_path = publisher.call_args_list[3][0][0] obj = publisher.call_args_list[3][0][1] self.assertEqual(target_task_path, object_path) self.assertIsInstance(obj, TaskInterface) self.assertIsInstance(obj.implementation, ConfigureSystemdDefaultTargetTask) self.assertEqual(obj.implementation._default_target, "") # Default desktop configuration object_path = publisher.call_args_list[4][0][0] obj = publisher.call_args_list[4][0][1] self.assertEqual(desktop_task_path, object_path) self.assertIsInstance(obj, TaskInterface) self.assertIsInstance(obj.implementation, ConfigureDefaultDesktopTask) self.assertEqual(obj.implementation._default_desktop, "") @patch_dbus_publish_object def initial_setup_config_task_enable_test(self, publisher): """Test the Initial Setup conifg task - enable.""" self.services_interface.SetSetupOnBoot(SETUP_ON_BOOT_ENABLED) tasks = self.services_interface.InstallWithTasks() is_task_path = tasks[0] publisher.assert_called() # Initial Setup configuration object_path = publisher.call_args_list[0][0][0] obj = publisher.call_args_list[0][0][1] self.assertEqual(is_task_path, object_path) self.assertIsInstance(obj, TaskInterface) self.assertIsInstance(obj.implementation, ConfigureInitialSetupTask) self.assertEqual(obj.implementation._setup_on_boot, SetupOnBootAction.ENABLED) @patch_dbus_publish_object def initial_setup_config_task_disable_test(self, publisher): """Test the Initial Setup config task - disable.""" self.services_interface.SetSetupOnBoot(SETUP_ON_BOOT_DISABLED) tasks = self.services_interface.InstallWithTasks() is_task_path = tasks[0] publisher.assert_called() # Initial Setup configuration object_path = publisher.call_args_list[0][0][0] obj = publisher.call_args_list[0][0][1] self.assertEqual(is_task_path, object_path) self.assertIsInstance(obj, TaskInterface) self.assertIsInstance(obj.implementation, ConfigureInitialSetupTask) self.assertEqual(obj.implementation._setup_on_boot, SetupOnBootAction.DISABLED) @patch_dbus_publish_object def initial_setup_config_task_reconfig_test(self, publisher): """Test the Initial Setup config task - reconfig.""" self.services_interface.SetSetupOnBoot(SETUP_ON_BOOT_RECONFIG) tasks = self.services_interface.InstallWithTasks() is_task_path = tasks[0] publisher.assert_called() # Initial Setup configuration object_path = publisher.call_args_list[0][0][0] obj = publisher.call_args_list[0][0][1] self.assertEqual(is_task_path, object_path) self.assertIsInstance(obj, TaskInterface) self.assertIsInstance(obj.implementation, ConfigureInitialSetupTask) self.assertEqual(obj.implementation._setup_on_boot, SetupOnBootAction.RECONFIG) @patch_dbus_publish_object def configure_services_task_test(self, publisher): """Test the services configuration task.""" self.services_interface.SetEnabledServices(["a", "b", "c"]) self.services_interface.SetDisabledServices(["c", "e", "f"]) tasks = self.services_interface.InstallWithTasks() services_task_path = tasks[2] publisher.assert_called() # Services configuration object_path = publisher.call_args_list[2][0][0] obj = publisher.call_args_list[2][0][1] self.assertEqual(services_task_path, object_path) self.assertIsInstance(obj, TaskInterface) self.assertIsInstance(obj.implementation, ConfigureServicesTask) self.assertEqual(obj.implementation._enabled_services, ["a", "b", "c"]) self.assertEqual(obj.implementation._disabled_services, ["c", "e", "f"]) @patch_dbus_publish_object def configure_systemd_target_task_text_test(self, publisher): """Test the systemd default traget configuration task - text.""" self.services_interface.SetDefaultTarget(TEXT_ONLY_TARGET) tasks = self.services_interface.InstallWithTasks() target_task_path = tasks[3] publisher.assert_called() # Default systemd target configuration object_path = publisher.call_args_list[3][0][0] obj = publisher.call_args_list[3][0][1] self.assertEqual(target_task_path, object_path) self.assertIsInstance(obj, TaskInterface) self.assertIsInstance(obj.implementation, ConfigureSystemdDefaultTargetTask) self.assertEqual(obj.implementation._default_target, TEXT_ONLY_TARGET) @patch_dbus_publish_object def configure_systemd_target_task_graphical_test(self, publisher): """Test the systemd default traget configuration task - graphical.""" self.services_interface.SetDefaultTarget(GRAPHICAL_TARGET) tasks = self.services_interface.InstallWithTasks() target_task_path = tasks[3] publisher.assert_called() # Default systemd target configuration object_path = publisher.call_args_list[3][0][0] obj = publisher.call_args_list[3][0][1] self.assertEqual(target_task_path, object_path) self.assertIsInstance(obj, TaskInterface) self.assertIsInstance(obj.implementation, ConfigureSystemdDefaultTargetTask) self.assertEqual(obj.implementation._default_target, GRAPHICAL_TARGET) @patch_dbus_publish_object def configure_default_desktop_task_test(self, publisher): """Test the default desktop configuration task.""" self.services_interface.SetDefaultDesktop("GNOME") tasks = self.services_interface.InstallWithTasks() desktop_task_path = tasks[4] publisher.assert_called() # Default desktop configuration object_path = publisher.call_args_list[4][0][0] obj = publisher.call_args_list[4][0][1] self.assertEqual(desktop_task_path, object_path) self.assertIsInstance(obj, TaskInterface) self.assertIsInstance(obj.implementation, ConfigureDefaultDesktopTask) self.assertEqual(obj.implementation._default_desktop, "GNOME")