Skip to content

Commit

Permalink
Added post checks to check if object are available in etcd post create
Browse files Browse the repository at this point in the history
tendrl-bug-id: Tendrl#296
Signed-off-by: Shubhendu <shtripat@redhat.com>
  • Loading branch information
Shubhendu committed Jun 14, 2017
1 parent 525aedc commit 62b55dd
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 0 deletions.
12 changes: 12 additions & 0 deletions tendrl/gluster_integration/objects/definition/gluster.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ namespace.gluster:
- Volume.tuned_profile
pre_run:
- gluster.objects.Volume.atoms.NamedVolumeNotExists
post_run:
- gluster.objects.Volume.atoms.CheckVolumeAvailable
run: gluster.flows.CreateVolume
type: Create
uuid: 1951e821-7aa9-4a91-8183-e73bc8275b8e
Expand Down Expand Up @@ -440,6 +442,16 @@ namespace.gluster:
run: gluster.objects.Volume.atoms.StopRebalance
type: Start
uuid: 242f6190-9b37-11e6-950d-a24fc0d96567
CheckVolumeAvailable:
enabled: true
help: check if volume is available
inputs:
mandatory:
- Volume.volname
name: volume available
run: gluster.objects.Volume.atoms.CheckVolumeAvailable
type: Start
uuid: 242f6190-9b37-11e6-950d-a24fc0d96765
flows:
DeleteVolume:
tags:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import etcd
import gevent
import subprocess

from tendrl.commons.event import Event
from tendrl.commons.message import Message
from tendrl.commons import objects
from tendrl.commons.objects import AtomExecutionFailedError
from tendrl.gluster_integration.objects.volume import Volume


class CheckVolumeAvailable(objects.BaseAtom):
def __init__(self, *args, **kwargs):
super(CheckVolumeAvailable, self).__init__(*args, **kwargs)

def run(self):
retry_count = 0
while True:
try:
volumes = NS._int.client.read(
"clusters/%s/Volumes" % NS.tendrl_context.integration_id
)
except etcd.EtcdKeyNotFound:
# ignore as no volumes available till now
pass

if volumes:
for entry in volumes.leaves:
volume = Volume(vol_id=entry.key.split("Volumes/")[-1]).load()
if volume.name == self.parameters['Volume.volname']:
return True

retry_count += 1
gevent.sleep(1)
if retry_count == 20:
Event(
Message(
priority="error",
publisher=NS.publisher_id,
payload={
"message": "Volume %s not reflected in tendrl yet. Timing out" %
self.parameters['Volume.volname']
},
job_id=self.parameters['job_id'],
flow_id=self.parameters['flow_id'],
cluster_id=NS.tendrl_context.integration_id,
)
)
raise AtomExecutionFailedError(
"Volume %s not reflected in tendrl yet. Timing out" %
self.parameters['Volume.volname']
)

0 comments on commit 62b55dd

Please sign in to comment.