~ubuntu-server-dev/nova/icehouse

« back to all changes in this revision

Viewing changes to debian/patches/add-support-for-syslog-connect-retries.patch

  • Committer: james.page at ubuntu
  • Date: 2015-07-16 10:56:04 UTC
  • mfrom: (704.1.5 icehouse)
  • Revision ID: james.page@ubuntu.com-20150716105604-kwj3ip8txujkjnme
Tags: 1:2014.1.5-0ubuntu1.2
releasing package nova version 1:2014.1.5-0ubuntu1.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
From fa2a6c6b6aee59b1a98fa7b93f55405457449bf0 Mon Sep 17 00:00:00 2001
 
2
From: Edward Hope-Morley <edward.hope-morley@canonical.com>
 
3
Date: Thu, 18 Jun 2015 13:38:58 +0100
 
4
Subject: [PATCH] Add support for syslog connect retries
 
5
 
 
6
If we have requested logging to syslog and syslog is
 
7
not yet ready we shoudl allow for retry attempts. This
 
8
patch provides a new option syslog-connect-retries to
 
9
allow for retries with a 5 second interval between
 
10
each retry.
 
11
 
 
12
Closes-Bug: 1459046
 
13
Co-authored-by: Liang Chen <liang.chen@canonical.com>
 
14
Conflicts:
 
15
        nova/openstack/common/log.py
 
16
 
 
17
Change-Id: I88269a75c56c68443230620217a469aebee523f8
 
18
---
 
19
 nova/openstack/common/log.py | 58 +++++++++++++++++++++++++++++++++++---------
 
20
 1 file changed, 46 insertions(+), 12 deletions(-)
 
21
 
 
22
diff --git a/nova/openstack/common/log.py b/nova/openstack/common/log.py
 
23
index cdc439a..71700b7 100644
 
24
--- a/nova/openstack/common/log.py
 
25
+++ b/nova/openstack/common/log.py
 
26
@@ -34,7 +34,9 @@ import logging.config
 
27
 import logging.handlers
 
28
 import os
 
29
 import re
 
30
+import socket
 
31
 import sys
 
32
+import time
 
33
 import traceback
 
34
 
 
35
 from oslo.config import cfg
 
36
@@ -118,6 +120,10 @@ logging_cli_opts = [
 
37
                 help='Use syslog for logging. '
 
38
                      'Existing syslog format is DEPRECATED during I, '
 
39
                      'and then will be changed in J to honor RFC5424'),
 
40
+    cfg.IntOpt('syslog-connect-retries',
 
41
+               default=3,
 
42
+               help='Number of attempts with a five second interval to retry '
 
43
+                    'connecting to syslog. (if use-syslog=True)'),
 
44
     cfg.BoolOpt('use-syslog-rfc-format',
 
45
                 # TODO(bogdando) remove or use True after existing
 
46
                 #    syslog format deprecation in J
 
47
@@ -490,18 +496,6 @@ def _setup_logging_from_conf():
 
48
     for handler in log_root.handlers:
 
49
         log_root.removeHandler(handler)
 
50
 
 
51
-    if CONF.use_syslog:
 
52
-        facility = _find_facility_from_conf()
 
53
-        # TODO(bogdando) use the format provided by RFCSysLogHandler
 
54
-        #   after existing syslog format deprecation in J
 
55
-        if CONF.use_syslog_rfc_format:
 
56
-            syslog = RFCSysLogHandler(address='/dev/log',
 
57
-                                      facility=facility)
 
58
-        else:
 
59
-            syslog = logging.handlers.SysLogHandler(address='/dev/log',
 
60
-                                                    facility=facility)
 
61
-        log_root.addHandler(syslog)
 
62
-
 
63
     logpath = _get_log_file_path()
 
64
     if logpath:
 
65
         filelog = logging.handlers.WatchedFileHandler(logpath)
 
66
@@ -548,6 +542,46 @@ def _setup_logging_from_conf():
 
67
         logger = logging.getLogger(mod)
 
68
         logger.setLevel(level)
 
69
 
 
70
+    if CONF.use_syslog:
 
71
+        retries = CONF.syslog_connect_retries
 
72
+        syslog_ready = False
 
73
+        while True:
 
74
+            try:
 
75
+                facility = _find_facility_from_conf()
 
76
+                # TODO(bogdando) use the format provided by RFCSysLogHandler
 
77
+                #   after existing syslog format deprecation in J
 
78
+                if CONF.use_syslog_rfc_format:
 
79
+                    syslog = RFCSysLogHandler(address='/dev/log',
 
80
+                                              facility=facility)
 
81
+                else:
 
82
+                    syslog = logging.handlers.SysLogHandler(address='/dev/log',
 
83
+                                                            facility=facility)
 
84
+                log_root.addHandler(syslog)
 
85
+                syslog_ready = True
 
86
+            except socket.error:
 
87
+                if CONF.syslog_connect_retries <= 0:
 
88
+                    log_root.error(_('Connection to syslog failed and no '
 
89
+                                     'retry attempts requested'))
 
90
+                    break
 
91
+
 
92
+                if retries:
 
93
+                    log_root.info(_('Connection to syslog failed - '
 
94
+                                    'retrying in 5 seconds'))
 
95
+                    retries -= 1
 
96
+                else:
 
97
+                    log_root.error(_('Connection to syslog failed and '
 
98
+                                     'max retry attempts reached'))
 
99
+                    break
 
100
+
 
101
+                time.sleep(5)
 
102
+            else:
 
103
+                break
 
104
+
 
105
+        if not syslog_ready:
 
106
+            log_root.error(_('Unable to add syslog handler. Verify that '
 
107
+                             'syslog is running.'))
 
108
+
 
109
+
 
110
 _loggers = {}
 
111
 
 
112
 
 
113
-- 
 
114
1.9.1
 
115