Coverage for nova/version.py: 89%

48 statements  

« prev     ^ index     » next       coverage.py v7.6.12, created at 2025-04-24 11:16 +0000

1# Copyright 2011 OpenStack Foundation 

2# 

3# Licensed under the Apache License, Version 2.0 (the "License"); you may 

4# not use this file except in compliance with the License. You may obtain 

5# a copy of the License at 

6# 

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

8# 

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

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

11# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 

12# License for the specific language governing permissions and limitations 

13# under the License. 

14 

15import pbr.version 

16 

17NOVA_VENDOR = "OpenStack Foundation" 

18NOVA_PRODUCT = "OpenStack Nova" 

19NOVA_PACKAGE = None # OS distro package version suffix 

20NOVA_SUPPORT = ( 

21 "Please report this at http://bugs.launchpad.net/nova/ " 

22 "and attach the Nova API log if possible.") 

23 

24loaded = False 

25version_info = pbr.version.VersionInfo('nova') 

26version_string = version_info.version_string 

27 

28 

29def _load_config(): 

30 # Don't load in global context, since we can't assume 

31 # these modules are accessible when distutils uses 

32 # this module 

33 import configparser 

34 

35 from oslo_config import cfg 

36 

37 from oslo_log import log as logging 

38 

39 global loaded, NOVA_VENDOR, NOVA_PRODUCT, NOVA_PACKAGE, NOVA_SUPPORT 

40 if loaded: 

41 return 

42 

43 loaded = True 

44 

45 cfgfile = cfg.CONF.find_file("release") 

46 if cfgfile is None: 

47 return 

48 

49 try: 

50 cfg = configparser.RawConfigParser() 

51 cfg.read(cfgfile) 

52 

53 if cfg.has_option("Nova", "vendor"): 53 ↛ 56line 53 didn't jump to line 56 because the condition on line 53 was always true

54 NOVA_VENDOR = cfg.get("Nova", "vendor") 

55 

56 if cfg.has_option("Nova", "product"): 56 ↛ 59line 56 didn't jump to line 59 because the condition on line 56 was always true

57 NOVA_PRODUCT = cfg.get("Nova", "product") 

58 

59 if cfg.has_option("Nova", "package"): 59 ↛ 62line 59 didn't jump to line 62 because the condition on line 59 was always true

60 NOVA_PACKAGE = cfg.get("Nova", "package") 

61 

62 if cfg.has_option("Nova", "support"): 62 ↛ exitline 62 didn't return from function '_load_config' because the condition on line 62 was always true

63 NOVA_SUPPORT = cfg.get("Nova", "support") 

64 except Exception as ex: 

65 LOG = logging.getLogger(__name__) 

66 LOG.error("Failed to load %(cfgfile)s: %(ex)s", 

67 {'cfgfile': cfgfile, 'ex': ex}) 

68 

69 

70def vendor_string(): 

71 _load_config() 

72 

73 return NOVA_VENDOR 

74 

75 

76def product_string(): 

77 _load_config() 

78 

79 return NOVA_PRODUCT 

80 

81 

82def package_string(): 

83 _load_config() 

84 

85 return NOVA_PACKAGE 

86 

87 

88def version_string_with_package(): 

89 if package_string() is None: 

90 return version_info.version_string() 

91 else: 

92 return "%s-%s" % (version_info.version_string(), package_string()) 

93 

94 

95def support_string(): 

96 _load_config() 

97 

98 return NOVA_SUPPORT