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
« 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#
20import time
22from oslo_log import log
23from watcher.applier.actions import base
25LOG = log.getLogger(__name__)
28class Sleep(base.BaseAction):
29 """Makes the executor of the action plan wait for a given duration
31 The action schema is::
33 schema = Schema({
34 'duration': float,
35 })
37 The `duration` is expressed in seconds.
38 """
40 DURATION = 'duration'
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 }
56 @property
57 def duration(self):
58 return int(self.input_parameters.get(self.DURATION))
60 def execute(self):
61 LOG.debug("Starting action sleep with duration: %s ", self.duration)
62 time.sleep(self.duration)
63 return True
65 def revert(self):
66 LOG.debug("Revert action sleep")
67 return True
69 def pre_condition(self):
70 pass
72 def post_condition(self):
73 pass
75 def get_description(self):
76 """Description of the action"""
77 return "Wait for a given interval in seconds."
79 def abort(self):
80 LOG.debug("Abort action sleep")
81 return True