Coverage for watcher/decision_engine/strategy/strategies/dummy_strategy.py: 97%

32 statements  

« prev     ^ index     » next       coverage.py v7.8.2, created at 2025-06-17 12:22 +0000

1# -*- encoding: utf-8 -*- 

2# Copyright (c) 2015 b<>com 

3# 

4# Authors: Jean-Emile DARTOIS <jean-emile.dartois@b-com.com> 

5# 

6# Licensed under the Apache License, Version 2.0 (the "License"); 

7# you may not use this file except in compliance with the License. 

8# You may obtain a copy of the License at 

9# 

10# http://www.apache.org/licenses/LICENSE-2.0 

11# 

12# Unless required by applicable law or agreed to in writing, software 

13# distributed under the License is distributed on an "AS IS" BASIS, 

14# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 

15# implied. 

16# See the License for the specific language governing permissions and 

17# limitations under the License. 

18# 

19from oslo_log import log 

20 

21from watcher._i18n import _ 

22from watcher.decision_engine.strategy.strategies import base 

23 

24LOG = log.getLogger(__name__) 

25 

26 

27class DummyStrategy(base.DummyBaseStrategy): 

28 """Dummy strategy used for integration testing via Tempest 

29 

30 *Description* 

31 

32 This strategy does not provide any useful optimization. Its only purpose 

33 is to be used by Tempest tests. 

34 

35 *Requirements* 

36 

37 <None> 

38 

39 *Limitations* 

40 

41 Do not use in production. 

42 

43 *Spec URL* 

44 

45 <None> 

46 """ 

47 

48 NOP = "nop" 

49 SLEEP = "sleep" 

50 

51 def pre_execute(self): 

52 self._pre_execute() 

53 

54 def do_execute(self, audit=None): 

55 para1 = self.input_parameters.para1 

56 para2 = self.input_parameters.para2 

57 LOG.debug("Executing Dummy strategy with para1=%(p1)f, para2=%(p2)s", 

58 {'p1': para1, 'p2': para2}) 

59 parameters = {'message': 'hello World'} 

60 self.solution.add_action(action_type=self.NOP, 

61 input_parameters=parameters) 

62 

63 parameters = {'message': para2} 

64 self.solution.add_action(action_type=self.NOP, 

65 input_parameters=parameters) 

66 

67 self.solution.add_action(action_type=self.SLEEP, 

68 input_parameters={'duration': para1}) 

69 

70 def post_execute(self): 

71 pass 

72 

73 @classmethod 

74 def get_name(cls): 

75 return "dummy" 

76 

77 @classmethod 

78 def get_display_name(cls): 

79 return _("Dummy strategy") 

80 

81 @classmethod 

82 def get_translatable_display_name(cls): 

83 return "Dummy strategy" 

84 

85 @classmethod 

86 def get_schema(cls): 

87 # Mandatory default setting for each element 

88 return { 

89 "properties": { 

90 "para1": { 

91 "description": "number parameter example", 

92 "type": "number", 

93 "default": 3.2, 

94 "minimum": 1.0, 

95 "maximum": 10.2, 

96 }, 

97 "para2": { 

98 "description": "string parameter example", 

99 "type": "string", 

100 "default": "hello" 

101 }, 

102 }, 

103 }