Coverage for watcher/common/loader/loadable.py: 100%

11 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 

17import abc 

18 

19from watcher.common import service 

20 

21 

22class Loadable(object, metaclass=abc.ABCMeta): 

23 """Generic interface for dynamically loading a driver/entry point. 

24 

25 This defines the contract in order to let the loader manager inject 

26 the configuration parameters during the loading. 

27 """ 

28 

29 def __init__(self, config): 

30 super(Loadable, self).__init__() 

31 self.config = config 

32 

33 @classmethod 

34 @abc.abstractmethod 

35 def get_config_opts(cls): 

36 """Defines the configuration options to be associated to this loadable 

37 

38 :return: A list of configuration options relative to this Loadable 

39 :rtype: list of :class:`oslo_config.cfg.Opt` instances 

40 """ 

41 raise NotImplementedError 

42 

43 

44LoadableSingletonMeta = type( 

45 "LoadableSingletonMeta", (abc.ABCMeta, service.Singleton), {}) 

46 

47 

48class LoadableSingleton(object, metaclass=LoadableSingletonMeta): 

49 """Generic interface for dynamically loading a driver as a singleton. 

50 

51 This defines the contract in order to let the loader manager inject 

52 the configuration parameters during the loading. Classes inheriting from 

53 this class will be singletons. 

54 """ 

55 

56 def __init__(self, config): 

57 super(LoadableSingleton, self).__init__() 

58 self.config = config 

59 

60 @classmethod 

61 @abc.abstractmethod 

62 def get_config_opts(cls): 

63 """Defines the configuration options to be associated to this loadable 

64 

65 :return: A list of configuration options relative to this Loadable 

66 :rtype: list of :class:`oslo_config.cfg.Opt` instances 

67 """ 

68 raise NotImplementedError