class ValidateService(Validator): """Validate a services configuration.""" config_class = ConfigService service_context = command_context.build_filled_context( command_context.ServiceInstanceContext) service_pid_context = command_context.build_filled_context( command_context.ServiceInstancePidContext) defaults = {'count': 1, 'monitor_retries': 3, 'restart_delay': None} validators = { 'name': valid_name_identifier, 'pid_file': build_format_string_validator(service_pid_context), 'command': build_format_string_validator(service_context), 'monitor_interval': valid_float, 'monitor_retries': valid_int, 'count': valid_int, 'node': valid_node_name, 'restart_delay': valid_float, } def cast(self, in_dict, config_context): in_dict['namespace'] = config_context.namespace # TODO: Deprecated - remove in 0.7 if 'restart_interval' in in_dict: msg = ("restart_interval at %s is deprecated. It has been renamed " "restart_delay and will be removed in 0.7") log.warn(msg % config_context.path) in_dict['restart_delay'] = in_dict.pop('restart_interval') return in_dict
class ValidateService(Validator): """Validate a services configuration.""" config_class = ConfigService service_context = command_context.build_filled_context( command_context.ServiceInstanceContext, ) service_pid_context = command_context.build_filled_context( command_context.ServiceInstancePidContext, ) defaults = { 'count': 1, 'monitor_retries': 5, 'restart_delay': None, } validators = { 'name': valid_name_identifier, 'pid_file': build_format_string_validator(service_pid_context), 'command': build_format_string_validator(service_context), 'monitor_interval': valid_float, 'monitor_retries': valid_int, 'count': valid_int, 'node': valid_node_name, 'restart_delay': valid_float, } def cast(self, in_dict, config_context): in_dict['namespace'] = config_context.namespace return in_dict
def test_build_filled_context_chain(self): objs = [command_context.JobContext, command_context.JobRunContext] output = command_context.build_filled_context(*objs) assert isinstance(output.base, objs[1]) assert isinstance(output.next.base, objs[0]) assert not output.next.next
def test_build_filled_context_single(self): output = command_context.build_filled_context(command_context.JobContext) assert isinstance(output.base, command_context.JobContext) assert not output.next
def test_build_filled_context_no_objects(self): output = command_context.build_filled_context() assert not output.base assert not output.next
valid_node_pool = ValidateNodePool() def valid_action_name(value, config_context): valid_identifier(value, config_context) if value == CLEANUP_ACTION_NAME: error_msg = "Invalid action name %s at %s" raise ConfigError(error_msg % (value, config_context.path)) return value action_context = command_context.build_filled_context( command_context.JobContext, command_context.JobRunContext, command_context.ActionRunContext, ) def valid_mesos_action(action, config_context): required_keys = {'cpus', 'mem', 'docker_image'} if action.get('executor') == schema.ExecutorTypes.mesos: missing_keys = required_keys - set(action.keys()) if missing_keys: raise ConfigError( 'Mesos executor for action {id} is missing these required keys: {keys}' .format( id=action['name'], keys=missing_keys, ), )
def test_build_filled_context_single(self): output = command_context.build_filled_context( command_context.JobContext) assert isinstance(output.base, command_context.JobContext) assert not output.next
def set_defaults(self, node_pool, _): node_pool.setdefault('name', '_'.join(node_pool['nodes'])) valid_node_pool = ValidateNodePool() def valid_action_name(value, config_context): valid_identifier(value, config_context) if value == CLEANUP_ACTION_NAME: error_msg = "Invalid action name %s at %s" raise ConfigError(error_msg % (value, config_context.path)) return value action_context = command_context.build_filled_context( command_context.JobContext, command_context.JobRunContext, command_context.ActionRunContext) class ValidateAction(Validator): """Validate an action.""" config_class = ConfigAction defaults = { 'node': None, 'requires': (), } requires = build_list_of_type_validator(valid_action_name, allow_empty=True) validators = { 'name': valid_action_name, 'command': build_format_string_validator(action_context),