Coverage for watcher/decision_engine/strategy/strategies/dummy_with_resize.py: 57%

35 statements  

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

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

2# 

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

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

5# You may obtain a copy of the License at 

6# 

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

8# 

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

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

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

12# implied. 

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

14# limitations under the License. 

15# 

16from oslo_log import log 

17 

18from watcher._i18n import _ 

19from watcher.decision_engine.strategy.strategies import base 

20 

21LOG = log.getLogger(__name__) 

22 

23 

24class DummyWithResize(base.DummyBaseStrategy): 

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

26 

27 *Description* 

28 

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

30 is to be used by Tempest tests. 

31 

32 *Requirements* 

33 

34 <None> 

35 

36 *Limitations* 

37 

38 Do not use in production. 

39 

40 *Spec URL* 

41 

42 <None> 

43 """ 

44 

45 NOP = "nop" 

46 SLEEP = "sleep" 

47 

48 def pre_execute(self): 

49 self._pre_execute() 

50 

51 def do_execute(self, audit=None): 

52 para1 = self.input_parameters.para1 

53 para2 = self.input_parameters.para2 

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

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

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

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

58 input_parameters=parameters) 

59 

60 parameters = {'message': 'Welcome'} 

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

62 input_parameters=parameters) 

63 

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

65 input_parameters={'duration': 5.0}) 

66 self.solution.add_action( 

67 action_type='migrate', 

68 resource_id='b199db0c-1408-4d52-b5a5-5ca14de0ff36', 

69 input_parameters={ 

70 'source_node': 'compute2', 

71 'destination_node': 'compute3', 

72 'migration_type': 'live'}) 

73 

74 self.solution.add_action( 

75 action_type='migrate', 

76 resource_id='8db1b3c1-7938-4c34-8c03-6de14b874f8f', 

77 input_parameters={ 

78 'source_node': 'compute2', 

79 'destination_node': 'compute3', 

80 'migration_type': 'live'} 

81 ) 

82 self.solution.add_action( 

83 action_type='resize', 

84 resource_id='8db1b3c1-7938-4c34-8c03-6de14b874f8f', 

85 input_parameters={'flavor': 'x2'} 

86 ) 

87 

88 def post_execute(self): 

89 pass 

90 

91 @classmethod 

92 def get_name(cls): 

93 return "dummy_with_resize" 

94 

95 @classmethod 

96 def get_display_name(cls): 

97 return _("Dummy strategy with resize") 

98 

99 @classmethod 

100 def get_translatable_display_name(cls): 

101 return "Dummy strategy with resize" 

102 

103 @classmethod 

104 def get_schema(cls): 

105 # Mandatory default setting for each element 

106 return { 

107 "properties": { 

108 "para1": { 

109 "description": "number parameter example", 

110 "type": "number", 

111 "default": 3.2, 

112 "minimum": 1.0, 

113 "maximum": 10.2, 

114 }, 

115 "para2": { 

116 "description": "string parameter example", 

117 "type": "string", 

118 "default": "hello" 

119 }, 

120 }, 

121 }