Martin Sivák has uploaded a new change for review.

Change subject: Save local maintenance flag to shared block in metadata
......................................................................

Save local maintenance flag to shared block in metadata

Change-Id: Idaf478c3973bd094a928005c5ea98a4e4fb5159d
Signed-off-by: Martin Sivak <m...@montik.net>
---
M ovirt_hosted_engine_ha/agent/hosted_engine.py
M ovirt_hosted_engine_ha/lib/metadata.py
2 files changed, 21 insertions(+), 4 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-hosted-engine-ha 
refs/changes/47/21647/1

diff --git a/ovirt_hosted_engine_ha/agent/hosted_engine.py 
b/ovirt_hosted_engine_ha/agent/hosted_engine.py
index 31f21d0..335ca71 100644
--- a/ovirt_hosted_engine_ha/agent/hosted_engine.py
+++ b/ovirt_hosted_engine_ha/agent/hosted_engine.py
@@ -130,6 +130,8 @@
             self.States.STOP: self._handle_stop,
             self.States.MIGRATE: self._handle_migrate,
             self.States.MAINTENANCE: self._handle_maintenance,
+            # TODO local maintenance state
+            # TODO unexpected crash state
         }
 
     def _get_required_monitors(self):
@@ -612,20 +614,23 @@
             score = 0
 
         # Hosts in local maintenance mode should not run the vm
-        if self._get_maintenance_mode() == self.MaintenanceMode.LOCAL:
+        local_maintenance = (self._get_maintenance_mode()
+                             == self.MaintenanceMode.LOCAL)
+        if local_maintenance:
             self._log.info('Score is 0 due to local maintenance mode')
             score = 0
 
         ts = int(time.time())
         data = ("{md_parse_vers}|{md_feature_vers}|{ts_int}"
-                "|{host_id}|{score}|{engine_status}|{name}"
+                "|{host_id}|{score}|{engine_status}|{name}|{maintenance}"
                 .format(md_parse_vers=constants.METADATA_PARSE_VERSION,
                         md_feature_vers=constants.METADATA_FEATURE_VERSION,
                         ts_int=ts,
                         host_id=self._rinfo['host-id'],
                         score=score,
                         engine_status=lm['engine-health']['status'],
-                        name=socket.gethostname()))
+                        name=socket.gethostname(),
+                        maintenance=1 if local_maintenance else 0))
         if len(data) > constants.METADATA_BLOCK_BYTES:
             raise Exception("Output metadata too long ({0} bytes)"
                             .format(data))
@@ -635,12 +640,14 @@
                 "timestamp={ts_int} ({ts_str})\n"
                 "host-id={host_id}\n"
                 "score={score}\n"
+                "maintenance={maintenance}\n"
                 .format(md_parse_vers=constants.METADATA_PARSE_VERSION,
                         md_feature_vers=constants.METADATA_FEATURE_VERSION,
                         ts_int=ts,
                         ts_str=time.ctime(ts),
                         host_id=self._rinfo['host-id'],
-                        score=score))
+                        score=score,
+                        maintenance=local_maintenance))
         for (k, v) in sorted(lm.iteritems()):
             info += "{0}={1}\n".format(k, str(v['status']))
 
@@ -901,6 +908,7 @@
             self._log.info("Global HA maintenance enabled")
             return self.States.MAINTENANCE, True
         elif self._rinfo['maintenance'] == self.MaintenanceMode.LOCAL:
+            # TODO local maintenance should have its own state
             self._log.info("Local HA maintenance enabled")
             return self.States.OFF, True
 
@@ -1015,10 +1023,12 @@
             self._log.error("Engine vm died unexpectedly")
             self._rinfo['unexpected-shutdown-time'] = int(time.time())
             # Switch to OFF after yielding so score can adjust to 0
+            # TODO make this into new state that keeps track of the time
             return self.States.OFF, True
         elif self._rinfo['best-engine-status-host-id'] != local_host_id:
             self._log.error("Engine vm unexpectedly running on other host")
             self._rinfo['unexpected-shutdown-time'] = int(time.time())
+            # TODO make this into new state that keeps track of the time
             return self.States.OFF, True
 
         if self._rinfo['maintenance'] == self.MaintenanceMode.GLOBAL:
@@ -1026,6 +1036,7 @@
             return self.States.MAINTENANCE, True
         elif self._rinfo['maintenance'] == self.MaintenanceMode.LOCAL:
             self._log.info("Local HA maintenance enabled")
+            # TODO local maintenance should have its own state as well
             return self.States.STOP, False
 
         best_host_id = self._rinfo['best-score-host-id']
diff --git a/ovirt_hosted_engine_ha/lib/metadata.py 
b/ovirt_hosted_engine_ha/lib/metadata.py
index c438956..54224c3 100644
--- a/ovirt_hosted_engine_ha/lib/metadata.py
+++ b/ovirt_hosted_engine_ha/lib/metadata.py
@@ -100,6 +100,8 @@
             (see HostedEngine:engine_status_score_lookup for full/updated
             list of possibilities)
          name - hostname of described host
+         maintenance - 0 or 1 representing host is operational or in
+            local maintenance
      - Next 3584 bytes (for a total of 4096): human-readable description of
        data to aid in debugging, including factors considered in the host score
 
@@ -147,6 +149,10 @@
         'hostname': str(tokens[6]),
     }
 
+    # support maintenance flag if present, but ignore if it isn't
+    if len(tokens) >= 8:
+        ret['maintenance'] = int(tokens[7]) > 0
+
     # check the timestamp to get the hosts liveness
     last_valid_time = time.time() - constants.HOST_ALIVE_TIMEOUT_SECS
     ret['live-data'] = ret['host-ts'] >= last_valid_time


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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Idaf478c3973bd094a928005c5ea98a4e4fb5159d
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-hosted-engine-ha
Gerrit-Branch: master
Gerrit-Owner: Martin Sivák <msi...@redhat.com>
_______________________________________________
Engine-patches mailing list
Engine-patches@ovirt.org
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to