Ramesh N has uploaded a new change for review.

Change subject: gluster:enforce gluster fencing policies
......................................................................

gluster:enforce gluster fencing policies

 Enforce gluster related fencing policies before fencing
the host.

1. skipFecingIfGlusterBricksUp
    Fencing should be skipped any brick is ONLINE in
the host being fenced.
2. skipFecingIfGlusterQuorumNotMet
    Fencing should be skipped if any brick is ONLINE
in the host being fenced and quorum will be lost if the
brick is brought down.

Gluster volume info command will be used to get the
volume details and 'volume status' command will be used
to get the brick status from fence proxy host.

Change-Id: I2c18571209a3a7682a43bd2814b9ee3f0a69c55f
Signed-off-by: Ramesh Nachimuthu <[email protected]>
---
M vdsm/API.py
1 file changed, 66 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/00/59600/1

diff --git a/vdsm/API.py b/vdsm/API.py
index 698ac29..fba19ac 100644
--- a/vdsm/API.py
+++ b/vdsm/API.py
@@ -22,6 +22,7 @@
 
 import os
 import logging
+import math
 
 from vdsm.network.errors import ConfigNetworkError
 
@@ -54,6 +55,7 @@
 import caps
 from vdsm.config import config
 from vdsm.virt import sampling
+from gluster import cli as glustercli
 
 
 haClient = None  # Define here to work around pyflakes issue #13
@@ -1255,8 +1257,72 @@
                     return False
 
             self.log.debug("Host doesn't have any live lease")
+            return can_fence_gluster_hosts(policy)
+
+        def can_fence_gluster_hosts(policy):
+            skipFecingIfGlusterBricksUp = \
+                policy.get('skipFencingIfGlusterBricksUp') == 'true'
+            skipFecingIfGlusterQuorumNotMet = \
+                policy.get('skipFencingIfGlusterQuorumNotMet') == 'true'
+            hostUuid = policy.get('glusterServerUuid')
+            if skipFecingIfGlusterBricksUp or skipFecingIfGlusterQuorumNotMet:
+                volumesList = glustercli.volumeInfo()
+                for volumeName in volumesList:
+                    if 'REPLICATE' in volumesList.get(volumeName).\
+                            get('volumeType'):
+                        volumeStatus = glustercli.volumeStatus(volumeName)
+                        if skipFecingIfGlusterBricksUp:
+                            for brick in volumeStatus.get('bricks'):
+                                if hostUuid == brick.get('hostuuid') \
+                                        and brick.get('status') == 'ONLINE':
+                                    self.log.error("Gluster brick '%s' "
+                                                   "is ONLINE.",
+                                                   brick.get("name"))
+                                    return False
+                        if skipFecingIfGlusterQuorumNotMet:
+                            if not is_gluster_quorum_met(
+                                    volumesList.get(volumeName),
+                                    volumeStatus, hostUuid):
+                                self.log.error("Gluster Quorum not met "
+                                               "for volume %s", volumeName)
+                                return False
             return True
 
+        def is_gluster_quorum_met(volumeInfo, volumeStatus, hostUuid):
+            replicaCount = volumeInfo.get("replicaCount")
+            subVolumes = volumeInfo.get('brickCount')
+            quorumType = volumeInfo.get("options").get("cluster.quorum-type")
+            if quorumType == "fixed":
+                quorumCount = volumeInfo.get("cluster.quorum-count")
+            elif quorumType == "auto":
+                quorumCount = math.ceil(replicaCount/2)
+            else:
+                return True
+            for index in range(0, subVolumes):
+                subVolume = \
+                    volumeInfo.get("bricksInfo")[index:index+replicaCount]
+
+                bricksRemainingUp = 0
+                bricksGoingDown = 0
+
+                for brick in subVolume:
+                    brick_status = get_brick_status(brick.get('hostUuid'),
+                                                    brick.get("name"),
+                                                    volumeStatus)
+                    if brick_status.get('status') == 'ONLINE':
+                        if brick.get('hostUuid') == hostUuid:
+                            bricksGoingDown += bricksGoingDown
+                        else:
+                            bricksRemainingUp += bricksRemainingUp
+                if bricksGoingDown > 0 and bricksRemainingUp < quorumCount:
+                    return False
+            return True
+
+        def get_brick_status(hostUuid, brickName, volumeStatus):
+            return [brick for brick in volumeStatus.get("bircks")
+                    if brick.get("hostuuid") == hostUuid
+                    and brick.get("brick") == brickName][0]
+
         self.log.debug('fenceNode(addr=%s,port=%s,agent=%s,user=%s,passwd=%s,'
                        'action=%s,secure=%s,options=%s,policy=%s)',
                        addr, port, agent, username, password, action, secure,


-- 
To view, visit https://gerrit.ovirt.org/59600
To unsubscribe, visit https://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I2c18571209a3a7682a43bd2814b9ee3f0a69c55f
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Ramesh N <[email protected]>
_______________________________________________
vdsm-patches mailing list
[email protected]
https://lists.fedorahosted.org/admin/lists/[email protected]

Reply via email to