Make Health Check work with new db and config

Change-Id: Ic4c9913b45e09add559adcae6c441b55ef356731
This commit is contained in:
xichengc 2014-08-06 11:26:25 -07:00
parent 21cc07bed3
commit bd745ff87e
8 changed files with 64 additions and 20 deletions

View File

@ -14,6 +14,8 @@
"""Base class for Compass Health Check."""
from compass.actions.health_check import utils as health_check_utils
from compass.db.api import database
from compass.db import models
from compass.utils import setting_wrapper as setting
@ -25,6 +27,32 @@ class BaseCheck(object):
self.code = 1
self.messages = []
self.dist, self.version, self.release = health_check_utils.get_dist()
self.os_installer = self._get_os_installer()
self.package_installer = self._get_package_installer()
def _get_os_installer(self):
database.init()
os_installer = {}
with database.session() as session:
installer = session.query(
models.OSInstaller
).first()
os_installer['name'] = health_check_utils.strip_name(
installer.name)
os_installer.update(installer.settings)
return os_installer
def _get_package_installer(self):
database.init()
package_installer = {}
with database.session() as session:
installer = session.query(
models.PackageInstaller
).first()
package_installer['name'] = health_check_utils.strip_name(
installer.name)
package_installer.update(installer.settings)
return package_installer
def _set_status(self, code, message):
"""set status."""

View File

@ -36,12 +36,12 @@ class BootCheck(base.BaseCheck):
status['celery'] = self._check_celery()
status['dhcp'] = self._check_dhcp()
status['dns'] = self._check_dns()
# status['hds'] = self._check_hds()
status['hds'] = self._check_hds()
status['os_installer'] = self._check_os_installer()
status['package_installer'] = self._check_package_installer()
status['squid'] = self._check_squid()
status['tftp'] = self._check_tftp()
# status['other'] = self._check_misc()
status['other'] = self._check_misc()
return status

View File

@ -29,8 +29,7 @@ class DhcpCheck(base.BaseCheck):
def run(self):
"""do health check."""
installer = self.config.OS_INSTALLER
method_name = "self.check_" + installer + "_dhcp()"
method_name = "self.check_" + self.os_installer['name'] + "_dhcp()"
return eval(method_name)
def check_cobbler_dhcp(self):
@ -38,10 +37,10 @@ class DhcpCheck(base.BaseCheck):
try:
remote = xmlrpclib.Server(
self.config.COBBLER_INSTALLER_URL,
self.os_installer['url'],
allow_none=True)
remote.login(
*self.config.COBBLER_INSTALLER_TOKEN)
*self.os_installer['token'])
except Exception:
self._set_status(
0,

View File

@ -28,18 +28,17 @@ class DnsCheck(base.BaseCheck):
def run(self):
"""do health check."""
installer = self.config.OS_INSTALLER
method_name = "self.check_" + installer + "_dns()"
method_name = "self.check_" + self.os_installer['name'] + "_dns()"
return eval(method_name)
def check_cobbler_dns(self):
"""Checks if Cobbler has taken over DNS service."""
try:
remote = xmlrpclib.Server(
self.config.COBBLER_INSTALLER_URL,
self.os_installer['url'],
allow_none=True)
remote.login(
*self.config.COBBLER_INSTALLER_TOKEN)
*self.os_installer['token'])
except Exception:
self._set_status(0,
"[%s]Error: Cannot login to Cobbler "

View File

@ -26,18 +26,17 @@ class OsInstallerCheck(base.BaseCheck):
def run(self):
"""do health check."""
installer = self.config.OS_INSTALLER
method_name = 'self.' + installer + '_check()'
method_name = 'self.' + self.os_installer['name'] + '_check()'
return eval(method_name)
def cobbler_check(self):
"""Runs cobbler check from xmlrpc client."""
try:
remote = xmlrpclib.Server(
self.config.COBBLER_INSTALLER_URL,
self.os_installer['url'],
allow_none=True)
token = remote.login(
*self.config.COBBLER_INSTALLER_TOKEN)
*self.os_installer['token'])
except Exception:
self.code = 0
self.messages.append(

View File

@ -28,8 +28,7 @@ class PackageInstallerCheck(base.BaseCheck):
def run(self):
"""do health check."""
installer = self.config.PACKAGE_INSTALLER
method_name = "self." + installer + "_check()"
method_name = "self." + self.package_installer['name'] + "_check()"
return eval(method_name)
def chef_check(self):

View File

@ -27,8 +27,7 @@ class TftpCheck(base.BaseCheck):
def run(self):
"""do health check."""
installer = self.config.OS_INSTALLER
method_name = "self.check_" + installer + "_tftp()"
method_name = "self.check_" + self.os_installer['name'] + "_tftp()"
return eval(method_name)
def check_cobbler_tftp(self):
@ -40,10 +39,10 @@ class TftpCheck(base.BaseCheck):
try:
remote = xmlrpclib.Server(
self.config.COBBLER_INSTALLER_URL,
self.os_installer['name'],
allow_none=True)
remote.login(
*self.config.COBBLER_INSTALLER_TOKEN)
*self.os_installer['token'])
except Exception:
self._set_status(
0,

View File

@ -16,6 +16,7 @@
import commands
import os
import platform
import re
def validate_setting(module, setting, param):
@ -91,3 +92,23 @@ def check_chkconfig(service_name):
break
return chk_on
def strip_name(name):
"""Reformats names."""
if not any([s in name for s in "(,),-,_".split(',')]):
return name
paren_regex = re.compile("(.*?)\s*\(")
dash_regex = re.compile("(.*?)\s*\-")
under_dash_regex = re.compile("(.*?)\s*\_")
r1 = paren_regex.match(name)
r2 = dash_regex.match(name)
r3 = under_dash_regex.match(name)
shortest = 'AVeryLongStringForDefualt'
for r in [r1, r2, r3]:
if r and len(r.group(1)) < len(shortest):
shortest = r.group(1)
return shortest