def test_systemctl_disabled(self, mock_systemctl): mock_systemctl.return_value = True self.mock_runner.run.return_value = ("disabled\n", "", 2) self.assertFalse(lib.is_service_enabled(self.mock_runner, self.service)) self.mock_runner.run.assert_called_once_with( [_systemctl, "is-enabled", self.service + ".service"])
def test_not_systemctl_disabled(self, mock_systemctl): mock_systemctl.return_value = False self.mock_runner.run.return_value = ("", "", 3) self.assertFalse(lib.is_service_enabled(self.mock_runner, self.service)) self.mock_runner.run.assert_called_once_with( [_chkconfig, self.service])
def test_systemctl_disabled(self, mock_systemctl): mock_systemctl.return_value = True self.mock_runner.run.return_value = ("disabled\n", 2) self.assertFalse(lib.is_service_enabled(self.mock_runner, self.service)) self.mock_runner.run.assert_called_once_with( ["systemctl", "is-enabled", self.service + ".service"] )
def test_not_systemctl_disabled(self, mock_systemctl): mock_systemctl.return_value = False self.mock_runner.run.return_value = ("", 3) self.assertFalse(lib.is_service_enabled(self.mock_runner, self.service)) self.mock_runner.run.assert_called_once_with( ["chkconfig", self.service] )
def test_systemctl_enabled(self, mock_systemctl): mock_systemctl.return_value = True self.mock_runner.run.return_value = ("enabled\n", "", 0) self.assertTrue(lib.is_service_enabled(self.mock_runner, self.service)) self.mock_runner.run.assert_called_once_with( [_systemctl, "is-enabled", self.service + ".service"] )
def is_sbd_enabled(runner): """ Check if SBD service is enabled in local system. Return True if SBD service is enabled, False otherwise. runner -- CommandRunner """ return external.is_service_enabled(runner, get_sbd_service_name())
def config_destroy(env, ignore_config_load_problems=False): env.booth.command_expect_live_env() if not env.is_cib_live: raise LibraryError(reports.live_environment_required(["CIB"])) name = env.booth.name config_is_used = partial(booth_reports.booth_config_is_used, name) report_list = [] if resource.find_for_config( get_resources(env.get_cib()), get_config_file_name(name), ): report_list.append(config_is_used("in cluster resource")) #Only systemd is currently supported. Initd does not supports multiple #instances (here specified by name) if external.is_systemctl(): if external.is_service_running(env.cmd_runner(), "booth", name): report_list.append(config_is_used("(running in systemd)")) if external.is_service_enabled(env.cmd_runner(), "booth", name): report_list.append(config_is_used("(enabled in systemd)")) if report_list: raise LibraryError(*report_list) authfile_path = None try: authfile_path = config_structure.get_authfile( parse(env.booth.get_config_content()) ) except LibraryError: if not ignore_config_load_problems: raise LibraryError(booth_reports.booth_cannot_identify_keyfile()) #if content not received, not valid,... still remove config needed env.report_processor.process( booth_reports.booth_cannot_identify_keyfile( severity=ReportItemSeverity.WARNING ) ) if( authfile_path and os.path.dirname(authfile_path) == settings.booth_config_dir ): env.booth.set_key_path(authfile_path) env.booth.remove_key() env.booth.remove_config()
def _get_local_services_status(runner: CommandRunner) -> List[_ServiceStatus]: service_def = [ # (service name, display even if not enabled nor running) ("corosync", True), ("pacemaker", True), ("pacemaker_remote", False), ("pcsd", True), (get_sbd_service_name(), False), ] service_status_list = [] for service, display_always in service_def: try: service_status_list.append( _ServiceStatus( service, display_always, is_service_enabled(runner, service), is_service_running(runner, service), )) except LibraryError: pass return service_status_list
def config_destroy( env: LibraryEnvironment, instance_name=None, ignore_config_load_problems=False, ): # pylint: disable=too-many-branches """ remove booth configuration files env string instance_name -- booth instance name bool ignore_config_load_problems -- delete as much as possible when unable to read booth configs for the given booth instance """ report_processor = env.report_processor booth_env = env.get_booth_env(instance_name) instance_name = booth_env.instance_name _ensure_live_env(env, booth_env) # TODO use constants in reports if resource.find_for_config( get_resources(env.get_cib()), booth_env.config_path, ): report_processor.report( ReportItem.error( reports.messages.BoothConfigIsUsed( instance_name, "in cluster resource", ) ) ) # Only systemd is currently supported. Initd does not supports multiple # instances (here specified by name) if external.is_systemctl(): if external.is_service_running( env.cmd_runner(), "booth", instance_name ): report_processor.report( ReportItem.error( reports.messages.BoothConfigIsUsed( instance_name, "(running in systemd)", ) ) ) if external.is_service_enabled( env.cmd_runner(), "booth", instance_name ): report_processor.report( ReportItem.error( reports.messages.BoothConfigIsUsed( instance_name, "(enabled in systemd)", ) ) ) if report_processor.has_errors: raise LibraryError() try: authfile_path = None booth_conf = booth_env.config.read_to_facade() authfile_path = booth_conf.get_authfile() except RawFileError as e: report_processor.report( raw_file_error_report( e, force_code=report_codes.FORCE_BOOTH_DESTROY, is_forced_or_warning=ignore_config_load_problems, ) ) except ParserErrorException as e: report_processor.report_list( booth_env.config.parser_exception_to_report_list( e, force_code=report_codes.FORCE_BOOTH_DESTROY, is_forced_or_warning=ignore_config_load_problems, ) ) if report_processor.has_errors: raise LibraryError() if authfile_path: authfile_dir, authfile_name = os.path.split(authfile_path) if (authfile_dir == settings.booth_config_dir) and authfile_name: try: key_file = FileInstance.for_booth_key(authfile_name) key_file.raw_file.remove(fail_if_file_not_found=False) except RawFileError as e: report_processor.report( raw_file_error_report( e, force_code=report_codes.FORCE_BOOTH_DESTROY, is_forced_or_warning=ignore_config_load_problems, ) ) else: report_processor.report( ReportItem.warning( reports.messages.BoothUnsupportedFileLocation( authfile_path, settings.booth_config_dir, file_type_codes.BOOTH_KEY, ) ) ) if report_processor.has_errors: raise LibraryError() try: booth_env.config.raw_file.remove() except RawFileError as e: report_processor.report(raw_file_error_report(e)) if report_processor.has_errors: raise LibraryError()
def skip_if_service_enabled(service_name): return skipUnless( not is_service_enabled(runner, service_name), "Service {0} must be disabled".format(service_name), )