Coverage for nova/config.py: 90%

39 statements  

« prev     ^ index     » next       coverage.py v7.6.12, created at 2025-04-17 15:08 +0000

1# Copyright 2010 United States Government as represented by the 

2# Administrator of the National Aeronautics and Space Administration. 

3# All Rights Reserved. 

4# Copyright 2012 Red Hat, Inc. 

5# 

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

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

8# 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, WITHOUT 

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

15# License for the specific language governing permissions and limitations 

16# under the License. 

17 

18import logging 

19 

20from oslo_log import log 

21from oslo_utils import importutils 

22 

23import nova.conf 

24from nova.db.api import api as api_db_api 

25from nova.db.main import api as main_db_api 

26from nova import middleware 

27from nova import rpc 

28from nova import version 

29 

30profiler = importutils.try_import('osprofiler.opts') 

31 

32 

33CONF = nova.conf.CONF 

34 

35 

36def set_lib_defaults(): 

37 """Update default value for configuration options from other namespace. 

38 

39 Example, oslo lib config options. This is needed for 

40 config generator tool to pick these default value changes. 

41 https://docs.openstack.org/oslo.config/latest/cli/ 

42 generator.html#modifying-defaults-from-other-namespaces 

43 """ 

44 

45 # Update default value of oslo.middleware cors config option. 

46 middleware.set_defaults() 

47 

48 # Update default value of RPC transport control_exchange config option. 

49 rpc.set_defaults(control_exchange='nova') 

50 

51 # Update default value of oslo_log default_log_levels and 

52 # logging_context_format_string config option. 

53 set_log_defaults() 

54 

55 

56def rabbit_heartbeat_filter(log_record): 

57 message = "Unexpected error during heartbeat thread processing" 

58 return message not in log_record.msg 

59 

60 

61def set_log_defaults(): 

62 # We use the oslo.log default log levels which includes suds=INFO 

63 # and add only the extra levels that Nova needs 

64 if CONF.glance.debug: 

65 extra_default_log_levels = ['glanceclient=DEBUG'] 

66 else: 

67 extra_default_log_levels = ['glanceclient=WARN'] 

68 

69 # Allow cinderclient and os_brick to log at DEBUG without Nova 

70 if CONF.cinder.debug: 70 ↛ 71line 70 didn't jump to line 71 because the condition on line 70 was never true

71 extra_default_log_levels += ['cinderclient=DEBUG', 'os_brick=DEBUG'] 

72 

73 # NOTE(danms): DEBUG logging in privsep will result in some large 

74 # and potentially sensitive things being logged. 

75 extra_default_log_levels.append('oslo.privsep.daemon=INFO') 

76 

77 log.set_defaults(default_log_levels=log.get_default_log_levels() + 

78 extra_default_log_levels) 

79 

80 

81def parse_args(argv, default_config_files=None, configure_db=True, 

82 init_rpc=True): 

83 log.register_options(CONF) 

84 

85 # NOTE(sean-k-mooney): this filter addresses bug #1825584 

86 # https://bugs.launchpad.net/nova/+bug/1825584 

87 # eventlet monkey-patching breaks AMQP heartbeat on uWSGI 

88 rabbit_logger = logging.getLogger('oslo.messaging._drivers.impl_rabbit') 

89 rabbit_logger.addFilter(rabbit_heartbeat_filter) 

90 

91 set_lib_defaults() 

92 if profiler: 92 ↛ 95line 92 didn't jump to line 95 because the condition on line 92 was always true

93 profiler.set_defaults(CONF) 

94 

95 CONF(argv[1:], 

96 project='nova', 

97 version=version.version_string(), 

98 default_config_files=default_config_files) 

99 

100 if init_rpc: 

101 rpc.init(CONF) 

102 

103 if configure_db: 

104 main_db_api.configure(CONF) 

105 api_db_api.configure(CONF)