Blame SOURCES/bz1913936-2-gcp-vpc-move-route-fixes.patch

524783
From 523c4cee64b3b8ee9f603a940d83a6628531078d Mon Sep 17 00:00:00 2001
524783
From: Oyvind Albrigtsen <oalbrigt@redhat.com>
524783
Date: Tue, 19 Jan 2021 10:56:47 +0100
524783
Subject: [PATCH 1/2] gcp-vpc-move-route: fix stop-action when route stopped,
524783
 and fix check_conflicting_routes()
524783
524783
---
524783
 heartbeat/gcp-vpc-move-route.in | 23 +++++++++++++++++------
524783
 1 file changed, 17 insertions(+), 6 deletions(-)
524783
524783
diff --git a/heartbeat/gcp-vpc-move-route.in b/heartbeat/gcp-vpc-move-route.in
524783
index 179eba15a..9fe985832 100644
524783
--- a/heartbeat/gcp-vpc-move-route.in
524783
+++ b/heartbeat/gcp-vpc-move-route.in
524783
@@ -252,8 +252,19 @@ def validate(ctx):
524783
 def check_conflicting_routes(ctx):
524783
   fl = '(destRange = "%s*") AND (network = "%s") AND (name != "%s")' % (
524783
       ctx.ip, ctx.vpc_network_url, ctx.route_name)
524783
-  request = ctx.conn.routes().list(project=ctx.project, filter=fl)
524783
-  response = request.execute()
524783
+  try:
524783
+    request = ctx.conn.routes().list(project=ctx.project, filter=fl)
524783
+    response = request.execute()
524783
+  except googleapiclient.errors.HttpError as e:
524783
+    if e.resp.status == 404:
524783
+      logger.error('VPC network not found')
524783
+      if 'stop' in sys.argv[1]:
524783
+        sys.exit(OCF_SUCCESS)
524783
+      else:
524783
+        sys.exit(OCF_ERR_CONFIGURED)
524783
+    else:
524783
+      raise
524783
+
524783
   route_list = response.get('items', None)
524783
   if route_list:
524783
     logger.error(
524783
@@ -353,16 +364,16 @@ def route_monitor(ctx):
524783
   logger.info('GCP route monitor: checking route table')
524783
 
524783
   # Ensure that there is no route that we are not aware of that is also handling our IP
524783
-  check_conflicting_routes
524783
+  check_conflicting_routes(ctx)
524783
 
524783
   try:
524783
     request = ctx.conn.routes().get(project=ctx.project, route=ctx.route_name)
524783
     response = request.execute()
524783
   except googleapiclient.errors.HttpError as e:
524783
-    if 'Insufficient Permission' in e.content:
524783
-      return OCF_ERR_PERM
524783
-    elif e.resp.status == 404:
524783
+    if e.resp.status == 404:
524783
       return OCF_NOT_RUNNING
524783
+    elif 'Insufficient Permission' in e.content:
524783
+      return OCF_ERR_PERM
524783
     else:
524783
       raise
524783
 
524783
524783
From 50dbfc3230e87b8d29163c235e6866d15fd6fc1b Mon Sep 17 00:00:00 2001
524783
From: Oyvind Albrigtsen <oalbrigt@redhat.com>
524783
Date: Tue, 19 Jan 2021 11:50:22 +0100
524783
Subject: [PATCH 2/2] gcp-vpc-move-vip: correctly return error when no
524783
 instances are returned
524783
524783
---
524783
 heartbeat/gcp-vpc-move-vip.in | 20 +++++++++++++++-----
524783
 1 file changed, 15 insertions(+), 5 deletions(-)
524783
524783
diff --git a/heartbeat/gcp-vpc-move-vip.in b/heartbeat/gcp-vpc-move-vip.in
524783
index e792f71d5..bbbd87b7a 100755
524783
--- a/heartbeat/gcp-vpc-move-vip.in
524783
+++ b/heartbeat/gcp-vpc-move-vip.in
524783
@@ -263,8 +263,14 @@ def get_instances_list(project, exclude):
524783
   hostlist = []
524783
   request = CONN.instances().aggregatedList(project=project)
524783
   while request is not None:
524783
-    response = request.execute()
524783
-    zones = response.get('items', {})
524783
+    try:
524783
+      response = request.execute()
524783
+      zones = response.get('items', {})
524783
+    except googleapiclient.errors.HttpError as e:
524783
+      if e.resp.status == 404:
524783
+        logger.debug('get_instances_list(): no instances found')
524783
+        return ''
524783
+
524783
     for zone in zones.values():
524783
       for inst in zone.get('instances', []):
524783
         if inst['name'] != exclude:
524783
@@ -303,9 +309,13 @@ def gcp_alias_start(alias):
524783
       break
524783
 
524783
   # Add alias IP range to localhost
524783
-  add_alias(
524783
-      project, my_zone, THIS_VM, alias,
524783
-      os.environ.get('OCF_RESKEY_alias_range_name'))
524783
+  try:
524783
+    add_alias(
524783
+        project, my_zone, THIS_VM, alias,
524783
+        os.environ.get('OCF_RESKEY_alias_range_name'))
524783
+  except googleapiclient.errors.HttpError as e:
524783
+    if e.resp.status == 404:
524783
+      sys.exit(OCF_ERR_CONFIGURED)
524783
 
524783
   # Verify that the IP range has been added
524783
   my_aliases = get_localhost_aliases()