Coverage for curator/validators/actions.py: 100%

20 statements  

« prev     ^ index     » next       coverage.py v7.3.0, created at 2023-08-16 15:27 -0600

1from voluptuous import All, Any, In, Schema, Optional, Required 

2from curator.defaults import settings 

3from curator.validators import SchemaCheck 

4from six import string_types 

5 

6### Schema information ### 

7# Actions: root level 

8def root(): 

9 return Schema({ Required('actions'): dict }) 

10 

11def valid_action(): 

12 return { 

13 Required('action'): Any( 

14 In(settings.all_actions()), 

15 msg='action must be one of {0}'.format( 

16 settings.all_actions() 

17 ) 

18 ) 

19 } 

20 

21# Basic action structure 

22def structure(data, location): 

23 # Validate the action type first, so we can use it for other tests 

24 _ = SchemaCheck( 

25 data, 

26 Schema(valid_action(), extra=True), 

27 'action type', 

28 location, 

29 ).result() 

30 # Build a valid schema knowing that the action has already been validated 

31 retval = valid_action() 

32 retval.update( 

33 { 

34 Optional('description', default='No description given'): Any( 

35 str, *string_types 

36 ) 

37 } 

38 ) 

39 retval.update( 

40 { Optional('options', default=settings.default_options()): dict } ) 

41 action = data['action'] 

42 if action in [ 'cluster_routing', 'create_index', 'rollover']: 

43 # The cluster_routing, create_index, and rollover actions should not 

44 # have a 'filters' block 

45 pass 

46 elif action == 'alias': 

47 # The alias action should not have a filters block, but should have 

48 # an add and/or remove block. 

49 retval.update( 

50 { 

51 Optional('add'): dict, 

52 Optional('remove'): dict, 

53 } 

54 ) 

55 else: 

56 retval.update( 

57 { Optional('filters', default=settings.default_filters()): list } 

58 ) 

59 return Schema(retval)