def test_set_to_run_on_boot(self): filename = self.makeFile("RUN=0\n") sysvconfig = SysVConfig(filename) sysvconfig.set_start_on_boot(True) with open(filename, "r") as res_file: result = res_file.read() self.assertEqual(result, "RUN=1\n")
def setup(config): """ Perform steps to ensure that landscape-client is correctly configured before we attempt to register it with a landscape server. If we are not configured to be silent then interrogate the user to provide necessary details for registration. """ bootstrap_tree(config) sysvconfig = SysVConfig() if not config.no_start: if config.silent: setup_init_script_and_start_client() elif not sysvconfig.is_configured_to_run(): answer = prompt_yes_no("\nThe Landscape client must be started " "on boot to operate correctly.\n\n" "Start Landscape client on boot?") if answer: setup_init_script_and_start_client() else: sys.exit("Aborting Landscape configuration") setup_http_proxy(config) check_account_name_and_password(config) if config.silent: check_script_users(config) else: script = LandscapeSetupScript(config) script.run() decode_base64_ssl_public_certificate(config) config.write() # Restart the client to ensure that it's using the new configuration. if not config.no_start: try: sysvconfig.restart_landscape() except ProcessError: print_text("Couldn't restart the Landscape client.", error=True) print_text( "This machine will be registered with the provided " "details when the client runs.", error=True) exit_code = 2 if config.ok_no_register: exit_code = 0 sys.exit(exit_code)
def stop_client_and_disable_init_script(): """ Stop landscape-client and change configuration to prevent starting landscape-client on boot. """ sysvconfig = SysVConfig() sysvconfig.stop_landscape() sysvconfig.set_start_on_boot(False)
def setup_init_script_and_start_client(): "Configure the init script to start the client on boot." # XXX This function is misnamed; it doesn't start the client. sysvconfig = SysVConfig() sysvconfig.set_start_on_boot(True)
def test_run_landscape(self, system_mock): filename = self.makeFile("RUN=1\n") sysvconfig = SysVConfig(filename) sysvconfig.restart_landscape() system_mock.assert_called_once_with( "/etc/init.d/landscape-client restart")
def test_stop_landscape_with_error(self, system_mock): filename = self.makeFile("RUN=1\n") sysvconfig = SysVConfig(filename) self.assertRaises(ProcessError, sysvconfig.stop_landscape) system_mock.assert_called_once_with( "/etc/init.d/landscape-client stop")
def test_non_integer_run(self): filename = self.makeFile("RUN=yesplease") sysvconfig = SysVConfig(filename) self.assertTrue(sysvconfig.is_configured_to_run())
def test_spaces_in_value(self): filename = self.makeFile(" RUN= 1 \n") sysvconfig = SysVConfig(filename) self.assertFalse(sysvconfig.is_configured_to_run())
def test_leading_and_trailing_spaces(self): filename = self.makeFile(" RUN=1 \n") sysvconfig = SysVConfig(filename) self.assertTrue(sysvconfig.is_configured_to_run())
def test_blank_line(self): filename = self.makeFile("RUN=1\n\n") sysvconfig = SysVConfig(filename) self.assertTrue(sysvconfig.is_configured_to_run())
def test_not_configured_to_run(self): filename = self.makeFile("RUN=0\n") sysvconfig = SysVConfig(filename) self.assertFalse(sysvconfig.is_configured_to_run())