resource-agents/SOURCES/bz1913932-2-gcp-vpc-move-ro...

107 lines
3.6 KiB
Diff

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