-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #177 from fmherschel/angi
Angi - srHooks now pylinter compatible
- Loading branch information
Showing
7 changed files
with
356 additions
and
189 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,95 +1,120 @@ | ||
# pylint: disable=invalid-name | ||
# remark: avoid pylint to react on module name does't conform to snake_case | ||
""" | ||
# SAPHana | ||
# Author: Fabian Herschel, 2015 | ||
# License: GNU General Public License (GPL) | ||
# Copyright: (c) 2015-2016 SUSE Linux GmbH | ||
# Copyright: (c) 2017-2022 SUSE LLC | ||
""" | ||
# pylint: enable=invalid-name | ||
# remark: switch-on now name checking | ||
try: | ||
from hdb_ha_dr.client import HADRBase | ||
except ImportError as e: | ||
print("Module HADRBase not found - running outside of SAP HANA? - {0}".format(e)) | ||
print(f"Module HADRBase not found - running outside of SAP HANA? - {e}") | ||
import os | ||
|
||
""" | ||
To use this HA/DR hook provide please add the following lines to your global.ini: | ||
[ha_dr_provider_susHanaSR] | ||
provider = susHanaSR | ||
path = /usr/share/SAPHanaSR-angi | ||
execution_order = 1 | ||
|
||
[trace] | ||
ha_dr_saphanasr = info | ||
""" | ||
fhSRHookVersion = "1.000.0" | ||
# To use this HA/DR hook provide please add the following lines to your global.ini: | ||
# [ha_dr_provider_susHanaSR] | ||
# provider = susHanaSR | ||
# path = /usr/share/SAPHanaSR-angi | ||
# execution_order = 1 | ||
# | ||
# [trace] | ||
# ha_dr_saphanasr = info | ||
# | ||
FH_SR_HOOK_VERSION = "1.001.1" | ||
|
||
|
||
try: | ||
# remark: case style is given by external configuration | ||
# pylint: disable-next=C0103 | ||
class susHanaSR(HADRBase): | ||
""" class susHanaSR to handle HADR events for srConnectionChanged """ | ||
|
||
def __init__(self, *args, **kwargs): | ||
# delegate construction to base class | ||
super(susHanaSR, self).__init__(*args, **kwargs) | ||
self.tracer.info("susHanaSR init()") | ||
""" constructor - delegate construction to base class """ | ||
super().__init__(*args, **kwargs) | ||
method = "init" | ||
self.my_sid = os.environ.get('SAPSYSTEMNAME') | ||
self.tracer.info(f"{self.__class__.__name__}.{method}()" | ||
f" version {FH_SR_HOOK_VERSION}") | ||
|
||
# pylint: disable-next=no-self-use | ||
def about(self): | ||
""" tell about the HADR hook """ | ||
return {"provider_company": "SUSE", | ||
"provider_name": "susHanaSR", # class name | ||
"provider_description": "Inform Cluster about SR state", | ||
"provider_version": "1.0"} | ||
|
||
# pylint: disable-next=unused-argument,invalid-name,too-many-locals | ||
def srConnectionChanged(self, ParamDict, **kwargs): | ||
""" finally we got the srConnection hook :) """ | ||
""" process srConnectionChanged event """ | ||
method = "srConnectionChanged" | ||
self.tracer.info("susHanaSR {0} {1}.srConnectionChanged method called with Dict={2}".format(fhSRHookVersion, self.__class__.__name__, ParamDict)) | ||
# myHostname = socket.gethostname() | ||
# myDatebase = ParamDict["database"] | ||
mySystemStatus = ParamDict["system_status"] | ||
mySID = os.environ.get('SAPSYSTEMNAME') | ||
mysid = mySID.lower() | ||
myInSync = ParamDict["is_in_sync"] | ||
myReason = ParamDict["reason"] | ||
mySite = ParamDict["siteName"] | ||
self.tracer.info("susHanaSR {0}.srConnectionChanged mySystemStatus={1} mySID={2} myInSync={3} myReason={4}".format(self.__class__.__name__, mySystemStatus, mySID, myInSync, myReason)) | ||
if mySystemStatus == 15: | ||
mySRS = "SOK" | ||
self.tracer.info(f"susHanaSR {FH_SR_HOOK_VERSION}" | ||
f" {self.__class__.__name__}.srConnectionChanged" | ||
f" method called with Dict={ParamDict}") | ||
my_system_status = ParamDict["system_status"] | ||
self.my_sid = os.environ.get('SAPSYSTEMNAME') | ||
mysid_lower = self.my_sid.lower() | ||
my_in_sync = ParamDict["is_in_sync"] | ||
my_reason = ParamDict["reason"] | ||
my_site = ParamDict["siteName"] | ||
self.tracer.info(f"susHanaSR {self.__class__.__name__}.srConnectionChanged" | ||
f" system_status={my_system_status} SID={self.my_sid}" | ||
f" in_sync={my_in_sync} reason={my_reason}") | ||
if my_system_status == 15: | ||
my_srs = "SOK" | ||
else: | ||
if myInSync: | ||
if my_in_sync: | ||
# ignoring the SFAIL, because we are still in sync | ||
self.tracer.info("susHanaSR (%s) %s.srConnectionChanged ignoring bad SR status because of is_in_sync=True (reason=%s)" % (fhSRHookVersion, self.__class__.__name__, myReason)) | ||
mySRS = "" | ||
self.tracer.info(f"susHanaSR {FH_SR_HOOK_VERSION}" | ||
f" {self.__class__.__name__}.srConnectionChanged ignoring bad" | ||
f" SR status because of is_in_sync=True (reason={my_reason})") | ||
my_srs = "" | ||
else: | ||
mySRS = "SFAIL" | ||
if mySRS == "": | ||
myMSG = "### Ignoring bad SR status because of is_in_sync=True ###" | ||
self.tracer.info("{0}.{1}() {2}\n".format(self.__class__.__name__, method, myMSG)) | ||
elif mySite == "": | ||
myMSG = "### Ignoring bad SR status because of empty site name in call params ###" | ||
self.tracer.info("{0}.{1}() {2}\n".format(self.__class__.__name__, method, myMSG)) | ||
my_srs = "SFAIL" | ||
if my_srs == "": | ||
my_msg = "### Ignoring bad SR status because of is_in_sync=True ###" | ||
self.tracer.info(f"{self.__class__.__name__}.{method}() {my_msg}\n") | ||
elif my_site == "": | ||
my_msg = "### Ignoring bad SR status because of empty site name in call params ###" | ||
self.tracer.info(f"{self.__class__.__name__}.{method}() {my_msg}\n") | ||
else: | ||
myCMD = "sudo /usr/sbin/crm_attribute -n hana_%s_site_srHook_%s -v %s -t crm_config -s SAPHanaSR" % (mysid, mySite, mySRS) | ||
rc = os.system(myCMD) | ||
myMSG = "CALLING CRM: <{0}> rc={1}".format(myCMD, rc) | ||
self.tracer.info("{0}.{1}() {2}\n".format(self.__class__.__name__, method, myMSG)) | ||
if rc != 0: | ||
my_cmd = ("sudo /usr/sbin/crm_attribute" | ||
f" -n hana_{mysid_lower}_site_srHook_{my_site}" | ||
f" -v {my_srs} -t crm_config -s SAPHanaSR") | ||
ret_code = os.system(my_cmd) | ||
my_msg = f"CALLING CRM: <{my_cmd}> ret_code={ret_code}" | ||
self.tracer.info(f"{self.__class__.__name__}.{method}() {my_msg}\n") | ||
if ret_code != 0: | ||
# | ||
# FALLBACK | ||
# sending attribute to the cluster failed - using fallback method and write status to a file - RA to pick-up the value during next SAPHanaController monitor operation | ||
# sending attribute to the cluster failed - using fallback method and write | ||
# status to a file - RA to pick-up the value during next SAPHanaController | ||
# monitor operation | ||
# | ||
myMSG = "sending attribute to the cluster failed - using local file as fallback" | ||
self.tracer.info("{0}.{1}() {2}\n".format(self.__class__.__name__, method, myMSG)) | ||
my_msg = "sending attribute to the cluster failed - using file as fallback" | ||
self.tracer.info(f"{self.__class__.__name__}.{method}() {my_msg}\n") | ||
# | ||
# cwd of hana is /hana/shared/<SID>/HDB00/<hananode> we use a relative path to cwd this gives us a <sid>adm permitted directory | ||
# however we go one level up (..) to have the file accessible for all SAP HANA swarm nodes | ||
# cwd of hana is /hana/shared/<SID>/HDB00/<hananode> we use a relative path | ||
# to cwd this gives us a <sid>adm permitted directory | ||
# however we go one level up (..) to have the file accessible for all | ||
# SAP HANA swarm nodes | ||
# | ||
fallbackFileObject = open("../.crm_attribute.stage.{0}".format(mySite), "w") | ||
fallbackFileObject.write("hana_{0}_site_srHook_{1} = {2}".format(mysid, mySite, mySRS)) | ||
fallbackFileObject.close() | ||
stage_file = f"../.crm_attribute.stage.{my_site}" | ||
attribute_name = f"hana_{mysid_lower}_site_srHook_{my_site}" | ||
with open(f"{stage_file}", "w", encoding="UTF-8") as fallback_file_obj: | ||
fallback_file_obj.write(f"{attribute_name} = {my_srs}") | ||
# | ||
# release the stage file to the original name (move is used to be atomic) | ||
# .crm_attribute.stage.<site> is renamed to .crm_attribute.<site> | ||
# | ||
os.rename("../.crm_attribute.stage.{0}".format(mySite), "../.crm_attribute.{0}".format(mySite)) | ||
os.rename(f"../.crm_attribute.stage.{my_site}", | ||
f"../.crm_attribute.{my_site}") | ||
return 0 | ||
except NameError as e: | ||
print("Could not find base class ({0})".format(e)) | ||
print(f"Could not find base class ({e})") |
Oops, something went wrong.