Coverage for watcher/applier/actions/sleep.py: 79%

28 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# 

19 

20import time 

21 

22from oslo_log import log 

23from watcher.applier.actions import base 

24 

25LOG = log.getLogger(__name__) 

26 

27 

28class Sleep(base.BaseAction): 

29 """Makes the executor of the action plan wait for a given duration 

30 

31 The action schema is:: 

32 

33 schema = Schema({ 

34 'duration': float, 

35 }) 

36 

37 The `duration` is expressed in seconds. 

38 """ 

39 

40 DURATION = 'duration' 

41 

42 @property 

43 def schema(self): 

44 return { 

45 'type': 'object', 

46 'properties': { 

47 'duration': { 

48 'type': 'number', 

49 'minimum': 0 

50 }, 

51 }, 

52 'required': ['duration'], 

53 'additionalProperties': False, 

54 } 

55 

56 @property 

57 def duration(self): 

58 return int(self.input_parameters.get(self.DURATION)) 

59 

60 def execute(self): 

61 LOG.debug("Starting action sleep with duration: %s ", self.duration) 

62 time.sleep(self.duration) 

63 return True 

64 

65 def revert(self): 

66 LOG.debug("Revert action sleep") 

67 return True 

68 

69 def pre_condition(self): 

70 pass 

71 

72 def post_condition(self): 

73 pass 

74 

75 def get_description(self): 

76 """Description of the action""" 

77 return "Wait for a given interval in seconds." 

78 

79 def abort(self): 

80 LOG.debug("Abort action sleep") 

81 return True