Commit 545d4cec authored by Agustin Pane's avatar Agustin Pane
Browse files

Merge branch 'hotfix/ubuntu' into 'development'

(Hotfix) - Fix issues on rpm systems

See merge request !25
parents aeb75858 0ff12d34
......@@ -4,7 +4,7 @@ from setuptools import setup
setup(
name='svmon-client',
version='2.4.0',
version='2.4.2',
packages=['svmon_client'],
scripts=['svmon'],
package_data={'' : ['*.json','*.pem']},
......
......@@ -176,7 +176,8 @@ class SVMONReport:
serviceVersionIterator=0
for serviceIterator in range(len(self.service_names)):
if serviceVersionIterator < len(self.tags) and self.tags[serviceVersionIterator] != None and self.tags[serviceVersionIterator] != "" :
res.append(self.site+'\t'+self.host+'\t'+self.operating_system+'\t'+self.service_type+'\t'+self.service_names[serviceIterator]+'\t'+self.tags[serviceVersionIterator]+'\n')
tagsDecoded = self.tags[serviceVersionIterator].decode('utf-8')
res.append(self.site+'\t'+self.host+'\t'+self.operating_system+'\t'+self.service_type+'\t'+self.service_names[serviceIterator]+'\t'+tagsDecoded+'\n')
serviceVersionIterator = serviceVersionIterator +1
return res
else:
......
......@@ -2,6 +2,8 @@
# -*- coding: UTF-8 -*-
import subprocess
import codecs
import sys
import os
from platform import python_version
from svmon_client import remoteConfig
......@@ -75,7 +77,8 @@ def get_service_tag(service_type,configs=None):
tmp = get_package_version("gitlab", 0 , 1)
if(enableDebug):
print('get_service_tag for gitlab result: ', tmp)
if tmp == None or tmp == '' or tmp.find('Failed') >-1:
tmp = to_bytes(tmp)
if tmp == None or tmp == '' or tmp.find('Failed'.encode('utf-8')) >-1:
print("no gitlab version can be resolved")
exit(1)
tags.append(tmp)
......@@ -93,13 +96,14 @@ def get_service_tag(service_type,configs=None):
tmp=get_package_version("irods-server")
if(enableDebug):
print('get_service_tag for irods-server result: '+ tmp)
if tmp != None and tmp != '' and tmp.find('Failed') == -1:
if tmp != None and tmp != '' and tmp.find('Failed'.encode('utf-8')) == -1:
tags.append(tmp)
return tags
tmp=get_package_version("irods-icat")
if(enableDebug):
print('get_service_tag for irods-icat result: '+tmp)
if tmp != None and tmp != '' and tmp.find('Failed') == -1:
tmp = to_bytes(tmp)
if tmp != None and tmp != '' and tmp.find('Failed'.encode('utf-8')) == -1:
tags.append(tmp)
return tags
print("No irods version can be resolved")
......@@ -131,6 +135,7 @@ def get_service_tag(service_type,configs=None):
def get_package_version(software,start=0,end=0):
config = remoteConfig.RemoteConfig().getConfig()
enableDebug = config["DEBUG_MODE"]
print('Get_package_version for software: '+software)
if(enableDebug):
print('Get_package_version for software: '+software)
......@@ -141,14 +146,22 @@ def get_package_version(software,start=0,end=0):
print("The input of indices should be integers to fetch correct version,")
exit(1)
dpkgResult = subprocess.Popen("which dpkg", shell=True, stdout=subprocess.PIPE)
dpkgResult = dpkgResult.communicate()
if dpkgResult[0] == None or dpkgResult == "":
osSupportsDPKG = False
try:
dpkgRunResult = subprocess.check_output("dpkg -l", shell=True, stderr=subprocess.STDOUT)
osSupportsDPKG = True
except subprocess.CalledProcessError as e:
if(enableDebug):
print('No dpkg found, running with rpm...')
print("Tried to run dpkg, is not working on this OS, output: ", e.output)
if osSupportsDPKG == False:
if(enableDebug):
print('No dpkg found, running with rpm...')
return get_by_rpm_packages(software, start,end)
if(enableDebug):
print('Dpkg found, running with dpkg...')
return get_by_dpkg_packages(software,start,end)
# for package version that can be accessed via rpm management
......@@ -167,8 +180,9 @@ def get_by_dpkg_packages(software,start=0,end=0):
if softwareListResult[0] == None or softwareListResult == "":
print('Failed, no dpkg packages can be found for ', software)
return ''
softwareListResult = softwareListResult[0]
return extractVersionFromCommandResult(software, softwareListResult[0], start,end)
return extractVersionFromCommandResult(software.encode('utf-8'), softwareListResult, start,end)
# for package version that can be accessed via rpm management
def get_by_rpm_packages(software,start=0,end=0):
......@@ -189,18 +203,30 @@ def get_by_rpm_packages(software,start=0,end=0):
return extractVersionFromCommandResult(software, softwareListResult[0], start,end)
def to_bytes(s):
if type(s) is bytes:
return s
elif type(s) is str or (sys.version_info[0] < 3 and type(s) is unicode):
return codecs.encode(s, 'utf-8')
else:
raise TypeError("Expected bytes or string, but got %s." % type(s))
def extractVersionFromCommandResult(software,unparsedVersion, start,end):
software=to_bytes(software)
unparsedVersion=to_bytes(unparsedVersion)
softwareIndex=unparsedVersion.find(software)
softwareIndex=softwareIndex+len(software)
parsedVersion=unparsedVersion[softwareIndex+1:len(unparsedVersion)].split('-')
versionIndex=unparsedVersion[softwareIndex+1:len(unparsedVersion)]
versionIndex=to_bytes(versionIndex)
parsedVersion=versionIndex.split('-'.encode('utf-8'))
if len(parsedVersion) > end:
if start == end:
return parsedVersion[start]
return ltmp[start]
elif start < end:
res=""
for i in range(start,end+1):
res=res+parsedVersion[i]
res=res+ltmp[i]
return res
else:
print('Failed, the start index should be smaller than end index for a correct rpm package resolver')
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment