def test_reboot_setting(self, reboot_setting_in_api='Never', reboot_setting_in_code=Constants.REBOOT_NEVER):
     argument_composer = ArgumentComposer()
     argument_composer.reboot_setting = reboot_setting_in_api
     runtime = RuntimeCompositor(argument_composer.get_composed_arguments(), True, Constants.YUM)
     reboot_manager = runtime.reboot_manager
     self.assertEqual(reboot_manager.is_setting(reboot_setting_in_code), True)
     runtime.stop()
 def test_reboot_setting_default_config(self):
     argument_composer = ArgumentComposer()
     argument_composer.reboot_setting = ""
     runtime = RuntimeCompositor(argument_composer.get_composed_arguments(), True, Constants.YUM)
     reboot_manager = runtime.reboot_manager
     self.assertEqual(reboot_manager.is_setting(Constants.REBOOT_IF_REQUIRED), True)
     runtime.stop()
    def test_reboot_always_runs_only_once_if_no_reboot_is_required(self):
        reboot_setting_in_api = 'Always'
        argument_composer = ArgumentComposer()
        argument_composer.reboot_setting = reboot_setting_in_api
        runtime = RuntimeCompositor(argument_composer.get_composed_arguments(),
                                    True, Constants.YUM)
        reboot_manager = runtime.reboot_manager

        # Validate single reboot scenario
        runtime.status_handler.is_reboot_pending = True
        self.assertEqual(
            reboot_manager.start_reboot_if_required_and_time_available(20),
            True)

        # mock completing the reboot once, with no reboot required
        runtime.status_handler.set_installation_reboot_status(
            Constants.RebootStatus.REQUIRED)
        runtime.status_handler.set_installation_reboot_status(
            Constants.RebootStatus.STARTED)
        runtime.status_handler.is_reboot_pending = False
        runtime.status_handler.set_installation_reboot_status(
            Constants.RebootStatus.COMPLETED)

        # no further reboot should be required
        self.assertEqual(
            reboot_manager.start_reboot_if_required_and_time_available(20),
            False)
        runtime.stop()
 def test_reboot_always_time_not_available(self):
     reboot_setting_in_api = 'Always'
     argument_composer = ArgumentComposer()
     argument_composer.reboot_setting = reboot_setting_in_api
     runtime = RuntimeCompositor(argument_composer.get_composed_arguments(), True, Constants.YUM)
     reboot_manager = runtime.reboot_manager
     self.assertEqual(reboot_manager.start_reboot_if_required_and_time_available(10), False)
     runtime.stop()