Coverage for watcher/applier/default.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_config import cfg 

20from oslo_log import log 

21 

22from watcher.applier import base 

23from watcher.applier.loading import default 

24from watcher import objects 

25 

26LOG = log.getLogger(__name__) 

27CONF = cfg.CONF 

28 

29 

30class DefaultApplier(base.BaseApplier): 

31 def __init__(self, context, applier_manager): 

32 super(DefaultApplier, self).__init__() 

33 self._applier_manager = applier_manager 

34 self._loader = default.DefaultWorkFlowEngineLoader() 

35 self._engine = None 

36 self._context = context 

37 

38 @property 

39 def context(self): 

40 return self._context 

41 

42 @property 

43 def applier_manager(self): 

44 return self._applier_manager 

45 

46 @property 

47 def engine(self): 

48 if self._engine is None: 48 ↛ 55line 48 didn't jump to line 55 because the condition on line 48 was always true

49 selected_workflow_engine = CONF.watcher_applier.workflow_engine 

50 LOG.debug("Loading workflow engine %s ", selected_workflow_engine) 

51 self._engine = self._loader.load( 

52 name=selected_workflow_engine, 

53 context=self.context, 

54 applier_manager=self.applier_manager) 

55 return self._engine 

56 

57 def execute(self, action_plan_uuid): 

58 LOG.debug("Executing action plan %s ", action_plan_uuid) 

59 

60 filters = {'action_plan_uuid': action_plan_uuid} 

61 actions = objects.Action.list(self.context, filters=filters, 

62 eager=True) 

63 return self.engine.execute(actions)