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

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