Simone Tiraboschi has uploaded a new change for review.

Change subject: Avoiding legacy health servlet usage
......................................................................

Avoiding legacy health servlet usage

Avoidind legacy health servlet usage to check engine health in favor
of REST API.

Change-Id: I3522ccb82eee4bf7f04ded012d9badc97c55b5a0
Bug-Url: https://bugzilla.redhat.com/show_bug.cgi?id=1027210
Signed-off-by: Simone Tiraboschi <stira...@redhat.com>
---
M src/ovirt_hosted_engine_setup/check_liveliness.py
M src/plugins/ovirt-hosted-engine-setup/engine/health.py
2 files changed, 53 insertions(+), 25 deletions(-)


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

diff --git a/src/ovirt_hosted_engine_setup/check_liveliness.py 
b/src/ovirt_hosted_engine_setup/check_liveliness.py
index cbfc7b6..7febc6a 100644
--- a/src/ovirt_hosted_engine_setup/check_liveliness.py
+++ b/src/ovirt_hosted_engine_setup/check_liveliness.py
@@ -19,15 +19,16 @@
 
 """Check for engine liveliness"""
 
-
 import contextlib
 import gettext
+import os
 import re
+import tempfile
+
 import urllib2
-
-
 from otopi import base
 from otopi import util
+from ovirt_hosted_engine_setup import constants as ohostedcons
 
 
 _ = lambda m: gettext.dgettext(message=m, domain='ovirt-hosted-engine-setup')
@@ -41,38 +42,65 @@
 
     def __init__(self):
         super(LivelinessChecker, self).__init__()
+        self.cert = None
+
+    def _getPKICert(self, fqdn):
+        self.logger.debug('Acquiring ca.crt from the engine')
+        with contextlib.closing(
+            urllib2.urlopen(
+                'http://{fqdn}/ca.crt'.format(
+                    fqdn=fqdn,
+                )
+            )
+        ) as urlObj:
+            content = urlObj.read()
+            if content:
+                self.logger.debug(content)
+                fd, self.cert = tempfile.mkstemp(
+                    prefix='engine-ca',
+                    suffix='.crt',
+                )
+                os.fchmod(fd, 0o600)
+                with os.fdopen(fd, 'w') as fileobj:
+                    fileobj.write(content)
 
     def isEngineUp(self, fqdn):
-        self.logger.debug('Checking for Engine health status')
-        health_url = 'http://{fqdn}/ovirt-engine/services/health'.format(
-            fqdn=fqdn,
-        )
+        self.logger.debug('Waiting Engine API response')
         isUp = False
+
+        if self.cert is None:
+            self._getPKICert(fqdn)
+
         try:
-            with contextlib.closing(
-                urllib2.urlopen(
-                    url=health_url,
-                    timeout=self.TIMEOUT,
-                )
-            ) 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:
+            # Now we are using the SDK to authenticate vs the API
+            # to check if the engine is up.
+            # Maybe in the future we can just rely on a
+            # not authenticated health API URL
+            self._ovirtsdk_api.API(
+                url='https://{fqdn}/ovirt-engine/api'.format(
+                    # should we also handle installation over
+                    # non standar port?
+                    fqdn=fqdn,
+                ),
+                username='admin@internal',
+                password=self.environment[
+                    ohostedcons.EngineEnv.ADMIN_PASSWORD,
+                ],
+                ca_file=self.cert,
+            )
+            isUp = True
+        except self._ovirtsdk_api.RequestError:
             self.logger.error(_('Engine is still unreachable'))
         return isUp
+
+    def __exit__(self, type, value, tb):
+        if self.cert is not None and os.path.exists(self.cert):
+            os.unlink(self.cert)
 
 
 if __name__ == "__main__":
     import sys
 
-    from ovirt_hosted_engine_setup import constants as ohostedcons
     config_re = re.compile('^(?P<key>[^=]+)=(?P<value>.*)$')
     config = {}
     try:
diff --git a/src/plugins/ovirt-hosted-engine-setup/engine/health.py 
b/src/plugins/ovirt-hosted-engine-setup/engine/health.py
index 8d4bfa8..7ac4740 100644
--- a/src/plugins/ovirt-hosted-engine-setup/engine/health.py
+++ b/src/plugins/ovirt-hosted-engine-setup/engine/health.py
@@ -89,7 +89,7 @@
                     poll = False
                 else:
                     self.dialog.note(
-                        _('Engine health status page is not yet reachable.\n')
+                        _('Engine APIs are not yet reachable.\n')
                     )
             elif response == _('2').lower():
                 self._destroy_vm()


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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I3522ccb82eee4bf7f04ded012d9badc97c55b5a0
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-hosted-engine-setup
Gerrit-Branch: master
Gerrit-Owner: Simone Tiraboschi <stira...@redhat.com>
_______________________________________________
Engine-patches mailing list
Engine-patches@ovirt.org
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to