Skip to content

Commit

Permalink
fix: make SAPHostCtrlInstances compatible with old archives (#3528)
Browse files Browse the repository at this point in the history
* fix: make SAPHostCtrlInstances compatible with old archives

- Generate the InstanceType as per the InstanceName,
  since it is not collected by the old archives.

Signed-off-by: Xiangce Liu <[email protected]>

* fix tests
* coverage 100%

Signed-off-by: Xiangce Liu <[email protected]>
  • Loading branch information
xiangce authored Sep 29, 2022
1 parent a186edf commit 1c53b43
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
6 changes: 5 additions & 1 deletion insights/parsers/saphostctrl.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,12 @@ def parse_content(self, content):
inst[fields[0]] = fields[2]

if fields[0] == 'InstanceName':
short_type = fields[2].strip('0123456789')
# Back forward compatible: a short InstanceType was from the InstanceName
if 'InstanceType' not in inst:
inst.update(dict(InstanceType=short_type))
self.instances.append(fields[2])
_types.add(fields[2].strip('0123456789'))
_types.add(short_type)
_sids.add(fields[2]) if fields[0] == 'SID' else None

if len(self) < 1:
Expand Down
29 changes: 29 additions & 0 deletions insights/tests/parsers/test_saphostctrl.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,28 @@
SapVersionInfo , String , 749, patch 211, changelist 1754007
'''

SAPHOSTCTRL_HOSTINSTANCES_DOCS_OLD = '''
*********************************************************
CreationClassName , String , SAPInstance
SID , String , D89
SystemNumber , String , 88
InstanceType , String , HANA Test
InstanceName , String , HDB88
Hostname , String , lu0417
FullQualifiedHostname , String , lu0417.example.com
IPAddress , String , 10.0.0.88
SapVersionInfo , String , 749, patch 211, changelist 1754007
*********************************************************
CreationClassName , String , SAPInstance
SID , String , D90
SystemNumber , String , 90
InstanceName , String , HDB90
Hostname , String , lu0418
FullQualifiedHostname , String , lu0418.example.com
IPAddress , String , 10.0.0.90
SapVersionInfo , String , 749, patch 211, changelist 1754007
'''

SAPHOSTCTRL_HOSTINSTANCES_GOOD = '''
*********************************************************
SID , String , D89
Expand Down Expand Up @@ -157,6 +179,13 @@ def test_saphostctrl():
])


def test_saphostctrl_old():
sap = SAPHostCtrlInstances(context_wrap(SAPHOSTCTRL_HOSTINSTANCES_DOCS_OLD))
assert sap.types == ['HDB'] # short types only
assert sap[0]['InstanceType'] == 'HANA Test'
assert sap[1]['InstanceType'] == 'HDB'


def test_saphostctrl_bad():
with pytest.raises(SkipException):
SAPHostCtrlInstances(context_wrap(''))
Expand Down

0 comments on commit 1c53b43

Please sign in to comment.