Blame SOURCES/bz1568588-5-python-library.patch

391384
From 13ae97dec5754642af4d0d0edc03d9290e792e7f Mon Sep 17 00:00:00 2001
391384
From: Oyvind Albrigtsen <oalbrigt@redhat.com>
391384
Date: Thu, 19 Jul 2018 16:12:35 +0200
391384
Subject: [PATCH 1/5] Add Python library
391384
391384
---
391384
 heartbeat/Makefile.am |   3 +-
391384
 heartbeat/ocf.py      | 136 ++++++++++++++++++++++++++++++++++++++++++++++++++
391384
 2 files changed, 138 insertions(+), 1 deletion(-)
391384
 create mode 100644 heartbeat/ocf.py
391384
391384
diff --git a/heartbeat/Makefile.am b/heartbeat/Makefile.am
391384
index d4750bf09..1333f8feb 100644
391384
--- a/heartbeat/Makefile.am
391384
+++ b/heartbeat/Makefile.am
391384
@@ -185,7 +185,8 @@ ocfcommon_DATA		= ocf-shellfuncs 	\
391384
 			  ora-common.sh		\
391384
 			  mysql-common.sh	\
391384
 			  nfsserver-redhat.sh	\
391384
-			  findif.sh
391384
+			  findif.sh		\
391384
+			  ocf.py
391384
 
391384
 # Legacy locations
391384
 hbdir			= $(sysconfdir)/ha.d
391384
diff --git a/heartbeat/ocf.py b/heartbeat/ocf.py
391384
new file mode 100644
391384
index 000000000..12be7a2a4
391384
--- /dev/null
391384
+++ b/heartbeat/ocf.py
391384
@@ -0,0 +1,136 @@
391384
+#
391384
+# Copyright (c) 2016 Red Hat, Inc, Oyvind Albrigtsen
391384
+#                    All Rights Reserved.
391384
+#
391384
+#
391384
+# This library is free software; you can redistribute it and/or
391384
+# modify it under the terms of the GNU Lesser General Public
391384
+# License as published by the Free Software Foundation; either
391384
+# version 2.1 of the License, or (at your option) any later version.
391384
+#
391384
+# This library is distributed in the hope that it will be useful,
391384
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
391384
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
391384
+# Lesser General Public License for more details.
391384
+#
391384
+# You should have received a copy of the GNU Lesser General Public
391384
+# License along with this library; if not, write to the Free Software
391384
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
391384
+# 
391384
+
391384
+import sys, os, logging, syslog
391384
+
391384
+argv=sys.argv
391384
+env=os.environ
391384
+
391384
+#
391384
+# 	Common variables for the OCF Resource Agents supplied by
391384
+# 	heartbeat.
391384
+#
391384
+
391384
+OCF_SUCCESS=0
391384
+OCF_ERR_GENERIC=1
391384
+OCF_ERR_ARGS=2
391384
+OCF_ERR_UNIMPLEMENTED=3
391384
+OCF_ERR_PERM=4
391384
+OCF_ERR_INSTALLED=5
391384
+OCF_ERR_CONFIGURED=6
391384
+OCF_NOT_RUNNING=7
391384
+
391384
+# Non-standard values.
391384
+#
391384
+# OCF does not include the concept of master/slave resources so we
391384
+#   need to extend it so we can discover a resource's complete state.
391384
+#
391384
+# OCF_RUNNING_MASTER:  
391384
+#    The resource is in "master" mode and fully operational
391384
+# OCF_FAILED_MASTER:
391384
+#    The resource is in "master" mode but in a failed state
391384
+# 
391384
+# The extra two values should only be used during a probe.
391384
+#
391384
+# Probes are used to discover resources that were started outside of
391384
+#    the CRM and/or left behind if the LRM fails.
391384
+# 
391384
+# They can be identified in RA scripts by checking for:
391384
+#   [ "${__OCF_ACTION}" = "monitor" -a "${OCF_RESKEY_CRM_meta_interval}" = "0" ]
391384
+# 
391384
+# Failed "slaves" should continue to use: OCF_ERR_GENERIC
391384
+# Fully operational "slaves" should continue to use: OCF_SUCCESS
391384
+#
391384
+OCF_RUNNING_MASTER=8
391384
+OCF_FAILED_MASTER=9
391384
+
391384
+
391384
+## Own logger handler that uses old-style syslog handler as otherwise
391384
+## everything is sourced from /dev/syslog
391384
+class SyslogLibHandler(logging.StreamHandler):
391384
+	"""
391384
+	A handler class that correctly push messages into syslog
391384
+	"""
391384
+	def emit(self, record):
391384
+		syslog_level = {
391384
+			logging.CRITICAL:syslog.LOG_CRIT,
391384
+			logging.ERROR:syslog.LOG_ERR,
391384
+			logging.WARNING:syslog.LOG_WARNING,
391384
+			logging.INFO:syslog.LOG_INFO,
391384
+			logging.DEBUG:syslog.LOG_DEBUG,
391384
+			logging.NOTSET:syslog.LOG_DEBUG,
391384
+		}[record.levelno]
391384
+
391384
+		msg = self.format(record)
391384
+
391384
+		# syslog.syslog can not have 0x00 character inside or exception
391384
+		# is thrown
391384
+		syslog.syslog(syslog_level, msg.replace("\x00","\n"))
391384
+		return
391384
+
391384
+
391384
+OCF_RESOURCE_INSTANCE = env.get("OCF_RESOURCE_INSTANCE")
391384
+
391384
+HA_DEBUG = env.get("HA_debug", 0)
391384
+HA_DATEFMT = env.get("HA_DATEFMT", "%b %d %T ")
391384
+HA_LOGFACILITY = env.get("HA_LOGFACILITY")
391384
+HA_LOGFILE = env.get("HA_LOGFILE")
391384
+HA_DEBUGLOG = env.get("HA_DEBUGLOG")
391384
+
391384
+log = logging.getLogger(os.path.basename(argv[0]))
391384
+log.setLevel(logging.DEBUG)
391384
+
391384
+## add logging to stderr
391384
+if sys.stdout.isatty():
391384
+	seh = logging.StreamHandler(stream=sys.stderr)
391384
+	if HA_DEBUG == 0:
391384
+		seh.setLevel(logging.WARNING)
391384
+	sehformatter = logging.Formatter('%(filename)s(%(OCF_RESOURCE_INSTANCE)s)[%(process)s]:\t%(asctime)s%(levelname)s: %(message)s', datefmt=HA_DATEFMT)
391384
+	seh.setFormatter(sehformatter)
391384
+	log.addHandler(seh)
391384
+
391384
+## add logging to syslog
391384
+if HA_LOGFACILITY:
391384
+	slh = SyslogLibHandler()
391384
+	if HA_DEBUG == 0:
391384
+		slh.setLevel(logging.WARNING)
391384
+	slhformatter = logging.Formatter('%(levelname)s: %(message)s')
391384
+	slh.setFormatter(slhformatter)
391384
+	log.addHandler(slh)
391384
+
391384
+## add logging to file
391384
+if HA_LOGFILE:
391384
+	lfh = logging.FileHandler(HA_LOGFILE)
391384
+	if HA_DEBUG == 0:
391384
+		lfh.setLevel(logging.WARNING)
391384
+	lfhformatter = logging.Formatter('%(filename)s(%(OCF_RESOURCE_INSTANCE)s)[%(process)s]:\t%(asctime)s%(levelname)s: %(message)s', datefmt=HA_DATEFMT)
391384
+	lfh.setFormatter(lfhformatter)
391384
+	log.addHandler(lfh)
391384
+
391384
+## add debug logging to file
391384
+if HA_DEBUGLOG and HA_LOGFILE != HA_DEBUGLOG:
391384
+	dfh = logging.FileHandler(HA_DEBUGLOG)
391384
+	if HA_DEBUG == 0:
391384
+		dfh.setLevel(logging.WARNING)
391384
+	dfhformatter = logging.Formatter('%(filename)s(%(OCF_RESOURCE_INSTANCE)s)[%(process)s]:\t%(asctime)s%(levelname)s: %(message)s', datefmt=HA_DATEFMT)
391384
+	dfh.setFormatter(dfhformatter)
391384
+	log.addHandler(dfh)
391384
+
391384
+logger = logging.LoggerAdapter(log, {'OCF_RESOURCE_INSTANCE': OCF_RESOURCE_INSTANCE})
391384
391384
From 2ade8dbf1f6f6d3889dd1ddbf40858edf10fbdc7 Mon Sep 17 00:00:00 2001
391384
From: Oyvind Albrigtsen <oalbrigt@redhat.com>
391384
Date: Thu, 19 Jul 2018 16:20:39 +0200
391384
Subject: [PATCH 2/5] gcp-vpc-move-vip: use Python library
391384
391384
---
391384
 heartbeat/gcp-vpc-move-vip.in | 42 +++++++++++++++++++++---------------------
391384
 1 file changed, 21 insertions(+), 21 deletions(-)
391384
391384
diff --git a/heartbeat/gcp-vpc-move-vip.in b/heartbeat/gcp-vpc-move-vip.in
391384
index af2080502..eb5bce6a8 100755
391384
--- a/heartbeat/gcp-vpc-move-vip.in
391384
+++ b/heartbeat/gcp-vpc-move-vip.in
391384
@@ -22,6 +22,11 @@ import os
391384
 import sys
391384
 import time
391384
 
391384
+OCF_FUNCTIONS_DIR="%s/lib/heartbeat" % os.environ.get("OCF_ROOT")
391384
+sys.path.append(OCF_FUNCTIONS_DIR)
391384
+
391384
+from ocf import *
391384
+
391384
 try:
391384
   import googleapiclient.discovery
391384
 except ImportError:
391384
@@ -40,10 +45,6 @@ else:
391384
 CONN = None
391384
 THIS_VM = None
391384
 ALIAS = None
391384
-OCF_SUCCESS = 0
391384
-OCF_ERR_GENERIC = 1
391384
-OCF_ERR_CONFIGURED = 6
391384
-OCF_NOT_RUNNING = 7
391384
 METADATA_SERVER = 'http://metadata.google.internal/computeMetadata/v1/'
391384
 METADATA_HEADERS = {'Metadata-Flavor': 'Google'}
391384
 METADATA = \
391384
@@ -206,11 +207,11 @@ def gcp_alias_start(alias):
391384
   # If I already have the IP, exit. If it has an alias IP that isn't the VIP,
391384
   # then remove it
391384
   if my_alias == alias:
391384
-    logging.info(
391384
+    logger.info(
391384
         '%s already has %s attached. No action required' % (THIS_VM, alias))
391384
     sys.exit(OCF_SUCCESS)
391384
   elif my_alias:
391384
-    logging.info('Removing %s from %s' % (my_alias, THIS_VM))
391384
+    logger.info('Removing %s from %s' % (my_alias, THIS_VM))
391384
     set_alias(project, my_zone, THIS_VM, '')
391384
 
391384
   # Loops through all hosts & remove the alias IP from the host that has it
391384
@@ -223,7 +224,7 @@ def gcp_alias_start(alias):
391384
     host_zone = get_zone(project, host)
391384
     host_alias = get_alias(project, host_zone, host)
391384
     if alias == host_alias:
391384
-      logging.info(
391384
+      logger.info(
391384
           '%s is attached to %s - Removing all alias IP addresses from %s' %
391384
           (alias, host, host))
391384
       set_alias(project, host_zone, host, '')
391384
@@ -237,14 +238,14 @@ def gcp_alias_start(alias):
391384
   # Check the IP has been added
391384
   my_alias = get_localhost_alias()
391384
   if alias == my_alias:
391384
-    logging.info('Finished adding %s to %s' % (alias, THIS_VM))
391384
+    logger.info('Finished adding %s to %s' % (alias, THIS_VM))
391384
   elif my_alias:
391384
-    logging.error(
391384
+    logger.error(
391384
         'Failed to add IP. %s has an IP attached but it isn\'t %s' %
391384
         (THIS_VM, alias))
391384
     sys.exit(OCF_ERR_GENERIC)
391384
   else:
391384
-    logging.error('Failed to add IP address %s to %s' % (alias, THIS_VM))
391384
+    logger.error('Failed to add IP address %s to %s' % (alias, THIS_VM))
391384
     sys.exit(OCF_ERR_GENERIC)
391384
 
391384
 
391384
@@ -254,14 +255,14 @@ def gcp_alias_stop(alias):
391384
   project = get_metadata('project/project-id')
391384
 
391384
   if my_alias == alias:
391384
-    logging.info('Removing %s from %s' % (my_alias, THIS_VM))
391384
+    logger.info('Removing %s from %s' % (my_alias, THIS_VM))
391384
     set_alias(project, my_zone, THIS_VM, '')
391384
 
391384
 
391384
 def gcp_alias_status(alias):
391384
   my_alias = get_localhost_alias()
391384
   if alias == my_alias:
391384
-    logging.info('%s has the correct IP address attached' % THIS_VM)
391384
+    logger.info('%s has the correct IP address attached' % THIS_VM)
391384
   else:
391384
     sys.exit(OCF_NOT_RUNNING)
391384
 
391384
@@ -275,25 +276,24 @@ def validate():
391384
   try:
391384
     CONN = googleapiclient.discovery.build('compute', 'v1')
391384
   except Exception as e:
391384
-    logging.error('Couldn\'t connect with google api: ' + str(e))
391384
+    logger.error('Couldn\'t connect with google api: ' + str(e))
391384
     sys.exit(OCF_ERR_CONFIGURED)
391384
 
391384
   try:
391384
     THIS_VM = get_metadata('instance/name')
391384
   except Exception as e:
391384
-    logging.error('Couldn\'t get instance name, is this running inside GCE?: ' + str(e))
391384
+    logger.error('Couldn\'t get instance name, is this running inside GCE?: ' + str(e))
391384
     sys.exit(OCF_ERR_CONFIGURED)
391384
 
391384
   ALIAS = os.environ.get('OCF_RESKEY_alias_ip')
391384
   if not ALIAS:
391384
-    logging.error('Missing alias_ip parameter')
391384
+    logger.error('Missing alias_ip parameter')
391384
     sys.exit(OCF_ERR_CONFIGURED)
391384
 
391384
 
391384
 def configure_logs():
391384
   # Prepare logging
391384
-  logging.basicConfig(
391384
-      format='gcp:alias - %(levelname)s - %(message)s', level=logging.INFO)
391384
+  global logger
391384
   logging.getLogger('googleapiclient').setLevel(logging.WARN)
391384
   logging_env = os.environ.get('OCF_RESKEY_stackdriver_logging')
391384
   if logging_env:
391384
@@ -307,10 +307,10 @@ def configure_logs():
391384
         handler.setLevel(logging.INFO)
391384
         formatter = logging.Formatter('gcp:alias "%(message)s"')
391384
         handler.setFormatter(formatter)
391384
-        root_logger = logging.getLogger()
391384
-        root_logger.addHandler(handler)
391384
+        log.addHandler(handler)
391384
+        logger = logging.LoggerAdapter(log, {'OCF_RESOURCE_INSTANCE': OCF_RESOURCE_INSTANCE})
391384
       except ImportError:
391384
-        logging.error('Couldn\'t import google.cloud.logging, '
391384
+        logger.error('Couldn\'t import google.cloud.logging, '
391384
             'disabling Stackdriver-logging support')
391384
 
391384
 
391384
@@ -331,7 +331,7 @@ def main():
391384
   elif 'status' in sys.argv[1] or 'monitor' in sys.argv[1]:
391384
     gcp_alias_status(ALIAS)
391384
   else:
391384
-    logging.error('no such function %s' % str(sys.argv[1]))
391384
+    logger.error('no such function %s' % str(sys.argv[1]))
391384
 
391384
 
391384
 if __name__ == "__main__":
391384
391384
From 9e9ea17c42df27d4c13fed9badba295df48437f2 Mon Sep 17 00:00:00 2001
391384
From: Oyvind Albrigtsen <oalbrigt@redhat.com>
391384
Date: Fri, 20 Jul 2018 13:27:42 +0200
391384
Subject: [PATCH 3/5] gcp-vpc-move-vip: moved alias-parameters to top of
391384
 metadata
391384
391384
---
391384
 heartbeat/gcp-vpc-move-vip.in | 20 ++++++++++----------
391384
 1 file changed, 10 insertions(+), 10 deletions(-)
391384
391384
diff --git a/heartbeat/gcp-vpc-move-vip.in b/heartbeat/gcp-vpc-move-vip.in
391384
index eb5bce6a8..ba61193b6 100755
391384
--- a/heartbeat/gcp-vpc-move-vip.in
391384
+++ b/heartbeat/gcp-vpc-move-vip.in
391384
@@ -55,6 +55,16 @@ METADATA = \
391384
   <longdesc lang="en">Floating IP Address on Google Cloud Platform - Using Alias IP address functionality to attach a secondary IP address to a running instance</longdesc>
391384
   <shortdesc lang="en">Floating IP Address on Google Cloud Platform</shortdesc>
391384
   <parameters>
391384
+    <parameter name="alias_ip" unique="1" required="1">
391384
+      <longdesc lang="en">IP Address to be added including CIDR. E.g 192.168.0.1/32</longdesc>
391384
+      <shortdesc lang="en">IP Address to be added including CIDR. E.g 192.168.0.1/32</shortdesc>
391384
+      <content type="string" default="" />
391384
+    </parameter>
391384
+    <parameter name="alias_range_name" unique="1" required="0">
391384
+      <longdesc lang="en">Subnet name for the Alias IP</longdesc>
391384
+      <shortdesc lang="en">Subnet name for the Alias IP</shortdesc>
391384
+      <content type="string" default="" />
391384
+    </parameter>
391384
     <parameter name="hostlist" unique="1" required="0">
391384
       <longdesc lang="en">List of hosts in the cluster</longdesc>
391384
       <shortdesc lang="en">Host list</shortdesc>
391384
@@ -65,16 +75,6 @@ METADATA = \
391384
       <shortdesc lang="en">Stackdriver-logging support</shortdesc>
391384
       <content type="boolean" default="" />
391384
     </parameter>
391384
-    <parameter name="alias_ip" unique="1" required="1">
391384
-      <longdesc lang="en">IP Address to be added including CIDR. E.g 192.168.0.1/32</longdesc>
391384
-      <shortdesc lang="en">IP Address to be added including CIDR. E.g 192.168.0.1/32</shortdesc>
391384
-      <content type="string" default="" />
391384
-    </parameter>
391384
-    <parameter name="alias_range_name" unique="1" required="0">
391384
-      <longdesc lang="en">Subnet name for the Alias IP2</longdesc>
391384
-      <shortdesc lang="en">Subnet name for the Alias IP</shortdesc>
391384
-      <content type="string" default="" />
391384
-    </parameter>
391384
   </parameters>
391384
   <actions>
391384
     <action name="start" timeout="300" />
391384
391384
From 716d69040dba7a769efb5a60eca934fdd65585f2 Mon Sep 17 00:00:00 2001
391384
From: Oyvind Albrigtsen <oalbrigt@redhat.com>
391384
Date: Mon, 23 Jul 2018 11:17:00 +0200
391384
Subject: [PATCH 4/5] gcp-vpc-move-route: use Python library
391384
391384
---
391384
 heartbeat/gcp-vpc-move-route.in | 58 ++++++++++++++++++++---------------------
391384
 1 file changed, 28 insertions(+), 30 deletions(-)
391384
391384
diff --git a/heartbeat/gcp-vpc-move-route.in b/heartbeat/gcp-vpc-move-route.in
391384
index 566a70f86..125289d86 100644
391384
--- a/heartbeat/gcp-vpc-move-route.in
391384
+++ b/heartbeat/gcp-vpc-move-route.in
391384
@@ -39,6 +39,11 @@ import os
391384
 import sys
391384
 import time
391384
 
391384
+OCF_FUNCTIONS_DIR="%s/lib/heartbeat" % os.environ.get("OCF_ROOT")
391384
+sys.path.append(OCF_FUNCTIONS_DIR)
391384
+
391384
+from ocf import *
391384
+
391384
 try:
391384
   import googleapiclient.discovery
391384
   import pyroute2
391384
@@ -55,12 +60,6 @@ else:
391384
   import urllib2 as urlrequest
391384
 
391384
 
391384
-OCF_SUCCESS = 0
391384
-OCF_ERR_GENERIC = 1
391384
-OCF_ERR_UNIMPLEMENTED = 3
391384
-OCF_ERR_PERM = 4
391384
-OCF_ERR_CONFIGURED = 6
391384
-OCF_NOT_RUNNING = 7
391384
 GCP_API_URL_PREFIX = 'https://www.googleapis.com/compute/v1'
391384
 METADATA_SERVER = 'http://metadata.google.internal/computeMetadata/v1/'
391384
 METADATA_HEADERS = {'Metadata-Flavor': 'Google'}
391384
@@ -199,18 +198,18 @@ def get_metadata(metadata_key, params=None, timeout=None):
391384
 
391384
 def validate(ctx):
391384
   if os.geteuid() != 0:
391384
-    logging.error('You must run this agent as root')
391384
+    logger.error('You must run this agent as root')
391384
     sys.exit(OCF_ERR_PERM)
391384
 
391384
   try:
391384
     ctx.conn = googleapiclient.discovery.build('compute', 'v1')
391384
   except Exception as e:
391384
-    logging.error('Couldn\'t connect with google api: ' + str(e))
391384
+    logger.error('Couldn\'t connect with google api: ' + str(e))
391384
     sys.exit(OCF_ERR_CONFIGURED)
391384
 
391384
   ctx.ip = os.environ.get('OCF_RESKEY_ip')
391384
   if not ctx.ip:
391384
-    logging.error('Missing ip parameter')
391384
+    logger.error('Missing ip parameter')
391384
     sys.exit(OCF_ERR_CONFIGURED)
391384
 
391384
   try:
391384
@@ -218,7 +217,7 @@ def validate(ctx):
391384
     ctx.zone = get_metadata('instance/zone').split('/')[-1]
391384
     ctx.project = get_metadata('project/project-id')
391384
   except Exception as e:
391384
-    logging.error(
391384
+    logger.error(
391384
         'Instance information not found. Is this a GCE instance ?: %s', str(e))
391384
     sys.exit(OCF_ERR_CONFIGURED)
391384
 
391384
@@ -234,7 +233,7 @@ def validate(ctx):
391384
   atexit.register(ctx.iproute.close)
391384
   idxs = ctx.iproute.link_lookup(ifname=ctx.interface)
391384
   if not idxs:
391384
-    logging.error('Network interface not found')
391384
+    logger.error('Network interface not found')
391384
     sys.exit(OCF_ERR_CONFIGURED)
391384
   ctx.iface_idx = idxs[0]
391384
 
391384
@@ -246,7 +245,7 @@ def check_conflicting_routes(ctx):
391384
   response = request.execute()
391384
   route_list = response.get('items', None)
391384
   if route_list:
391384
-    logging.error(
391384
+    logger.error(
391384
         'Conflicting unnmanaged routes for destination %s/32 in VPC %s found : %s',
391384
         ctx.ip, ctx.vpc_network, str(route_list))
391384
     sys.exit(OCF_ERR_CONFIGURED)
391384
@@ -258,7 +257,7 @@ def route_release(ctx):
391384
 
391384
 
391384
 def ip_monitor(ctx):
391384
-  logging.info('IP monitor: checking local network configuration')
391384
+  logger.info('IP monitor: checking local network configuration')
391384
 
391384
   def address_filter(addr):
391384
     for attr in addr['attrs']:
391384
@@ -271,12 +270,12 @@ def ip_monitor(ctx):
391384
   route = ctx.iproute.get_addr(
391384
       index=ctx.iface_idx, match=address_filter)
391384
   if not route:
391384
-    logging.warn(
391384
+    logger.warning(
391384
         'The floating IP %s is not locally configured on this instance (%s)',
391384
         ctx.ip, ctx.instance)
391384
     return OCF_NOT_RUNNING
391384
 
391384
-  logging.debug(
391384
+  logger.debug(
391384
       'The floating IP %s is correctly configured on this instance (%s)',
391384
       ctx.ip, ctx.instance)
391384
   return OCF_SUCCESS
391384
@@ -287,7 +286,7 @@ def ip_release(ctx):
391384
 
391384
 
391384
 def ip_and_route_start(ctx):
391384
-  logging.info('Bringing up the floating IP %s', ctx.ip)
391384
+  logger.info('Bringing up the floating IP %s', ctx.ip)
391384
 
391384
   # Add a new entry in the routing table
391384
   # If the route entry exists and is pointing to another instance, take it over
391384
@@ -322,7 +321,7 @@ def ip_and_route_start(ctx):
391384
       request.execute()
391384
     except googleapiclient.errors.HttpError as e:
391384
       if e.resp.status == 404:
391384
-        logging.error('VPC network not found')
391384
+        logger.error('VPC network not found')
391384
         sys.exit(OCF_ERR_CONFIGURED)
391384
       else:
391384
         raise
391384
@@ -336,11 +335,11 @@ def ip_and_route_start(ctx):
391384
 
391384
   ctx.iproute.addr('add', index=ctx.iface_idx, address=ctx.ip, mask=32)
391384
   ctx.iproute.link('set', index=ctx.iface_idx, state='up')
391384
-  logging.info('Successfully brought up the floating IP %s', ctx.ip)
391384
+  logger.info('Successfully brought up the floating IP %s', ctx.ip)
391384
 
391384
 
391384
 def route_monitor(ctx):
391384
-  logging.info('GCP route monitor: checking route table')
391384
+  logger.info('GCP route monitor: checking route table')
391384
 
391384
   # Ensure that there is no route that we are not aware of that is also handling our IP
391384
   check_conflicting_routes
391384
@@ -360,39 +359,38 @@ def route_monitor(ctx):
391384
   instance_url = '%s/projects/%s/zones/%s/instances/%s' % (
391384
       GCP_API_URL_PREFIX, ctx.project, ctx.zone, ctx.instance)
391384
   if routed_to_instance != instance_url:
391384
-    logging.warn(
391384
+    logger.warning(
391384
         'The floating IP %s is not routed to this instance (%s) but to instance %s',
391384
         ctx.ip, ctx.instance, routed_to_instance.split('/')[-1])
391384
     return OCF_NOT_RUNNING
391384
 
391384
-  logging.debug(
391384
+  logger.debug(
391384
       'The floating IP %s is correctly routed to this instance (%s)',
391384
       ctx.ip, ctx.instance)
391384
   return OCF_SUCCESS
391384
 
391384
 
391384
 def ip_and_route_stop(ctx):
391384
-  logging.info('Bringing down the floating IP %s', ctx.ip)
391384
+  logger.info('Bringing down the floating IP %s', ctx.ip)
391384
 
391384
   # Delete the route entry
391384
   # If the route entry exists and is pointing to another instance, don't touch it
391384
   if route_monitor(ctx) == OCF_NOT_RUNNING:
391384
-    logging.info(
391384
+    logger.info(
391384
         'The floating IP %s is already not routed to this instance (%s)',
391384
         ctx.ip, ctx.instance)
391384
   else:
391384
     route_release(ctx)
391384
 
391384
   if ip_monitor(ctx) == OCF_NOT_RUNNING:
391384
-    logging.info('The floating IP %s is already down', ctx.ip)
391384
+    logger.info('The floating IP %s is already down', ctx.ip)
391384
   else:
391384
     ip_release(ctx)
391384
 
391384
 
391384
 def configure_logs(ctx):
391384
   # Prepare logging
391384
-  logging.basicConfig(
391384
-      format='gcp:route - %(levelname)s - %(message)s', level=logging.INFO)
391384
+  global logger
391384
   logging.getLogger('googleapiclient').setLevel(logging.WARN)
391384
   logging_env = os.environ.get('OCF_RESKEY_stackdriver_logging')
391384
   if logging_env:
391384
@@ -406,10 +404,10 @@ def configure_logs(ctx):
391384
         handler.setLevel(logging.INFO)
391384
         formatter = logging.Formatter('gcp:route "%(message)s"')
391384
         handler.setFormatter(formatter)
391384
-        root_logger = logging.getLogger()
391384
-        root_logger.addHandler(handler)
391384
+        log.addHandler(handler)
391384
+        logger = logging.LoggerAdapter(log, {'OCF_RESOURCE_INSTANCE': OCF_RESOURCE_INSTANCE})
391384
       except ImportError:
391384
-        logging.error('Couldn\'t import google.cloud.logging, '
391384
+        logger.error('Couldn\'t import google.cloud.logging, '
391384
             'disabling Stackdriver-logging support')
391384
 
391384
 
391384
@@ -434,7 +432,7 @@ def main():
391384
   else:
391384
     usage = 'usage: %s {start|stop|monitor|status|meta-data|validate-all}' % \
391384
         os.path.basename(sys.argv[0])
391384
-    logging.error(usage)
391384
+    logger.error(usage)
391384
     sys.exit(OCF_ERR_UNIMPLEMENTED)
391384
 
391384
 
391384
391384
From 6ec7e87693a51cbb16a1822e6d15f1dbfc11f8e6 Mon Sep 17 00:00:00 2001
391384
From: Oyvind Albrigtsen <oalbrigt@redhat.com>
391384
Date: Mon, 23 Jul 2018 15:55:48 +0200
391384
Subject: [PATCH 5/5] Python: add logging.basicConfig() to support background
391384
 logging
391384
391384
---
391384
 heartbeat/ocf.py | 1 +
391384
 1 file changed, 1 insertion(+)
391384
391384
diff --git a/heartbeat/ocf.py b/heartbeat/ocf.py
391384
index 12be7a2a4..36e7ccccd 100644
391384
--- a/heartbeat/ocf.py
391384
+++ b/heartbeat/ocf.py
391384
@@ -94,6 +94,7 @@ def emit(self, record):
391384
 HA_LOGFILE = env.get("HA_LOGFILE")
391384
 HA_DEBUGLOG = env.get("HA_DEBUGLOG")
391384
 
391384
+logging.basicConfig()
391384
 log = logging.getLogger(os.path.basename(argv[0]))
391384
 log.setLevel(logging.DEBUG)
391384