[openstack-neutron/el6-havana] Sync service and systemd modules from oslo-incubator

Ihar Hrachyshka ihrachyshka at fedoraproject.org
Mon Apr 28 16:08:10 UTC 2014


commit db935845f0a1c0172b714de3ea8a88d5f88d3935
Author: Ihar Hrachyshka <ihrachys at redhat.com>
Date:   Mon Apr 28 17:58:30 2014 +0200

    Sync service and systemd modules from oslo-incubator

 ...e-and-systemd-modules-from-oslo-incubator.patch |  151 ++++++++++++++++++++
 openstack-neutron.spec                             |    7 +-
 2 files changed, 157 insertions(+), 1 deletions(-)
---
diff --git a/0003-Sync-service-and-systemd-modules-from-oslo-incubator.patch b/0003-Sync-service-and-systemd-modules-from-oslo-incubator.patch
new file mode 100644
index 0000000..823b146
--- /dev/null
+++ b/0003-Sync-service-and-systemd-modules-from-oslo-incubator.patch
@@ -0,0 +1,151 @@
+From 18ae28ae43aad3c085e1d28bb981608dd85ed479 Mon Sep 17 00:00:00 2001
+From: Jakub Libosvar <libosvar at redhat.com>
+Date: Mon, 17 Mar 2014 16:36:01 +0100
+Subject: [PATCH] Sync service and systemd modules from oslo-incubator
+
+This patch make systemd know when neutron-service was started. This is
+needed in HA environment, previously systemd returned success even
+before neutron-server was able to handle requests.
+
+Current oslo-incubator commit on HEAD:
+b7ad6ddab8b1d61bf4f52ccaa461a9d68809747b
+
+Implements: blueprint service-readiness
+Change-Id: Ic9e4abd11b614a896fbd7454b9a604a69a248d0f (Neutron)
+Change-Id: I80f325c9be9c171c2dc8d5526570bf64f0f87c78 (Oslo)
+---
+ neutron/openstack/common/systemd.py | 104 ++++++++++++++++++++++++++++++++++++
+ neutron/server/__init__.py          |   2 +
+ 2 files changed, 106 insertions(+)
+ create mode 100644 neutron/openstack/common/systemd.py
+
+diff --git a/neutron/openstack/common/systemd.py b/neutron/openstack/common/systemd.py
+new file mode 100644
+index 0000000..e1ba656
+--- /dev/null
++++ b/neutron/openstack/common/systemd.py
+@@ -0,0 +1,104 @@
++# Copyright 2012-2014 Red Hat, Inc.
++#
++#    Licensed under the Apache License, Version 2.0 (the "License"); you may
++#    not use this file except in compliance with the License. You may obtain
++#    a copy of the License at
++#
++#         http://www.apache.org/licenses/LICENSE-2.0
++#
++#    Unless required by applicable law or agreed to in writing, software
++#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
++#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
++#    License for the specific language governing permissions and limitations
++#    under the License.
++
++"""
++Helper module for systemd service readiness notification.
++"""
++
++import os
++import socket
++import sys
++
++from neutron.openstack.common import log as logging
++
++
++LOG = logging.getLogger(__name__)
++
++
++def _abstractify(socket_name):
++    if socket_name.startswith('@'):
++        # abstract namespace socket
++        socket_name = '\0%s' % socket_name[1:]
++    return socket_name
++
++
++def _sd_notify(unset_env, msg):
++    notify_socket = os.getenv('NOTIFY_SOCKET')
++    if notify_socket:
++        sock = socket.socket(socket.AF_UNIX, socket.SOCK_DGRAM)
++        try:
++            sock.connect(_abstractify(notify_socket))
++            sock.sendall(msg)
++            if unset_env:
++                del os.environ['NOTIFY_SOCKET']
++        except EnvironmentError:
++            LOG.debug("Systemd notification failed", exc_info=True)
++        finally:
++            sock.close()
++
++
++def notify():
++    """Send notification to Systemd that service is ready.
++    For details see
++      http://www.freedesktop.org/software/systemd/man/sd_notify.html
++    """
++    _sd_notify(False, 'READY=1')
++
++
++def notify_once():
++    """Send notification once to Systemd that service is ready.
++    Systemd sets NOTIFY_SOCKET environment variable with the name of the
++    socket listening for notifications from services.
++    This method removes the NOTIFY_SOCKET environment variable to ensure
++    notification is sent only once.
++    """
++    _sd_notify(True, 'READY=1')
++
++
++def onready(notify_socket, timeout):
++    """Wait for systemd style notification on the socket.
++
++    :param notify_socket: local socket address
++    :type notify_socket:  string
++    :param timeout:       socket timeout
++    :type timeout:        float
++    :returns:             0 service ready
++                          1 service not ready
++                          2 timeout occured
++    """
++    sock = socket.socket(socket.AF_UNIX, socket.SOCK_DGRAM)
++    sock.settimeout(timeout)
++    sock.bind(_abstractify(notify_socket))
++    try:
++        msg = sock.recv(512)
++    except socket.timeout:
++        return 2
++    finally:
++        sock.close()
++    if 'READY=1' in msg:
++        return 0
++    else:
++        return 1
++
++
++if __name__ == '__main__':
++    # simple CLI for testing
++    if len(sys.argv) == 1:
++        notify()
++    elif len(sys.argv) >= 2:
++        timeout = float(sys.argv[1])
++        notify_socket = os.getenv('NOTIFY_SOCKET')
++        if notify_socket:
++            retval = onready(notify_socket, timeout)
++            sys.exit(retval)
+diff --git a/neutron/server/__init__.py b/neutron/server/__init__.py
+index e8a4051..64bf4ee 100755
+--- a/neutron/server/__init__.py
++++ b/neutron/server/__init__.py
+@@ -28,6 +28,7 @@ from neutron.common import config
+ from neutron import service
+ 
+ from neutron.openstack.common import gettextutils
++from neutron.openstack.common import systemd
+ gettextutils.install('neutron', lazy=False)
+ 
+ 
+@@ -42,6 +43,7 @@ def main():
+                    " the '--config-file' option!"))
+     try:
+         neutron_service = service.serve_wsgi(service.NeutronApiService)
++        systemd.notify_once()
+         neutron_service.wait()
+     except RuntimeError as e:
+         sys.exit(_("ERROR: %s") % e)
diff --git a/openstack-neutron.spec b/openstack-neutron.spec
index 2066098..ddd3778 100644
--- a/openstack-neutron.spec
+++ b/openstack-neutron.spec
@@ -2,7 +2,7 @@
 
 Name:		openstack-neutron
 Version:	2013.2.3
-Release:	2%{?dist}
+Release:	3%{?dist}
 Provides:	openstack-quantum = %{version}-%{release}
 Obsoletes:	openstack-quantum < 2013.2-0.3.b3
 
@@ -56,6 +56,7 @@ Source90:	neutron-dist.conf
 #
 Patch0001: 0001-use-parallel-installed-versions-in-RHEL6.patch
 Patch0002: 0002-Remove-dnsmasq-version-warning.patch
+Patch0003: 0003-Sync-service-and-systemd-modules-from-oslo-incubator.patch
 
 BuildArch:	noarch
 
@@ -423,6 +424,7 @@ IPSec.
 
 %patch0001 -p1
 %patch0002 -p1
+%patch0003 -p1
 
 find neutron -name \*.py -exec sed -i '/\/usr\/bin\/env python/{d;q}' {} +
 
@@ -1022,6 +1024,9 @@ fi
 
 
 %changelog
+* Mon Apr 28 2014 Ihar Hrachyshka <ihrachys at redhat.com> 2013.2.3-3
+- Sync service and systemd modules from oslo-incubator, bz#1063427
+
 * Thu Apr 10 2014 Ihar Hrachyshka <ihrachys at redhat.com> 2013.2.3-2
 - Remove signing_dir from neutron-dist.conf, bz#1050842
 


More information about the scm-commits mailing list