Sandro Bonazzola has uploaded a new change for review.

Change subject: bin: add --check-liveliness support
......................................................................

bin: add --check-liveliness support

Refactored the healt checking plugin creating
a shared module for checking the engine liveliness.
Adedd --check-liveliness support calling the new module.

Change-Id: If146459d62815dcf030fcd151b61faddb6af8be9
Signed-off-by: Sandro Bonazzola <[email protected]>
---
M src/bin/hosted-engine.in
M src/ovirt_hosted_engine_setup/Makefile.am
A src/ovirt_hosted_engine_setup/check_liveliness.py
M src/plugins/ovirt-hosted-engine-setup/engine/health.py
4 files changed, 112 insertions(+), 29 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-hosted-engine-setup 
refs/changes/53/16953/1

diff --git a/src/bin/hosted-engine.in b/src/bin/hosted-engine.in
index baf3186..c5239e5 100644
--- a/src/bin/hosted-engine.in
+++ b/src/bin/hosted-engine.in
@@ -23,6 +23,9 @@
         VM status according to sanlock
     --add-console-password=<password>
         Create a temporary password for vnc/spice connection
+    --check-liveliness
+        Checks liveliness page of engine
+
 
 __EOF__
     exit $rc
@@ -65,6 +68,9 @@
                 echo "You must run --deploy first"
             fi
         ;;
+        --check-liveliness)
+            python -m ovirt_hosted_engine_setup.check_liveliness
+        ;;
         --help)
             rc=0
             usage
diff --git a/src/ovirt_hosted_engine_setup/Makefile.am 
b/src/ovirt_hosted_engine_setup/Makefile.am
index bdfba99..d4a7daa 100644
--- a/src/ovirt_hosted_engine_setup/Makefile.am
+++ b/src/ovirt_hosted_engine_setup/Makefile.am
@@ -28,6 +28,7 @@
 
 dist_ovirthostedenginelib_PYTHON = \
        __init__.py \
+       check_liveliness.py \
        constants.py \
        domains.py \
        util.py \
diff --git a/src/ovirt_hosted_engine_setup/check_liveliness.py 
b/src/ovirt_hosted_engine_setup/check_liveliness.py
new file mode 100644
index 0000000..1c96849
--- /dev/null
+++ b/src/ovirt_hosted_engine_setup/check_liveliness.py
@@ -0,0 +1,99 @@
+#
+# ovirt-hosted-engine-setup -- ovirt hosted engine setup
+# Copyright (C) 2013 Red Hat, Inc.
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+#
+
+"""Check for engine liveliness"""
+
+
+import contextlib
+import gettext
+import re
+import urllib2
+
+
+from otopi import base
+from otopi import util
+
+
+_ = lambda m: gettext.dgettext(message=m, domain='ovirt-hosted-engine-setup')
+
+
[email protected]
+class LivelinessChecker(base.Base):
+
+    DB_UP_RE = re.compile('.*DB Up.*')
+
+    def __init__(self):
+        super(LivelinessChecker, self).__init__()
+
+    def isEngineUp(self, fqdn):
+        self.logger.debug('Checking for Engine health status')
+        health_url = 'http://{fqdn}/OvirtEngineWeb/HealthStatus'.format(
+            fqdn=fqdn,
+        )
+        isUp = False
+        try:
+            with contextlib.closing(urllib2.urlopen(health_url)) as urlObj:
+                content = urlObj.read()
+                if content:
+                    if self.DB_UP_RE.match(content) is not None:
+                        isUp = True
+                    self.logger.info(
+                        _('Engine replied: {status}').format(
+                            status=content,
+                        )
+                    )
+        except urllib2.URLError:
+            self.logger.error(_('Engine is still unreachable'))
+        return isUp
+
+
+if __name__ == "__main__":
+    import sys
+
+    from ovirt_hosted_engine_setup import constants as ohostedcons
+
+    config = {}
+    try:
+        with open(
+            ohostedcons.FileLocations.OVIRT_HOSTED_ENGINE_SETUP_CONF
+        ) as f:
+            content = f.read().splitlines()
+            for line in content:
+                if '=' in line:
+                    key, value = line.split('=')
+                    config[key] = value
+    except IOError:
+        sys.stderr.write(_('Error reading the configuration file\n'))
+        sys.exit(2)
+    if not 'fqdn' in config:
+        sys.stderr.write(
+            _(
+                'Incomplete configuration, missing FQDN '
+                'of the hosted engine VM\n'
+            )
+        )
+        sys.exit(2)
+
+    live_checker = LivelinessChecker()
+    if not live_checker.isEngineUp(config['fqdn']):
+        print _('Hosted Engine is not up!')
+        sys.exit(1)
+    print _('Hosted Engine is up!')
+
+# vim: expandtab tabstop=4 shiftwidth=4
diff --git a/src/plugins/ovirt-hosted-engine-setup/engine/health.py 
b/src/plugins/ovirt-hosted-engine-setup/engine/health.py
index c292a30..474e679 100644
--- a/src/plugins/ovirt-hosted-engine-setup/engine/health.py
+++ b/src/plugins/ovirt-hosted-engine-setup/engine/health.py
@@ -23,10 +23,7 @@
 """
 
 
-import contextlib
 import gettext
-import re
-import urllib2
 
 
 from otopi import util
@@ -34,6 +31,7 @@
 
 
 from ovirt_hosted_engine_setup import constants as ohostedcons
+from ovirt_hosted_engine_setup import check_liveliness
 
 
 _ = lambda m: gettext.dgettext(message=m, domain='ovirt-hosted-engine-setup')
@@ -45,33 +43,8 @@
     engine health status handler plugin.
     """
 
-    DB_UP_RE = re.compile('.*DB Up.*')
-
     def __init__(self, context):
         super(Plugin, self).__init__(context=context)
-
-    def _isEngineUp(self):
-        self.logger.debug('Checking for Engine health status')
-        health_url = 'http://{fqdn}/OvirtEngineWeb/HealthStatus'.format(
-            fqdn=self.environment[
-                ohostedcons.NetworkEnv.OVIRT_HOSTED_ENGINE_FQDN
-            ],
-        )
-        isUp = False
-        try:
-            with contextlib.closing(urllib2.urlopen(health_url)) as urlObj:
-                content = urlObj.read()
-                if content:
-                    if self.DB_UP_RE.match(content) is not None:
-                        isUp = True
-                    self.logger.info(
-                        _('Engine replied: {status}').format(
-                            status=content,
-                        )
-                    )
-        except urllib2.URLError:
-            self.logger.error(_('Engine is still unreachable'))
-        return isUp
 
     @plugin.event(
         stage=plugin.Stages.STAGE_CLOSEUP,
@@ -82,6 +55,10 @@
     )
     def _closeup(self):
         poll = True
+        fqdn = self.environment[
+            ohostedcons.NetworkEnv.OVIRT_HOSTED_ENGINE_FQDN
+        ]
+        live_checker = check_liveliness.LivelinessChecker()
         while poll:
             self.dialog.queryString(
                 name='ovehosted_engine_up',
@@ -92,7 +69,7 @@
                 prompt=True,
                 default='y'  # Allow enter without any value
             )
-            if self._isEngineUp():
+            if live_checker.isEngineUp(fqdn):
                 poll = False
             elif self.dialog.queryString(
                 name='ovehosted_engine_check_again',


-- 
To view, visit http://gerrit.ovirt.org/16953
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: If146459d62815dcf030fcd151b61faddb6af8be9
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-hosted-engine-setup
Gerrit-Branch: master
Gerrit-Owner: Sandro Bonazzola <[email protected]>
_______________________________________________
Engine-patches mailing list
[email protected]
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to