def disale_post_install_tools_test(self): """Test that SAM can correctly disable post install tools via the user interaction config.""" screen_access.initSAM() sam = screen_access.sam try: test_dir, config_path = self._get_config_path() # post install tools should be enabled by default self.assertFalse(sam.post_install_tools_disabled) # set post install tools to disabled sam.post_install_tools_disabled = True # check if SAM correctly reports the change self.assertTrue(sam.post_install_tools_disabled) sam.write_out_config_file( os.path.join(test_dir, screen_access.CONFIG_FILE_NAME)) # check if the option is correctly reflected in the # user interaction config file config = self._parse_config_file(config_path) self.assertTrue( config.has_section(screen_access.CONFIG_GENERAL_SECTION)) self.assertEqual( config.get(screen_access.CONFIG_GENERAL_SECTION, screen_access.CONFIG_DISABLE_POSTINST_TOOLS_KEY), screen_access.CONFIG_TRUE) finally: shutil.rmtree(test_dir)
def spoke_visited_test(self): """Test that SAM correctly marks a spoke as visited in the output config.""" screen_access.initSAM() sam = screen_access.sam try: test_dir, config_path = self._get_config_path() # mark a screen as visited sam.mark_screen_visited("FooSpoke") # it should be safe to mark a screen as visited multiple times sam.mark_screen_visited("FooSpoke") # write the config file sam.write_out_config_file( os.path.join(test_dir, screen_access.CONFIG_FILE_NAME)) # the resulting config file needs to exist and be non-empty self.assertTrue(os.path.exists(config_path)) self.assertGreater(os.path.getsize(config_path), 0) # parse the file and check if it contains the FooSpoke section # and visited key set to 0 config = self._parse_config_file(config_path) self.assertTrue(config.has_section("FooSpoke")) self.assertEqual( config.get("FooSpoke", screen_access.CONFIG_VISITED_KEY), screen_access.CONFIG_TRUE) finally: shutil.rmtree(test_dir)
def file_header_test(self): """Test that the Anaconda generated config file header looks fine.""" screen_access.initSAM() sam = screen_access.sam header = sam._get_new_config_header() # check that the header starts with a hash self.assertEqual(header[0], "#") # check that it has a newline at the end self.assertEqual(header[-1], "\n")
def file_header_test(self): """Test that the Anaconda generated config file header looks fine.""" screen_access.initSAM() sam = screen_access.sam header = sam._get_new_config_header() # check that the header starts with a hash self.assertEqual(header[0], "#") # check that it has a newline at the end self.assertEqual(header[-1], "\n")
def spoke_option_changed_test(self): """Test that SAM correctly marks option as changed in the output config.""" screen_access.initSAM() sam = screen_access.sam try: test_dir, config_path = self._get_config_path() # mark a screen as visited sam.mark_screen_visited("FooSpoke") # mark some options on it as changed sam.mark_screen_option_changed("FooSpoke", "BarOption") sam.mark_screen_option_changed("FooSpoke", "BazOption") # it should be possible to mark an option as changed multiple # times so that Anaconda doesn't have to check before marking # an option as changed sam.mark_screen_option_changed("FooSpoke", "BarOption") sam.mark_screen_option_changed("FooSpoke", "BazOption") # check if SAM correctly reports the options as changed self.assertTrue( sam.get_screen_option_changed("FooSpoke", "BarOption")) self.assertTrue( sam.get_screen_option_changed("FooSpoke", "BazOption")) # try marking something as changed on a spoke # that has not been visited sam.mark_screen_option_changed("UnvisitedSpoke", "UnaccessibleOption") # the option should still be marked as not changed self.assertFalse( sam.get_screen_option_changed("UnvisitedSpoke", "UnaccessibleOption")) # now write out the config and check if it is valid sam.write_out_config_file( os.path.join(test_dir, screen_access.CONFIG_FILE_NAME)) config = self._parse_config_file(config_path) self.assertTrue(config.has_section("FooSpoke")) self.assertEqual( config.get("FooSpoke", screen_access.CONFIG_VISITED_KEY), screen_access.CONFIG_TRUE) self.assertEqual( config.get("FooSpoke", screen_access.CONFIG_OPTION_PREFIX + "BarOption"), screen_access.CONFIG_TRUE) self.assertEqual( config.get("FooSpoke", screen_access.CONFIG_OPTION_PREFIX + "BazOption"), screen_access.CONFIG_TRUE) # make sure there is no "UnvisitedSpoke" in the config self.assertFalse(config.has_section("UnvisitedSpoke")) self.assertEqual( config.get("UnivisitedSpoke", screen_access.CONFIG_OPTION_PREFIX + "UnaccessibleOption", fallback=None), None) finally: shutil.rmtree(test_dir)
def no_interaction_test(self): """Test that SAM can handle no user interaction taking place.""" screen_access.initSAM() sam = screen_access.sam try: test_dir, config_path = self._get_config_path() sam.write_out_config_file(os.path.join(test_dir, screen_access.CONFIG_FILE_NAME)) self.assertTrue(os.path.exists(config_path)) # the config should have the "created by Anaconda" header, so it should # be non-zero self.assertGreater(os.path.getsize(config_path), 0) finally: shutil.rmtree(test_dir)
def no_interaction_test(self): """Test that SAM can handle no user interaction taking place.""" screen_access.initSAM() sam = screen_access.sam try: test_dir, config_path = self._get_config_path() sam.write_out_config_file( os.path.join(test_dir, screen_access.CONFIG_FILE_NAME)) self.assertTrue(os.path.exists(config_path)) # the config should have the "created by Anaconda" header, so it should # be non-zero self.assertGreater(os.path.getsize(config_path), 0) finally: shutil.rmtree(test_dir)
def spoke_option_changed_test(self): """Test that SAM correctly marks option as changed in the output config.""" screen_access.initSAM() sam = screen_access.sam try: test_dir, config_path = self._get_config_path() # mark a screen as visited sam.mark_screen_visited("FooSpoke") # mark some options on it as changed sam.mark_screen_option_changed("FooSpoke", "BarOption") sam.mark_screen_option_changed("FooSpoke", "BazOption") # it should be possible to mark an option as changed multiple # times so that Anaconda doesn't have to check before marking # an option as changed sam.mark_screen_option_changed("FooSpoke", "BarOption") sam.mark_screen_option_changed("FooSpoke", "BazOption") # check if SAM correctly reports the options as changed self.assertTrue(sam.get_screen_option_changed("FooSpoke", "BarOption")) self.assertTrue(sam.get_screen_option_changed("FooSpoke", "BazOption")) # try marking something as changed on a spoke # that has not been visited sam.mark_screen_option_changed("UnvisitedSpoke", "UnaccessibleOption") # the option should still be marked as not changed self.assertFalse(sam.get_screen_option_changed("UnvisitedSpoke", "UnaccessibleOption")) # now write out the config and check if it is valid sam.write_out_config_file(os.path.join(test_dir, screen_access.CONFIG_FILE_NAME)) config = self._parse_config_file(config_path) self.assertTrue(config.has_section("FooSpoke")) self.assertEqual(config.get("FooSpoke", screen_access.CONFIG_VISITED_KEY), screen_access.CONFIG_TRUE) self.assertEqual(config.get("FooSpoke", screen_access.CONFIG_OPTION_PREFIX + "BarOption"), screen_access.CONFIG_TRUE) self.assertEqual(config.get("FooSpoke", screen_access.CONFIG_OPTION_PREFIX + "BazOption"), screen_access.CONFIG_TRUE) # make sure there is no "UnvisitedSpoke" in the config self.assertFalse(config.has_section("UnvisitedSpoke")) self.assertEqual(config.get("UnivisitedSpoke", screen_access.CONFIG_OPTION_PREFIX + "UnaccessibleOption", fallback=None), None) finally: shutil.rmtree(test_dir)
def disale_post_install_tools_test(self): """Test that SAM can correctly disable post install tools via the user interaction config.""" screen_access.initSAM() sam = screen_access.sam try: test_dir, config_path = self._get_config_path() # post install tools should be enabled by default self.assertFalse(sam.post_install_tools_disabled) # set post install tools to disabled sam.post_install_tools_disabled = True # check if SAM correctly reports the change self.assertTrue(sam.post_install_tools_disabled) sam.write_out_config_file(os.path.join(test_dir, screen_access.CONFIG_FILE_NAME)) # check if the option is correctly reflected in the # user interaction config file config = self._parse_config_file(config_path) self.assertTrue(config.has_section(screen_access.CONFIG_GENERAL_SECTION)) self.assertEqual(config.get(screen_access.CONFIG_GENERAL_SECTION, screen_access.CONFIG_DISABLE_POSTINST_TOOLS_KEY), screen_access.CONFIG_TRUE) finally: shutil.rmtree(test_dir)
def spoke_visited_test(self): """Test that SAM correctly marks a spoke as visited in the output config.""" screen_access.initSAM() sam = screen_access.sam try: test_dir, config_path = self._get_config_path() # mark a screen as visited sam.mark_screen_visited("FooSpoke") # it should be safe to mark a screen as visited multiple times sam.mark_screen_visited("FooSpoke") # write the config file sam.write_out_config_file(os.path.join(test_dir, screen_access.CONFIG_FILE_NAME)) # the resulting config file needs to exist and be non-empty self.assertTrue(os.path.exists(config_path)) self.assertGreater(os.path.getsize(config_path), 0) # parse the file and check if it contains the FooSpoke section # and visited key set to 0 config = self._parse_config_file(config_path) self.assertTrue(config.has_section("FooSpoke")) self.assertEqual(config.get("FooSpoke", screen_access.CONFIG_VISITED_KEY), screen_access.CONFIG_TRUE) finally: shutil.rmtree(test_dir)
# Initialize the network now, in case the display needs it from pyanaconda.network import networkInitialize, wait_for_connecting_NM_thread, wait_for_connected_NM networkInitialize(ksdata) # If required by user, wait for connection before starting the installation. if opts.waitfornet: log.info("network: waiting for connectivity requested by inst.waitfornet=%d", opts.waitfornet) wait_for_connected_NM(timeout=opts.waitfornet) # In any case do some actions only after NM finishes its connecting. threadMgr.add(AnacondaThread(name=constants.THREAD_WAIT_FOR_CONNECTING_NM, target=wait_for_connecting_NM_thread, args=(ksdata,))) # initialize the screen access manager before launching the UI from pyanaconda import screen_access screen_access.initSAM() # try to open any existing config file # (might be created by pre-anaconda helper tools, injected during image # generation, etc.) screen_access.sam.open_config_file() # now start the interface display.setup_display(anaconda, opts, addon_paths=addon_paths) if anaconda.gui_startup_failed: # we need to reinitialize the locale if GUI startup failed, # as we might now be in text mode, which might not be able to display # the characters from our current locale log.warning("reinitializing locale due to failed attempt to start the GUI") localization.setup_locale(os.environ["LANG"], ksdata.lang, text_mode=anaconda.tui_mode) # we now know in which mode we are going to run so store the information
def run(self): """Run Initial setup GUI will be used when the gui_mode property is True (TUI mode is the default). :returns: True if the IS run was successful, False if it failed :rtype: bool """ self._load_kickstart() self._setup_locale() # initialize the screen access manager before launching the UI screen_access.initSAM() if self.gui_mode: try: # Try to import IS gui specifics log.debug("trying to import GUI") import initial_setup.gui except ImportError: log.exception("GUI import failed, falling back to TUI") self.gui_mode = False if self.gui_mode: # gui already imported (see above) # Add addons to search paths initial_setup.gui.InitialSetupGraphicalUserInterface.update_paths( self._addon_module_paths) # Initialize the UI log.debug("initializing GUI") ui = initial_setup.gui.InitialSetupGraphicalUserInterface( None, None, PostInstallClass()) # set Window header visibility based on command line options ui.mainWindow.set_hide_titlebar_when_maximized( not self.args.show_window_header) else: # Import IS tui specifics import initial_setup.tui # Add addons to search paths initial_setup.tui.InitialSetupTextUserInterface.update_paths( self._addon_module_paths) # Initialize the UI log.debug("initializing TUI") ui = initial_setup.tui.InitialSetupTextUserInterface( None, None, None) # Pass the data object to user interface log.debug("setting up the UI") ui.setup(self.data) # Start the application log.info("starting the UI") ret = ui.run() # we need to reboot the machine if the EULA was not agreed if not self.data.eula.agreed: log.warning( "EULA has not been agreed - the system will be rebooted.") self._reboot_on_quit = True # TUI returns False if the app was ended prematurely # all other cases return True or None if ret is False: log.warning("ended prematurely in TUI") return True # apply changes self._apply() # and we are done return True
def run(self): """Run Initial setup :param bool gui_mode: if GUI should be used (TUI is the default) :returns: True if the IS run was successful, False if it failed :rtype: bool """ # start Boss & our DBUS session self.run_boss_with_dbus() # also register boss shutdown & DBUS session cleanup via exit handler atexit.register(self.cleanup_dbus_session) # Make sure that all DBus modules are ready. if not startup_utils.wait_for_modules(timeout=30): log.error("Anaconda DBus modules failed to start on time.") return True self._load_kickstart() self._setup_locale() # initialize the screen access manager before launching the UI screen_access.initSAM() if self.gui_mode: try: # Try to import IS gui specifics log.debug("trying to import GUI") import initial_setup.gui except ImportError: log.exception("GUI import failed, falling back to TUI") self.gui_mode = False if self.gui_mode: # gui already imported (see above) # Add addons to search paths initial_setup.gui.InitialSetupGraphicalUserInterface.update_paths(self._addon_module_paths) # Initialize the UI log.debug("initializing GUI") ui = initial_setup.gui.InitialSetupGraphicalUserInterface(None, None, PostInstallClass()) else: # Import IS gui specifics import initial_setup.tui # Add addons to search paths initial_setup.tui.InitialSetupTextUserInterface.update_paths(self._addon_module_paths) # Initialize the UI log.debug("initializing TUI") ui = initial_setup.tui.InitialSetupTextUserInterface(None, None, None) # Pass the data object to user interface log.debug("setting up the UI") ui.setup(self.data) # Start the application log.info("starting the UI") ret = ui.run() # TUI returns False if the app was ended prematurely # all other cases return True or None if ret is False: log.warning("ended prematurely in TUI") return True # apply changes self._apply() # in the TUI mode shutdown the multi TTY handler if not self.gui_mode: # TODO: wait for this to finish or make it blockng ? ui.multi_tty_handler.shutdown() # and we are done return True
def existing_config_test(self): """Test that SAM can correctly parse an existing user interaction config.""" screen_access.initSAM() sam = screen_access.sam try: test_dir, config_path = self._get_config_path() third_party_config = """ # Generated by some third party tool [General] # disable post install tools post_install_tools_disabled=1 [FooScreen] visited=1 [BarScreen] visited=1 # some options have been changed changed_some_option=1 changed_other_option=1 # these options use wrong boolean syntax # (only 1 and 0 is allowed by the spec) changed_bad_syntax_1=yes changed_bad_syntax_2=true changed_bad_syntax_3=True changed_bad_syntax_4=no changed_bad_syntax_5=false changed_bad_syntax_6=False changed_bad_syntax_7=2 changed_bad_syntax_8=something # a random keys that should be ignored not_an_option=1 not_changed=abc """ with open(config_path, "wt") as f: f.write(third_party_config) sam.open_config_file(config_path) # check that SAM has correctly parsed the config file self.assertTrue(sam.post_install_tools_disabled) self.assertTrue(sam.get_screen_visited("FooScreen")) self.assertTrue(sam.get_screen_visited("BarScreen")) self.assertTrue(sam.get_screen_option_changed("BarScreen", "some_option")) self.assertTrue(sam.get_screen_option_changed("BarScreen", "other_option")) # options using bad boolean syntax should be ignored self.assertFalse(sam.get_screen_option_changed("BarScreen", "bad_syntax_1")) self.assertFalse(sam.get_screen_option_changed("BarScreen", "bad_syntax_2")) self.assertFalse(sam.get_screen_option_changed("BarScreen", "bad_syntax_3")) self.assertFalse(sam.get_screen_option_changed("BarScreen", "bad_syntax_4")) self.assertFalse(sam.get_screen_option_changed("BarScreen", "bad_syntax_5")) self.assertFalse(sam.get_screen_option_changed("BarScreen", "bad_syntax_6")) self.assertFalse(sam.get_screen_option_changed("BarScreen", "bad_syntax_7")) self.assertFalse(sam.get_screen_option_changed("BarScreen", "bad_syntax_8")) # those other two keys don̈́'t have the changed prefix, so should not be parsed # as changed options self.assertFalse(sam.get_screen_option_changed("BarScreen", "not_an_option")) self.assertFalse(sam.get_screen_option_changed("BarScreen", "not_changed")) # now try changing more stuff and then check if it correctly propagates # to the resulting user interaction config file # lets say the user changed something else on the BarScreen sam.mark_screen_option_changed("BarScreen", "option_changed_in_anaconda") # and then visited the BazScreen and also changed something on it sam.mark_screen_visited("BazScreen") sam.mark_screen_option_changed("BazScreen", "baz_option_1") sam.mark_screen_option_changed("BazScreen", "baz_option_2") # write out the config file and check if it is valid sam.write_out_config_file(os.path.join(test_dir, screen_access.CONFIG_FILE_NAME)) config = self._parse_config_file(config_path) self.assertTrue(config.has_section(screen_access.CONFIG_GENERAL_SECTION)) self.assertTrue(config.get(screen_access.CONFIG_GENERAL_SECTION, screen_access.CONFIG_DISABLE_POSTINST_TOOLS_KEY), screen_access.CONFIG_TRUE) self.assertTrue(config.has_section("FooScreen")) self.assertEqual(config.get("FooScreen", screen_access.CONFIG_VISITED_KEY), screen_access.CONFIG_TRUE) self.assertTrue(config.has_section("BarScreen")) self.assertEqual(config.get("BarScreen", screen_access.CONFIG_OPTION_PREFIX + "some_option"), screen_access.CONFIG_TRUE) self.assertEqual(config.get("BarScreen", screen_access.CONFIG_OPTION_PREFIX + "other_option"), screen_access.CONFIG_TRUE) self.assertEqual(config.get("BarScreen", screen_access.CONFIG_OPTION_PREFIX + "option_changed_in_anaconda"), screen_access.CONFIG_TRUE) self.assertTrue(config.has_section("BazScreen")) self.assertEqual(config.get("BazScreen", screen_access.CONFIG_OPTION_PREFIX + "baz_option_1"), screen_access.CONFIG_TRUE) self.assertEqual(config.get("BazScreen", screen_access.CONFIG_OPTION_PREFIX + "baz_option_2"), screen_access.CONFIG_TRUE) finally: shutil.rmtree(test_dir)
def existing_config_test(self): """Test that SAM can correctly parse an existing user interaction config.""" screen_access.initSAM() sam = screen_access.sam try: test_dir, config_path = self._get_config_path() third_party_config = """ # Generated by some third party tool [General] # disable post install tools post_install_tools_disabled=1 [FooScreen] visited=1 [BarScreen] visited=1 # some options have been changed changed_some_option=1 changed_other_option=1 # these options use wrong boolean syntax # (only 1 and 0 is allowed by the spec) changed_bad_syntax_1=yes changed_bad_syntax_2=true changed_bad_syntax_3=True changed_bad_syntax_4=no changed_bad_syntax_5=false changed_bad_syntax_6=False changed_bad_syntax_7=2 changed_bad_syntax_8=something # a random keys that should be ignored not_an_option=1 not_changed=abc """ with open(config_path, "wt") as f: f.write(third_party_config) sam.open_config_file(config_path) # check that SAM has correctly parsed the config file self.assertTrue(sam.post_install_tools_disabled) self.assertTrue(sam.get_screen_visited("FooScreen")) self.assertTrue(sam.get_screen_visited("BarScreen")) self.assertTrue( sam.get_screen_option_changed("BarScreen", "some_option")) self.assertTrue( sam.get_screen_option_changed("BarScreen", "other_option")) # options using bad boolean syntax should be ignored self.assertFalse( sam.get_screen_option_changed("BarScreen", "bad_syntax_1")) self.assertFalse( sam.get_screen_option_changed("BarScreen", "bad_syntax_2")) self.assertFalse( sam.get_screen_option_changed("BarScreen", "bad_syntax_3")) self.assertFalse( sam.get_screen_option_changed("BarScreen", "bad_syntax_4")) self.assertFalse( sam.get_screen_option_changed("BarScreen", "bad_syntax_5")) self.assertFalse( sam.get_screen_option_changed("BarScreen", "bad_syntax_6")) self.assertFalse( sam.get_screen_option_changed("BarScreen", "bad_syntax_7")) self.assertFalse( sam.get_screen_option_changed("BarScreen", "bad_syntax_8")) # those other two keys don̈́'t have the changed prefix, so should not be parsed # as changed options self.assertFalse( sam.get_screen_option_changed("BarScreen", "not_an_option")) self.assertFalse( sam.get_screen_option_changed("BarScreen", "not_changed")) # now try changing more stuff and then check if it correctly propagates # to the resulting user interaction config file # lets say the user changed something else on the BarScreen sam.mark_screen_option_changed("BarScreen", "option_changed_in_anaconda") # and then visited the BazScreen and also changed something on it sam.mark_screen_visited("BazScreen") sam.mark_screen_option_changed("BazScreen", "baz_option_1") sam.mark_screen_option_changed("BazScreen", "baz_option_2") # write out the config file and check if it is valid sam.write_out_config_file( os.path.join(test_dir, screen_access.CONFIG_FILE_NAME)) config = self._parse_config_file(config_path) self.assertTrue( config.has_section(screen_access.CONFIG_GENERAL_SECTION)) self.assertTrue( config.get(screen_access.CONFIG_GENERAL_SECTION, screen_access.CONFIG_DISABLE_POSTINST_TOOLS_KEY), screen_access.CONFIG_TRUE) self.assertTrue(config.has_section("FooScreen")) self.assertEqual( config.get("FooScreen", screen_access.CONFIG_VISITED_KEY), screen_access.CONFIG_TRUE) self.assertTrue(config.has_section("BarScreen")) self.assertEqual( config.get("BarScreen", screen_access.CONFIG_OPTION_PREFIX + "some_option"), screen_access.CONFIG_TRUE) self.assertEqual( config.get("BarScreen", screen_access.CONFIG_OPTION_PREFIX + "other_option"), screen_access.CONFIG_TRUE) self.assertEqual( config.get( "BarScreen", screen_access.CONFIG_OPTION_PREFIX + "option_changed_in_anaconda"), screen_access.CONFIG_TRUE) self.assertTrue(config.has_section("BazScreen")) self.assertEqual( config.get("BazScreen", screen_access.CONFIG_OPTION_PREFIX + "baz_option_1"), screen_access.CONFIG_TRUE) self.assertEqual( config.get("BazScreen", screen_access.CONFIG_OPTION_PREFIX + "baz_option_2"), screen_access.CONFIG_TRUE) finally: shutil.rmtree(test_dir)
# Initialize the network now, in case the display needs it from pyanaconda.network import networkInitialize, wait_for_connecting_NM_thread, wait_for_connected_NM networkInitialize(ksdata) # If required by user, wait for connection before starting the installation. if opts.waitfornet: log.info("network: waiting for connectivity requested by inst.waitfornet=%d", opts.waitfornet) wait_for_connected_NM(timeout=opts.waitfornet) # In any case do some actions only after NM finishes its connecting. threadMgr.add(AnacondaThread(name=constants.THREAD_WAIT_FOR_CONNECTING_NM, target=wait_for_connecting_NM_thread)) # initialize the screen access manager before launching the UI from pyanaconda import screen_access screen_access.initSAM() # try to open any existing config file # (might be created by pre-anaconda helper tools, injected during image # generation, etc.) screen_access.sam.open_config_file() # now start the interface display.setup_display(anaconda, opts, addon_paths=addon_paths) if anaconda.gui_startup_failed: # we need to reinitialize the locale if GUI startup failed, # as we might now be in text mode, which might not be able to display # the characters from our current locale log.warning("reinitializing locale due to failed attempt to start the GUI") localization.setup_locale(os.environ["LANG"], localization_proxy, text_mode=anaconda.tui_mode) # we now know in which mode we are going to run so store the information