Coverage for watcher/applier/actions/factory.py: 100%

13 statements  

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

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

2# Copyright (c) 2016 b<>com 

3# 

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

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

6# You may obtain a copy of the License at 

7# 

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

9# 

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

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

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

13# implied. 

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

15# limitations under the License. 

16# 

17 

18from oslo_log import log 

19 

20from watcher.applier.loading import default 

21 

22LOG = log.getLogger(__name__) 

23 

24 

25class ActionFactory(object): 

26 def __init__(self): 

27 self.action_loader = default.DefaultActionLoader() 

28 

29 def make_action(self, object_action, osc=None): 

30 LOG.debug("Creating instance of %s", object_action.action_type) 

31 loaded_action = self.action_loader.load(name=object_action.action_type, 

32 osc=osc) 

33 loaded_action.input_parameters = object_action.input_parameters 

34 LOG.debug("Checking the input parameters") 

35 # NOTE(jed) if we change the schema of an action and we try to reload 

36 # an older version of the Action, the validation can fail. 

37 # We need to add the versioning of an Action or a migration tool. 

38 # We can also create an new Action which extends the previous one. 

39 loaded_action.validate_parameters() 

40 return loaded_action